Example #1
0
bool CMarkup::_ParseAttributes(LPTSTR& pstrText)
{   
   if( *pstrText == '>' ) return true;
   *pstrText++ = '\0';
   _SkipWhitespace(pstrText);
   while( *pstrText != '\0' && *pstrText != '>' && *pstrText != '/' ) {
      _SkipIdentifier(pstrText);
      if( *pstrText != '=' ) return _Failed(_T("Error while parsing attributes"), pstrText);
      *pstrText++ = '\0';
      TCHAR chQuote = *pstrText++;
      if( chQuote != '\"' && chQuote != '\'' ) return _Failed(_T("Expected attribute value"), pstrText);
      LPTSTR pstrDest = pstrText;
      if( !_ParseData(pstrText, pstrDest, chQuote) ) return false;
      if( *pstrText == '\0' ) return _Failed(_T("Error while parsing attribute string"), pstrText);
      *pstrDest = '\0';
      *pstrText++ = '\0';
      _SkipWhitespace(pstrText);
   }
   return true;
}
Example #2
0
bool CMarkup::_ParseAttributes(wchar_t*& pstrText)
{   
    if( *pstrText == _T('>') ) return true;
    *pstrText++ = _T('\0');
    _SkipWhitespace(pstrText);
    while( *pstrText != _T('\0') && *pstrText != _T('>') && *pstrText != _T('/') ) {
        _SkipIdentifier(pstrText);
        wchar_t* pstrIdentifierEnd = pstrText;
        _SkipWhitespace(pstrText);
        if( *pstrText != _T('=') ) return _Failed(L"Error while parsing attributes", pstrText);
        *pstrText++ = _T(' ');
        *pstrIdentifierEnd = _T('\0');
        _SkipWhitespace(pstrText);
        if( *pstrText++ != _T('\"') ) return _Failed(L"Expected attribute value", pstrText);
        wchar_t* pstrDest = pstrText;
        if( !_ParseData(pstrText, pstrDest, _T('\"')) ) return false;
        if( *pstrText == _T('\0') ) return _Failed(L"Error while parsing attribute string", pstrText);
        *pstrDest = _T('\0');
        if( pstrText != pstrDest ) *pstrText = _T(' ');
        pstrText++;
        _SkipWhitespace(pstrText);
    }
    return true;
}
Example #3
0
bool CXmlManager::_ParseAttributes(LPTSTR& pstrText)
{   
    if( *pstrText == _T('>') ) return true;
    *pstrText++ = _T('\0');
    _SkipWhitespace(pstrText);
    while( *pstrText != _T('\0') && *pstrText != _T('>') && *pstrText != _T('/') ) 
	{
        _SkipIdentifier(pstrText);
        LPTSTR pstrIdentifierEnd = pstrText;
        _SkipWhitespace(pstrText);
        if( *pstrText != _T('=') ) return _Failed(_T("Error while parsing attributes"), pstrText);
        *pstrText++ = _T(' ');
        *pstrIdentifierEnd = _T('\0');
        _SkipWhitespace(pstrText);
        if( *pstrText++ != _T('\"') ) return _Failed(_T("Expected attribute value"), pstrText);
        LPTSTR pstrDest = pstrText;
        if( !_ParseData(pstrText, pstrDest, _T('\"')) ) return false;
        if( *pstrText == _T('\0') ) return _Failed(_T("Error while parsing attribute string"), pstrText);
        *pstrDest = _T('\0');
        *pstrText++ = _T('\0');
        _SkipWhitespace(pstrText);
    }
    return true;
}
Example #4
0
bool CMarkup::_Parse(wchar_t*& pstrText, ULONG iParent)
{
    _SkipWhitespace(pstrText);
    ULONG iPrevious = 0;
    for( ; ; ) 
    {
        if( *pstrText == _T('\0') && iParent <= 1 ) return true;
        _SkipWhitespace(pstrText);
        if( *pstrText != _T('<') ) return _Failed(L"Expected start tag", pstrText);
        if( pstrText[1] == _T('/') ) return true;
        *pstrText++ = _T('\0');
        _SkipWhitespace(pstrText);
        // Skip comment or processing directive
        if( *pstrText == _T('!') || *pstrText == _T('?') ) {
            wchar_t ch = *pstrText;
            if( *pstrText == _T('!') ) ch = _T('-');
            while( *pstrText != _T('\0') && !(*pstrText == ch && *(pstrText + 1) == _T('>')) ) pstrText = ::CharNextW(pstrText);
            if( *pstrText != _T('\0') ) pstrText += 2;
            _SkipWhitespace(pstrText);
            continue;
        }
        _SkipWhitespace(pstrText);
        // Fill out element structure
        XMLELEMENT* pEl = _ReserveElement();
        ULONG iPos = pEl - m_pElements;
        pEl->iStart = pstrText - m_pstrXML;
        pEl->iParent = iParent;
        pEl->iNext = pEl->iChild = 0;
        if( iPrevious != 0 ) m_pElements[iPrevious].iNext = iPos;
        else if( iParent > 0 ) m_pElements[iParent].iChild = iPos;
        iPrevious = iPos;
        // Parse name
        const wchar_t* pstrName = pstrText;
        _SkipIdentifier(pstrText);
        wchar_t* pstrNameEnd = pstrText;
        if( *pstrText == _T('\0') ) return _Failed(L"Error parsing element name", pstrText);
        // Parse attributes
        if( !_ParseAttributes(pstrText) ) return false;
        _SkipWhitespace(pstrText);
        if( pstrText[0] == _T('/') && pstrText[1] == _T('>') )
        {
            pEl->iData = pstrText - m_pstrXML;
            *pstrText = _T('\0');
            pstrText += 2;
        }
        else
        {
            if( *pstrText != _T('>') ) return _Failed(L"Expected start-tag closing", pstrText);
            // Parse node data
            pEl->iData = ++pstrText - m_pstrXML;
            wchar_t* pstrDest = pstrText;
            if( !_ParseData(pstrText, pstrDest, _T('<')) ) return false;
            // Determine type of next element
            if( *pstrText == _T('\0') && iParent <= 1 ) return true;
            if( *pstrText != _T('<') ) return _Failed(L"Expected end-tag start", pstrText);
            if( pstrText[0] == _T('<') && pstrText[1] != _T('/') ) 
            {
                if( !_Parse(pstrText, iPos) ) return false;
            }
            if( pstrText[0] == _T('<') && pstrText[1] == _T('/') ) 
            {
                *pstrDest = _T('\0');
                *pstrText = _T('\0');
                pstrText += 2;
                _SkipWhitespace(pstrText);
                SIZE_T cchName = pstrNameEnd - pstrName;
                if( wcsncmp(pstrText, pstrName, cchName) != 0 ) return _Failed(L"Unmatched closing tag", pstrText);
                pstrText += cchName;
                _SkipWhitespace(pstrText);
                if( *pstrText++ != _T('>') ) return _Failed(L"Unmatched closing tag", pstrText);
            }
        }
        *pstrNameEnd = _T('\0');
        _SkipWhitespace(pstrText);
    }
}
Example #5
0
bool CMarkup::_Parse(LPTSTR& pstrText, ULONG iParent)
{
   ULONG iPrevious = 0;
   for( ; ; ) 
   {
      if( *pstrText == '\0' && iParent <= 1 ) return true;
      if( *pstrText != '<' ) return _Failed(_T("Expected start tag"), pstrText);
      if( pstrText[1] == '/' ) return true;
      *pstrText++ = '\0';
      // Skip comment or processing directive
      if( *pstrText == '!' || *pstrText == '?' ) {
         TCHAR chEnd = *pstrText == '!' ? '-' : '?';
         while( *pstrText != '\0' && !(*pstrText == chEnd && *(pstrText + 1) == '>') ) pstrText = ::CharNext(pstrText);
         if( *pstrText != '\0' ) pstrText += 2;
         _SkipWhitespace(pstrText);
         continue;
      }
      // Fill out element structure
      XMLELEMENT* pEl = _ReserveElement();
      ULONG iPos = pEl - m_pElements;
      pEl->iStart = pstrText - m_pstrXML;
      pEl->iParent = iParent;
      pEl->iNext = pEl->iChild = 0;
      if( iPrevious != 0 ) m_pElements[iPrevious].iNext = iPos;
      else if( iParent > 0 ) m_pElements[iParent].iChild = iPos;
      iPrevious = iPos;
      // Parse name
      LPCTSTR pstrName = pstrText;
      _SkipIdentifier(pstrText);
      LPTSTR pstrNameEnd = pstrText;
      if( *pstrText == '\0' ) return _Failed(_T("Error parsing element name"), pstrText);
      // Parse attributes
      if( !_ParseAttributes(pstrText) ) return false;
      _SkipWhitespace(pstrText);
      if( pstrText[0] == '/' && pstrText[1] == '>' )
      {
         pEl->iData = pstrText - m_pstrXML;
         *pstrText = '\0';
         pstrText += 2;
      }
      else
      {
         if( *pstrText != '>' ) return _Failed(_T("Expected start-tag closing"), pstrText);
         // Parse node data
         pEl->iData = ++pstrText - m_pstrXML;
         LPTSTR pstrDest = pstrText;
         if( !_ParseData(pstrText, pstrDest, '<') ) return false;
         // Determine type of next element
         if( *pstrText == '\0' && iParent <= 1 ) return true;
         if( *pstrText != '<' ) return _Failed(_T("Expected end-tag start"), pstrText);
         if( pstrText[0] == '<' && pstrText[1] != '/' ) 
         {
            if( !_Parse(pstrText, iPos) ) return false;
         }
         if( pstrText[0] == '<' && pstrText[1] == '/' ) 
         {
            *pstrDest = '\0';
            *pstrText = '\0';
            pstrText += 2;
            SIZE_T cchName = pstrNameEnd - pstrName;
            if( _tcsncmp(pstrText, pstrName, cchName) != 0 ) return _Failed(_T("Unmatched closing tag"), pstrText);
            if( pstrText[cchName] != '>' ) return _Failed(_T("Unmatched closing tag"), pstrText);
            pstrText += cchName + 1;
         }
      }
      *pstrNameEnd = '\0';
      _SkipWhitespace(pstrText);
   }
}