LCOV - code coverage report
Current view: top level - include/rtl - ustrbuf.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 180 187 96.3 %
Date: 2014-11-03 Functions: 129 235 54.9 %
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 INCLUDED_RTL_USTRBUF_HXX
      21             : #define INCLUDED_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    13062370 :     OUStringBuffer()
     100             :         : pData(NULL)
     101    13062370 :         , nCapacity( 16 )
     102             :     {
     103    13062370 :         rtl_uString_new_WithLength( &pData, nCapacity );
     104    13062370 :     }
     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      200174 :     OUStringBuffer( const OUStringBuffer & value )
     113             :         : pData(NULL)
     114      200174 :         , nCapacity( value.nCapacity )
     115             :     {
     116      200174 :         rtl_uStringbuffer_newFromStringBuffer( &pData, value.nCapacity, value.pData );
     117      200174 :     }
     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     3231151 :     explicit OUStringBuffer(int length)
     126             :         : pData(NULL)
     127     3231151 :         , nCapacity( length )
     128             :     {
     129     3231151 :         rtl_uString_new_WithLength( &pData, length );
     130     3231151 :     }
     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    10024864 :     OUStringBuffer(const OUString& value)
     143             :         : pData(NULL)
     144    10024864 :         , nCapacity( value.getLength() + 16 )
     145             :     {
     146    10024864 :         rtl_uStringbuffer_newFromStr_WithLength( &pData, value.getStr(), value.getLength() );
     147    10024864 :     }
     148             : 
     149             :     template< typename T >
     150       23017 :     OUStringBuffer( T& literal, typename libreoffice_internal::ConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type = libreoffice_internal::Dummy() )
     151             :         : pData(NULL)
     152       23017 :         , nCapacity( libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 + 16 )
     153             :     {
     154             :         assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
     155       23017 :         rtl_uString_newFromLiteral( &pData, literal, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1, 16 );
     156             : #ifdef RTL_STRING_UNITTEST
     157           6 :         rtl_string_unittest_const_literal = true;
     158             : #endif
     159       23017 :     }
     160             : 
     161             : #ifdef RTL_STRING_UNITTEST
     162             :     /**
     163             :      * Only used by unittests to detect incorrect conversions.
     164             :      * @internal
     165             :      */
     166             :     template< typename T >
     167          16 :     OUStringBuffer( T&, typename libreoffice_internal::ExceptConstCharArrayDetector< T >::Type = libreoffice_internal::Dummy() )
     168             :     {
     169          16 :         pData = 0;
     170          16 :         nCapacity = 10;
     171          16 :         rtl_uString_newFromLiteral( &pData, "!!br0ken!!", 10, 0 ); // set to garbage
     172          16 :         rtl_string_unittest_invalid_conversion = true;
     173          16 :     }
     174             :     /**
     175             :      * Only used by unittests to detect incorrect conversions.
     176             :      * @internal
     177             :      */
     178             :     template< typename T >
     179           2 :     OUStringBuffer( const T&, typename libreoffice_internal::ExceptCharArrayDetector< T >::Type = libreoffice_internal::Dummy() )
     180             :     {
     181           2 :         pData = 0;
     182           2 :         nCapacity = 10;
     183           2 :         rtl_uString_newFromLiteral( &pData, "!!br0ken!!", 10, 0 ); // set to garbage
     184           2 :         rtl_string_unittest_invalid_conversion = true;
     185           2 :     }
     186             : #endif
     187             : 
     188             : #ifdef RTL_FAST_STRING
     189             :     /**
     190             :      @overload
     191             :      @internal
     192             :     */
     193             :     template< typename T1, typename T2 >
     194          80 :     OUStringBuffer( const OUStringConcat< T1, T2 >& c )
     195             :     {
     196          80 :         const sal_Int32 l = c.length();
     197          80 :         nCapacity = l + 16;
     198          80 :         pData = rtl_uString_alloc( nCapacity );
     199          80 :         sal_Unicode* end = c.addData( pData->buffer );
     200          80 :         *end = '\0';
     201          80 :         pData->length = end - pData->buffer;
     202             :         // TODO realloc in case pData->>length is noticeably smaller than l ?
     203          80 :     }
     204             : #endif
     205             :     /** Assign to this a copy of value.
     206             :      */
     207     7198185 :     OUStringBuffer& operator = ( const OUStringBuffer& value )
     208             :     {
     209     7198185 :         if (this != &value)
     210             :         {
     211             :             rtl_uStringbuffer_newFromStringBuffer(&pData,
     212             :                                                   value.nCapacity,
     213     7198093 :                                                   value.pData);
     214     7198093 :             nCapacity = value.nCapacity;
     215             :         }
     216     7198185 :         return *this;
     217             :     }
     218             : 
     219             :     /**
     220             :         Release the string data.
     221             :      */
     222    26542486 :     ~OUStringBuffer()
     223             :     {
     224    26542486 :         rtl_uString_release( pData );
     225    26542486 :     }
     226             : 
     227             :     /**
     228             :         Fill the string data in the new string and clear the buffer.
     229             : 
     230             :         This method is more efficient than the contructor of the string. It does
     231             :         not copy the buffer.
     232             : 
     233             :         @return the string previously contained in the buffer.
     234             :      */
     235    18765222 :     OUString makeStringAndClear()
     236             :     {
     237             :         return OUString(
     238             :                   rtl_uStringBuffer_makeStringAndClear( &pData, &nCapacity ),
     239    18765222 :                   SAL_NO_ACQUIRE );
     240             :     }
     241             : 
     242             :     /**
     243             :         Returns the length (character count) of this string buffer.
     244             : 
     245             :         @return  the number of characters in this string buffer.
     246             :      */
     247   141206308 :     sal_Int32 getLength() const
     248             :     {
     249   141206308 :         return pData->length;
     250             :     }
     251             : 
     252             :     /**
     253             :       Checks if a string buffer is empty.
     254             : 
     255             :       @return   true if the string buffer is empty;
     256             :                 false, otherwise.
     257             : 
     258             :       @since LibreOffice 4.1
     259             :     */
     260     3714034 :     bool isEmpty() const
     261             :     {
     262     3714034 :         return pData->length == 0;
     263             :     }
     264             : 
     265             :     /**
     266             :         Returns the current capacity of the String buffer.
     267             : 
     268             :         The capacity
     269             :         is the amount of storage available for newly inserted
     270             :         characters. The real buffer size is 2 bytes longer, because
     271             :         all strings are 0 terminated.
     272             : 
     273             :         @return  the current capacity of this string buffer.
     274             :      */
     275             :     sal_Int32 getCapacity() const
     276             :     {
     277             :         return nCapacity;
     278             :     }
     279             : 
     280             :     /**
     281             :         Ensures that the capacity of the buffer is at least equal to the
     282             :         specified minimum.
     283             : 
     284             :         The new capacity will be at least as large as the maximum of the current
     285             :         length (so that no contents of the buffer is destroyed) and the given
     286             :         minimumCapacity.  If the given minimumCapacity is negative, nothing is
     287             :         changed.
     288             : 
     289             :         @param   minimumCapacity   the minimum desired capacity.
     290             :      */
     291      213193 :     void ensureCapacity(sal_Int32 minimumCapacity)
     292             :     {
     293      213193 :         rtl_uStringbuffer_ensureCapacity( &pData, &nCapacity, minimumCapacity );
     294      213193 :     }
     295             : 
     296             :     /**
     297             :         Sets the length of this String buffer.
     298             : 
     299             :         If the <code>newLength</code> argument is less than the current
     300             :         length of the string buffer, the string buffer is truncated to
     301             :         contain exactly the number of characters given by the
     302             :         <code>newLength</code> argument.
     303             :         <p>
     304             :         If the <code>newLength</code> argument is greater than or equal
     305             :         to the current length, sufficient null characters
     306             :         (<code>'&#92;u0000'</code>) are appended to the string buffer so that
     307             :         length becomes the <code>newLength</code> argument.
     308             :         <p>
     309             :         The <code>newLength</code> argument must be greater than or equal
     310             :         to <code>0</code>.
     311             : 
     312             :         @param      newLength   the new length of the buffer.
     313             :      */
     314     2079000 :     void setLength(sal_Int32 newLength)
     315             :     {
     316             :         assert(newLength >= 0);
     317             :         // Avoid modifications if pData points to const empty string:
     318     2079000 :         if( newLength != pData->length )
     319             :         {
     320      149978 :             if( newLength > nCapacity )
     321       19084 :                 rtl_uStringbuffer_ensureCapacity(&pData, &nCapacity, newLength);
     322             :             else
     323      130894 :                 pData->buffer[newLength] = 0;
     324      149978 :             pData->length = newLength;
     325             :         }
     326     2079000 :     }
     327             : 
     328             :     /**
     329             :         Returns the character at a specific index in this string buffer.
     330             : 
     331             :         The first character of a string buffer is at index
     332             :         <code>0</code>, the next at index <code>1</code>, and so on, for
     333             :         array indexing.
     334             :         <p>
     335             :         The index argument must be greater than or equal to
     336             :         <code>0</code>, and less than the length of this string buffer.
     337             : 
     338             :         @param      index   the index of the desired character.
     339             :         @return     the character at the specified index of this string buffer.
     340             :      */
     341             :     SAL_DEPRECATED("use rtl::OUStringBuffer::operator [] instead")
     342             :     sal_Unicode charAt( sal_Int32 index ) const
     343             :     {
     344             :         assert(index >= 0 && index < pData->length);
     345             :         return pData->buffer[ index ];
     346             :     }
     347             : 
     348             :     /**
     349             :         The character at the specified index of this string buffer is set
     350             :         to <code>ch</code>.
     351             : 
     352             :         The index argument must be greater than or equal to
     353             :         <code>0</code>, and less than the length of this string buffer.
     354             : 
     355             :         @param      index   the index of the character to modify.
     356             :         @param      ch      the new character.
     357             :      */
     358             :     SAL_DEPRECATED("use rtl::OUStringBuffer::operator [] instead")
     359             :     OUStringBuffer & setCharAt(sal_Int32 index, sal_Unicode ch)
     360             :     {
     361             :         assert(index >= 0 && index < pData->length);
     362             :         pData->buffer[ index ] = ch;
     363             :         return *this;
     364             :     }
     365             : 
     366             :     /**
     367             :         Return a null terminated unicode character array.
     368             :      */
     369     6887298 :     const sal_Unicode*  getStr() const { return pData->buffer; }
     370             : 
     371             :     /**
     372             :       Access to individual characters.
     373             : 
     374             :       @param index must be non-negative and less than length.
     375             : 
     376             :       @return a reference to the character at the given index.
     377             : 
     378             :       @since LibreOffice 3.5
     379             :     */
     380    51892570 :     sal_Unicode & operator [](sal_Int32 index)
     381             :     {
     382             :         assert(index >= 0 && index < pData->length);
     383    51892570 :         return pData->buffer[index];
     384             :     }
     385             : 
     386             :     /**
     387             :       Access to individual characters.
     388             : 
     389             :       @param index must be non-negative and less than length.
     390             : 
     391             :       @return a reference to the character at the given index.
     392             : 
     393             :       @since LibreOffice 4.2
     394             :     */
     395             :     const sal_Unicode & operator [](sal_Int32 index) const
     396             :     {
     397             :         assert(index >= 0 && index < pData->length);
     398             :         return pData->buffer[index];
     399             :     }
     400             : 
     401             :     /**
     402             :         Return a OUString instance reflecting the current content
     403             :         of this OUStringBuffer.
     404             :      */
     405     3068310 :     const OUString toString() const
     406             :     {
     407     3068310 :         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    11682767 :     OUStringBuffer & append(const OUString &str)
     421             :     {
     422    11682767 :         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         330 :     OUStringBuffer & append(const OUStringBuffer &str)
     438             :     {
     439         330 :         if(!str.isEmpty())
     440             :         {
     441         328 :             append( str.getStr(), str.getLength() );
     442             :         }
     443         330 :         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       79786 :     OUStringBuffer & append( const sal_Unicode * str )
     458             :     {
     459       79786 :         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   115166132 :     OUStringBuffer & append( const sal_Unicode * str, sal_Int32 len)
     476             :     {
     477             :         assert( len >= 0 );
     478   115166132 :         rtl_uStringbuffer_insert( &pData, &nCapacity, getLength(), str, len );
     479   115166138 :         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     2053526 :     typename libreoffice_internal::ConstCharArrayDetector< T, OUStringBuffer& >::Type append( T& literal )
     489             :     {
     490             :         assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
     491     2053526 :         rtl_uStringbuffer_insert_ascii( &pData, &nCapacity, getLength(), literal,
     492     2053526 :             libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 );
     493     2053526 :         return *this;
     494             :     }
     495             : 
     496             : #ifdef RTL_FAST_STRING
     497             :     /**
     498             :      @overload
     499             :      @internal
     500             :     */
     501             :     template< typename T1, typename T2 >
     502      239785 :     OUStringBuffer& append( const OUStringConcat< T1, T2 >& c )
     503             :     {
     504      239785 :         const int l = c.length();
     505      239785 :         if( l == 0 )
     506           0 :             return *this;
     507      239785 :         rtl_uStringbuffer_ensureCapacity( &pData, &nCapacity, pData->length + l );
     508      239785 :         sal_Unicode* end = c.addData( pData->buffer + pData->length );
     509      239785 :         *end = '\0';
     510      239785 :         pData->length = end - pData->buffer;
     511      239785 :         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     2660925 :     OUStringBuffer & appendAscii( const sal_Char * str )
     532             :     {
     533     2660925 :         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     2876909 :     OUStringBuffer & appendAscii( const sal_Char * str, sal_Int32 len)
     555             :     {
     556             :         assert( len >= 0 );
     557     2876909 :         rtl_uStringbuffer_insert_ascii( &pData, &nCapacity, getLength(), str, len );
     558     2876909 :         return *this;
     559             :     }
     560             : 
     561             :     /**
     562             :         Appends the string representation of the <code>bool</code>
     563             :         argument to the string buffer.
     564             : 
     565             :         The argument is converted to a string as if by the method
     566             :         <code>String.valueOf</code>, and the characters of that
     567             :         string are then appended to this string buffer.
     568             : 
     569             :         @param   b   a <code>bool</code>.
     570             :         @return  this string buffer.
     571             : 
     572             :         @since LibreOffice 4.1
     573             :      */
     574             :     OUStringBuffer & append(bool b)
     575             :     {
     576             :         sal_Unicode sz[RTL_USTR_MAX_VALUEOFBOOLEAN];
     577             :         return append( sz, rtl_ustr_valueOfBoolean( sz, b ) );
     578             :     }
     579             : 
     580             :     /// @cond INTERNAL
     581             :     // Pointer can be automatically converted to bool, which is unwanted here.
     582             :     // Explicitly delete all pointer append() overloads to prevent this
     583             :     // (except for char* and sal_Unicode* overloads, which are handled elsewhere).
     584             :     template< typename T >
     585             :     typename libreoffice_internal::Enable< void,
     586             :         !libreoffice_internal::CharPtrDetector< T* >::ok && !libreoffice_internal::SalUnicodePtrDetector< T* >::ok >::Type
     587             :         append( T* ) SAL_DELETED_FUNCTION;
     588             :     /// @endcond
     589             : 
     590             :     // This overload is needed because OUString has a ctor from rtl_uString*, but
     591             :     // the bool overload above would be preferred to the conversion.
     592             :     /**
     593             :      @internal
     594             :     */
     595      863107 :     OUStringBuffer & append(rtl_uString* str)
     596             :     {
     597      863107 :         return append( OUString( str ));
     598             :     }
     599             : 
     600             :     /**
     601             :         Appends the string representation of the <code>sal_Bool</code>
     602             :         argument to the string buffer.
     603             : 
     604             :         The argument is converted to a string as if by the method
     605             :         <code>String.valueOf</code>, and the characters of that
     606             :         string are then appended to this string buffer.
     607             : 
     608             :         @param   b   a <code>sal_Bool</code>.
     609             :         @return  this string buffer.
     610             :      */
     611             :     OUStringBuffer & append(sal_Bool b)
     612             :     {
     613             :         sal_Unicode sz[RTL_USTR_MAX_VALUEOFBOOLEAN];
     614             :         return append( sz, rtl_ustr_valueOfBoolean( sz, b ) );
     615             :     }
     616             : 
     617             :     /**
     618             :         Appends the string representation of the ASCII <code>char</code>
     619             :         argument to this string buffer.
     620             : 
     621             :         The argument is appended to the contents of this string buffer.
     622             :         The length of this string buffer increases by <code>1</code>.
     623             : 
     624             :         @param   c   an ASCII <code>char</code>.
     625             :         @return  this string buffer.
     626             : 
     627             :         @since LibreOffice 3.5
     628             :      */
     629    15411066 :     OUStringBuffer & append(char c)
     630             :     {
     631             :         assert(static_cast< unsigned char >(c) <= 0x7F);
     632    15411066 :         return append(sal_Unicode(c));
     633             :     }
     634             : 
     635             :     /**
     636             :         Appends the string representation of the <code>char</code>
     637             :         argument to this string buffer.
     638             : 
     639             :         The argument is appended to the contents of this string buffer.
     640             :         The length of this string buffer increases by <code>1</code>.
     641             : 
     642             :         @param   c   a <code>char</code>.
     643             :         @return  this string buffer.
     644             :      */
     645    99440961 :     OUStringBuffer & append(sal_Unicode c)
     646             :     {
     647    99440961 :         return append( &c, 1 );
     648             :     }
     649             : 
     650             :     /**
     651             :         Appends the string representation of the <code>sal_Int32</code>
     652             :         argument to this string buffer.
     653             : 
     654             :         The argument is converted to a string as if by the method
     655             :         <code>String.valueOf</code>, and the characters of that
     656             :         string are then appended to this string buffer.
     657             : 
     658             :         @param   i   an <code>sal_Int32</code>.
     659             :         @param radix the radix
     660             :         @return  this string buffer.
     661             :      */
     662     2200484 :     OUStringBuffer & append(sal_Int32 i, sal_Int16 radix = 10 )
     663             :     {
     664             :         sal_Unicode sz[RTL_USTR_MAX_VALUEOFINT32];
     665     2200484 :         return append( sz, rtl_ustr_valueOfInt32( sz, i, radix ) );
     666             :     }
     667             : 
     668             :     /**
     669             :         Appends the string representation of the <code>long</code>
     670             :         argument to this string buffer.
     671             : 
     672             :         The argument is converted to a string as if by the method
     673             :         <code>String.valueOf</code>, and the characters of that
     674             :         string are then appended to this string buffer.
     675             : 
     676             :         @param   l   a <code>long</code>.
     677             :         @param radix the radix
     678             :         @return  this string buffer.
     679             :      */
     680      570097 :     OUStringBuffer & append(sal_Int64 l, sal_Int16 radix = 10 )
     681             :     {
     682             :         sal_Unicode sz[RTL_USTR_MAX_VALUEOFINT64];
     683      570097 :         return append( sz, rtl_ustr_valueOfInt64( sz, l, radix ) );
     684             :     }
     685             : 
     686             :     /**
     687             :         Appends the string representation of the <code>float</code>
     688             :         argument to this string buffer.
     689             : 
     690             :         The argument is converted to a string as if by the method
     691             :         <code>String.valueOf</code>, and the characters of that
     692             :         string are then appended to this string buffer.
     693             : 
     694             :         @param   f   a <code>float</code>.
     695             :         @return  this string buffer.
     696             :      */
     697           0 :     OUStringBuffer & append(float f)
     698             :     {
     699             :         sal_Unicode sz[RTL_USTR_MAX_VALUEOFFLOAT];
     700           0 :         return append( sz, rtl_ustr_valueOfFloat( sz, f ) );
     701             :     }
     702             : 
     703             :     /**
     704             :         Appends the string representation of the <code>double</code>
     705             :         argument to this string buffer.
     706             : 
     707             :         The argument is converted to a string as if by the method
     708             :         <code>String.valueOf</code>, and the characters of that
     709             :         string are then appended to this string buffer.
     710             : 
     711             :         @param   d   a <code>double</code>.
     712             :         @return  this string buffer.
     713             :      */
     714        9156 :     OUStringBuffer & append(double d)
     715             :     {
     716             :         sal_Unicode sz[RTL_USTR_MAX_VALUEOFDOUBLE];
     717        9156 :         return append( sz, rtl_ustr_valueOfDouble( sz, d ) );
     718             :     }
     719             : 
     720             :     /**
     721             :        Appends a single UTF-32 character to this string buffer.
     722             : 
     723             :        <p>The single UTF-32 character will be represented within the string
     724             :        buffer as either one or two UTF-16 code units.</p>
     725             : 
     726             :        @param c a well-formed UTF-32 code unit (that is, a value in the range
     727             :        <code>0</code>&ndash;<code>0x10FFFF</code>, but excluding
     728             :        <code>0xD800</code>&ndash;<code>0xDFFF</code>)
     729             : 
     730             :        @return
     731             :        this string buffer
     732             :      */
     733     7605570 :     OUStringBuffer & appendUtf32(sal_uInt32 c) {
     734     7605570 :         return insertUtf32(getLength(), c);
     735             :     }
     736             : 
     737             :     /**
     738             :         Inserts the string into this string buffer.
     739             : 
     740             :         The characters of the <code>String</code> argument are inserted, in
     741             :         order, into this string buffer at the indicated offset. The length
     742             :         of this string buffer is increased by the length of the argument.
     743             :         <p>
     744             :         The offset argument must be greater than or equal to
     745             :         <code>0</code>, and less than or equal to the length of this
     746             :         string buffer.
     747             : 
     748             :         @param      offset   the offset.
     749             :         @param      str      a string.
     750             :         @return     this string buffer.
     751             :      */
     752      727570 :     OUStringBuffer & insert(sal_Int32 offset, const OUString & str)
     753             :     {
     754      727570 :         return insert( offset, str.getStr(), str.getLength() );
     755             :     }
     756             : 
     757             :     /**
     758             :         Inserts the string representation of the <code>char</code> array
     759             :         argument into this string buffer.
     760             : 
     761             :         The characters of the array argument are inserted into the
     762             :         contents of this string buffer at the position indicated by
     763             :         <code>offset</code>. The length of this string buffer increases by
     764             :         the length of the argument.
     765             :         <p>
     766             :         The offset argument must be greater than or equal to
     767             :         <code>0</code>, and less than or equal to the length of this
     768             :         string buffer.
     769             : 
     770             :         @param      offset   the offset.
     771             :         @param      str      a character array.
     772             :         @return     this string buffer.
     773             :      */
     774           0 :     OUStringBuffer & insert( sal_Int32 offset, const sal_Unicode * str )
     775             :     {
     776           0 :         return insert( offset, str, rtl_ustr_getLength( str ) );
     777             :     }
     778             : 
     779             :     /**
     780             :         Inserts the string representation of the <code>char</code> array
     781             :         argument into this string buffer.
     782             : 
     783             :         The characters of the array argument are inserted into the
     784             :         contents of this string buffer at the position indicated by
     785             :         <code>offset</code>. The length of this string buffer increases by
     786             :         the length of the argument.
     787             :         <p>
     788             :         The offset argument must be greater than or equal to
     789             :         <code>0</code>, and less than or equal to the length of this
     790             :         string buffer.
     791             : 
     792             :         @param      offset   the offset.
     793             :         @param      str      a character array.
     794             :         @param      len     the number of characters to append.
     795             :         @return     this string buffer.
     796             :      */
     797      750229 :     OUStringBuffer & insert( sal_Int32 offset, const sal_Unicode * str, sal_Int32 len)
     798             :     {
     799             :         assert( offset >= 0 && offset <= pData->length );
     800             :         assert( len >= 0 );
     801      750229 :         rtl_uStringbuffer_insert( &pData, &nCapacity, offset, str, len );
     802      750229 :         return *this;
     803             :     }
     804             : 
     805             :     /**
     806             :         @overload
     807             :         This function accepts an ASCII string literal as its argument.
     808             :         @since LibreOffice 3.6
     809             :      */
     810             :     template< typename T >
     811      120908 :     typename libreoffice_internal::ConstCharArrayDetector< T, OUStringBuffer& >::Type insert( sal_Int32 offset, T& literal )
     812             :     {
     813             :         assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
     814      120908 :         rtl_uStringbuffer_insert_ascii( &pData, &nCapacity, offset, literal,
     815      120908 :             libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 );
     816      120908 :         return *this;
     817             :     }
     818             : 
     819             :     /**
     820             :         Inserts the string representation of the <code>sal_Bool</code>
     821             :         argument into this string buffer.
     822             : 
     823             :         The second argument is converted to a string as if by the method
     824             :         <code>String.valueOf</code>, and the characters of that
     825             :         string are then inserted into this string buffer at the indicated
     826             :         offset.
     827             :         <p>
     828             :         The offset argument must be greater than or equal to
     829             :         <code>0</code>, and less than or equal to the length of this
     830             :         string buffer.
     831             : 
     832             :         @param      offset   the offset.
     833             :         @param      b        a <code>sal_Bool</code>.
     834             :         @return     this string buffer.
     835             :      */
     836             :     OUStringBuffer & insert(sal_Int32 offset, sal_Bool b)
     837             :     {
     838             :         sal_Unicode sz[RTL_USTR_MAX_VALUEOFBOOLEAN];
     839             :         return insert( offset, sz, rtl_ustr_valueOfBoolean( sz, b ) );
     840             :     }
     841             : 
     842             :     /**
     843             :         Inserts the string representation of the <code>bool</code>
     844             :         argument into this string buffer.
     845             : 
     846             :         The second argument is converted to a string as if by the method
     847             :         <code>OUString::boolean</code>, and the characters of that
     848             :         string are then inserted into this string buffer at the indicated
     849             :         offset.
     850             :         <p>
     851             :         The offset argument must be greater than or equal to
     852             :         <code>0</code>, and less than or equal to the length of this
     853             :         string buffer.
     854             : 
     855             :         @param      offset   the offset.
     856             :         @param      b        a <code>bool</code>.
     857             :         @return     this string buffer.
     858             : 
     859             :         @since LibreOffice 4.3
     860             :      */
     861             :     OUStringBuffer & insert(sal_Int32 offset, bool b)
     862             :     {
     863             :         sal_Unicode sz[RTL_USTR_MAX_VALUEOFBOOLEAN];
     864             :         return insert( offset, sz, rtl_ustr_valueOfBoolean( sz, b ) );
     865             :     }
     866             : 
     867             :     /**
     868             :         Inserts the string representation of the <code>char</code>
     869             :         argument into this string buffer.
     870             : 
     871             :         The second argument is inserted into the contents of this string
     872             :         buffer at the position indicated by <code>offset</code>. The length
     873             :         of this string buffer increases by one.
     874             :         <p>
     875             :         The offset argument must be greater than or equal to
     876             :         <code>0</code>, and less than or equal to the length of this
     877             :         string buffer.
     878             : 
     879             :         @param      offset   the offset.
     880             :         @param      c        a <code>char</code>.
     881             :         @return     this string buffer.
     882             : 
     883             :         @since LibreOffice 3.6
     884             :      */
     885       15464 :     OUStringBuffer & insert(sal_Int32 offset, char c)
     886             :     {
     887       15464 :         sal_Unicode u = c;
     888       15464 :         return insert( offset, &u, 1 );
     889             :     }
     890             : 
     891             :     /**
     892             :         Inserts the string representation of the <code>char</code>
     893             :         argument into this string buffer.
     894             : 
     895             :         The second argument is inserted into the contents of this string
     896             :         buffer at the position indicated by <code>offset</code>. The length
     897             :         of this string buffer increases by one.
     898             :         <p>
     899             :         The offset argument must be greater than or equal to
     900             :         <code>0</code>, and less than or equal to the length of this
     901             :         string buffer.
     902             : 
     903             :         @param      offset   the offset.
     904             :         @param      c        a <code>char</code>.
     905             :         @return     this string buffer.
     906             :      */
     907        7195 :     OUStringBuffer & insert(sal_Int32 offset, sal_Unicode c)
     908             :     {
     909        7195 :         return insert( offset, &c, 1 );
     910             :     }
     911             : 
     912             :     /**
     913             :         Inserts the string representation of the second <code>sal_Int32</code>
     914             :         argument into this string buffer.
     915             : 
     916             :         The second argument is converted to a string as if by the method
     917             :         <code>String.valueOf</code>, and the characters of that
     918             :         string are then inserted into this string buffer at the indicated
     919             :         offset.
     920             :         <p>
     921             :         The offset argument must be greater than or equal to
     922             :         <code>0</code>, and less than or equal to the length of this
     923             :         string buffer.
     924             : 
     925             :         @param      offset   the offset.
     926             :         @param      i        an <code>sal_Int32</code>.
     927             :         @param      radix    the radix.
     928             :         @return     this string buffer.
     929             :         @exception  StringIndexOutOfBoundsException  if the offset is invalid.
     930             :      */
     931           0 :     OUStringBuffer & insert(sal_Int32 offset, sal_Int32 i, sal_Int16 radix = 10 )
     932             :     {
     933             :         sal_Unicode sz[RTL_USTR_MAX_VALUEOFINT32];
     934           0 :         return insert( offset, sz, rtl_ustr_valueOfInt32( sz, i, radix ) );
     935             :     }
     936             : 
     937             :     /**
     938             :         Inserts the string representation of the <code>long</code>
     939             :         argument into this string buffer.
     940             : 
     941             :         The second argument is converted to a string as if by the method
     942             :         <code>String.valueOf</code>, and the characters of that
     943             :         string are then inserted into this string buffer at the indicated
     944             :         offset.
     945             :         <p>
     946             :         The offset argument must be greater than or equal to
     947             :         <code>0</code>, and less than or equal to the length of this
     948             :         string buffer.
     949             : 
     950             :         @param      offset   the offset.
     951             :         @param      l        a <code>long</code>.
     952             :         @param      radix    the radix.
     953             :         @return     this string buffer.
     954             :         @exception  StringIndexOutOfBoundsException  if the offset is invalid.
     955             :      */
     956             :     OUStringBuffer & insert(sal_Int32 offset, sal_Int64 l, sal_Int16 radix = 10 )
     957             :     {
     958             :         sal_Unicode sz[RTL_USTR_MAX_VALUEOFINT64];
     959             :         return insert( offset, sz, rtl_ustr_valueOfInt64( sz, l, radix ) );
     960             :     }
     961             : 
     962             :     /**
     963             :         Inserts the string representation of the <code>float</code>
     964             :         argument into this string buffer.
     965             : 
     966             :         The second argument is converted to a string as if by the method
     967             :         <code>String.valueOf</code>, and the characters of that
     968             :         string are then inserted into this string buffer at the indicated
     969             :         offset.
     970             :         <p>
     971             :         The offset argument must be greater than or equal to
     972             :         <code>0</code>, and less than or equal to the length of this
     973             :         string buffer.
     974             : 
     975             :         @param      offset   the offset.
     976             :         @param      f        a <code>float</code>.
     977             :         @return     this string buffer.
     978             :         @exception  StringIndexOutOfBoundsException  if the offset is invalid.
     979             :      */
     980             :     OUStringBuffer insert(sal_Int32 offset, float f)
     981             :     {
     982             :         sal_Unicode sz[RTL_USTR_MAX_VALUEOFFLOAT];
     983             :         return insert( offset, sz, rtl_ustr_valueOfFloat( sz, f ) );
     984             :     }
     985             : 
     986             :     /**
     987             :         Inserts the string representation of the <code>double</code>
     988             :         argument into this string buffer.
     989             : 
     990             :         The second argument is converted to a string as if by the method
     991             :         <code>String.valueOf</code>, and the characters of that
     992             :         string are then inserted into this string buffer at the indicated
     993             :         offset.
     994             :         <p>
     995             :         The offset argument must be greater than or equal to
     996             :         <code>0</code>, and less than or equal to the length of this
     997             :         string buffer.
     998             : 
     999             :         @param      offset   the offset.
    1000             :         @param      d        a <code>double</code>.
    1001             :         @return     this string buffer.
    1002             :         @exception  StringIndexOutOfBoundsException  if the offset is invalid.
    1003             :      */
    1004             :     OUStringBuffer & insert(sal_Int32 offset, double d)
    1005             :     {
    1006             :         sal_Unicode sz[RTL_USTR_MAX_VALUEOFDOUBLE];
    1007             :         return insert( offset, sz, rtl_ustr_valueOfDouble( sz, d ) );
    1008             :     }
    1009             : 
    1010             :     /**
    1011             :        Inserts a single UTF-32 character into this string buffer.
    1012             : 
    1013             :        <p>The single UTF-32 character will be represented within the string
    1014             :        buffer as either one or two UTF-16 code units.</p>
    1015             : 
    1016             :        @param offset the offset into this string buffer (from zero to the length
    1017             :        of this string buffer, inclusive)
    1018             : 
    1019             :        @param c a well-formed UTF-32 code unit (that is, a value in the range
    1020             :        <code>0</code>&ndash;<code>0x10FFFF</code>, but excluding
    1021             :        <code>0xD800</code>&ndash;<code>0xDFFF</code>)
    1022             : 
    1023             :        @return this string buffer
    1024             :      */
    1025     7605574 :     OUStringBuffer & insertUtf32(sal_Int32 offset, sal_uInt32 c) {
    1026     7605574 :         rtl_uStringbuffer_insertUtf32(&pData, &nCapacity, offset, c);
    1027     7605574 :         return *this;
    1028             :     }
    1029             : 
    1030             :     /**
    1031             :         Removes the characters in a substring of this sequence.
    1032             : 
    1033             :         The substring begins at the specified <code>start</code> and
    1034             :         is <code>len</code> characters long.
    1035             : 
    1036             :         start must be >= 0 && <= This->length
    1037             : 
    1038             :         @param  start       The beginning index, inclusive
    1039             :         @param  len         The substring length
    1040             :         @return this string buffer.
    1041             :      */
    1042     3395925 :     OUStringBuffer & remove( sal_Int32 start, sal_Int32 len )
    1043             :     {
    1044             :         assert( start >= 0 && start <= pData->length );
    1045             :         assert( len >= 0 );
    1046     3395925 :         rtl_uStringbuffer_remove( &pData, start, len );
    1047     3395925 :         return *this;
    1048             :     }
    1049             : 
    1050             :     /**
    1051             :         Removes the tail of a string buffer start at the indicate position
    1052             : 
    1053             :         start must be >= 0 && <= This->length
    1054             : 
    1055             :         @param  start       The beginning index, inclusive. default to 0
    1056             :         @return this string buffer.
    1057             : 
    1058             :         @since LibreOffice 4.0
    1059             :      */
    1060         616 :     OUStringBuffer & truncate( sal_Int32 start = 0 )
    1061             :     {
    1062             :         assert( start >= 0 && start <= pData->length );
    1063         616 :         rtl_uStringbuffer_remove( &pData, start, getLength() - start );
    1064         616 :         return *this;
    1065             :     }
    1066             : 
    1067             :     /**
    1068             :        Replace all occurrences of
    1069             :        oldChar in this string buffer with newChar.
    1070             : 
    1071             :        @since LibreOffice 4.0
    1072             : 
    1073             :        @param    oldChar     the old character.
    1074             :        @param    newChar     the new character.
    1075             :        @return   this string buffer
    1076             :     */
    1077         653 :     OUStringBuffer& replace( sal_Unicode oldChar, sal_Unicode newChar )
    1078             :     {
    1079         653 :         sal_Int32 index = 0;
    1080        1632 :         while((index = indexOf(oldChar, index)) >= 0)
    1081             :         {
    1082         326 :             pData->buffer[ index ] = newChar;
    1083             :         }
    1084         653 :         return *this;
    1085             :     }
    1086             : 
    1087             :     /** Allows access to the internal data of this OUStringBuffer, for effective
    1088             :         manipulation.
    1089             : 
    1090             :         This method should be used with care.  After you have called this
    1091             :         method, you may use the returned pInternalData or pInternalCapacity only
    1092             :         as long as you make no other method call on this OUStringBuffer.
    1093             : 
    1094             :         @param pInternalData
    1095             :         This output parameter receives a pointer to the internal data
    1096             :         (rtl_uString pointer).  pInternalData itself must not be null.
    1097             : 
    1098             :         @param pInternalCapacity
    1099             :         This output parameter receives a pointer to the internal capacity.
    1100             :         pInternalCapacity itself must not be null.
    1101             :      */
    1102       35652 :     inline void accessInternals(rtl_uString *** pInternalData,
    1103             :                                 sal_Int32 ** pInternalCapacity)
    1104             :     {
    1105       35652 :         *pInternalData = &pData;
    1106       35652 :         *pInternalCapacity = &nCapacity;
    1107       35652 :     }
    1108             : 
    1109             : 
    1110             :     /**
    1111             :        Returns the index within this string of the first occurrence of the
    1112             :        specified character, starting the search at the specified index.
    1113             : 
    1114             :        @since LibreOffice 4.0
    1115             : 
    1116             :        @param    ch          character to be located.
    1117             :        @param    fromIndex   the index to start the search from.
    1118             :                              The index must be greater or equal than 0
    1119             :                              and less or equal as the string length.
    1120             :        @return   the index of the first occurrence of the character in the
    1121             :                  character sequence represented by this string that is
    1122             :                  greater than or equal to fromIndex, or
    1123             :                  -1 if the character does not occur.
    1124             :     */
    1125       18203 :     sal_Int32 indexOf( sal_Unicode ch, sal_Int32 fromIndex = 0 ) const
    1126             :     {
    1127             :         assert( fromIndex >= 0 && fromIndex <= pData->length );
    1128       18203 :         sal_Int32 ret = rtl_ustr_indexOfChar_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, ch );
    1129       18203 :         return (ret < 0 ? ret : ret+fromIndex);
    1130             :     }
    1131             : 
    1132             :     /**
    1133             :        Returns the index within this string of the last occurrence of the
    1134             :        specified character, searching backward starting at the end.
    1135             : 
    1136             :        @since LibreOffice 4.0
    1137             : 
    1138             :        @param    ch          character to be located.
    1139             :        @return   the index of the last occurrence of the character in the
    1140             :                  character sequence represented by this string, or
    1141             :                  -1 if the character does not occur.
    1142             :     */
    1143        2908 :     sal_Int32 lastIndexOf( sal_Unicode ch ) const
    1144             :     {
    1145        2908 :         return rtl_ustr_lastIndexOfChar_WithLength( pData->buffer, pData->length, ch );
    1146             :     }
    1147             : 
    1148             :     /**
    1149             :        Returns the index within this string of the last occurrence of the
    1150             :        specified character, searching backward starting before the specified
    1151             :        index.
    1152             : 
    1153             :        @since LibreOffice 4.0
    1154             : 
    1155             :        @param    ch          character to be located.
    1156             :        @param    fromIndex   the index before which to start the search.
    1157             :        @return   the index of the last occurrence of the character in the
    1158             :                  character sequence represented by this string that
    1159             :                  is less than fromIndex, or -1
    1160             :                  if the character does not occur before that point.
    1161             :     */
    1162             :     sal_Int32 lastIndexOf( sal_Unicode ch, sal_Int32 fromIndex ) const
    1163             :     {
    1164             :         assert( fromIndex >= 0 && fromIndex <= pData->length );
    1165             :         return rtl_ustr_lastIndexOfChar_WithLength( pData->buffer, fromIndex, ch );
    1166             :     }
    1167             : 
    1168             :     /**
    1169             :        Returns the index within this string of the first occurrence of the
    1170             :        specified substring, starting at the specified index.
    1171             : 
    1172             :        If str doesn't include any character, always -1 is
    1173             :        returned. This is also the case, if both strings are empty.
    1174             : 
    1175             :        @since LibreOffice 4.0
    1176             : 
    1177             :        @param    str         the substring to search for.
    1178             :        @param    fromIndex   the index to start the search from.
    1179             :        @return   If the string argument occurs one or more times as a substring
    1180             :                  within this string at the starting index, then the index
    1181             :                  of the first character of the first such substring is
    1182             :                  returned. If it does not occur as a substring starting
    1183             :                  at fromIndex or beyond, -1 is returned.
    1184             :     */
    1185        5592 :     sal_Int32 indexOf( const OUString & str, sal_Int32 fromIndex = 0 ) const
    1186             :     {
    1187             :         assert( fromIndex >= 0 && fromIndex <= pData->length );
    1188        5592 :         sal_Int32 ret = rtl_ustr_indexOfStr_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
    1189       11184 :                                                         str.pData->buffer, str.pData->length );
    1190        5592 :         return (ret < 0 ? ret : ret+fromIndex);
    1191             :     }
    1192             : 
    1193             :     /**
    1194             :        @overload
    1195             :        This function accepts an ASCII string literal as its argument.
    1196             : 
    1197             :        @since LibreOffice 4.0
    1198             :     */
    1199             :     template< typename T >
    1200             :     typename libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type indexOf( T& literal, sal_Int32 fromIndex = 0 ) const
    1201             :     {
    1202             :         assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
    1203             :         sal_Int32 ret = rtl_ustr_indexOfAscii_WithLength(
    1204             :             pData->buffer + fromIndex, pData->length - fromIndex, literal,
    1205             :             libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1);
    1206             :         return ret < 0 ? ret : ret + fromIndex;
    1207             :     }
    1208             : 
    1209             :     /**
    1210             :        Returns the index within this string of the last occurrence of
    1211             :        the specified substring, searching backward starting at the end.
    1212             : 
    1213             :        The returned index indicates the starting index of the substring
    1214             :        in this string.
    1215             :        If str doesn't include any character, always -1 is
    1216             :        returned. This is also the case, if both strings are empty.
    1217             : 
    1218             :        @since LibreOffice 4.0
    1219             : 
    1220             :        @param    str         the substring to search for.
    1221             :        @return   If the string argument occurs one or more times as a substring
    1222             :                  within this string, then the index of the first character of
    1223             :                  the last such substring is returned. If it does not occur as
    1224             :                  a substring, -1 is returned.
    1225             :     */
    1226             :     sal_Int32 lastIndexOf( const OUString & str ) const
    1227             :     {
    1228             :         return rtl_ustr_lastIndexOfStr_WithLength( pData->buffer, pData->length,
    1229             :                                                    str.pData->buffer, str.pData->length );
    1230             :     }
    1231             : 
    1232             :     /**
    1233             :        Returns the index within this string of the last occurrence of
    1234             :        the specified substring, searching backward starting before the specified
    1235             :        index.
    1236             : 
    1237             :        The returned index indicates the starting index of the substring
    1238             :        in this string.
    1239             :        If str doesn't include any character, always -1 is
    1240             :        returned. This is also the case, if both strings are empty.
    1241             : 
    1242             :        @since LibreOffice 4.0
    1243             : 
    1244             :        @param    str         the substring to search for.
    1245             :        @param    fromIndex   the index before which to start the search.
    1246             :        @return   If the string argument occurs one or more times as a substring
    1247             :                  within this string before the starting index, then the index
    1248             :                  of the first character of the last such substring is
    1249             :                  returned. Otherwise, -1 is returned.
    1250             :     */
    1251             :     sal_Int32 lastIndexOf( const OUString & str, sal_Int32 fromIndex ) const
    1252             :     {
    1253             :         assert( fromIndex >= 0 && fromIndex <= pData->length );
    1254             :         return rtl_ustr_lastIndexOfStr_WithLength( pData->buffer, fromIndex,
    1255             :                                                    str.pData->buffer, str.pData->length );
    1256             :     }
    1257             : 
    1258             :     /**
    1259             :        @overload
    1260             :        This function accepts an ASCII string literal as its argument.
    1261             :        @since LibreOffice 4.0
    1262             :     */
    1263             :     template< typename T >
    1264             :     typename libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type lastIndexOf( T& literal ) const
    1265             :     {
    1266             :         assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
    1267             :         return rtl_ustr_lastIndexOfAscii_WithLength(
    1268             :             pData->buffer, pData->length, literal, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1);
    1269             :     }
    1270             : 
    1271             :     /**
    1272             :        Strip the given character from the start of the buffer.
    1273             : 
    1274             :        @since LibreOffice 4.0
    1275             : 
    1276             :        @param    c         the character to strip
    1277             :        @return   The number of characters stripped
    1278             : 
    1279             :     */
    1280       57142 :     sal_Int32 stripStart(sal_Unicode c = (sal_Unicode)' ')
    1281             :     {
    1282             :         sal_Int32 index;
    1283      108398 :         for(index = 0; index < getLength() ; index++)
    1284             :         {
    1285       57476 :             if(pData->buffer[ index ] != c)
    1286             :             {
    1287        6220 :                 break;
    1288             :             }
    1289             :         }
    1290       57142 :         if(index)
    1291             :         {
    1292       51256 :             remove(0, index);
    1293             :         }
    1294       57142 :         return index;
    1295             :     }
    1296             : 
    1297             :     /**
    1298             :        Strip the given character from the end of the buffer.
    1299             : 
    1300             :        @since LibreOffice 4.0
    1301             : 
    1302             :        @param    c         the character to strip
    1303             :        @return   The number of characters stripped
    1304             : 
    1305             :     */
    1306         440 :     sal_Int32 stripEnd(sal_Unicode c = (sal_Unicode)' ')
    1307             :     {
    1308         440 :         sal_Int32 result = getLength();
    1309             :         sal_Int32 index;
    1310         880 :         for(index = getLength(); index > 0 ; index--)
    1311             :         {
    1312         880 :             if(pData->buffer[ index - 1 ] != c)
    1313             :             {
    1314         440 :                 break;
    1315             :             }
    1316             :         }
    1317         440 :         if(index < getLength())
    1318             :         {
    1319         440 :             truncate(index);
    1320             :         }
    1321         440 :         return result - getLength();
    1322             :     }
    1323             :     /**
    1324             :        Strip the given character from the both end of the buffer.
    1325             : 
    1326             :        @since LibreOffice 4.0
    1327             : 
    1328             :        @param    c         the character to strip
    1329             :        @return   The number of characters stripped
    1330             : 
    1331             :     */
    1332             :     sal_Int32 strip(sal_Unicode c = (sal_Unicode)' ')
    1333             :     {
    1334             :         return stripStart(c) + stripEnd(c);
    1335             :     }
    1336             :     /**
    1337             :       Returns a new string buffer that is a substring of this string.
    1338             : 
    1339             :       The substring begins at the specified beginIndex. If
    1340             :       beginIndex is negative or be greater than the length of
    1341             :       this string, behaviour is undefined.
    1342             : 
    1343             :       @param     beginIndex   the beginning index, inclusive.
    1344             :       @return    the specified substring.
    1345             :       @since LibreOffice 4.1
    1346             :     */
    1347         824 :     OUStringBuffer copy( sal_Int32 beginIndex ) const
    1348             :     {
    1349             :         assert(beginIndex >= 0 && beginIndex <= getLength());
    1350         824 :         return copy( beginIndex, getLength() - beginIndex );
    1351             :     }
    1352             : 
    1353             :     /**
    1354             :       Returns a new string buffer that is a substring of this string.
    1355             : 
    1356             :       The substring begins at the specified beginIndex and contains count
    1357             :       characters.  If either beginIndex or count are negative,
    1358             :       or beginIndex + count are greater than the length of this string
    1359             :       then behaviour is undefined.
    1360             : 
    1361             :       @param     beginIndex   the beginning index, inclusive.
    1362             :       @param     count        the number of characters.
    1363             :       @return    the specified substring.
    1364             :       @since LibreOffice 4.1
    1365             :     */
    1366         824 :     OUStringBuffer copy( sal_Int32 beginIndex, sal_Int32 count ) const
    1367             :     {
    1368             :         assert(beginIndex >= 0 && beginIndex <= getLength());
    1369             :         assert(count >= 0 && count <= getLength() - beginIndex);
    1370         824 :         rtl_uString *pNew = 0;
    1371         824 :         rtl_uStringbuffer_newFromStr_WithLength( &pNew, getStr() + beginIndex, count );
    1372         824 :         return OUStringBuffer( pNew, count + 16 );
    1373             :     }
    1374             : 
    1375             : #ifdef LIBO_INTERNAL_ONLY
    1376             :     // This is to complement the RTL_FAST_STRING operator+, which allows any combination of valid operands,
    1377             :     // even two buffers. It's intentional it returns OUString, just like the operator+ would in the fast variant.
    1378             : #ifndef RTL_FAST_STRING
    1379             :     /**
    1380             :      @internal
    1381             :      @since LibreOffice 4.1
    1382             :     */
    1383             :     friend OUString operator+( const OUStringBuffer& str1, const OUStringBuffer& str2  )
    1384             :     {
    1385             :         return OUString( str1.pData ).concat( str2.pData );
    1386             :     }
    1387             : #endif
    1388             : #endif
    1389             : 
    1390             : private:
    1391         824 :     OUStringBuffer( rtl_uString * value, const sal_Int32 capacity )
    1392             :     {
    1393         824 :         pData = value;
    1394         824 :         nCapacity = capacity;
    1395         824 :     }
    1396             : 
    1397             :     /**
    1398             :         A pointer to the data structure which contains the data.
    1399             :      */
    1400             :     rtl_uString * pData;
    1401             : 
    1402             :     /**
    1403             :         The len of the pData->buffer.
    1404             :      */
    1405             :     sal_Int32       nCapacity;
    1406             : };
    1407             : 
    1408             : #ifdef RTL_FAST_STRING
    1409             : /**
    1410             :  @internal
    1411             : */
    1412             : template<>
    1413             : struct ToStringHelper< OUStringBuffer >
    1414             :     {
    1415           2 :     static int length( const OUStringBuffer& s ) { return s.getLength(); }
    1416           2 :     static sal_Unicode* addData( sal_Unicode* buffer, const OUStringBuffer& s ) { return addDataHelper( buffer, s.getStr(), s.getLength()); }
    1417             :     static const bool allowOStringConcat = false;
    1418             :     static const bool allowOUStringConcat = true;
    1419             :     };
    1420             : #endif
    1421             : 
    1422             : }
    1423             : 
    1424             : #ifdef RTL_STRING_UNITTEST
    1425             : namespace rtl
    1426             : {
    1427             : typedef rtlunittest::OUStringBuffer OUStringBuffer;
    1428             : }
    1429             : #endif
    1430             : 
    1431             : #ifdef RTL_USING
    1432             : using ::rtl::OUStringBuffer;
    1433             : #endif
    1434             : 
    1435             : #endif // INCLUDED_RTL_USTRBUF_HXX
    1436             : 
    1437             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10