Author: amassari
Date: Tue Jun 21 10:49:44 2011
New Revision: 1137951
URL: http://svn.apache.org/viewvc?rev=1137951&view=rev
Log:
Added a version of tokenize that uses a specified character as delimiter
Modified:
xerces/c/trunk/src/xercesc/util/XMLString.cpp
xerces/c/trunk/src/xercesc/util/XMLString.hpp
Modified: xerces/c/trunk/src/xercesc/util/XMLString.cpp
URL:
http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/util/XMLString.cpp?rev=1137951&r1=1137950&r2=1137951&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/util/XMLString.cpp (original)
+++ xerces/c/trunk/src/xercesc/util/XMLString.cpp Tue Jun 21 10:49:44 2011
@@ -1582,6 +1582,54 @@ void XMLString::subString(XMLCh* const t
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)
{
Modified: xerces/c/trunk/src/xercesc/util/XMLString.hpp
URL:
http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/util/XMLString.hpp?rev=1137951&r1=1137950&r2=1137951&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/util/XMLString.hpp (original)
+++ xerces/c/trunk/src/xercesc/util/XMLString.hpp Tue Jun 21 10:49:44 2011
@@ -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 */
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]