LCOV - code coverage report
Current view: top level - libreoffice/solver/unxlngi6.pro/inc/rtl - ustrbuf.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 147 172 85.5 %
Date: 2012-12-27 Functions: 78 120 65.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #ifndef _RTL_USTRBUF_HXX_
      21             : #define _RTL_USTRBUF_HXX_
      22             : 
      23             : #include "sal/config.h"
      24             : 
      25             : #include <cassert>
      26             : #include <string.h>
      27             : 
      28             : #include <osl/diagnose.h>
      29             : #include <rtl/ustrbuf.h>
      30             : #include <rtl/ustring.hxx>
      31             : #include <rtl/stringutils.hxx>
      32             : #include <sal/types.h>
      33             : 
      34             : #ifdef RTL_FAST_STRING
      35             : #include <rtl/stringconcat.hxx>
      36             : #endif
      37             : 
      38             : // The unittest uses slightly different code to help check that the proper
      39             : // calls are made. The class is put into a different namespace to make
      40             : // sure the compiler generates a different (if generating also non-inline)
      41             : // copy of the function and does not merge them together. The class
      42             : // is "brought" into the proper rtl namespace by a typedef below.
      43             : #ifdef RTL_STRING_UNITTEST
      44             : #define rtl rtlunittest
      45             : #endif
      46             : 
      47             : namespace rtl
      48             : {
      49             : 
      50             : #ifdef RTL_STRING_UNITTEST
      51             : #undef rtl
      52             : #endif
      53             : 
      54             : /** A string buffer implements a mutable sequence of characters.
      55             :     <p>
      56             :     String buffers are safe for use by multiple threads. The methods
      57             :     are synchronized where necessary so that all the operations on any
      58             :     particular instance behave as if they occur in some serial order.
      59             :     <p>
      60             :     String buffers are used by the compiler to implement the binary
      61             :     string concatenation operator <code>+</code>. For example, the code:
      62             :     <p><blockquote><pre>
      63             :         x = "a" + 4 + "c"
      64             :     </pre></blockquote><p>
      65             :     is compiled to the equivalent of:
      66             :     <p><blockquote><pre>
      67             :         x = new OUStringBuffer().append("a").append(4).append("c")
      68             :                               .makeStringAndClear()
      69             :     </pre></blockquote><p>
      70             :     The principal operations on a <code>OUStringBuffer</code> are the
      71             :     <code>append</code> and <code>insert</code> methods, which are
      72             :     overloaded so as to accept data of any type. Each effectively
      73             :     converts a given datum to a string and then appends or inserts the
      74             :     characters of that string to the string buffer. The
      75             :     <code>append</code> method always adds these characters at the end
      76             :     of the buffer; the <code>insert</code> method adds the characters at
      77             :     a specified point.
      78             :     <p>
      79             :     For example, if <code>z</code> refers to a string buffer object
      80             :     whose current contents are "<code>start</code>", then
      81             :     the method call <code>z.append("le")</code> would cause the string
      82             :     buffer to contain "<code>startle</code>", whereas
      83             :     <code>z.insert(4, "le")</code> would alter the string buffer to
      84             :     contain "<code>starlet</code>".
      85             :     <p>
      86             :     Every string buffer has a capacity. As long as the length of the
      87             :     character sequence contained in the string buffer does not exceed
      88             :     the capacity, it is not necessary to allocate a new internal
      89             :     buffer array. If the internal buffer overflows, it is
      90             :     automatically made larger.
      91             :  */
      92             : class SAL_WARN_UNUSED OUStringBuffer
      93             : {
      94             : public:
      95             :     /**
      96             :         Constructs a string buffer with no characters in it and an
      97             :         initial capacity of 16 characters.
      98             :      */
      99      352060 :     OUStringBuffer()
     100             :         : pData(NULL)
     101      352060 :         , nCapacity( 16 )
     102             :     {
     103      352060 :         rtl_uString_new_WithLength( &pData, nCapacity );
     104      352060 :     }
     105             : 
     106             :     /**
     107             :         Allocates a new string buffer that contains the same sequence of
     108             :         characters as the string buffer argument.
     109             : 
     110             :         @param   value   a <code>OUStringBuffer</code>.
     111             :      */
     112       14393 :     OUStringBuffer( const OUStringBuffer & value )
     113             :         : pData(NULL)
     114       14393 :         , nCapacity( value.nCapacity )
     115             :     {
     116       14393 :         rtl_uStringbuffer_newFromStringBuffer( &pData, value.nCapacity, value.pData );
     117       14393 :     }
     118             : 
     119             :     /**
     120             :         Constructs a string buffer with no characters in it and an
     121             :         initial capacity specified by the <code>length</code> argument.
     122             : 
     123             :         @param      length   the initial capacity.
     124             :      */
     125      193088 :     explicit OUStringBuffer(int length)
     126             :         : pData(NULL)
     127      193088 :         , nCapacity( length )
     128             :     {
     129      193088 :         rtl_uString_new_WithLength( &pData, length );
     130      193088 :     }
     131             : 
     132             :     /**
     133             :         Constructs a string buffer so that it represents the same
     134             :         sequence of characters as the string argument.
     135             : 
     136             :         The initial
     137             :         capacity of the string buffer is <code>16</code> plus the length
     138             :         of the string argument.
     139             : 
     140             :         @param   value   the initial contents of the buffer.
     141             :      */
     142      721907 :     OUStringBuffer(const OUString& value)
     143             :         : pData(NULL)
     144      721907 :         , nCapacity( value.getLength() + 16 )
     145             :     {
     146      721907 :         rtl_uStringbuffer_newFromStr_WithLength( &pData, value.getStr(), value.getLength() );
     147      721907 :     }
     148             : 
     149             : #ifdef HAVE_SFINAE_ANONYMOUS_BROKEN // see OUString ctors
     150             :     template< int N >
     151             :     OUStringBuffer( const char (&literal)[ N ] )
     152             :         : pData(NULL)
     153             :         , nCapacity( N - 1 + 16 )
     154             :     {
     155             :         assert( strlen( literal ) == N - 1 );
     156             :         rtl_uString_newFromLiteral( &pData, literal, N - 1, 16 );
     157             : #ifdef RTL_STRING_UNITTEST
     158             :         rtl_string_unittest_const_literal = true;
     159             : #endif
     160             :     }
     161             : 
     162             :     /**
     163             :      * It is an error to call this overload. Strings cannot directly use non-const char[].
     164             :      * @internal
     165             :      */
     166             :     template< int N >
     167             :     OUStringBuffer( char (&value)[ N ] )
     168             : #ifndef RTL_STRING_UNITTEST
     169             :         ; // intentionally not implemented
     170             : #else
     171             :     {
     172             :         (void) value; // unused
     173             :         pData = 0;
     174             :         nCapacity = 10;
     175             :         rtl_uString_newFromLiteral( &pData, "!!br0ken!!", 10, 0 ); // set to garbage
     176             :         rtl_string_unittest_invalid_conversion = true;
     177             :     }
     178             : #endif
     179             : #else // HAVE_SFINAE_ANONYMOUS_BROKEN
     180             :     template< typename T >
     181         230 :     OUStringBuffer( T& literal, typename internal::ConstCharArrayDetector< T, internal::Dummy >::Type = internal::Dummy() )
     182             :         : pData(NULL)
     183         230 :         , nCapacity( internal::ConstCharArrayDetector< T, void >::size - 1 + 16 )
     184             :     {
     185             :         assert( strlen( literal ) == internal::ConstCharArrayDetector< T >::size - 1 );
     186         230 :         rtl_uString_newFromLiteral( &pData, literal, internal::ConstCharArrayDetector< T, void >::size - 1, 16 );
     187             : #ifdef RTL_STRING_UNITTEST
     188           3 :         rtl_string_unittest_const_literal = true;
     189             : #endif
     190         230 :     }
     191             : #endif // HAVE_SFINAE_ANONYMOUS_BROKEN
     192             : 
     193             : #ifdef RTL_STRING_UNITTEST
     194             :     /**
     195             :      * Only used by unittests to detect incorrect conversions.
     196             :      * @internal
     197             :      */
     198             :     template< typename T >
     199           9 :     OUStringBuffer( T&, typename internal::ExceptConstCharArrayDetector< T >::Type = internal::Dummy() )
     200             :     {
     201           9 :         pData = 0;
     202           9 :         nCapacity = 10;
     203           9 :         rtl_uString_newFromLiteral( &pData, "!!br0ken!!", 10, 0 ); // set to garbage
     204           9 :         rtl_string_unittest_invalid_conversion = true;
     205           9 :     }
     206             :     /**
     207             :      * Only used by unittests to detect incorrect conversions.
     208             :      * @internal
     209             :      */
     210             :     template< typename T >
     211           1 :     OUStringBuffer( const T&, typename internal::ExceptCharArrayDetector< T >::Type = internal::Dummy() )
     212             :     {
     213           1 :         pData = 0;
     214           1 :         nCapacity = 10;
     215           1 :         rtl_uString_newFromLiteral( &pData, "!!br0ken!!", 10, 0 ); // set to garbage
     216           1 :         rtl_string_unittest_invalid_conversion = true;
     217           1 :     }
     218             : #endif
     219             : 
     220             : #ifdef RTL_FAST_STRING
     221             :     /**
     222             :      @overload
     223             :      @internal
     224             :     */
     225             :     template< typename T1, typename T2 >
     226           0 :     OUStringBuffer( const OUStringConcat< T1, T2 >& c )
     227             :     {
     228           0 :         const sal_Int32 l = c.length();
     229           0 :         nCapacity = l + 16;
     230           0 :         pData = rtl_uString_alloc( nCapacity );
     231           0 :         sal_Unicode* end = c.addData( pData->buffer );
     232           0 :         *end = '\0';
     233           0 :         pData->length = end - pData->buffer;
     234             :         // TODO realloc in case pData->>length is noticeably smaller than l ?
     235           0 :     }
     236             : #endif
     237             :     /** Assign to this a copy of value.
     238             :      */
     239      105089 :     OUStringBuffer& operator = ( const OUStringBuffer& value )
     240             :     {
     241      105089 :         if (this != &value)
     242             :         {
     243             :             rtl_uStringbuffer_newFromStringBuffer(&pData,
     244             :                                                   value.nCapacity,
     245      105089 :                                                   value.pData);
     246      105089 :             nCapacity = value.nCapacity;
     247             :         }
     248      105089 :         return *this;
     249             :     }
     250             : 
     251             :     /**
     252             :         Release the string data.
     253             :      */
     254     1281102 :     ~OUStringBuffer()
     255             :     {
     256     1281102 :         rtl_uString_release( pData );
     257     1281102 :     }
     258             : 
     259             :     /**
     260             :         Fill the string data in the new string and clear the buffer.
     261             : 
     262             :         This method is more efficient than the contructor of the string. It does
     263             :         not copy the buffer.
     264             : 
     265             :         @return the string previously contained in the buffer.
     266             :      */
     267     1147612 :     OUString makeStringAndClear()
     268             :     {
     269             :         return OUString(
     270             :                   rtl_uStringBuffer_makeStringAndClear( &pData, &nCapacity ),
     271     1147612 :                   SAL_NO_ACQUIRE );
     272             :     }
     273             : 
     274             :     /**
     275             :         Returns the length (character count) of this string buffer.
     276             : 
     277             :         @return  the number of characters in this string buffer.
     278             :      */
     279     6919793 :     sal_Int32 getLength() const
     280             :     {
     281     6919793 :         return pData->length;
     282             :     }
     283             : 
     284             :     /**
     285             :         Returns the current capacity of the String buffer.
     286             : 
     287             :         The capacity
     288             :         is the amount of storage available for newly inserted
     289             :         characters. The real buffer size is 2 bytes longer, because
     290             :         all strings are 0 terminated.
     291             : 
     292             :         @return  the current capacity of this string buffer.
     293             :      */
     294             :     sal_Int32 getCapacity() const
     295             :     {
     296             :         return nCapacity;
     297             :     }
     298             : 
     299             :     /**
     300             :         Ensures that the capacity of the buffer is at least equal to the
     301             :         specified minimum.
     302             : 
     303             :         The new capacity will be at least as large as the maximum of the current
     304             :         length (so that no contents of the buffer is destroyed) and the given
     305             :         minimumCapacity.  If the given minimumCapacity is negative, nothing is
     306             :         changed.
     307             : 
     308             :         @param   minimumCapacity   the minimum desired capacity.
     309             :      */
     310       33787 :     void ensureCapacity(sal_Int32 minimumCapacity)
     311             :     {
     312       33787 :         rtl_uStringbuffer_ensureCapacity( &pData, &nCapacity, minimumCapacity );
     313       33787 :     }
     314             : 
     315             :     /**
     316             :         Sets the length of this String buffer.
     317             : 
     318             :         If the <code>newLength</code> argument is less than the current
     319             :         length of the string buffer, the string buffer is truncated to
     320             :         contain exactly the number of characters given by the
     321             :         <code>newLength</code> argument.
     322             :         <p>
     323             :         If the <code>newLength</code> argument is greater than or equal
     324             :         to the current length, sufficient null characters
     325             :         (<code>'&#92;u0000'</code>) are appended to the string buffer so that
     326             :         length becomes the <code>newLength</code> argument.
     327             :         <p>
     328             :         The <code>newLength</code> argument must be greater than or equal
     329             :         to <code>0</code>.
     330             : 
     331             :         @param      newLength   the new length of the buffer.
     332             :      */
     333       55419 :     void setLength(sal_Int32 newLength)
     334             :     {
     335             :         assert(newLength >= 0);
     336             :         // Avoid modifications if pData points to const empty string:
     337       55419 :         if( newLength != pData->length )
     338             :         {
     339        2230 :             if( newLength > nCapacity )
     340          16 :                 rtl_uStringbuffer_ensureCapacity(&pData, &nCapacity, newLength);
     341             :             else
     342        2214 :                 pData->buffer[newLength] = 0;
     343        2230 :             pData->length = newLength;
     344             :         }
     345       55419 :     }
     346             : 
     347             :     /**
     348             :         Returns the character at a specific index in this string buffer.
     349             : 
     350             :         The first character of a string buffer is at index
     351             :         <code>0</code>, the next at index <code>1</code>, and so on, for
     352             :         array indexing.
     353             :         <p>
     354             :         The index argument must be greater than or equal to
     355             :         <code>0</code>, and less than the length of this string buffer.
     356             : 
     357             :         @param      index   the index of the desired character.
     358             :         @return     the character at the specified index of this string buffer.
     359             :      */
     360             :     SAL_DEPRECATED("use rtl::OUStringBuffer::operator [] instead")
     361             :     sal_Unicode charAt( sal_Int32 index ) const
     362             :     {
     363             :         assert(index >= 0 && index < pData->length);
     364             :         return pData->buffer[ index ];
     365             :     }
     366             : 
     367             :     /**
     368             :         The character at the specified index of this string buffer is set
     369             :         to <code>ch</code>.
     370             : 
     371             :         The index argument must be greater than or equal to
     372             :         <code>0</code>, and less than the length of this string buffer.
     373             : 
     374             :         @param      index   the index of the character to modify.
     375             :         @param      ch      the new character.
     376             :      */
     377             :     SAL_DEPRECATED("use rtl::OUStringBuffer::operator [] instead")
     378             :     OUStringBuffer & setCharAt(sal_Int32 index, sal_Unicode ch)
     379             :     {
     380             :         assert(index >= 0 && index < pData->length);
     381             :         pData->buffer[ index ] = ch;
     382             :         return *this;
     383             :     }
     384             : 
     385             :     /**
     386             :         Return a null terminated unicode character array.
     387             :      */
     388      183970 :     const sal_Unicode*  getStr() const { return pData->buffer; }
     389             : 
     390             :     /**
     391             :       Access to individual characters.
     392             : 
     393             :       @param index must be non-negative and less than length.
     394             : 
     395             :       @return a reference to the character at the given index.
     396             : 
     397             :       @since LibreOffice 3.5
     398             :     */
     399     1029822 :     sal_Unicode & operator [](sal_Int32 index) { return pData->buffer[index]; }
     400             : 
     401             :     /**
     402             :         Return a OUString instance reflecting the current content
     403             :         of this OUStringBuffer.
     404             :      */
     405       13056 :     const OUString toString() const
     406             :     {
     407       13056 :         return OUString(pData->buffer, pData->length);
     408             :     }
     409             : 
     410             :     /**
     411             :         Appends the string to this string buffer.
     412             : 
     413             :         The characters of the <code>OUString</code> argument are appended, in
     414             :         order, to the contents of this string buffer, increasing the
     415             :         length of this string buffer by the length of the argument.
     416             : 
     417             :         @param   str   a string.
     418             :         @return  this string buffer.
     419             :      */
     420      677289 :     OUStringBuffer & append(const OUString &str)
     421             :     {
     422      677289 :         return append( str.getStr(), str.getLength() );
     423             :     }
     424             : 
     425             :     /**
     426             :         Appends the content of a stringbuffer to this string buffer.
     427             : 
     428             :         The characters of the <code>OUStringBuffer</code> argument are appended, in
     429             :         order, to the contents of this string buffer, increasing the
     430             :         length of this string buffer by the length of the argument.
     431             : 
     432             :         @param   str   a string.
     433             :         @return  this string buffer.
     434             : 
     435             :         @since LibreOffice 4.0
     436             :      */
     437          27 :     OUStringBuffer & append(const OUStringBuffer &str)
     438             :     {
     439          27 :         if(str.getLength() > 0)
     440             :         {
     441          27 :             append( str.getStr(), str.getLength() );
     442             :         }
     443          27 :         return *this;
     444             :     }
     445             : 
     446             :     /**
     447             :         Appends the string representation of the <code>char</code> array
     448             :         argument to this string buffer.
     449             : 
     450             :         The characters of the array argument are appended, in order, to
     451             :         the contents of this string buffer. The length of this string
     452             :         buffer increases by the length of the argument.
     453             : 
     454             :         @param   str   the characters to be appended.
     455             :         @return  this string buffer.
     456             :      */
     457           5 :     OUStringBuffer & append( const sal_Unicode * str )
     458             :     {
     459           5 :         return append( str, rtl_ustr_getLength( str ) );
     460             :     }
     461             : 
     462             :     /**
     463             :         Appends the string representation of the <code>char</code> array
     464             :         argument to this string buffer.
     465             : 
     466             :         Characters of the character array <code>str</code> are appended,
     467             :         in order, to the contents of this string buffer. The length of this
     468             :         string buffer increases by the value of <code>len</code>.
     469             : 
     470             :         @param str the characters to be appended; must be non-null, and must
     471             :         point to at least len characters
     472             :         @param len the number of characters to append; must be non-negative
     473             :         @return  this string buffer.
     474             :      */
     475     4923175 :     OUStringBuffer & append( const sal_Unicode * str, sal_Int32 len)
     476             :     {
     477             :         // insert behind the last character
     478     4923175 :         rtl_uStringbuffer_insert( &pData, &nCapacity, getLength(), str, len );
     479     4923175 :         return *this;
     480             :     }
     481             : 
     482             :     /**
     483             :         @overload
     484             :         This function accepts an ASCII string literal as its argument.
     485             :         @since LibreOffice 3.6
     486             :      */
     487             :     template< typename T >
     488         348 :     typename internal::ConstCharArrayDetector< T, OUStringBuffer& >::Type append( T& literal )
     489             :     {
     490             :         assert( strlen( literal ) == internal::ConstCharArrayDetector< T >::size - 1 );
     491         348 :         rtl_uStringbuffer_insert_ascii( &pData, &nCapacity, getLength(), literal,
     492             :             internal::ConstCharArrayDetector< T, void >::size - 1 );
     493         348 :         return *this;
     494             :     }
     495             : 
     496             : #ifdef RTL_FAST_STRING
     497             :     /**
     498             :      @overload
     499             :      @internal
     500             :     */
     501             :     template< typename T1, typename T2 >
     502           1 :     OUStringBuffer& append( const OUStringConcat< T1, T2 >& c )
     503             :     {
     504           1 :         const int l = c.length();
     505           1 :         if( l == 0 )
     506           0 :             return *this;
     507           1 :         rtl_uStringbuffer_ensureCapacity( &pData, &nCapacity, pData->length + l );
     508           1 :         sal_Unicode* end = c.addData( pData->buffer + pData->length );
     509           1 :         *end = '\0';
     510           1 :         pData->length = end - pData->buffer;
     511           1 :         return *this;
     512             :     }
     513             : #endif
     514             : 
     515             :     /**
     516             :         Appends a 8-Bit ASCII character string to this string buffer.
     517             : 
     518             :        Since this method is optimized for performance. the ASCII
     519             :         character values are not converted in any way. The caller
     520             :         has to make sure that all ASCII characters are in the
     521             :         allowed range between 0 and 127. The ASCII string must be
     522             :         NULL-terminated.
     523             :         <p>
     524             :         The characters of the array argument are appended, in order, to
     525             :         the contents of this string buffer. The length of this string
     526             :         buffer increases by the length of the argument.
     527             : 
     528             :         @param   str   the 8-Bit ASCII characters to be appended.
     529             :         @return  this string buffer.
     530             :      */
     531      122395 :     OUStringBuffer & appendAscii( const sal_Char * str )
     532             :     {
     533      122395 :         return appendAscii( str, rtl_str_getLength( str ) );
     534             :     }
     535             : 
     536             :     /**
     537             :         Appends a 8-Bit ASCII character string to this string buffer.
     538             : 
     539             :         Since this method is optimized for performance. the ASCII
     540             :         character values are not converted in any way. The caller
     541             :         has to make sure that all ASCII characters are in the
     542             :         allowed range between 0 and 127. The ASCII string must be
     543             :         NULL-terminated.
     544             :         <p>
     545             :         Characters of the character array <code>str</code> are appended,
     546             :         in order, to the contents of this string buffer. The length of this
     547             :         string buffer increases by the value of <code>len</code>.
     548             : 
     549             :         @param str the 8-Bit ASCII characters to be appended; must be non-null,
     550             :         and must point to at least len characters
     551             :         @param len the number of characters to append; must be non-negative
     552             :         @return  this string buffer.
     553             :      */
     554      293819 :     OUStringBuffer & appendAscii( const sal_Char * str, sal_Int32 len)
     555             :     {
     556      293819 :         rtl_uStringbuffer_insert_ascii( &pData, &nCapacity, getLength(), str, len );
     557      293819 :         return *this;
     558             :     }
     559             : 
     560             :     /**
     561             :         Appends the string representation of the <code>bool</code>
     562             :         argument to the string buffer.
     563             : 
     564             :         The argument is converted to a string as if by the method
     565             :         <code>String.valueOf</code>, and the characters of that
     566             :         string are then appended to this string buffer.
     567             : 
     568             :         @param   b   a <code>bool</code>.
     569             :         @return  this string buffer.
     570             : 
     571             :         @since LibreOffice 4.1
     572             :      */
     573             :     OUStringBuffer & append(bool b)
     574             :     {
     575             :         sal_Unicode sz[RTL_USTR_MAX_VALUEOFBOOLEAN];
     576             :         return append( sz, rtl_ustr_valueOfBoolean( sz, b ) );
     577             :     }
     578             : #ifndef HAVE_SFINAE_ANONYMOUS_BROKEN
     579             :     // Pointer can be automatically converted to bool, which is unwanted here.
     580             :     // Explicitly delete all pointer append() overloads to prevent this
     581             :     // (except for char* and sal_Unicode* overloads, which are handled elsewhere).
     582             :     template< typename T >
     583             :     typename internal::Enable< void,
     584             :         !internal::CharPtrDetector< T* >::ok && !internal::SalUnicodePtrDetector< T* >::ok >::Type
     585             :         append( T* ) SAL_DELETED_FUNCTION;
     586             : #endif
     587             : 
     588             :     // This overload is needed because OUString has a ctor from rtl_uString*, but
     589             :     // the bool overload above would be prefered to the conversion.
     590             :     /**
     591             :      @internal
     592             :     */
     593       94215 :     OUStringBuffer & append(rtl_uString* str)
     594             :     {
     595       94215 :         return append( OUString( str ));
     596             :     }
     597             : 
     598             :     /**
     599             :         Appends the string representation of the <code>sal_Bool</code>
     600             :         argument to the string buffer.
     601             : 
     602             :         The argument is converted to a string as if by the method
     603             :         <code>String.valueOf</code>, and the characters of that
     604             :         string are then appended to this string buffer.
     605             : 
     606             :         @param   b   a <code>sal_Bool</code>.
     607             :         @return  this string buffer.
     608             :      */
     609           0 :     OUStringBuffer & append(sal_Bool b)
     610             :     {
     611             :         sal_Unicode sz[RTL_USTR_MAX_VALUEOFBOOLEAN];
     612           0 :         return append( sz, rtl_ustr_valueOfBoolean( sz, b ) );
     613             :     }
     614             : 
     615             :     /**
     616             :         Appends the string representation of the ASCII <code>char</code>
     617             :         argument to this string buffer.
     618             : 
     619             :         The argument is appended to the contents of this string buffer.
     620             :         The length of this string buffer increases by <code>1</code>.
     621             : 
     622             :         @param   c   an ASCII <code>char</code>.
     623             :         @return  this string buffer.
     624             : 
     625             :         @since LibreOffice 3.5
     626             :      */
     627       12503 :     OUStringBuffer & append(char c)
     628             :     {
     629             :         assert(static_cast< unsigned char >(c) <= 0x7F);
     630       12503 :         return append(sal_Unicode(c));
     631             :     }
     632             : 
     633             :     /**
     634             :         Appends the string representation of the <code>char</code>
     635             :         argument to this string buffer.
     636             : 
     637             :         The argument is appended to the contents of this string buffer.
     638             :         The length of this string buffer increases by <code>1</code>.
     639             : 
     640             :         @param   c   a <code>char</code>.
     641             :         @return  this string buffer.
     642             :      */
     643     3499293 :     OUStringBuffer & append(sal_Unicode c)
     644             :     {
     645     3499293 :         return append( &c, 1 );
     646             :     }
     647             : 
     648             :     /**
     649             :         Appends the string representation of the <code>sal_Int32</code>
     650             :         argument to this string buffer.
     651             : 
     652             :         The argument is converted to a string as if by the method
     653             :         <code>String.valueOf</code>, and the characters of that
     654             :         string are then appended to this string buffer.
     655             : 
     656             :         @param   i   an <code>sal_Int32</code>.
     657             :         @return  this string buffer.
     658             :      */
     659      221288 :     OUStringBuffer & append(sal_Int32 i, sal_Int16 radix = 10 )
     660             :     {
     661             :         sal_Unicode sz[RTL_USTR_MAX_VALUEOFINT32];
     662      221288 :         return append( sz, rtl_ustr_valueOfInt32( sz, i, radix ) );
     663             :     }
     664             : 
     665             :     /**
     666             :         Appends the string representation of the <code>long</code>
     667             :         argument to this string buffer.
     668             : 
     669             :         The argument is converted to a string as if by the method
     670             :         <code>String.valueOf</code>, and the characters of that
     671             :         string are then appended to this string buffer.
     672             : 
     673             :         @param   l   a <code>long</code>.
     674             :         @return  this string buffer.
     675             :      */
     676        7273 :     OUStringBuffer & append(sal_Int64 l, sal_Int16 radix = 10 )
     677             :     {
     678             :         sal_Unicode sz[RTL_USTR_MAX_VALUEOFINT64];
     679        7273 :         return append( sz, rtl_ustr_valueOfInt64( sz, l, radix ) );
     680             :     }
     681             : 
     682             :     /**
     683             :         Appends the string representation of the <code>float</code>
     684             :         argument to this string buffer.
     685             : 
     686             :         The argument is converted to a string as if by the method
     687             :         <code>String.valueOf</code>, and the characters of that
     688             :         string are then appended to this string buffer.
     689             : 
     690             :         @param   f   a <code>float</code>.
     691             :         @return  this string buffer.
     692             :      */
     693           0 :     OUStringBuffer & append(float f)
     694             :     {
     695             :         sal_Unicode sz[RTL_USTR_MAX_VALUEOFFLOAT];
     696           0 :         return append( sz, rtl_ustr_valueOfFloat( sz, f ) );
     697             :     }
     698             : 
     699             :     /**
     700             :         Appends the string representation of the <code>double</code>
     701             :         argument to this string buffer.
     702             : 
     703             :         The argument is converted to a string as if by the method
     704             :         <code>String.valueOf</code>, and the characters of that
     705             :         string are then appended to this string buffer.
     706             : 
     707             :         @param   d   a <code>double</code>.
     708             :         @return  this string buffer.
     709             :      */
     710        3047 :     OUStringBuffer & append(double d)
     711             :     {
     712             :         sal_Unicode sz[RTL_USTR_MAX_VALUEOFDOUBLE];
     713        3047 :         return append( sz, rtl_ustr_valueOfDouble( sz, d ) );
     714             :     }
     715             : 
     716             :     /**
     717             :        Appends a single UTF-32 character to this string buffer.
     718             : 
     719             :        <p>The single UTF-32 character will be represented within the string
     720             :        buffer as either one or two UTF-16 code units.</p>
     721             : 
     722             :        @param c a well-formed UTF-32 code unit (that is, a value in the range
     723             :        <code>0</code>&ndash;<code>0x10FFFF</code>, but excluding
     724             :        <code>0xD800</code>&ndash;<code>0xDFFF</code>)
     725             : 
     726             :        @return
     727             :        this string buffer
     728             :      */
     729      264368 :     OUStringBuffer & appendUtf32(sal_uInt32 c) {
     730      264368 :         return insertUtf32(getLength(), c);
     731             :     }
     732             : 
     733             :     /**
     734             :         Inserts the string into this string buffer.
     735             : 
     736             :         The characters of the <code>String</code> argument are inserted, in
     737             :         order, into this string buffer at the indicated offset. The length
     738             :         of this string buffer is increased by the length of the argument.
     739             :         <p>
     740             :         The offset argument must be greater than or equal to
     741             :         <code>0</code>, and less than or equal to the length of this
     742             :         string buffer.
     743             : 
     744             :         @param      offset   the offset.
     745             :         @param      str      a string.
     746             :         @return     this string buffer.
     747             :      */
     748       42684 :     OUStringBuffer & insert(sal_Int32 offset, const OUString & str)
     749             :     {
     750       42684 :         return insert( offset, str.getStr(), str.getLength() );
     751             :     }
     752             : 
     753             :     /**
     754             :         Inserts the string representation of the <code>char</code> array
     755             :         argument into this string buffer.
     756             : 
     757             :         The characters of the array argument are inserted into the
     758             :         contents of this string buffer at the position indicated by
     759             :         <code>offset</code>. The length of this string buffer increases by
     760             :         the length of the argument.
     761             :         <p>
     762             :         The offset argument must be greater than or equal to
     763             :         <code>0</code>, and less than or equal to the length of this
     764             :         string buffer.
     765             : 
     766             :         @param      offset   the offset.
     767             :         @param      str      a character array.
     768             :         @return     this string buffer.
     769             :      */
     770           0 :     OUStringBuffer & insert( sal_Int32 offset, const sal_Unicode * str )
     771             :     {
     772           0 :         return insert( offset, str, rtl_ustr_getLength( str ) );
     773             :     }
     774             : 
     775             :     /**
     776             :         Inserts the string representation of the <code>char</code> array
     777             :         argument into this string buffer.
     778             : 
     779             :         The characters of the array argument are inserted into the
     780             :         contents of this string buffer at the position indicated by
     781             :         <code>offset</code>. The length of this string buffer increases by
     782             :         the length of the argument.
     783             :         <p>
     784             :         The offset argument must be greater than or equal to
     785             :         <code>0</code>, and less than or equal to the length of this
     786             :         string buffer.
     787             : 
     788             :         @param      offset   the offset.
     789             :         @param      str      a character array.
     790             :         @param      len     the number of characters to append.
     791             :         @return     this string buffer.
     792             :      */
     793       43430 :     OUStringBuffer & insert( sal_Int32 offset, const sal_Unicode * str, sal_Int32 len)
     794             :     {
     795             :         // insert behind the last character
     796       43430 :         rtl_uStringbuffer_insert( &pData, &nCapacity, offset, str, len );
     797       43430 :         return *this;
     798             :     }
     799             : 
     800             :     /**
     801             :         @overload
     802             :         This function accepts an ASCII string literal as its argument.
     803             :         @since LibreOffice 3.6
     804             :      */
     805             :     template< typename T >
     806        7345 :     typename internal::ConstCharArrayDetector< T, OUStringBuffer& >::Type insert( sal_Int32 offset, T& literal )
     807             :     {
     808             :         assert( strlen( literal ) == internal::ConstCharArrayDetector< T >::size - 1 );
     809        7345 :         rtl_uStringbuffer_insert_ascii( &pData, &nCapacity, offset, literal,
     810             :             internal::ConstCharArrayDetector< T, void >::size - 1 );
     811        7345 :         return *this;
     812             :     }
     813             : 
     814             :     /**
     815             :         Inserts the string representation of the <code>sal_Bool</code>
     816             :         argument into this string buffer.
     817             : 
     818             :         The second argument is converted to a string as if by the method
     819             :         <code>String.valueOf</code>, and the characters of that
     820             :         string are then inserted into this string buffer at the indicated
     821             :         offset.
     822             :         <p>
     823             :         The offset argument must be greater than or equal to
     824             :         <code>0</code>, and less than or equal to the length of this
     825             :         string buffer.
     826             : 
     827             :         @param      offset   the offset.
     828             :         @param      b        a <code>sal_Bool</code>.
     829             :         @return     this string buffer.
     830             :      */
     831             :     OUStringBuffer & insert(sal_Int32 offset, sal_Bool b)
     832             :     {
     833             :         sal_Unicode sz[RTL_USTR_MAX_VALUEOFBOOLEAN];
     834             :         return insert( offset, sz, rtl_ustr_valueOfBoolean( sz, b ) );
     835             :     }
     836             : 
     837             :     /**
     838             :         Inserts the string representation of the <code>char</code>
     839             :         argument into this string buffer.
     840             : 
     841             :         The second argument is inserted into the contents of this string
     842             :         buffer at the position indicated by <code>offset</code>. The length
     843             :         of this string buffer increases by one.
     844             :         <p>
     845             :         The offset argument must be greater than or equal to
     846             :         <code>0</code>, and less than or equal to the length of this
     847             :         string buffer.
     848             : 
     849             :         @param      offset   the offset.
     850             :         @param      c        a <code>char</code>.
     851             :         @return     this string buffer.
     852             : 
     853             :         @since LibreOffice 3.6
     854             :      */
     855         529 :     OUStringBuffer & insert(sal_Int32 offset, char c)
     856             :     {
     857         529 :         sal_Unicode u = c;
     858         529 :         return insert( offset, &u, 1 );
     859             :     }
     860             : 
     861             :     /**
     862             :         Inserts the string representation of the <code>char</code>
     863             :         argument into this string buffer.
     864             : 
     865             :         The second argument is inserted into the contents of this string
     866             :         buffer at the position indicated by <code>offset</code>. The length
     867             :         of this string buffer increases by one.
     868             :         <p>
     869             :         The offset argument must be greater than or equal to
     870             :         <code>0</code>, and less than or equal to the length of this
     871             :         string buffer.
     872             : 
     873             :         @param      offset   the offset.
     874             :         @param      c        a <code>char</code>.
     875             :         @return     this string buffer.
     876             :      */
     877         197 :     OUStringBuffer & insert(sal_Int32 offset, sal_Unicode c)
     878             :     {
     879         197 :         return insert( offset, &c, 1 );
     880             :     }
     881             : 
     882             :     /**
     883             :         Inserts the string representation of the second <code>sal_Int32</code>
     884             :         argument into this string buffer.
     885             : 
     886             :         The second argument is converted to a string as if by the method
     887             :         <code>String.valueOf</code>, and the characters of that
     888             :         string are then inserted into this string buffer at the indicated
     889             :         offset.
     890             :         <p>
     891             :         The offset argument must be greater than or equal to
     892             :         <code>0</code>, and less than or equal to the length of this
     893             :         string buffer.
     894             : 
     895             :         @param      offset   the offset.
     896             :         @param      i        an <code>sal_Int32</code>.
     897             :         @param      radix    the radix.
     898             :         @return     this string buffer.
     899             :         @exception  StringIndexOutOfBoundsException  if the offset is invalid.
     900             :      */
     901           0 :     OUStringBuffer & insert(sal_Int32 offset, sal_Int32 i, sal_Int16 radix = 10 )
     902             :     {
     903             :         sal_Unicode sz[RTL_USTR_MAX_VALUEOFINT32];
     904           0 :         return insert( offset, sz, rtl_ustr_valueOfInt32( sz, i, radix ) );
     905             :     }
     906             : 
     907             :     /**
     908             :         Inserts the string representation of the <code>long</code>
     909             :         argument into this string buffer.
     910             : 
     911             :         The second argument is converted to a string as if by the method
     912             :         <code>String.valueOf</code>, and the characters of that
     913             :         string are then inserted into this string buffer at the indicated
     914             :         offset.
     915             :         <p>
     916             :         The offset argument must be greater than or equal to
     917             :         <code>0</code>, and less than or equal to the length of this
     918             :         string buffer.
     919             : 
     920             :         @param      offset   the offset.
     921             :         @param      l        a <code>long</code>.
     922             :         @param      radix    the radix.
     923             :         @return     this string buffer.
     924             :         @exception  StringIndexOutOfBoundsException  if the offset is invalid.
     925             :      */
     926             :     OUStringBuffer & insert(sal_Int32 offset, sal_Int64 l, sal_Int16 radix = 10 )
     927             :     {
     928             :         sal_Unicode sz[RTL_USTR_MAX_VALUEOFINT64];
     929             :         return insert( offset, sz, rtl_ustr_valueOfInt64( sz, l, radix ) );
     930             :     }
     931             : 
     932             :     /**
     933             :         Inserts the string representation of the <code>float</code>
     934             :         argument into this string buffer.
     935             : 
     936             :         The second argument is converted to a string as if by the method
     937             :         <code>String.valueOf</code>, and the characters of that
     938             :         string are then inserted into this string buffer at the indicated
     939             :         offset.
     940             :         <p>
     941             :         The offset argument must be greater than or equal to
     942             :         <code>0</code>, and less than or equal to the length of this
     943             :         string buffer.
     944             : 
     945             :         @param      offset   the offset.
     946             :         @param      f        a <code>float</code>.
     947             :         @return     this string buffer.
     948             :         @exception  StringIndexOutOfBoundsException  if the offset is invalid.
     949             :      */
     950             :     OUStringBuffer insert(sal_Int32 offset, float f)
     951             :     {
     952             :         sal_Unicode sz[RTL_USTR_MAX_VALUEOFFLOAT];
     953             :         return insert( offset, sz, rtl_ustr_valueOfFloat( sz, f ) );
     954             :     }
     955             : 
     956             :     /**
     957             :         Inserts the string representation of the <code>double</code>
     958             :         argument into this string buffer.
     959             : 
     960             :         The second argument is converted to a string as if by the method
     961             :         <code>String.valueOf</code>, and the characters of that
     962             :         string are then inserted into this string buffer at the indicated
     963             :         offset.
     964             :         <p>
     965             :         The offset argument must be greater than or equal to
     966             :         <code>0</code>, and less than or equal to the length of this
     967             :         string buffer.
     968             : 
     969             :         @param      offset   the offset.
     970             :         @param      d        a <code>double</code>.
     971             :         @return     this string buffer.
     972             :         @exception  StringIndexOutOfBoundsException  if the offset is invalid.
     973             :      */
     974             :     OUStringBuffer & insert(sal_Int32 offset, double d)
     975             :     {
     976             :         sal_Unicode sz[RTL_USTR_MAX_VALUEOFDOUBLE];
     977             :         return insert( offset, sz, rtl_ustr_valueOfDouble( sz, d ) );
     978             :     }
     979             : 
     980             :     /**
     981             :        Inserts a single UTF-32 character into this string buffer.
     982             : 
     983             :        <p>The single UTF-32 character will be represented within the string
     984             :        buffer as either one or two UTF-16 code units.</p>
     985             : 
     986             :        @param offset the offset into this string buffer (from zero to the length
     987             :        of this string buffer, inclusive)
     988             : 
     989             :        @param c a well-formed UTF-32 code unit (that is, a value in the range
     990             :        <code>0</code>&ndash;<code>0x10FFFF</code>, but excluding
     991             :        <code>0xD800</code>&ndash;<code>0xDFFF</code>)
     992             : 
     993             :        @return this string buffer
     994             :      */
     995      264370 :     OUStringBuffer & insertUtf32(sal_Int32 offset, sal_uInt32 c) {
     996      264370 :         rtl_uStringbuffer_insertUtf32(&pData, &nCapacity, offset, c);
     997      264370 :         return *this;
     998             :     }
     999             : 
    1000             :     /**
    1001             :         Removes the characters in a substring of this sequence.
    1002             : 
    1003             :         The substring begins at the specified <code>start</code> and
    1004             :         is <code>len</code> characters long.
    1005             : 
    1006             :         start must be >= 0 && <= This->length
    1007             : 
    1008             :         @param  start       The beginning index, inclusive
    1009             :         @param  len         The substring length
    1010             :         @return this string buffer.
    1011             :      */
    1012       45359 :     OUStringBuffer & remove( sal_Int32 start, sal_Int32 len )
    1013             :     {
    1014       45359 :         rtl_uStringbuffer_remove( &pData, start, len );
    1015       45359 :         return *this;
    1016             :     }
    1017             : 
    1018             :     /**
    1019             :         Removes the tail of a string buffer start at the indicate position
    1020             : 
    1021             :         start must be >= 0 && <= This->length
    1022             : 
    1023             :         @param  start       The beginning index, inclusive. default to 0
    1024             :         @return this string buffer.
    1025             : 
    1026             :         @since LibreOffice 4.0
    1027             :      */
    1028          10 :     OUStringBuffer & truncate( sal_Int32 start = 0 )
    1029             :     {
    1030          10 :         rtl_uStringbuffer_remove( &pData, start, getLength() - start );
    1031          10 :         return *this;
    1032             :     }
    1033             : 
    1034             :     /**
    1035             :        Replace all occurrences of
    1036             :        oldChar in this string buffer with newChar.
    1037             : 
    1038             :        @since LibreOffice 4.0
    1039             : 
    1040             :        @param    oldChar     the old character.
    1041             :        @param    newChar     the new character.
    1042             :        @return   this string buffer
    1043             :     */
    1044          57 :     OUStringBuffer& replace( sal_Unicode oldChar, sal_Unicode newChar )
    1045             :     {
    1046          57 :         sal_Int32 index = 0;
    1047         138 :         while((index = indexOf(oldChar, index)) >= 0)
    1048             :         {
    1049          24 :             pData->buffer[ index ] = newChar;
    1050             :         }
    1051          57 :         return *this;
    1052             :     }
    1053             : 
    1054             :     /** Allows access to the internal data of this OUStringBuffer, for effective
    1055             :         manipulation.
    1056             : 
    1057             :         This method should be used with care.  After you have called this
    1058             :         method, you may use the returned pInternalData or pInternalCapacity only
    1059             :         as long as you make no other method call on this OUStringBuffer.
    1060             : 
    1061             :         @param pInternalData
    1062             :         This output parameter receives a pointer to the internal data
    1063             :         (rtl_uString pointer).  pInternalData itself must not be null.
    1064             : 
    1065             :         @param pInternalCapacity
    1066             :         This output parameter receives a pointer to the internal capacity.
    1067             :         pInternalCapacity itself must not be null.
    1068             :      */
    1069         121 :     inline void accessInternals(rtl_uString *** pInternalData,
    1070             :                                 sal_Int32 ** pInternalCapacity)
    1071             :     {
    1072         121 :         *pInternalData = &pData;
    1073         121 :         *pInternalCapacity = &nCapacity;
    1074         121 :     }
    1075             : 
    1076             : 
    1077             :     /**
    1078             :        Returns the index within this string of the first occurrence of the
    1079             :        specified character, starting the search at the specified index.
    1080             : 
    1081             :        @since LibreOffice 4.0
    1082             : 
    1083             :        @param    ch          character to be located.
    1084             :        @param    fromIndex   the index to start the search from.
    1085             :                              The index must be greater or equal than 0
    1086             :                              and less or equal as the string length.
    1087             :        @return   the index of the first occurrence of the character in the
    1088             :                  character sequence represented by this string that is
    1089             :                  greater than or equal to fromIndex, or
    1090             :                  -1 if the character does not occur.
    1091             :     */
    1092         374 :     sal_Int32 indexOf( sal_Unicode ch, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
    1093             :     {
    1094         374 :         sal_Int32 ret = rtl_ustr_indexOfChar_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, ch );
    1095         374 :         return (ret < 0 ? ret : ret+fromIndex);
    1096             :     }
    1097             : 
    1098             :     /**
    1099             :        Returns the index within this string of the last occurrence of the
    1100             :        specified character, searching backward starting at the end.
    1101             : 
    1102             :        @since LibreOffice 4.0
    1103             : 
    1104             :        @param    ch          character to be located.
    1105             :        @return   the index of the last occurrence of the character in the
    1106             :                  character sequence represented by this string, or
    1107             :                  -1 if the character does not occur.
    1108             :     */
    1109             :     sal_Int32 lastIndexOf( sal_Unicode ch ) const SAL_THROW(())
    1110             :     {
    1111             :         return rtl_ustr_lastIndexOfChar_WithLength( pData->buffer, pData->length, ch );
    1112             :     }
    1113             : 
    1114             :     /**
    1115             :        Returns the index within this string of the last occurrence of the
    1116             :        specified character, searching backward starting before the specified
    1117             :        index.
    1118             : 
    1119             :        @since LibreOffice 4.0
    1120             : 
    1121             :        @param    ch          character to be located.
    1122             :        @param    fromIndex   the index before which to start the search.
    1123             :        @return   the index of the last occurrence of the character in the
    1124             :                  character sequence represented by this string that
    1125             :                  is less than fromIndex, or -1
    1126             :                  if the character does not occur before that point.
    1127             :     */
    1128             :     sal_Int32 lastIndexOf( sal_Unicode ch, sal_Int32 fromIndex ) const SAL_THROW(())
    1129             :     {
    1130             :         return rtl_ustr_lastIndexOfChar_WithLength( pData->buffer, fromIndex, ch );
    1131             :     }
    1132             : 
    1133             :     /**
    1134             :        Returns the index within this string of the first occurrence of the
    1135             :        specified substring, starting at the specified index.
    1136             : 
    1137             :        If str doesn't include any character, always -1 is
    1138             :        returned. This is also the case, if both strings are empty.
    1139             : 
    1140             :        @since LibreOffice 4.0
    1141             : 
    1142             :        @param    str         the substring to search for.
    1143             :        @param    fromIndex   the index to start the search from.
    1144             :        @return   If the string argument occurs one or more times as a substring
    1145             :                  within this string at the starting index, then the index
    1146             :                  of the first character of the first such substring is
    1147             :                  returned. If it does not occur as a substring starting
    1148             :                  at fromIndex or beyond, -1 is returned.
    1149             :     */
    1150         185 :     sal_Int32 indexOf( const OUString & str, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
    1151             :     {
    1152         185 :         sal_Int32 ret = rtl_ustr_indexOfStr_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
    1153         370 :                                                         str.pData->buffer, str.pData->length );
    1154         185 :         return (ret < 0 ? ret : ret+fromIndex);
    1155             :     }
    1156             : 
    1157             :     /**
    1158             :        @overload
    1159             :        This function accepts an ASCII string literal as its argument.
    1160             : 
    1161             :        @since LibreOffice 4.0
    1162             :     */
    1163             :     template< typename T >
    1164             :     typename internal::ConstCharArrayDetector< T, sal_Int32 >::Type indexOf( T& literal, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
    1165             :     {
    1166             :         assert( strlen( literal ) == internal::ConstCharArrayDetector< T >::size - 1 );
    1167             :         sal_Int32 ret = rtl_ustr_indexOfAscii_WithLength(
    1168             :             pData->buffer + fromIndex, pData->length - fromIndex, literal,
    1169             :             internal::ConstCharArrayDetector< T, void >::size - 1);
    1170             :         return ret < 0 ? ret : ret + fromIndex;
    1171             :     }
    1172             : 
    1173             :     /**
    1174             :        Returns the index within this string of the last occurrence of
    1175             :        the specified substring, searching backward starting at the end.
    1176             : 
    1177             :        The returned index indicates the starting index of the substring
    1178             :        in this string.
    1179             :        If str doesn't include any character, always -1 is
    1180             :        returned. This is also the case, if both strings are empty.
    1181             : 
    1182             :        @since LibreOffice 4.0
    1183             : 
    1184             :        @param    str         the substring to search for.
    1185             :        @return   If the string argument occurs one or more times as a substring
    1186             :                  within this string, then the index of the first character of
    1187             :                  the last such substring is returned. If it does not occur as
    1188             :                  a substring, -1 is returned.
    1189             :     */
    1190             :     sal_Int32 lastIndexOf( const OUString & str ) const SAL_THROW(())
    1191             :     {
    1192             :         return rtl_ustr_lastIndexOfStr_WithLength( pData->buffer, pData->length,
    1193             :                                                    str.pData->buffer, str.pData->length );
    1194             :     }
    1195             : 
    1196             :     /**
    1197             :        Returns the index within this string of the last occurrence of
    1198             :        the specified substring, searching backward starting before the specified
    1199             :        index.
    1200             : 
    1201             :        The returned index indicates the starting index of the substring
    1202             :        in this string.
    1203             :        If str doesn't include any character, always -1 is
    1204             :        returned. This is also the case, if both strings are empty.
    1205             : 
    1206             :        @since LibreOffice 4.0
    1207             : 
    1208             :        @param    str         the substring to search for.
    1209             :        @param    fromIndex   the index before which to start the search.
    1210             :        @return   If the string argument occurs one or more times as a substring
    1211             :                  within this string before the starting index, then the index
    1212             :                  of the first character of the last such substring is
    1213             :                  returned. Otherwise, -1 is returned.
    1214             :     */
    1215             :     sal_Int32 lastIndexOf( const OUString & str, sal_Int32 fromIndex ) const SAL_THROW(())
    1216             :     {
    1217             :         return rtl_ustr_lastIndexOfStr_WithLength( pData->buffer, fromIndex,
    1218             :                                                    str.pData->buffer, str.pData->length );
    1219             :     }
    1220             : 
    1221             :     /**
    1222             :        @overload
    1223             :        This function accepts an ASCII string literal as its argument.
    1224             :        @since LibreOffice 4.0
    1225             :     */
    1226             :     template< typename T >
    1227             :     typename internal::ConstCharArrayDetector< T, sal_Int32 >::Type lastIndexOf( T& literal ) const SAL_THROW(())
    1228             :     {
    1229             :         assert( strlen( literal ) == internal::ConstCharArrayDetector< T >::size - 1 );
    1230             :         return rtl_ustr_lastIndexOfAscii_WithLength(
    1231             :             pData->buffer, pData->length, literal, internal::ConstCharArrayDetector< T, void >::size - 1);
    1232             :     }
    1233             : 
    1234             :     /**
    1235             :        Strip the given character from the start of the buffer.
    1236             : 
    1237             :        @since LibreOffice 4.0
    1238             : 
    1239             :        @param    c         the character to strip
    1240             :        @return   The number of characters stripped
    1241             : 
    1242             :     */
    1243        3543 :     sal_Int32 stripStart(sal_Unicode c = (sal_Unicode)' ')
    1244             :     {
    1245             :         sal_Int32 index;
    1246        6736 :         for(index = 0; index < getLength() ; index++)
    1247             :         {
    1248        3409 :             if(pData->buffer[ index ] != c)
    1249             :             {
    1250         216 :                 break;
    1251             :             }
    1252             :         }
    1253        3543 :         if(index)
    1254             :         {
    1255        3193 :             remove(0, index);
    1256             :         }
    1257        3543 :         return index;
    1258             :     }
    1259             : 
    1260             :     /**
    1261             :        Strip the given character from the end of the buffer.
    1262             : 
    1263             :        @since LibreOffice 4.0
    1264             : 
    1265             :        @param    c         the character to strip
    1266             :        @return   The number of characters stripped
    1267             : 
    1268             :     */
    1269           0 :     sal_Int32 stripEnd(sal_Unicode c = (sal_Unicode)' ')
    1270             :     {
    1271           0 :         sal_Int32 result = getLength();
    1272             :         sal_Int32 index;
    1273           0 :         for(index = getLength(); index > 0 ; index--)
    1274             :         {
    1275           0 :             if(pData->buffer[ index - 1 ] != c)
    1276             :             {
    1277           0 :                 break;
    1278             :             }
    1279             :         }
    1280           0 :         if(index < getLength())
    1281             :         {
    1282           0 :             truncate(index);
    1283             :         }
    1284           0 :         return result - getLength();
    1285             :     }
    1286             :     /**
    1287             :        Strip the given character from the both end of the buffer.
    1288             : 
    1289             :        @since LibreOffice 4.0
    1290             : 
    1291             :        @param    c         the character to strip
    1292             :        @return   The number of characters stripped
    1293             : 
    1294             :     */
    1295             :     sal_Int32 strip(sal_Unicode c = (sal_Unicode)' ')
    1296             :     {
    1297             :         return stripStart(c) + stripEnd(c);
    1298             :     }
    1299             : 
    1300             : #ifdef LIBO_INTERNAL_ONLY
    1301             :     // This is to complement the RTL_FAST_STRING operator+, which allows any combination of valid operands,
    1302             :     // even two buffers. It's intentional it returns OUString, just like the operator+ would in the fast variant.
    1303             : #ifndef RTL_FAST_STRING
    1304             :     /**
    1305             :      @internal
    1306             :      @since LibreOffice 4.1
    1307             :     */
    1308             :     friend OUString operator+( const OUStringBuffer& str1, const OUStringBuffer& str2  ) SAL_THROW(())
    1309             :     {
    1310             :         return OUString( str1.pData ).concat( str2.pData );
    1311             :     }
    1312             : #endif
    1313             : #endif
    1314             : 
    1315             : private:
    1316             :     /**
    1317             :         A pointer to the data structur which contains the data.
    1318             :      */
    1319             :     rtl_uString * pData;
    1320             : 
    1321             :     /**
    1322             :         The len of the pData->buffer.
    1323             :      */
    1324             :     sal_Int32       nCapacity;
    1325             : };
    1326             : 
    1327             : #ifdef RTL_FAST_STRING
    1328             : /**
    1329             :  @internal
    1330             : */
    1331             : template<>
    1332             : struct ToStringHelper< OUStringBuffer >
    1333             :     {
    1334           1 :     static int length( const OUStringBuffer& s ) { return s.getLength(); }
    1335           1 :     static sal_Unicode* addData( sal_Unicode* buffer, const OUStringBuffer& s ) { return addDataHelper( buffer, s.getStr(), s.getLength()); }
    1336             :     static const bool allowOStringConcat = false;
    1337             :     static const bool allowOUStringConcat = true;
    1338             :     };
    1339             : #endif
    1340             : 
    1341             : }
    1342             : 
    1343             : #ifdef RTL_STRING_UNITTEST
    1344             : namespace rtl
    1345             : {
    1346             : typedef rtlunittest::OUStringBuffer OUStringBuffer;
    1347             : }
    1348             : #endif
    1349             : 
    1350             : #ifdef RTL_USING
    1351             : using ::rtl::OUStringBuffer;
    1352             : #endif
    1353             : 
    1354             : #endif  /* _RTL_USTRBUF_HXX_ */
    1355             : 
    1356             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10