You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by tn...@apache.org on 2001/05/18 22:18:04 UTC
cvs commit: xml-xerces/c/src/validators/datatype DecimalDatatypeValidator.cpp
tng 01/05/18 13:18:04
Modified: c/src/util XMLBigDecimal.cpp XMLBigDecimal.hpp
XMLBigInteger.cpp XMLBigInteger.hpp
c/src/validators/datatype DecimalDatatypeValidator.cpp
Log:
Schema: More exception messages in XMLBigDecimal/XMLBigInteger/DecimalDatatypeValidator. By Pei Yong Zhang.
Revision Changes Path
1.4 +31 -57 xml-xerces/c/src/util/XMLBigDecimal.cpp
Index: XMLBigDecimal.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/util/XMLBigDecimal.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- XMLBigDecimal.cpp 2001/05/18 13:22:54 1.3
+++ XMLBigDecimal.cpp 2001/05/18 20:17:55 1.4
@@ -56,6 +56,9 @@
/*
* $Log: XMLBigDecimal.cpp,v $
+ * Revision 1.4 2001/05/18 20:17:55 tng
+ * Schema: More exception messages in XMLBigDecimal/XMLBigInteger/DecimalDatatypeValidator. By Pei Yong Zhang.
+ *
* Revision 1.3 2001/05/18 13:22:54 tng
* Schema: Exception messages in DatatypeValidator. By Pei Yong Zhang.
*
@@ -70,56 +73,52 @@
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
-#include <string.h>
-#include <iostream.h>
#include <util/XMLBigDecimal.hpp>
#include <util/PlatformUtils.hpp>
#include <util/XMLString.hpp>
#include <util/XMLUniDefs.hpp>
#include <util/NumberFormatException.hpp>
-#include <util/RuntimeException.hpp>
#include <util/TransService.hpp>
#include <util/Janitor.hpp>
/**
- * Constructs a BigDecimal from a string containing an optional minus
- * sign followed by a sequence of zero or more decimal digits, optionally
- * followed by a fraction, which consists of a decimal point followed by
- * zero or more decimal digits. The string must contain at least one
- * digit in the integer or fractional part. The scale of the resulting
- * BigDecimal will be the number of digits to the right of the decimal
- * point in the string, or 0 if the string contains no decimal point.
- * Any extraneous characters (including whitespace) will result in
- * a NumberFormatException.
-*/
-//
-// since parseBigDecimal and XMLBigInteger() may
-// throw exception, caller of XMLBigDecimal better
-// be ready to catch it.
+ * Constructs a BigDecimal from a string containing an optional (plus | minus)
+ * sign followed by a sequence of zero or more decimal digits, optionally
+ * followed by a fraction, which consists of a decimal point followed by
+ * zero or more decimal digits. The string must contain at least one
+ * digit in the integer or fractional part. The scale of the resulting
+ * BigDecimal will be the number of digits to the right of the decimal
+ * point in the string, or 0 if the string contains no decimal point.
+ * Any extraneous characters (including whitespace) will result in
+ * a NumberFormatException.
+
+ * since parseBigDecimal and XMLBigInteger() may throw exception,
+ * caller of XMLBigDecimal need to catch it.
//
+**/
XMLBigDecimal::XMLBigDecimal(const XMLCh* const strValue)
:fIntVal(0)
,fScale(0)
{
+ if (!strValue)
+ ThrowXML(NumberFormatException, XMLExcepts::XMLNUM_emptyString);
+
XMLCh* ret_value = new XMLCh[XMLString::stringLen(strValue)+1];
ArrayJanitor<XMLCh> janName(ret_value);
parseBigDecimal(strValue, ret_value, fScale);
fIntVal = new XMLBigInteger(ret_value);
-
}
XMLBigDecimal::XMLBigDecimal(const XMLBigDecimal& toCopy)
:fIntVal(0)
,fScale(toCopy.getScale())
{
-
//invoke XMLBigInteger' copy ctor
fIntVal = new XMLBigInteger(*(toCopy.getValue()));
}
-
/***
*
* Leading and trailing whitespaces are allowed, and trimmed
@@ -154,10 +153,8 @@
scaleValue = 0;
// If no string, then its a failure
- if ((!toConvert) ||
- (!*toConvert))
- ThrowXML(NumberFormatException, XMLExcepts::CM_UnaryOpHadBinType);
- //ThrowXML(NumberFormatException, XMLExcepts::XMLINT_Invalid);
+ if ((!toConvert) || (!*toConvert))
+ ThrowXML(NumberFormatException, XMLExcepts::XMLNUM_emptyString);
// Scan past any whitespace. If we hit the end, then return failure
const XMLCh* startPtr = toConvert;
@@ -165,8 +162,7 @@
startPtr++;
if (!*startPtr)
- ThrowXML(NumberFormatException, XMLExcepts::CM_UnaryOpHadBinType);
- //ThrowXML(NumberFormatException, XMLExcepts::XMLINT_Invalid);
+ ThrowXML(NumberFormatException, XMLExcepts::XMLNUM_WSString);
// Start at the end and work back through any whitespace
const XMLCh* endPtr = toConvert + XMLString::stringLen(toConvert);
@@ -181,27 +177,18 @@
// '+' or '-' is allowed only at the first position
//
if (*startPtr == chDash)
- {
- // copy the '-'
- *retPtr = chDash;
+ {
+ *retPtr = chDash; // copy the '-'
startPtr++;
retPtr++;
}
else if (*startPtr == chPlus)
- {
- // skip the '+'
- startPtr++;
- }
+ startPtr++; // skip the '+'
// Leading zero will be taken care by BigInteger
-
bool dotSignFound = false;
-
while (startPtr < endPtr)
{
- //
- // '.' is allowed only once
- //
if (*startPtr == chPeriod)
{
if (dotSignFound == false)
@@ -211,15 +198,13 @@
startPtr++;
continue;
}
- else
- ThrowXML(NumberFormatException, XMLExcepts::CM_UnaryOpHadBinType);
- //ThrowXML(NumberFormatException, XMLExcepts::XMLBIGDECIMAL_MANY_DOT);
+ else // '.' is allowed only once
+ ThrowXML(NumberFormatException, XMLExcepts::XMLNUM_2ManyDecPoint);
}
// If not valid decimal digit, then an error
if ((*startPtr < chDigit_0) || (*startPtr > chDigit_9))
- ThrowXML(NumberFormatException, XMLExcepts::CM_UnaryOpHadBinType);
- //ThrowXML(NumberFormatException, XMLExcepts::XMLBIGDECIMAL_Invalid);
+ ThrowXML(NumberFormatException, XMLExcepts::XMLNUM_Inv_chars);
// copy over
*retPtr = *startPtr;
@@ -235,16 +220,12 @@
* Returns -1, 0 or 1 as lValue is less than, equal to, or greater
* than rValue. Two BigDecimals that are equal in value but have a
* different scale (e.g., 2.0, 2.00) are considered equal by this method.
-*/
-
+**/
int XMLBigDecimal::compareValues(const XMLBigDecimal* const lValue
, const XMLBigDecimal* const rValue)
{
- //
- if ((!lValue) ||
- (!rValue) )
- ThrowXML(NumberFormatException, XMLExcepts::CM_UnaryOpHadBinType);
- //ThrowXML(NumberFormatException, XMLExcepts::XMLBIGDECIMAL_Null_value);
+ if ((!lValue) || (!rValue) )
+ ThrowXML(NumberFormatException, XMLExcepts::XMLNUM_null_ptr);
/* Optimization: would run fine without the next three lines */
int sigDiff = lValue->getSign() - rValue->getSign();
@@ -306,13 +287,6 @@
}
return;
-}
-
-void XMLBigDecimal::dumpData() const
-{
- cout<<"scale="<<"<"<<fScale<<">"<<endl;
- fIntVal->dumpData();
- cout<<endl;
}
//
1.4 +1 -3 xml-xerces/c/src/util/XMLBigDecimal.hpp
Index: XMLBigDecimal.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/util/XMLBigDecimal.hpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- XMLBigDecimal.hpp 2001/05/18 13:22:58 1.3
+++ XMLBigDecimal.hpp 2001/05/18 20:17:56 1.4
@@ -55,7 +55,7 @@
*/
/*
- * $Id: XMLBigDecimal.hpp,v 1.3 2001/05/18 13:22:58 tng Exp $
+ * $Id: XMLBigDecimal.hpp,v 1.4 2001/05/18 20:17:56 tng Exp $
*/
#ifndef XML_BIGDECIMAL_HPP
@@ -109,8 +109,6 @@
unsigned int getScale() const;
unsigned int getTotalDigit() const;
-
- void dumpData() const;
/**
* Return string representation of the decimal value.
1.4 +16 -44 xml-xerces/c/src/util/XMLBigInteger.cpp
Index: XMLBigInteger.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/util/XMLBigInteger.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- XMLBigInteger.cpp 2001/05/18 13:23:01 1.3
+++ XMLBigInteger.cpp 2001/05/18 20:17:57 1.4
@@ -56,6 +56,9 @@
/*
* $Log: XMLBigInteger.cpp,v $
+ * Revision 1.4 2001/05/18 20:17:57 tng
+ * Schema: More exception messages in XMLBigDecimal/XMLBigInteger/DecimalDatatypeValidator. By Pei Yong Zhang.
+ *
* Revision 1.3 2001/05/18 13:23:01 tng
* Schema: Exception messages in DatatypeValidator. By Pei Yong Zhang.
*
@@ -70,16 +73,12 @@
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
-#include <string.h>
-#include <iostream.h>
#include <util/XMLBigInteger.hpp>
#include <util/XMLString.hpp>
#include <util/NumberFormatException.hpp>
-#include <util/RuntimeException.hpp>
#include <util/PlatformUtils.hpp>
#include <util/TransService.hpp>
#include <util/XMLUniDefs.hpp>
-#include <util/XMLUni.hpp>
#include <util/Janitor.hpp>
/***
@@ -112,10 +111,8 @@
, int& signValue)
{
// If no string, then its a failure
- if ((!toConvert) ||
- (!*toConvert))
- ThrowXML(NumberFormatException, XMLExcepts::CM_UnaryOpHadBinType);
- //ThrowXML(NumberFormatException, XMLExcepts::XMLINT_Invalid);
+ if ((!toConvert) || (!*toConvert))
+ ThrowXML(NumberFormatException, XMLExcepts::XMLNUM_emptyString);
//
// Note: in Java's BigInteger, it seems any leading and/or trailing
@@ -129,8 +126,7 @@
startPtr++;
if (!*startPtr)
- ThrowXML(NumberFormatException, XMLExcepts::CM_UnaryOpHadBinType);
- //ThrowXML(NumberFormatException, XMLExcepts::XMLINT_Invalid);
+ ThrowXML(NumberFormatException, XMLExcepts::XMLNUM_WSString);
// Start at the end and work back through any whitespace
const XMLCh* endPtr = toConvert + XMLString::stringLen(toConvert);
@@ -174,8 +170,7 @@
{
// If not valid decimal digit, then an error
if ((*startPtr < chDigit_0) || (*startPtr > chDigit_9))
- ThrowXML(NumberFormatException, XMLExcepts::CM_UnaryOpHadBinType);
- //ThrowXML(NumberFormatException, XMLExcepts::XMLINT_Invalid);
+ ThrowXML(NumberFormatException, XMLExcepts::XMLNUM_Inv_chars);
// copy over
*retPtr = *startPtr;
@@ -195,29 +190,18 @@
*/
XMLBigInteger::XMLBigInteger(const XMLCh* const strValue)
{
+ if (!strValue)
+ ThrowXML(NumberFormatException, XMLExcepts::XMLNUM_emptyString);
+
XMLCh* ret_value = new XMLCh[XMLString::stringLen(strValue)+1];
ArrayJanitor<XMLCh> janName(ret_value);
- try
- {
- parseBigInteger(strValue, ret_value, fSign);
- }
- catch (NumberFormatException)
- {
- throw;
- //ThrowXML(NumberFormatException, XMLExcepts::CM_UnaryOpHadBinType);
- //ThrowXML(NumberFormatException, XMLExcepts::XMLBIGDECIMAL_Inv_format);
- }
+ parseBigInteger(strValue, ret_value, fSign);
if (fSign == 0)
fMagnitude = XMLString::replicate(XMLUni::fgZeroLenString);
else
- {
- unsigned int strLen = XMLString::stringLen(ret_value);
- fMagnitude = new XMLCh[strLen+1];
- XMLString::moveChars(fMagnitude, ret_value, strLen);
- fMagnitude[strLen]=0;
- }
+ fMagnitude = XMLString::replicate(ret_value);
}
@@ -229,11 +213,7 @@
XMLBigInteger::XMLBigInteger(const XMLBigInteger& toCopy)
{
setSign(toCopy.getSign());
-
- int strLen = XMLString::stringLen(toCopy.fMagnitude);
- fMagnitude = new XMLCh[strLen+1];
- XMLString::moveChars(fMagnitude, toCopy.fMagnitude, strLen);
- fMagnitude[strLen]=0;
+ fMagnitude = XMLString::replicate(toCopy.fMagnitude);
}
/**
@@ -243,6 +223,9 @@
int XMLBigInteger::compareValues(const XMLBigInteger* const lValue
, const XMLBigInteger* const rValue)
{
+ if ((!lValue) || (!rValue) )
+ ThrowXML(NumberFormatException, XMLExcepts::XMLNUM_null_ptr);
+
int lSign = lValue->getSign();
int rSign = rValue->getSign();
@@ -329,17 +312,6 @@
delete[] fMagnitude;
fMagnitude = tmp;
-}
-
-void XMLBigInteger::dumpData() const
-{
- char *p;
- p = XMLString::transcode(fMagnitude);
- cout<<"sign="<<"<"<<fSign<<">"<<endl;
- cout<<"fMagnitude="<<"<"<<p<<">"<<endl;
- cout<<endl;
- delete[] p;
-
}
//
1.4 +1 -3 xml-xerces/c/src/util/XMLBigInteger.hpp
Index: XMLBigInteger.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/util/XMLBigInteger.hpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- XMLBigInteger.hpp 2001/05/18 13:23:03 1.3
+++ XMLBigInteger.hpp 2001/05/18 20:17:58 1.4
@@ -55,7 +55,7 @@
*/
/*
- * $Id: XMLBigInteger.hpp,v 1.3 2001/05/18 13:23:03 tng Exp $
+ * $Id: XMLBigInteger.hpp,v 1.4 2001/05/18 20:17:58 tng Exp $
*/
#ifndef XML_BIGINTEGER_HPP
@@ -98,8 +98,6 @@
void divide(const unsigned int byteToShift);
int getTotalDigit() const;
-
- void dumpData() const;
/**
* Return a copy of the fMagnitue.
1.6 +34 -5 xml-xerces/c/src/validators/datatype/DecimalDatatypeValidator.cpp
Index: DecimalDatatypeValidator.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/validators/datatype/DecimalDatatypeValidator.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DecimalDatatypeValidator.cpp 2001/05/18 13:36:45 1.5
+++ DecimalDatatypeValidator.cpp 2001/05/18 20:18:02 1.6
@@ -56,6 +56,9 @@
/*
* $Log: DecimalDatatypeValidator.cpp,v $
+ * Revision 1.6 2001/05/18 20:18:02 tng
+ * Schema: More exception messages in XMLBigDecimal/XMLBigInteger/DecimalDatatypeValidator. By Pei Yong Zhang.
+ *
* Revision 1.5 2001/05/18 13:36:45 tng
* Schema: Catch RegularExpression exception and NumberFormatException
*
@@ -619,14 +622,40 @@
XMLString::binToText(fTotalDigits, value1, BUF_LEN, 10);
XMLString::binToText(numBase->fTotalDigits, value2, BUF_LEN, 10);
ThrowXML2(InvalidDatatypeFacetException
- , XMLExcepts::FACET_TotDigit_FractDigit
- , value2
- , value1);
+ , XMLExcepts::FACET_totalDigit_base_totalDigit
+ , value1
+ , value2);
}
}
+
+ if (( getFacetsDefined() & DatatypeValidator::FACET_SCALE) != 0)
+ {
+ // check question error: fractionDigits > base.fractionDigits ???
+ if ( (( numBase->getFacetsDefined() & DatatypeValidator::FACET_SCALE) != 0) &&
+ ( fFractionDigits > numBase->fFractionDigits ))
+ {
+ XMLString::binToText(fFractionDigits, value1, BUF_LEN, 10);
+ XMLString::binToText(numBase->fFractionDigits, value2, BUF_LEN, 10);
+ ThrowXML2(InvalidDatatypeFacetException
+ , XMLExcepts::FACET_fractDigit_base_fractDigit
+ , value1
+ , value2);
+ }
+
+ // check question error: fractionDigits > base.totalDigits ???
+ if ( (( numBase->getFacetsDefined() & DatatypeValidator::FACET_PRECISSION) != 0) &&
+ ( fFractionDigits > numBase->fTotalDigits ))
+ {
+ XMLString::binToText(fFractionDigits, value1, BUF_LEN, 10);
+ XMLString::binToText(numBase->fTotalDigits, value2, BUF_LEN, 10);
+ ThrowXML2(InvalidDatatypeFacetException
+ , XMLExcepts::FACET_fractDigit_base_totalDigit
+ , value1
+ , value2);
+ }
+ }
+
- // check question error: fractionDigits > base.fractionDigits ???
- // check question error: fractionDigits > base.totalDigits ???
// check question error: totalDigits conflicts with bounds ???
// check 4.3.5.c0 must: enumeration values from the value space of base
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org