]>
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 // Include private headers
31 #include "wx/applet/prepecho.h"
32 #include "wx/applet/echovar.h"
35 #include "wx/html/forcelnk.h"
38 #include "wx/msgdlg.h"
40 /*----------------------------- Implementation ----------------------------*/
42 /****************************************************************************
44 text - HTML to process for echo directives
47 The string containing the processed HTML
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
58 ****************************************************************************/
59 wxString
wxEchoPrep::Process(
60 const wxString
& text
) const
63 char ft
[] = "<!--#echo ";
65 // make a copy so we can replace text as we go without affecting the original
66 wxString output
= text
;
68 while ((i
= (output
.Lower()).Find(ft
)) != -1) {
69 // Loop until every #echo directive is found
71 wxString cname
, parms
;
74 // grab the tag and remove it from the file
75 end
= (output
.Mid(i
)).Find("-->");
78 wxMessageBox("wxHTML #echo error: Premature end of file while parsing #echo.","Error",wxICON_ERROR
);
84 tag
= output
.Mid(i
, end
);
85 output
.Remove(i
, end
);
87 n
= (tag
.Lower()).Find(" parm=");
92 c
= (tag
.Mid(10, n
-10)).Find(" ");
95 cname
= tag
.Mid(10, n
);
97 // grab the value from the class, put it in tag since the data is no longer needed
98 tag
= wxEchoVariable::GetValue(cname
, NULL
);
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;
112 cname
= tag
.Mid(10, n
);
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());
117 // remove ampersands and <> chars
118 tag
.Replace("&", "&");
119 tag
.Replace("<", "<");
120 tag
.Replace(">", ">");
122 output
= (output
.Mid(0,i
) + tag
+ output
.Mid(i
));