You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by pe...@apache.org on 2002/03/06 20:13:12 UTC

cvs commit: xml-xerces/c/src/xercesc/util XMLUni.hpp XMLUni.cpp XMLAbstractDoubleFloat.hpp XMLAbstractDoubleFloat.cpp

peiyongz    02/03/06 11:13:12

  Modified:    c/src/xercesc/util XMLUni.hpp XMLUni.cpp
                        XMLAbstractDoubleFloat.hpp
                        XMLAbstractDoubleFloat.cpp
  Log:
  Patch: more valid lexcial representation for positive/negative zero
  
  Revision  Changes    Path
  1.4       +1 -2      xml-xerces/c/src/xercesc/util/XMLUni.hpp
  
  Index: XMLUni.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/XMLUni.hpp,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- XMLUni.hpp	13 Feb 2002 16:09:24 -0000	1.3
  +++ XMLUni.hpp	6 Mar 2002 19:13:12 -0000	1.4
  @@ -55,7 +55,7 @@
    */
   
   /*
  - * $Id: XMLUni.hpp,v 1.3 2002/02/13 16:09:24 knoaman Exp $
  + * $Id: XMLUni.hpp,v 1.4 2002/03/06 19:13:12 peiyongz Exp $
    */
   
   
  @@ -209,7 +209,6 @@
   
       static const XMLCh fgNegINFString[];
       static const XMLCh fgNegZeroString[];
  -    static const XMLCh fgNeuralZeroString[];
       static const XMLCh fgPosZeroString[];
       static const XMLCh fgPosINFString[];
       static const XMLCh fgNaNString[];
  
  
  
  1.5       +1 -6      xml-xerces/c/src/xercesc/util/XMLUni.cpp
  
  Index: XMLUni.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/XMLUni.cpp,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- XMLUni.cpp	1 Mar 2002 18:47:37 -0000	1.4
  +++ XMLUni.cpp	6 Mar 2002 19:13:12 -0000	1.5
  @@ -55,7 +55,7 @@
    */
   
   /*
  - * $Id: XMLUni.cpp,v 1.4 2002/03/01 18:47:37 peiyongz Exp $
  + * $Id: XMLUni.cpp,v 1.5 2002/03/06 19:13:12 peiyongz Exp $
    */
   
   
  @@ -790,11 +790,6 @@
   const XMLCh XMLUni::fgNegZeroString[] =
   {
       chDash, chDigit_0, chNull
  -};
  -
  -const XMLCh XMLUni::fgNeuralZeroString[] =
  -{
  -    chDigit_0, chNull
   };
   
   const XMLCh XMLUni::fgPosZeroString[] =
  
  
  
  1.4       +5 -3      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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- XMLAbstractDoubleFloat.hpp	1 Mar 2002 18:47:37 -0000	1.3
  +++ XMLAbstractDoubleFloat.hpp	6 Mar 2002 19:13:12 -0000	1.4
  @@ -55,8 +55,11 @@
    */
   
   /*
  - * $Id: XMLAbstractDoubleFloat.hpp,v 1.3 2002/03/01 18:47:37 peiyongz Exp $
  + * $Id: XMLAbstractDoubleFloat.hpp,v 1.4 2002/03/06 19:13:12 peiyongz Exp $
    * $Log: XMLAbstractDoubleFloat.hpp,v $
  + * 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 @@
       {
           NegINF,
           NegZero,
  -        NeuralZero,
           PosZero,
           PosINF,
           NaN,
  @@ -179,7 +181,7 @@
       XMLAbstractDoubleFloat(const XMLAbstractDoubleFloat& toCopy);
       XMLAbstractDoubleFloat& operator=(const XMLAbstractDoubleFloat& toAssign);
   
  -	void                  normalizeToNeuralZero(XMLCh* const);
  +	void                  normalizeZero(XMLCh* const);
   
       inline bool           isSpecialValue() const;
   
  
  
  
  1.3       +61 -26    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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- XMLAbstractDoubleFloat.cpp	1 Mar 2002 18:47:37 -0000	1.2
  +++ XMLAbstractDoubleFloat.cpp	6 Mar 2002 19:13:12 -0000	1.3
  @@ -55,8 +55,11 @@
    */
   
   /*
  - * $Id: XMLAbstractDoubleFloat.cpp,v 1.2 2002/03/01 18:47:37 peiyongz Exp $
  + * $Id: XMLAbstractDoubleFloat.cpp,v 1.3 2002/03/06 19:13:12 peiyongz Exp $
    * $Log: XMLAbstractDoubleFloat.cpp,v $
  + * 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 @@
       ArrayJanitor<XMLCh> janTmpName(tmpStrValue);
       XMLString::trim(tmpStrValue);
   
  -    normalizeToNeuralZero(tmpStrValue);
  +    normalizeZero(tmpStrValue);
   
       if (XMLString::compareString(tmpStrValue, XMLUni::fgNegINFString) == 0)
       {
  @@ -126,11 +129,6 @@
           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 @@
       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 @@
           return -1;
   
       case NegZero:
  -    case NeuralZero:
       case PosZero:
           return (normalValue->getSign() > 0 ? -1 : 1);
   
  @@ -345,26 +339,67 @@
   }
   
   //
  -// 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;
  +	// do a quick check
  +	if (!inData  || 
  +		!*inData ||
  +        (XMLString::compareString(inData, XMLUni::fgNegZeroString) == 0) ||
  +        (XMLString::compareString(inData, XMLUni::fgPosZeroString) == 0)  )
  +        return;
   
  -    unsigned int index;
  -    for ( index = 2; (index < len) && (inData[index] == chDigit_0); index++);
  +    XMLCh*   srcStr = inData;
  +	bool     minusSeen = false;
   
  -	if (index >= len) 
  -		XMLString::copyString(inData, XMLUni::fgNeuralZeroString);
  +	// 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;
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org