Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / include / rtl / strbuf.hxx
blob5cb9e3b08aabc04c1e0d617b2074aa1836344c66
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_RTL_STRBUF_HXX
21 #define INCLUDED_RTL_STRBUF_HXX
23 #include <sal/config.h>
25 #include <cassert>
26 #include <string.h>
28 #include <rtl/strbuf.h>
29 #include <rtl/string.hxx>
30 #include <rtl/stringutils.hxx>
32 #ifdef RTL_FAST_STRING
33 #include <rtl/stringconcat.hxx>
34 #endif
36 #ifdef __cplusplus
38 // The unittest uses slightly different code to help check that the proper
39 // calls are made. The class is put into a different namespace to make
40 // sure the compiler generates a different (if generating also non-inline)
41 // copy of the function and does not merge them together. The class
42 // is "brought" into the proper rtl namespace by a typedef below.
43 #ifdef RTL_STRING_UNITTEST
44 #define rtl rtlunittest
45 #endif
47 namespace rtl
50 /// @cond INTERNAL
51 #ifdef RTL_STRING_UNITTEST
52 #undef rtl
53 // helper macro to make functions appear more readable
54 #define RTL_STRING_CONST_FUNCTION rtl_string_unittest_const_literal_function = true;
55 #else
56 #define RTL_STRING_CONST_FUNCTION
57 #endif
58 /// @endcond
60 /** A string buffer implements a mutable sequence of characters.
61 <p>
62 String buffers are safe for use by multiple threads. The methods
63 are synchronized where necessary so that all the operations on any
64 particular instance behave as if they occur in some serial order.
65 <p>
66 String buffers are used by the compiler to implement the binary
67 string concatenation operator <code>+</code>. For example, the code:
68 <p><blockquote><pre>
69 x = "a" + 4 + "c"
70 </pre></blockquote><p>
71 is compiled to the equivalent of:
72 <p><blockquote><pre>
73 x = new OStringBuffer().append("a").append(4).append("c")
74 .makeStringAndClear()
75 </pre></blockquote><p>
76 The principal operations on a <code>OStringBuffer</code> are the
77 <code>append</code> and <code>insert</code> methods, which are
78 overloaded so as to accept data of any type. Each effectively
79 converts a given datum to a string and then appends or inserts the
80 characters of that string to the string buffer. The
81 <code>append</code> method always adds these characters at the end
82 of the buffer; the <code>insert</code> method adds the characters at
83 a specified point.
84 <p>
85 For example, if <code>z</code> refers to a string buffer object
86 whose current contents are "<code>start</code>", then
87 the method call <code>z.append("le")</code> would cause the string
88 buffer to contain "<code>startle</code>", whereas
89 <code>z.insert(4, "le")</code> would alter the string buffer to
90 contain "<code>starlet</code>".
91 <p>
92 Every string buffer has a capacity. As long as the length of the
93 character sequence contained in the string buffer does not exceed
94 the capacity, it is not necessary to allocate a new internal
95 buffer array. If the internal buffer overflows, it is
96 automatically made larger.
98 class SAL_WARN_UNUSED OStringBuffer
100 public:
102 Constructs a string buffer with no characters in it and an
103 initial capacity of 16 characters.
105 OStringBuffer()
106 : pData(NULL)
107 , nCapacity( 16 )
109 rtl_string_new_WithLength( &pData, nCapacity );
113 Allocates a new string buffer that contains the same sequence of
114 characters as the string buffer argument.
116 @param value a <code>OStringBuffer</code>.
118 OStringBuffer( const OStringBuffer & value )
119 : pData(NULL)
120 , nCapacity( value.nCapacity )
122 rtl_stringbuffer_newFromStringBuffer( &pData, value.nCapacity, value.pData );
126 Constructs a string buffer with no characters in it and an
127 initial capacity specified by the <code>length</code> argument.
129 @param length the initial capacity.
131 explicit OStringBuffer(int length)
132 : pData(NULL)
133 , nCapacity( length )
135 rtl_string_new_WithLength( &pData, length );
139 Constructs a string buffer so that it represents the same
140 sequence of characters as the string argument.
142 The initial
143 capacity of the string buffer is <code>16</code> plus the length
144 of the string argument.
146 @param value the initial string value.
148 OStringBuffer(const OString& value)
149 : pData(NULL)
150 , nCapacity( value.getLength() + 16 )
152 rtl_stringbuffer_newFromStr_WithLength( &pData, value.getStr(), value.getLength() );
156 @overload
157 @since LibreOffice 3.6
159 template< typename T >
160 OStringBuffer( const T& value, typename internal::CharPtrDetector< T, internal::Dummy >::Type = internal::Dummy())
161 : pData(NULL)
163 sal_Int32 length = rtl_str_getLength( value );
164 nCapacity = length + 16;
165 rtl_stringbuffer_newFromStr_WithLength( &pData, value, length );
168 template< typename T >
169 OStringBuffer( T& value, typename internal::NonConstCharArrayDetector< T, internal::Dummy >::Type = internal::Dummy())
170 : pData(NULL)
172 sal_Int32 length = rtl_str_getLength( value );
173 nCapacity = length + 16;
174 rtl_stringbuffer_newFromStr_WithLength( &pData, value, length );
178 Constructs a string buffer so that it represents the same
179 sequence of characters as the string literal.
181 If there are any embedded \0's in the string literal, the result is undefined.
182 Use the overload that explicitly accepts length.
184 @since LibreOffice 3.6
186 @param literal a string literal
188 template< typename T >
189 OStringBuffer( T& literal, typename internal::ConstCharArrayDetector< T, internal::Dummy >::Type = internal::Dummy())
190 : pData(NULL)
191 , nCapacity( internal::ConstCharArrayDetector< T, void >::size - 1 + 16 )
193 assert( strlen( literal ) == internal::ConstCharArrayDetector< T >::size - 1 );
194 rtl_string_newFromLiteral( &pData, literal, internal::ConstCharArrayDetector< T, void >::size - 1, 16 );
195 #ifdef RTL_STRING_UNITTEST
196 rtl_string_unittest_const_literal = true;
197 #endif
201 Constructs a string buffer so that it represents the same
202 sequence of characters as the string argument.
204 The initial
205 capacity of the string buffer is <code>16</code> plus length
207 @param value a character array.
208 @param length the number of character which should be copied.
209 The character array length must be greater or
210 equal than this value.
212 OStringBuffer(const sal_Char * value, sal_Int32 length)
213 : pData(NULL)
214 , nCapacity( length + 16 )
216 rtl_stringbuffer_newFromStr_WithLength( &pData, value, length );
219 #ifdef RTL_FAST_STRING
221 @overload
222 @internal
224 template< typename T1, typename T2 >
225 OStringBuffer( const OStringConcat< T1, T2 >& c )
227 const sal_Int32 l = c.length();
228 nCapacity = l + 16;
229 pData = rtl_string_alloc( nCapacity );
230 char* end = c.addData( pData->buffer );
231 *end = '\0';
232 pData->length = end - pData->buffer;
234 #endif
236 /** Assign to this a copy of value.
238 OStringBuffer& operator = ( const OStringBuffer& value )
240 if (this != &value)
242 rtl_stringbuffer_newFromStringBuffer(&pData,
243 value.nCapacity,
244 value.pData);
245 nCapacity = value.nCapacity;
247 return *this;
251 Release the string data.
253 ~OStringBuffer()
255 rtl_string_release( pData );
259 Fill the string data in the new string and clear the buffer.
261 This method is more efficient than the contructor of the string. It does
262 not copy the buffer.
264 @return the string previously contained in the buffer.
266 OString makeStringAndClear()
268 OString aRet( pData );
269 rtl_string_new(&pData);
270 nCapacity = 0;
271 return aRet;
275 Returns the length (character count) of this string buffer.
277 @return the number of characters in this string buffer.
279 sal_Int32 getLength() const
281 return pData->length;
285 Checks if a string buffer is empty.
287 @return true if the string buffer is empty;
288 false, otherwise.
290 @since LibreOffice 4.1
292 bool isEmpty() const SAL_THROW(())
294 return pData->length == 0;
298 Returns the current capacity of the String buffer.
300 The capacity
301 is the amount of storage available for newly inserted
302 characters. The real buffer size is 2 bytes longer, because
303 all strings are 0 terminated.
305 @return the current capacity of this string buffer.
307 sal_Int32 getCapacity() const
309 return nCapacity;
313 Ensures that the capacity of the buffer is at least equal to the
314 specified minimum.
316 The new capacity will be at least as large as the maximum of the current
317 length (so that no contents of the buffer is destroyed) and the given
318 minimumCapacity. If the given minimumCapacity is negative, nothing is
319 changed.
321 @param minimumCapacity the minimum desired capacity.
323 void ensureCapacity(sal_Int32 minimumCapacity)
325 rtl_stringbuffer_ensureCapacity( &pData, &nCapacity, minimumCapacity );
329 Sets the length of this String buffer.
331 If the <code>newLength</code> argument is less than the current
332 length of the string buffer, the string buffer is truncated to
333 contain exactly the number of characters given by the
334 <code>newLength</code> argument.
336 If the <code>newLength</code> argument is greater than or equal
337 to the current length, sufficient null characters
338 (<code>'&#92;u0000'</code>) are appended to the string buffer so that
339 length becomes the <code>newLength</code> argument.
341 The <code>newLength</code> argument must be greater than or equal
342 to <code>0</code>.
344 @param newLength the new length of the buffer.
346 void setLength(sal_Int32 newLength)
348 assert(newLength >= 0);
349 // Avoid modifications if pData points to const empty string:
350 if( newLength != pData->length )
352 if( newLength > nCapacity )
353 rtl_stringbuffer_ensureCapacity(&pData, &nCapacity, newLength);
354 else
355 pData->buffer[newLength] = '\0';
356 pData->length = newLength;
361 Returns the character at a specific index in this string buffer.
363 The first character of a string buffer is at index
364 <code>0</code>, the next at index <code>1</code>, and so on, for
365 array indexing.
367 The index argument must be greater than or equal to
368 <code>0</code>, and less than the length of this string buffer.
370 @param index the index of the desired character.
371 @return the character at the specified index of this string buffer.
373 SAL_DEPRECATED("use rtl::OStringBuffer::operator [] instead")
374 sal_Char charAt( sal_Int32 index )
376 assert(index >= 0 && index < pData->length);
377 return pData->buffer[ index ];
381 The character at the specified index of this string buffer is set
382 to <code>ch</code>.
384 The index argument must be greater than or equal to
385 <code>0</code>, and less than the length of this string buffer.
387 @param index the index of the character to modify.
388 @param ch the new character.
390 SAL_DEPRECATED("use rtl::OStringBuffer::operator [] instead")
391 OStringBuffer & setCharAt(sal_Int32 index, sal_Char ch)
393 assert(index >= 0 && index < pData->length);
394 pData->buffer[ index ] = ch;
395 return *this;
399 Return a null terminated character array.
401 const sal_Char* getStr() const { return pData->buffer; }
404 Access to individual characters.
406 @param index must be non-negative and less than length.
408 @return a reference to the character at the given index.
410 @since LibreOffice 3.5
412 sal_Char & operator [](sal_Int32 index)
414 assert(index >= 0 && index < pData->length);
415 return pData->buffer[index];
419 Return a OString instance reflecting the current content
420 of this OStringBuffer.
422 const OString toString() const
424 return OString(pData->buffer, pData->length);
428 Appends the string to this string buffer.
430 The characters of the <code>String</code> argument are appended, in
431 order, to the contents of this string buffer, increasing the
432 length of this string buffer by the length of the argument.
434 @param str a string.
435 @return this string buffer.
437 OStringBuffer & append(const OString &str)
439 return append( str.getStr(), str.getLength() );
443 Appends the string representation of the <code>char</code> array
444 argument to this string buffer.
446 The characters of the array argument are appended, in order, to
447 the contents of this string buffer. The length of this string
448 buffer increases by the length of the argument.
450 @param str the characters to be appended.
451 @return this string buffer.
453 template< typename T >
454 typename internal::CharPtrDetector< T, OStringBuffer& >::Type append( const T& str )
456 return append( str, rtl_str_getLength( str ) );
459 template< typename T >
460 typename internal::NonConstCharArrayDetector< T, OStringBuffer& >::Type append( T& str )
462 return append( str, rtl_str_getLength( str ) );
466 @overload
467 This function accepts an ASCII string literal as its argument.
468 @since LibreOffice 3.6
470 template< typename T >
471 typename internal::ConstCharArrayDetector< T, OStringBuffer& >::Type append( T& literal )
473 RTL_STRING_CONST_FUNCTION
474 assert( strlen( literal ) == internal::ConstCharArrayDetector< T >::size - 1 );
475 rtl_stringbuffer_insert( &pData, &nCapacity, getLength(), literal, internal::ConstCharArrayDetector< T, void >::size - 1 );
476 return *this;
480 Appends the string representation of the <code>char</code> array
481 argument to this string buffer.
483 Characters of the character array <code>str</code> are appended,
484 in order, to the contents of this string buffer. The length of this
485 string buffer increases by the value of <code>len</code>.
487 @param str the characters to be appended; must be non-null, and must
488 point to at least len characters
489 @param len the number of characters to append; must be non-negative
490 @return this string buffer.
492 OStringBuffer & append( const sal_Char * str, sal_Int32 len)
494 // insert behind the last character
495 rtl_stringbuffer_insert( &pData, &nCapacity, getLength(), str, len );
496 return *this;
499 #ifdef RTL_FAST_STRING
501 @overload
502 @internal
504 template< typename T1, typename T2 >
505 OStringBuffer& append( const OStringConcat< T1, T2 >& c )
507 const int l = c.length();
508 if( l == 0 )
509 return *this;
510 rtl_stringbuffer_ensureCapacity( &pData, &nCapacity, pData->length + l );
511 char* end = c.addData( pData->buffer + pData->length );
512 *end = '\0';
513 pData->length = end - pData->buffer;
514 return *this;
516 #endif
519 Appends the string representation of the <code>sal_Bool</code>
520 argument to the string buffer.
522 The argument is converted to a string as if by the method
523 <code>String.valueOf</code>, and the characters of that
524 string are then appended to this string buffer.
526 @param b a <code>sal_Bool</code>.
527 @return this string buffer.
529 OStringBuffer & append(sal_Bool b)
531 sal_Char sz[RTL_STR_MAX_VALUEOFBOOLEAN];
532 return append( sz, rtl_str_valueOfBoolean( sz, b ) );
536 Appends the string representation of the <code>bool</code>
537 argument to the string buffer.
539 The argument is converted to a string as if by the method
540 <code>String.valueOf</code>, and the characters of that
541 string are then appended to this string buffer.
543 @param b a <code>bool</code>.
544 @return this string buffer.
546 @since LibreOffice 4.3
548 OStringBuffer & append(bool b)
550 sal_Char sz[RTL_STR_MAX_VALUEOFBOOLEAN];
551 return append( sz, rtl_str_valueOfBoolean( sz, b ) );
554 /// @cond INTERNAL
555 // Pointer can be automatically converted to bool, which is unwanted here.
556 // Explicitly delete all pointer append() overloads to prevent this
557 // (except for char* overload, which is handled elsewhere).
558 template< typename T >
559 typename internal::Enable< void,
560 !internal::CharPtrDetector< T* >::ok >::Type
561 append( T* ) SAL_DELETED_FUNCTION;
562 /// @endcond
565 Appends the string representation of the <code>char</code>
566 argument to this string buffer.
568 The argument is appended to the contents of this string buffer.
569 The length of this string buffer increases by <code>1</code>.
571 @param c a <code>char</code>.
572 @return this string buffer.
574 OStringBuffer & append(sal_Char c)
576 return append( &c, 1 );
580 Appends the string representation of the <code>sal_Int32</code>
581 argument to this string buffer.
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.
587 @param i an <code>sal_Int32</code>.
588 @param radix the radix
589 @return this string buffer.
591 OStringBuffer & append(sal_Int32 i, sal_Int16 radix = 10 )
593 sal_Char sz[RTL_STR_MAX_VALUEOFINT32];
594 return append( sz, rtl_str_valueOfInt32( sz, i, radix ) );
598 Appends the string representation of the <code>long</code>
599 argument to this string buffer.
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.
605 @param l a <code>long</code>.
606 @param radix the radix
607 @return this string buffer.
609 OStringBuffer & append(sal_Int64 l, sal_Int16 radix = 10 )
611 sal_Char sz[RTL_STR_MAX_VALUEOFINT64];
612 return append( sz, rtl_str_valueOfInt64( sz, l, radix ) );
616 Appends the string representation of the <code>float</code>
617 argument to this string buffer.
619 The argument is converted to a string as if by the method
620 <code>String.valueOf</code>, and the characters of that
621 string are then appended to this string buffer.
623 @param f a <code>float</code>.
624 @return this string buffer.
626 OStringBuffer & append(float f)
628 sal_Char sz[RTL_STR_MAX_VALUEOFFLOAT];
629 return append( sz, rtl_str_valueOfFloat( sz, f ) );
633 Appends the string representation of the <code>double</code>
634 argument to this string buffer.
636 The argument is converted to a string as if by the method
637 <code>String.valueOf</code>, and the characters of that
638 string are then appended to this string buffer.
640 @param d a <code>double</code>.
641 @return this string buffer.
643 OStringBuffer & append(double d)
645 sal_Char sz[RTL_STR_MAX_VALUEOFDOUBLE];
646 return append( sz, rtl_str_valueOfDouble( sz, d ) );
650 Inserts the string into this string buffer.
652 The characters of the <code>String</code> argument are inserted, in
653 order, into this string buffer at the indicated offset. The length
654 of this string buffer is increased by the length of the argument.
656 The offset argument must be greater than or equal to
657 <code>0</code>, and less than or equal to the length of this
658 string buffer.
660 @param offset the offset.
661 @param str a string.
662 @return this string buffer.
664 OStringBuffer & insert(sal_Int32 offset, const OString & str)
666 return insert( offset, str.getStr(), str.getLength() );
670 Inserts the string representation of the <code>char</code> array
671 argument into this string buffer.
673 The characters of the array argument are inserted into the
674 contents of this string buffer at the position indicated by
675 <code>offset</code>. The length of this string buffer increases by
676 the length of the argument.
678 The offset argument must be greater than or equal to
679 <code>0</code>, and less than or equal to the length of this
680 string buffer.
682 @param offset the offset.
683 @param str a character array.
684 @return this string buffer.
686 template< typename T >
687 typename internal::CharPtrDetector< T, OStringBuffer& >::Type insert( sal_Int32 offset, const T& str )
689 return insert( offset, str, rtl_str_getLength( str ) );
692 template< typename T >
693 typename internal::NonConstCharArrayDetector< T, OStringBuffer& >::Type insert( sal_Int32 offset, T& str )
695 return insert( offset, str, rtl_str_getLength( str ) );
699 @overload
700 This function accepts an ASCII string literal as its argument.
701 @since LibreOffice 3.6
703 template< typename T >
704 typename internal::ConstCharArrayDetector< T, OStringBuffer& >::Type insert( sal_Int32 offset, T& literal )
706 RTL_STRING_CONST_FUNCTION
707 assert( strlen( literal ) == internal::ConstCharArrayDetector< T >::size - 1 );
708 rtl_stringbuffer_insert( &pData, &nCapacity, offset, literal, internal::ConstCharArrayDetector< T, void >::size - 1 );
709 return *this;
713 Inserts the string representation of the <code>char</code> array
714 argument into this string buffer.
716 The characters of the array argument are inserted into the
717 contents of this string buffer at the position indicated by
718 <code>offset</code>. The length of this string buffer increases by
719 the length of the argument.
721 The offset argument must be greater than or equal to
722 <code>0</code>, and less than or equal to the length of this
723 string buffer.
725 @param offset the offset.
726 @param str a character array.
727 @param len the number of characters to append.
728 @return this string buffer.
730 OStringBuffer & insert( sal_Int32 offset, const sal_Char * str, sal_Int32 len)
732 // insert behind the last character
733 rtl_stringbuffer_insert( &pData, &nCapacity, offset, str, len );
734 return *this;
738 Inserts the string representation of the <code>sal_Bool</code>
739 argument into this string buffer.
741 The second argument is converted to a string as if by the method
742 <code>String.valueOf</code>, and the characters of that
743 string are then inserted into this string buffer at the indicated
744 offset.
746 The offset argument must be greater than or equal to
747 <code>0</code>, and less than or equal to the length of this
748 string buffer.
750 @param offset the offset.
751 @param b a <code>sal_Bool</code>.
752 @return this string buffer.
754 OStringBuffer & insert(sal_Int32 offset, sal_Bool b)
756 sal_Char sz[RTL_STR_MAX_VALUEOFBOOLEAN];
757 return insert( offset, sz, rtl_str_valueOfBoolean( sz, b ) );
761 Inserts the string representation of the <code>bool</code>
762 argument into this string buffer.
764 The second argument is converted to a string as if by the method
765 <code>OString::boolean</code>, and the characters of that
766 string are then inserted into this string buffer at the indicated
767 offset.
769 The offset argument must be greater than or equal to
770 <code>0</code>, and less than or equal to the length of this
771 string buffer.
773 @param offset the offset.
774 @param b a <code>bool</code>.
775 @return this string buffer.
777 @since LibreOffice 4.3
779 OStringBuffer & insert(sal_Int32 offset, bool b)
781 sal_Char sz[RTL_STR_MAX_VALUEOFBOOLEAN];
782 return insert( offset, sz, rtl_str_valueOfBoolean( sz, b ) );
786 Inserts the string representation of the <code>char</code>
787 argument into this string buffer.
789 The second argument is inserted into the contents of this string
790 buffer at the position indicated by <code>offset</code>. The length
791 of this string buffer increases by one.
793 The offset argument must be greater than or equal to
794 <code>0</code>, and less than or equal to the length of this
795 string buffer.
797 @param offset the offset.
798 @param c a <code>char</code>.
799 @return this string buffer.
801 OStringBuffer & insert(sal_Int32 offset, sal_Char c)
803 return insert( offset, &c, 1 );
807 Inserts the string representation of the second <code>sal_Int32</code>
808 argument into this string buffer.
810 The second argument is converted to a string as if by the method
811 <code>String.valueOf</code>, and the characters of that
812 string are then inserted into this string buffer at the indicated
813 offset.
815 The offset argument must be greater than or equal to
816 <code>0</code>, and less than or equal to the length of this
817 string buffer.
819 @param offset the offset.
820 @param i an <code>sal_Int32</code>.
821 @param radix the radix
822 @return this string buffer.
824 OStringBuffer & insert(sal_Int32 offset, sal_Int32 i, sal_Int16 radix = 10 )
826 sal_Char sz[RTL_STR_MAX_VALUEOFINT32];
827 return insert( offset, sz, rtl_str_valueOfInt32( sz, i, radix ) );
831 Inserts the string representation of the <code>long</code>
832 argument into this string buffer.
834 The second argument is converted to a string as if by the method
835 <code>String.valueOf</code>, and the characters of that
836 string are then inserted into this string buffer at the indicated
837 offset.
839 The offset argument must be greater than or equal to
840 <code>0</code>, and less than or equal to the length of this
841 string buffer.
843 @param offset the offset.
844 @param l a <code>long</code>.
845 @param radix the radix
846 @return this string buffer.
848 OStringBuffer & insert(sal_Int32 offset, sal_Int64 l, sal_Int16 radix = 10 )
850 sal_Char sz[RTL_STR_MAX_VALUEOFINT64];
851 return insert( offset, sz, rtl_str_valueOfInt64( sz, l, radix ) );
855 Inserts the string representation of the <code>float</code>
856 argument into this string buffer.
858 The second argument is converted to a string as if by the method
859 <code>String.valueOf</code>, and the characters of that
860 string are then inserted into this string buffer at the indicated
861 offset.
863 The offset argument must be greater than or equal to
864 <code>0</code>, and less than or equal to the length of this
865 string buffer.
867 @param offset the offset.
868 @param f a <code>float</code>.
869 @return this string buffer.
871 OStringBuffer insert(sal_Int32 offset, float f)
873 sal_Char sz[RTL_STR_MAX_VALUEOFFLOAT];
874 return insert( offset, sz, rtl_str_valueOfFloat( sz, f ) );
878 Inserts the string representation of the <code>double</code>
879 argument into this string buffer.
881 The second argument is converted to a string as if by the method
882 <code>String.valueOf</code>, and the characters of that
883 string are then inserted into this string buffer at the indicated
884 offset.
886 The offset argument must be greater than or equal to
887 <code>0</code>, and less than or equal to the length of this
888 string buffer.
890 @param offset the offset.
891 @param d a <code>double</code>.
892 @return this string buffer.
894 OStringBuffer & insert(sal_Int32 offset, double d)
896 sal_Char sz[RTL_STR_MAX_VALUEOFDOUBLE];
897 return insert( offset, sz, rtl_str_valueOfDouble( sz, d ) );
901 Removes the characters in a substring of this sequence.
903 The substring begins at the specified <code>start</code> and
904 is <code>len</code> characters long.
906 start must be >= 0 && <= getLength() && <= end
908 @param start The beginning index, inclusive
909 @param len The substring length
910 @return this string buffer.
912 OStringBuffer & remove( sal_Int32 start, sal_Int32 len )
914 rtl_stringbuffer_remove( &pData, start, len );
915 return *this;
918 #ifdef LIBO_INTERNAL_ONLY
919 // This is to complement the RTL_FAST_STRING operator+, which allows any combination of valid operands,
920 // even two buffers. It's intentional it returns OString, just like the operator+ would in the fast variant.
921 #ifndef RTL_FAST_STRING
923 @internal
924 @since LibreOffice 4.1
926 friend OString operator+( const OStringBuffer& str1, const OStringBuffer& str2 ) SAL_THROW(())
928 return OString( str1.pData ).concat( str2.pData );
930 #endif
931 #endif
933 private:
935 A pointer to the data structur which contains the data.
937 rtl_String * pData;
940 The len of the pData->buffer.
942 sal_Int32 nCapacity;
945 #ifdef RTL_FAST_STRING
947 @internal
949 template<>
950 struct ToStringHelper< OStringBuffer >
952 static int length( const OStringBuffer& s ) { return s.getLength(); }
953 static char* addData( char* buffer, const OStringBuffer& s ) { return addDataHelper( buffer, s.getStr(), s.getLength()); }
954 static const bool allowOStringConcat = true;
955 static const bool allowOUStringConcat = false;
957 #endif
962 #ifdef RTL_STRING_UNITTEST
963 namespace rtl
965 typedef rtlunittest::OStringBuffer OStringBuffer;
967 #undef RTL_STRING_CONST_FUNCTION
968 #endif
970 #ifdef RTL_USING
971 using ::rtl::OStringBuffer;
972 #endif
974 #endif /* __cplusplus */
975 #endif // INCLUDED_RTL_STRBUF_HXX
978 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */