dbertoni    00/05/18 11:34:47

  Modified:    c/src/PlatformSupport DOMStringHelper.cpp
                        DOMStringHelper.hpp
  Log:
  Added a few more convenience functions.  Fixed bug where vector was not 
null-terminated.  Added more error checking to DOMStringToDouble().
  
  Revision  Changes    Path
  1.23      +20 -3     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.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- DOMStringHelper.cpp       2000/05/12 22:01:30     1.22
  +++ DOMStringHelper.cpp       2000/05/18 18:34:42     1.23
  @@ -844,7 +844,7 @@
        unsigned int    theLength = length(data);
   
        // Create a vector which includes the terminating 0.
  -     return XalanDOMCharVectorType(data, data + theLength);
  +     return XalanDOMCharVectorType(data, data + theLength + 1);
   }
   
   
  @@ -967,14 +967,15 @@
                        // localization as well.
                        bool    fError = false;
   
  -                     VectorType::const_iterator      i = theVector.begin();
  +                     VectorType::const_iterator      begin = 
theVector.begin();
  +                     VectorType::const_iterator      i = begin;
                        VectorType::const_iterator      j = theVector.end();
   
                        j--;
   
                        do
                        {
  -                             if ((*i < '0' || *i > '9') && !(*i == '.' || *i 
== 'e' || *i == 'E' || *i == 'f' || *i == 'F' || *i == '-'))
  +                             if ((*i < '0' || *i > '9') && !(*i == '.' || *i 
== 'e' || *i == 'E' || *i == 'f' || *i == 'F' || (*i == '-' && i == begin)))
                                {
                                        fError = true;
                                }
  @@ -1122,6 +1123,22 @@
        return theString;
   
   #endif
  +}
  +
  +
  +
  +XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString)
  +UnsignedLongToHexDOMString(unsigned long     theUnsignedLong)
  +{
  +     ostrstream      theFormatter;
  +
  +     theFormatter << hex << theUnsignedLong << '\0';
  +
  +     const XalanDOMString    theString = theFormatter.str();
  +
  +     theFormatter.freeze(false);
  +
  +     return theString;
   }
   
   
  
  
  
  1.20      +173 -2    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.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- DOMStringHelper.hpp       2000/05/11 19:01:58     1.19
  +++ DOMStringHelper.hpp       2000/05/18 18:34:43     1.20
  @@ -481,7 +481,7 @@
    * @return hexadecimal string representation of the number
    */
   XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString)
  -LongToHexDOMString(long              theInt);
  +LongToHexDOMString(long              theLong);
   
   
   
  @@ -489,10 +489,21 @@
    * Converts a long value into a XalanDOMString
    * 
    * @param theInt number to be converted
  + * @return hexadecimal string representation of the number
  + */
  +XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString)
  +UnsignedLongToHexDOMString(unsigned long     theUnsignedLong);
  +
  +
  +
  +/**
  + * Converts a long value into a XalanDOMString
  + * 
  + * @param theInt number to be converted
    * @return decimal string representation of the number
    */
   XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString)
  -LongToDOMString(long theInt);
  +LongToDOMString(long theLong);
   
   
   
  @@ -1203,6 +1214,166 @@
   #endif
   
   
  +
  +/**
  + * Get a pointer to the first element of the vector as
  + * a null-terminated string
  + *
  + * @param theSVector target vector
  + * @return null-terminated string of XalanDOMChar
  + */
  +inline const XalanDOMChar*
  +c_wstr(const XalanDOMCharVectorType& theVector)
  +{
  +     return &theVector[0];
  +}
  +
  +
  +
  +/**
  + * Compare the contents of two vectors for equality
  + * 
  + * @param theLHS first vector to compare
  + * @param theRHS second vector to compare
  + * @return true if the contents of both vectors are identical
  + */
  +inline bool
  +equals(
  +                     const XalanDOMCharVectorType&   theLHS,
  +                     const XalanDOMCharVectorType&   theRHS)
  +{
  +     return theLHS == theRHS;
  +}
  +
  +
  +
  +/**
  + * Compare the contents of two strings for equality
  + * 
  + * @param theLHS XalanDOMCharVectorType to compare
  + * @param theRHS string to compare
  + * @return true if the contents of are identical
  + */
  +inline bool
  +equals(
  +                     const XalanDOMCharVectorType&   theLHS,
  +                     const XalanDOMChar*                             theRHS)
  +{
  +     return equals(c_wstr(theLHS), theRHS);
  +}
  +
  +
  +
  +/**
  + * Compare the contents of two strings for equality
  + * 
  + * @param theLHS string to compare
  + * @param theRHS XalanDOMCharVectorType to compare
  + * @return true if the contents are identical
  + */
  +inline bool
  +equals(
  +                     const XalanDOMChar*                             theLHS,
  +                     const XalanDOMCharVectorType&   theRHS)
  +{
  +     return equals(theLHS, c_wstr(theRHS));
  +}
  +
  +
  +
  +/**
  + * Compare the contents of a XalanDOMCharVectorType
  + * and a XalanDOMString for equality
  + * 
  + * @param theLHS XalanDOMCharVectorType to compare
  + * @param theRHS XalanDOMString to compare
  + * @return true if the contents of both are identical
  + */
  +inline bool
  +equals(
  +                     const XalanDOMCharVectorType&   theLHS,
  +                     const XalanDOMString&                   theRHS)
  +{
  +     return equals(c_wstr(theLHS), c_wstr(theRHS));
  +}
  +
  +
  +
  +/**
  + * Compare the contents of a XalanDOMString and a
  + * XalanDOMCharVectorType for equality
  + * 
  + * @param theLHS XalanDOMString to compare
  + * @param theRHS XalanDOMCharVectorType to compare
  + * @return true if the contents of both are identical
  + */
  +inline bool
  +equals(
  +                     const XalanDOMString&                   theLHS,
  +                     const XalanDOMCharVectorType&   theRHS)
  +{
  +     return equals(c_wstr(theLHS), c_wstr(theRHS));
  +}
  +
  +
  +
  +/**
  + * Compare the contents of two XalanDOMCharVectorTypes.
  + * 
  + * @param theLHS first vector to compare
  + * @param theRHS second vector to compare
  + * @return Returns 0 for equal vectors, less than 0 if theLHS is less
  + * than theRHS, or greater than 0 if theRHS is greater than theLHS.
  + * @see operator<
  + * @see collationCompare
  + */
  +inline int
  +compare(
  +                     const XalanDOMCharVectorType&   theLHS,
  +                     const XalanDOMCharVectorType&   theRHS)
  +{
  +     return compare(&theLHS[0], &theRHS[0]);
  +}
  +
  +
  +
  +/**
  + * Compare the contents of two vectors using the
  + * the collation settings of the current code page.
  + * 
  + * @param theLHS first vector to compare
  + * @param theRHS second vector to compare
  + * @return Returns 0 for equal vectors, less than 0 if theLHS is less
  + * than theRHS, or greater than 0 if theRHS is greater than theLHS.
  + * @see operator<()
  + * @see compare()
  + */
  +inline int
  +collationCompare(
  +                     const XalanDOMCharVectorType&   theLHS,
  +                     const XalanDOMCharVectorType&   theRHS)
  +{
  +     return collationCompare(&theLHS[0], &theRHS[0]);
  +}
  +
  +
  +
  +/**
  + * Implements operator< for XalanDOMCharVectorType.
  + * 
  + * @param theLHS first vector to compare
  + * @param theRHS second vector to compare
  + * @return Returns true if theLHS is lexically
  + * less than theRHS
  + * @see compare
  + */
  +inline bool
  +operator<(
  +                     const XalanDOMCharVectorType&   theLHS,
  +                     const XalanDOMCharVectorType&   theRHS)
  +{
  +     return compare(theLHS, theRHS) < 0 ? true : false;
  +}
   
   
   
  
  
  

Reply via email to