示例#1
0
void wxHtmlParser::DoParsing(int begin_pos, int end_pos)
{
    if (end_pos <= begin_pos) return;

    wxHtmlTextPieces& pieces = *m_TextPieces;
    size_t piecesCnt = pieces.GetCount();

    while (begin_pos < end_pos)
    {
        while (m_CurTag && m_CurTag->GetBeginPos() < begin_pos)
            m_CurTag = m_CurTag->GetNextTag();
        while (m_CurTextPiece < piecesCnt &&
               pieces[m_CurTextPiece].m_pos < begin_pos)
            m_CurTextPiece++;

        if (m_CurTextPiece < piecesCnt &&
            (!m_CurTag ||
             pieces[m_CurTextPiece].m_pos < m_CurTag->GetBeginPos()))
        {
            // 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;
            m_CurTextPiece++;
        }
        else if (m_CurTag)
        {
            // Add tag:
            if (m_CurTag)
            {
                if (m_CurTag->HasEnding())
                    begin_pos = m_CurTag->GetEndPos2();
                else
                    begin_pos = m_CurTag->GetBeginPos();
            }
            wxHtmlTag *t = m_CurTag;
            m_CurTag = m_CurTag->GetNextTag();
            AddTag(*t);
            if (m_stopParsing)
                return;
        }
        else break;
    }
}
示例#2
0
void wxHtmlParser::DoParsing(const wxString::const_iterator& begin_pos_,
                             const wxString::const_iterator& end_pos)
{
    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)
    {
        while (m_CurTag && m_CurTag->GetBeginIter() < begin_pos)
            m_CurTag = m_CurTag->GetNextTag();
        while (m_CurTextPiece < piecesCnt &&
               pieces[m_CurTextPiece].m_start < begin_pos)
            m_CurTextPiece++;

        if (m_CurTextPiece < piecesCnt &&
            (!m_CurTag ||
             pieces[m_CurTextPiece].m_start < m_CurTag->GetBeginIter()))
        {
            // Add text:
            AddText(GetEntitiesParser()->Parse(
                       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())
                begin_pos = m_CurTag->GetEndIter2();
            else
                begin_pos = m_CurTag->GetBeginIter();
            wxHtmlTag *t = m_CurTag;
            m_CurTag = m_CurTag->GetNextTag();
            AddTag(*t);
            if (m_stopParsing)
                return;
        }
        else break;
    }
}
示例#3
0
 HP_Parser()
 {
     GetEntitiesParser()->SetEncoding(wxFONTENCODING_ISO8859_1);
 }
