auriemma    00/11/07 06:58:06

  Modified:    c/src/XPath FunctionNormalizeSpace.cpp
                        FunctionNormalizeSpace.hpp
  Log:
  Merged string class changes from hpp to cpp.
  
  Revision  Changes    Path
  1.2       +33 -21    xml-xalan/c/src/XPath/FunctionNormalizeSpace.cpp
  
  Index: FunctionNormalizeSpace.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XPath/FunctionNormalizeSpace.cpp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FunctionNormalizeSpace.cpp        2000/11/06 19:49:15     1.1
  +++ FunctionNormalizeSpace.cpp        2000/11/07 14:58:05     1.2
  @@ -77,12 +77,8 @@
                const XObject*                                  arg1)
   {
        assert(arg1 != 0);
  -     
  -     XalanDOMString  theSourceString;
  -
  -     theSourceString = arg1->str();
  -
  -     return 
executionContext.getXObjectFactory().createString(NormalizeSpace(theSourceString));
  +             
  +     return normalize(executionContext, arg1->str());
   }
   
   
  @@ -115,15 +111,16 @@
                theSourceString = theXObject->str();            
        }
   
  -     return 
executionContext.getXObjectFactory().createString(NormalizeSpace(theSourceString));
  +     return normalize(executionContext, theSourceString);
   }
   
  -
   
  -const XalanDOMString
  -FunctionNormalizeSpace::NormalizeSpace(const XalanDOMString& 
theSourceString) const
  +XObject*
  +FunctionNormalizeSpace::normalize(
  +             XPathExecutionContext&  executionContext,
  +             const XalanDOMString&   theString)
   {
  -     const unsigned int              theSourceStringLength = 
length(theSourceString);
  +     const unsigned int              theStringLength = length(theString);
   
        XalanDOMChar                    thePreviousChar = 0;
   
  @@ -132,18 +129,24 @@
   #if !defined(XALAN_NO_NAMESPACES)
        using std::vector;
   #endif
  +
  +#if defined(XALAN_NO_NAMESPACES)
  +     typedef vector<XalanDOMChar>            VectorType;
  +#else
  +     typedef std::vector<XalanDOMChar>       VectorType;
  +#endif
   
  -     vector<XalanDOMChar>    theVector;
  +     // A vector to contain the result.
  +     VectorType                              theVector;
   
        // The result string can only be as large as the source string, so
  -     // just reserve the space now.  Also reserve a space for the
  -     // terminating 0.
  -     theVector.reserve(theSourceStringLength + 1);
  +     // just reserve the space now.
  +     theVector.reserve(theStringLength);
   
        // OK, strip out any multiple spaces...
  -     for (unsigned int i = 0; i < theSourceStringLength; i++)
  +     for (unsigned int i = 0; i < theStringLength; i++)
        {
  -             const XalanDOMChar      theCurrentChar = 
charAt(theSourceString, i);
  +             const XalanDOMChar      theCurrentChar = charAt(theString, i);
   
                if (isXMLWhitespace(theCurrentChar) == true)
                {
  @@ -163,13 +166,22 @@
                thePreviousChar = theCurrentChar;
        }
   
  -     if (theVector.empty() == false && isXMLWhitespace(theVector.back()) == 
true)
  +     VectorType::size_type   theSize = theVector.size();
  +
  +     if (theSize == 0)
        {
  -             // The last character is a space, so remove it
  -             theVector.pop_back();
  +             return 
executionContext.getXObjectFactory().createString(XalanDOMString());
        }
  +     else
  +     {
  +             if (isXMLWhitespace(theVector.back()) == true)
  +             {
  +                     // The last character is a space, so remove it
  +                     --theSize;
  +             }
   
  -     return XalanDOMString(theVector.begin(), theVector.size());
  +             return 
executionContext.getXObjectFactory().createString(XalanDOMString(theVector.begin(),
 theSize));
  +     }
   }
   
   
  
  
  
  1.2       +5 -0      xml-xalan/c/src/XPath/FunctionNormalizeSpace.hpp
  
  Index: FunctionNormalizeSpace.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XPath/FunctionNormalizeSpace.hpp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FunctionNormalizeSpace.hpp        2000/11/06 19:52:44     1.1
  +++ FunctionNormalizeSpace.hpp        2000/11/07 14:58:06     1.2
  @@ -102,6 +102,11 @@
   
   private:
   
  +     XObject*
  +     normalize(
  +             XPathExecutionContext&  executionContext,
  +             const XalanDOMString&   theString);
  +
        const XalanDOMString
        NormalizeSpace(
                        const XalanDOMString& theSourceString) const;
  
  
  

Reply via email to