]> git.saurik.com Git - wxWidgets.git/blob - contrib/src/applet/prepecho.cpp
Fixed an OOR related bug that happened when a class has been renamed.
[wxWidgets.git] / contrib / src / applet / prepecho.cpp
1 /****************************************************************************
2 *
3 * wxWindows HTML Applet Package
4 *
5 * Copyright (C) 1991-2001 SciTech Software, Inc.
6 * All rights reserved.
7 *
8 * ========================================================================
9 *
10 * The contents of this file are subject to the wxWindows License
11 * Version 3.0 (the "License"); you may not use this file except in
12 * compliance with the License. You may obtain a copy of the License at
13 * http://www.wxwindows.org/licence3.txt
14 *
15 * Software distributed under the License is distributed on an
16 * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
17 * implied. See the License for the specific language governing
18 * rights and limitations under the License.
19 *
20 * ========================================================================
21 *
22 * Language: ANSI C++
23 * Environment: Any
24 *
25 * Description: This file is the implementation of the Preprocessor object
26 * for parsing the <!--#echo directive
27 *
28 ****************************************************************************/
29
30 // For compilers that support precompilation
31 #include "wx/wxprec.h"
32 #include "wx/html/forcelnk.h"
33
34 // Include private headers
35 #include "wx/applet/prepecho.h"
36 #include "wx/applet/echovar.h"
37
38 /*---------------------------- Global variables ---------------------------*/
39
40
41 /*----------------------------- Implementation ----------------------------*/
42
43 /****************************************************************************
44 PARAMETERS:
45 text - HTML to process for echo directives
46
47 RETURNS:
48 The string containing the processed HTML
49
50 REMARKS:
51 This function replaces #echo directives with a variable retrieved from the
52 class given in the HTML directive. These classes are created by making a sub
53 class of wxEchoVariable. Dynamic class construction is used at run time
54 internally to create an instance of this class and access the value of the
55 variable.
56
57 SEE ALSO:
58 wxEchoVariable
59 ****************************************************************************/
60 wxString wxEchoPrep::Process(
61 const wxString& text) const
62 {
63 int i;
64 char ft[] = "<!--#echo ";
65
66 // make a copy so we can replace text as we go without affecting the original
67 wxString output = text;
68
69 while ((i = (output.Lower()).Find(ft)) != -1) {
70 // Loop until every #echo directive is found
71
72 int n, c, end;
73 wxString cname, parms;
74 wxString tag;
75
76 // grab the tag and remove it from the file
77 end = (output.Mid(i)).Find("-->");
78 if (end == -1) {
79 #ifdef CHECKED
80 wxMessageBox("wxHTML #echo error: Premature end of file while parsing #echo.","Error",wxICON_ERROR);
81 #endif
82 break;
83 }
84
85 end += 3;
86 tag = output.Mid(i, end);
87 output.Remove(i, end);
88
89 n = (tag.Lower()).Find(" parm=");
90 c = tag.Find("-->");
91 if (n == -1) {
92 n = c;
93 // find the classname
94 c = (tag.Mid(10, n-10)).Find(" ");
95 if (c == -1) n -= 10;
96 else n = c;
97 cname = tag.Mid(10, n);
98
99 // grab the value from the class, put it in tag since the data is no longer needed
100 tag = wxEchoVariable::FindValue(cname, NULL);
101 }
102 else {
103 // Find the parms
104 parms = tag.Mid(n+6, c-n-6);
105 // Clip off any quotation marks if they exist. (don't die if there arn't any)
106 c = parms.Find("\"");
107 if (c != -1) parms = parms.Mid(c+1);
108 c = parms.Find("\"");
109 if (c != -1) parms = parms.Mid(0, c);
110 // find the classname
111 c = (tag.Mid(10, n-10)).Find(" ");
112 if (c == -1) n -= 10;
113 else n = c;
114 cname = tag.Mid(10, n);
115
116 // grab the value from the class, put it in tag since the data is no longer needed
117 tag = wxEchoVariable::FindValue(cname, parms.c_str());
118 }
119
120
121 output = (output.Mid(0,i) + tag + output.Mid(i));
122 }
123
124 return output;
125 }
126
127 FORCE_LINK(echovar)
128