X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/71ada1a5fbecf774be6cb7ab7421a8f784d6c84c..3a39df31ff47004a46cfb06f3fb2d3e317f96d2b:/utils/configtool/src/htmlparser.cpp diff --git a/utils/configtool/src/htmlparser.cpp b/utils/configtool/src/htmlparser.cpp index d486caad16..d4d2d7a23f 100644 --- a/utils/configtool/src/htmlparser.cpp +++ b/utils/configtool/src/htmlparser.cpp @@ -16,18 +16,16 @@ #pragma implementation "htmlparser.h" #endif -#include "wx/wx.h" +// For compilers that support precompilation, includes "wx/wx.h". +#include "wx/wxprec.h" #ifdef __BORLANDC__ #pragma hdrstop #endif -#include "wx/textfile.h" #include "wx/wfstream.h" +#include "wx/textfile.h" #include "wx/txtstrm.h" - -#include - #include "htmlparser.h" /// Useful insertion operators for wxOutputStream. @@ -106,7 +104,7 @@ bool wxSimpleHtmlParser::ParseFile(const wxString& filename) return ParseString(text); } else - return FALSE; + return false; } bool wxSimpleHtmlParser::ParseString(const wxString& str) @@ -121,7 +119,7 @@ bool wxSimpleHtmlParser::ParseString(const wxString& str) bool bResult = ParseHtml(m_topLevel); - wxASSERT(bResult); // Failed to parse the TAGs. + wxASSERT(bResult); // Failed to parse the TAGs. // Hint: Check if every open tag has a close tag! return bResult; @@ -131,7 +129,7 @@ bool wxSimpleHtmlParser::ParseString(const wxString& str) bool wxSimpleHtmlParser::ParseHtml(wxSimpleHtmlTag* parent) { if (!parent) - return FALSE; + return false; while (!Eof()) { @@ -160,13 +158,13 @@ bool wxSimpleHtmlParser::ParseHtml(wxSimpleHtmlTag* parent) if (IsCloseTagNeeded(tag->GetName())) { if (!parent->GetParent()) - return FALSE; + return false; parent->GetParent()->AppendTag(tag); - return TRUE; + return true; } else parent->AppendTag(tag); - } + } } else if (IsTagStartBracket(GetChar(m_pos))) { @@ -177,7 +175,7 @@ bool wxSimpleHtmlParser::ParseHtml(wxSimpleHtmlTag* parent) if (IsCloseTagNeeded(tag->GetName())) { if (!ParseHtml(tag)) - return FALSE; // Something didn't go ok, so don't continue. + return false; // Something didn't go ok, so don't continue. } } else @@ -191,11 +189,11 @@ bool wxSimpleHtmlParser::ParseHtml(wxSimpleHtmlTag* parent) if(parent->GetParent()) parent->GetParent()->AppendTag(tag); else - parent->AppendTag(tag); // When this occurs it is probably the + parent->AppendTag(tag); // When this occurs it is probably the // empty lines at the end of the file... } } - return TRUE; + return true; } // Plain text, up until an angled bracket @@ -203,11 +201,11 @@ bool wxSimpleHtmlParser::ParseText(wxString& text) { while (!Eof() && GetChar(m_pos) != wxT('<')) { - text += GetChar(m_pos); + text += (wxChar)GetChar(m_pos); m_pos ++; } DecodeSpecialChars(text); - return TRUE; + return true; } wxSimpleHtmlTag* wxSimpleHtmlParser::ParseTagHeader() @@ -218,7 +216,7 @@ wxSimpleHtmlTag* wxSimpleHtmlParser::ParseTagHeader() EatWhitespace(); wxString word; - ReadWord(word, TRUE); + ReadWord(word, true); EatWhitespace(); @@ -239,12 +237,12 @@ wxSimpleHtmlTag* wxSimpleHtmlParser::ParseTagHeader() wxSimpleHtmlTag* wxSimpleHtmlParser::ParseTagClose() { - Matches(wxT("AppendAttribute(attrName, wxEmptyString); } else if (IsNumeric(GetChar(m_pos))) { - ReadNumber(attrName, TRUE); + ReadNumber(attrName, true); tag->AppendAttribute(attrName, wxEmptyString); } else { // Try to read an attribute name/value pair, or at least a name // without the value - ReadLiteral(attrName, TRUE); + ReadLiteral(attrName, true); EatWhitespace(); if (GetChar(m_pos) == wxT('=')) @@ -285,26 +283,26 @@ bool wxSimpleHtmlParser::ParseAttributes(wxSimpleHtmlTag* tag) EatWhitespace(); if (IsString()) - ReadString(attrValue, TRUE); + ReadString(attrValue, true); else if (!Eof() && !IsTagEndBracket(GetChar(m_pos))) - ReadLiteral(attrValue, TRUE); + ReadLiteral(attrValue, true); } if (!attrName.IsEmpty()) tag->AppendAttribute(attrName, attrValue); } } - return TRUE; + return true; } // e.g. wxSimpleHtmlTag* wxSimpleHtmlParser::ParseDirective() { - Matches(wxT(" wxSimpleHtmlTag* wxSimpleHtmlParser::ParseXMLDeclaration() { - Matches(wxT(""), TRUE)) + while (!Eof() && !Matches(wxT("-->"), true)) { m_pos ++; } - return TRUE; + return true; } bool wxSimpleHtmlParser::EatWhitespace() { while (!Eof() && IsWhitespace(GetChar(m_pos))) m_pos ++; - return TRUE; + return true; } bool wxSimpleHtmlParser::EatWhitespace(int& pos) { while (!Eof(pos) && IsWhitespace(GetChar(pos))) pos ++; - return TRUE; + return true; } bool wxSimpleHtmlParser::ReadString(wxString& str, bool eatIt) @@ -388,10 +386,10 @@ bool wxSimpleHtmlParser::ReadString(wxString& str, bool eatIt) if (eatIt) m_pos = pos; DecodeSpecialChars(str); - return TRUE; + return true; } else - return FALSE; + return false; } bool wxSimpleHtmlParser::ReadWord(wxString& str, bool eatIt) @@ -399,7 +397,7 @@ bool wxSimpleHtmlParser::ReadWord(wxString& str, bool eatIt) int pos = m_pos; if (!IsAlpha(GetChar(pos))) - return FALSE; + return false; str += (wxChar) GetChar(pos) ; pos ++; @@ -412,7 +410,7 @@ bool wxSimpleHtmlParser::ReadWord(wxString& str, bool eatIt) if (eatIt) m_pos = pos; DecodeSpecialChars(str); - return TRUE; + return true; } bool wxSimpleHtmlParser::ReadNumber(wxString& str, bool eatIt) @@ -420,7 +418,7 @@ bool wxSimpleHtmlParser::ReadNumber(wxString& str, bool eatIt) int pos = m_pos; if (!IsNumeric(GetChar(pos))) - return FALSE; + return false; str += (wxChar) GetChar(pos) ; pos ++; @@ -433,7 +431,7 @@ bool wxSimpleHtmlParser::ReadNumber(wxString& str, bool eatIt) if (eatIt) m_pos = pos; DecodeSpecialChars(str); - return TRUE; + return true; } // Could be number, string, whatever, but read up until whitespace or end of tag (but not a quoted string) @@ -443,13 +441,13 @@ bool wxSimpleHtmlParser::ReadLiteral(wxString& str, bool eatIt) while (!Eof(pos) && !IsWhitespace(GetChar(pos)) && !IsTagEndBracket(GetChar(pos)) && GetChar(pos) != wxT('=')) { - str += GetChar(pos); + str += (wxChar)GetChar(pos); pos ++; } if (eatIt) m_pos = pos; DecodeSpecialChars(str); - return TRUE; + return true; } bool wxSimpleHtmlParser::IsComment() @@ -514,37 +512,37 @@ bool wxSimpleHtmlParser::IsNumeric(int ch) bool wxSimpleHtmlParser::IsCloseTagNeeded(const wxString &name) { - if (name.IsSameAs(wxT("P"), FALSE)) // e.g

