peiyongz 2003/02/02 15:54:44 Modified: c/src/xercesc/util XMLNumber.hpp XMLFloat.cpp XMLDouble.cpp XMLDateTime.hpp XMLDateTime.cpp XMLBigDecimal.hpp XMLBigDecimal.cpp XMLAbstractDoubleFloat.hpp XMLAbstractDoubleFloat.cpp Log: getFormattedString() added to return original and converted value. Revision Changes Path 1.4 +13 -1 xml-xerces/c/src/xercesc/util/XMLNumber.hpp Index: XMLNumber.hpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/XMLNumber.hpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- XMLNumber.hpp 30 Jan 2003 21:55:22 -0000 1.3 +++ XMLNumber.hpp 2 Feb 2003 23:54:43 -0000 1.4 @@ -57,6 +57,9 @@ /* * $Id$ * $Log$ + * Revision 1.4 2003/02/02 23:54:43 peiyongz + * getFormattedString() added to return original and converted value. + * * Revision 1.3 2003/01/30 21:55:22 tng * Performance: create getRawData which is similar to toString but return the internal data directly, user is not required to delete the returned memory. * @@ -103,6 +106,15 @@ * the returned buffer */ virtual XMLCh* getRawData() const = 0; + + /** + * Return the original and converted value of the original data. + * (applicable to double/float) + * + * The internal buffer is returned directly, user is not required + * to delete the returned buffer + */ + virtual const XMLCh* getFormattedString() const = 0; /** * Returns the sign of this number 1.8 +13 -1 xml-xerces/c/src/xercesc/util/XMLFloat.cpp Index: XMLFloat.cpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/XMLFloat.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- XMLFloat.cpp 30 Jan 2003 19:14:43 -0000 1.7 +++ XMLFloat.cpp 2 Feb 2003 23:54:43 -0000 1.8 @@ -57,6 +57,9 @@ /* * $Id$ * $Log$ + * Revision 1.8 2003/02/02 23:54:43 peiyongz + * getFormattedString() added to return original and converted value. + * * Revision 1.7 2003/01/30 19:14:43 tng * On some platforms like Solaris strtod will return -0.0. So need to consider this scenario as well. * @@ -170,11 +173,13 @@ if (fValue > (-1)*DBL_MIN) { fType = NegZero; + fDataConverted = true; fValue = 0; } else { fType = NegINF; + fDataConverted = true; } } else if ( fValue > 0) @@ -182,16 +187,19 @@ if (fValue < DBL_MIN ) { fType = PosZero; + fDataConverted = true; fValue = 0; } else { fType = PosINF; + fDataConverted = true; } } else { fType = (getSign() == 1) ? PosZero : NegZero; + fDataConverted = true; } } else @@ -202,20 +210,24 @@ if (fValue < (-1) * FLT_MAX) { fType = NegINF; + fDataConverted = true; } else if (fValue > (-1)*FLT_MIN && fValue < 0) { fType = NegZero; + fDataConverted = true; fValue = 0; } else if (fValue > 0 && fValue < FLT_MIN ) { fType = PosZero; + fDataConverted = true; fValue = 0; } else if (fValue > FLT_MAX) { fType = PosINF; + fDataConverted = true; } } } 1.7 +9 -1 xml-xerces/c/src/xercesc/util/XMLDouble.cpp Index: XMLDouble.cpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/XMLDouble.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- XMLDouble.cpp 30 Jan 2003 19:14:43 -0000 1.6 +++ XMLDouble.cpp 2 Feb 2003 23:54:43 -0000 1.7 @@ -57,6 +57,9 @@ /* * $Id$ * $Log$ + * Revision 1.7 2003/02/02 23:54:43 peiyongz + * getFormattedString() added to return original and converted value. + * * Revision 1.6 2003/01/30 19:14:43 tng * On some platforms like Solaris strtod will return -0.0. So need to consider this scenario as well. * @@ -175,11 +178,13 @@ if (fValue > (-1)*DBL_MIN) { fType = NegZero; + fDataConverted = true; fValue = 0; } else { fType = NegINF; + fDataConverted = true; } } else if ( fValue > 0) @@ -187,16 +192,19 @@ if (fValue < DBL_MIN ) { fType = PosZero; + fDataConverted = true; fValue = 0; } else { fType = PosINF; + fDataConverted = true; } } else { fType = (getSign() == 1) ? PosZero : NegZero; + fDataConverted = true; } } 1.4 +6 -1 xml-xerces/c/src/xercesc/util/XMLDateTime.hpp Index: XMLDateTime.hpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/XMLDateTime.hpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- XMLDateTime.hpp 30 Jan 2003 21:55:22 -0000 1.3 +++ XMLDateTime.hpp 2 Feb 2003 23:54:43 -0000 1.4 @@ -57,6 +57,9 @@ /* * $Id$ * $Log$ + * Revision 1.4 2003/02/02 23:54:43 peiyongz + * getFormattedString() added to return original and converted value. + * * Revision 1.3 2003/01/30 21:55:22 tng * Performance: create getRawData which is similar to toString but return the internal data directly, user is not required to delete the returned memory. * @@ -152,6 +155,8 @@ virtual XMLCh* toString() const; virtual XMLCh* getRawData() const; + + virtual const XMLCh* getFormattedString() const; virtual int getSign() const; 1.6 +10 -1 xml-xerces/c/src/xercesc/util/XMLDateTime.cpp Index: XMLDateTime.cpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/XMLDateTime.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- XMLDateTime.cpp 30 Jan 2003 21:55:22 -0000 1.5 +++ XMLDateTime.cpp 2 Feb 2003 23:54:43 -0000 1.6 @@ -57,6 +57,9 @@ /* * $Id$ * $Log$ + * Revision 1.6 2003/02/02 23:54:43 peiyongz + * getFormattedString() added to return original and converted value. + * * Revision 1.5 2003/01/30 21:55:22 tng * Performance: create getRawData which is similar to toString but return the internal data directly, user is not required to delete the returned memory. * @@ -514,6 +517,12 @@ { assertBuffer(); return fBuffer; +} + + +const XMLCh* XMLDateTime::getFormattedString() const +{ + return getRawData(); } int XMLDateTime::getSign() const 1.6 +3 -1 xml-xerces/c/src/xercesc/util/XMLBigDecimal.hpp Index: XMLBigDecimal.hpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/XMLBigDecimal.hpp,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- XMLBigDecimal.hpp 30 Jan 2003 21:55:22 -0000 1.5 +++ XMLBigDecimal.hpp 2 Feb 2003 23:54:43 -0000 1.6 @@ -108,6 +108,8 @@ virtual XMLCh* getRawData() const; + virtual const XMLCh* getFormattedString() const; + virtual int getSign() const; XMLBigInteger* getValue() const; 1.5 +8 -0 xml-xerces/c/src/xercesc/util/XMLBigDecimal.cpp Index: XMLBigDecimal.cpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/XMLBigDecimal.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- XMLBigDecimal.cpp 30 Jan 2003 21:55:22 -0000 1.4 +++ XMLBigDecimal.cpp 2 Feb 2003 23:54:43 -0000 1.5 @@ -56,6 +56,9 @@ /* * $Log$ + * Revision 1.5 2003/02/02 23:54:43 peiyongz + * getFormattedString() added to return original and converted value. + * * Revision 1.4 2003/01/30 21:55:22 tng * Performance: create getRawData which is similar to toString but return the internal data directly, user is not required to delete the returned memory. * @@ -360,6 +363,11 @@ } XMLCh* XMLBigDecimal::getRawData() const +{ + return fRawData; +} + +const XMLCh* XMLBigDecimal::getFormattedString() const { return fRawData; } 1.8 +20 -1 xml-xerces/c/src/xercesc/util/XMLAbstractDoubleFloat.hpp Index: XMLAbstractDoubleFloat.hpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/XMLAbstractDoubleFloat.hpp,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- XMLAbstractDoubleFloat.hpp 30 Jan 2003 21:55:22 -0000 1.7 +++ XMLAbstractDoubleFloat.hpp 2 Feb 2003 23:54:43 -0000 1.8 @@ -57,6 +57,9 @@ /* * $Id$ * $Log$ + * Revision 1.8 2003/02/02 23:54:43 peiyongz + * getFormattedString() added to return original and converted value. + * * Revision 1.7 2003/01/30 21:55:22 tng * Performance: create getRawData which is similar to toString but return the internal data directly, user is not required to delete the returned memory. * @@ -151,6 +154,8 @@ virtual XMLCh* getRawData() const; + virtual const XMLCh* getFormattedString() const; + virtual int getSign() const; protected: @@ -199,13 +204,27 @@ static int compareSpecial(const XMLAbstractDoubleFloat* const specialValue , const XMLAbstractDoubleFloat* const normalValue); + void formatString(); + protected: double fValue; LiteralType fType; + bool fDataConverted; private: int fSign; XMLCh* fRawData; + + // + // If the original string is not lexcially the same as the five + // special value notations, and the value is converted to + // special value due underlying platform restriction on data + // representation, then this string is constructed and + // takes the form "original_string (special_value_notation)", + // otherwise it is empty. + // + XMLCh* fFormattedString; + }; inline bool XMLAbstractDoubleFloat::isSpecialValue() const 1.9 +71 -11 xml-xerces/c/src/xercesc/util/XMLAbstractDoubleFloat.cpp Index: XMLAbstractDoubleFloat.cpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/XMLAbstractDoubleFloat.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- XMLAbstractDoubleFloat.cpp 30 Jan 2003 21:55:22 -0000 1.8 +++ XMLAbstractDoubleFloat.cpp 2 Feb 2003 23:54:43 -0000 1.9 @@ -57,6 +57,9 @@ /* * $Id$ * $Log$ + * Revision 1.9 2003/02/02 23:54:43 peiyongz + * getFormattedString() added to return original and converted value. + * * Revision 1.8 2003/01/30 21:55:22 tng * Performance: create getRawData which is similar to toString but return the internal data directly, user is not required to delete the returned memory. * @@ -114,14 +117,17 @@ XMLAbstractDoubleFloat::XMLAbstractDoubleFloat() :fValue(0) ,fType(Normal) +,fDataConverted(false) ,fSign(0) ,fRawData(0) +,fFormattedString(0) { } XMLAbstractDoubleFloat::~XMLAbstractDoubleFloat() { delete [] fRawData; + delete [] fFormattedString; } void XMLAbstractDoubleFloat::init(const XMLCh* const strValue) @@ -141,37 +147,35 @@ { fType = NegINF; fSign = -1; - return; } else if (XMLString::equals(tmpStrValue, XMLUni::fgNegZeroString) ) { fType = NegZero; fSign = -1; - return; } else if (XMLString::equals(tmpStrValue, XMLUni::fgPosZeroString) ) { fType = PosZero; fSign = 1; - return; } else if (XMLString::equals(tmpStrValue, XMLUni::fgPosINFString) ) { fType = PosINF; fSign = 1; - return; } else if (XMLString::equals(tmpStrValue, XMLUni::fgNaNString) ) { fType = NaN; fSign = 1; - return; + } + else + // + // Normal case + // + { + checkBoundary(tmpStrValue); } - // - // Normal case - // - checkBoundary(tmpStrValue); } // @@ -186,6 +190,62 @@ { return fRawData; } + +const XMLCh* XMLAbstractDoubleFloat::getFormattedString() const +{ + if (!fDataConverted) + { + return fRawData; + } + else + { + if (!fFormattedString) + { + XMLAbstractDoubleFloat *temp = (XMLAbstractDoubleFloat *) this; + temp->formatString(); + } + + return fFormattedString; + } + +} + +void XMLAbstractDoubleFloat::formatString() +{ + + unsigned int rawDataLen = XMLString::stringLen(fRawData); + fFormattedString = new XMLCh [ rawDataLen + 8]; + for (unsigned int i = 0; i < rawDataLen + 8; i++) + fFormattedString[i] = chNull; + + XMLString::copyString(fFormattedString, fRawData); + + fFormattedString[rawDataLen] = chSpace; + fFormattedString[rawDataLen + 1] = chOpenParen; + + switch (fType) + { + case NegINF: + XMLString::catString(fFormattedString, XMLUni::fgNegINFString); + break; + case NegZero: + XMLString::catString(fFormattedString, XMLUni::fgNegZeroString); + break; + case PosZero: + XMLString::catString(fFormattedString, XMLUni::fgPosZeroString); + break; + case PosINF: + XMLString::catString(fFormattedString, XMLUni::fgPosINFString); + break; + case NaN: + XMLString::catString(fFormattedString, XMLUni::fgNaNString); + break; + } + + fFormattedString[XMLString::stringLen(fFormattedString)] = chCloseParen; + +} + int XMLAbstractDoubleFloat::getSign() const { return fSign; @@ -344,6 +404,6 @@ } return; -} +} XERCES_CPP_NAMESPACE_END
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]