From 1cbe472072346422cfeeb5a16bcf05bc34fac3ea Mon Sep 17 00:00:00 2001 From: PeiYong Zhang <peiyongz@apache.org> Date: Wed, 11 Aug 2004 16:17:58 +0000 Subject: [PATCH] Light weight parsing method git-svn-id: https://svn.apache.org/repos/asf/xerces/c/trunk@175975 13f79535-47bb-0310-9956-ffa450edef68 --- src/xercesc/util/XMLBigDecimal.cpp | 71 ++++++++++++++++++++++++++++++ src/xercesc/util/XMLBigDecimal.hpp | 14 ++++++ 2 files changed, 85 insertions(+) diff --git a/src/xercesc/util/XMLBigDecimal.cpp b/src/xercesc/util/XMLBigDecimal.cpp index b998f6d15..ecac4ca05 100644 --- a/src/xercesc/util/XMLBigDecimal.cpp +++ b/src/xercesc/util/XMLBigDecimal.cpp @@ -56,6 +56,9 @@ /* * $Log$ + * Revision 1.23 2004/08/11 16:17:58 peiyongz + * Light weight parsing method + * * Revision 1.22 2004/03/19 01:15:55 peiyongz * store/load fRawData * @@ -420,6 +423,74 @@ void XMLBigDecimal::parseDecimal(const XMLCh* const toParse return; } +void XMLBigDecimal::parseDecimal(const XMLCh* const toParse + , MemoryManager* const manager) +{ + + // Strip leading white space, if any. + const XMLCh* startPtr = toParse; + while (XMLChar1_0::isWhitespace(*startPtr)) + startPtr++; + + // If we hit the end, then return failure + if (!*startPtr) + ThrowXMLwithMemMgr(NumberFormatException, XMLExcepts::XMLNUM_WSString, manager); + + // Strip tailing white space, if any. + const XMLCh* endPtr = toParse + XMLString::stringLen(toParse); + while (XMLChar1_0::isWhitespace(*(endPtr - 1))) + endPtr--; + + // '+' or '-' is allowed only at the first position + // and is NOT included in the return parsed string + + if (*startPtr == chDash) + { + startPtr++; + } + else if (*startPtr == chPlus) + { + startPtr++; + } + + // Strip leading zeros + while (*startPtr == chDigit_0) + startPtr++; + + // containning zero, only zero, nothing but zero + // it is a zero, indeed + if (startPtr >= endPtr) + { + return; + } + + // Scan data + bool dotSignFound = false; + while (startPtr < endPtr) + { + if (*startPtr == chPeriod) + { + if (!dotSignFound) + { + dotSignFound = true; + startPtr++; + continue; + } + else // '.' is allowed only once + ThrowXMLwithMemMgr(NumberFormatException, XMLExcepts::XMLNUM_2ManyDecPoint, manager); + } + + // If not valid decimal digit, then an error + if ((*startPtr < chDigit_0) || (*startPtr > chDigit_9)) + ThrowXMLwithMemMgr(NumberFormatException, XMLExcepts::XMLNUM_Inv_chars, manager); + + startPtr++; + + } + + return; +} + int XMLBigDecimal::compareValues( const XMLBigDecimal* const lValue , const XMLBigDecimal* const rValue , MemoryManager* const manager) diff --git a/src/xercesc/util/XMLBigDecimal.hpp b/src/xercesc/util/XMLBigDecimal.hpp index 33a8e8612..57085c22d 100644 --- a/src/xercesc/util/XMLBigDecimal.hpp +++ b/src/xercesc/util/XMLBigDecimal.hpp @@ -111,6 +111,12 @@ public: , MemoryManager* const manager ); + static void parseDecimal + ( + const XMLCh* const toParse + , MemoryManager* const manager + ); + /** * * Deprecated: please use getRawData @@ -130,6 +136,8 @@ public: unsigned int getTotalDigit() const; + inline XMLCh* getIntVal() const; + /** * Compares this object to the specified object. * @@ -196,6 +204,7 @@ private: XMLCh* fRawData; XMLCh* fIntVal; MemoryManager* fMemoryManager; + }; inline int XMLBigDecimal::getSign() const @@ -233,6 +242,11 @@ inline MemoryManager* XMLBigDecimal::getMemoryManager() const return fMemoryManager; } +inline XMLCh* XMLBigDecimal::getIntVal() const +{ + return fIntVal; +} + // // The caller needs to de-allocate the memory allocated by this function // -- GitLab