]> git.saurik.com Git - wxWidgets.git/blame - src/html/styleparams.cpp
Misc validity fixes to samples/xrc/rc/*.xrc.
[wxWidgets.git] / src / html / styleparams.cpp
CommitLineData
f68e16c5
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/html/styleparams.cpp
3// Purpose: wxHtml helper code for extracting style parameters
4// Author: Nigel Paton
f68e16c5
VZ
5// Copyright: wxWidgets team
6// Licence: wxWindows licence
7/////////////////////////////////////////////////////////////////////////////
8
9#include "wx/wxprec.h"
10#include "wx/tokenzr.h"
11#include "wx/html/htmltag.h"
12#include "wx/html/styleparams.h"
13
14#ifdef __BORLANDC__
15 #pragma hdrstop
16#endif
17
18#if wxUSE_HTML
19
20wxHtmlStyleParams::wxHtmlStyleParams(const wxHtmlTag& tag)
21{
22 wxString wd = tag.GetParam(wxT("STYLE"));
23
24 // Make sure no whitespace
25 wd.Trim(true).Trim(false);
26 if ( wd.empty() )
27 return;
28
29 // Check for bracketed entries
30 // Only support element properties and not pseudo-element or pseudo-classes
31 if (wd.Find('{') == 0)
32 {
33 // Extract string up to end bracket
34 int endBracket = wd.Find('}');
35 if (endBracket != wxNOT_FOUND)
36 {
37 // Replace original string with bracketed options
38 wd = wd.SubString(1, endBracket - 1);
39 // Make sure no whitespace
40 wd.Trim(true).Trim(false);
41 }
42 else
43 {
44 // Syntax problem change to blank string
45 wd = "";
46 }
47 }
48
49 // Should now have a semi-colon delimited list of options
50 // Each option is a name and a value separated by a colon
51 // Split the list into names and values
52 wxStringTokenizer tkz(wd, wxT(";"), wxTOKEN_STRTOK);
53 while ( tkz.HasMoreTokens() )
54 {
55 wxString token = tkz.GetNextToken();
56 // Split into name and value
57 int colonIndex = token.Find(':');
58 if ((colonIndex != wxNOT_FOUND) && // Not a name value pair
59 (colonIndex != 0)) // No name
60 {
61 wxString tempString;
62 // Extract and trim name
63 tempString = token.SubString(0, colonIndex - 1);
64 tempString.Trim(true).Trim(false);
65 // Add to name list
66 m_names.Add(tempString);
67
68 // Extract and trim values
69 tempString = token.SubString(colonIndex + 1, token.Length() - 1);
70 tempString.Trim(true).Trim(false);
71 // Add to values list
72 m_values.Add(tempString);
73 }
74 }
75}
76
77#endif // wxUSE_HTML