]>
git.saurik.com Git - wxWidgets.git/blob - contrib/src/applet/prepecho.cpp
1 /****************************************************************************
3 * wxWindows HTML Applet Package
5 * Copyright (C) 1991-2001 SciTech Software, Inc.
8 * ========================================================================
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
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.
20 * ========================================================================
25 * Description: This file is the implementation of the Preprocessor object
26 * for parsing the <!--#echo directive
28 ****************************************************************************/
30 // For compilers that support precompilation
31 #include "wx/wxprec.h"
32 #include "wx/html/forcelnk.h"
34 // Include private headers
35 #include "wx/applet/prepecho.h"
36 #include "wx/applet/echovar.h"
38 /*---------------------------- Global variables ---------------------------*/
41 /*----------------------------- Implementation ----------------------------*/
43 /****************************************************************************
45 text - HTML to process for echo directives
48 The string containing the processed HTML
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
59 ****************************************************************************/
60 wxString
wxEchoPrep::Process(
61 const wxString
& text
) const
64 char ft
[] = "<!--#echo ";
66 // make a copy so we can replace text as we go without affecting the original
67 wxString output
= text
;
69 while ((i
= (output
.Lower()).Find(ft
)) != -1) {
70 // Loop until every #echo directive is found
73 wxString cname
, parms
;
76 // grab the tag and remove it from the file
77 end
= (output
.Mid(i
)).Find("-->");
80 wxMessageBox("wxHTML #echo error: Premature end of file while parsing #echo.","Error",wxICON_ERROR
);
86 tag
= output
.Mid(i
, end
);
87 output
.Remove(i
, end
);
89 n
= (tag
.Lower()).Find(" parm=");
94 c
= (tag
.Mid(10, n
-10)).Find(" ");
97 cname
= tag
.Mid(10, n
);
99 // grab the value from the class, put it in tag since the data is no longer needed
100 tag
= wxEchoVariable::FindValue(cname
, NULL
);
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;
114 cname
= tag
.Mid(10, n
);
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());
121 // remove ampersands and <> chars
122 tag
.Replace("&", "&");
123 tag
.Replace("<", "<");
124 tag
.Replace(">", ">");
126 output
= (output
.Mid(0,i
) + tag
+ output
.Mid(i
));