void wx28HtmlParser::CreateDOMTree() { wx28HtmlTagsCache cache(m_Source); m_TextPieces = new wx28HtmlTextPieces; CreateDOMSubTree(NULL, 0, m_Source.length(), &cache); m_CurTextPiece = 0; }
void wxHtmlParser::CreateDOMTree() { wxHtmlTagsCache cache(*m_Source); m_TextPieces = new wxHtmlTextPieces; CreateDOMSubTree(NULL, m_Source->begin(), m_Source->end(), &cache); m_CurTextPiece = 0; }
void wx28HtmlParser::CreateDOMSubTree(wx28HtmlTag *cur, int begin_pos, int end_pos, wx28HtmlTagsCache *cache) { if (end_pos <= begin_pos) return; wxChar c; int i = begin_pos; int 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 (cur != NULL && wxIsCDATAElement(cur->GetName().c_str())) { i = end_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( wx28HtmlTextPiece(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('/')) { wx28HtmlTag *chd; if (cur) chd = new wx28HtmlTag(cur, m_Source, i, end_pos, cache, m_entitiesParser); else { chd = new wx28HtmlTag(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++; } // add remaining text to m_TextPieces: if (end_pos - textBeginning > 0) m_TextPieces->Add( wx28HtmlTextPiece(textBeginning, end_pos - textBeginning)); }
void wxHtmlParser::CreateDOMSubTree(wxHtmlTag *cur, const wxString::const_iterator& begin_pos, const wxString::const_iterator& end_pos, wxHtmlTagsCache *cache) { if (end_pos <= begin_pos) return; wxChar c; 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 (cur != NULL && wxIsCDATAElement(cur->GetName())) { i = end_pos; } while (i < end_pos) { c = *i; if (c == wxT('<')) { // add text to m_TextPieces: if (i > textBeginning) m_TextPieces->push_back(wxHtmlTextPiece(textBeginning, i)); // if it is a comment, skip it: if ( SkipCommentTag(i, m_Source->end()) ) { textBeginning = i = i + 1; // skip closing '>' too } // add another tag to the tree: else if (i < end_pos-1 && *(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->GetBeginIter(), chd->GetEndIter1(), cache); i = chd->GetEndIter2(); } else i = chd->GetBeginIter(); textBeginning = i; } // ... or skip ending tag: else { while (i < end_pos && *i != wxT('>')) ++i; textBeginning = i < end_pos ? i+1 : i; } } else ++i; } // add remaining text to m_TextPieces: if (end_pos > textBeginning) m_TextPieces->push_back(wxHtmlTextPiece(textBeginning, end_pos)); }