summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
4f33a4d)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@48390
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
// Parses the m_Source from begin_pos to end_pos-1.
// (in noparams version it parses whole m_Source)
// Parses the m_Source from begin_pos to end_pos-1.
// (in noparams version it parses whole m_Source)
- void DoParsing(int begin_pos, int end_pos);
+ void DoParsing(const wxString::const_iterator& begin_pos,
+ const wxString::const_iterator& end_pos);
void DoParsing();
// Returns pointer to the tag at parser's current position
void DoParsing();
// Returns pointer to the tag at parser's current position
// Restores state before last call to PushTagHandler
void PopTagHandler();
// Restores state before last call to PushTagHandler
void PopTagHandler();
- wxString* GetSource() {return &m_Source;}
+ const wxString* GetSource() {return m_Source;}
void SetSource(const wxString& src);
// Sets HTML source and remembers current parser's state so that it can
void SetSource(const wxString& src);
// Sets HTML source and remembers current parser's state so that it can
void CreateDOMTree();
void DestroyDOMTree();
void CreateDOMSubTree(wxHtmlTag *cur,
void CreateDOMTree();
void DestroyDOMTree();
void CreateDOMSubTree(wxHtmlTag *cur,
- int begin_pos, int end_pos,
+ const wxString::const_iterator& begin_pos,
+ const wxString::const_iterator& end_pos,
wxHtmlTagsCache *cache);
// Adds text to the output.
wxHtmlTagsCache *cache);
// Adds text to the output.
wxHtmlTextPieces *m_TextPieces;
size_t m_CurTextPiece;
wxHtmlTextPieces *m_TextPieces;
size_t m_CurTextPiece;
+ const wxString *m_Source;
wxHtmlParserState *m_SavedStates;
wxHtmlParserState *m_SavedStates;
// parses input between beginning and ending tag.
// m_Parser must be set.
void ParseInner(const wxHtmlTag& tag)
// parses input between beginning and ending tag.
// m_Parser must be set.
void ParseInner(const wxHtmlTag& tag)
- { m_Parser->DoParsing(tag.GetBeginPos(), tag.GetEndPos1()); }
+ { m_Parser->DoParsing(tag.GetBeginIter(), tag.GetEndIter1()); }
// Parses given source as if it was tag's inner code (see
// wxHtmlParser::GetInnerSource). Unlike ParseInner(), this method lets
// Parses given source as if it was tag's inner code (see
// wxHtmlParser::GetInnerSource). Unlike ParseInner(), this method lets
{
private:
wxHtmlTagsCacheData *m_Cache;
{
private:
wxHtmlTagsCacheData *m_Cache;
wxHtmlTagsCacheData& Cache() { return *m_Cache; }
wxHtmlTagsCacheData& Cache() { return *m_Cache; }
virtual ~wxHtmlTagsCache();
// Finds parameters for tag starting at at and fills the variables
virtual ~wxHtmlTagsCache();
// Finds parameters for tag starting at at and fills the variables
- void QueryTag(int at, int* end1, int* end2);
+ void QueryTag(const wxString::const_iterator& at,
+ const wxString::const_iterator& inputEnd,
+ wxString::const_iterator *end1,
+ wxString::const_iterator *end2,
+ bool *hasEnding);
DECLARE_NO_COPY_CLASS(wxHtmlTagsCache)
};
DECLARE_NO_COPY_CLASS(wxHtmlTagsCache)
};
// The tag begins (with '<' character) at position pos in source
// end_pos is position where parsing ends (usually end of document)
wxHtmlTag(wxHtmlTag *parent,
// The tag begins (with '<' character) at position pos in source
// end_pos is position where parsing ends (usually end of document)
wxHtmlTag(wxHtmlTag *parent,
- const wxString& source, int pos, int end_pos,
+ const wxString *source,
+ const wxString::const_iterator& pos,
+ const wxString::const_iterator& end_pos,
wxHtmlTagsCache *cache,
wxHtmlEntitiesParser *entParser);
friend class wxHtmlParser;
wxHtmlTagsCache *cache,
wxHtmlEntitiesParser *entParser);
friend class wxHtmlParser;
// Returns string containing all params.
wxString GetAllParams() const;
// Returns string containing all params.
wxString GetAllParams() const;
- // return true if this there is matching ending tag
- inline bool HasEnding() const {return m_End1 >= 0;}
+ // return true if there is matching ending tag
+ inline bool HasEnding() const {return m_hasEnding;}
// returns beginning position of _internal_ block of text
// See explanation (returned value is marked with *):
// bla bla bla <MYTAG>* bla bla intenal text</MYTAG> bla bla
// returns beginning position of _internal_ block of text
// See explanation (returned value is marked with *):
// bla bla bla <MYTAG>* bla bla intenal text</MYTAG> bla bla
- inline int GetBeginPos() const {return m_Begin;}
+ wxString::const_iterator GetBeginIter() const
+ { return m_Begin; }
// returns ending position of _internal_ block of text.
// bla bla bla <MYTAG> bla bla intenal text*</MYTAG> bla bla
// returns ending position of _internal_ block of text.
// bla bla bla <MYTAG> bla bla intenal text*</MYTAG> bla bla
- inline int GetEndPos1() const {return m_End1;}
+ wxString::const_iterator GetEndIter1() const
+ { wxASSERT(m_hasEnding); return m_End1; }
// returns end position 2 :
// bla bla bla <MYTAG> bla bla internal text</MYTAG>* bla bla
// returns end position 2 :
// bla bla bla <MYTAG> bla bla internal text</MYTAG>* bla bla
- inline int GetEndPos2() const {return m_End2;}
+ wxString::const_iterator GetEndIter2() const
+ { wxASSERT(m_hasEnding); return m_End2; }
+
+#if WXWIN_COMPATIBILITY_2_8
+ wxDEPRECATED( inline int GetBeginPos() const );
+ wxDEPRECATED( inline int GetEndPos1() const );
+ wxDEPRECATED( inline int GetEndPos2() const );
+#endif // WXWIN_COMPATIBILITY_2_8
private:
wxString m_Name;
private:
wxString m_Name;
- int m_Begin, m_End1, m_End2;
+ bool m_hasEnding;
+ wxString::const_iterator m_Begin, m_End1, m_End2;
wxArrayString m_ParamNames, m_ParamValues;
wxArrayString m_ParamNames, m_ParamValues;
+#if WXWIN_COMPATIBILITY_2_8
+ wxString::const_iterator m_sourceStart;
+#endif
// DOM tree relations:
wxHtmlTag *m_Next;
// DOM tree relations:
wxHtmlTag *m_Next;
+#if WXWIN_COMPATIBILITY_2_8
+inline int wxHtmlTag::GetBeginPos() const { return m_Begin - m_sourceStart; }
+inline int wxHtmlTag::GetEndPos1() const { return m_End1 - m_sourceStart; }
+inline int wxHtmlTag::GetEndPos2() const { return m_End2 - m_sourceStart; }
+#endif // WXWIN_COMPATIBILITY_2_8
{
public:
wxHtmlTextPiece() {}
{
public:
wxHtmlTextPiece() {}
- wxHtmlTextPiece(int pos, int lng) : m_pos(pos), m_lng(lng) {}
- int m_pos, m_lng;
+ wxHtmlTextPiece(const wxString::const_iterator& start,
+ const wxString::const_iterator& end)
+ : m_start(start), m_end(end) {}
+ wxString::const_iterator m_start, m_end;
};
// NB: this is an empty class and not typedef because of forward declaration
};
// NB: this is an empty class and not typedef because of forward declaration
wxHtmlTag *m_tags;
wxHtmlTextPieces *m_textPieces;
int m_curTextPiece;
wxHtmlTag *m_tags;
wxHtmlTextPieces *m_textPieces;
int m_curTextPiece;
+ const wxString *m_source;
wxHtmlParserState *m_nextState;
};
wxHtmlParserState *m_nextState;
};
: wxObject(), m_HandlersHash(wxKEY_STRING),
m_FS(NULL), m_HandlersStack(NULL)
{
: wxObject(), m_HandlersHash(wxKEY_STRING),
m_FS(NULL), m_HandlersStack(NULL)
{
m_entitiesParser = new wxHtmlEntitiesParser;
m_Tags = NULL;
m_CurTag = NULL;
m_entitiesParser = new wxHtmlEntitiesParser;
m_Tags = NULL;
m_CurTag = NULL;
m_HandlersHash.Clear();
WX_CLEAR_LIST(wxList, m_HandlersList);
delete m_entitiesParser;
m_HandlersHash.Clear();
WX_CLEAR_LIST(wxList, m_HandlersList);
delete m_entitiesParser;
}
wxObject* wxHtmlParser::Parse(const wxString& source)
}
wxObject* wxHtmlParser::Parse(const wxString& source)
void wxHtmlParser::SetSource(const wxString& src)
{
DestroyDOMTree();
void wxHtmlParser::SetSource(const wxString& src)
{
DestroyDOMTree();
+ // NB: this is allocated on heap because wxHtmlTag keeps a pointer to
+ // this string if WXWIN_COMPATIBILITY_2_8
+ delete m_Source;
+ m_Source = new wxString(src);
CreateDOMTree();
m_CurTag = NULL;
m_CurTextPiece = 0;
CreateDOMTree();
m_CurTag = NULL;
m_CurTextPiece = 0;
void wxHtmlParser::CreateDOMTree()
{
void wxHtmlParser::CreateDOMTree()
{
- wxHtmlTagsCache cache(m_Source);
+ wxHtmlTagsCache cache(*m_Source);
m_TextPieces = new wxHtmlTextPieces;
m_TextPieces = new wxHtmlTextPieces;
- CreateDOMSubTree(NULL, 0, m_Source.length(), &cache);
+ CreateDOMSubTree(NULL, m_Source->begin(), m_Source->end(), &cache);
-extern bool wxIsCDATAElement(const wxChar *tag);
+extern bool wxIsCDATAElement(const wxString& tag);
void wxHtmlParser::CreateDOMSubTree(wxHtmlTag *cur,
void wxHtmlParser::CreateDOMSubTree(wxHtmlTag *cur,
- int begin_pos, int end_pos,
+ const wxString::const_iterator& begin_pos,
+ const wxString::const_iterator& end_pos,
wxHtmlTagsCache *cache)
{
wxHtmlTagsCache *cache)
{
- if (end_pos <= begin_pos) return;
+ if (end_pos <= begin_pos)
+ return;
- int i = begin_pos;
- int textBeginning = begin_pos;
+ wxString::const_iterator i = begin_pos;
+ wxString::const_iterator textBeginning = begin_pos;
// If the tag contains CDATA text, we include the text between beginning
// and ending tag verbosely. Setting i=end_pos will skip to the very
// end of this function where text piece is added, bypassing any child
// tags parsing (CDATA element can't have child elements by definition):
// If the tag contains CDATA text, we include the text between beginning
// and ending tag verbosely. Setting i=end_pos will skip to the very
// end of this function where text piece is added, bypassing any child
// tags parsing (CDATA element can't have child elements by definition):
- if (cur != NULL && wxIsCDATAElement(cur->GetName().c_str()))
+ if (cur != NULL && wxIsCDATAElement(cur->GetName()))
{
i = end_pos;
}
while (i < end_pos)
{
{
i = end_pos;
}
while (i < end_pos)
{
- c = m_Source.GetChar(i);
if (c == wxT('<'))
{
// add text to m_TextPieces:
if (c == wxT('<'))
{
// add text to m_TextPieces:
- if (i - textBeginning > 0)
- m_TextPieces->push_back(
- wxHtmlTextPiece(textBeginning, i - textBeginning));
+ if (i > textBeginning)
+ m_TextPieces->push_back(wxHtmlTextPiece(textBeginning, i));
// if it is a comment, skip it:
// if it is a comment, skip it:
- wxString::const_iterator iter = m_Source.begin() + i;
- if ( SkipCommentTag(iter, m_Source.end()) )
+ if ( SkipCommentTag(i, m_Source->end()) )
- textBeginning =
- i = iter - m_Source.begin() + 1; // skip closing '>' too
+ textBeginning = i = i + 1; // skip closing '>' too
}
// add another tag to the tree:
}
// add another tag to the tree:
- else if (i < end_pos-1 && m_Source.GetChar(i+1) != wxT('/'))
+ else if (i < end_pos-1 && *(i+1) != wxT('/'))
{
wxHtmlTag *chd;
if (cur)
{
wxHtmlTag *chd;
if (cur)
if (chd->HasEnding())
{
CreateDOMSubTree(chd,
if (chd->HasEnding())
{
CreateDOMSubTree(chd,
- chd->GetBeginPos(), chd->GetEndPos1(),
+ chd->GetBeginIter(), chd->GetEndIter1(),
+ i = chd->GetEndIter2();
- i = chd->GetBeginPos();
+ i = chd->GetBeginIter();
// ... or skip ending tag:
else
{
// ... or skip ending tag:
else
{
- while (i < end_pos && m_Source.GetChar(i) != wxT('>')) i++;
+ while (i < end_pos && *i != wxT('>')) ++i;
}
// add remaining text to m_TextPieces:
}
// add remaining text to m_TextPieces:
- if (end_pos - textBeginning > 0)
- m_TextPieces->push_back(
- wxHtmlTextPiece(textBeginning, end_pos - textBeginning));
+ if (end_pos > textBeginning)
+ m_TextPieces->push_back(wxHtmlTextPiece(textBeginning, end_pos));
}
void wxHtmlParser::DestroyDOMTree()
}
void wxHtmlParser::DestroyDOMTree()
{
m_CurTag = m_Tags;
m_CurTextPiece = 0;
{
m_CurTag = m_Tags;
m_CurTextPiece = 0;
- DoParsing(0, m_Source.length());
+ DoParsing(m_Source->begin(), m_Source->end());
-void wxHtmlParser::DoParsing(int begin_pos, int end_pos)
+void wxHtmlParser::DoParsing(const wxString::const_iterator& begin_pos_,
+ const wxString::const_iterator& end_pos)
- if (end_pos <= begin_pos) return;
+ wxString::const_iterator begin_pos(begin_pos_);
+
+ if (end_pos <= begin_pos)
+ return;
wxHtmlTextPieces& pieces = *m_TextPieces;
size_t piecesCnt = pieces.size();
while (begin_pos < end_pos)
{
wxHtmlTextPieces& pieces = *m_TextPieces;
size_t piecesCnt = pieces.size();
while (begin_pos < end_pos)
{
- while (m_CurTag && m_CurTag->GetBeginPos() < begin_pos)
+ while (m_CurTag && m_CurTag->GetBeginIter() < begin_pos)
m_CurTag = m_CurTag->GetNextTag();
while (m_CurTextPiece < piecesCnt &&
m_CurTag = m_CurTag->GetNextTag();
while (m_CurTextPiece < piecesCnt &&
- pieces[m_CurTextPiece].m_pos < begin_pos)
+ pieces[m_CurTextPiece].m_start < begin_pos)
m_CurTextPiece++;
if (m_CurTextPiece < piecesCnt &&
(!m_CurTag ||
m_CurTextPiece++;
if (m_CurTextPiece < piecesCnt &&
(!m_CurTag ||
- pieces[m_CurTextPiece].m_pos < m_CurTag->GetBeginPos()))
+ pieces[m_CurTextPiece].m_start < m_CurTag->GetBeginIter()))
{
// Add text:
AddText(GetEntitiesParser()->Parse(
{
// Add text:
AddText(GetEntitiesParser()->Parse(
- m_Source.Mid(pieces[m_CurTextPiece].m_pos,
- pieces[m_CurTextPiece].m_lng)));
- begin_pos = pieces[m_CurTextPiece].m_pos +
- pieces[m_CurTextPiece].m_lng;
+ wxString(pieces[m_CurTextPiece].m_start,
+ pieces[m_CurTextPiece].m_end)));
+ begin_pos = pieces[m_CurTextPiece].m_end;
m_CurTextPiece++;
}
else if (m_CurTag)
{
if (m_CurTag->HasEnding())
m_CurTextPiece++;
}
else if (m_CurTag)
{
if (m_CurTag->HasEnding())
- begin_pos = m_CurTag->GetEndPos2();
+ begin_pos = m_CurTag->GetEndIter2();
- begin_pos = m_CurTag->GetBeginPos();
+ begin_pos = m_CurTag->GetBeginIter();
wxHtmlTag *t = m_CurTag;
m_CurTag = m_CurTag->GetNextTag();
AddTag(*t);
wxHtmlTag *t = m_CurTag;
m_CurTag = m_CurTag->GetNextTag();
AddTag(*t);
if (!inner)
{
if (tag.HasEnding())
if (!inner)
{
if (tag.HasEnding())
- DoParsing(tag.GetBeginPos(), tag.GetEndPos1());
+ DoParsing(tag.GetBeginIter(), tag.GetEndIter1());
m_Tags = NULL;
m_TextPieces = NULL;
m_CurTextPiece = 0;
m_Tags = NULL;
m_TextPieces = NULL;
m_CurTextPiece = 0;
- m_Source = wxEmptyString;
wxString wxHtmlParser::GetInnerSource(const wxHtmlTag& tag)
{
wxString wxHtmlParser::GetInnerSource(const wxHtmlTag& tag)
{
- return GetSource()->Mid(tag.GetBeginPos(),
- tag.GetEndPos1() - tag.GetBeginPos());
+ return wxString(tag.GetBeginIter(), tag.GetEndIter1());
}
//-----------------------------------------------------------------------------
}
//-----------------------------------------------------------------------------
const wxString::const_iterator ent_s = c;
wxChar entity_char;
const wxString::const_iterator ent_s = c;
wxChar entity_char;
- 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) {}
+ for ( ; c != end; ++c )
+ {
+ wxChar ch = *c;
+ if ( !((ch >= wxT('a') && ch <= wxT('z')) ||
+ (ch >= wxT('A') && ch <= wxT('Z')) ||
+ (ch >= wxT('0') && ch <= wxT('9')) ||
+ ch == wxT('_') || ch == wxT('#')) )
+ break;
+ }
+
entity.append(ent_s, c);
if (c == end || *c != wxT(';')) --c;
last = c+1;
entity.append(ent_s, c);
if (c == end || *c != wxT(';')) --c;
last = c+1;
{
// this is "pos" value passed to wxHtmlTag's constructor.
// it is position of '<' character of the tag
{
// this is "pos" value passed to wxHtmlTag's constructor.
// it is position of '<' character of the tag
+ wxString::const_iterator Key;
+
+ // Tag type
+ enum Type
+ {
+ Type_Normal, // normal tag with a matching ending tag
+ Type_NoMatchingEndingTag, // there's no ending tag for this tag
+ Type_EndingTag // this is ending tag </..>
+ };
+ Type type;
// end positions for the tag:
// end1 is '<' of ending tag,
// end2 is '>' or both are
// end positions for the tag:
// end1 is '<' of ending tag,
// end2 is '>' or both are
- // -1 if there is no ending tag for this one...
- // or -2 if this is ending tag </...>
- int End1, End2;
+ wxString::const_iterator End1, End2;
// name of this tag
wxChar *Name;
// name of this tag
wxChar *Name;
(wxStrcmp(tag, _T("STYLE")) == 0);
}
(wxStrcmp(tag, _T("STYLE")) == 0);
}
+bool wxIsCDATAElement(const wxString& tag)
+{
+ return (wxStrcmp(tag.wx_str(), wxSTRING_TEXT("SCRIPT")) == 0) ||
+ (wxStrcmp(tag.wx_str(), wxSTRING_TEXT("STYLE")) == 0);
+}
+
wxHtmlTagsCache::wxHtmlTagsCache(const wxString& source)
{
m_Cache = new wxHtmlTagsCacheData;
m_CachePos = 0;
wxHtmlTagsCache::wxHtmlTagsCache(const wxString& source)
{
m_Cache = new wxHtmlTagsCacheData;
m_CachePos = 0;
- const wxChar *src = source.c_str();
- int lng = source.length();
- for ( int pos = 0; pos < lng; pos++ )
+ const wxString::const_iterator end = source.end();
+ for ( wxString::const_iterator pos = source.begin(); pos < end; ++pos )
- if (src[pos] == wxT('<')) // tag found:
+ if (*pos == wxT('<')) // tag found:
{
// don't cache comment tags
{
// don't cache comment tags
- wxString::const_iterator iter = source.begin() + pos;
- if ( wxHtmlParser::SkipCommentTag(iter, source.end()) )
- {
- pos = iter - source.begin();
+ if ( wxHtmlParser::SkipCommentTag(pos, source.end()) )
size_t tg = Cache().size();
Cache().push_back(wxHtmlCacheItem());
size_t tg = Cache().size();
Cache().push_back(wxHtmlCacheItem());
+ wxString::const_iterator stpos = pos++;
Cache()[tg].Key = stpos;
int i;
for ( i = 0;
Cache()[tg].Key = stpos;
int i;
for ( i = 0;
- pos < lng && i < (int)WXSIZEOF(tagBuffer) - 1 &&
- src[pos] != wxT('>') && !wxIsspace(src[pos]);
- i++, pos++ )
+ pos < end && i < (int)WXSIZEOF(tagBuffer) - 1 &&
+ *pos != wxT('>') && !wxIsspace(*pos);
+ ++i, ++pos )
- tagBuffer[i] = (wxChar)wxToupper(src[pos]);
+ tagBuffer[i] = (wxChar)wxToupper(*pos);
}
tagBuffer[i] = _T('\0');
Cache()[tg].Name = new wxChar[i+1];
memcpy(Cache()[tg].Name, tagBuffer, (i+1)*sizeof(wxChar));
}
tagBuffer[i] = _T('\0');
Cache()[tg].Name = new wxChar[i+1];
memcpy(Cache()[tg].Name, tagBuffer, (i+1)*sizeof(wxChar));
- while (pos < lng && src[pos] != wxT('>')) pos++;
+ while (pos < end && *pos != wxT('>'))
+ ++pos;
- if (src[stpos+1] == wxT('/')) // ending tag:
+ if ((stpos+1) < end && *(stpos+1) == wxT('/')) // ending tag:
- Cache()[tg].End1 = Cache()[tg].End2 = -2;
+ Cache()[tg].type = wxHtmlCacheItem::Type_EndingTag;
// find matching begin tag:
for (i = tg; i >= 0; i--)
// find matching begin tag:
for (i = tg; i >= 0; i--)
- if ((Cache()[i].End1 == -1) && (wxStrcmp(Cache()[i].Name, tagBuffer+1) == 0))
+ {
+ if ((Cache()[i].type == wxHtmlCacheItem::Type_NoMatchingEndingTag) && (wxStrcmp(Cache()[i].Name, tagBuffer+1) == 0))
+ Cache()[i].type = wxHtmlCacheItem::Type_Normal;
Cache()[i].End1 = stpos;
Cache()[i].End2 = pos + 1;
break;
}
Cache()[i].End1 = stpos;
Cache()[i].End2 = pos + 1;
break;
}
- Cache()[tg].End1 = Cache()[tg].End2 = -1;
+ Cache()[tg].type = wxHtmlCacheItem::Type_NoMatchingEndingTag;
if (wxIsCDATAElement(tagBuffer))
{
// store the orig pos in case we are missing the closing
// tag (see below)
if (wxIsCDATAElement(tagBuffer))
{
// store the orig pos in case we are missing the closing
// tag (see below)
+ const wxString::const_iterator old_pos = pos;
bool foundCloseTag = false;
// find next matching tag
int tag_len = wxStrlen(tagBuffer);
bool foundCloseTag = false;
// find next matching tag
int tag_len = wxStrlen(tagBuffer);
- while (pos + 1 < lng &&
- (src[pos] != '<' || src[pos+1] != '/'))
+ while (pos + 1 < end &&
+ (*pos != '<' || *(pos+1) != '/'))
++pos;
// see if it matches
int match_pos = 0;
++pos;
// see if it matches
int match_pos = 0;
- while (pos < lng && match_pos < tag_len && src[pos] != '>' && src[pos] != '<') {
+ while (pos < end && match_pos < tag_len )
+ {
+ wxChar c = *pos;
+ if ( c == '>' || c == '<' )
+ break;
+
// cast to wxChar needed to suppress warning in
// Unicode build
// cast to wxChar needed to suppress warning in
// Unicode build
- if ((wxChar)wxToupper(src[pos]) == tagBuffer[match_pos]) {
+ if ((wxChar)wxToupper(c) == tagBuffer[match_pos])
+ {
- else if (src[pos] == wxT(' ') || src[pos] == wxT('\n') ||
- src[pos] == wxT('\r') || src[pos] == wxT('\t')) {
+ else if (c == wxT(' ') || c == wxT('\n') ||
+ c == wxT('\r') || c == wxT('\t'))
+ {
// need to skip over these
}
// need to skip over these
}
-void wxHtmlTagsCache::QueryTag(int at, int* end1, int* end2)
+void wxHtmlTagsCache::QueryTag(const wxString::const_iterator& at,
+ const wxString::const_iterator& inputEnd,
+ wxString::const_iterator *end1,
+ wxString::const_iterator *end2,
+ bool *hasEnding)
{
if (Cache().empty())
return;
{
if (Cache().empty())
return;
int delta = (at < Cache()[m_CachePos].Key) ? -1 : 1;
do
{
int delta = (at < Cache()[m_CachePos].Key) ? -1 : 1;
do
{
- if ( m_CachePos < 0 || m_CachePos == Cache().size() )
+ m_CachePos += delta;
+
+ if ( m_CachePos < 0 || m_CachePos >= (int)Cache().size() )
+ if ( m_CachePos < 0 )
+ m_CachePos = 0;
+ else
+ m_CachePos = Cache().size() - 1;
// something is very wrong with HTML, give up by returning an
// impossibly large value which is going to be ignored by the
// caller
*end1 =
// something is very wrong with HTML, give up by returning an
// impossibly large value which is going to be ignored by the
// caller
*end1 =
+ *end2 = inputEnd;
+ *hasEnding = true;
}
while (Cache()[m_CachePos].Key != at);
}
*end1 = Cache()[m_CachePos].End1;
*end2 = Cache()[m_CachePos].End2;
}
while (Cache()[m_CachePos].Key != at);
}
*end1 = Cache()[m_CachePos].End1;
*end2 = Cache()[m_CachePos].End2;
+ *hasEnding = (Cache()[m_CachePos].type == wxHtmlCacheItem::Type_Normal);
//-----------------------------------------------------------------------------
wxHtmlTag::wxHtmlTag(wxHtmlTag *parent,
//-----------------------------------------------------------------------------
wxHtmlTag::wxHtmlTag(wxHtmlTag *parent,
- const wxString& source, int pos, int end_pos,
+ const wxString *source,
+ const wxString::const_iterator& pos,
+ const wxString::const_iterator& end_pos,
wxHtmlTagsCache *cache,
wxHtmlEntitiesParser *entParser)
{
wxHtmlTagsCache *cache,
wxHtmlEntitiesParser *entParser)
{
/* Find parameters and their values: */
/* Find parameters and their values: */
wxChar c;
// fill-in name, params and begin pos:
wxChar c;
// fill-in name, params and begin pos:
+ wxString::const_iterator i(pos+1);
// find tag's name and convert it to uppercase:
while ((i < end_pos) &&
// find tag's name and convert it to uppercase:
while ((i < end_pos) &&
- ((c = source[i++]) != wxT(' ') && c != wxT('\r') &&
+ ((c = *(i++)) != wxT(' ') && c != wxT('\r') &&
c != wxT('\n') && c != wxT('\t') &&
c != wxT('>')))
{
c != wxT('\n') && c != wxT('\t') &&
c != wxT('>')))
{
// if the tag has parameters, read them and "normalize" them,
// i.e. convert to uppercase, replace whitespaces by spaces and
// remove whitespaces around '=':
// if the tag has parameters, read them and "normalize" them,
// i.e. convert to uppercase, replace whitespaces by spaces and
// remove whitespaces around '=':
- if (source[i-1] != wxT('>'))
+ if (*(i-1) != wxT('>'))
{
#define IS_WHITE(c) (c == wxT(' ') || c == wxT('\r') || \
c == wxT('\n') || c == wxT('\t'))
{
#define IS_WHITE(c) (c == wxT(' ') || c == wxT('\r') || \
c == wxT('\n') || c == wxT('\t'))
state = ST_BEFORE_NAME;
while (i < end_pos)
{
state = ST_BEFORE_NAME;
while (i < end_pos)
{
if (c == wxT('>') && !(state == ST_VALUE && quote != 0))
{
if (state == ST_BEFORE_EQ || state == ST_NAME)
{
m_ParamNames.Add(pname);
if (c == wxT('>') && !(state == ST_VALUE && quote != 0))
{
if (state == ST_BEFORE_EQ || state == ST_NAME)
{
m_ParamNames.Add(pname);
- m_ParamValues.Add(wxEmptyString);
+ m_ParamValues.Add(wxGetEmptyString());
}
else if (state == ST_VALUE && quote == 0)
{
}
else if (state == ST_VALUE && quote == 0)
{
else if (!IS_WHITE(c))
{
m_ParamNames.Add(pname);
else if (!IS_WHITE(c))
{
m_ParamNames.Add(pname);
- m_ParamValues.Add(wxEmptyString);
+ m_ParamValues.Add(wxGetEmptyString());
pname = c;
state = ST_NAME;
}
pname = c;
state = ST_NAME;
}
if (!IS_WHITE(c))
{
if (c == wxT('"') || c == wxT('\''))
if (!IS_WHITE(c))
{
if (c == wxT('"') || c == wxT('\''))
- quote = c, pvalue = wxEmptyString;
+ quote = c, pvalue = wxGetEmptyString();
else
quote = 0, pvalue = c;
state = ST_VALUE;
else
quote = 0, pvalue = c;
state = ST_VALUE;
#undef IS_WHITE
}
m_Begin = i;
#undef IS_WHITE
}
m_Begin = i;
-
- cache->QueryTag(pos, &m_End1, &m_End2);
+ cache->QueryTag(pos, source->end(), &m_End1, &m_End2, &m_hasEnding);
if (m_End1 > end_pos) m_End1 = end_pos;
if (m_End2 > end_pos) m_End2 = end_pos;
if (m_End1 > end_pos) m_End1 = end_pos;
if (m_End2 > end_pos) m_End2 = end_pos;
+
+#if WXWIN_COMPATIBILITY_2_8
+ m_sourceStart = source->begin();
+#endif
}
wxHtmlTag::~wxHtmlTag()
}
wxHtmlTag::~wxHtmlTag()
{
int index = m_ParamNames.Index(par, false);
if (index == wxNOT_FOUND)
{
int index = m_ParamNames.Index(par, false);
if (index == wxNOT_FOUND)
+ return wxGetEmptyString();
if (with_commas)
{
// VS: backward compatibility, seems to be never used by wxHTML...
if (with_commas)
{
// VS: backward compatibility, seems to be never used by wxHTML...
// handle colours defined in HTML 4.0 first:
if (str.length() > 1 && str[0] != _T('#'))
{
// handle colours defined in HTML 4.0 first:
if (str.length() > 1 && str[0] != _T('#'))
{
- #define HTML_COLOUR(name, r, g, b) \
- if (str.IsSameAs(wxT(name), false)) \
+ #define HTML_COLOUR(name, r, g, b) \
+ if (str.IsSameAs(wxSTRING_TEXT(name), false)) \
{ clr->Set(r, g, b); return true; }
HTML_COLOUR("black", 0x00,0x00,0x00)
HTML_COLOUR("silver", 0xC0,0xC0,0xC0)
{ clr->Set(r, g, b); return true; }
HTML_COLOUR("black", 0x00,0x00,0x00)
HTML_COLOUR("silver", 0xC0,0xC0,0xC0)
wxHtmlWindowInterface *winIface = m_WParser->GetWindowInterface();
if (winIface)
{
wxHtmlWindowInterface *winIface = m_WParser->GetWindowInterface();
if (winIface)
{
- wxString title = m_WParser->GetSource()->Mid(
- tag.GetBeginPos(),
- tag.GetEndPos1()-tag.GetBeginPos());
+ wxString title(tag.GetBeginIter(), tag.GetEndIter1());
#if !wxUSE_UNICODE && wxUSE_WCHAR_T
const wxFontEncoding enc = m_WParser->GetInputEncoding();
if ( enc != wxFONTENCODING_DEFAULT )
#if !wxUSE_UNICODE && wxUSE_WCHAR_T
const wxFontEncoding enc = m_WParser->GetInputEncoding();
if ( enc != wxFONTENCODING_DEFAULT )