dbertoni    00/12/01 14:13:27

  Modified:    c/src/PlatformSupport DOMStringHelper.cpp
                        DOMStringHelper.hpp
  Log:
  Code cleanup and new number/string conversion routines.
  
  Revision  Changes    Path
  1.46      +414 -194  xml-xalan/c/src/PlatformSupport/DOMStringHelper.cpp
  
  Index: DOMStringHelper.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/PlatformSupport/DOMStringHelper.cpp,v
  retrieving revision 1.45
  retrieving revision 1.46
  diff -u -r1.45 -r1.46
  --- DOMStringHelper.cpp       2000/11/29 21:34:54     1.45
  +++ DOMStringHelper.cpp       2000/12/01 22:13:20     1.46
  @@ -122,8 +122,11 @@
   // number strings when we don't have to,
   const size_t MAX_PRINTF_DIGITS = 100;
   
  +// The maximum number of characters for a floating point number.
  +const size_t MAX_FLOAT_CHARACTERS = 100;
   
   
  +
   #if !defined(XALAN_LSTRSUPPORT)
   
   
  @@ -153,8 +156,12 @@
   
   static XalanDOMString        thePositiveInfinityString;
   
  +static XalanDOMString        theNegativeZeroString;
  +
  +static XalanDOMString        thePositiveZeroString;
   
   
  +
   /**
    * Initialize static data.  Must be called before any
    * other functions are called.  See PlatformSupportInit.
  @@ -165,6 +172,8 @@
        theNaNString = XALAN_STATIC_UCODE_STRING("NaN");
        theNegativeInfinityString = XALAN_STATIC_UCODE_STRING("-Infinity");
        thePositiveInfinityString = XALAN_STATIC_UCODE_STRING("Infinity");
  +     theNegativeZeroString = XALAN_STATIC_UCODE_STRING("-0");
  +     thePositiveZeroString = XALAN_STATIC_UCODE_STRING("0");
   }
   
   
  @@ -179,6 +188,8 @@
        clear(theNaNString);
        clear(theNegativeInfinityString);
        clear(thePositiveInfinityString);
  +     clear(theNegativeZeroString);
  +     clear(thePositiveZeroString);
   }
   
   
  @@ -403,8 +414,7 @@
   
        const unsigned int      theSubStringLength = length(theSubstring);
   
  -     // If either string is of length 0, or if the substring
  -     // is longer, there's no point in continuing.
  +     // If the substring is longer, there's no point in continuing.
        if (theStringLength >= theSubStringLength)
        {
                int             i = theStringLength - 1;
  @@ -451,7 +461,7 @@
   #else
                        std::ostream&                   theStream,
   #endif
  -                      const CharVectorType&  theString)
  +                     const CharVectorType&   theString)
   {
        if (theString.size() > 0)
        {
  @@ -520,48 +530,54 @@
   
   #if defined(XALAN_NO_ALGORITHMS_WITH_BUILTINS)
   
  -template<class OutputIteratorType>
  -inline void
  +template<class InputIteratorType, class OutputIteratorType>
  +inline OutputIteratorType
   XalanCopy(
  -                     const char*                     begin,
  -                     const char*                     end,
  +                     InputIteratorType       begin,
  +                     InputIteratorType       end,
                        OutputIteratorType      iterator)
   {
        for(; begin != end; ++iterator, ++begin)
        {
                *iterator = *begin;
        }
  +
  +     return iterator;
   }
   
   
   
  -template<class OutputIteratorType>
  -inline void
  +template<class InputIteratorType, class OutputIteratorType>
  +inline OutputIteratorType
   XalanCopy(
  -                     const XalanDOMChar*             begin,
  -                     const XalanDOMChar*             end,
  +                     InputIteratorType               begin,
  +                     InputIteratorType               end,
                        OutputIteratorType              iterator)
   {
        for(; begin != end; ++iterator, ++begin)
        {
                *iterator = *begin;
        }
  +
  +     return iterator;
   }
   
   
   
  -template<class OutputIteratorType, class UnaryFunction>
  -inline void
  +template<class InputIteratorType, class OutputIteratorType, class 
UnaryFunction>
  +inline OutputIteratorType
   XalanTransform(
  -                     const XalanDOMChar*             begin,
  -                     const XalanDOMChar*             end,
  -                     OutputIteratorType              iterator,
  -                     UnaryFunction                   function)
  +                     InputIteratorType       begin,
  +                     InputIteratorType       end,
  +                     OutputIteratorType      iterator,
  +                     UnaryFunction           function)
   {
        for(; begin != end; ++iterator, ++begin)
        {
                *iterator = function(*begin);
        }
  +
  +     return iterator;
   }
   
   #endif
  @@ -598,6 +614,9 @@
                {
                        assert(theStartIndex + theLength <= theStringLength);
   
  +#if defined(XALAN_USE_CUSTOM_STRING) || defined(XALAN_USE_STD_STRING)
  +                     return theString.substr(theStartIndex, theLength);
  +#else
                        // @@ JMD:
                        // If this is the case, the DOMString class doesn't 
create a new string,
                        // and in any case, does not null terminate the string, 
just points to
  @@ -605,6 +624,8 @@
                        // and create a new buffer
                        if (0 == theStartIndex)
                        {
  +                             const XalanDOMChar* const       ptr = 
toCharArray(theString);
  +
                                vector<XalanDOMChar>    theBuffer;
   
                                // Reserve the buffer now.  We don't have to 
null-terminate,
  @@ -612,8 +633,6 @@
                                // parameter.
                                theBuffer.reserve(theLength);
   
  -                             const XalanDOMChar* const       ptr = 
toCharArray(theString);
  -
   #if defined(XALAN_NO_ALGORITHMS_WITH_BUILTINS)
                                XalanCopy(
                                        ptr,
  @@ -626,22 +645,44 @@
                                        back_inserter(theBuffer));
   #endif
   
  -                             return XalanDOMString(theBuffer.begin(), 
theBuffer.size());
  +                             return XalanDOMString(&*theBuffer.begin(), 
theBuffer.size());
                        }
                        else
                        {
  -#if defined(XALAN_USE_CUSTOM_STRING) || defined(XALAN_USE_STD_STRING)
  -                             return theString.substr(theStartIndex, 
theLength);
  -#else
                                return theString.substringData(theStartIndex, 
theLength);
  -#endif
                        }
  +#endif       // defined(XALAN_USE_CUSTOM_STRING) || 
defined(XALAN_USE_STD_STRING)
                }
        }
   }
   
   
   
  +template <class InputIteratorType, class OutputIteratorType, class 
FunctionType>
  +OutputIteratorType
  +TransformString(
  +                     InputIteratorType       theInputBegin,
  +                     InputIteratorType       theInputEnd,
  +                     OutputIteratorType      theOutputIterator,
  +                     FunctionType            theFunction)
  +{
  +#if defined(XALAN_NO_ALGORITHMS_WITH_BUILTINS)
  +     return XalanTransform(
  +                     theInputBegin,
  +                     theInputEnd,
  +                     theOutputIterator,
  +                     theFunction);
  +#else
  +     return transform(
  +                     theInputBegin,
  +                     theInputEnd,
  +                     theOutputIterator,
  +                     theFunction);
  +#endif
  +}
  +
  +
  +
   template <class SizeType, class FunctionType>
   XalanDOMString
   TransformString(
  @@ -651,23 +692,27 @@
   {
        assert(theInputString != 0);
   
  +#if defined(XALAN_USE_XERCES_DOMSTRING)
        vector<XalanDOMChar>    theConvertedString;
   
  -#if defined(XALAN_NO_ALGORITHMS_WITH_BUILTINS)
  -             XalanTransform(
  +     TransformString(
                        theInputString,
                        theInputString + theInputStringLength,
                        back_inserter(theConvertedString),
                        theFunction);
  +
  +     return XalanDOMString(&*theConvertedString.begin(), 
theConvertedString.size());
   #else
  -             transform(
  +     XalanDOMString  theConvertedString;
  +
  +     TransformString(
                        theInputString,
                        theInputString + theInputStringLength,
                        back_inserter(theConvertedString),
                        theFunction);
  -#endif
   
  -     return XalanDOMString(theConvertedString.begin(), 
theConvertedString.size());
  +     return theConvertedString;
  +#endif
   }
   
   
  @@ -695,7 +740,6 @@
   
   
   
  -
   XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString)
   toLowerCase(const XalanDOMChar*              theString)
   {
  @@ -1443,7 +1487,7 @@
   Type
   WideStringToIntegral(
                        const XalanDOMChar*             theString,
  -                     Type                                    theDummy)
  +                     Type                                    /* theDummy */)
   {
        if (theString == 0)
        {
  @@ -1523,7 +1567,7 @@
        const int       strLen = length(theString);
        
        // index of first non-whitespace character
  -     int leadingSpace = 0;
  +     int                     leadingSpace = 0;
   
        for (; leadingSpace < strLen; ++leadingSpace)
                if (!isXMLWhitespace(charAt(theString, leadingSpace)))
  @@ -1541,257 +1585,433 @@
   
   
   
  -XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString)
  -DoubleToDOMString(double     theDouble)
  +template <class InputCharType, class OutputCharType>
  +class IdentityTransform
   {
  -     if (DoubleSupport::isNaN(theDouble) == true)
  -     {
  -             return theNaNString;
  -     }
  -     else if (DoubleSupport::isPositiveInfinity(theDouble) == true)
  -     {
  -             return thePositiveInfinityString;
  -     }
  -     else if (DoubleSupport::isNegativeInfinity(theDouble) == true)
  +public:
  +
  +     OutputCharType
  +     operator()(InputCharType        theChar) const
        {
  -             return theNegativeInfinityString;
  +             return OutputCharType(theChar);
        }
  -     else
  +};
  +
  +
  +
  +template<class InputCharType, class OutputCharType>
  +IdentityTransform<InputCharType, OutputCharType>
  +makeIdentityTransform(
  +                     const InputCharType*,
  +                     const OutputCharType*)
  +{
  +     return IdentityTransform<InputCharType, OutputCharType>();
  +}
  +
  +
  +
  +// A very cheap decimal number transcoder...
  +template <class InputCharType, class OutputCharType>
  +class DecimalNumberTranscodeTransform
  +{
  +public:
  +
  +     OutputCharType
  +     operator()(InputCharType        theChar) const
        {
  -             // $$$ ToDo: this is all temporary, until we get the 
NumberFormat and DecimalFormat
  -             // classes working.
  -             // According to the XPath standard, any values without
  -             // a fractional part are printed as integers.
  -             double  intPart = 0;
  +             switch(theChar)
  +             {
  +             case '-':
  +                     return OutputCharType(XalanUnicode::charHyphenMinus);
  +                     break;
   
  -             double  fracPart = fabs(modf(theDouble, &intPart));
  +             case '.':
  +                     return OutputCharType(XalanUnicode::charFullStop);
  +                     break;
   
  -             char            theBuffer[MAX_PRINTF_DIGITS + 1];
  +             case '0':
  +                     return OutputCharType(XalanUnicode::charDigit_0);
  +                     break;
   
  -#if 1
  -             sprintf(theBuffer, "%f", theDouble);
  -#else
  -             ostrstream      theFormatter(theBuffer, sizeof(theBuffer));
  +             case '1':
  +                     return OutputCharType(XalanUnicode::charDigit_1);
  +                     break;
   
  -             // Ensure that we get fixed point results, and that there's 
enough precision.
  -             theFormatter.flags((theFormatter.flags() & ~ios::scientific) | 
ios::fixed);
  +             case '2':
  +                     return OutputCharType(XalanUnicode::charDigit_2);
  +                     break;
   
  -             theFormatter.precision(20);
  +             case '3':
  +                     return OutputCharType(XalanUnicode::charDigit_3);
  +                     break;
   
  -             theFormatter << theDouble << '\0';
  -#endif
  -             // OK, now we have to clean up the output for
  -             // the XPath standard, which says no trailing
  -             // '0's for the decimal portion.  So start with
  -             // the last digit, and replace any '0's with the
  -             // null character.  We know at this point that
  -             // we have at least 1 digit before the decimal
  -             // point, and and least 1 non-zero digit after
  -             // the decimal point, since any values with no
  -             // fractional part were printed as integers
  -             XalanDOMCharVectorType          theResult =
  -#if defined(XALAN_NON_ASCII_PLATFORM)
  -                             MakeXalanDOMCharVector(theBuffer, true);
  -#else
  -                             MakeXalanDOMCharVector(theBuffer, false);
  -#endif
  +             case '4':
  +                     return OutputCharType(XalanUnicode::charDigit_4);
  +                     break;
   
  -             XalanDOMCharVectorType::iterator        thePosition = 
theResult.end();
  +             case '5':
  +                     return OutputCharType(XalanUnicode::charDigit_5);
  +                     break;
   
  -             // Move to the terminating null byte...
  -             --thePosition;
  +             case '6':
  +                     return OutputCharType(XalanUnicode::charDigit_6);
  +                     break;
   
  -             // Now, move back while there are zeros.
  -             while(*--thePosition == XalanUnicode::charDigit_0)
  -             {
  -             }
  +             case '7':
  +                     return OutputCharType(XalanUnicode::charDigit_7);
  +                     break;
   
  -             // If there's no fractional part, make sure we get rid
  -             // of the decimal point...
  -             if (fracPart != 0 ||
  -                     *thePosition != XalanUnicode::charFullStop)
  -             {
  -                     // Move up one, since we need to keep at least one...
  -                     ++thePosition;
  -             }
  +             case '8':
  +                     return OutputCharType(XalanUnicode::charDigit_8);
  +                     break;
  +
  +             case '9':
  +                     return OutputCharType(XalanUnicode::charDigit_9);
  +                     break;
   
  -             // Terminate it...
  -             *thePosition = 0;
  -                     
  -             return XalanDOMString(theResult.begin());
  +             default:
  +                     return OutputCharType(0);
  +                     break;
  +             }
        }
  +};
  +
  +
  +
  +template<class InputCharType, class OutputCharType>
  +DecimalNumberTranscodeTransform<InputCharType, OutputCharType>
  +makeDecimalNumberTranscodeTransform(
  +                     const InputCharType*,
  +                     const OutputCharType*)
  +{
  +     return DecimalNumberTranscodeTransform<InputCharType, OutputCharType>();
   }
   
   
   
  -XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString)
  -LongToHexDOMString(long              theLong)
  +// A very cheap hex number transcoder...
  +template <class InputCharType, class OutputCharType>
  +class HexadecimalDecimalNumberTranscodeTransform : public 
