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