示例#4
0
void wxHtmlWinParser::AddText(const wxString& txt)
{
#if !wxUSE_UNICODE
    if ( m_nbsp == 0 )
        m_nbsp = GetEntitiesParser()->GetCharForCode(NBSP_UNICODE_VALUE);
#endif

    if ( m_whitespaceMode == Whitespace_Normal )
    {
        int templen = 0;

        size_t lng = txt.length();
        if (lng+1 > m_tmpStrBufSize)
        {
            delete[] m_tmpStrBuf;
            m_tmpStrBuf = new wxChar[lng+1];
            m_tmpStrBufSize = lng+1;
        }
        wxChar *temp = m_tmpStrBuf;

        wxString::const_iterator i = txt.begin();
        const wxString::const_iterator end = txt.end();

        if (m_tmpLastWasSpace)
        {
            while ( (i < end) &&
                    (*i == wxT('\n') || *i == wxT('\r') || *i == wxT(' ') ||
                     *i == wxT('\t')) )
            {
                ++i;
            }
        }

        while (i < end)
        {
            size_t x = 0;
            const wxChar d = temp[templen++] = *i;
            if ((d == wxT('\n')) || (d == wxT('\r')) || (d == wxT(' ')) || (d == wxT('\t')))
            {
                ++i, ++x;
                while ( (i < end) &&
                        (*i == wxT('\n') || *i == wxT('\r') ||
                         *i == wxT(' ') || *i == wxT('\t')) )
                {
                    ++i;
                    ++x;
                }
            }
            else
            {
                ++i;
            }

            if (x)
            {
                temp[templen-1] = wxT(' ');
                FlushWordBuf(temp, templen);
                m_tmpLastWasSpace = true;
            }
        }

        if (templen && (templen > 1 || temp[0] != wxT(' ')))
        {
            FlushWordBuf(temp, templen);
            m_tmpLastWasSpace = false;
        }
    }
    else // m_whitespaceMode == Whitespace_Pre
    {
        if ( txt.find(CUR_NBSP_VALUE) != wxString::npos )
        {
            // we need to substitute spaces for &nbsp; here just like we
            // did in the Whitespace_Normal branch above
            wxString txt2(txt);
            txt2.Replace(CUR_NBSP_VALUE, ' ');
            AddPreBlock(txt2);
        }
        else
        {
            AddPreBlock(txt);
        }

        // don't eat any whitespace in <pre> block
        m_tmpLastWasSpace = false;
    }
}
示例#5
0
void wxHtmlParser::DoParsing(const wxString::const_iterator& begin_pos_,
                             const wxString::const_iterator& end_pos)
{
    wxString::const_iterator begin_pos(begin_pos_);

    if (end_pos <= begin_pos)
        return;

    wxHtmlTextPieces& pieces = *m_TextPieces;
    size_t piecesCnt = pieces.size();

#if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */
#   pragma ivdep
#   pragma swp
#   pragma unroll
#   pragma prefetch
#   if 0
#       pragma simd noassert
#   endif
#endif /* VDM auto patch */
    while (begin_pos < end_pos)
    {
#if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */
#   pragma ivdep
#   pragma swp
#   pragma unroll
#   pragma prefetch
#   if 0
#       pragma simd noassert
#   endif
#endif /* VDM auto patch */
        while (m_CurTag && m_CurTag->GetBeginIter() < begin_pos)
            m_CurTag = m_CurTag->GetNextTag();
#if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */
#   pragma ivdep
#   pragma swp
#   pragma unroll
#   pragma prefetch
#   if 0
#       pragma simd noassert
#   endif
#endif /* VDM auto patch */
        while (m_CurTextPiece < piecesCnt &&
               pieces[m_CurTextPiece].m_start < begin_pos)
            m_CurTextPiece++;

        if (m_CurTextPiece < piecesCnt &&
            (!m_CurTag ||
             pieces[m_CurTextPiece].m_start < m_CurTag->GetBeginIter()))
        {
            // Add text:
            AddText(GetEntitiesParser()->Parse(
                       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())
                begin_pos = m_CurTag->GetEndIter2();
            else
                begin_pos = m_CurTag->GetBeginIter();
            wxHtmlTag *t = m_CurTag;
            m_CurTag = m_CurTag->GetNextTag();
            AddTag(*t);
            if (m_stopParsing)
                return;
        }
        else break;
    }
}
示例#6
0
void CHtmlWinParser::AddText(const wxChar* txt)
{
    CHtmlCell *c, *cspace;
    size_t i = 0,
           x,
           lng = wxStrlen(txt);
    register wxChar d;
    int templen = 0;
    wxChar nbsp = GetEntitiesParser()->GetCharForCode(160 /* nbsp */);

    if (lng+1 > m_tmpStrBufSize)
    {
        delete[] m_tmpStrBuf;
        m_tmpStrBuf = new wxChar[lng+1];
        m_tmpStrBufSize = lng+1;
    }
    wxChar *temp = m_tmpStrBuf;

    if (m_tmpLastWasSpace)
    {
        while ((i < lng) &&
               ((txt[i] == wxT('\n')) || (txt[i] == wxT('\r')) || (txt[i] == wxT(' ')) ||
                (txt[i] == wxT('\t')))) i++;
    }

    while (i < lng)
    {
        x = 0;
        d = temp[templen++] = txt[i];
        if ((d == wxT('\n')) || (d == wxT('\r')) || (d == wxT(' ')) || (d == wxT('\t')))
        {
            i++, x++;
            while ((i < lng) && ((txt[i] == wxT('\n')) || (txt[i] == wxT('\r')) ||
                                 (txt[i] == wxT(' ')) || (txt[i] == wxT('\t')))) i++, x++;
        }
        else i++;

        if (x)
        {
            temp[templen-1] = 0;
            templen = 0;
#if !wxUSE_UNICODE
            if (m_EncConv)
                m_EncConv->Convert(temp);
#endif
            size_t len = wxStrlen(temp);

            for (size_t j = 0; j < len; j++)
                if (temp[j] == nbsp)
                    temp[j] = wxT(' ');
            c = new CHtmlWordCell(temp, *(GetDC()));
            cspace = new CHtmlWordCell(wxT(' '), *(GetDC()));
            if (m_UseLink)
            {
                c->SetLink(m_Link);
                cspace->SetLink(m_Link);
            }
            m_Container->InsertCell(c);
            m_Container->InsertCell(cspace);
            ((CHtmlWordCell*)c)->SetPreviousWord(m_lastWordCell);
            m_lastWordCell = (CHtmlWordCell*)c;
            m_tmpLastWasSpace = true;
        }
    }

    if (templen && (templen > 1 || temp[0] != wxT(' ')))
    {
        temp[templen] = 0;
#if !wxUSE_UNICODE
        if (m_EncConv)
            m_EncConv->Convert(temp);
#endif
        size_t len = wxStrlen(temp);
        for (size_t j = 0; j < len; j++)
            if (temp[j] == nbsp)
                temp[j] = wxT(' ');
        c = new CHtmlWordCell(temp, *(GetDC()));
        if (m_UseLink)
            c->SetLink(m_Link);
        m_Container->InsertCell(c);
        ((CHtmlWordCell*)c)->SetPreviousWord(m_lastWordCell);
        m_lastWordCell = (CHtmlWordCell*)c;
        m_tmpLastWasSpace = false;
    }
}