- return FALSE; + if (name.IsSameAs(wxT("P"), false)) // e.g

+ return false; // ToDo add more items here. - return TRUE; + return true; } // Encode/Decode Special Characters. // See here for the used table: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsql/ac_xml1_1nqk.asp /* static */ void wxSimpleHtmlParser::DecodeSpecialChars(wxString &value) { - // XML translation - value.Replace(wxT(">"), wxT(">"), TRUE); - value.Replace(wxT("<"), wxT("<"), TRUE); - value.Replace(wxT("""), wxT("\""), TRUE); - value.Replace(wxT("'"), wxT("'"), TRUE); - value.Replace(wxT("&"), wxT("&"), TRUE); // Note: do this as last to prevent replace problems. + // XML translation + value.Replace(wxT(">"), wxT(">"), true); + value.Replace(wxT("<"), wxT("<"), true); + value.Replace(wxT("""), wxT("\""), true); + value.Replace(wxT("'"), wxT("'"), true); + value.Replace(wxT("&"), wxT("&"), true); // Note: do this as last to prevent replace problems. } /* static */ wxString wxSimpleHtmlParser::EncodeSpecialChars(const wxString &value) { wxString newvalue = value; - // XML translation - newvalue.Replace(wxT("&"), wxT("&"), TRUE); // Note: do this as first to prevent replace problems. - newvalue.Replace(wxT(">"), wxT(">"), TRUE); - newvalue.Replace(wxT("<"), wxT("<"), TRUE); - newvalue.Replace(wxT("\""),wxT("""), TRUE); - newvalue.Replace(wxT("'"), wxT("'"), TRUE); - + // XML translation + newvalue.Replace(wxT("&"), wxT("&"), true); // Note: do this as first to prevent replace problems. + newvalue.Replace(wxT(">"), wxT(">"), true); + newvalue.Replace(wxT("<"), wxT("<"), true); + newvalue.Replace(wxT("\""),wxT("""), true); + newvalue.Replace(wxT("'"), wxT("'"), true); + return newvalue; } @@ -591,10 +589,10 @@ bool wxSimpleHtmlParser::WriteFile(wxString& filename) if (fstream.Ok()) { Write(fstream); - return TRUE; + return true; } else - return FALSE; + return false; } /* @@ -697,7 +695,7 @@ void wxSimpleHtmlTag::RemoveChild(wxSimpleHtmlTag *remove) { child->m_next = NULL; delete child; - + if (prev != NULL) prev->m_next = next; else @@ -723,7 +721,7 @@ void wxSimpleHtmlTag::AppendTag(wxSimpleHtmlTag* tag) while (last->m_next) last = last->m_next; - last->m_next = tag; + last->m_next = tag; } else { @@ -819,13 +817,13 @@ bool wxSimpleHtmlTag::GetAttributeValue(wxString& value, const wxString& attrNam if (attr) { value = attr->GetValue(); - return TRUE; + return true; } else - return FALSE; + return false; } -// Search forward from this tag until we find a tag with this name & attribute +// Search forward from this tag until we find a tag with this name & attribute wxSimpleHtmlTag* wxSimpleHtmlTag::FindTag(const wxString& tagName, const wxString& attrName) { wxSimpleHtmlTag* tag = m_next; @@ -845,14 +843,14 @@ bool wxSimpleHtmlTag::FindTextUntilTagClose(wxString& text, const wxString& tagN while (tag) { if (tag->GetType() == wxSimpleHtmlTag_Close && tag->NameIs(tagName)) - return TRUE; + return true; if (tag->GetType() == wxSimpleHtmlTag_Text) text += tag->GetText(); tag = tag->m_next; } - return TRUE; + return true; } @@ -874,7 +872,7 @@ wxSimpleHtmlTag* wxSimpleHtmlTag::GetChild(int i) const void wxSimpleHtmlTag::Write(wxOutputStream& stream) { // Some helpers to layout the open and close tags. - static bool sbUseTab = TRUE; + static bool sbUseTab = true; static size_t snTabLevel = 0; #if 0 // Enable if no tabs should be used to align the tags. @@ -904,16 +902,16 @@ void wxSimpleHtmlTag::Write(wxOutputStream& stream) attr->Write(stream); if (i < GetAttributeCount() - 1) stream << wxT(" "); - } + } if(!m_children) { - sbUseTab = FALSE; // We're putting the open a close tag on the same line, + sbUseTab = false; // We're putting the open a close tag on the same line, // so we don't wan't any tabs stream << wxT(">"); } else { - // sbUseTab = TRUE; + // sbUseTab = true; stream << wxT(">\n"); } snTabLevel++; @@ -958,7 +956,7 @@ void wxSimpleHtmlTag::Write(wxOutputStream& stream) stream << wxT("\t"); } stream << wxT("\n"); - sbUseTab = TRUE; + sbUseTab = true; break; } default: