LCOV - code coverage report
Current view: top level - include/rtl - strbuf.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 127 132 96.2 %
Date: 2015-06-13 12:38:46 Functions: 120 179 67.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #ifndef INCLUDED_RTL_STRBUF_HXX
      21             : #define INCLUDED_RTL_STRBUF_HXX
      22             : 
      23             : #include <sal/config.h>
      24             : 
      25             : #include <cassert>
      26             : #include <string.h>
      27             : 
      28             : #include <rtl/strbuf.h>
      29             : #include <rtl/string.hxx>
      30             : #include <rtl/stringutils.hxx>
      31             : 
      32             : #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
      33             : #include <rtl/stringconcat.hxx>
      34             : #endif
      35             : 
      36             : // The unittest uses slightly different code to help check that the proper
      37             : // calls are made. The class is put into a different namespace to make
      38             : // sure the compiler generates a different (if generating also non-inline)
      39             : // copy of the function and does not merge them together. The class
      40             : // is "brought" into the proper rtl namespace by a typedef below.
      41             : #ifdef RTL_STRING_UNITTEST
      42             : #define rtl rtlunittest
      43             : #endif
      44             : 
      45             : namespace rtl
      46             : {
      47             : 
      48             : /// @cond INTERNAL
      49             : #ifdef RTL_STRING_UNITTEST
      50             : #undef rtl
      51             : // helper macro to make functions appear more readable
      52             : #define RTL_STRING_CONST_FUNCTION rtl_string_unittest_const_literal_function = true;
      53             : #else
      54             : #define RTL_STRING_CONST_FUNCTION
      55             : #endif
      56             : /// @endcond
      57             : 
      58             : /** A string buffer implements a mutable sequence of characters.
      59             :  */
      60             : class SAL_WARN_UNUSED OStringBuffer
      61             : {
      62             : public:
      63             :     /**
      64             :         Constructs a string buffer with no characters in it and an
      65             :         initial capacity of 16 characters.
      66             :      */
      67     1139335 :     OStringBuffer()
      68             :         : pData(NULL)
      69     1139335 :         , nCapacity( 16 )
      70             :     {
      71     1139335 :         rtl_string_new_WithLength( &pData, nCapacity );
      72     1139335 :     }
      73             : 
      74             :     /**
      75             :         Allocates a new string buffer that contains the same sequence of
      76             :         characters as the string buffer argument.
      77             : 
      78             :         @param   value   a <code>OStringBuffer</code>.
      79             :      */
      80       14053 :     OStringBuffer( const OStringBuffer & value )
      81             :         : pData(NULL)
      82       14053 :         , nCapacity( value.nCapacity )
      83             :     {
      84       14053 :         rtl_stringbuffer_newFromStringBuffer( &pData, value.nCapacity, value.pData );
      85       14053 :     }
      86             : 
      87             :     /**
      88             :         Constructs a string buffer with no characters in it and an
      89             :         initial capacity specified by the <code>length</code> argument.
      90             : 
      91             :         @param      length   the initial capacity.
      92             :      */
      93     1149494 :     explicit OStringBuffer(int length)
      94             :         : pData(NULL)
      95     1149494 :         , nCapacity( length )
      96             :     {
      97     1149494 :         rtl_string_new_WithLength( &pData, length );
      98     1149494 :     }
      99             : #if __cplusplus >= 201103L
     100       37877 :     explicit OStringBuffer(unsigned int length)
     101       37877 :         : OStringBuffer(static_cast<int>(length))
     102             :     {
     103       37877 :     }
     104             : #if SAL_TYPES_SIZEOFLONG == 4
     105             :     // additional overloads for sal_Int32 sal_uInt32
     106             :     explicit OStringBuffer(long length)
     107             :         : OStringBuffer(static_cast<int>(length))
     108             :     {
     109             :     }
     110             :     explicit OStringBuffer(unsigned long length)
     111             :         : OStringBuffer(static_cast<int>(length))
     112             :     {
     113             :     }
     114             : #endif
     115             :     // avoid obvious bugs
     116             :     explicit OStringBuffer(char) = delete;
     117             :     explicit OStringBuffer(sal_Unicode) = delete;
     118             : #endif
     119             : 
     120             :     /**
     121             :         Constructs a string buffer so that it represents the same
     122             :         sequence of characters as the string argument.
     123             : 
     124             :         The initial
     125             :         capacity of the string buffer is <code>16</code> plus the length
     126             :         of the string argument.
     127             : 
     128             :         @param   value   the initial string value.
     129             :      */
     130       55218 :     OStringBuffer(const OString& value)
     131             :         : pData(NULL)
     132       55218 :         , nCapacity( value.getLength() + 16 )
     133             :     {
     134       55218 :         rtl_stringbuffer_newFromStr_WithLength( &pData, value.getStr(), value.getLength() );
     135       55218 :     }
     136             : 
     137             :     /**
     138             :         @overload
     139             :         @since LibreOffice 3.6
     140             :      */
     141             :     template< typename T >
     142           8 :     OStringBuffer( const T& value, typename libreoffice_internal::CharPtrDetector< T, libreoffice_internal::Dummy >::Type = libreoffice_internal::Dummy())
     143           8 :         : pData(NULL)
     144             :     {
     145           8 :         sal_Int32 length = rtl_str_getLength( value );
     146           8 :         nCapacity = length + 16;
     147           8 :         rtl_stringbuffer_newFromStr_WithLength( &pData, value, length );
     148           8 :     }
     149             : 
     150             :     template< typename T >
     151           3 :     OStringBuffer( T& value, typename libreoffice_internal::NonConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type = libreoffice_internal::Dummy())
     152           3 :         : pData(NULL)
     153             :     {
     154           3 :         sal_Int32 length = rtl_str_getLength( value );
     155           3 :         nCapacity = length + 16;
     156           3 :         rtl_stringbuffer_newFromStr_WithLength( &pData, value, length );
     157           3 :     }
     158             : 
     159             :     /**
     160             :       Constructs a string buffer so that it represents the same
     161             :         sequence of characters as the string literal.
     162             : 
     163             :       If there are any embedded \0's in the string literal, the result is undefined.
     164             :       Use the overload that explicitly accepts length.
     165             : 
     166             :       @since LibreOffice 3.6
     167             : 
     168             :       @param    literal       a string literal
     169             :     */
     170             :     template< typename T >
     171       47243 :     OStringBuffer( T& literal, typename libreoffice_internal::ConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type = libreoffice_internal::Dummy())
     172             :         : pData(NULL)
     173       47243 :         , nCapacity( libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 + 16 )
     174             :     {
     175             :         assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
     176       47243 :         rtl_string_newFromLiteral( &pData, literal, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1, 16 );
     177             : #ifdef RTL_STRING_UNITTEST
     178           3 :         rtl_string_unittest_const_literal = true;
     179             : #endif
     180       47243 :     }
     181             : 
     182             :     /**
     183             :         Constructs a string buffer so that it represents the same
     184             :         sequence of characters as the string argument.
     185             : 
     186             :         The initial
     187             :         capacity of the string buffer is <code>16</code> plus length
     188             : 
     189             :         @param    value       a character array.
     190             :         @param    length      the number of character which should be copied.
     191             :                               The character array length must be greater or
     192             :                               equal than this value.
     193             :      */
     194           1 :     OStringBuffer(const sal_Char * value, sal_Int32 length)
     195             :         : pData(NULL)
     196           1 :         , nCapacity( length + 16 )
     197             :     {
     198           1 :         rtl_stringbuffer_newFromStr_WithLength( &pData, value, length );
     199           1 :     }
     200             : 
     201             : #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
     202             :     /**
     203             :      @overload
     204             :      @internal
     205             :     */
     206             :     template< typename T1, typename T2 >
     207             :     OStringBuffer( const OStringConcat< T1, T2 >& c )
     208             :     {
     209             :         const sal_Int32 l = c.length();
     210             :         nCapacity = l + 16;
     211             :         pData = rtl_string_alloc( nCapacity );
     212             :         char* end = c.addData( pData->buffer );
     213             :         *end = '\0';
     214             :         pData->length = end - pData->buffer;
     215             :     }
     216             : #endif
     217             : 
     218             :     /** Assign to this a copy of value.
     219             :      */
     220         227 :     OStringBuffer& operator = ( const OStringBuffer& value )
     221             :     {
     222         227 :         if (this != &value)
     223             :         {
     224             :             rtl_stringbuffer_newFromStringBuffer(&pData,
     225             :                                                   value.nCapacity,
     226         227 :                                                   value.pData);
     227         227 :             nCapacity = value.nCapacity;
     228             :         }
     229         227 :         return *this;
     230             :     }
     231             : 
     232             :     /**
     233             :         Release the string data.
     234             :      */
     235     2405355 :     ~OStringBuffer()
     236             :     {
     237     2405355 :         rtl_string_release( pData );
     238     2405355 :     }
     239             : 
     240             :     /**
     241             :         Fill the string data in the new string and clear the buffer.
     242             : 
     243             :         This method is more efficient than the constructor of the string. It does
     244             :         not copy the buffer.
     245             : 
     246             :         @return the string previously contained in the buffer.
     247             :      */
     248     2003590 :     OString makeStringAndClear()
     249             :     {
     250     2003590 :         OString aRet( pData );
     251     2003590 :         rtl_string_new(&pData);
     252     2003590 :         nCapacity = 0;
     253     2003590 :         return aRet;
     254             :     }
     255             : 
     256             :     /**
     257             :         Returns the length (character count) of this string buffer.
     258             : 
     259             :         @return  the number of characters in this string buffer.
     260             :      */
     261    30474299 :     sal_Int32 getLength() const
     262             :     {
     263    30474299 :         return pData->length;
     264             :     }
     265             : 
     266             :     /**
     267             :       Checks if a string buffer is empty.
     268             : 
     269             :       @return   true if the string buffer is empty;
     270             :                 false, otherwise.
     271             : 
     272             :       @since LibreOffice 4.1
     273             :     */
     274    25467342 :     bool isEmpty() const
     275             :     {
     276    25467342 :         return pData->length == 0;
     277             :     }
     278             : 
     279             :     /**
     280             :         Returns the current capacity of the String buffer.
     281             : 
     282             :         The capacity
     283             :         is the amount of storage available for newly inserted
     284             :         characters. The real buffer size is 2 bytes longer, because
     285             :         all strings are 0 terminated.
     286             : 
     287             :         @return  the current capacity of this string buffer.
     288             :      */
     289          66 :     sal_Int32 getCapacity() const
     290             :     {
     291          66 :         return nCapacity;
     292             :     }
     293             : 
     294             :     /**
     295             :         Ensures that the capacity of the buffer is at least equal to the
     296             :         specified minimum.
     297             : 
     298             :         The new capacity will be at least as large as the maximum of the current
     299             :         length (so that no contents of the buffer is destroyed) and the given
     300             :         minimumCapacity.  If the given minimumCapacity is negative, nothing is
     301             :         changed.
     302             : 
     303             :         @param   minimumCapacity   the minimum desired capacity.
     304             :      */
     305         924 :     void ensureCapacity(sal_Int32 minimumCapacity)
     306             :     {
     307         924 :         rtl_stringbuffer_ensureCapacity( &pData, &nCapacity, minimumCapacity );
     308         924 :     }
     309             : 
     310             :     /**
     311             :         Sets the length of this String buffer.
     312             : 
     313             :         If the <code>newLength</code> argument is less than the current
     314             :         length of the string buffer, the string buffer is truncated to
     315             :         contain exactly the number of characters given by the
     316             :         <code>newLength</code> argument.
     317             :         <p>
     318             :         If the <code>newLength</code> argument is greater than or equal
     319             :         to the current length, sufficient null characters
     320             :         (<code>'&#92;u0000'</code>) are appended to the string buffer so that
     321             :         length becomes the <code>newLength</code> argument.
     322             :         <p>
     323             :         The <code>newLength</code> argument must be greater than or equal
     324             :         to <code>0</code>.
     325             : 
     326             :         @param      newLength   the new length of the buffer.
     327             :      */
     328    24770452 :     void setLength(sal_Int32 newLength)
     329             :     {
     330             :         assert(newLength >= 0);
     331             :         // Avoid modifications if pData points to const empty string:
     332    24770452 :         if( newLength != pData->length )
     333             :         {
     334       67643 :             if( newLength > nCapacity )
     335       37203 :                 rtl_stringbuffer_ensureCapacity(&pData, &nCapacity, newLength);
     336             :             else
     337       30440 :                 pData->buffer[newLength] = '\0';
     338       67643 :             pData->length = newLength;
     339             :         }
     340    24770452 :     }
     341             : 
     342             :     /**
     343             :         Returns the character at a specific index in this string buffer.
     344             : 
     345             :         The first character of a string buffer is at index
     346             :         <code>0</code>, the next at index <code>1</code>, and so on, for
     347             :         array indexing.
     348             :         <p>
     349             :         The index argument must be greater than or equal to
     350             :         <code>0</code>, and less than the length of this string buffer.
     351             : 
     352             :         @param      index   the index of the desired character.
     353             :         @return     the character at the specified index of this string buffer.
     354             :     */
     355             :     SAL_DEPRECATED("use rtl::OStringBuffer::operator [] instead")
     356             :     sal_Char charAt( sal_Int32 index )
     357             :     {
     358             :         assert(index >= 0 && index < pData->length);
     359             :         return pData->buffer[ index ];
     360             :     }
     361             : 
     362             :     /**
     363             :         The character at the specified index of this string buffer is set
     364             :         to <code>ch</code>.
     365             : 
     366             :         The index argument must be greater than or equal to
     367             :         <code>0</code>, and less than the length of this string buffer.
     368             : 
     369             :         @param      index   the index of the character to modify.
     370             :         @param      ch      the new character.
     371             :      */
     372             :     SAL_DEPRECATED("use rtl::OStringBuffer::operator [] instead")
     373             :     OStringBuffer & setCharAt(sal_Int32 index, sal_Char ch)
     374             :     {
     375             :         assert(index >= 0 && index < pData->length);
     376             :         pData->buffer[ index ] = ch;
     377             :         return *this;
     378             :     }
     379             : 
     380             :     /**
     381             :         Return a null terminated character array.
     382             :      */
     383      825777 :     const sal_Char* getStr() const { return pData->buffer; }
     384             : 
     385             :     /**
     386             :       Access to individual characters.
     387             : 
     388             :       @param index must be non-negative and less than length.
     389             : 
     390             :       @return a reference to the character at the given index.
     391             : 
     392             :       @since LibreOffice 3.5
     393             :     */
     394     4619497 :     sal_Char & operator [](sal_Int32 index)
     395             :     {
     396             :         assert(index >= 0 && index < pData->length);
     397     4619497 :         return pData->buffer[index];
     398             :     }
     399             : 
     400             :     /**
     401             :         Return a OString instance reflecting the current content
     402             :         of this OStringBuffer.
     403             :      */
     404        1458 :     const OString toString() const
     405             :     {
     406        1458 :         return OString(pData->buffer, pData->length);
     407             :     }
     408             : 
     409             :     /**
     410             :         Appends the string to this string buffer.
     411             : 
     412             :         The characters of the <code>String</code> argument are appended, in
     413             :         order, to the contents of this string buffer, increasing the
     414             :         length of this string buffer by the length of the argument.
     415             : 
     416             :         @param   str   a string.
     417             :         @return  this string buffer.
     418             :      */
     419     1057539 :     OStringBuffer & append(const OString &str)
     420             :     {
     421     1057539 :         return append( str.getStr(), str.getLength() );
     422             :     }
     423             : 
     424             :     /**
     425             :         Appends the string representation of the <code>char</code> array
     426             :         argument to this string buffer.
     427             : 
     428             :         The characters of the array argument are appended, in order, to
     429             :         the contents of this string buffer. The length of this string
     430             :         buffer increases by the length of the argument.
     431             : 
     432             :         @param   str   the characters to be appended.
     433             :         @return  this string buffer.
     434             :      */
     435             :     template< typename T >
     436      343968 :     typename libreoffice_internal::CharPtrDetector< T, OStringBuffer& >::Type append( const T& str )
     437             :     {
     438      343968 :         return append( str, rtl_str_getLength( str ) );
     439             :     }
     440             : 
     441             :     template< typename T >
     442       28998 :     typename libreoffice_internal::NonConstCharArrayDetector< T, OStringBuffer& >::Type append( T& str )
     443             :     {
     444       28998 :         return append( str, rtl_str_getLength( str ) );
     445             :     }
     446             : 
     447             :     /**
     448             :      @overload
     449             :      This function accepts an ASCII string literal as its argument.
     450             :      @since LibreOffice 3.6
     451             :     */
     452             :     template< typename T >
     453      151241 :     typename libreoffice_internal::ConstCharArrayDetector< T, OStringBuffer& >::Type append( T& literal )
     454             :     {
     455           2 :         RTL_STRING_CONST_FUNCTION
     456             :         assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
     457      151241 :         rtl_stringbuffer_insert( &pData, &nCapacity, getLength(), literal, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 );
     458      151241 :         return *this;
     459             :     }
     460             : 
     461             :     /**
     462             :         Appends the string representation of the <code>char</code> array
     463             :         argument to this string buffer.
     464             : 
     465             :         Characters of the character array <code>str</code> are appended,
     466             :         in order, to the contents of this string buffer. The length of this
     467             :         string buffer increases by the value of <code>len</code>.
     468             : 
     469             :         @param str the characters to be appended; must be non-null, and must
     470             :         point to at least len characters
     471             :         @param len the number of characters to append; must be non-negative
     472             :         @return  this string buffer.
     473             :      */
     474    26566523 :     OStringBuffer & append( const sal_Char * str, sal_Int32 len)
     475             :     {
     476             :         assert( len == 0 || str != 0 ); // cannot assert that in rtl_stringbuffer_insert
     477    26566523 :         rtl_stringbuffer_insert( &pData, &nCapacity, getLength(), str, len );
     478    26566523 :         return *this;
     479             :     }
     480             : 
     481             : #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
     482             :     /**
     483             :      @overload
     484             :      @internal
     485             :     */
     486             :     template< typename T1, typename T2 >
     487      370331 :     OStringBuffer& append( const OStringConcat< T1, T2 >& c )
     488             :     {
     489      370331 :         const int l = c.length();
     490      370331 :         if( l == 0 )
     491           0 :             return *this;
     492      370331 :         rtl_stringbuffer_ensureCapacity( &pData, &nCapacity, pData->length + l );
     493      370331 :         char* end = c.addData( pData->buffer + pData->length );
     494      370331 :         *end = '\0';
     495      370331 :         pData->length = end - pData->buffer;
     496      370331 :         return *this;
     497             :     }
     498             : #endif
     499             : 
     500             :     /**
     501             :         Appends the string representation of the <code>sal_Bool</code>
     502             :         argument to the string buffer.
     503             : 
     504             :         The argument is converted to a string as if by the method
     505             :         <code>String.valueOf</code>, and the characters of that
     506             :         string are then appended to this string buffer.
     507             : 
     508             :         @param   b   a <code>sal_Bool</code>.
     509             :         @return  this string buffer.
     510             :      */
     511           0 :     OStringBuffer & append(sal_Bool b)
     512             :     {
     513             :         sal_Char sz[RTL_STR_MAX_VALUEOFBOOLEAN];
     514           0 :         return append( sz, rtl_str_valueOfBoolean( sz, b ) );
     515             :     }
     516             : 
     517             :     /**
     518             :         Appends the string representation of the <code>bool</code>
     519             :         argument to the string buffer.
     520             : 
     521             :         The argument is converted to a string as if by the method
     522             :         <code>String.valueOf</code>, and the characters of that
     523             :         string are then appended to this string buffer.
     524             : 
     525             :         @param   b   a <code>bool</code>.
     526             :         @return  this string buffer.
     527             : 
     528             :         @since LibreOffice 4.3
     529             :      */
     530          19 :     OStringBuffer & append(bool b)
     531             :     {
     532             :         sal_Char sz[RTL_STR_MAX_VALUEOFBOOLEAN];
     533          19 :         return append( sz, rtl_str_valueOfBoolean( sz, b ) );
     534             :     }
     535             : 
     536             :     /// @cond INTERNAL
     537             :     // Pointer can be automatically converted to bool, which is unwanted here.
     538             :     // Explicitly delete all pointer append() overloads to prevent this
     539             :     // (except for char* overload, which is handled elsewhere).
     540             :     template< typename T >
     541             :     typename libreoffice_internal::Enable< void,
     542             :         !libreoffice_internal::CharPtrDetector< T* >::ok >::Type
     543             :         append( T* ) SAL_DELETED_FUNCTION;
     544             :     /// @endcond
     545             : 
     546             :     /**
     547             :         Appends the string representation of the <code>char</code>
     548             :         argument to this string buffer.
     549             : 
     550             :         The argument is appended to the contents of this string buffer.
     551             :         The length of this string buffer increases by <code>1</code>.
     552             : 
     553             :         @param   c   a <code>char</code>.
     554             :         @return  this string buffer.
     555             :      */
     556    23688793 :     OStringBuffer & append(sal_Char c)
     557             :     {
     558    23688793 :         return append( &c, 1 );
     559             :     }
     560             : 
     561             :     /**
     562             :         Appends the string representation of the <code>sal_Int32</code>
     563             :         argument to this 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   i   an <code>sal_Int32</code>.
     570             :         @param radix the radix
     571             :         @return  this string buffer.
     572             :      */
     573      391271 :     OStringBuffer & append(sal_Int32 i, sal_Int16 radix = 10 )
     574             :     {
     575             :         sal_Char sz[RTL_STR_MAX_VALUEOFINT32];
     576      391271 :         return append( sz, rtl_str_valueOfInt32( sz, i, radix ) );
     577             :     }
     578             : 
     579             :     /**
     580             :         Appends the string representation of the <code>long</code>
     581             :         argument to this string buffer.
     582             : 
     583             :         The argument is converted to a string as if by the method
     584             :         <code>String.valueOf</code>, and the characters of that
     585             :         string are then appended to this string buffer.
     586             : 
     587             :         @param   l   a <code>long</code>.
     588             :         @param radix the radix
     589             :         @return  this string buffer.
     590             :      */
     591        3936 :     OStringBuffer & append(sal_Int64 l, sal_Int16 radix = 10 )
     592             :     {
     593             :         sal_Char sz[RTL_STR_MAX_VALUEOFINT64];
     594        3936 :         return append( sz, rtl_str_valueOfInt64( sz, l, radix ) );
     595             :     }
     596             : 
     597             :     /**
     598             :         Appends the string representation of the <code>float</code>
     599             :         argument to this string buffer.
     600             : 
     601             :         The argument is converted to a string as if by the method
     602             :         <code>String.valueOf</code>, and the characters of that
     603             :         string are then appended to this string buffer.
     604             : 
     605             :         @param   f   a <code>float</code>.
     606             :         @return  this string buffer.
     607             :      */
     608          50 :     OStringBuffer & append(float f)
     609             :     {
     610             :         sal_Char sz[RTL_STR_MAX_VALUEOFFLOAT];
     611          50 :         return append( sz, rtl_str_valueOfFloat( sz, f ) );
     612             :     }
     613             : 
     614             :     /**
     615             :         Appends the string representation of the <code>double</code>
     616             :         argument to this string buffer.
     617             : 
     618             :         The argument is converted to a string as if by the method
     619             :         <code>String.valueOf</code>, and the characters of that
     620             :         string are then appended to this string buffer.
     621             : 
     622             :         @param   d   a <code>double</code>.
     623             :         @return  this string buffer.
     624             :      */
     625        3020 :     OStringBuffer & append(double d)
     626             :     {
     627             :         sal_Char sz[RTL_STR_MAX_VALUEOFDOUBLE];
     628        3020 :         return append( sz, rtl_str_valueOfDouble( sz, d ) );
     629             :     }
     630             : 
     631             :     /**
     632             :        Unsafe way to make space for a fixed amount of characters to be appended
     633             :        into this OStringBuffer.
     634             : 
     635             :        A call to this function must immediately be followed by code that
     636             :        completely fills the uninitialized block pointed to by the return value.
     637             : 
     638             :        @param length the length of the uninitialized block of char entities;
     639             :        must be non-negative
     640             : 
     641             :        @return a pointer to the start of the uninitialized block; only valid
     642             :        until this OStringBuffer's capacity changes
     643             : 
     644             :        @since LibreOffice 4.4
     645             :     */
     646           3 :     char * appendUninitialized(sal_Int32 length) {
     647           3 :         sal_Int32 n = getLength();
     648           3 :         rtl_stringbuffer_insert(&pData, &nCapacity, n, 0, length);
     649           3 :         return pData->buffer + n;
     650             :     }
     651             : 
     652             :     /**
     653             :         Inserts the string into this string buffer.
     654             : 
     655             :         The characters of the <code>String</code> argument are inserted, in
     656             :         order, into this string buffer at the indicated offset. The length
     657             :         of this string buffer is increased by the length of the argument.
     658             :         <p>
     659             :         The offset argument must be greater than or equal to
     660             :         <code>0</code>, and less than or equal to the length of this
     661             :         string buffer.
     662             : 
     663             :         @param      offset   the offset.
     664             :         @param      str      a string.
     665             :         @return     this string buffer.
     666             :      */
     667         488 :     OStringBuffer & insert(sal_Int32 offset, const OString & str)
     668             :     {
     669         488 :         return insert( offset, str.getStr(), str.getLength() );
     670             :     }
     671             : 
     672             :     /**
     673             :         Inserts the string representation of the <code>char</code> array
     674             :         argument into this string buffer.
     675             : 
     676             :         The characters of the array argument are inserted into the
     677             :         contents of this string buffer at the position indicated by
     678             :         <code>offset</code>. The length of this string buffer increases by
     679             :         the length of the argument.
     680             :         <p>
     681             :         The offset argument must be greater than or equal to
     682             :         <code>0</code>, and less than or equal to the length of this
     683             :         string buffer.
     684             : 
     685             :         @param      offset   the offset.
     686             :         @param      str      a character array.
     687             :         @return     this string buffer.
     688             :      */
     689             :     template< typename T >
     690             :     typename libreoffice_internal::CharPtrDetector< T, OStringBuffer& >::Type insert( sal_Int32 offset, const T& str )
     691             :     {
     692             :         return insert( offset, str, rtl_str_getLength( str ) );
     693             :     }
     694             : 
     695             :     template< typename T >
     696           1 :     typename libreoffice_internal::NonConstCharArrayDetector< T, OStringBuffer& >::Type insert( sal_Int32 offset, T& str )
     697             :     {
     698           1 :         return insert( offset, str, rtl_str_getLength( str ) );
     699             :     }
     700             : 
     701             :     /**
     702             :      @overload
     703             :      This function accepts an ASCII string literal as its argument.
     704             :      @since LibreOffice 3.6
     705             :     */
     706             :     template< typename T >
     707           1 :     typename libreoffice_internal::ConstCharArrayDetector< T, OStringBuffer& >::Type insert( sal_Int32 offset, T& literal )
     708             :     {
     709           1 :         RTL_STRING_CONST_FUNCTION
     710             :         assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
     711           1 :         rtl_stringbuffer_insert( &pData, &nCapacity, offset, literal, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 );
     712           1 :         return *this;
     713             :     }
     714             : 
     715             :     /**
     716             :         Inserts the string representation of the <code>char</code> array
     717             :         argument into this string buffer.
     718             : 
     719             :         The characters of the array argument are inserted into the
     720             :         contents of this string buffer at the position indicated by
     721             :         <code>offset</code>. The length of this string buffer increases by
     722             :         the length of the argument.
     723             :         <p>
     724             :         The offset argument must be greater than or equal to
     725             :         <code>0</code>, and less than or equal to the length of this
     726             :         string buffer.
     727             : 
     728             :         @param      offset   the offset.
     729             :         @param      str      a character array.
     730             :         @param      len      the number of characters to append.
     731             :         @return     this string buffer.
     732             :      */
     733       73885 :     OStringBuffer & insert( sal_Int32 offset, const sal_Char * str, sal_Int32 len)
     734             :     {
     735             :         assert( len == 0 || str != 0 ); // cannot assert that in rtl_stringbuffer_insert
     736       73885 :         rtl_stringbuffer_insert( &pData, &nCapacity, offset, str, len );
     737       73885 :         return *this;
     738             :     }
     739             : 
     740             :     /**
     741             :         Inserts the string representation of the <code>sal_Bool</code>
     742             :         argument into this string buffer.
     743             : 
     744             :         The second argument is converted to a string as if by the method
     745             :         <code>String.valueOf</code>, and the characters of that
     746             :         string are then inserted into this string buffer at the indicated
     747             :         offset.
     748             :         <p>
     749             :         The offset argument must be greater than or equal to
     750             :         <code>0</code>, and less than or equal to the length of this
     751             :         string buffer.
     752             : 
     753             :         @param      offset   the offset.
     754             :         @param      b        a <code>sal_Bool</code>.
     755             :         @return     this string buffer.
     756             :      */
     757             :     OStringBuffer & insert(sal_Int32 offset, sal_Bool b)
     758             :     {
     759             :         sal_Char sz[RTL_STR_MAX_VALUEOFBOOLEAN];
     760             :         return insert( offset, sz, rtl_str_valueOfBoolean( sz, b ) );
     761             :     }
     762             : 
     763             :     /**
     764             :         Inserts the string representation of the <code>bool</code>
     765             :         argument into this string buffer.
     766             : 
     767             :         The second argument is converted to a string as if by the method
     768             :         <code>OString::boolean</code>, and the characters of that
     769             :         string are then inserted into this string buffer at the indicated
     770             :         offset.
     771             :         <p>
     772             :         The offset argument must be greater than or equal to
     773             :         <code>0</code>, and less than or equal to the length of this
     774             :         string buffer.
     775             : 
     776             :         @param      offset   the offset.
     777             :         @param      b        a <code>bool</code>.
     778             :         @return     this string buffer.
     779             : 
     780             :         @since LibreOffice 4.3
     781             :      */
     782             :     OStringBuffer & insert(sal_Int32 offset, bool b)
     783             :     {
     784             :         sal_Char sz[RTL_STR_MAX_VALUEOFBOOLEAN];
     785             :         return insert( offset, sz, rtl_str_valueOfBoolean( sz, b ) );
     786             :     }
     787             : 
     788             :     /**
     789             :         Inserts the string representation of the <code>char</code>
     790             :         argument into this string buffer.
     791             : 
     792             :         The second argument is inserted into the contents of this string
     793             :         buffer at the position indicated by <code>offset</code>. The length
     794             :         of this string buffer increases by one.
     795             :         <p>
     796             :         The offset argument must be greater than or equal to
     797             :         <code>0</code>, and less than or equal to the length of this
     798             :         string buffer.
     799             : 
     800             :         @param      offset   the offset.
     801             :         @param      c        a <code>char</code>.
     802             :         @return     this string buffer.
     803             :      */
     804           0 :     OStringBuffer & insert(sal_Int32 offset, sal_Char c)
     805             :     {
     806           0 :         return insert( offset, &c, 1 );
     807             :     }
     808             : 
     809             :     /**
     810             :         Inserts the string representation of the second <code>sal_Int32</code>
     811             :         argument into this string buffer.
     812             : 
     813             :         The second argument is converted to a string as if by the method
     814             :         <code>String.valueOf</code>, and the characters of that
     815             :         string are then inserted into this string buffer at the indicated
     816             :         offset.
     817             :         <p>
     818             :         The offset argument must be greater than or equal to
     819             :         <code>0</code>, and less than or equal to the length of this
     820             :         string buffer.
     821             : 
     822             :         @param      offset   the offset.
     823             :         @param      i        an <code>sal_Int32</code>.
     824             :         @param      radix the radix
     825             :         @return     this string buffer.
     826             :      */
     827             :     OStringBuffer & insert(sal_Int32 offset, sal_Int32 i, sal_Int16 radix = 10 )
     828             :     {
     829             :         sal_Char sz[RTL_STR_MAX_VALUEOFINT32];
     830             :         return insert( offset, sz, rtl_str_valueOfInt32( sz, i, radix ) );
     831             :     }
     832             : 
     833             :     /**
     834             :         Inserts the string representation of the <code>long</code>
     835             :         argument into this string buffer.
     836             : 
     837             :         The second argument is converted to a string as if by the method
     838             :         <code>String.valueOf</code>, and the characters of that
     839             :         string are then inserted into this string buffer at the indicated
     840             :         offset.
     841             :         <p>
     842             :         The offset argument must be greater than or equal to
     843             :         <code>0</code>, and less than or equal to the length of this
     844             :         string buffer.
     845             : 
     846             :         @param      offset   the offset.
     847             :         @param      l        a <code>long</code>.
     848             :         @param      radix the radix
     849             :         @return     this string buffer.
     850             :      */
     851             :     OStringBuffer & insert(sal_Int32 offset, sal_Int64 l, sal_Int16 radix = 10 )
     852             :     {
     853             :         sal_Char sz[RTL_STR_MAX_VALUEOFINT64];
     854             :         return insert( offset, sz, rtl_str_valueOfInt64( sz, l, radix ) );
     855             :     }
     856             : 
     857             :     /**
     858             :         Inserts the string representation of the <code>float</code>
     859             :         argument into this string buffer.
     860             : 
     861             :         The second argument is converted to a string as if by the method
     862             :         <code>String.valueOf</code>, and the characters of that
     863             :         string are then inserted into this string buffer at the indicated
     864             :         offset.
     865             :         <p>
     866             :         The offset argument must be greater than or equal to
     867             :         <code>0</code>, and less than or equal to the length of this
     868             :         string buffer.
     869             : 
     870             :         @param      offset   the offset.
     871             :         @param      f        a <code>float</code>.
     872             :         @return     this string buffer.
     873             :      */
     874             :     OStringBuffer insert(sal_Int32 offset, float f)
     875             :     {
     876             :         sal_Char sz[RTL_STR_MAX_VALUEOFFLOAT];
     877             :         return insert( offset, sz, rtl_str_valueOfFloat( sz, f ) );
     878             :     }
     879             : 
     880             :     /**
     881             :         Inserts the string representation of the <code>double</code>
     882             :         argument into this string buffer.
     883             : 
     884             :         The second argument is converted to a string as if by the method
     885             :         <code>String.valueOf</code>, and the characters of that
     886             :         string are then inserted into this string buffer at the indicated
     887             :         offset.
     888             :         <p>
     889             :         The offset argument must be greater than or equal to
     890             :         <code>0</code>, and less than or equal to the length of this
     891             :         string buffer.
     892             : 
     893             :         @param      offset   the offset.
     894             :         @param      d        a <code>double</code>.
     895             :         @return     this string buffer.
     896             :      */
     897             :     OStringBuffer & insert(sal_Int32 offset, double d)
     898             :     {
     899             :         sal_Char sz[RTL_STR_MAX_VALUEOFDOUBLE];
     900             :         return insert( offset, sz, rtl_str_valueOfDouble( sz, d ) );
     901             :     }
     902             : 
     903             :     /**
     904             :         Removes the characters in a substring of this sequence.
     905             : 
     906             :         The substring begins at the specified <code>start</code> and
     907             :         is <code>len</code> characters long.
     908             : 
     909             :         start must be >= 0 && <= getLength() && <= end
     910             : 
     911             :         @param  start       The beginning index, inclusive
     912             :         @param  len         The substring length
     913             :         @return this string buffer.
     914             :      */
     915        2379 :     OStringBuffer & remove( sal_Int32 start, sal_Int32 len )
     916             :     {
     917        2379 :         rtl_stringbuffer_remove( &pData, start, len );
     918        2379 :         return *this;
     919             :     }
     920             : 
     921             : private:
     922             :     /**
     923             :         A pointer to the data structure which contains the data.
     924             :      */
     925             :     rtl_String * pData;
     926             : 
     927             :     /**
     928             :         The len of the pData->buffer.
     929             :      */
     930             :     sal_Int32       nCapacity;
     931             : };
     932             : 
     933             : #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
     934             : /**
     935             :  @internal
     936             : */
     937             : template<>
     938             : struct ToStringHelper< OStringBuffer >
     939             :     {
     940          41 :     static int length( const OStringBuffer& s ) { return s.getLength(); }
     941          41 :     static char* addData( char* buffer, const OStringBuffer& s ) { return addDataHelper( buffer, s.getStr(), s.getLength()); }
     942             :     static const bool allowOStringConcat = true;
     943             :     static const bool allowOUStringConcat = false;
     944             :     };
     945             : #endif
     946             : 
     947             : 
     948             : }
     949             : 
     950             : #ifdef RTL_STRING_UNITTEST
     951             : namespace rtl
     952             : {
     953             : typedef rtlunittest::OStringBuffer OStringBuffer;
     954             : }
     955             : #undef RTL_STRING_CONST_FUNCTION
     956             : #endif
     957             : 
     958             : #if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST
     959             : using ::rtl::OStringBuffer;
     960             : #endif
     961             : 
     962             : #endif // INCLUDED_RTL_STRBUF_HXX
     963             : 
     964             : 
     965             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11