diff --git a/src/xercesc/util/XMLAbstractDoubleFloat.cpp b/src/xercesc/util/XMLAbstractDoubleFloat.cpp index fdcf3d58a0966a14ad3108312156a31a7ec88958..399d7672920e502d23048301c159d7307679d235 100644 --- a/src/xercesc/util/XMLAbstractDoubleFloat.cpp +++ b/src/xercesc/util/XMLAbstractDoubleFloat.cpp @@ -57,6 +57,9 @@ /* * $Id$ * $Log$ + * Revision 1.3 2002/03/06 19:13:12 peiyongz + * Patch: more valid lexcial representation for positive/negative zero + * * Revision 1.2 2002/03/01 18:47:37 peiyongz * fix: more valid lexcial representation forms for "neural zero" * @@ -114,7 +117,7 @@ void XMLAbstractDoubleFloat::init(const XMLCh* const strValue) ArrayJanitor<XMLCh> janTmpName(tmpStrValue); XMLString::trim(tmpStrValue); - normalizeToNeuralZero(tmpStrValue); + normalizeZero(tmpStrValue); if (XMLString::compareString(tmpStrValue, XMLUni::fgNegINFString) == 0) { @@ -126,11 +129,6 @@ void XMLAbstractDoubleFloat::init(const XMLCh* const strValue) fType = NegZero; return; } - else if (XMLString::compareString(tmpStrValue, XMLUni::fgNeuralZeroString) == 0) - { - fType = NeuralZero; - return; - } else if (XMLString::compareString(tmpStrValue, XMLUni::fgPosZeroString) == 0) { fType = PosZero; @@ -206,9 +204,6 @@ XMLCh* XMLAbstractDoubleFloat::toString() const case NegZero: return XMLString::replicate(XMLUni::fgNegZeroString); - case NeuralZero: - return XMLString::replicate(XMLUni::fgNeuralZeroString); - case PosZero: return XMLString::replicate(XMLUni::fgPosZeroString); @@ -324,7 +319,6 @@ int XMLAbstractDoubleFloat::compareSpecial(const XMLAbstractDoubleFloat* const s return -1; case NegZero: - case NeuralZero: case PosZero: return (normalValue->getSign() > 0 ? -1 : 1); @@ -345,26 +339,67 @@ int XMLAbstractDoubleFloat::compareSpecial(const XMLAbstractDoubleFloat* const s } // -// Apply to string -// "0.[0]+" -> "0" +// Assumption: no leading space // - -void XMLAbstractDoubleFloat::normalizeToNeuralZero(XMLCh* const inData) +// 1. The valid char set is "+-.0" +// 2. There shall be only one sign at the first position, if there is one. +// 3. There shall be only one dot '.', if there is one. +// +// Return: +// +// for input comforming to [+]? [0]* '.'? [0]*, +// normalize the input to positive zero string +// for input comforming to '-' [0]* '.'? [0]*, +// normalize the input to negative zero string +// otherwise, do nothing +// +void XMLAbstractDoubleFloat::normalizeZero(XMLCh* const inData) { - if (!inData || !*inData) - return; - const unsigned int len = XMLString::stringLen(inData); - - // the first two have to be "0." - if (len < 3 || inData[0] != chDigit_0 || inData[1] != chPeriod) - return; - - unsigned int index; - for ( index = 2; (index < len) && (inData[index] == chDigit_0); index++); + // do a quick check + if (!inData || + !*inData || + (XMLString::compareString(inData, XMLUni::fgNegZeroString) == 0) || + (XMLString::compareString(inData, XMLUni::fgPosZeroString) == 0) ) + return; - if (index >= len) - XMLString::copyString(inData, XMLUni::fgNeuralZeroString); + XMLCh* srcStr = inData; + bool minusSeen = false; + + // process sign if any + if (*srcStr == chDash) + { + minusSeen = true; + srcStr++; + } + else if (*srcStr == chPlus) + { + srcStr++; + } + + // scan the string + bool dotSeen = false; + bool isValidStr = true; + XMLCh theChar; + while ((theChar=*srcStr++) && isValidStr) + { + if ( theChar != chPeriod && theChar != chDigit_0 ) + isValidStr = false; // invalid char + else if (theChar == chPeriod) // process dot + dotSeen ? isValidStr = false : dotSeen = true; + } + + // need not to worry about the memory problem + // since either fgNegZeroString or fgPosZeroString + // is the canonical form (meaning the shortest in length) + // of their category respectively. + if (isValidStr) + { + if (minusSeen) + XMLString::copyString(inData, XMLUni::fgNegZeroString); + else + XMLString::copyString(inData, XMLUni::fgPosZeroString); + } return; } \ No newline at end of file diff --git a/src/xercesc/util/XMLAbstractDoubleFloat.hpp b/src/xercesc/util/XMLAbstractDoubleFloat.hpp index 21b603de6610b8266295258675f1b955f60d2422..4ffe6035c6c94f6c3047215f32f5451a057b45c6 100644 --- a/src/xercesc/util/XMLAbstractDoubleFloat.hpp +++ b/src/xercesc/util/XMLAbstractDoubleFloat.hpp @@ -57,6 +57,9 @@ /* * $Id$ * $Log$ + * Revision 1.4 2002/03/06 19:13:12 peiyongz + * Patch: more valid lexcial representation for positive/negative zero + * * Revision 1.3 2002/03/01 18:47:37 peiyongz * fix: more valid lexcial representation forms for "neural zero" * @@ -126,7 +129,6 @@ public: { NegINF, NegZero, - NeuralZero, PosZero, PosINF, NaN, @@ -179,7 +181,7 @@ private: XMLAbstractDoubleFloat(const XMLAbstractDoubleFloat& toCopy); XMLAbstractDoubleFloat& operator=(const XMLAbstractDoubleFloat& toAssign); - void normalizeToNeuralZero(XMLCh* const); + void normalizeZero(XMLCh* const); inline bool isSpecialValue() const; diff --git a/src/xercesc/util/XMLUni.cpp b/src/xercesc/util/XMLUni.cpp index 33c3e46f7629d83677ab19fa60836030315057af..f98404015518f869ab6127fd33b207506cb72cf6 100644 --- a/src/xercesc/util/XMLUni.cpp +++ b/src/xercesc/util/XMLUni.cpp @@ -792,11 +792,6 @@ const XMLCh XMLUni::fgNegZeroString[] = chDash, chDigit_0, chNull }; -const XMLCh XMLUni::fgNeuralZeroString[] = -{ - chDigit_0, chNull -}; - const XMLCh XMLUni::fgPosZeroString[] = { chDigit_0, chNull diff --git a/src/xercesc/util/XMLUni.hpp b/src/xercesc/util/XMLUni.hpp index bfbaa1e47589942c3f2a97a24c006a6936a333cd..34928cef017d1ad6eff0e2bafc551e240b3224d1 100644 --- a/src/xercesc/util/XMLUni.hpp +++ b/src/xercesc/util/XMLUni.hpp @@ -209,7 +209,6 @@ public : static const XMLCh fgNegINFString[]; static const XMLCh fgNegZeroString[]; - static const XMLCh fgNeuralZeroString[]; static const XMLCh fgPosZeroString[]; static const XMLCh fgPosINFString[]; static const XMLCh fgNaNString[];