dbertoni    02/04/01 22:10:44

  Modified:    c/src/XalanDOM XalanDOMString.cpp XalanDOMString.hpp
  Log:
  Better implementations of assign.  Added new iterator accessors.
  
  Revision  Changes    Path
  1.18      +50 -7     xml-xalan/c/src/XalanDOM/XalanDOMString.cpp
  
  Index: XalanDOMString.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XalanDOM/XalanDOMString.cpp,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- XalanDOMString.cpp        6 Feb 2002 20:05:25 -0000       1.17
  +++ XalanDOMString.cpp        2 Apr 2002 06:10:44 -0000       1.18
  @@ -2,7 +2,7 @@
    * The Apache Software License, Version 1.1
    *
    *
  - * Copyright (c) 1999-2000 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
  @@ -175,9 +175,7 @@
                        // If the string is not of 0 length, resize but
                        // put a copy of theChar where the terminating
                        // byte used to be.
  -                     m_data.resize(theCount, theChar);
  -
  -                     m_data[theOldSize] = theChar;
  +                     m_data.resize(theCount + 1, theChar);
                }
   
                m_size = theCount;
  @@ -232,16 +230,61 @@
   
   XalanDOMString&
   XalanDOMString::assign(
  +                     const XalanDOMString&   theSource,
  +                     size_type                               thePosition,
  +                     size_type                               theCount)
  +{
  +     invariants();
  +
  +     assert(thePosition < theSource.size() && thePosition + theCount <= 
theSource.size());
  +
  +     if (&theSource != this)
  +     {
  +             erase();
  +
  +             append(theSource, thePosition, theCount);
  +     }
  +     else
  +     {
  +             if (thePosition == 0)
  +             {
  +                     // See if we're being asked to
  +                     // assign everything to ourself,
  +                     // which is a noop...
  +                     if (theCount != m_size)
  +                     {
  +                             // We're being asked to truncate...
  +                             resize(theCount);
  +                     }
  +             }
  +             else
  +             {
  +                     // Yuck.  We have to move data...
  +                     memmove(&*begin(), &*begin() + thePosition, theCount * 
sizeof(XalanDOMChar));
  +
  +                     resize(theCount);
  +             }
  +     }
  +
  +     invariants();
  +
  +     return *this;
  +}
  +
  +
  +
  +XalanDOMString&
  +XalanDOMString::assign(
                const_iterator  theFirstPosition,
                const_iterator  theLastPosition)
   {
        invariants();
   
  -     erase();
  +     m_data.assign(theFirstPosition, theLastPosition);
   
  -     invariants();
  +     m_data.push_back(XalanDOMChar(0));
   
  -     insert(begin(), theFirstPosition, theLastPosition);
  +     m_size = m_data.size() - 1;
   
        invariants();
   
  
  
  
  1.21      +34 -16    xml-xalan/c/src/XalanDOM/XalanDOMString.hpp
  
  Index: XalanDOMString.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XalanDOM/XalanDOMString.hpp,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- XalanDOMString.hpp        25 Sep 2001 21:13:55 -0000      1.20
  +++ XalanDOMString.hpp        2 Apr 2002 06:10:44 -0000       1.21
  @@ -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
  @@ -177,6 +177,22 @@
                return m_data.begin();
        }
   
  +     iterator
  +     end()
  +     {
  +             invariants();
  +
  +             return m_data.end();
  +     }
  +
  +     const_iterator
  +     end() const
  +     {
  +             invariants();
  +
  +             return m_data.end();
  +     }
  +
        reverse_iterator
        rbegin()
        {
  @@ -193,6 +209,22 @@
                return m_data.rbegin();
        }
   
  +     reverse_iterator
  +     rend()
  +     {
  +             invariants();
  +
  +             return m_data.rend();
  +     }
  +
  +     const_reverse_iterator
  +     rend() const
  +     {
  +             invariants();
  +
  +             return m_data.rend();
  +     }
  +
        size_type
        size() const
        {
  @@ -417,21 +449,7 @@
        assign(
                        const XalanDOMString&   theSource,
                        size_type                               thePosition,
  -                     size_type                               theCount)
  -     {
  -             invariants();
  -
  -             if (&theSource != this)
  -             {
  -                     erase();
  -
  -                     append(theSource, thePosition, theCount);
  -             }
  -
  -             invariants();
  -
  -             return *this;
  -     }
  +                     size_type                               theCount);
   
        XalanDOMString&
        assign(const XalanDOMString&    theSource)
  
  
  

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

Reply via email to