xmluri.cpp
来自「IBM的解析xml的工具Xerces的源代码」· C++ 代码 · 共 2,222 行 · 第 1/5 页
CPP
2,222 行
} } else if (!isUnreservedCharacter(testChar) && !isPathCharacter(testChar)) { XMLCh value1[BUF_LEN+1]; value1[0] = testChar; value1[1] = chNull; ThrowXMLwithMemMgr2(MalformedURLException , XMLExcepts::XMLNUM_URI_Component_Invalid_Char , errMsg_PATH , value1 , fMemoryManager); } index++; }//while (index < end) } else { // Scan opaque part. // opaque_part = uric_no_slash *uric while (index < end) { testChar = uriSpec[index]; if (testChar == chQuestion || testChar == chPound) { break; } // check for valid escape sequence if (testChar == chPercent) { if (index+2 >= end || !XMLString::isHex(uriSpec[index+1]) || !XMLString::isHex(uriSpec[index+2])) { XMLCh value1[BUF_LEN+1]; XMLString::moveChars(value1, &(uriSpec[index]), 3); value1[3] = chNull; ThrowXMLwithMemMgr2(MalformedURLException , XMLExcepts::XMLNUM_URI_Component_Invalid_EscapeSequence , errMsg_PATH , value1 , fMemoryManager); } } // If the scheme specific part is opaque, it can contain '[' // and ']'. uric_no_slash wasn't modified by RFC 2732, which // I've interpreted as an error in the spec, since the // production should be equivalent to (uric - '/'), and uric // contains '[' and ']'. else if (!isReservedOrUnreservedCharacter(testChar)) { XMLCh value1[BUF_LEN+1]; value1[0] = testChar; value1[1] = chNull; ThrowXMLwithMemMgr2(MalformedURLException , XMLExcepts::XMLNUM_URI_Component_Invalid_Char , errMsg_PATH , value1 , fMemoryManager); } index++; }//while (index < end) } } //if (start < end) if (getPath()) { fMemoryManager->deallocate(fPath);//delete [] fPath; } fPath = (XMLCh*) fMemoryManager->allocate((index+1) * sizeof(XMLCh));//new XMLCh[index+1]; XMLString::subString(fPath, uriSpec, start, index, fMemoryManager); // query - starts with ? and up to fragment or end if (testChar == chQuestion) { index++; start = index; while (index < end) { testChar = uriSpec[index]; if (testChar == chPound) { break; } if (testChar == chPercent) { if (index+2 >= end || !XMLString::isHex(uriSpec[index+1]) || !XMLString::isHex(uriSpec[index+2])) { XMLCh value1[BUF_LEN+1]; XMLString::moveChars(value1, &(uriSpec[index]), 3); value1[3] = chNull; ThrowXMLwithMemMgr2(MalformedURLException , XMLExcepts::XMLNUM_URI_Component_Invalid_EscapeSequence , errMsg_QUERY , value1 , fMemoryManager); } } else if (!isReservedOrUnreservedCharacter(testChar)) { XMLCh value1[BUF_LEN+1]; value1[0] = testChar; value1[1] = chNull; ThrowXMLwithMemMgr2(MalformedURLException , XMLExcepts::XMLNUM_URI_Component_Invalid_Char , errMsg_QUERY , value1 , fMemoryManager); } index++; } if (getQueryString()) { fMemoryManager->deallocate(fQueryString);//delete [] fQueryString; } fQueryString = (XMLCh*) fMemoryManager->allocate ( (index - start + 1) * sizeof(XMLCh) );//new XMLCh[index - start + 1]; XMLString::subString(fQueryString, uriSpec, start, index, fMemoryManager); } // fragment - starts with # if (testChar == chPound) { index++; start = index; while (index < end) { testChar = uriSpec[index]; if (testChar == chPercent) { if (index+2 >= end || !XMLString::isHex(uriSpec[index+1]) || !XMLString::isHex(uriSpec[index+2])) { XMLCh value1[BUF_LEN+1]; XMLString::moveChars(value1, &(uriSpec[index]), 3); value1[3] = chNull; ThrowXMLwithMemMgr2(MalformedURLException , XMLExcepts::XMLNUM_URI_Component_Invalid_EscapeSequence , errMsg_FRAGMENT , value1 , fMemoryManager); } } else if (!isReservedOrUnreservedCharacter(testChar)) { XMLCh value1[BUF_LEN+1]; value1[0] = testChar; value1[1] = chNull; ThrowXMLwithMemMgr2(MalformedURLException , XMLExcepts::XMLNUM_URI_Component_Invalid_Char , errMsg_FRAGMENT , value1 , fMemoryManager); } index++; } if (getFragment()) fMemoryManager->deallocate(fFragment);//delete [] fFragment; //make sure that there is something following the '#' if (index > start) { fFragment = (XMLCh*) fMemoryManager->allocate ( (index - start + 1) * sizeof(XMLCh) );//new XMLCh[index - start + 1]; XMLString::subString(fFragment, uriSpec, start, index, fMemoryManager); } else { // RFC 2396, 4.0. URI Reference // URI-reference = [absoulteURI | relativeURI] [# fragment] // // RFC 2396, 4.1. Fragment Identifier // fragment = *uric // // empty fragment is valid fFragment = 0; } }}// ---------------------------------------------------------------------------// Setter// ---------------------------------------------------------------------------void XMLUri::setScheme(const XMLCh* const newScheme){ if ( !newScheme ) { ThrowXMLwithMemMgr1(MalformedURLException , XMLExcepts::XMLNUM_URI_Component_Set_Null , errMsg_SCHEME , fMemoryManager); } if (!isConformantSchemeName(newScheme)) { ThrowXMLwithMemMgr2(MalformedURLException , XMLExcepts::XMLNUM_URI_Component_Not_Conformant , errMsg_SCHEME , newScheme , fMemoryManager); } if (getScheme()) { fMemoryManager->deallocate(fScheme);//delete [] fScheme; } fScheme = XMLString::replicate(newScheme, fMemoryManager); XMLString::lowerCase(fScheme);}//// server = [ [ userinfo "@" ] hostport ]// hostport = host [":" port]//// setUserInfo(), setHost() and setPort() are closely related// three methods, in a word, userinfo and port has dependency// on host.//// if host is not present, userinfo must be null and port = -1//void XMLUri::setUserInfo(const XMLCh* const newUserInfo){ if ( newUserInfo && !getHost() ) { ThrowXMLwithMemMgr2(MalformedURLException , XMLExcepts::XMLNUM_URI_NullHost , errMsg_USERINFO , newUserInfo , fMemoryManager); } try { isConformantUserInfo(newUserInfo, fMemoryManager); } catch(const OutOfMemoryException&) { throw; } catch (...) { throw; } if (getUserInfo()) { fMemoryManager->deallocate(fUserInfo);//delete [] fUserInfo; } //sometimes we get passed a empty string rather than a null. //Other procedures rely on it being null if(newUserInfo && *newUserInfo) { fUserInfo = XMLString::replicate(newUserInfo, fMemoryManager); } else fUserInfo = 0;}void XMLUri::setHost(const XMLCh* const newHost){ if ( !newHost ) { if (getHost()) fMemoryManager->deallocate(fHost);//delete [] fHost; fHost = 0; setUserInfo(0); setPort(-1); return; } if ( *newHost && !isWellFormedAddress(newHost, fMemoryManager)) { ThrowXMLwithMemMgr2(MalformedURLException , XMLExcepts::XMLNUM_URI_Component_Not_Conformant , errMsg_HOST , newHost , fMemoryManager); } if (getHost()) { fMemoryManager->deallocate(fHost);//delete [] fHost; } fHost = XMLString::replicate(newHost, fMemoryManager); setRegBasedAuthority(0);}void XMLUri::setPort(int newPort){ if (newPort >= 0 && newPort <= 65535) { if (!getHost()) { XMLCh value1[BUF_LEN+1]; XMLString::binToText(newPort, value1, BUF_LEN, 10, fMemoryManager); ThrowXMLwithMemMgr2(MalformedURLException , XMLExcepts::XMLNUM_URI_NullHost , errMsg_PORT , value1 , fMemoryManager); } } else if (newPort != -1) { XMLCh value1[BUF_LEN+1]; XMLString::binToText(newPort, value1, BUF_LEN, 10, fMemoryManager); ThrowXMLwithMemMgr1(MalformedURLException , XMLExcepts::XMLNUM_URI_PortNo_Invalid , value1 , fMemoryManager); } fPort = newPort;}void XMLUri::setRegBasedAuthority(const XMLCh* const newRegAuth){ if ( !newRegAuth ) { if (getRegBasedAuthority()) fMemoryManager->deallocate(fRegAuth);//delete [] fRegAuth; fRegAuth = 0; return; } // reg_name = 1*( unreserved | escaped | "$" | "," | // ";" | ":" | "@" | "&" | "=" | "+" ) else if ( !*newRegAuth || !isValidRegistryBasedAuthority(newRegAuth) ) { ThrowXMLwithMemMgr2(MalformedURLException , XMLExcepts::XMLNUM_URI_Component_Not_Conformant , errMsg_REGNAME , newRegAuth , fMemoryManager); } if (getRegBasedAuthority()) fMemoryManager->deallocate(fRegAuth);//delete [] fRegAuth; fRegAuth = XMLString::replicate(newRegAuth, fMemoryManager); setHost(0);}//// setPath(), setQueryString() and setFragment() are closely// related three methods as well.//void XMLUri::setPath(const XMLCh* const newPath){ if (!newPath) { if (getPath()) fMemoryManager->deallocate(fPath);//delete [] fPath; fPath = 0; setQueryString(0); setFragment(0); } else { initializePath(newPath); }}//// fragment = *uric//void XMLUri::setFragment(const XMLCh* const newFragment){ if ( !newFragment ) { if (getFragment()) fMemoryManager->deallocate(fFragment);//delete [] fFragment; fFragment = 0; } else if (!isGenericURI()) { ThrowXMLwithMemMgr2(MalformedURLException , XMLExcepts::XMLNUM_URI_Component_for_GenURI_Only , errMsg_FRAGMENT , newFragment , fMemoryManager); } else if ( !getPath() ) { ThrowXMLwithMemMgr2(MalformedURLException , XMLExcepts::XMLNUM_URI_NullPath , errMsg_FRAGMENT , newFragment , fMemoryManager); } else if (!isURIString(newFragment)) { ThrowXMLwithMemMgr1(MalformedURLException , XMLExcepts::XMLNUM_URI_Component_Invalid_Char , errMsg_FRAGMENT , fMemoryManager); } else { if (getFragment()) { fMemoryManager->deallocate(fFragment);//delete [] fFragment; } fFragment = XMLString::replicate(newFragment, fMemoryManager); }}//// query = *uric//void XMLUri::setQueryString(const XMLCh* const newQueryString){ if ( !newQueryString ) { if (getQueryString()) fMemoryManager->deallocate(fQueryString);//delete [] fQueryString;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?