RapidReply( const std::string& header, const std::string& reply) :document_(), header_(header) { _Parse(reply); }
bool CMarkup::LoadFromFile(LPCTSTR pstrFilename) { Release(); HANDLE hFile = ::CreateFile(pstrFilename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if( hFile == INVALID_HANDLE_VALUE ) return _Failed(_T("Error opening file")); DWORD dwSize = ::GetFileSize(hFile, NULL); if( dwSize == 0 ) return _Failed(_T("File is empty")); DWORD dwRead = 0; #ifdef _UNICODE // BUG: We don't support UNICODE file loading yet. ::CloseHandle(hFile); return false; #else m_pstrXML = static_cast<LPTSTR>(malloc(dwSize + 1)); ::ReadFile(hFile, m_pstrXML, dwSize, &dwRead, NULL); ::CloseHandle(hFile); m_pstrXML[dwSize] = '\0'; #endif // _UNICODE if( dwRead != dwSize ) { Release(); return _Failed(_T("Could not read file")); } bool bRes = _Parse(); if( !bRes ) Release(); return bRes; }
CControlUI* CDialogBuilder::Create(const char* xml, CPaintManagerUI* pManager, CControlUI* pParent) { if (!m_xml.LoadFromFile(xml)) return NULL; CMarkupNode root = m_xml.GetRoot(); if (!root.IsValid()) return NULL; if (pManager) { LPCTSTR pstrClass = NULL; LPCTSTR pstrName = NULL; LPCTSTR pstrValue = NULL; pstrClass = root.GetName(); if (strcmp(pstrClass, _T("Window")) == 0) { if (pManager->GetPaintWindow()) { int nAttributes = root.GetAttributeCount(); for (int i = 0; i < nAttributes; i++) { pstrName = root.GetAttributeName(i); pstrValue = root.GetAttributeValue(i); pManager->SetWindowAttribute(pstrName, pstrValue); } } } } return _Parse(&root, pParent, pManager); }
bool JsonHelper::GetJsonItem2(const char* node1, const char* node2, int & result) { result = 0; if (!b_parse) { _Parse(); //没分析 就分析一次 } if(m_json == NULL) { return false; } cJSON* obj1 = cJSON_GetObjectItem(m_json, node1); if(obj1 == NULL) { return false; } cJSON* obj2 = cJSON_GetObjectItem(obj1, node2); if(obj2 == NULL) { return false; } result = obj2->valueint; return true; }
bool CXmlManager::_Parse() { _ReserveElement(); // Reserve index 0 for errors ::ZeroMemory(m_szErrorMsg, sizeof(m_szErrorMsg)); ::ZeroMemory(m_szErrorXML, sizeof(m_szErrorXML)); LPTSTR pstrXML = m_pstrXML; return _Parse(pstrXML, 0); }
bool CMarkup::_Parse() { _ReserveElement(); // Reserve index 0 for errors ::ZeroMemory(m_szErrorMsg, sizeof(m_szErrorMsg)); ::ZeroMemory(m_szErrorXML, sizeof(m_szErrorXML)); wchar_t* pstrXML = m_pstrXML; return _Parse(pstrXML, 0); }
void VJSONArrayReader::FromJSONString(const VString& inJSONString) { fLastParseError = VE_OK; fValues.clear(); fVectorSize = 0; _Parse(inJSONString); }
CControlUI* CDialogBuilder::Create(LPCTSTR pstrXML, IDialogBuilderCallback* pCallback /*= NULL*/) { m_pCallback = pCallback; if( !m_xml.Load(pstrXML) ) return NULL; // NOTE: The root element is actually discarded since the _Parse() methods is // parsing children and attaching to the current node. CMarkupNode root = m_xml.GetRoot(); return _Parse(&root); }
bool CCompiler::Compile(LPCTSTR pszFile) { m_strErrMsg.Format("Compile Failed......Unknown Error"); if(false == _Parse(pszFile)) return false; if(false == _Check()) return false; m_oClassMaker.SetInfo(m_nType, m_nCharsetNet, m_nCharsetHost); if(false == m_oClassMaker.Make(&m_oMainParser, &m_oVecChildParsers, m_strHPilePath,m_strCppFilePath)) { m_strErrMsg = m_oClassMaker.GetErrMsg(); return false; } m_strErrMsg.Format("Compile OK"); return true; //if(false == _SavePos()) // return false; //if(false == m_oClassMaker.Init()) // return false; //m_fpCpp = NULL; //m_fpH = NULL; // //if(false == _ProcFileHeader()) // return false; //if(false == _ProcDefines()) // return false; //if(false == _ProcTypes()) // return false; //if(false == _ProcMessages()) // return false; //if(false == m_oClassMaker.MakeEndPart()) // return false; //m_oClassMaker.SaveToHpp(m_fpH); //m_oClassMaker.SaveToCpp(m_fpCpp); // //fprintf(m_fpH, "#endif\n"); //m_strErrMsg.Format("Compile OK"); //_CloseFile(); // //return true; }
bool CMarkup::LoadFromMem(BYTE* pByte, DWORD dwSize, int encoding) { if (encoding == XMLFILE_ENCODING_UTF8) { if( dwSize >= 3 && pByte[0] == 0xEF && pByte[1] == 0xBB && pByte[2] == 0xBF ) { pByte += 3; dwSize -= 3; } DWORD nWide = ::MultiByteToWideChar( CP_UTF8, 0, (LPCSTR)pByte, dwSize, NULL, 0 ); m_pstrXML = static_cast<wchar_t*>(malloc((nWide + 1)*sizeof(wchar_t))); ::MultiByteToWideChar( CP_UTF8, 0, (LPCSTR)pByte, dwSize, m_pstrXML, nWide ); m_pstrXML[nWide] = _T('\0'); } else if (encoding == XMLFILE_ENCODING_ASNI) { DWORD nWide = ::MultiByteToWideChar( CP_ACP, 0, (LPCSTR)pByte, dwSize, NULL, 0 ); m_pstrXML = static_cast<wchar_t*>(malloc((nWide + 1)*sizeof(wchar_t))); ::MultiByteToWideChar( CP_ACP, 0, (LPCSTR)pByte, dwSize, m_pstrXML, nWide ); m_pstrXML[nWide] = _T('\0'); } else { if ( dwSize >= 2 && ( ( pByte[0] == 0xFE && pByte[1] == 0xFF ) || ( pByte[0] == 0xFF && pByte[1] == 0xFE ) ) ) { dwSize = dwSize / 2 - 1; if ( pByte[0] == 0xFE && pByte[1] == 0xFF ) { pByte += 2; for ( DWORD nSwap = 0 ; nSwap < dwSize ; nSwap ++ ) { register CHAR nTemp = pByte[ ( nSwap << 1 ) + 0 ]; pByte[ ( nSwap << 1 ) + 0 ] = pByte[ ( nSwap << 1 ) + 1 ]; pByte[ ( nSwap << 1 ) + 1 ] = nTemp; } } else { pByte += 2; } m_pstrXML = static_cast<wchar_t*>(malloc((dwSize + 1)*sizeof(wchar_t))); ::CopyMemory( m_pstrXML, pByte, dwSize * sizeof(wchar_t) ); m_pstrXML[dwSize] = _T('\0'); pByte -= 2; } } bool bRes = _Parse(); if( !bRes ) Release(); return bRes; }
bool CMarkup::Load(LPCTSTR pstrXML) { Release(); SIZE_T cbLen = (_tcslen(pstrXML) + 1) * sizeof(TCHAR); m_pstrXML = static_cast<LPTSTR>(malloc(cbLen)); ::CopyMemory(m_pstrXML, pstrXML, cbLen); bool bRes = _Parse(); if( !bRes ) Release(); return bRes; }
bool CXmlManager::Load(LPCTSTR pstrXML) { Release(); SIZE_T cchLen = _tcslen(pstrXML) + 1; m_pstrXML = static_cast<LPTSTR>(malloc(cchLen * sizeof(TCHAR))); ::CopyMemory(m_pstrXML, pstrXML, cchLen * sizeof(TCHAR)); bool bRes = _Parse(); if( !bRes ) Release(); return bRes; }
bool CMarkup::Load(const wchar_t* pstrXML) { Release(); SIZE_T cchLen = wcslen(pstrXML) + 1; m_pstrXML = static_cast<wchar_t*>(malloc(cchLen * sizeof(wchar_t))); ::CopyMemory(m_pstrXML, pstrXML, cchLen * sizeof(wchar_t)); bool bRes = _Parse(); if( !bRes ) Release(); return bRes; }
status_t BJson::Parse(BMessage& message, BString& JSON) { try { _Parse(message, JSON); return B_OK; } catch (ParseException e) { e.PrintToStream(); return e.ReturnCode(); } return B_ERROR; }
bool CXMLResource::LoadXML(const std::string& strPath) { TiXmlDocument XmlParse; if (strPath.empty()) { return false; } if (XmlParse.LoadFile(strPath.c_str())) { return _Parse(XmlParse); } return true; }
void Cluster::Load(string filename) { //open and read file to memory if(_Read(filename) != 0) { cout <<"Error reading file"<<endl; exit; }; //parse term-doc count file _Parse(terms); //Weight by tf*idf, return total number of food items this->N = _Weight(); //normalize indices to unit vector _Norm(); set_lambda(0.5); }
int main(int argc, char *argv[]) { local_parameter p; /*************************************************** * * parsing parameters * ***************************************************/ program = argv[0]; /* no arguments */ if ( argc == 1 ) _ErrorParse( NULL, 0 ); /* parsing parameters */ _InitParam( &p ); _Parse( argc, argv, &p ); /*************************************************** * * * ***************************************************/ if (applyTrsfToPoints( p.thefile_name, p.resfile_name, p.real_transformation_name, _verbose_, _debug_)) { fprintf( stderr, "%s: Failure.\n",program); } exit( 0 ); }
bool JsonHelper::GetJsonItem(const char* node_name, string & result) { result = ""; if (!b_parse) { _Parse(); //没分析 就分析一次 } if(m_json == NULL) { return false; } cJSON* obj_find = cJSON_GetObjectItem(m_json, node_name); if(obj_find == NULL) { return false; } result = obj_find->valuestring; return true; }
XMLNode* XMLParser::Parse(wchar_t* buf, size_t bufSize) { _mBufSize = bufSize; return _Parse(buf); }
VJSONArrayReader::VJSONArrayReader(const VString& inJSONString) : fLastParseError(VE_OK), fVectorSize(0) { _Parse(inJSONString); }
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); } }
XMLNode* XMLParser::_Parse(wchar_t* buf) { std::wstring token; eCurState state = NONE; attrMap attributeMap; std::wstring attrKey; XMLNode* curNode = new XMLNode; while( _mParsingIndex < _mBufSize ) { switch( buf[_mParsingIndex] ) { case L'<': if( state == ELEMENT ) // After element, It could be either closing node or new child node { if( _IsTokenTab(token) ) // At first, delete the all gap (similar to trim function) { token.clear(); } if( buf[_mParsingIndex+1] == L'/' ) // In case of closing the node { curNode->SetElement( token ); token.clear(); state = CLOSING_NODE; ++_mParsingIndex; } else // In case of new child node { curNode->AddChild( _Parse(buf) ); } } else // In case of new node { ++_mParsingIndex; if( buf[_mParsingIndex] == L'?' || buf[_mParsingIndex] == L'!') // if new node is about xml information { _GetTokenWith(buf, L'>'); } else // Read the new node's name { token += buf[_mParsingIndex]; state = OPENING_NODE; } } break; case L'>': switch( state ) { case ATTR_VALUE: // In case that new node's attr setting is all set curNode->SetAttrMap(attributeMap); attributeMap.clear(); state = ELEMENT; break; case CLOSING_NODE: // In case that making node is all set if( curNode->GetName().compare(token) != 0 ) { delete curNode; wprintf(L"XML ERROR ( closing element's name isn't correct [%s] ) - line %d", curNode->GetName().c_str(), _mLine ); return nullptr; } return curNode; case OPENING_NODE: // In case that new node's name setting is all set curNode->SetName( token ); token.clear(); state = ELEMENT; break; default: std::wcerr<<L"SWITCH_DEFAULT : "<<__FILE__<<L" "<<__LINE__<<std::endl; return nullptr; } break; case L' ': switch( state ) { case OPENING_NODE: // After setting the name of new node curNode->SetName( token ); token.clear(); state = ATTR_VALUE; break; case ELEMENT : // if ' ' is used for element, then just use that token += L' '; break; default: std::wcerr<<L"SWITCH_DEFAULT : "<<__FILE__<<L" "<<__LINE__<<std::endl; return nullptr; } break; case L'=': switch( state ) { case ELEMENT: // If '=' is used for element, then just use that token += L'='; break; case ATTR_VALUE: // In case of setting the attribute, attribute's key will come next attrKey = token; token.clear(); state = ATTR_KEY; break; default: std::wcerr<<L"SWITCH_DEFAULT : "<<__FILE__<<L" "<<__LINE__<<std::endl; return nullptr; } break; case L'\"': switch( state ) { case ATTR_KEY: // Set the attribute's key ++_mParsingIndex; token = _GetTokenWith(buf, L'\"'); attributeMap[attrKey] = token; attrKey.clear(); token.clear(); state = ATTR_VALUE; break; default: std::wcerr<<L"SWITCH_DEFAULT : "<<__FILE__<<L" "<<__LINE__<<std::endl; return nullptr; } break; case L'/': // If node is closed by using '/>' if( state == ATTR_VALUE && buf[_mParsingIndex+1] == L'>' ) { curNode->SetAttrMap(attributeMap); attributeMap.clear(); ++_mParsingIndex; return curNode; } break; default: if( buf[_mParsingIndex] == L'\n' ) ++_mLine; else token += buf[_mParsingIndex]; break; } ++_mParsingIndex; } return nullptr; }
CControlUI* CDialogBuilder::_Parse(CMarkupNode* pRoot, CControlUI* pParent, CPaintManagerUI* pManager) { CControlUI* pReturn = NULL; for (CMarkupNode node = pRoot->GetChild(); node.IsValid(); node = node.GetSibling()) { LPCTSTR pstrClass = node.GetName(); CControlUI* pControl = NULL; if (strcmp(pstrClass, _T("Include")) == 0) { if (!node.HasAttributes()) continue; } else if (strcmp(pstrClass, _T("TreeNode")) == 0) { } else { SIZE_T cchLen = strlen(pstrClass); switch (cchLen) { case 5: if (strcmp(pstrClass, DUI_CTR_LABEL) == 0) pControl = new CLabelUI; break; case 9: if (strcmp(pstrClass, DUI_CTR_CONTAINER) == 0) pControl = new CContainerUI; break; case 7: if (strcmp(pstrClass, DUI_CTR_CONTROL) == 0) pControl = new CControlUI; } } if (pControl == NULL) continue; if (node.HasChildren()) { _Parse(&node, pControl, pManager); } if (pParent != NULL) { if (pParent->GetClass() == DUI_CTR_CONTAINER) { IContainerUI* pContainer = static_cast<IContainerUI*>(pParent->GetInterface(DUI_CTR_ICONTAINER)); pContainer->Add(pControl); } } if (node.HasAttributes()) { // Set ordinary attributes int nAttributes = node.GetAttributeCount(); for (int i = 0; i < nAttributes; i++) { pControl->SetAttribute(node.GetAttributeName(i), node.GetAttributeValue(i)); } } if (pManager) { pControl->SetManager(pManager, pParent, false); } if (pReturn == NULL) pReturn = pControl; } return pReturn; }
bool CXmlManager::LoadFromMem(BYTE* pByte, DWORD dwSize, int encoding) { #ifdef _UNICODE if (encoding == XMLFILE_ENCODING_UTF8) { DWORD nWide = ::MultiByteToWideChar( CP_UTF8, 0, (LPCSTR)pByte, dwSize, NULL, 0 ); m_pstrXML = static_cast<LPTSTR>(malloc((nWide + 1)*sizeof(TCHAR))); ::MultiByteToWideChar( CP_UTF8, 0, (LPCSTR)pByte, dwSize, m_pstrXML, nWide ); m_pstrXML[nWide] = _T('\0'); } else if (encoding == XMLFILE_ENCODING_ASNI) { DWORD nWide = ::MultiByteToWideChar( CP_ACP, 0, (LPCSTR)pByte, dwSize, NULL, 0 ); m_pstrXML = static_cast<LPTSTR>(malloc((nWide + 1)*sizeof(TCHAR))); ::MultiByteToWideChar( CP_ACP, 0, (LPCSTR)pByte, dwSize, m_pstrXML, nWide ); m_pstrXML[nWide] = _T('\0'); } else { if ( dwSize >= 2 && ( ( pByte[0] == 0xFE && pByte[1] == 0xFF ) || ( pByte[0] == 0xFF && pByte[1] == 0xFE ) ) ) { dwSize = dwSize / 2 - 1; if ( pByte[0] == 0xFE && pByte[1] == 0xFF ) { pByte += 2; for ( DWORD nSwap = 0 ; nSwap < dwSize ; nSwap ++ ) { register CHAR nTemp = pByte[ ( nSwap << 1 ) + 0 ]; pByte[ ( nSwap << 1 ) + 0 ] = pByte[ ( nSwap << 1 ) + 1 ]; pByte[ ( nSwap << 1 ) + 1 ] = nTemp; } } else { pByte += 2; } m_pstrXML = static_cast<LPTSTR>(malloc((dwSize + 1)*sizeof(TCHAR))); ::CopyMemory( m_pstrXML, pByte, dwSize * sizeof(TCHAR) ); m_pstrXML[dwSize] = _T('\0'); pByte -= 2; } } #else // !_UNICODE if (encoding == XMLFILE_ENCODING_UTF8) { DWORD nWide = ::MultiByteToWideChar( CP_UTF8, 0, (LPCSTR)pByte, dwSize, NULL, 0 ); LPWSTR w_str = static_cast<LPWSTR>(malloc((nWide + 1)*sizeof(WCHAR))); ::MultiByteToWideChar( CP_UTF8, 0, (LPCSTR)pByte, dwSize, w_str, nWide ); w_str[nWide] = L'\0'; DWORD wide = ::WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)w_str, nWide, NULL, 0, NULL, NULL); m_pstrXML = static_cast<LPTSTR>(malloc((wide + 1)*sizeof(TCHAR))); ::WideCharToMultiByte( CP_ACP, 0, (LPCWSTR)w_str, nWide, m_pstrXML, wide, NULL, NULL); m_pstrXML[wide] = _T('\0'); free(w_str); } else if (encoding == XMLFILE_ENCODING_UNICODE) { if ( dwSize >= 2 && ( ( pByte[0] == 0xFE && pByte[1] == 0xFF ) || ( pByte[0] == 0xFF && pByte[1] == 0xFE ) ) ) { dwSize = dwSize / 2 - 1; if ( pByte[0] == 0xFE && pByte[1] == 0xFF ) { pByte += 2; for ( DWORD nSwap = 0 ; nSwap < dwSize ; nSwap ++ ) { register CHAR nTemp = pByte[ ( nSwap << 1 ) + 0 ]; pByte[ ( nSwap << 1 ) + 0 ] = pByte[ ( nSwap << 1 ) + 1 ]; pByte[ ( nSwap << 1 ) + 1 ] = nTemp; } } else { pByte += 2; } DWORD nWide = ::WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)pByte, dwSize, NULL, 0, NULL, NULL); m_pstrXML = static_cast<LPTSTR>(malloc((nWide + 1)*sizeof(TCHAR))); ::WideCharToMultiByte( CP_ACP, 0, (LPCWSTR)pByte, dwSize, m_pstrXML, nWide, NULL, NULL); m_pstrXML[nWide] = _T('\0'); pByte -= 2; } } else { m_pstrXML = static_cast<LPTSTR>(malloc((dwSize + 1)*sizeof(TCHAR))); ::CopyMemory( m_pstrXML, pByte, dwSize * sizeof(TCHAR) ); m_pstrXML[dwSize] = _T('\0'); } #endif // _UNICODE bool bRes = _Parse(); if( !bRes ) Release(); return bRes; }
CControlUI* CDialogBuilder::_Parse(CMarkupNode* pRoot, CControlUI* pParent) { CDialogLayoutUI* pStretched = NULL; IContainerUI* pContainer = NULL; CControlUI* pReturn = NULL; for( CMarkupNode node = pRoot->GetChild() ; node.IsValid(); node = node.GetSibling() ) { LPCTSTR pstrClass = node.GetName(); SIZE_T cchLen = _tcslen(pstrClass); CControlUI* pControl = NULL; switch( cchLen ) { case 4: if( _tcscmp(pstrClass, _T("List")) == 0 ) pControl = new CListUI; break; case 6: if( _tcscmp(pstrClass, _T("Canvas")) == 0 ) pControl = new CCanvasUI; else if( _tcscmp(pstrClass, _T("Button")) == 0 ) pControl = new CButtonUI; else if( _tcscmp(pstrClass, _T("Option")) == 0 ) pControl = new COptionUI; break; case 7: if( _tcscmp(pstrClass, _T("Toolbar")) == 0 ) pControl = new CToolbarUI; else if( _tcscmp(pstrClass, _T("TabPage")) == 0 ) pControl = new CTabPageUI; else if( _tcscmp(pstrClass, _T("ActiveX")) == 0 ) pControl = new CActiveXUI; break; case 8: if( _tcscmp(pstrClass, _T("DropDown")) == 0 ) pControl = new CDropDownUI; break; case 9: if( _tcscmp(pstrClass, _T("FadedLine")) == 0 ) pControl = new CFadedLineUI; else if( _tcscmp(pstrClass, _T("TaskPanel")) == 0 ) pControl = new CTaskPanelUI; else if( _tcscmp(pstrClass, _T("Statusbar")) == 0 ) pControl = new CStatusbarUI; else if( _tcscmp(pstrClass, _T("TabFolder")) == 0 ) pControl = new CTabFolderUI; else if( _tcscmp(pstrClass, _T("TextPanel")) == 0 ) pControl = new CTextPanelUI; break; case 10: if( _tcscmp(pstrClass, _T("ListHeader")) == 0 ) pControl = new CListHeaderUI; else if( _tcscmp(pstrClass, _T("ListFooter")) == 0 ) pControl = new CListFooterUI; else if( _tcscmp(pstrClass, _T("TileLayout")) == 0 ) pControl = new CTileLayoutUI; else if( _tcscmp(pstrClass, _T("ToolButton")) == 0 ) pControl = new CToolButtonUI; else if( _tcscmp(pstrClass, _T("ImagePanel")) == 0 ) pControl = new CImagePanelUI; else if( _tcscmp(pstrClass, _T("LabelPanel")) == 0 ) pControl = new CLabelPanelUI; break; case 11: if( _tcscmp(pstrClass, _T("ToolGripper")) == 0 ) pControl = new CToolGripperUI; else if( _tcscmp(pstrClass, _T("WhiteCanvas")) == 0 ) pControl = new CWhiteCanvasUI; else if( _tcscmp(pstrClass, _T("TitleShadow")) == 0 ) pControl = new CTitleShadowUI; break; case 12: if( _tcscmp(pstrClass, _T("WindowCanvas")) == 0 ) pControl = new CWindowCanvasUI; else if( _tcscmp(pstrClass, _T("DialogCanvas")) == 0 ) pControl = new CDialogCanvasUI; else if( _tcscmp(pstrClass, _T("DialogLayout")) == 0 ) pControl = new CDialogLayoutUI; else if( _tcscmp(pstrClass, _T("PaddingPanel")) == 0 ) pControl = new CPaddingPanelUI; else if( _tcscmp(pstrClass, _T("WarningPanel")) == 0 ) pControl = new CWarningPanelUI; break; case 13: if( _tcscmp(pstrClass, _T("SeparatorLine")) == 0 ) pControl = new CSeparatorLineUI; else if( _tcscmp(pstrClass, _T("ControlCanvas")) == 0 ) pControl = new CControlCanvasUI; else if( _tcscmp(pstrClass, _T("MultiLineEdit")) == 0 ) pControl = new CMultiLineEditUI; else if( _tcscmp(pstrClass, _T("ToolSeparator")) == 0 ) pControl = new CToolSeparatorUI; break; case 14: if( _tcscmp(pstrClass, _T("VerticalLayout")) == 0 ) pControl = new CVerticalLayoutUI; else if( _tcscmp(pstrClass, _T("SingleLineEdit")) == 0 ) pControl = new CSingleLineEditUI; else if( _tcscmp(pstrClass, _T("SingleLinePick")) == 0 ) pControl = new CSingleLinePickUI; else if( _tcscmp(pstrClass, _T("NavigatorPanel")) == 0 ) pControl = new CNavigatorPanelUI; else if( _tcscmp(pstrClass, _T("ListHeaderItem")) == 0 ) pControl = new CListHeaderItemUI; else if( _tcscmp(pstrClass, _T("GreyTextHeader")) == 0 ) pControl = new CGreyTextHeaderUI; break; case 15: if( _tcscmp(pstrClass, _T("ListTextElement")) == 0 ) pControl = new CListTextElementUI; else if( _tcscmp(pstrClass, _T("NavigatorButton")) == 0 ) pControl = new CNavigatorButtonUI; else if( _tcscmp(pstrClass, _T("TabFolderCanvas")) == 0 ) pControl = new CTabFolderCanvasUI; break; case 16: if( _tcscmp(pstrClass, _T("ListHeaderShadow")) == 0 ) pControl = new CListHeaderShadowUI; else if( _tcscmp(pstrClass, _T("HorizontalLayout")) == 0 ) pControl = new CHorizontalLayoutUI; else if( _tcscmp(pstrClass, _T("ListLabelElement")) == 0 ) pControl = new CListLabelElementUI; else if( _tcscmp(pstrClass, _T("SearchTitlePanel")) == 0 ) pControl = new CSearchTitlePanelUI; break; case 17: if( _tcscmp(pstrClass, _T("ToolbarTitlePanel")) == 0 ) pControl = new CToolbarTitlePanelUI; else if( _tcscmp(pstrClass, _T("ListExpandElement")) == 0 ) pControl = new CListExpandElementUI; break; } // User-supplied control factory if( pControl == NULL && m_pCallback != NULL ) { pControl = m_pCallback->CreateControl(pstrClass); } ASSERT(pControl); if( pControl == NULL ) return NULL; // Add children if( node.HasChildren() ) { _Parse(&node, pControl); } // Attach to parent if( pParent != NULL ) { if( pContainer == NULL ) pContainer = static_cast<IContainerUI*>(pParent->GetInterface(_T("Container"))); ASSERT(pContainer); if( pContainer == NULL ) return NULL; pContainer->Add(pControl); } // Process attributes if( node.HasAttributes() ) { TCHAR szValue[500] = { 0 }; SIZE_T cchLen = lengthof(szValue) - 1; // Set ordinary attributes int nAttributes = node.GetAttributeCount(); for( int i = 0; i < nAttributes; i++ ) { pControl->SetAttribute(node.GetAttributeName(i), node.GetAttributeValue(i)); } // Very custom attributes if( node.GetAttributeValue(_T("stretch"), szValue, cchLen) ) { if( pStretched == NULL ) pStretched = static_cast<CDialogLayoutUI*>(pParent->GetInterface(_T("DialogLayout"))); ASSERT(pStretched); if( pStretched == NULL ) return NULL; UINT uMode = 0; if( _tcsstr(szValue, _T("move_x")) != NULL ) uMode |= UISTRETCH_MOVE_X; if( _tcsstr(szValue, _T("move_y")) != NULL ) uMode |= UISTRETCH_MOVE_Y; if( _tcsstr(szValue, _T("move_xy")) != NULL ) uMode |= UISTRETCH_MOVE_X | UISTRETCH_MOVE_Y; if( _tcsstr(szValue, _T("size_x")) != NULL ) uMode |= UISTRETCH_SIZE_X; if( _tcsstr(szValue, _T("size_y")) != NULL ) uMode |= UISTRETCH_SIZE_Y; if( _tcsstr(szValue, _T("size_xy")) != NULL ) uMode |= UISTRETCH_SIZE_X | UISTRETCH_SIZE_Y; if( _tcsstr(szValue, _T("group")) != NULL ) uMode |= UISTRETCH_NEWGROUP; if( _tcsstr(szValue, _T("line")) != NULL ) uMode |= UISTRETCH_NEWLINE; pStretched->SetStretchMode(pControl, uMode); } } // Return first item if( pReturn == NULL ) pReturn = pControl; } return pReturn; }
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); } }