1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #ifndef _RTL_STRBUF_HXX_ 29*cdf0e10cSrcweir #define _RTL_STRBUF_HXX_ 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "osl/diagnose.h" 32*cdf0e10cSrcweir #include <rtl/strbuf.h> 33*cdf0e10cSrcweir #include <rtl/string.hxx> 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir #ifdef __cplusplus 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir namespace rtl 38*cdf0e10cSrcweir { 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir /** @HTML 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir A string buffer implements a mutable sequence of characters. 43*cdf0e10cSrcweir <p> 44*cdf0e10cSrcweir String buffers are safe for use by multiple threads. The methods 45*cdf0e10cSrcweir are synchronized where necessary so that all the operations on any 46*cdf0e10cSrcweir particular instance behave as if they occur in some serial order. 47*cdf0e10cSrcweir <p> 48*cdf0e10cSrcweir String buffers are used by the compiler to implement the binary 49*cdf0e10cSrcweir string concatenation operator <code>+</code>. For example, the code: 50*cdf0e10cSrcweir <p><blockquote><pre> 51*cdf0e10cSrcweir x = "a" + 4 + "c" 52*cdf0e10cSrcweir </pre></blockquote><p> 53*cdf0e10cSrcweir is compiled to the equivalent of: 54*cdf0e10cSrcweir <p><blockquote><pre> 55*cdf0e10cSrcweir x = new OStringBuffer().append("a").append(4).append("c") 56*cdf0e10cSrcweir .toString() 57*cdf0e10cSrcweir </pre></blockquote><p> 58*cdf0e10cSrcweir The principal operations on a <code>OStringBuffer</code> are the 59*cdf0e10cSrcweir <code>append</code> and <code>insert</code> methods, which are 60*cdf0e10cSrcweir overloaded so as to accept data of any type. Each effectively 61*cdf0e10cSrcweir converts a given datum to a string and then appends or inserts the 62*cdf0e10cSrcweir characters of that string to the string buffer. The 63*cdf0e10cSrcweir <code>append</code> method always adds these characters at the end 64*cdf0e10cSrcweir of the buffer; the <code>insert</code> method adds the characters at 65*cdf0e10cSrcweir a specified point. 66*cdf0e10cSrcweir <p> 67*cdf0e10cSrcweir For example, if <code>z</code> refers to a string buffer object 68*cdf0e10cSrcweir whose current contents are "<code>start</code>", then 69*cdf0e10cSrcweir the method call <code>z.append("le")</code> would cause the string 70*cdf0e10cSrcweir buffer to contain "<code>startle</code>", whereas 71*cdf0e10cSrcweir <code>z.insert(4, "le")</code> would alter the string buffer to 72*cdf0e10cSrcweir contain "<code>starlet</code>". 73*cdf0e10cSrcweir <p> 74*cdf0e10cSrcweir Every string buffer has a capacity. As long as the length of the 75*cdf0e10cSrcweir character sequence contained in the string buffer does not exceed 76*cdf0e10cSrcweir the capacity, it is not necessary to allocate a new internal 77*cdf0e10cSrcweir buffer array. If the internal buffer overflows, it is 78*cdf0e10cSrcweir automatically made larger. 79*cdf0e10cSrcweir */ 80*cdf0e10cSrcweir class OStringBuffer 81*cdf0e10cSrcweir { 82*cdf0e10cSrcweir public: 83*cdf0e10cSrcweir /** 84*cdf0e10cSrcweir Constructs a string buffer with no characters in it and an 85*cdf0e10cSrcweir initial capacity of 16 characters. 86*cdf0e10cSrcweir */ 87*cdf0e10cSrcweir OStringBuffer() 88*cdf0e10cSrcweir : pData(NULL) 89*cdf0e10cSrcweir , nCapacity( 16 ) 90*cdf0e10cSrcweir { 91*cdf0e10cSrcweir rtl_string_new_WithLength( &pData, nCapacity ); 92*cdf0e10cSrcweir } 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir /** 95*cdf0e10cSrcweir Allocates a new string buffer that contains the same sequence of 96*cdf0e10cSrcweir characters as the string buffer argument. 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir @param value a <code>OStringBuffer</code>. 99*cdf0e10cSrcweir */ 100*cdf0e10cSrcweir OStringBuffer( const OStringBuffer & value ) 101*cdf0e10cSrcweir : pData(NULL) 102*cdf0e10cSrcweir , nCapacity( value.nCapacity ) 103*cdf0e10cSrcweir { 104*cdf0e10cSrcweir rtl_stringbuffer_newFromStringBuffer( &pData, value.nCapacity, value.pData ); 105*cdf0e10cSrcweir } 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir /** 108*cdf0e10cSrcweir Constructs a string buffer with no characters in it and an 109*cdf0e10cSrcweir initial capacity specified by the <code>length</code> argument. 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir @param length the initial capacity. 112*cdf0e10cSrcweir */ 113*cdf0e10cSrcweir OStringBuffer(sal_Int32 length) 114*cdf0e10cSrcweir : pData(NULL) 115*cdf0e10cSrcweir , nCapacity( length ) 116*cdf0e10cSrcweir { 117*cdf0e10cSrcweir rtl_string_new_WithLength( &pData, length ); 118*cdf0e10cSrcweir } 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir /** 121*cdf0e10cSrcweir Constructs a string buffer so that it represents the same 122*cdf0e10cSrcweir sequence of characters as the string argument. 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir The initial 125*cdf0e10cSrcweir capacity of the string buffer is <code>16</code> plus the length 126*cdf0e10cSrcweir of the string argument. 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir @param value the initial string value. 129*cdf0e10cSrcweir */ 130*cdf0e10cSrcweir OStringBuffer(OString value) 131*cdf0e10cSrcweir : pData(NULL) 132*cdf0e10cSrcweir , nCapacity( value.getLength() + 16 ) 133*cdf0e10cSrcweir { 134*cdf0e10cSrcweir rtl_stringbuffer_newFromStr_WithLength( &pData, value.getStr(), value.getLength() ); 135*cdf0e10cSrcweir } 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir /** Assign to this a copy of value. 138*cdf0e10cSrcweir */ 139*cdf0e10cSrcweir OStringBuffer& operator = ( const OStringBuffer& value ) 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir if (this != &value) 142*cdf0e10cSrcweir { 143*cdf0e10cSrcweir rtl_stringbuffer_newFromStringBuffer(&pData, 144*cdf0e10cSrcweir value.nCapacity, 145*cdf0e10cSrcweir value.pData); 146*cdf0e10cSrcweir nCapacity = value.nCapacity; 147*cdf0e10cSrcweir } 148*cdf0e10cSrcweir return *this; 149*cdf0e10cSrcweir } 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir /** 152*cdf0e10cSrcweir Release the string data. 153*cdf0e10cSrcweir */ 154*cdf0e10cSrcweir ~OStringBuffer() 155*cdf0e10cSrcweir { 156*cdf0e10cSrcweir rtl_string_release( pData ); 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir /** 160*cdf0e10cSrcweir Fill the string data in the new string and clear the buffer. 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir This method is more efficient than the contructor of the string. It does 163*cdf0e10cSrcweir not copy the buffer. 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir @return the string previously contained in the buffer. 166*cdf0e10cSrcweir */ 167*cdf0e10cSrcweir OString makeStringAndClear() 168*cdf0e10cSrcweir { 169*cdf0e10cSrcweir OString aRet( pData ); 170*cdf0e10cSrcweir rtl_string_new(&pData); 171*cdf0e10cSrcweir nCapacity = 0; 172*cdf0e10cSrcweir return aRet; 173*cdf0e10cSrcweir } 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir /** 176*cdf0e10cSrcweir Returns the length (character count) of this string buffer. 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir @return the number of characters in this string buffer. 179*cdf0e10cSrcweir */ 180*cdf0e10cSrcweir sal_Int32 getLength() const 181*cdf0e10cSrcweir { 182*cdf0e10cSrcweir return pData->length; 183*cdf0e10cSrcweir } 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir /** 186*cdf0e10cSrcweir Returns the current capacity of the String buffer. 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir The capacity 189*cdf0e10cSrcweir is the amount of storage available for newly inserted 190*cdf0e10cSrcweir characters. The real buffer size is 2 bytes longer, because 191*cdf0e10cSrcweir all strings are 0 terminated. 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir @return the current capacity of this string buffer. 194*cdf0e10cSrcweir */ 195*cdf0e10cSrcweir sal_Int32 getCapacity() const 196*cdf0e10cSrcweir { 197*cdf0e10cSrcweir return nCapacity; 198*cdf0e10cSrcweir } 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir /** 201*cdf0e10cSrcweir Ensures that the capacity of the buffer is at least equal to the 202*cdf0e10cSrcweir specified minimum. 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir The new capacity will be at least as large as the maximum of the current 205*cdf0e10cSrcweir length (so that no contents of the buffer is destroyed) and the given 206*cdf0e10cSrcweir minimumCapacity. If the given minimumCapacity is negative, nothing is 207*cdf0e10cSrcweir changed. 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir @param minimumCapacity the minimum desired capacity. 210*cdf0e10cSrcweir */ 211*cdf0e10cSrcweir void ensureCapacity(sal_Int32 minimumCapacity) 212*cdf0e10cSrcweir { 213*cdf0e10cSrcweir rtl_stringbuffer_ensureCapacity( &pData, &nCapacity, minimumCapacity ); 214*cdf0e10cSrcweir } 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir /** 217*cdf0e10cSrcweir Sets the length of this String buffer. 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir If the <code>newLength</code> argument is less than the current 220*cdf0e10cSrcweir length of the string buffer, the string buffer is truncated to 221*cdf0e10cSrcweir contain exactly the number of characters given by the 222*cdf0e10cSrcweir <code>newLength</code> argument. 223*cdf0e10cSrcweir <p> 224*cdf0e10cSrcweir If the <code>newLength</code> argument is greater than or equal 225*cdf0e10cSrcweir to the current length, sufficient null characters 226*cdf0e10cSrcweir (<code>'\u0000'</code>) are appended to the string buffer so that 227*cdf0e10cSrcweir length becomes the <code>newLength</code> argument. 228*cdf0e10cSrcweir <p> 229*cdf0e10cSrcweir The <code>newLength</code> argument must be greater than or equal 230*cdf0e10cSrcweir to <code>0</code>. 231*cdf0e10cSrcweir 232*cdf0e10cSrcweir @param newLength the new length of the buffer. 233*cdf0e10cSrcweir */ 234*cdf0e10cSrcweir void setLength(sal_Int32 newLength) 235*cdf0e10cSrcweir { 236*cdf0e10cSrcweir OSL_ASSERT(newLength >= 0); 237*cdf0e10cSrcweir // Avoid modifications if pData points to const empty string: 238*cdf0e10cSrcweir if( newLength != pData->length ) 239*cdf0e10cSrcweir { 240*cdf0e10cSrcweir if( newLength > nCapacity ) 241*cdf0e10cSrcweir rtl_stringbuffer_ensureCapacity(&pData, &nCapacity, newLength); 242*cdf0e10cSrcweir else 243*cdf0e10cSrcweir pData->buffer[newLength] = '\0'; 244*cdf0e10cSrcweir pData->length = newLength; 245*cdf0e10cSrcweir } 246*cdf0e10cSrcweir } 247*cdf0e10cSrcweir 248*cdf0e10cSrcweir /** 249*cdf0e10cSrcweir Returns the character at a specific index in this string buffer. 250*cdf0e10cSrcweir 251*cdf0e10cSrcweir The first character of a string buffer is at index 252*cdf0e10cSrcweir <code>0</code>, the next at index <code>1</code>, and so on, for 253*cdf0e10cSrcweir array indexing. 254*cdf0e10cSrcweir <p> 255*cdf0e10cSrcweir The index argument must be greater than or equal to 256*cdf0e10cSrcweir <code>0</code>, and less than the length of this string buffer. 257*cdf0e10cSrcweir 258*cdf0e10cSrcweir @param index the index of the desired character. 259*cdf0e10cSrcweir @return the character at the specified index of this string buffer. 260*cdf0e10cSrcweir */ 261*cdf0e10cSrcweir sal_Char charAt( sal_Int32 index ) 262*cdf0e10cSrcweir { 263*cdf0e10cSrcweir OSL_ASSERT(index >= 0 && index < pData->length); 264*cdf0e10cSrcweir return pData->buffer[ index ]; 265*cdf0e10cSrcweir } 266*cdf0e10cSrcweir 267*cdf0e10cSrcweir /** 268*cdf0e10cSrcweir Return a null terminated character array. 269*cdf0e10cSrcweir */ 270*cdf0e10cSrcweir operator const sal_Char *() const { return pData->buffer; } 271*cdf0e10cSrcweir 272*cdf0e10cSrcweir /** 273*cdf0e10cSrcweir Return a null terminated character array. 274*cdf0e10cSrcweir */ 275*cdf0e10cSrcweir const sal_Char* getStr() const { return pData->buffer; } 276*cdf0e10cSrcweir 277*cdf0e10cSrcweir 278*cdf0e10cSrcweir /** 279*cdf0e10cSrcweir The character at the specified index of this string buffer is set 280*cdf0e10cSrcweir to <code>ch</code>. 281*cdf0e10cSrcweir 282*cdf0e10cSrcweir The index argument must be greater than or equal to 283*cdf0e10cSrcweir <code>0</code>, and less than the length of this string buffer. 284*cdf0e10cSrcweir 285*cdf0e10cSrcweir @param index the index of the character to modify. 286*cdf0e10cSrcweir @param ch the new character. 287*cdf0e10cSrcweir */ 288*cdf0e10cSrcweir OStringBuffer & setCharAt(sal_Int32 index, sal_Char ch) 289*cdf0e10cSrcweir { 290*cdf0e10cSrcweir OSL_ASSERT(index >= 0 && index < pData->length); 291*cdf0e10cSrcweir pData->buffer[ index ] = ch; 292*cdf0e10cSrcweir return *this; 293*cdf0e10cSrcweir } 294*cdf0e10cSrcweir 295*cdf0e10cSrcweir /** 296*cdf0e10cSrcweir Appends the string to this string buffer. 297*cdf0e10cSrcweir 298*cdf0e10cSrcweir The characters of the <code>String</code> argument are appended, in 299*cdf0e10cSrcweir order, to the contents of this string buffer, increasing the 300*cdf0e10cSrcweir length of this string buffer by the length of the argument. 301*cdf0e10cSrcweir 302*cdf0e10cSrcweir @param str a string. 303*cdf0e10cSrcweir @return this string buffer. 304*cdf0e10cSrcweir */ 305*cdf0e10cSrcweir OStringBuffer & append(const OString &str) 306*cdf0e10cSrcweir { 307*cdf0e10cSrcweir return append( str.getStr(), str.getLength() ); 308*cdf0e10cSrcweir } 309*cdf0e10cSrcweir 310*cdf0e10cSrcweir /** 311*cdf0e10cSrcweir Appends the string representation of the <code>char</code> array 312*cdf0e10cSrcweir argument to this string buffer. 313*cdf0e10cSrcweir 314*cdf0e10cSrcweir The characters of the array argument are appended, in order, to 315*cdf0e10cSrcweir the contents of this string buffer. The length of this string 316*cdf0e10cSrcweir buffer increases by the length of the argument. 317*cdf0e10cSrcweir 318*cdf0e10cSrcweir @param str the characters to be appended. 319*cdf0e10cSrcweir @return this string buffer. 320*cdf0e10cSrcweir */ 321*cdf0e10cSrcweir OStringBuffer & append( const sal_Char * str ) 322*cdf0e10cSrcweir { 323*cdf0e10cSrcweir return append( str, rtl_str_getLength( str ) ); 324*cdf0e10cSrcweir } 325*cdf0e10cSrcweir 326*cdf0e10cSrcweir /** 327*cdf0e10cSrcweir Appends the string representation of the <code>char</code> array 328*cdf0e10cSrcweir argument to this string buffer. 329*cdf0e10cSrcweir 330*cdf0e10cSrcweir Characters of the character array <code>str</code> are appended, 331*cdf0e10cSrcweir in order, to the contents of this string buffer. The length of this 332*cdf0e10cSrcweir string buffer increases by the value of <code>len</code>. 333*cdf0e10cSrcweir 334*cdf0e10cSrcweir @param str the characters to be appended; must be non-null, and must 335*cdf0e10cSrcweir point to at least len characters 336*cdf0e10cSrcweir @param len the number of characters to append; must be non-negative 337*cdf0e10cSrcweir @return this string buffer. 338*cdf0e10cSrcweir */ 339*cdf0e10cSrcweir OStringBuffer & append( const sal_Char * str, sal_Int32 len) 340*cdf0e10cSrcweir { 341*cdf0e10cSrcweir // insert behind the last character 342*cdf0e10cSrcweir rtl_stringbuffer_insert( &pData, &nCapacity, getLength(), str, len ); 343*cdf0e10cSrcweir return *this; 344*cdf0e10cSrcweir } 345*cdf0e10cSrcweir 346*cdf0e10cSrcweir /** 347*cdf0e10cSrcweir Appends the string representation of the <code>sal_Bool</code> 348*cdf0e10cSrcweir argument to the string buffer. 349*cdf0e10cSrcweir 350*cdf0e10cSrcweir The argument is converted to a string as if by the method 351*cdf0e10cSrcweir <code>String.valueOf</code>, and the characters of that 352*cdf0e10cSrcweir string are then appended to this string buffer. 353*cdf0e10cSrcweir 354*cdf0e10cSrcweir @param b a <code>sal_Bool</code>. 355*cdf0e10cSrcweir @return this string buffer. 356*cdf0e10cSrcweir */ 357*cdf0e10cSrcweir OStringBuffer & append(sal_Bool b) 358*cdf0e10cSrcweir { 359*cdf0e10cSrcweir sal_Char sz[RTL_STR_MAX_VALUEOFBOOLEAN]; 360*cdf0e10cSrcweir return append( sz, rtl_str_valueOfBoolean( sz, b ) ); 361*cdf0e10cSrcweir } 362*cdf0e10cSrcweir 363*cdf0e10cSrcweir /** 364*cdf0e10cSrcweir Appends the string representation of the <code>char</code> 365*cdf0e10cSrcweir argument to this string buffer. 366*cdf0e10cSrcweir 367*cdf0e10cSrcweir The argument is appended to the contents of this string buffer. 368*cdf0e10cSrcweir The length of this string buffer increases by <code>1</code>. 369*cdf0e10cSrcweir 370*cdf0e10cSrcweir @param ch a <code>char</code>. 371*cdf0e10cSrcweir @return this string buffer. 372*cdf0e10cSrcweir */ 373*cdf0e10cSrcweir OStringBuffer & append(sal_Char c) 374*cdf0e10cSrcweir { 375*cdf0e10cSrcweir return append( &c, 1 ); 376*cdf0e10cSrcweir } 377*cdf0e10cSrcweir 378*cdf0e10cSrcweir /** 379*cdf0e10cSrcweir Appends the string representation of the <code>sal_Int32</code> 380*cdf0e10cSrcweir argument to this string buffer. 381*cdf0e10cSrcweir 382*cdf0e10cSrcweir The argument is converted to a string as if by the method 383*cdf0e10cSrcweir <code>String.valueOf</code>, and the characters of that 384*cdf0e10cSrcweir string are then appended to this string buffer. 385*cdf0e10cSrcweir 386*cdf0e10cSrcweir @param i an <code>sal_Int32</code>. 387*cdf0e10cSrcweir @return this string buffer. 388*cdf0e10cSrcweir */ 389*cdf0e10cSrcweir OStringBuffer & append(sal_Int32 i, sal_Int16 radix = 10 ) 390*cdf0e10cSrcweir { 391*cdf0e10cSrcweir sal_Char sz[RTL_STR_MAX_VALUEOFINT32]; 392*cdf0e10cSrcweir return append( sz, rtl_str_valueOfInt32( sz, i, radix ) ); 393*cdf0e10cSrcweir } 394*cdf0e10cSrcweir 395*cdf0e10cSrcweir /** 396*cdf0e10cSrcweir Appends the string representation of the <code>long</code> 397*cdf0e10cSrcweir argument to this string buffer. 398*cdf0e10cSrcweir 399*cdf0e10cSrcweir The argument is converted to a string as if by the method 400*cdf0e10cSrcweir <code>String.valueOf</code>, and the characters of that 401*cdf0e10cSrcweir string are then appended to this string buffer. 402*cdf0e10cSrcweir 403*cdf0e10cSrcweir @param l a <code>long</code>. 404*cdf0e10cSrcweir @return this string buffer. 405*cdf0e10cSrcweir */ 406*cdf0e10cSrcweir OStringBuffer & append(sal_Int64 l, sal_Int16 radix = 10 ) 407*cdf0e10cSrcweir { 408*cdf0e10cSrcweir sal_Char sz[RTL_STR_MAX_VALUEOFINT64]; 409*cdf0e10cSrcweir return append( sz, rtl_str_valueOfInt64( sz, l, radix ) ); 410*cdf0e10cSrcweir } 411*cdf0e10cSrcweir 412*cdf0e10cSrcweir /** 413*cdf0e10cSrcweir Appends the string representation of the <code>float</code> 414*cdf0e10cSrcweir argument to this string buffer. 415*cdf0e10cSrcweir 416*cdf0e10cSrcweir The argument is converted to a string as if by the method 417*cdf0e10cSrcweir <code>String.valueOf</code>, and the characters of that 418*cdf0e10cSrcweir string are then appended to this string buffer. 419*cdf0e10cSrcweir 420*cdf0e10cSrcweir @param f a <code>float</code>. 421*cdf0e10cSrcweir @return this string buffer. 422*cdf0e10cSrcweir */ 423*cdf0e10cSrcweir OStringBuffer & append(float f) 424*cdf0e10cSrcweir { 425*cdf0e10cSrcweir sal_Char sz[RTL_STR_MAX_VALUEOFFLOAT]; 426*cdf0e10cSrcweir return append( sz, rtl_str_valueOfFloat( sz, f ) ); 427*cdf0e10cSrcweir } 428*cdf0e10cSrcweir 429*cdf0e10cSrcweir /** 430*cdf0e10cSrcweir Appends the string representation of the <code>double</code> 431*cdf0e10cSrcweir argument to this string buffer. 432*cdf0e10cSrcweir 433*cdf0e10cSrcweir The argument is converted to a string as if by the method 434*cdf0e10cSrcweir <code>String.valueOf</code>, and the characters of that 435*cdf0e10cSrcweir string are then appended to this string buffer. 436*cdf0e10cSrcweir 437*cdf0e10cSrcweir @param d a <code>double</code>. 438*cdf0e10cSrcweir @return this string buffer. 439*cdf0e10cSrcweir */ 440*cdf0e10cSrcweir OStringBuffer & append(double d) 441*cdf0e10cSrcweir { 442*cdf0e10cSrcweir sal_Char sz[RTL_STR_MAX_VALUEOFDOUBLE]; 443*cdf0e10cSrcweir return append( sz, rtl_str_valueOfDouble( sz, d ) ); 444*cdf0e10cSrcweir } 445*cdf0e10cSrcweir 446*cdf0e10cSrcweir /** 447*cdf0e10cSrcweir Inserts the string into this string buffer. 448*cdf0e10cSrcweir 449*cdf0e10cSrcweir The characters of the <code>String</code> argument are inserted, in 450*cdf0e10cSrcweir order, into this string buffer at the indicated offset. The length 451*cdf0e10cSrcweir of this string buffer is increased by the length of the argument. 452*cdf0e10cSrcweir <p> 453*cdf0e10cSrcweir The offset argument must be greater than or equal to 454*cdf0e10cSrcweir <code>0</code>, and less than or equal to the length of this 455*cdf0e10cSrcweir string buffer. 456*cdf0e10cSrcweir 457*cdf0e10cSrcweir @param offset the offset. 458*cdf0e10cSrcweir @param str a string. 459*cdf0e10cSrcweir @return this string buffer. 460*cdf0e10cSrcweir */ 461*cdf0e10cSrcweir OStringBuffer & insert(sal_Int32 offset, const OString & str) 462*cdf0e10cSrcweir { 463*cdf0e10cSrcweir return insert( offset, str.getStr(), str.getLength() ); 464*cdf0e10cSrcweir } 465*cdf0e10cSrcweir 466*cdf0e10cSrcweir /** 467*cdf0e10cSrcweir Inserts the string representation of the <code>char</code> array 468*cdf0e10cSrcweir argument into this string buffer. 469*cdf0e10cSrcweir 470*cdf0e10cSrcweir The characters of the array argument are inserted into the 471*cdf0e10cSrcweir contents of this string buffer at the position indicated by 472*cdf0e10cSrcweir <code>offset</code>. The length of this string buffer increases by 473*cdf0e10cSrcweir the length of the argument. 474*cdf0e10cSrcweir <p> 475*cdf0e10cSrcweir The offset argument must be greater than or equal to 476*cdf0e10cSrcweir <code>0</code>, and less than or equal to the length of this 477*cdf0e10cSrcweir string buffer. 478*cdf0e10cSrcweir 479*cdf0e10cSrcweir @param offset the offset. 480*cdf0e10cSrcweir @param ch a character array. 481*cdf0e10cSrcweir @return this string buffer. 482*cdf0e10cSrcweir */ 483*cdf0e10cSrcweir OStringBuffer & insert( sal_Int32 offset, const sal_Char * str ) 484*cdf0e10cSrcweir { 485*cdf0e10cSrcweir return insert( offset, str, rtl_str_getLength( str ) ); 486*cdf0e10cSrcweir } 487*cdf0e10cSrcweir 488*cdf0e10cSrcweir /** 489*cdf0e10cSrcweir Inserts the string representation of the <code>char</code> array 490*cdf0e10cSrcweir argument into this string buffer. 491*cdf0e10cSrcweir 492*cdf0e10cSrcweir The characters of the array argument are inserted into the 493*cdf0e10cSrcweir contents of this string buffer at the position indicated by 494*cdf0e10cSrcweir <code>offset</code>. The length of this string buffer increases by 495*cdf0e10cSrcweir the length of the argument. 496*cdf0e10cSrcweir <p> 497*cdf0e10cSrcweir The offset argument must be greater than or equal to 498*cdf0e10cSrcweir <code>0</code>, and less than or equal to the length of this 499*cdf0e10cSrcweir string buffer. 500*cdf0e10cSrcweir 501*cdf0e10cSrcweir @param offset the offset. 502*cdf0e10cSrcweir @param ch a character array. 503*cdf0e10cSrcweir @param len the number of characters to append. 504*cdf0e10cSrcweir @return this string buffer. 505*cdf0e10cSrcweir */ 506*cdf0e10cSrcweir OStringBuffer & insert( sal_Int32 offset, const sal_Char * str, sal_Int32 len) 507*cdf0e10cSrcweir { 508*cdf0e10cSrcweir // insert behind the last character 509*cdf0e10cSrcweir rtl_stringbuffer_insert( &pData, &nCapacity, offset, str, len ); 510*cdf0e10cSrcweir return *this; 511*cdf0e10cSrcweir } 512*cdf0e10cSrcweir 513*cdf0e10cSrcweir /** 514*cdf0e10cSrcweir Inserts the string representation of the <code>sal_Bool</code> 515*cdf0e10cSrcweir argument into this string buffer. 516*cdf0e10cSrcweir 517*cdf0e10cSrcweir The second argument is converted to a string as if by the method 518*cdf0e10cSrcweir <code>String.valueOf</code>, and the characters of that 519*cdf0e10cSrcweir string are then inserted into this string buffer at the indicated 520*cdf0e10cSrcweir offset. 521*cdf0e10cSrcweir <p> 522*cdf0e10cSrcweir The offset argument must be greater than or equal to 523*cdf0e10cSrcweir <code>0</code>, and less than or equal to the length of this 524*cdf0e10cSrcweir string buffer. 525*cdf0e10cSrcweir 526*cdf0e10cSrcweir @param offset the offset. 527*cdf0e10cSrcweir @param b a <code>sal_Bool</code>. 528*cdf0e10cSrcweir @return this string buffer. 529*cdf0e10cSrcweir */ 530*cdf0e10cSrcweir OStringBuffer & insert(sal_Int32 offset, sal_Bool b) 531*cdf0e10cSrcweir { 532*cdf0e10cSrcweir sal_Char sz[RTL_STR_MAX_VALUEOFBOOLEAN]; 533*cdf0e10cSrcweir return insert( offset, sz, rtl_str_valueOfBoolean( sz, b ) ); 534*cdf0e10cSrcweir } 535*cdf0e10cSrcweir 536*cdf0e10cSrcweir /** 537*cdf0e10cSrcweir Inserts the string representation of the <code>char</code> 538*cdf0e10cSrcweir argument into this string buffer. 539*cdf0e10cSrcweir 540*cdf0e10cSrcweir The second argument is inserted into the contents of this string 541*cdf0e10cSrcweir buffer at the position indicated by <code>offset</code>. The length 542*cdf0e10cSrcweir of this string buffer increases by one. 543*cdf0e10cSrcweir <p> 544*cdf0e10cSrcweir The offset argument must be greater than or equal to 545*cdf0e10cSrcweir <code>0</code>, and less than or equal to the length of this 546*cdf0e10cSrcweir string buffer. 547*cdf0e10cSrcweir 548*cdf0e10cSrcweir @param offset the offset. 549*cdf0e10cSrcweir @param ch a <code>char</code>. 550*cdf0e10cSrcweir @return this string buffer. 551*cdf0e10cSrcweir */ 552*cdf0e10cSrcweir OStringBuffer & insert(sal_Int32 offset, sal_Char c) 553*cdf0e10cSrcweir { 554*cdf0e10cSrcweir return insert( offset, &c, 1 ); 555*cdf0e10cSrcweir } 556*cdf0e10cSrcweir 557*cdf0e10cSrcweir /** 558*cdf0e10cSrcweir Inserts the string representation of the second <code>sal_Int32</code> 559*cdf0e10cSrcweir argument into this string buffer. 560*cdf0e10cSrcweir 561*cdf0e10cSrcweir The second argument is converted to a string as if by the method 562*cdf0e10cSrcweir <code>String.valueOf</code>, and the characters of that 563*cdf0e10cSrcweir string are then inserted into this string buffer at the indicated 564*cdf0e10cSrcweir offset. 565*cdf0e10cSrcweir <p> 566*cdf0e10cSrcweir The offset argument must be greater than or equal to 567*cdf0e10cSrcweir <code>0</code>, and less than or equal to the length of this 568*cdf0e10cSrcweir string buffer. 569*cdf0e10cSrcweir 570*cdf0e10cSrcweir @param offset the offset. 571*cdf0e10cSrcweir @param b an <code>sal_Int32</code>. 572*cdf0e10cSrcweir @return this string buffer. 573*cdf0e10cSrcweir */ 574*cdf0e10cSrcweir OStringBuffer & insert(sal_Int32 offset, sal_Int32 i, sal_Int16 radix = 10 ) 575*cdf0e10cSrcweir { 576*cdf0e10cSrcweir sal_Char sz[RTL_STR_MAX_VALUEOFINT32]; 577*cdf0e10cSrcweir return insert( offset, sz, rtl_str_valueOfInt32( sz, i, radix ) ); 578*cdf0e10cSrcweir } 579*cdf0e10cSrcweir 580*cdf0e10cSrcweir /** 581*cdf0e10cSrcweir Inserts the string representation of the <code>long</code> 582*cdf0e10cSrcweir argument into this string buffer. 583*cdf0e10cSrcweir 584*cdf0e10cSrcweir The second argument is converted to a string as if by the method 585*cdf0e10cSrcweir <code>String.valueOf</code>, and the characters of that 586*cdf0e10cSrcweir string are then inserted into this string buffer at the indicated 587*cdf0e10cSrcweir offset. 588*cdf0e10cSrcweir <p> 589*cdf0e10cSrcweir The offset argument must be greater than or equal to 590*cdf0e10cSrcweir <code>0</code>, and less than or equal to the length of this 591*cdf0e10cSrcweir string buffer. 592*cdf0e10cSrcweir 593*cdf0e10cSrcweir @param offset the offset. 594*cdf0e10cSrcweir @param b a <code>long</code>. 595*cdf0e10cSrcweir @return this string buffer. 596*cdf0e10cSrcweir */ 597*cdf0e10cSrcweir OStringBuffer & insert(sal_Int32 offset, sal_Int64 l, sal_Int16 radix = 10 ) 598*cdf0e10cSrcweir { 599*cdf0e10cSrcweir sal_Char sz[RTL_STR_MAX_VALUEOFINT64]; 600*cdf0e10cSrcweir return insert( offset, sz, rtl_str_valueOfInt64( sz, l, radix ) ); 601*cdf0e10cSrcweir } 602*cdf0e10cSrcweir 603*cdf0e10cSrcweir /** 604*cdf0e10cSrcweir Inserts the string representation of the <code>float</code> 605*cdf0e10cSrcweir argument into this string buffer. 606*cdf0e10cSrcweir 607*cdf0e10cSrcweir The second argument is converted to a string as if by the method 608*cdf0e10cSrcweir <code>String.valueOf</code>, and the characters of that 609*cdf0e10cSrcweir string are then inserted into this string buffer at the indicated 610*cdf0e10cSrcweir offset. 611*cdf0e10cSrcweir <p> 612*cdf0e10cSrcweir The offset argument must be greater than or equal to 613*cdf0e10cSrcweir <code>0</code>, and less than or equal to the length of this 614*cdf0e10cSrcweir string buffer. 615*cdf0e10cSrcweir 616*cdf0e10cSrcweir @param offset the offset. 617*cdf0e10cSrcweir @param b a <code>float</code>. 618*cdf0e10cSrcweir @return this string buffer. 619*cdf0e10cSrcweir */ 620*cdf0e10cSrcweir OStringBuffer insert(sal_Int32 offset, float f) 621*cdf0e10cSrcweir { 622*cdf0e10cSrcweir sal_Char sz[RTL_STR_MAX_VALUEOFFLOAT]; 623*cdf0e10cSrcweir return insert( offset, sz, rtl_str_valueOfFloat( sz, f ) ); 624*cdf0e10cSrcweir } 625*cdf0e10cSrcweir 626*cdf0e10cSrcweir /** 627*cdf0e10cSrcweir Inserts the string representation of the <code>double</code> 628*cdf0e10cSrcweir argument into this string buffer. 629*cdf0e10cSrcweir 630*cdf0e10cSrcweir The second argument is converted to a string as if by the method 631*cdf0e10cSrcweir <code>String.valueOf</code>, and the characters of that 632*cdf0e10cSrcweir string are then inserted into this string buffer at the indicated 633*cdf0e10cSrcweir offset. 634*cdf0e10cSrcweir <p> 635*cdf0e10cSrcweir The offset argument must be greater than or equal to 636*cdf0e10cSrcweir <code>0</code>, and less than or equal to the length of this 637*cdf0e10cSrcweir string buffer. 638*cdf0e10cSrcweir 639*cdf0e10cSrcweir @param offset the offset. 640*cdf0e10cSrcweir @param b a <code>double</code>. 641*cdf0e10cSrcweir @return this string buffer. 642*cdf0e10cSrcweir */ 643*cdf0e10cSrcweir OStringBuffer & insert(sal_Int32 offset, double d) 644*cdf0e10cSrcweir { 645*cdf0e10cSrcweir sal_Char sz[RTL_STR_MAX_VALUEOFDOUBLE]; 646*cdf0e10cSrcweir return insert( offset, sz, rtl_str_valueOfDouble( sz, d ) ); 647*cdf0e10cSrcweir } 648*cdf0e10cSrcweir private: 649*cdf0e10cSrcweir /** 650*cdf0e10cSrcweir A pointer to the data structur which contains the data. 651*cdf0e10cSrcweir */ 652*cdf0e10cSrcweir rtl_String * pData; 653*cdf0e10cSrcweir 654*cdf0e10cSrcweir /** 655*cdf0e10cSrcweir The len of the pData->buffer. 656*cdf0e10cSrcweir */ 657*cdf0e10cSrcweir sal_Int32 nCapacity; 658*cdf0e10cSrcweir }; 659*cdf0e10cSrcweir 660*cdf0e10cSrcweir } 661*cdf0e10cSrcweir 662*cdf0e10cSrcweir #endif /* __cplusplus */ 663*cdf0e10cSrcweir #endif /* _RTL_STRBUF_HXX_ */ 664*cdf0e10cSrcweir 665*cdf0e10cSrcweir 666