- if (m_CacheSize % CACHE_INCREMENT == 0)
- m_Cache = (wxHtmlCacheItem*) realloc(m_Cache, (m_CacheSize + CACHE_INCREMENT) * sizeof(wxHtmlCacheItem));
- tg = m_CacheSize++;
- m_Cache[tg].Key = stpos = pos++;
- dummy[0] = 0; i = 0;
- while (pos < lng &&
- src[pos] != wxT('>') &&
- src[pos] != wxT(' ') && src[pos] != wxT('\r') &&
- src[pos] != wxT('\n') && src[pos] != wxT('\t'))
+ tagBuffer[i] = (wxChar)wxToupper(*pos);
+ }
+ tagBuffer[i] = wxT('\0');
+
+ 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;
+ // find matching begin tag:
+ for (i = tg; i >= 0; i--)