dbertoni    02/05/05 22:16:56

  Modified:    c/src/PlatformSupport DOMStringHelper.cpp
                        DOMStringHelper.hpp
  Log:
  Better implementations of startsWith() and endsWith().
  
  Revision  Changes    Path
  1.70      +27 -67    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.69
  retrieving revision 1.70
  diff -u -r1.69 -r1.70
  --- DOMStringHelper.cpp       11 Apr 2002 05:52:02 -0000      1.69
  +++ DOMStringHelper.cpp       6 May 2002 05:16:56 -0000       1.70
  @@ -285,21 +285,21 @@
   
   XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(bool)
   startsWith(
  -                     const XalanDOMChar*             theString,
  -                     const XalanDOMChar*             theSubstring)
  +                     const XalanDOMChar*                     theString,
  +                     XalanDOMString::size_type       theStringLength,
  +                     const XalanDOMChar*                     theSubstring,
  +                     XalanDOMString::size_type       theSubstringLength)
   {
  -     bool            fResult = false;
  -
  -     const XalanDOMString::size_type         theStringLength = 
length(theString);
  -
  -     const XalanDOMString::size_type         theSubstringLength = 
length(theSubstring);
  -
        if (theSubstringLength == 0)
        {
                // Make this work like Java...
                return true;
        }
  -     else if (theStringLength >= theSubstringLength)
  +     else if (theStringLength < theSubstringLength)
  +     {
  +             return false;
  +     }
  +     else
        {
                XalanDOMString::size_type       i = 0;
   
  @@ -307,7 +307,7 @@
                for (;
                                i < theSubstringLength &&
                                                theString[i] == theSubstring[i];
  -                                     i++)
  +                                     ++i)
                {
                        ;
                }
  @@ -316,77 +316,29 @@
                // return true.
                if (i == theSubstringLength)
                {
  -                     fResult = true;
  +                     return true;
  +             }
  +             else
  +             {
  +                     return false;
                }
        }
  -
  -     return fResult;
  -}
  -
  -
  -
  -static const XalanDOMChar    theDummyEmptyString = 0;
  -
  -
  -
  -XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(bool)
  -startsWith(
  -                     const XalanDOMChar*             theString,
  -                     const XalanDOMString&   theSubstring)
  -{
  -     const XalanDOMChar*     const   theBuffer =
  -             c_wstr(theSubstring);
  -
  -     return startsWith(theString, theBuffer == 0 ? &theDummyEmptyString : 
theBuffer);
  -}
  -
  -
  -
  -XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(bool)
  -startsWith(
  -                     const XalanDOMString&   theString,
  -                     const XalanDOMChar*             theSubstring)
  -{
  -     const XalanDOMChar*     const   theBuffer =
  -             c_wstr(theString);
  -
  -     return startsWith(theBuffer == 0 ? &theDummyEmptyString : theBuffer, 
theSubstring);
  -}
  -
  -
  -
  -XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(bool)
  -startsWith(
  -                     const XalanDOMString&   theString,
  -                     const XalanDOMString&   theSubstring)
  -{
  -     const XalanDOMChar*     const   theStringBuffer =
  -             c_wstr(theString);
  -
  -     const XalanDOMChar*     const   theSubstringBuffer =
  -             c_wstr(theSubstring);
  -
  -     return startsWith(
  -             theStringBuffer == 0 ? &theDummyEmptyString : theStringBuffer,
  -             theSubstringBuffer == 0 ? &theDummyEmptyString : 
theSubstringBuffer);
   }
   
   
   
   XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(bool)
   endsWith(
  -                     const XalanDOMChar*             theString,
  -                     const XalanDOMChar*             theSubstring)
  +                     const XalanDOMChar*                     theString,
  +                     XalanDOMString::size_type       theStringLength,
  +                     const XalanDOMChar*                     theSubstring,
  +                     XalanDOMString::size_type       theSubstringLength)
   {
        assert(theString != 0);
        assert(theSubstring != 0);
   
        bool                            fResult = false;
   
  -     const XalanDOMString::size_type         theStringLength = 
length(theString);
  -
  -     const XalanDOMString::size_type         theSubstringLength = 
length(theSubstring);
  -
        // If the substring is longer, there's no point in continuing.
        if (theSubstringLength >  0 && theStringLength >= theSubstringLength)
        {
  @@ -1455,6 +1407,10 @@
   {
        char                    theBuffer[MAX_PRINTF_DIGITS + 1];
   
  +#if defined(XALAN_STRICT_ANSI_HEADERS)
  +        using std::sprintf;
  +#endif
  +
        unsigned int    theCharsWritten = sprintf(theBuffer, "%p", theValue);
        assert(theCharsWritten != 0);
   
  @@ -1502,6 +1458,10 @@
        else
        {
                char                    theBuffer[MAX_PRINTF_DIGITS + 1];
  +
  +#if defined(XALAN_STRICT_ANSI_HEADERS)
  +             using std::sprintf;
  +#endif
   
                unsigned int    theCharsWritten = sprintf(theBuffer, "%f", 
theDouble);
                assert(theCharsWritten != 0);
  
  
  
  1.56      +82 -15    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.55
  retrieving revision 1.56
  diff -u -r1.55 -r1.56
  --- DOMStringHelper.hpp       11 Apr 2002 05:52:02 -0000      1.55
  +++ DOMStringHelper.hpp       6 May 2002 05:16:56 -0000       1.56
  @@ -2,7 +2,7 @@
    * The Apache Software License, Version 1.1
    *
    *
  - * Copyright (c) 1999 The Apache Software Foundation.  All rights 
  + * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights 
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -498,8 +498,29 @@
    */
   XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(bool)
   startsWith(
  +                     const XalanDOMChar*                     theString,
  +                     XalanDOMString::size_type       theStringLength,
  +                     const XalanDOMChar*                     theSubstring,
  +                     XalanDOMString::size_type       theSubstringLength);
  +
  +
  +
  +/**
  + * Simulates the java String method startsWith().
  + * 
  + * @param theDOMString target string to search
  + * @param theSubstring substring searched for
  + * @return true if the target string begins with the substring
  + */
  +inline bool
  +startsWith(
                        const XalanDOMChar*             theString,
  -                     const XalanDOMChar*             theSubstring);
  +                     const XalanDOMChar*             theSubstring)
  +{
  +     assert(theString != 0 && theSubstring != 0);
  +
  +     return startsWith(theString, length(theString), theSubstring, 
length(theSubstring));
  +}
   
   
   
  @@ -510,10 +531,15 @@
    * @param theSubstring substring searched for
    * @return true if the target string begins with the substring
    */
  -XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(bool)
  +inline bool
   startsWith(
                        const XalanDOMChar*             theString,
  -                     const XalanDOMString&   theSubstring);
  +                     const XalanDOMString&   theSubstring)
  +{
  +     assert(theString != 0);
  +
  +     return startsWith(theString, length(theString), c_wstr(theSubstring), 
length(theSubstring));
  +}
   
   
   
  @@ -524,10 +550,15 @@
    * @param theSubstring substring searched for
    * @return true if the target string begins with the substring
    */
  -XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(bool)
  +inline bool
   startsWith(
                        const XalanDOMString&   theString,
  -                     const XalanDOMChar*             theSubstring);
  +                     const XalanDOMChar*             theSubstring)
  +{
  +     assert(theSubstring != 0);
  +
  +     return startsWith(c_wstr(theString), length(theString), theSubstring, 
length(theSubstring));
  +}
   
   
   
  @@ -538,17 +569,20 @@
    * @param theSubstring substring searched for
    * @return true if the target string begins with the substring
    */
  -XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(bool)
  +inline bool
   startsWith(
                        const XalanDOMString&   theString,
  -                     const XalanDOMString&   theSubstring);
  +                     const XalanDOMString&   theSubstring)
  +{
  +     return startsWith(c_wstr(theString), length(theString), 
c_wstr(theSubstring), length(theSubstring));
  +}
   
   
   
   /**
    * Simulates the java String method startsWith().
    * 
  - * @param theDOMString target string to search
  + * @param theString target string to search
    * @param theSubstring substring searched for
    * @return true if the target string begins with the substring
    */
  @@ -567,30 +601,51 @@
   /**
    * Simulates the java String method endsWith().
    * 
  - * @param theDOMString target string to search
  + * @param theString target string to search
    * @param theSubstring substring searched for
    * @return true if the target string ends with the substring
    */
   XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(bool)
   endsWith(
  +                     const XalanDOMChar*                     theString,
  +                     XalanDOMString::size_type       theStringLength,
  +                     const XalanDOMChar*                     theSubstring,
  +                     XalanDOMString::size_type       theSubstringLength);
  +
  +
  +
  +/**
  + * Simulates the java String method endsWith().
  + * 
  + * @param theString target string to search
  + * @param theSubstring substring searched for
  + * @return true if the target string ends with the substring
  + */
  +inline bool
  +endsWith(
                        const XalanDOMChar*             theString,
  -                     const XalanDOMChar*             theSubstring);
  +                     const XalanDOMChar*             theSubstring)
  +{
  +     assert(theString != 0 && theSubstring != 0);
  +
  +     return endsWith(theString, length(theString), theSubstring, 
length(theSubstring));
  +}
   
   
   
   /**
    * Simulates the java String method endsWith().
    * 
  - * @param theDOMString target string to search
  + * @param theString target string to search
    * @param theSubstring substring searched for
    * @return true if the target string ends with the substring
    */
   inline bool
   endsWith(
  -                     const XalanDOMString&   theDOMString,
  +                     const XalanDOMString&   theString,
                        const XalanDOMString&   theSubstring)
   {
  -     return endsWith(c_wstr(theDOMString), c_wstr(theSubstring));
  +     return endsWith(c_wstr(theString), length(theString), 
c_wstr(theSubstring), length(theSubstring));
   }
   
   
  @@ -1222,7 +1277,7 @@
    * @param theSubstring  target string
    * @param theStartIndex starting index, inclusive
    * @param theEndIndex   ending index, exclusive
  - * @return Returns a reference to theSubstring
  + * @return A reference to theSubstring
    */
   XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString)&
   substring(
  @@ -1435,6 +1490,9 @@
   /**
    * Compare the contents of two strings.
    * 
  + * THIS FUNCTION DOES NOT COMPARE STRINGS LIKE strcmp() OR ANY
  + * OTHER "COLLATION" ALGORITHM.
  + *
    * @param theLHS first string to compare
    * @param theRHS second string to compare
    * @return Returns 0 for equal strings, less than 0 if theLHS is less
  @@ -1499,6 +1557,9 @@
    * manner.  Only the characters a-z and A-Z are considered as
    * characters with "case".
    *
  + * THIS FUNCTION DOES NOT COMPARE STRINGS LIKE strcmp() OR ANY
  + * OTHER "COLLATION" ALGORITHM.
  + *
    * @param theLHS first array to compare
    * @param theLHSLength the length of the first array
    * @param theRHS second array to compare
  @@ -1520,6 +1581,9 @@
    * manner.  Only the characters a-z and A-Z are considered as
    * characters with "case".
    *
  + * THIS FUNCTION DOES NOT COMPARE STRINGS LIKE strcmp() OR ANY
  + * OTHER "COLLATION" ALGORITHM.
  + *
    * @param theLHS first string to compare
    * @param theRHS second string to compare
    * @return Returns 0 for equal strings, less than 0 if theLHS is less
  @@ -1539,6 +1603,9 @@
    * Compare the contents of two strings, in a case insensitive
    * manner.  Only the characters a-z and A-Z are considered as
    * characters with "case".
  + *
  + * THIS FUNCTION DOES NOT COMPARE STRINGS LIKE strcmp() OR ANY
  + * OTHER "COLLATION" ALGORITHM.
    *
    * @param theLHS first string to compare
    * @param theRHS second string to compare
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to