dbertoni    01/06/18 14:36:47

  Modified:    c/src/XalanDOM XalanDOMString.cpp XalanDOMString.hpp
  Log:
  Implemented exception throwing for transcoding errors.  Implemented new 
member functions for better inter-operability with narrow character strings.
  
  Revision  Changes    Path
  1.11      +92 -27    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.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- XalanDOMString.cpp        2001/04/11 20:25:56     1.10
  +++ XalanDOMString.cpp        2001/06/18 21:36:42     1.11
  @@ -132,18 +132,7 @@
   
        if (*theString != 0)
        {
  -             if (theCount == size_type(npos))
  -             {
  -            TranscodeFromLocalCodePage(theString, m_data, true);
  -             }
  -             else
  -             {
  -                     TranscodeFromLocalCodePage(theString, theCount, m_data, 
true);
  -             }
  -
  -#if defined(XALAN_DOMSTRING_CACHE_SIZE)
  -             m_size = m_data.size() - 1;
  -#endif
  +             append(theString, theCount);
        }
   
        invariants();
  @@ -176,20 +165,6 @@
   
   
   
  -XalanDOMString&
  -XalanDOMString::operator=(const XalanDOMChar*        theRHS)
  -{
  -     erase();
  -
  -     append(theRHS, length(theRHS));
  -
  -     invariants();
  -
  -     return *this;
  -}
  -
  -
  -
   void
   XalanDOMString::resize(
                        size_type               theCount,
  @@ -334,11 +309,75 @@
   
   
   
  +static inline void
  +doTranscode(
  +                     const char*                                     
theString,
  +                     XalanDOMString::size_type       theCount,
  +                     XalanDOMCharVectorType&         theVector)
  +{
  +     assert(theString != 0);
  +
  +     if (theCount == XalanDOMString::size_type(XalanDOMString::npos))
  +     {
  +             if (TranscodeFromLocalCodePage(theString, theVector, true) == 
false)
  +             {
  +                     throw XalanDOMString::TranscodingError();
  +             }
  +     }
  +     else
  +     {
  +             if (TranscodeFromLocalCodePage(theString, theCount, theVector, 
true) == false)
  +             {
  +                     throw XalanDOMString::TranscodingError();
  +             }
  +     }
  +}
  +
  +
  +
  +XalanDOMString&
  +XalanDOMString::append(
  +                     const char*             theString,
  +                     size_type               theCount)
  +{
  +     invariants();
  +
  +     const size_type         theLength =
  +                     theCount == size_type(npos) ? length(theString) : 
theCount;
  +
  +     if (theLength != 0)
  +     {
  +             if (size() == 0)
  +             {
  +                     doTranscode(theString, theCount, m_data);
  +             }
  +             else
  +             {
  +                     XalanDOMCharVectorType  theTempVector;
  +
  +                     doTranscode(theString, theCount, theTempVector);
  +
  +                     append(&*theTempVector.begin(), theTempVector.size());
  +             }
  +
  +     #if defined(XALAN_DOMSTRING_CACHE_SIZE)
  +             m_size = m_data.size() - 1;
  +     #endif
  +     }
  +
  +     invariants();
  +
  +     return *this;
  +}
  +
  +
   XalanDOMString&
   XalanDOMString::append(
                        size_type               theCount,
                        XalanDOMChar    theChar)
   {
  +     invariants();
  +
        if (m_data.size() == 0)
        {
                m_data.insert(m_data.end(), theCount + 1, theChar);
  @@ -373,6 +412,8 @@
                        const XalanDOMChar*             theString,
                        size_type                               theCount)
   {
  +     invariants();
  +
        m_data.insert(getIteratorForPosition(thePosition), theString, theString 
+ theCount);
   
   #if defined(XALAN_DOMSTRING_CACHE_SIZE)
  @@ -392,6 +433,8 @@
                        size_type               theCount,
                        XalanDOMChar    theChar)
   {
  +     invariants();
  +
        m_data.insert(getIteratorForPosition(thePosition), theCount, theChar);
   
   #if defined(XALAN_DOMSTRING_CACHE_SIZE)
  @@ -410,6 +453,8 @@
                        iterator                thePosition,
                        XalanDOMChar    theChar)
   {
  +     invariants();
  +
        m_data.insert(thePosition, theChar);
   
   #if defined(XALAN_DOMSTRING_CACHE_SIZE)
  @@ -429,6 +474,8 @@
                        size_type               theCount,
                        XalanDOMChar    theChar)
   {
  +     invariants();
  +
        m_data.insert(thePosition, theCount, theChar);
   
   #if defined(XALAN_DOMSTRING_CACHE_SIZE)
  @@ -446,6 +493,8 @@
                const_iterator  theFirstPosition,
                const_iterator  theLastPosition)
   {
  +     invariants();
  +
        m_data.insert(theInsertPosition, theFirstPosition, theLastPosition);
   
   #if defined(XALAN_DOMSTRING_CACHE_SIZE)
  @@ -548,7 +597,10 @@
   
        CharVectorType  theResult;
   
  -     TranscodeToLocalCodePage(c_str(), length(), theResult, true);
  +     if (TranscodeToLocalCodePage(c_str(), length(), theResult, true) == 
false)
  +     {
  +             throw TranscodingError();
  +     }
   
        return theResult;
   }
  @@ -639,6 +691,16 @@
   
   
   
  +XalanDOMString::size_type
  +XalanDOMString::length(const char*   theString)
  +{
  +     assert(theString != 0);
  +
  +     return strlen(theString);
  +}
  +
  +
  +
   #if defined(XALAN_USE_XERCES_LOCAL_CODEPAGE_TRANSCODERS)
   
   
  @@ -697,6 +759,9 @@
   
        do
        {
  +             // $$$ ToDo: We should use the Xerces transcoder interface
  +             // instead of XMLString::transcode(), so we can better control
  +             // error handling and failures due to inadequate space.
                fSuccess = XMLString::transcode(
                                        theRealSourceString,
                                        &*theTargetVector.begin(),
  
  
  
  1.16      +92 -44    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.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- XalanDOMString.hpp        2001/06/14 18:52:35     1.15
  +++ XalanDOMString.hpp        2001/06/18 21:36:43     1.16
  @@ -67,6 +67,10 @@
   
   
   
  +#include <XalanDOM/XalanDOMException.hpp>
  +
  +
  +
   // UTF-16 character...
   typedef unsigned short       XalanDOMChar;
   
  @@ -136,38 +140,25 @@
        XalanDOMString&
        operator=(const XalanDOMString& theRHS)
        {
  -             if (&theRHS != this)
  -             {
  -                     m_data = theRHS.m_data;
  -
  -#if defined(XALAN_DOMSTRING_CACHE_SIZE)
  -                     m_size = theRHS.m_size;
  -#endif
  -             }
  -
  -             invariants();
  +             return assign(theRHS);
  +     }
   
  -             return *this;
  +     XalanDOMString&
  +     operator=(const XalanDOMChar*   theRHS)
  +     {
  +             return assign(theRHS);
        }
   
        XalanDOMString&
  -     operator=(const XalanDOMChar*   theRHS);
  +     operator=(const char*   theRHS)
  +     {
  +             return assign(theRHS);
  +     }
   
        XalanDOMString&
        operator=(XalanDOMChar  theRHS)
        {
  -             m_data.resize(2);
  -
  -             m_data[0] = theRHS;
  -             m_data[1] = XalanDOMChar(0);
  -
  -#if defined(XALAN_DOMSTRING_CACHE_SIZE)
  -             m_size = 1;
  -#endif
  -
  -             invariants();
  -
  -             return *this;
  +             return assign(1, theRHS);
        }
   
        iterator
  @@ -365,24 +356,18 @@
        XalanDOMString&
        operator+=(const XalanDOMString&        theSource)
        {
  -             invariants();
  -
                return append(theSource);
        }
   
        XalanDOMString&
        operator+=(const XalanDOMChar*  theString)
        {
  -             invariants();
  -
                return append(theString);
        }
   
        XalanDOMString&
        operator+=(XalanDOMChar theChar)
        {
  -             invariants();
  -
                append(1, theChar);
   
                return *this;
  @@ -415,18 +400,49 @@
        }
   
        XalanDOMString&
  +     assign(const char*      theSource)
  +     {
  +             invariants();
  +
  +             erase();
  +
  +             invariants();
  +
  +             return append(theSource);
  +     }
  +
  +     XalanDOMString&
        assign(
  +                     const char*             theSource,
  +                     size_type               theCount)
  +     {
  +             invariants();
  +
  +             erase();
  +
  +             invariants();
  +
  +             return append(theSource, theCount);
  +     }
  +
  +     XalanDOMString&
  +     assign(
                        const XalanDOMString&   theSource,
                        size_type                               thePosition,
                        size_type                               theCount)
        {
                invariants();
   
  -             erase();
  +             if (&theSource != this)
  +             {
  +                     erase();
   
  +                     append(theSource, thePosition, theCount);
  +             }
  +
                invariants();
   
  -             return append(theSource, thePosition, theCount);
  +             return *this;
        }
   
        XalanDOMString&
  @@ -434,7 +450,14 @@
        {
                invariants();
   
  -             m_data = theSource.m_data;
  +             if (&theSource != this)
  +             {
  +                     m_data = theSource.m_data;
  +
  +#if defined(XALAN_DOMSTRING_CACHE_SIZE)
  +                     m_size = theSource.m_size;
  +#endif
  +             }
   
                invariants();
   
  @@ -463,8 +486,6 @@
        XalanDOMString&
        append(const XalanDOMString&    theSource)
        {
  -             invariants();
  -
                return append(theSource.c_str(), theSource.length());
        }
   
  @@ -474,7 +495,8 @@
                        size_type                               thePosition,
                        size_type                               theCount)
        {
  -             invariants();
  +             assert(thePosition < theSource.length() &&
  +                        (theCount == size_type(npos) || thePosition + 
theCount <= theSource.length()));
   
                return append(theSource.c_str() + thePosition, theCount);
        }
  @@ -487,10 +509,17 @@
        XalanDOMString&
        append(const XalanDOMChar*      theString)
        {
  -             assert(theString != 0);
  +             return append(theString, length(theString));
  +     }
   
  -             invariants();
  +     XalanDOMString&
  +     append(
  +                     const char*             theString,
  +                     size_type               theCount);
   
  +     XalanDOMString&
  +     append(const char*      theString)
  +     {
                return append(theString, length(theString));
        }
   
  @@ -514,8 +543,6 @@
                        size_type                               thePosition,
                        const XalanDOMString&   theString)
        {
  -             invariants();
  -
                return insert(thePosition, theString.c_str(), 
theString.length());
        }
   
  @@ -526,8 +553,6 @@
                        size_type                               thePosition2,
                        size_type                               theCount)
        {
  -             invariants();
  -
                return insert(thePosition1, theString.c_str() + thePosition2, 
theCount);
        }
   
  @@ -542,8 +567,6 @@
                        size_type                               thePosition,
                        const XalanDOMChar*             theString)
        {
  -             invariants();
  -
                return insert(thePosition, theString, length(theString));
        }
   
  @@ -707,6 +730,31 @@
         */
        static size_type
        length(const XalanDOMChar*      theString);
  +
  +     /*
  +      * Helper function to determine the length of a null-
  +      * terminated string.
  +      *
  +      * @theString The string
  +      * @return the length
  +      */
  +     static size_type
  +     length(const char*      theString);
  +
  +     class TranscodingError : public XalanDOMException
  +     {
  +     public:
  +
  +             TranscodingError() :
  +                     XalanDOMException(ExceptionCode::TRANSCODING_ERR)
  +             {
  +             }
  +
  +             virtual
  +             ~TranscodingError()
  +             {
  +             }
  +     };
   
   protected:
   
  
  
  

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

Reply via email to