LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/include/rtl - ustrbuf.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 182 189 96.3 %
Date: 2013-07-09 Functions: 112 188 59.6 %
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     3287912 :     OUStringBuffer()
     100             :         : pData(NULL)
     101     3287912 :         , nCapacity( 16 )
     102             :     {
     103     3287912 :         rtl_uString_new_WithLength( &pData, nCapacity );
     104     3287912 :     }
     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       26624 :     OUStringBuffer( const OUStringBuffer & value )
     113             :         : pData(NULL)
     114       26624 :         , nCapacity( value.nCapacity )
     115             :     {
     116       26624 :         rtl_uStringbuffer_newFromStringBuffer( &pData, value.nCapacity, value.pData );
     117       26624 :     }
     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     1912841 :     explicit OUStringBuffer(int length)
     126             :         : pData(NULL)
     127     1912841 :         , nCapacity( length )
     128             :     {
     129     1912841 :         rtl_uString_new_WithLength( &pData, length );
     130     1912841 :     }
     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     5759713 :     OUStringBuffer(const OUString& value)
     143             :         : pData(NULL)
     144     5759713 :         , nCapacity( value.getLength() + 16 )
     145             :     {
     146     5759713 :         rtl_uStringbuffer_newFromStr_WithLength( &pData, value.getStr(), value.getLength() );
     147     5759713 :     }
     148             : 
     149             :     template< typename T >
     150        6158 :     OUStringBuffer( T& literal, typename internal::ConstCharArrayDetector< T, internal::Dummy >::Type = internal::Dummy() )
     151             :         : pData(NULL)
     152        6158 :         , nCapacity( internal::ConstCharArrayDetector< T, void >::size - 1 + 16 )
     153             :     {
     154             :         assert( strlen( literal ) == internal::ConstCharArrayDetector< T >::size - 1 );
     155        6158 :         rtl_uString_newFromLiteral( &pData, literal, internal::ConstCharArrayDetector< T, void >::size - 1, 16 );
     156             : #ifdef RTL_STRING_UNITTEST
     157           3 :         rtl_string_unittest_const_literal = true;
     158             : #endif
     159        6158 :     }
     160             : 
     161             : #ifdef RTL_STRING_UNITTEST
     162             :     /**
     163             :      * Only used by unittests to detect incorrect conversions.
     164             :      * @internal
     165             :      */
     166             :     template< typename T >
     167           9 :     OUStringBuffer( T&, typename internal::ExceptConstCharArrayDetector< T >::Type = internal::Dummy() )
     168             :     {
     169           9 :         pData = 0;
     170           9 :         nCapacity = 10;
     171           9 :         rtl_uString_newFromLiteral( &pData, "!!br0ken!!", 10, 0 ); // set to garbage
     172           9 :         rtl_string_unittest_invalid_conversion = true;
     173           9 :     }
     174             :     /**
     175             :      * Only used by unittests to detect incorrect conversions.
     176             :      * @internal
     177             :      */
     178             :     template< typename T >
     179           1 :     OUStringBuffer( const T&, typename internal::ExceptCharArrayDetector< T >::Type = internal::Dummy() )
     180             :     {
     181           1 :         pData = 0;
     182           1 :         nCapacity = 10;
     183           1 :         rtl_uString_newFromLiteral( &pData, "!!br0ken!!", 10, 0 ); // set to garbage
     184           1 :         rtl_string_unittest_invalid_conversion = true;
     185           1 :     }
     186             : #endif
     187             : 
     188             : #ifdef RTL_FAST_STRING
     189             :     /**
     190             :      @overload
     191             :      @internal
     192             :     */
     193             :     template< typename T1, typename T2 >
     194          39 :     OUStringBuffer( const OUStringConcat< T1, T2 >& c )
     195             :     {
     196          39 :         const sal_Int32 l = c.length();
     197          39 :         nCapacity = l + 16;
     198          39 :         pData = rtl_uString_alloc( nCapacity );
     199          39 :         sal_Unicode* end = c.addData( pData->buffer );
     200          39 :         *end = '\0';
     201          39 :         pData->length = end - pData->buffer;
     202             :         // TODO realloc in case pData->>length is noticeably smaller than l ?
     203          39 :     }
     204             : #endif
     205             :     /** Assign to this a copy of value.
     206             :      */
     207     1023638 :     OUStringBuffer& operator = ( const OUStringBuffer& value )
     208             :     {
     209     1023638 :         if (this != &value)
     210             :         {
     211             :             rtl_uStringbuffer_newFromStringBuffer(&pData,
     212             :                                                   value.nCapacity,
     213     1023628 :                                                   value.pData);
     214     1023628 :             nCapacity = value.nCapacity;
     215             :         }
     216     1023638 :         return *this;
     217             :     }
     218             : 
     219             :     /**
     220             :         Release the string data.
     221             :      */
     222    10993651 :     ~OUStringBuffer()
     223             :     {
     224    10993651 :         rtl_uString_release( pData );
     225    10993651 :     }
     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     9867873 :     OUString makeStringAndClear()
     236             :     {
     237             :         return OUString(
     238             :                   rtl_uStringBuffer_makeStringAndClear( &pData, &nCapacity ),
     239     9867873 :                   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    38992220 :     sal_Int32 getLength() const
     248             :     {
     249    38992220 :         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      557690 :     bool isEmpty() const SAL_THROW(())
     261             :     {
     262      557690 :         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      141359 :     void ensureCapacity(sal_Int32 minimumCapacity)
     292             :     {
     293      141359 :         rtl_uStringbuffer_ensureCapacity( &pData, &nCapacity, minimumCapacity );
     294      141359 :     }
     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      476600 :     void setLength(sal_Int32 newLength)
     315             :     {
     316             :         assert(newLength >= 0);
     317             :         // Avoid modifications if pData points to const empty string:
     318      476600 :         if( newLength != pData->length )
     319             :         {
     320        9603 :             if( newLength > nCapacity )
     321          93 :                 rtl_uStringbuffer_ensureCapacity(&pData, &nCapacity, newLength);
     322             :             else
     323        9510 :                 pData->buffer[newLength] = 0;
     324        9603 :             pData->length = newLength;
     325             :         }
     326      476600 :     }
     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     2200492 :     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     5613870 :     sal_Unicode & operator [](sal_Int32 index)
     381             :     {
     382             :         assert(index >= 0 && index < pData->length);
     383     5613870 :         return pData->buffer[index];
     384             :     }
     385             : 
     386             :     /**
     387             :         Return a OUString instance reflecting the current content
     388             :         of this OUStringBuffer.
     389             :      */
     390       64426 :     const OUString toString() const
     391             :     {
     392       64426 :         return OUString(pData->buffer, pData->length);
     393             :     }
     394             : 
     395             :     /**
     396             :         Appends the string to this string buffer.
     397             : 
     398             :         The characters of the <code>OUString</code> argument are appended, in
     399             :         order, to the contents of this string buffer, increasing the
     400             :         length of this string buffer by the length of the argument.
     401             : 
     402             :         @param   str   a string.
     403             :         @return  this string buffer.
     404             :      */
     405     5057297 :     OUStringBuffer & append(const OUString &str)
     406             :     {
     407     5057297 :         return append( str.getStr(), str.getLength() );
     408             :     }
     409             : 
     410             :     /**
     411             :         Appends the content of a stringbuffer to this string buffer.
     412             : 
     413             :         The characters of the <code>OUStringBuffer</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             :         @since LibreOffice 4.0
     421             :      */
     422         146 :     OUStringBuffer & append(const OUStringBuffer &str)
     423             :     {
     424         146 :         if(!str.isEmpty())
     425             :         {
     426         146 :             append( str.getStr(), str.getLength() );
     427             :         }
     428         146 :         return *this;
     429             :     }
     430             : 
     431             :     /**
     432             :         Appends the string representation of the <code>char</code> array
     433             :         argument to this string buffer.
     434             : 
     435             :         The characters of the array argument are appended, in order, to
     436             :         the contents of this string buffer. The length of this string
     437             :         buffer increases by the length of the argument.
     438             : 
     439             :         @param   str   the characters to be appended.
     440             :         @return  this string buffer.
     441             :      */
     442        7757 :     OUStringBuffer & append( const sal_Unicode * str )
     443             :     {
     444        7757 :         return append( str, rtl_ustr_getLength( str ) );
     445             :     }
     446             : 
     447             :     /**
     448             :         Appends the string representation of the <code>char</code> array
     449             :         argument to this string buffer.
     450             : 
     451             :         Characters of the character array <code>str</code> are appended,
     452             :         in order, to the contents of this string buffer. The length of this
     453             :         string buffer increases by the value of <code>len</code>.
     454             : 
     455             :         @param str the characters to be appended; must be non-null, and must
     456             :         point to at least len characters
     457             :         @param len the number of characters to append; must be non-negative
     458             :         @return  this string buffer.
     459             :      */
     460    34555684 :     OUStringBuffer & append( const sal_Unicode * str, sal_Int32 len)
     461             :     {
     462             :         // insert behind the last character
     463    34555684 :         rtl_uStringbuffer_insert( &pData, &nCapacity, getLength(), str, len );
     464    34555684 :         return *this;
     465             :     }
     466             : 
     467             :     /**
     468             :         @overload
     469             :         This function accepts an ASCII string literal as its argument.
     470             :         @since LibreOffice 3.6
     471             :      */
     472             :     template< typename T >
     473      115965 :     typename internal::ConstCharArrayDetector< T, OUStringBuffer& >::Type append( T& literal )
     474             :     {
     475             :         assert( strlen( literal ) == internal::ConstCharArrayDetector< T >::size - 1 );
     476      115965 :         rtl_uStringbuffer_insert_ascii( &pData, &nCapacity, getLength(), literal,
     477      115965 :             internal::ConstCharArrayDetector< T, void >::size - 1 );
     478      115965 :         return *this;
     479             :     }
     480             : 
     481             : #ifdef RTL_FAST_STRING
     482             :     /**
     483             :      @overload
     484             :      @internal
     485             :     */
     486             :     template< typename T1, typename T2 >
     487          43 :     OUStringBuffer& append( const OUStringConcat< T1, T2 >& c )
     488             :     {
     489          43 :         const int l = c.length();
     490          43 :         if( l == 0 )
     491           0 :             return *this;
     492          43 :         rtl_uStringbuffer_ensureCapacity( &pData, &nCapacity, pData->length + l );
     493          43 :         sal_Unicode* end = c.addData( pData->buffer + pData->length );
     494          43 :         *end = '\0';
     495          43 :         pData->length = end - pData->buffer;
     496          43 :         return *this;
     497             :     }
     498             : #endif
     499             : 
     500             :     /**
     501             :         Appends a 8-Bit ASCII character string to this string buffer.
     502             : 
     503             :        Since this method is optimized for performance. the ASCII
     504             :         character values are not converted in any way. The caller
     505             :         has to make sure that all ASCII characters are in the
     506             :         allowed range between 0 and 127. The ASCII string must be
     507             :         NULL-terminated.
     508             :         <p>
     509             :         The characters of the array argument are appended, in order, to
     510             :         the contents of this string buffer. The length of this string
     511             :         buffer increases by the length of the argument.
     512             : 
     513             :         @param   str   the 8-Bit ASCII characters to be appended.
     514             :         @return  this string buffer.
     515             :      */
     516      897590 :     OUStringBuffer & appendAscii( const sal_Char * str )
     517             :     {
     518      897590 :         return appendAscii( str, rtl_str_getLength( str ) );
     519             :     }
     520             : 
     521             :     /**
     522             :         Appends a 8-Bit ASCII character string to this string buffer.
     523             : 
     524             :         Since this method is optimized for performance. the ASCII
     525             :         character values are not converted in any way. The caller
     526             :         has to make sure that all ASCII characters are in the
     527             :         allowed range between 0 and 127. The ASCII string must be
     528             :         NULL-terminated.
     529             :         <p>
     530             :         Characters of the character array <code>str</code> are appended,
     531             :         in order, to the contents of this string buffer. The length of this
     532             :         string buffer increases by the value of <code>len</code>.
     533             : 
     534             :         @param str the 8-Bit ASCII characters to be appended; must be non-null,
     535             :         and must point to at least len characters
     536             :         @param len the number of characters to append; must be non-negative
     537             :         @return  this string buffer.
     538             :      */
     539     1378450 :     OUStringBuffer & appendAscii( const sal_Char * str, sal_Int32 len)
     540             :     {
     541     1378450 :         rtl_uStringbuffer_insert_ascii( &pData, &nCapacity, getLength(), str, len );
     542     1378450 :         return *this;
     543             :     }
     544             : 
     545             :     /**
     546             :         Appends the string representation of the <code>bool</code>
     547             :         argument to the string buffer.
     548             : 
     549             :         The argument is converted to a string as if by the method
     550             :         <code>String.valueOf</code>, and the characters of that
     551             :         string are then appended to this string buffer.
     552             : 
     553             :         @param   b   a <code>bool</code>.
     554             :         @return  this string buffer.
     555             : 
     556             :         @since LibreOffice 4.1
     557             :      */
     558           1 :     OUStringBuffer & append(bool b)
     559             :     {
     560             :         sal_Unicode sz[RTL_USTR_MAX_VALUEOFBOOLEAN];
     561           1 :         return append( sz, rtl_ustr_valueOfBoolean( sz, b ) );
     562             :     }
     563             : 
     564             :     // Pointer can be automatically converted to bool, which is unwanted here.
     565             :     // Explicitly delete all pointer append() overloads to prevent this
     566             :     // (except for char* and sal_Unicode* overloads, which are handled elsewhere).
     567             :     template< typename T >
     568             :     typename internal::Enable< void,
     569             :         !internal::CharPtrDetector< T* >::ok && !internal::SalUnicodePtrDetector< T* >::ok >::Type
     570             :         append( T* ) SAL_DELETED_FUNCTION;
     571             : 
     572             :     // This overload is needed because OUString has a ctor from rtl_uString*, but
     573             :     // the bool overload above would be prefered to the conversion.
     574             :     /**
     575             :      @internal
     576             :     */
     577      362123 :     OUStringBuffer & append(rtl_uString* str)
     578             :     {
     579      362123 :         return append( OUString( str ));
     580             :     }
     581             : 
     582             :     /**
     583             :         Appends the string representation of the <code>sal_Bool</code>
     584             :         argument to the string buffer.
     585             : 
     586             :         The argument is converted to a string as if by the method
     587             :         <code>String.valueOf</code>, and the characters of that
     588             :         string are then appended to this string buffer.
     589             : 
     590             :         @param   b   a <code>sal_Bool</code>.
     591             :         @return  this string buffer.
     592             :      */
     593             :     OUStringBuffer & append(sal_Bool b)
     594             :     {
     595             :         sal_Unicode sz[RTL_USTR_MAX_VALUEOFBOOLEAN];
     596             :         return append( sz, rtl_ustr_valueOfBoolean( sz, b ) );
     597             :     }
     598             : 
     599             :     /**
     600             :         Appends the string representation of the ASCII <code>char</code>
     601             :         argument to this string buffer.
     602             : 
     603             :         The argument is appended to the contents of this string buffer.
     604             :         The length of this string buffer increases by <code>1</code>.
     605             : 
     606             :         @param   c   an ASCII <code>char</code>.
     607             :         @return  this string buffer.
     608             : 
     609             :         @since LibreOffice 3.5
     610             :      */
     611     5028584 :     OUStringBuffer & append(char c)
     612             :     {
     613             :         assert(static_cast< unsigned char >(c) <= 0x7F);
     614     5028584 :         return append(sal_Unicode(c));
     615             :     }
     616             : 
     617             :     /**
     618             :         Appends the string representation of the <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   a <code>char</code>.
     625             :         @return  this string buffer.
     626             :      */
     627    28314918 :     OUStringBuffer & append(sal_Unicode c)
     628             :     {
     629    28314918 :         return append( &c, 1 );
     630             :     }
     631             : 
     632             :     /**
     633             :         Appends the string representation of the <code>sal_Int32</code>
     634             :         argument to this string buffer.
     635             : 
     636             :         The argument is converted to a string as if by the method
     637             :         <code>String.valueOf</code>, and the characters of that
     638             :         string are then appended to this string buffer.
     639             : 
     640             :         @param   i   an <code>sal_Int32</code>.
     641             :         @param radix the radix
     642             :         @return  this string buffer.
     643             :      */
     644      843389 :     OUStringBuffer & append(sal_Int32 i, sal_Int16 radix = 10 )
     645             :     {
     646             :         sal_Unicode sz[RTL_USTR_MAX_VALUEOFINT32];
     647      843389 :         return append( sz, rtl_ustr_valueOfInt32( sz, i, radix ) );
     648             :     }
     649             : 
     650             :     /**
     651             :         Appends the string representation of the <code>long</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   l   a <code>long</code>.
     659             :         @param radix the radix
     660             :         @return  this string buffer.
     661             :      */
     662      176591 :     OUStringBuffer & append(sal_Int64 l, sal_Int16 radix = 10 )
     663             :     {
     664             :         sal_Unicode sz[RTL_USTR_MAX_VALUEOFINT64];
     665      176591 :         return append( sz, rtl_ustr_valueOfInt64( sz, l, radix ) );
     666             :     }
     667             : 
     668             :     /**
     669             :         Appends the string representation of the <code>float</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   f   a <code>float</code>.
     677             :         @return  this string buffer.
     678             :      */
     679           0 :     OUStringBuffer & append(float f)
     680             :     {
     681             :         sal_Unicode sz[RTL_USTR_MAX_VALUEOFFLOAT];
     682           0 :         return append( sz, rtl_ustr_valueOfFloat( sz, f ) );
     683             :     }
     684             : 
     685             :     /**
     686             :         Appends the string representation of the <code>double</code>
     687             :         argument to this string buffer.
     688             : 
     689             :         The argument is converted to a string as if by the method
     690             :         <code>String.valueOf</code>, and the characters of that
     691             :         string are then appended to this string buffer.
     692             : 
     693             :         @param   d   a <code>double</code>.
     694             :         @return  this string buffer.
     695             :      */
     696        3059 :     OUStringBuffer & append(double d)
     697             :     {
     698             :         sal_Unicode sz[RTL_USTR_MAX_VALUEOFDOUBLE];
     699        3059 :         return append( sz, rtl_ustr_valueOfDouble( sz, d ) );
     700             :     }
     701             : 
     702             :     /**
     703             :        Appends a single UTF-32 character to this string buffer.
     704             : 
     705             :        <p>The single UTF-32 character will be represented within the string
     706             :        buffer as either one or two UTF-16 code units.</p>
     707             : 
     708             :        @param c a well-formed UTF-32 code unit (that is, a value in the range
     709             :        <code>0</code>&ndash;<code>0x10FFFF</code>, but excluding
     710             :        <code>0xD800</code>&ndash;<code>0xDFFF</code>)
     711             : 
     712             :        @return
     713             :        this string buffer
     714             :      */
     715      993299 :     OUStringBuffer & appendUtf32(sal_uInt32 c) {
     716      993299 :         return insertUtf32(getLength(), c);
     717             :     }
     718             : 
     719             :     /**
     720             :         Inserts the string into this string buffer.
     721             : 
     722             :         The characters of the <code>String</code> argument are inserted, in
     723             :         order, into this string buffer at the indicated offset. The length
     724             :         of this string buffer is increased by the length of the argument.
     725             :         <p>
     726             :         The offset argument must be greater than or equal to
     727             :         <code>0</code>, and less than or equal to the length of this
     728             :         string buffer.
     729             : 
     730             :         @param      offset   the offset.
     731             :         @param      str      a string.
     732             :         @return     this string buffer.
     733             :      */
     734      154553 :     OUStringBuffer & insert(sal_Int32 offset, const OUString & str)
     735             :     {
     736      154553 :         return insert( offset, str.getStr(), str.getLength() );
     737             :     }
     738             : 
     739             :     /**
     740             :         Inserts the string representation of the <code>char</code> array
     741             :         argument into this string buffer.
     742             : 
     743             :         The characters of the array argument are inserted into the
     744             :         contents of this string buffer at the position indicated by
     745             :         <code>offset</code>. The length of this string buffer increases by
     746             :         the length of the argument.
     747             :         <p>
     748             :         The offset argument must be greater than or equal to
     749             :         <code>0</code>, and less than or equal to the length of this
     750             :         string buffer.
     751             : 
     752             :         @param      offset   the offset.
     753             :         @param      str      a character array.
     754             :         @return     this string buffer.
     755             :      */
     756           0 :     OUStringBuffer & insert( sal_Int32 offset, const sal_Unicode * str )
     757             :     {
     758           0 :         return insert( offset, str, rtl_ustr_getLength( str ) );
     759             :     }
     760             : 
     761             :     /**
     762             :         Inserts the string representation of the <code>char</code> array
     763             :         argument into this string buffer.
     764             : 
     765             :         The characters of the array argument are inserted into the
     766             :         contents of this string buffer at the position indicated by
     767             :         <code>offset</code>. The length of this string buffer increases by
     768             :         the length of the argument.
     769             :         <p>
     770             :         The offset argument must be greater than or equal to
     771             :         <code>0</code>, and less than or equal to the length of this
     772             :         string buffer.
     773             : 
     774             :         @param      offset   the offset.
     775             :         @param      str      a character array.
     776             :         @param      len     the number of characters to append.
     777             :         @return     this string buffer.
     778             :      */
     779      159430 :     OUStringBuffer & insert( sal_Int32 offset, const sal_Unicode * str, sal_Int32 len)
     780             :     {
     781             :         // insert behind the last character
     782      159430 :         rtl_uStringbuffer_insert( &pData, &nCapacity, offset, str, len );
     783      159430 :         return *this;
     784             :     }
     785             : 
     786             :     /**
     787             :         @overload
     788             :         This function accepts an ASCII string literal as its argument.
     789             :         @since LibreOffice 3.6
     790             :      */
     791             :     template< typename T >
     792       26300 :     typename internal::ConstCharArrayDetector< T, OUStringBuffer& >::Type insert( sal_Int32 offset, T& literal )
     793             :     {
     794             :         assert( strlen( literal ) == internal::ConstCharArrayDetector< T >::size - 1 );
     795       26300 :         rtl_uStringbuffer_insert_ascii( &pData, &nCapacity, offset, literal,
     796       26300 :             internal::ConstCharArrayDetector< T, void >::size - 1 );
     797       26300 :         return *this;
     798             :     }
     799             : 
     800             :     /**
     801             :         Inserts the string representation of the <code>sal_Bool</code>
     802             :         argument into this string buffer.
     803             : 
     804             :         The second argument is converted to a string as if by the method
     805             :         <code>String.valueOf</code>, and the characters of that
     806             :         string are then inserted into this string buffer at the indicated
     807             :         offset.
     808             :         <p>
     809             :         The offset argument must be greater than or equal to
     810             :         <code>0</code>, and less than or equal to the length of this
     811             :         string buffer.
     812             : 
     813             :         @param      offset   the offset.
     814             :         @param      b        a <code>sal_Bool</code>.
     815             :         @return     this string buffer.
     816             :      */
     817             :     OUStringBuffer & insert(sal_Int32 offset, sal_Bool b)
     818             :     {
     819             :         sal_Unicode sz[RTL_USTR_MAX_VALUEOFBOOLEAN];
     820             :         return insert( offset, sz, rtl_ustr_valueOfBoolean( sz, b ) );
     821             :     }
     822             : 
     823             :     /**
     824             :         Inserts the string representation of the <code>char</code>
     825             :         argument into this string buffer.
     826             : 
     827             :         The second argument is inserted into the contents of this string
     828             :         buffer at the position indicated by <code>offset</code>. The length
     829             :         of this string buffer increases by one.
     830             :         <p>
     831             :         The offset argument must be greater than or equal to
     832             :         <code>0</code>, and less than or equal to the length of this
     833             :         string buffer.
     834             : 
     835             :         @param      offset   the offset.
     836             :         @param      c        a <code>char</code>.
     837             :         @return     this string buffer.
     838             : 
     839             :         @since LibreOffice 3.6
     840             :      */
     841        1828 :     OUStringBuffer & insert(sal_Int32 offset, char c)
     842             :     {
     843        1828 :         sal_Unicode u = c;
     844        1828 :         return insert( offset, &u, 1 );
     845             :     }
     846             : 
     847             :     /**
     848             :         Inserts the string representation of the <code>char</code>
     849             :         argument into this string buffer.
     850             : 
     851             :         The second argument is inserted into the contents of this string
     852             :         buffer at the position indicated by <code>offset</code>. The length
     853             :         of this string buffer increases by one.
     854             :         <p>
     855             :         The offset argument must be greater than or equal to
     856             :         <code>0</code>, and less than or equal to the length of this
     857             :         string buffer.
     858             : 
     859             :         @param      offset   the offset.
     860             :         @param      c        a <code>char</code>.
     861             :         @return     this string buffer.
     862             :      */
     863        2923 :     OUStringBuffer & insert(sal_Int32 offset, sal_Unicode c)
     864             :     {
     865        2923 :         return insert( offset, &c, 1 );
     866             :     }
     867             : 
     868             :     /**
     869             :         Inserts the string representation of the second <code>sal_Int32</code>
     870             :         argument into this string buffer.
     871             : 
     872             :         The second argument is converted to a string as if by the method
     873             :         <code>String.valueOf</code>, and the characters of that
     874             :         string are then inserted into this string buffer at the indicated
     875             :         offset.
     876             :         <p>
     877             :         The offset argument must be greater than or equal to
     878             :         <code>0</code>, and less than or equal to the length of this
     879             :         string buffer.
     880             : 
     881             :         @param      offset   the offset.
     882             :         @param      i        an <code>sal_Int32</code>.
     883             :         @param      radix    the radix.
     884             :         @return     this string buffer.
     885             :         @exception  StringIndexOutOfBoundsException  if the offset is invalid.
     886             :      */
     887           0 :     OUStringBuffer & insert(sal_Int32 offset, sal_Int32 i, sal_Int16 radix = 10 )
     888             :     {
     889             :         sal_Unicode sz[RTL_USTR_MAX_VALUEOFINT32];
     890           0 :         return insert( offset, sz, rtl_ustr_valueOfInt32( sz, i, radix ) );
     891             :     }
     892             : 
     893             :     /**
     894             :         Inserts the string representation of the <code>long</code>
     895             :         argument into this string buffer.
     896             : 
     897             :         The second argument is converted to a string as if by the method
     898             :         <code>String.valueOf</code>, and the characters of that
     899             :         string are then inserted into this string buffer at the indicated
     900             :         offset.
     901             :         <p>
     902             :         The offset argument must be greater than or equal to
     903             :         <code>0</code>, and less than or equal to the length of this
     904             :         string buffer.
     905             : 
     906             :         @param      offset   the offset.
     907             :         @param      l        a <code>long</code>.
     908             :         @param      radix    the radix.
     909             :         @return     this string buffer.
     910             :         @exception  StringIndexOutOfBoundsException  if the offset is invalid.
     911             :      */
     912             :     OUStringBuffer & insert(sal_Int32 offset, sal_Int64 l, sal_Int16 radix = 10 )
     913             :     {
     914             :         sal_Unicode sz[RTL_USTR_MAX_VALUEOFINT64];
     915             :         return insert( offset, sz, rtl_ustr_valueOfInt64( sz, l, radix ) );
     916             :     }
     917             : 
     918             :     /**
     919             :         Inserts the string representation of the <code>float</code>
     920             :         argument into this string buffer.
     921             : 
     922             :         The second argument is converted to a string as if by the method
     923             :         <code>String.valueOf</code>, and the characters of that
     924             :         string are then inserted into this string buffer at the indicated
     925             :         offset.
     926             :         <p>
     927             :         The offset argument must be greater than or equal to
     928             :         <code>0</code>, and less than or equal to the length of this
     929             :         string buffer.
     930             : 
     931             :         @param      offset   the offset.
     932             :         @param      f        a <code>float</code>.
     933             :         @return     this string buffer.
     934             :         @exception  StringIndexOutOfBoundsException  if the offset is invalid.
     935             :      */
     936             :     OUStringBuffer insert(sal_Int32 offset, float f)
     937             :     {
     938             :         sal_Unicode sz[RTL_USTR_MAX_VALUEOFFLOAT];
     939             :         return insert( offset, sz, rtl_ustr_valueOfFloat( sz, f ) );
     940             :     }
     941             : 
     942             :     /**
     943             :         Inserts the string representation of the <code>double</code>
     944             :         argument into this string buffer.
     945             : 
     946             :         The second argument is converted to a string as if by the method
     947             :         <code>String.valueOf</code>, and the characters of that
     948             :         string are then inserted into this string buffer at the indicated
     949             :         offset.
     950             :         <p>
     951             :         The offset argument must be greater than or equal to
     952             :         <code>0</code>, and less than or equal to the length of this
     953             :         string buffer.
     954             : 
     955             :         @param      offset   the offset.
     956             :         @param      d        a <code>double</code>.
     957             :         @return     this string buffer.
     958             :         @exception  StringIndexOutOfBoundsException  if the offset is invalid.
     959             :      */
     960             :     OUStringBuffer & insert(sal_Int32 offset, double d)
     961             :     {
     962             :         sal_Unicode sz[RTL_USTR_MAX_VALUEOFDOUBLE];
     963             :         return insert( offset, sz, rtl_ustr_valueOfDouble( sz, d ) );
     964             :     }
     965             : 
     966             :     /**
     967             :        Inserts a single UTF-32 character into this string buffer.
     968             : 
     969             :        <p>The single UTF-32 character will be represented within the string
     970             :        buffer as either one or two UTF-16 code units.</p>
     971             : 
     972             :        @param offset the offset into this string buffer (from zero to the length
     973             :        of this string buffer, inclusive)
     974             : 
     975             :        @param c a well-formed UTF-32 code unit (that is, a value in the range
     976             :        <code>0</code>&ndash;<code>0x10FFFF</code>, but excluding
     977             :        <code>0xD800</code>&ndash;<code>0xDFFF</code>)
     978             : 
     979             :        @return this string buffer
     980             :      */
     981      993301 :     OUStringBuffer & insertUtf32(sal_Int32 offset, sal_uInt32 c) {
     982      993301 :         rtl_uStringbuffer_insertUtf32(&pData, &nCapacity, offset, c);
     983      993301 :         return *this;
     984             :     }
     985             : 
     986             :     /**
     987             :         Removes the characters in a substring of this sequence.
     988             : 
     989             :         The substring begins at the specified <code>start</code> and
     990             :         is <code>len</code> characters long.
     991             : 
     992             :         start must be >= 0 && <= This->length
     993             : 
     994             :         @param  start       The beginning index, inclusive
     995             :         @param  len         The substring length
     996             :         @return this string buffer.
     997             :      */
     998     1455701 :     OUStringBuffer & remove( sal_Int32 start, sal_Int32 len )
     999             :     {
    1000     1455701 :         rtl_uStringbuffer_remove( &pData, start, len );
    1001     1455701 :         return *this;
    1002             :     }
    1003             : 
    1004             :     /**
    1005             :         Removes the tail of a string buffer start at the indicate position
    1006             : 
    1007             :         start must be >= 0 && <= This->length
    1008             : 
    1009             :         @param  start       The beginning index, inclusive. default to 0
    1010             :         @return this string buffer.
    1011             : 
    1012             :         @since LibreOffice 4.0
    1013             :      */
    1014         895 :     OUStringBuffer & truncate( sal_Int32 start = 0 )
    1015             :     {
    1016         895 :         rtl_uStringbuffer_remove( &pData, start, getLength() - start );
    1017         895 :         return *this;
    1018             :     }
    1019             : 
    1020             :     /**
    1021             :        Replace all occurrences of
    1022             :        oldChar in this string buffer with newChar.
    1023             : 
    1024             :        @since LibreOffice 4.0
    1025             : 
    1026             :        @param    oldChar     the old character.
    1027             :        @param    newChar     the new character.
    1028             :        @return   this string buffer
    1029             :     */
    1030         195 :     OUStringBuffer& replace( sal_Unicode oldChar, sal_Unicode newChar )
    1031             :     {
    1032         195 :         sal_Int32 index = 0;
    1033         446 :         while((index = indexOf(oldChar, index)) >= 0)
    1034             :         {
    1035          56 :             pData->buffer[ index ] = newChar;
    1036             :         }
    1037         195 :         return *this;
    1038             :     }
    1039             : 
    1040             :     /** Allows access to the internal data of this OUStringBuffer, for effective
    1041             :         manipulation.
    1042             : 
    1043             :         This method should be used with care.  After you have called this
    1044             :         method, you may use the returned pInternalData or pInternalCapacity only
    1045             :         as long as you make no other method call on this OUStringBuffer.
    1046             : 
    1047             :         @param pInternalData
    1048             :         This output parameter receives a pointer to the internal data
    1049             :         (rtl_uString pointer).  pInternalData itself must not be null.
    1050             : 
    1051             :         @param pInternalCapacity
    1052             :         This output parameter receives a pointer to the internal capacity.
    1053             :         pInternalCapacity itself must not be null.
    1054             :      */
    1055        1109 :     inline void accessInternals(rtl_uString *** pInternalData,
    1056             :                                 sal_Int32 ** pInternalCapacity)
    1057             :     {
    1058        1109 :         *pInternalData = &pData;
    1059        1109 :         *pInternalCapacity = &nCapacity;
    1060        1109 :     }
    1061             : 
    1062             : 
    1063             :     /**
    1064             :        Returns the index within this string of the first occurrence of the
    1065             :        specified character, starting the search at the specified index.
    1066             : 
    1067             :        @since LibreOffice 4.0
    1068             : 
    1069             :        @param    ch          character to be located.
    1070             :        @param    fromIndex   the index to start the search from.
    1071             :                              The index must be greater or equal than 0
    1072             :                              and less or equal as the string length.
    1073             :        @return   the index of the first occurrence of the character in the
    1074             :                  character sequence represented by this string that is
    1075             :                  greater than or equal to fromIndex, or
    1076             :                  -1 if the character does not occur.
    1077             :     */
    1078        2082 :     sal_Int32 indexOf( sal_Unicode ch, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
    1079             :     {
    1080        2082 :         sal_Int32 ret = rtl_ustr_indexOfChar_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, ch );
    1081        2082 :         return (ret < 0 ? ret : ret+fromIndex);
    1082             :     }
    1083             : 
    1084             :     /**
    1085             :        Returns the index within this string of the last occurrence of the
    1086             :        specified character, searching backward starting at the end.
    1087             : 
    1088             :        @since LibreOffice 4.0
    1089             : 
    1090             :        @param    ch          character to be located.
    1091             :        @return   the index of the last occurrence of the character in the
    1092             :                  character sequence represented by this string, or
    1093             :                  -1 if the character does not occur.
    1094             :     */
    1095         394 :     sal_Int32 lastIndexOf( sal_Unicode ch ) const SAL_THROW(())
    1096             :     {
    1097         394 :         return rtl_ustr_lastIndexOfChar_WithLength( pData->buffer, pData->length, ch );
    1098             :     }
    1099             : 
    1100             :     /**
    1101             :        Returns the index within this string of the last occurrence of the
    1102             :        specified character, searching backward starting before the specified
    1103             :        index.
    1104             : 
    1105             :        @since LibreOffice 4.0
    1106             : 
    1107             :        @param    ch          character to be located.
    1108             :        @param    fromIndex   the index before which to start the search.
    1109             :        @return   the index of the last occurrence of the character in the
    1110             :                  character sequence represented by this string that
    1111             :                  is less than fromIndex, or -1
    1112             :                  if the character does not occur before that point.
    1113             :     */
    1114             :     sal_Int32 lastIndexOf( sal_Unicode ch, sal_Int32 fromIndex ) const SAL_THROW(())
    1115             :     {
    1116             :         return rtl_ustr_lastIndexOfChar_WithLength( pData->buffer, fromIndex, ch );
    1117             :     }
    1118             : 
    1119             :     /**
    1120             :        Returns the index within this string of the first occurrence of the
    1121             :        specified substring, starting at the specified index.
    1122             : 
    1123             :        If str doesn't include any character, always -1 is
    1124             :        returned. This is also the case, if both strings are empty.
    1125             : 
    1126             :        @since LibreOffice 4.0
    1127             : 
    1128             :        @param    str         the substring to search for.
    1129             :        @param    fromIndex   the index to start the search from.
    1130             :        @return   If the string argument occurs one or more times as a substring
    1131             :                  within this string at the starting index, then the index
    1132             :                  of the first character of the first such substring is
    1133             :                  returned. If it does not occur as a substring starting
    1134             :                  at fromIndex or beyond, -1 is returned.
    1135             :     */
    1136        1742 :     sal_Int32 indexOf( const OUString & str, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
    1137             :     {
    1138        1742 :         sal_Int32 ret = rtl_ustr_indexOfStr_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
    1139        3484 :                                                         str.pData->buffer, str.pData->length );
    1140        1742 :         return (ret < 0 ? ret : ret+fromIndex);
    1141             :     }
    1142             : 
    1143             :     /**
    1144             :        @overload
    1145             :        This function accepts an ASCII string literal as its argument.
    1146             : 
    1147             :        @since LibreOffice 4.0
    1148             :     */
    1149             :     template< typename T >
    1150             :     typename internal::ConstCharArrayDetector< T, sal_Int32 >::Type indexOf( T& literal, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
    1151             :     {
    1152             :         assert( strlen( literal ) == internal::ConstCharArrayDetector< T >::size - 1 );
    1153             :         sal_Int32 ret = rtl_ustr_indexOfAscii_WithLength(
    1154             :             pData->buffer + fromIndex, pData->length - fromIndex, literal,
    1155             :             internal::ConstCharArrayDetector< T, void >::size - 1);
    1156             :         return ret < 0 ? ret : ret + fromIndex;
    1157             :     }
    1158             : 
    1159             :     /**
    1160             :        Returns the index within this string of the last occurrence of
    1161             :        the specified substring, searching backward starting at the end.
    1162             : 
    1163             :        The returned index indicates the starting index of the substring
    1164             :        in this string.
    1165             :        If str doesn't include any character, always -1 is
    1166             :        returned. This is also the case, if both strings are empty.
    1167             : 
    1168             :        @since LibreOffice 4.0
    1169             : 
    1170             :        @param    str         the substring to search for.
    1171             :        @return   If the string argument occurs one or more times as a substring
    1172             :                  within this string, then the index of the first character of
    1173             :                  the last such substring is returned. If it does not occur as
    1174             :                  a substring, -1 is returned.
    1175             :     */
    1176             :     sal_Int32 lastIndexOf( const OUString & str ) const SAL_THROW(())
    1177             :     {
    1178             :         return rtl_ustr_lastIndexOfStr_WithLength( pData->buffer, pData->length,
    1179             :                                                    str.pData->buffer, str.pData->length );
    1180             :     }
    1181             : 
    1182             :     /**
    1183             :        Returns the index within this string of the last occurrence of
    1184             :        the specified substring, searching backward starting before the specified
    1185             :        index.
    1186             : 
    1187             :        The returned index indicates the starting index of the substring
    1188             :        in this string.
    1189             :        If str doesn't include any character, always -1 is
    1190             :        returned. This is also the case, if both strings are empty.
    1191             : 
    1192             :        @since LibreOffice 4.0
    1193             : 
    1194             :        @param    str         the substring to search for.
    1195             :        @param    fromIndex   the index before which to start the search.
    1196             :        @return   If the string argument occurs one or more times as a substring
    1197             :                  within this string before the starting index, then the index
    1198             :                  of the first character of the last such substring is
    1199             :                  returned. Otherwise, -1 is returned.
    1200             :     */
    1201             :     sal_Int32 lastIndexOf( const OUString & str, sal_Int32 fromIndex ) const SAL_THROW(())
    1202             :     {
    1203             :         return rtl_ustr_lastIndexOfStr_WithLength( pData->buffer, fromIndex,
    1204             :                                                    str.pData->buffer, str.pData->length );
    1205             :     }
    1206             : 
    1207             :     /**
    1208             :        @overload
    1209             :        This function accepts an ASCII string literal as its argument.
    1210             :        @since LibreOffice 4.0
    1211             :     */
    1212             :     template< typename T >
    1213             :     typename internal::ConstCharArrayDetector< T, sal_Int32 >::Type lastIndexOf( T& literal ) const SAL_THROW(())
    1214             :     {
    1215             :         assert( strlen( literal ) == internal::ConstCharArrayDetector< T >::size - 1 );
    1216             :         return rtl_ustr_lastIndexOfAscii_WithLength(
    1217             :             pData->buffer, pData->length, literal, internal::ConstCharArrayDetector< T, void >::size - 1);
    1218             :     }
    1219             : 
    1220             :     /**
    1221             :        Strip the given character from the start of the buffer.
    1222             : 
    1223             :        @since LibreOffice 4.0
    1224             : 
    1225             :        @param    c         the character to strip
    1226             :        @return   The number of characters stripped
    1227             : 
    1228             :     */
    1229       12794 :     sal_Int32 stripStart(sal_Unicode c = (sal_Unicode)' ')
    1230             :     {
    1231             :         sal_Int32 index;
    1232       23676 :         for(index = 0; index < getLength() ; index++)
    1233             :         {
    1234       12651 :             if(pData->buffer[ index ] != c)
    1235             :             {
    1236        1769 :                 break;
    1237             :             }
    1238             :         }
    1239       12794 :         if(index)
    1240             :         {
    1241       10882 :             remove(0, index);
    1242             :         }
    1243       12794 :         return index;
    1244             :     }
    1245             : 
    1246             :     /**
    1247             :        Strip the given character from the end of the buffer.
    1248             : 
    1249             :        @since LibreOffice 4.0
    1250             : 
    1251             :        @param    c         the character to strip
    1252             :        @return   The number of characters stripped
    1253             : 
    1254             :     */
    1255         891 :     sal_Int32 stripEnd(sal_Unicode c = (sal_Unicode)' ')
    1256             :     {
    1257         891 :         sal_Int32 result = getLength();
    1258             :         sal_Int32 index;
    1259        1782 :         for(index = getLength(); index > 0 ; index--)
    1260             :         {
    1261        1782 :             if(pData->buffer[ index - 1 ] != c)
    1262             :             {
    1263         891 :                 break;
    1264             :             }
    1265             :         }
    1266         891 :         if(index < getLength())
    1267             :         {
    1268         891 :             truncate(index);
    1269             :         }
    1270         891 :         return result - getLength();
    1271             :     }
    1272             :     /**
    1273             :        Strip the given character from the both end of the buffer.
    1274             : 
    1275             :        @since LibreOffice 4.0
    1276             : 
    1277             :        @param    c         the character to strip
    1278             :        @return   The number of characters stripped
    1279             : 
    1280             :     */
    1281             :     sal_Int32 strip(sal_Unicode c = (sal_Unicode)' ')
    1282             :     {
    1283             :         return stripStart(c) + stripEnd(c);
    1284             :     }
    1285             :     /**
    1286             :       Returns a new string buffer that is a substring of this string.
    1287             : 
    1288             :       The substring begins at the specified beginIndex. If
    1289             :       beginIndex is negative or be greater than the length of
    1290             :       this string, behaviour is undefined.
    1291             : 
    1292             :       @param     beginIndex   the beginning index, inclusive.
    1293             :       @return    the specified substring.
    1294             :       @since LibreOffice 4.1
    1295             :     */
    1296         406 :     OUStringBuffer copy( sal_Int32 beginIndex ) const SAL_THROW(())
    1297             :     {
    1298             :         assert(beginIndex >= 0 && beginIndex <= getLength());
    1299         406 :         return copy( beginIndex, getLength() - beginIndex );
    1300             :     }
    1301             : 
    1302             :     /**
    1303             :       Returns a new string buffer that is a substring of this string.
    1304             : 
    1305             :       The substring begins at the specified beginIndex and contains count
    1306             :       characters.  If either beginIndex or count are negative,
    1307             :       or beginIndex + count are greater than the length of this string
    1308             :       then behaviour is undefined.
    1309             : 
    1310             :       @param     beginIndex   the beginning index, inclusive.
    1311             :       @param     count        the number of characters.
    1312             :       @return    the specified substring.
    1313             :       @since LibreOffice 4.1
    1314             :     */
    1315         406 :     OUStringBuffer copy( sal_Int32 beginIndex, sal_Int32 count ) const SAL_THROW(())
    1316             :     {
    1317             :         assert(beginIndex >= 0 && beginIndex <= getLength());
    1318             :         assert(count >= 0 && count <= getLength() - beginIndex);
    1319         406 :         rtl_uString *pNew = 0;
    1320         406 :         rtl_uStringbuffer_newFromStr_WithLength( &pNew, getStr() + beginIndex, count );
    1321         406 :         return OUStringBuffer( pNew, count + 16 );
    1322             :     }
    1323             : 
    1324             : #ifdef LIBO_INTERNAL_ONLY
    1325             :     // This is to complement the RTL_FAST_STRING operator+, which allows any combination of valid operands,
    1326             :     // even two buffers. It's intentional it returns OUString, just like the operator+ would in the fast variant.
    1327             : #ifndef RTL_FAST_STRING
    1328             :     /**
    1329             :      @internal
    1330             :      @since LibreOffice 4.1
    1331             :     */
    1332             :     friend OUString operator+( const OUStringBuffer& str1, const OUStringBuffer& str2  ) SAL_THROW(())
    1333             :     {
    1334             :         return OUString( str1.pData ).concat( str2.pData );
    1335             :     }
    1336             : #endif
    1337             : #endif
    1338             : 
    1339             : private:
    1340         406 :     OUStringBuffer( rtl_uString * value, const sal_Int32 capacity )
    1341             :     {
    1342         406 :         pData = value;
    1343         406 :         nCapacity = capacity;
    1344         406 :     }
    1345             : 
    1346             :     /**
    1347             :         A pointer to the data structur which contains the data.
    1348             :      */
    1349             :     rtl_uString * pData;
    1350             : 
    1351             :     /**
    1352             :         The len of the pData->buffer.
    1353             :      */
    1354             :     sal_Int32       nCapacity;
    1355             : };
    1356             : 
    1357             : #ifdef RTL_FAST_STRING
    1358             : /**
    1359             :  @internal
    1360             : */
    1361             : template<>
    1362             : struct ToStringHelper< OUStringBuffer >
    1363             :     {
    1364           1 :     static int length( const OUStringBuffer& s ) { return s.getLength(); }
    1365           1 :     static sal_Unicode* addData( sal_Unicode* buffer, const OUStringBuffer& s ) { return addDataHelper( buffer, s.getStr(), s.getLength()); }
    1366             :     static const bool allowOStringConcat = false;
    1367             :     static const bool allowOUStringConcat = true;
    1368             :     };
    1369             : #endif
    1370             : 
    1371             : }
    1372             : 
    1373             : #ifdef RTL_STRING_UNITTEST
    1374             : namespace rtl
    1375             : {
    1376             : typedef rtlunittest::OUStringBuffer OUStringBuffer;
    1377             : }
    1378             : #endif
    1379             : 
    1380             : #ifdef RTL_USING
    1381             : using ::rtl::OUStringBuffer;
    1382             : #endif
    1383             : 
    1384             : #endif  /* _RTL_USTRBUF_HXX_ */
    1385             : 
    1386             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10