DecimalNumberTranscodeTransform<InputCharType, OutputCharType>
   {
  -// I'm 99% sure that we don't need to use swprintf
  -// to format, since strings of numbers don't to be
  -// generated as wide strings.
  -#if 0 // defined(XALAN_USE_WCHAR_SUPPORT)
  +public:
   
  -     wchar_t         theBuffer[MAX_PRINTF_DIGITS + 1];
  +     typedef DecimalNumberTranscodeTransform<InputCharType, OutputCharType>  
BaseClassType;
   
  -     swprintf(theBuffer,
  -                      L"%lx",
  -                      theLong);
  +     OutputCharType
  +     operator()(InputCharType        theChar) const
  +     {
  +             switch(theChar)
  +             {
  +             case 'A':
  +                     return OutputCharType(XalanUnicode::char_A);
  +                     break;
   
  -     return XalanDOMString(theBuffer, length(theBuffer));
  +             case 'a':
  +                     return OutputCharType(XalanUnicode::char_a);
  +                     break;
   
  -#else
  +             case 'B':
  +                     return OutputCharType(XalanUnicode::char_B);
  +                     break;
  +
  +             case 'b':
  +                     return OutputCharType(XalanUnicode::char_b);
  +                     break;
   
  -     char            theBuffer[MAX_PRINTF_DIGITS + 1];
  +             case 'C':
  +                     return OutputCharType(XalanUnicode::char_C);
  +                     break;
   
  -     ostrstream      theFormatter(theBuffer, sizeof(theBuffer));
  +             case 'c':
  +                     return OutputCharType(XalanUnicode::char_c);
  +                     break;
   
  -     theFormatter << hex << theLong << '\0';
  +             case 'D':
  +                     return OutputCharType(XalanUnicode::char_D);
  +                     break;
   
  -     // We don't need to transcode, so just make it a
  -     // wide character string...
  -     XalanDOMChar    theResult[MAX_PRINTF_DIGITS + 1];
  +             case 'd':
  +                     return OutputCharType(XalanUnicode::char_d);
  +                     break;
   
  -     const unsigned int      theLength = strlen(theBuffer);
  +             case 'E':
  +                     return OutputCharType(XalanUnicode::char_E);
  +                     break;
   
  -#if defined(XALAN_NO_ALGORITHMS_WITH_BUILTINS)
  -     XalanCopy(theBuffer, theBuffer + theLength, theResult);
  -#else
  -     copy(theBuffer, theBuffer + theLength, theResult);
  -#endif
  +             case 'e':
  +                     return OutputCharType(XalanUnicode::char_e);
  +                     break;
  +
  +             case 'F':
  +                     return OutputCharType(XalanUnicode::char_F);
  +                     break;
   
  -     return XalanDOMString(theResult, theLength);
  +             case 'f':
  +                     return OutputCharType(XalanUnicode::char_f);
  +                     break;
  +
  +             default:
  +                     return BaseClassType::operator()(theChar);
  +                     break;
  +             }
  +     }
  +};
  +
   
  +
  +template <class InputIteratorType, class OutputIteratorType>
  +OutputIteratorType
  +TranscodeNumber(
  +                     InputIteratorType       theInputBegin,
  +                     InputIteratorType       theInputEnd,
  +                     OutputIteratorType      theOutputIterator)
  +{
  +     return TransformString(
  +                             theInputBegin,
  +                             theInputEnd,
  +                             theOutputIterator,
  +#if defined(XALAN_NON_ASCII_PLATFORM)
  +                             DecimalNumberTranscodeTransform<char, 
XalanDOMChar>());
  +#else
  +                             IdentityTransform<char, XalanDOMChar>());
   #endif
   }
   
   
   
  -XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString)
  -UnsignedLongToHexDOMString(unsigned long     theUnsignedLong)
  +XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(void)
  +DoubleToDOMString(
  +                     double                          theDouble,
  +                     XalanDOMString&         theString)
   {
  -     char            theBuffer[MAX_PRINTF_DIGITS + 1];
  +     if (DoubleSupport::isNaN(theDouble) == true)
  +     {
  +             theString = theNaNString;
  +     }
  +     else if (DoubleSupport::isPositiveInfinity(theDouble) == true)
  +     {
  +             theString = thePositiveInfinityString;
  +     }
  +     else if (DoubleSupport::isNegativeInfinity(theDouble) == true)
  +     {
  +             theString = theNegativeInfinityString;
  +     }
  +     else if (DoubleSupport::isNegativeZero(theDouble) == true)
  +     {
  +             theString = theNegativeZeroString;
  +     }
  +     else if (DoubleSupport::isPositiveZero(theDouble) == true)
  +     {
  +             theString = thePositiveZeroString;
  +     }
  +     else
  +     {
  +             char                    theBuffer[MAX_PRINTF_DIGITS + 1];
   
  -     ostrstream      theFormatter(theBuffer, sizeof(theBuffer));
  +             unsigned int    theCharsWritten = sprintf(theBuffer, "%f", 
theDouble);
  +             assert(theCharsWritten != 0);
   
  -     theFormatter << hex << theUnsignedLong << '\0';
  +             // First, cleanup the output to conform to the XPath standard,
  +             // which says no trailing '0's for the decimal portion.
  +             // So start with the last digit, and search until we find
  +             // the last correct character for the output.
  +             // Also, according to the XPath standard, any values without
  +             // a fractional part are printed as integers.  There's always
  +             // a decimal point, so we have to strip stuff away...
   
  -     // We don't need to transcode, so just make it a
  -     // wide character string...
  -     XalanDOMChar    theResult[MAX_PRINTF_DIGITS + 1];
  +             // Now, move back while there are zeros...
  +             while(theBuffer[--theCharsWritten] == '0')
  +             {
  +             }
   
  -     const unsigned int      theLength = strlen(theBuffer);
  +             // If a decimal point stopped the loop, then
  +             // we don't want to preserve it.  Otherwise,
  +             // another digit stopped the loop, so we must
  +             // preserve it.
  +             if(theBuffer[theCharsWritten] != '.')
  +             {
  +                     ++theCharsWritten;
  +             }
   
  -#if defined(XALAN_NO_ALGORITHMS_WITH_BUILTINS)
  -     XalanCopy(theBuffer, theBuffer + theLength, theResult);
  +#if defined(XALAN_USE_XERCES_DOMSTRING)
  +             XalanDOMChar    theResult[sizeof(theBuffer)];
  +
  +             TranscodeNumber(
  +                             theBuffer,
  +                             theBuffer + theCharsWritten,
  +                             theResult);
  +
  +             theString = XalanDOMString(theResult, theCharsWritten);
   #else
  -     copy(theBuffer, theBuffer + theLength, theResult);
  -#endif
  +             reserve(theString, theCharsWritten);
   
  -     return XalanDOMString(theResult, theLength);
  +             TranscodeNumber(
  +                             theBuffer,
  +                             theBuffer + theCharsWritten,
  +                             back_inserter(theString));
  +#endif
  +     }
   }
   
   
   
  -XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString)
  -LongToDOMString(long theLong)
  +template <class ScalarType>
  +XalanDOMChar*
  +ScalarToDecimalString(
  +                     ScalarType              theValue,
  +                     XalanDOMChar*   theOutput)
   {
  -#if 0 // defined(XALAN_USE_WCHAR_SUPPORT)
  +     // Null terminate it...
  +     *theOutput = 0;
   
  -     wchar_t         theBuffer[MAX_PRINTF_DIGITS + 1];
  +     if (theValue < 0)
  +     {
  +             do
  +             {
  +                     *--theOutput = XalanDOMChar(-(theValue % 10) + 
XalanUnicode::charDigit_0);
   
  -     swprintf(theBuffer,
  -                      L"%ld",
  -                      theLong);
  +                     // OK, we're done with it...
  +                     theValue /= 10;
  +             }
  +             while(theValue != 0);
   
  -     return XalanDOMString(theBuffer, length(theBuffer));
  +             *--theOutput = XalanUnicode::charHyphenMinus;
  +     }
  +     else
  +     {
  +             do
  +             {
  +                     *--theOutput = XalanDOMChar(theValue % 10 + 
XalanUnicode::charDigit_0);
   
  -#else
  +                     // OK, we're done with it...
  +                     theValue /= 10;
  +             }
  +             while(theValue != 0);
  +     }
   
  -     char            theBuffer[MAX_PRINTF_DIGITS + 1];
  +     return theOutput;
  +}
   
  -     ostrstream      theFormatter(theBuffer, sizeof(theBuffer));
   
  -     theFormatter << theLong << '\0';
   
  +template <class ScalarType>
  +void
  +ScalarToDecimalString(
  +                     ScalarType                      theValue,
  +                     XalanDOMString&         theResult)
  +{
        // We don't need to transcode, so just make it a
        // wide character string...
  -     XalanDOMChar    theResult[MAX_PRINTF_DIGITS + 1];
  +     XalanDOMChar                    theBuffer[MAX_PRINTF_DIGITS + 1];
   
  -     const unsigned int      theLength = strlen(theBuffer);
  +     XalanDOMChar* const             theEnd = &theBuffer[MAX_PRINTF_DIGITS];
   
  -#if defined(XALAN_NO_ALGORITHMS_WITH_BUILTINS)
  -     XalanCopy(theBuffer, theBuffer + theLength, theResult);
  -#else
  -     copy(theBuffer, theBuffer + theLength, theResult);
  -#endif
  +     XalanDOMChar* const             theBegin = 
ScalarToDecimalString(theValue, theEnd);
   
  -     return XalanDOMString(theResult, theLength);
  -#endif
  +     append(theResult, theBegin, theEnd - theBegin);
   }
   
   
   
  -XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(void)
  -UnsignedLongToDOMString(
  -                     unsigned long           theValue,
  -                     XalanDOMString&         theResult)
  +template <class ScalarType>
  +XalanDOMChar*
  +UnsignedScalarToHexadecimalString(
  +                     ScalarType              theValue,
  +                     XalanDOMChar*   theOutput)
   {
  -#if 1
  +     if (theValue >= 0)
  +     {
  +             // Null terminate it...
  +             *theOutput = 0;
   
  -     XalanDOMChar                            theBuffer[MAX_PRINTF_DIGITS + 
1];
  +             do
  +             {
  +                     // Next spot...
  +                     --theOutput;
   
  -     XalanDOMChar*                           thePointer = 
&theBuffer[MAX_PRINTF_DIGITS];
  -     const XalanDOMChar* const       theEnd = thePointer;
  +                     const ScalarType        theTemp = theValue % 16;
   
  -     // Null terminate it...
  -     *thePointer = 0;
  +                     // Isolate the left most character.
  +                     if (theTemp >= 0 && theTemp <= 9)
  +                     {
  +                             *theOutput = XalanDOMChar(theTemp + 
XalanUnicode::charDigit_0);
  +                     }
  +                     else
  +                     {
  +                             assert(theTemp >= 10 && theTemp <= 15);
  +
  +                             *theOutput = XalanDOMChar(theTemp - 10 + 
XalanUnicode::charLetter_A);
  +                     }
  +
  +                     // OK, we're done with it...
  +                     theValue /= 16;
  +             }
  +             while(theValue != 0);
  +     }
   
  -     do
  +     return theOutput;
  +}
  +
  +
  +
  +template <class ScalarType>
  +void
  +UnsignedScalarToHexadecimalString(
  +                     ScalarType                      theValue,
  +                     XalanDOMString&         theResult)
  +{
  +     if (theValue >= 0)
        {
  -             // Next spot...
  -             --thePointer;
  +             // We don't need to transcode, so just make it a
  +             // wide character string...
  +             XalanDOMChar                    theBuffer[MAX_PRINTF_DIGITS + 
1];
   
  -             // Isolate the left most character.
  -             *thePointer = XalanDOMChar(theValue % 10 + 
XalanUnicode::charDigit_0);
  +             XalanDOMChar* const             theEnd = 
&theBuffer[MAX_PRINTF_DIGITS];
   
  -             // OK, we're done with it...
  -             theValue /= 10;
  +             XalanDOMChar* const             theBegin = 
UnsignedScalarToHexadecimalString(theValue, theEnd);
  +
  +             append(theResult, theBegin, theEnd - theBegin);
        }
  -     while(theValue != 0);
  +}
   
  -     assign(theResult, thePointer, theEnd - thePointer);
   
  -#elif defined(XALAN_USE_WCHAR_SUPPORT)
   
  -     wchar_t         theBuffer[MAX_PRINTF_DIGITS + 1];
  +XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(void)
  +LongToHexDOMString(
  +                     long                            theValue,
  +                     XalanDOMString&         theResult)
  +{
  +     UnsignedScalarToHexadecimalString(theValue, theResult);
  +}
   
  -     swprintf(theBuffer,
  -                      L"%lu",
  -                      theValue);
   
  -     assign(theResult, theBuffer, length(theBuffer));
   
  -#else
  -
  -     char            theBuffer[MAX_PRINTF_DIGITS + 1];
  +XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(void)
  +UnsignedLongToHexDOMString(
  +                     unsigned long           theValue,
  +                     XalanDOMString&         theResult)
  +{
  +     UnsignedScalarToHexadecimalString(theValue, theResult);
  +}
   
  -     ostrstream      theFormatter(theBuffer, sizeof(theBuffer));
   
  -     theFormatter << theValue << '\0';
   
  -     XalanDOMChar    theWideBuffer[MAX_PRINTF_DIGITS + 1];
  +XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(void)
  +LongToDOMString(
  +                     long                            theValue,
  +                     XalanDOMString&         theResult)
  +{
  +     ScalarToDecimalString(theValue, theResult);
  +}
   
  -     const unsigned int      theLength = length(theBuffer);
   
  -#if defined(XALAN_NO_ALGORITHMS_WITH_BUILTINS)
  -     XalanCopy(theBuffer, theBuffer + theLength, theWideBuffer);
  -#else
  -     copy(theBuffer, theBuffer + theLength, theWideBuffer);
  -#endif
   
  -     assign(theResult, theWideBuffer, theLength);
  -#endif
  +XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(void)
  +UnsignedLongToDOMString(
  +                     unsigned long           theValue,
  +                     XalanDOMString&         theResult)
  +{
  +     ScalarToDecimalString(theValue, theResult);
   }
   
   
  
  
  
  1.38      +112 -105  xml-xalan/c/src/PlatformSupport/DOMStringHelper.hpp
  
  Index: DOMStringHelper.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/PlatformSupport/DOMStringHelper.hpp,v
  retrieving revision 1.37
  retrieving revision 1.38
  diff -u -r1.37 -r1.38
  --- DOMStringHelper.hpp       2000/11/29 18:29:41     1.37
  +++ DOMStringHelper.hpp       2000/12/01 22:13:21     1.38
  @@ -124,8 +124,6 @@
        return XalanDOMString(theString);
   }
   
  -
  -
   #else
   
   #define XALAN_STATIC_UCODE_STRING(str) TranscodeFromLocalCodePage(str)
  @@ -144,8 +142,6 @@
        return theString;
   }
   
  -
  -
   #endif
   
   
  @@ -335,24 +331,6 @@
                        const XalanDOMChar*             theString,
                        XalanDOMChar                    theChar)
   {
  -     // For the time being, we're using our own custom routine,
  -     // since performance is better.
  -#if 0 // defined(XALAN_USE_WCHAR_SUPPORT)
  -
  -     const XalanDOMChar* const       thePointer =
  -                     wcschr(theString, theChar);
  -
  -     if (thePointer == 0)
  -     {
  -             return length(theString);
  -     }
  -     else
  -     {
  -             return thePointer - theString;
  -     }
  -
  -#else
  -
        const XalanDOMChar*             thePointer = theString;
   
        while(*thePointer != theChar && *thePointer != 0)
  @@ -361,8 +339,6 @@
        }
   
        return thePointer - theString;
  -
  -#endif
   }
   
   
  @@ -434,37 +410,13 @@
    * found.
    */
   
  -// For the time being, we're using our own custom routine,
  -// since performance is better.
  -#if 0 // defined(XALAN_USE_WCHAR_SUPPORT)
  -
  -inline unsigned int
  -lastIndexOf(
  -                     const XalanDOMChar*             theString,
  -                     XalanDOMChar                    theChar)
  -{
  -     const XalanDOMChar* const       thePointer =
  -                     wcsrchr(theString, theChar);
  -
  -     if (thePointer == 0)
  -     {
  -             return length(theString);
  -     }
  -     else
  -     {
  -             return thePointer - theString;
  -     }
  -}
  -
  -#else
  -
   XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(unsigned int)
   lastIndexOf(
                        const XalanDOMChar*             theString,
                        XalanDOMChar                    theChar);
   
  -#endif
   
  +
   /**
    * Simulates the java String method lastIndexOf().
    * 
  @@ -562,6 +514,7 @@
   }
   
   
  +
   /**
    * Simulates the java String method endsWith().
    * 
  @@ -596,52 +549,137 @@
   /**
    * Converts a double value into a XalanDOMString
    * 
  - * @param theDouble number to be converted
  + * @param theValue number to be converted
  + * @param theResult the string to append with the result
  + */
  +XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(void)
  +DoubleToDOMString(
  +                     double                          theValue,
  +                     XalanDOMString&         theResult);
  +
  +
  +
  +/**
  + * Converts a double value into a XalanDOMString
  + * 
  + * @param theValue number to be converted
    * @return decimal string representation of the number
    */
  -XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString)
  -DoubleToDOMString(double     theDouble);
  +inline const XalanDOMString
  +DoubleToDOMString(double     theValue)
  +{
  +     XalanDOMString  theResult;
  +
  +     DoubleToDOMString(theValue, theResult);
   
  +     return theResult;
  +}
   
   
  +
   /**
  - * Converts a long value into a XalanDOMString
  + * Converts a long value into a XalanDOMString.  Negative
  + * values are ignored.
    * 
  - * @param theInt number to be converted
  + * @param theValue number to be converted
  + * @param theResult the string to append with the result
  + */
  +XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(void)
  +LongToHexDOMString(
  +                     long                            theValue,
  +                     XalanDOMString&         theResult);
  +
  +
  +
  +/**
  + * Converts a long value into a XalanDOMString.  Returns
  + * an empty string for negative values.
  + * 
  + * @param theValue number to be converted
    * @return hexadecimal string representation of the number
    */
  -XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString)
  -LongToHexDOMString(long              theLong);
  +inline const XalanDOMString
  +LongToHexDOMString(long              theValue)
  +{
  +     XalanDOMString  theResult;
   
  +     LongToHexDOMString(theValue, theResult);
   
  +     return theResult;
  +}
  +
  +
   
   /**
  - * Converts an unsigned long value into a XalanDOMString
  + * Converts an unsigned long value  and appends the
  + * result to a XalanDOMString.
    * 
  - * @param theUnsignedLong number to be converted
  + * @param theValue number to be converted
  + * @param theResult the string to append with the result
  + */
  +XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(void)
  +UnsignedLongToHexDOMString(
  +                     unsigned long           theValue,
  +                     XalanDOMString&         theResult);
  +
  +
  +
  +/**
  + * Converts an unsigned long value and appends the
  + * result to a XalanDOMString.
  + *
  + * @param theValue number to be converted
    * @return hexadecimal string representation of the number
    */
  -XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString)
  -UnsignedLongToHexDOMString(unsigned long     theValue);
  +inline const XalanDOMString
  +UnsignedLongToHexDOMString(unsigned long     theValue)
  +{
  +     XalanDOMString  theResult;
  +
  +     UnsignedLongToHexDOMString(theValue, theResult);
  +
  +     return theResult;
  +}
   
   
   
   /**
    * Converts a long value into a XalanDOMString
    * 
  - * @param theInt number to be converted
  + * @param theValue number to be converted
  + * @param theResult the string to append with the result
  + */
  +XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(void)
  +LongToDOMString(
  +                     long                            theValue,
  +                     XalanDOMString&         theResult);
  +
  +
  +
  +/**
  + * Converts a long value into a XalanDOMString
  + * 
  + * @param theValue number to be converted
    * @return decimal string representation of the number
    */
  -XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString)
  -LongToDOMString(long theValue);
  +inline const XalanDOMString
  +LongToDOMString(long theValue)
  +{
  +     XalanDOMString  theResult;
   
  +     LongToDOMString(theValue, theResult);
   
  +     return theResult;
  +}
   
  +
  +
   /**
  - * Converts an unsigned long value into a XalanDOMString
  + * Converts an unsigned long value and appends the
  + * result to a XalanDOMString.
    * 
    * @param theValue number to be converted
  - * @param theString The string for the result.
  + * @param theResult the string to append with the result
    */
   XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(void)
   UnsignedLongToDOMString(
  @@ -653,7 +691,7 @@
   /**
    * Converts an unsigned long value into a XalanDOMString
    * 
  - * @param theInt number to be converted
  + * @param theValue number to be converted
    * @return decimal string representation of the number
    */
   inline const XalanDOMString
  @@ -1057,7 +1095,7 @@
   inline bool
   isXMLWhitespace(XalanDOMChar theChar)
   {
  -     return XalanXMLChar::isWhitespace(theChar) ? true : false;
  +     return XalanXMLChar::isWhitespace(theChar);
   }
   
   
  @@ -1069,9 +1107,9 @@
    * @return true if character represents a digit
    */
   inline bool
  -isXMLDigit(XalanDOMChar      theChar)
  +isXMLDigit(XalanDOMChar              theChar)
   {    
  -     return XalanXMLChar::isDigit(theChar) ? true : false;
  +     return XalanXMLChar::isDigit(theChar);
   }
   
   
  @@ -1083,10 +1121,10 @@
    * @return true if character represents a letter or digit
    */
   inline bool
  -isXMLLetterOrDigit(XalanDOMChar      theChar)
  +isXMLLetterOrDigit(XalanDOMChar              theChar)
   {
        return  XalanXMLChar::isDigit(theChar) || 
  -                     XalanXMLChar::isLetter(theChar) ? true : false;
  +                     XalanXMLChar::isLetter(theChar);
   }
   
   
  @@ -1106,7 +1144,7 @@
   substring(
                        const XalanDOMChar*             theString,
                        unsigned int                    theStartIndex,
  -                     unsigned int                    theEndIndex = UINT_MAX);
  +                     unsigned int                    theEndIndex = 
unsigned(-1));
   
   
   
  @@ -1125,7 +1163,7 @@
   substring(
                        const XalanDOMString&   theString,
                        unsigned int                    theStartIndex,
  -                     unsigned int                    theEndIndex = UINT_MAX);
  +                     unsigned int                    theEndIndex = 
