?? xmlstring.cpp
字號:
{ // Refer this one to the transcoding service XMLPlatformUtils::fgTransService->upperCase(toUpperCase);}void XMLString::lowerCase(XMLCh* const toLowerCase){ // Refer this one to the transcoding service XMLPlatformUtils::fgTransService->lowerCase(toLowerCase);}void XMLString::subString(XMLCh* const targetStr, const XMLCh* const srcStr , const int startIndex, const int endIndex , MemoryManager* const manager){ //if (startIndex < 0 || endIndex < 0) // ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::Str_NegativeIndex); if (targetStr == 0) ThrowXMLwithMemMgr(IllegalArgumentException, XMLExcepts::Str_ZeroSizedTargetBuf, manager); const int srcLen = stringLen(srcStr); const int copySize = endIndex - startIndex; // Make sure the start index is within the XMLString bounds if ( startIndex < 0 || startIndex > endIndex || endIndex > srcLen) ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::Str_StartIndexPastEnd, manager); for (int i= startIndex; i < endIndex; i++) { targetStr[i-startIndex] = srcStr[i]; } targetStr[copySize] = 0;}BaseRefVectorOf<XMLCh>* XMLString::tokenizeString(const XMLCh* const tokenizeSrc , MemoryManager* const manager){ XMLCh* orgText = replicate(tokenizeSrc, manager); ArrayJanitor<XMLCh> janText(orgText, manager); XMLCh* tokenizeStr = orgText; RefArrayVectorOf<XMLCh>* tokenStack = new (manager) RefArrayVectorOf<XMLCh>(16, true, manager); unsigned int len = stringLen(tokenizeStr); unsigned int skip; unsigned int index = 0; while (index != len) { // find the first non-space character for (skip = index; skip < len; skip++) { if (!XMLPlatformUtils::fgTransService->isSpace(tokenizeStr[skip])) break; } index = skip; // find the delimiter (space character) for (; skip < len; skip++) { if (XMLPlatformUtils::fgTransService->isSpace(tokenizeStr[skip])) break; } // we reached the end of the string if (skip == index) break; // these tokens are adopted in the RefVector and will be deleted // when the vector is deleted by the caller XMLCh* token = (XMLCh*) manager->allocate ( (skip+1-index) * sizeof(XMLCh) );//new XMLCh[skip+1-index]; XMLString::subString(token, tokenizeStr, index, skip, manager); tokenStack->addElement(token); index = skip; } return tokenStack;}//// This method is called when we get a notation or enumeration type attribute// to validate. We have to confirm that the passed value to find is one of// the values in the passed list. The list is a space separated string of// values to match against.//bool XMLString::isInList(const XMLCh* const toFind, const XMLCh* const enumList){ // // We loop through the values in the list via this outer loop. We end // when we hit the end of the enum list or get a match. // const XMLCh* listPtr = enumList; const unsigned int findLen = XMLString::stringLen(toFind); while (*listPtr) { unsigned int testInd; for (testInd = 0; testInd < findLen; testInd++) { // // If they don't match, then reset and try again. Note that // hitting the end of the current item will cause a mismatch // because there can be no spaces in the toFind string. // if (listPtr[testInd] != toFind[testInd]) break; } // // If we went the distance, see if we matched. If we did, the current // list character has to be null or space. // if (testInd == findLen) { if ((listPtr[testInd] == chSpace) || !listPtr[testInd]) return true; } // Run the list pointer up to the next substring while ((*listPtr != chSpace) && *listPtr) listPtr++; // If we hit the end, then we failed if (!*listPtr) return false; // Else move past the space and try again listPtr++; } // We never found it return false;}//// a string is whitespace:replaced, is having no// #xD Carriage Return// #xA Line Feed// #x9 TAB//bool XMLString::isWSReplaced(const XMLCh* const toCheck){ // If no string, then its a OK if (( !toCheck ) || ( !*toCheck )) return true; const XMLCh* startPtr = toCheck; while ( *startPtr ) { if ( ( *startPtr == chCR) || ( *startPtr == chLF) || ( *startPtr == chHTab)) return false; startPtr++; } return true;}//// to replace characters listed below to #x20// #xD Carriage Return// #xA Line Feed// #x9 TAB//void XMLString::replaceWS(XMLCh* const toConvert , MemoryManager* const manager){ int strLen = XMLString::stringLen(toConvert); if (strLen == 0) return; XMLCh* retBuf = (XMLCh*) manager->allocate ( (strLen+1) * sizeof(XMLCh) );//new XMLCh[strLen+1]; XMLCh* retPtr = &(retBuf[0]); XMLCh* startPtr = toConvert; while ( *startPtr ) { if ( ( *startPtr == chCR) || ( *startPtr == chLF) || ( *startPtr == chHTab)) *retPtr = chSpace; else *retPtr = *startPtr; retPtr++; startPtr++; } retBuf[strLen] = chNull; XMLString::moveChars(toConvert, retBuf, strLen); manager->deallocate(retBuf);//delete[] retBuf; return;}//// a string is whitespace:collapsed, is whitespace::replaced// and no// leading space (#x20)// trailing space// no contiguous sequences of spaces//bool XMLString::isWSCollapsed(const XMLCh* const toCheck){ if (( !toCheck ) || ( !*toCheck )) return true; // shall be whitespace::replaced first if ( !isWSReplaced(toCheck) ) return false; // no leading or trailing space if ((*toCheck == chSpace) || (toCheck[XMLString::stringLen(toCheck)-1] == chSpace)) return false; const XMLCh* startPtr = toCheck; XMLCh theChar; bool inSpace = false; while ( (theChar = *startPtr) != 0 ) { if ( theChar == chSpace) { if (inSpace) return false; else inSpace = true; } else inSpace = false; startPtr++; } return true;}//// no leading and/or trailing spaces// no continuous sequences of spaces//void XMLString::collapseWS(XMLCh* const toConvert , MemoryManager* const manager){ // If no string, then its a failure if (( !toConvert ) || ( !*toConvert )) return; // replace whitespace first replaceWS(toConvert, manager); // remove leading spaces const XMLCh* startPtr = toConvert; while ( *startPtr == chSpace ) startPtr++; if (!*startPtr) return; // remove trailing spaces const XMLCh* endPtr = toConvert + stringLen(toConvert); while (*(endPtr - 1) == chSpace) endPtr--; // // Work through what remains and chop continuous spaces // XMLCh* retBuf = (XMLCh*) manager->allocate ( (endPtr - startPtr + 1) * sizeof(XMLCh) );//new XMLCh[endPtr - startPtr + 1]; XMLCh* retPtr = &(retBuf[0]); bool inSpace = false; while (startPtr < endPtr) { if ( *startPtr == chSpace) { if (inSpace) { //discard it; } else { inSpace = true; *retPtr = chSpace; //copy the first chSpace retPtr++; } } else { inSpace = false; *retPtr = *startPtr; retPtr++; } startPtr++; } *retPtr = chNull; XMLString::moveChars(toConvert, retBuf, stringLen(retBuf)+1); //copy the last chNull as well manager->deallocate(retBuf);//delete[] retBuf; return;}//// remove whitespace//void XMLString::removeWS(XMLCh* const toConvert , MemoryManager* const manager){ // If no string, then its a failure if (( !toConvert ) || ( !*toConvert )) return; XMLCh* retBuf = (XMLCh*) manager->allocate ( (XMLString::stringLen(toConvert) + 1) * sizeof(XMLCh) );//new XMLCh[ XMLString::stringLen(toConvert) + 1]; XMLCh* retPtr = &(retBuf[0]); XMLCh* startPtr = toConvert; while (*startPtr) { if ( ( *startPtr != chCR) && ( *startPtr != chLF) && ( *startPtr != chHTab) && ( *startPtr != chSpace) ) { *retPtr++ = *startPtr; } startPtr++; } *retPtr = chNull; XMLString::moveChars(toConvert, retBuf, stringLen(retBuf)+1); //copy the last chNull as well manager->deallocate(retBuf);//delete[] retBuf; return;}void XMLString::removeChar(const XMLCh* const srcString , const XMLCh& toRemove , XMLBuffer& dstBuffer){ const XMLCh* pszSrc = srcString; XMLCh c; dstBuffer.reset(); while (c=*pszSrc++) { if (c != toRemove) dstBuffer.append(c); }}/** * Fixes a platform dependent absolute path filename to standard URI form. * 1. Windows: fix 'x:' to 'file:///x:' and convert any backslash to forward slash * 2. UNIX: fix '/blah/blahblah' to 'file:///blah/blahblah' */void XMLString::fixURI(const XMLCh* const str, XMLCh* const target){ if (!str || !*str) return; int colonIdx = XMLString::indexOf(str, chColon); // If starts with a '/' we assume // this is an absolute (UNIX) file path and prefix it with file:// if (colonIdx == -1 && XMLString::indexOf(str, chForwardSlash) == 0) { unsigned index = 0; target[index++] = chLatin_f; target[index++] = chLatin_i; target[index++] = chLatin_l; target[index++] = chLatin_e; target[index++] = chColon; target[index++] = chForwardSlash; target[index++] = chForwardSlash; // copy the string const XMLCh* inPtr = str; while (*inPtr) target[index++] = *inPtr++; target[index] = chNull; } else if (colonIdx == 1 && XMLString::isAlpha(*str)) { // If starts with a driver letter 'x:' we assume // this is an absolute (Windows) file path and prefix it with file:/// unsigned index = 0; target[index++] = chLatin_f; target[index++] = chLatin_i; target[index++] = chLatin_l; target[index++] = chLatin_e; target[index++] = chColon; target[index++] = chForwardSlash; target[index++] = chForwardSlash; target[index++] = chForwardSlash; // copy the string and fix any backward slash const XMLCh* inPtr = str; while (*inPtr) { if (*inPtr == chYenSign || *inPtr == chWonSign || *inPtr == chBackSlash) target[index++] = chForwardSlash; else target[index++] = *inPtr; inPtr++; } // cap it with null target[index] = chNull; } else { // not specific case, so just copy the string over copyString(target, str); }}void XMLString::release(char** buf){ delete [] *buf; *buf = 0;}void XMLString::release(XMLCh** buf){ delete [] *buf; *buf = 0;}void XMLString::release(XMLByte** buf){ delete [] *buf; *buf = 0;}// ---------------------------------------------------------------------------// XMLString: Private static methods// ---------------------------------------------------------------------------void XMLString::initString(XMLLCPTranscoder* const defToUse, MemoryManager* const manager){ // Store away the default transcoder that we are to use gTranscoder = defToUse; // Store memory manager fgMemoryManager = manager;}void XMLString::termString(){ // Just clean up our local code page transcoder delete gTranscoder; gTranscoder = 0; // reset memory manager fgMemoryManager = 0;}XERCES_CPP_NAMESPACE_END
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -