]> git.saurik.com Git - wxWidgets.git/blob - contrib/src/applet/prepecho.cpp
corrected assert even better
[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 // Include private headers
31 #include "wx/applet/prepecho.h"
32 #include "wx/applet/echovar.h"
33
34 // Force Link macro
35 #include "wx/html/forcelnk.h"
36
37 // wxWindows headers
38 #include "wx/msgdlg.h"
39
40 /*----------------------------- Implementation ----------------------------*/
41
42 /****************************************************************************
43 PARAMETERS:
44 text - HTML to process for echo directives
45
46 RETURNS:
47 The string containing the processed HTML
48
49 REMARKS:
50 This function replaces #echo directives with a variable retrieved from the
51 class given in the HTML directive. These classes are created by making a sub
52 class of wxEchoVariable. Dynamic class construction is used at run time
53 internally to create an instance of this class and access the value of the
54 variable.
55
56 SEE ALSO:
57 wxEchoVariable
58 ****************************************************************************/
59 wxString wxEchoPrep::Process(
60 const wxString& text) const
61 {
62 int i;
63 char ft[] = "<!--#echo ";
64
65 // make a copy so we can replace text as we go without affecting the original
66 wxString output = text;
67
68 while ((i = (output.Lower()).Find(ft)) != -1) {
69 // Loop until every #echo directive is found
70 int n, c, end;
71 wxString cname, parms;
72 wxString tag;
73
74 // grab the tag and remove it from the file
75 end = (output.Mid(i)).Find("-->");
76 if (end == -1) {
77 #ifdef CHECKED
78 wxMessageBox("wxHTML #echo error: Premature end of file while parsing #echo.","Error",wxICON_ERROR);
79 #endif
80 break;
81 }
82
83 end += 3;
84 tag = output.Mid(i, end);
85 output.Remove(i, end);
86
87 n = (tag.Lower()).Find(" parm=");
88 c = tag.Find("-->");
89 if (n == -1) {
90 n = c;
91 // find the classname
92 c = (tag.Mid(10, n-10)).Find(" ");
93 if (c == -1) n -= 10;
94 else n = c;
95 cname = tag.Mid(10, n);
96
97 // grab the value from the class, put it in tag since the data is no longer needed
98 tag = wxEchoVariable::GetValue(cname, NULL);
99 }
100 else {
101 // Find the parms
102 parms = tag.Mid(n+6, c-n-6);
103 // Clip off any quotation marks if they exist. (don't die if there arn't any)
104 c = parms.Find("\"");
105 if (c != -1) parms = parms.Mid(c+1);
106 c = parms.Find("\"");
107 if (c != -1) parms = parms.Mid(0, c);
108 // find the classname
109 c = (tag.Mid(10, n-10)).Find(" ");
110 if (c == -1) n -= 10;
111 else n = c;
112 cname = tag.Mid(10, n);
113
114 // grab the value from the class, put it in tag since the data is no longer needed
115 tag = wxEchoVariable::GetValue(cname, parms.c_str());
116 }
117 // remove ampersands and <> chars
118 tag.Replace("&", "&amp;");
119 tag.Replace("<", "&lt;");
120 tag.Replace(">", "&gt;");
121
122 output = (output.Mid(0,i) + tag + output.Mid(i));
123 }
124 return output;
125 }
126
127 FORCE_LINK(echovar)
128