#endif
}
-wxString wxHtmlEntitiesParser::Parse(const wxString& input)
+wxString wxHtmlEntitiesParser::Parse(const wxString& input) const
{
- const wxChar *c, *last;
- const wxChar *in_str = input.c_str();
wxString output;
- output.reserve(input.length());
+ const wxString::const_iterator end(input.end());
+ wxString::const_iterator c(input.begin());
+ wxString::const_iterator last(c);
- for (c = in_str, last = in_str; *c != wxT('\0'); c++)
+ for ( ; c < end; ++c )
{
if (*c == wxT('&'))
{
+ if ( output.empty() )
+ output.reserve(input.length());
+
if (c - last > 0)
- output.append(last, c - last);
- if ( *++c == wxT('\0') )
+ output.append(last, c);
+ if ( ++c == end )
break;
wxString entity;
- const wxChar *ent_s = c;
+ const wxString::const_iterator ent_s = c;
wxChar entity_char;
- for (; (*c >= wxT('a') && *c <= wxT('z')) ||
- (*c >= wxT('A') && *c <= wxT('Z')) ||
- (*c >= wxT('0') && *c <= wxT('9')) ||
- *c == wxT('_') || *c == wxT('#'); c++) {}
- entity.append(ent_s, c - ent_s);
- if (*c != wxT(';')) c--;
+ for (; c != end &&
+ ((*c >= wxT('a') && *c <= wxT('z')) ||
+ (*c >= wxT('A') && *c <= wxT('Z')) ||
+ (*c >= wxT('0') && *c <= wxT('9')) ||
+ *c == wxT('_') || *c == wxT('#')); ++c) {}
+ entity.append(ent_s, c);
+ if (c == end || *c != wxT(';')) --c;
last = c+1;
entity_char = GetEntityChar(entity);
if (entity_char)
output << entity_char;
else
{
- output.append(ent_s-1, c-ent_s+2);
+ output.append(ent_s-1, c+1);
wxLogTrace(wxTRACE_HTML_DEBUG,
- wxT("Unrecognized HTML entity: '%s'"),
- entity.c_str());
+ "Unrecognized HTML entity: '%s'",
+ entity);
}
}
}
- if (*last != wxT('\0'))
- output.append(last);
+ if ( last == input.begin() ) // common case: no entity
+ return input;
+ if ( last != end )
+ output.append(last, end);
return output;
}
#if !wxUSE_UNICODE
-wxChar wxHtmlEntitiesParser::GetCharForCode(unsigned code)
+wxChar wxHtmlEntitiesParser::GetCharForCode(unsigned code) const
{
#if wxUSE_WCHAR_T
char buf[2];
#endif
}
-wxChar wxHtmlEntitiesParser::GetEntityChar(const wxString& entity)
+wxChar wxHtmlEntitiesParser::GetEntityChar(const wxString& entity) const
{
unsigned code = 0;
if (entity[0] == wxT('#'))
{
- const wxChar *ent_s = entity.c_str();
- const wxChar *format;
+ // NB: parsed value is a number, so it's OK to use wx_str(), internal
+ // representation is the same for numbers
+ const wxStringCharType *ent_s = entity.wx_str();
+ const wxStringCharType *format;
- if (ent_s[1] == wxT('x') || ent_s[1] == wxT('X'))
+ if (ent_s[1] == wxSTRING_TEXT('x') || ent_s[1] == wxSTRING_TEXT('X'))
{
- format = wxT("%x");
+ format = wxSTRING_TEXT("%x");
ent_s++;
}
else
- format = wxT("%u");
+ format = wxSTRING_TEXT("%u");
ent_s++;
if (wxSscanf(ent_s, format, &code) != 1)
wxObject* GetProduct() { return NULL; }
protected:
- virtual void AddText(const wxChar* WXUNUSED(txt)) {}
+ virtual void AddText(const wxString& WXUNUSED(txt)) {}
DECLARE_NO_COPY_CLASS(wxMetaTagParser)
};
wxString::const_iterator p = start;
// comments begin with "<!--" in HTML 4.0
- if ( end - p < 3 || *++p != '!' || *++p != '-' || *++p != '-' )
+ if ( p > end - 3 || *++p != '!' || *++p != '-' || *++p != '-' )
{
// not a comment at all
return false;