unsigned(-1));
   
   
   
  @@ -1313,11 +1351,6 @@
   
   
   
  -// For the time being, we're using our own custom routine,
  -// since performance is better.
  -
  -#if 0 // defined(XALAN_USE_WCHAR_SUPPORT)
  -
   /**
    * Compare the contents of two strings.
    * 
  @@ -1326,23 +1359,11 @@
    * @return Returns 0 for equal strings, less than 0 if theLHS is less
    * than theRHS, or greater than 0 if theRHS is greater than theLHS.
    */
  -inline int
  -compare(
  -                     const XalanDOMChar*             theLHS,
  -                     const XalanDOMChar*             theRHS)
  -{
  -     return wcscmp(theLHS, theRHS);
  -}
  -
  -#else
  -
   XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(int)
   compare(
                        const XalanDOMChar*             theLHS,
                        const XalanDOMChar*             theRHS);
   
  -#endif
  -
   
   
   /**
  @@ -1444,8 +1465,6 @@
   
   
   
  -#if 0 // defined(XALAN_USE_WCHAR_SUPPORT)
  -
   /**
    * Compare the contents of two strings using the
    * the collation settings of the current code page.
  @@ -1457,16 +1476,6 @@
    * @see operator<()
    * @see compare()
    */
  -inline int
  -collationCompare(
  -                     const XalanDOMChar*             theLHS,
  -                     const XalanDOMChar*             theRHS)
  -{
  -     return wcscoll(theLHS, theRHS);
  -}
  -
  -#else
  -
   // Can't really do it, so just call compare...
   inline int
   collationCompare(
  @@ -1476,8 +1485,6 @@
        return compare(theLHS, theRHS);
   }
   
  -#endif
  -
   
   
   /**
  @@ -2029,7 +2036,7 @@
   
                theTemp.push_back(char(0));
   
  -             append(theString, XalanDOMString(&theTemp[0]));
  +             append(theString, XalanDOMString(&theTemp[0], theTemp.size() - 
1));
        }
   #endif
   
  
  
  

Reply via email to