]> git.saurik.com Git - wxWidgets.git/blobdiff - src/html/htmltag.cpp
Misc validity fixes to samples/xrc/rc/*.xrc.
[wxWidgets.git] / src / html / htmltag.cpp
index b2af5eff7f1d738cce91a734d9909bc892e6c2f1..d507d5373a48f60e1ac4f0a563ee72b4163d4911 100644 (file)
@@ -2,7 +2,6 @@
 // Name:        src/html/htmltag.cpp
 // Purpose:     wxHtmlTag class (represents single tag)
 // Author:      Vaclav Slavik
-// RCS-ID:      $Id$
 // Copyright:   (c) 1999 Vaclav Slavik
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
@@ -94,12 +93,10 @@ wxHtmlTagsCache::wxHtmlTagsCache(const wxString& source)
         if ( wxHtmlParser::SkipCommentTag(pos, end) )
             continue;
 
-        size_t tg = Cache().size();
-        Cache().push_back(wxHtmlCacheItem());
-
+        // Remember the starting tag position.
         wxString::const_iterator stpos = pos++;
-        Cache()[tg].Key = stpos;
 
+        // And look for the ending one.
         int i;
         for ( i = 0;
               pos < end && i < (int)WXSIZEOF(tagBuffer) - 1 &&
@@ -110,12 +107,26 @@ wxHtmlTagsCache::wxHtmlTagsCache(const wxString& source)
         }
         tagBuffer[i] = wxT('\0');
 
-        Cache()[tg].Name = new wxChar[i+1];
-        memcpy(Cache()[tg].Name, tagBuffer, (i+1)*sizeof(wxChar));
-
         while (pos < end && *pos != wxT('>'))
             ++pos;
 
+        if ( pos == end )
+        {
+            // We didn't find a closing bracket, this is not a valid tag after
+            // all. Notice that we need to roll back pos to avoid creating an
+            // invalid iterator when "++pos" is done in the loop statement.
+            --pos;
+
+            continue;
+        }
+
+        // We have a valid tag, add it to the cache.
+        size_t tg = Cache().size();
+        Cache().push_back(wxHtmlCacheItem());
+        Cache()[tg].Key = stpos;
+        Cache()[tg].Name = new wxChar[i+1];
+        memcpy(Cache()[tg].Name, tagBuffer, (i+1)*sizeof(wxChar));
+
         if ((stpos+1) < end && *(stpos+1) == wxT('/')) // ending tag:
         {
             Cache()[tg].type = wxHtmlCacheItem::Type_EndingTag;
@@ -223,7 +234,12 @@ void wxHtmlTagsCache::QueryTag(const wxString::const_iterator& at,
                                bool *hasEnding)
 {
     if (Cache().empty())
+    {
+        *end1 =
+        *end2 = inputEnd;
+        *hasEnding = true;
         return;
+    }
 
     if (Cache()[m_CachePos].Key != at)
     {
@@ -447,6 +463,7 @@ wxHtmlTag::wxHtmlTag(wxHtmlTag *parent,
         { "width",              "WIDTH"         },
         { "vertical-align",     "VALIGN"        },
         { "background",         "BGCOLOR"       },
+        { "background-color",   "BGCOLOR"       },
     };
 
     wxHtmlStyleParams styleParams(*this);
@@ -494,6 +511,19 @@ wxString wxHtmlTag::GetParam(const wxString& par, bool with_quotes) const
         return m_ParamValues[index];
 }
 
+bool wxHtmlTag::GetParamAsString(const wxString& par, wxString *str) const
+{
+    wxCHECK_MSG( str, false, wxT("NULL output string argument") );
+
+    int index = m_ParamNames.Index(par, false);
+    if (index == wxNOT_FOUND)
+        return false;
+
+    *str = m_ParamValues[index];
+
+    return true;
+}
+
 int wxHtmlTag::ScanParam(const wxString& par,
                          const char *format,
                          void *param) const
@@ -569,6 +599,38 @@ bool wxHtmlTag::GetParamAsInt(const wxString& par, int *clr) const
     return true;
 }
 
+bool
+wxHtmlTag::GetParamAsIntOrPercent(const wxString& par,
+                                  int* value,
+                                  bool& isPercent) const
+{
+    const wxString param = GetParam(par);
+    if ( param.empty() )
+        return false;
+
+    wxString num;
+    if ( param.EndsWith("%", &num) )
+    {
+        isPercent = true;
+    }
+    else
+    {
+        isPercent = false;
+        num = param;
+    }
+
+    long lValue;
+    if ( !num.ToLong(&lValue) )
+        return false;
+
+    if ( lValue > INT_MAX || lValue < INT_MIN )
+        return false;
+
+    *value = static_cast<int>(lValue);
+
+    return true;
+}
+
 wxString wxHtmlTag::GetAllParams() const
 {
     // VS: this function is for backward compatibility only,