+ wxChar c;
+ int i = begin_pos;
+ int textBeginning = begin_pos;
+
+ while (i < end_pos)
+ {
+ c = m_Source.GetChar(i);
+
+ if (c == wxT('<'))
+ {
+ // add text to m_TextPieces:
+ if (i - textBeginning > 0)
+ m_TextPieces->Add(
+ wxHtmlTextPiece(textBeginning, i - textBeginning));
+
+ // if it is a comment, skip it:
+ if (i < end_pos-6 && m_Source.GetChar(i+1) == wxT('!') &&
+ m_Source.GetChar(i+2) == wxT('-') &&
+ m_Source.GetChar(i+3) == wxT('-'))
+ {
+ // Comments begin with "<!--" and end with "--[ \t\r\n]*>"
+ // according to HTML 4.0
+ int dashes = 0;
+ i += 4;
+ while (i < end_pos)
+ {
+ c = m_Source.GetChar(i++);
+ if ((c == wxT(' ') || c == wxT('\n') ||
+ c == wxT('\r') || c == wxT('\t')) && dashes >= 2) {}
+ else if (c == wxT('>') && dashes >= 2)
+ {
+ textBeginning = i;
+ break;
+ }
+ else if (c == wxT('-'))
+ dashes++;
+ else
+ dashes = 0;
+ }
+ }
+
+ // add another tag to the tree:
+ else if (i < end_pos-1 && m_Source.GetChar(i+1) != wxT('/'))
+ {
+ wxHtmlTag *chd;
+ if (cur)
+ chd = new wxHtmlTag(cur, m_Source,
+ i, end_pos, cache, m_entitiesParser);
+ else
+ {
+ chd = new wxHtmlTag(NULL, m_Source,
+ i, end_pos, cache, m_entitiesParser);
+ if (!m_Tags)
+ {
+ // if this is the first tag to be created make the root
+ // m_Tags point to it:
+ m_Tags = chd;
+ }
+ else
+ {
+ // if there is already a root tag add this tag as
+ // the last sibling:
+ chd->m_Prev = m_Tags->GetLastSibling();
+ chd->m_Prev->m_Next = chd;
+ }
+ }
+
+ if (chd->HasEnding())
+ {
+ CreateDOMSubTree(chd,
+ chd->GetBeginPos(), chd->GetEndPos1(),
+ cache);
+ i = chd->GetEndPos2();
+ }
+ else
+ i = chd->GetBeginPos();
+ textBeginning = i;
+ }
+
+ // ... or skip ending tag:
+ else
+ {
+ while (i < end_pos && m_Source.GetChar(i) != wxT('>')) i++;
+ textBeginning = i+1;
+ }
+ }
+ else i++;
+ }