diff --git a/src/xercesc/util/XMLString.cpp b/src/xercesc/util/XMLString.cpp index a13bbe451074609c1f6a27f7bdaa457058632e6b..8ec1a0b5a3c770c313bd7c4fd4ecc8695dddb203 100644 --- a/src/xercesc/util/XMLString.cpp +++ b/src/xercesc/util/XMLString.cpp @@ -1582,6 +1582,54 @@ void XMLString::subString(XMLCh* const targetStr, const XMLCh* const srcStr targetStr[copySize] = 0; } +BaseRefVectorOf<XMLCh>* XMLString::tokenizeString(const XMLCh* const tokenizeSrc + , XMLCh delimiter + , 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); + + XMLSize_t len = stringLen(tokenizeStr); + XMLSize_t skip; + XMLSize_t index = 0; + + while (index != len) { + // find the first non-space character + for (skip = index; skip < len; skip++) + { + if (tokenizeStr[skip]!=delimiter) + break; + } + index = skip; + + // find the delimiter (space character) + for (; skip < len; skip++) + { + if (tokenizeStr[skip]==delimiter) + 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, len, manager); + tokenStack->addElement(token); + index = skip; + } + return tokenStack; +} + BaseRefVectorOf<XMLCh>* XMLString::tokenizeString(const XMLCh* const tokenizeSrc , MemoryManager* const manager) { diff --git a/src/xercesc/util/XMLString.hpp b/src/xercesc/util/XMLString.hpp index c47c16fb78ba94dc5e1d541541b0ed8ba9566c0f..57da0bf1ef0454ab14332788ee8b61e88410eb12 100644 --- a/src/xercesc/util/XMLString.hpp +++ b/src/xercesc/util/XMLString.hpp @@ -1247,6 +1247,17 @@ public: static BaseRefVectorOf<XMLCh>* tokenizeString(const XMLCh* const tokenizeSrc , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); + /** Break a string into tokens with the given character as delimiter, and + * stored in a string vector. The caller owns the string vector + * that is returned, and is responsible for deleting it. + * @param tokenizeSrc String to be tokenized + * @param delimiter Delimiter character + * @param manager The MemoryManager to use to allocate objects + * @return a vector of all the tokenized string + */ + static BaseRefVectorOf<XMLCh>* tokenizeString(const XMLCh* const tokenizeSrc + , XMLCh delimiter + , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); //@} /** @name Formatting functions */