bump product version to 6.3.0.0.beta1
[LibreOffice.git] / include / rtl / strbuf.hxx
blobc674f34d997cac9cae72fda9782e1dde051df372
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 <cstring>
28 #include "rtl/strbuf.h"
29 #include "rtl/string.hxx"
30 #include "rtl/stringutils.hxx"
32 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
33 #include "rtl/stringconcat.hxx"
34 #endif
36 #ifdef RTL_STRING_UNITTEST
37 extern bool rtl_string_unittest_const_literal;
38 extern bool rtl_string_unittest_const_literal_function;
39 #endif
41 // The unittest uses slightly different code to help check that the proper
42 // calls are made. The class is put into a different namespace to make
43 // sure the compiler generates a different (if generating also non-inline)
44 // copy of the function and does not merge them together. The class
45 // is "brought" into the proper rtl namespace by a typedef below.
46 #ifdef RTL_STRING_UNITTEST
47 #define rtl rtlunittest
48 #endif
50 namespace rtl
53 /// @cond INTERNAL
54 #ifdef RTL_STRING_UNITTEST
55 #undef rtl
56 // helper macro to make functions appear more readable
57 #define RTL_STRING_CONST_FUNCTION rtl_string_unittest_const_literal_function = true;
58 #else
59 #define RTL_STRING_CONST_FUNCTION
60 #endif
61 /// @endcond
63 /** A string buffer implements a mutable sequence of characters.
65 class SAL_WARN_UNUSED OStringBuffer
67 public:
68 /**
69 Constructs a string buffer with no characters in it and an
70 initial capacity of 16 characters.
72 OStringBuffer()
73 : pData(NULL)
74 , nCapacity( 16 )
76 rtl_string_new_WithLength( &pData, nCapacity );
79 /**
80 Allocates a new string buffer that contains the same sequence of
81 characters as the string buffer argument.
83 @param value a <code>OStringBuffer</code>.
85 OStringBuffer( const OStringBuffer & value )
86 : pData(NULL)
87 , nCapacity( value.nCapacity )
89 rtl_stringbuffer_newFromStringBuffer( &pData, value.nCapacity, value.pData );
92 /**
93 Constructs a string buffer with no characters in it and an
94 initial capacity specified by the <code>length</code> argument.
96 @param length the initial capacity.
98 explicit OStringBuffer(int length)
99 : pData(NULL)
100 , nCapacity( length )
102 rtl_string_new_WithLength( &pData, length );
104 #if __cplusplus >= 201103L
105 explicit OStringBuffer(unsigned int length)
106 : OStringBuffer(static_cast<int>(length))
109 #if SAL_TYPES_SIZEOFLONG == 4
110 // additional overloads for sal_Int32 sal_uInt32
111 explicit OStringBuffer(long length)
112 : OStringBuffer(static_cast<int>(length))
115 explicit OStringBuffer(unsigned long length)
116 : OStringBuffer(static_cast<int>(length))
119 #endif
120 // avoid obvious bugs
121 explicit OStringBuffer(char) = delete;
122 explicit OStringBuffer(sal_Unicode) = delete;
123 #endif
126 Constructs a string buffer so that it represents the same
127 sequence of characters as the string argument.
129 The initial
130 capacity of the string buffer is <code>16</code> plus the length
131 of the string argument.
133 @param value the initial string value.
135 OStringBuffer(const OString& value)
136 : pData(NULL)
137 , nCapacity( value.getLength() + 16 )
139 rtl_stringbuffer_newFromStr_WithLength( &pData, value.getStr(), value.getLength() );
143 @overload
144 @since LibreOffice 3.6
146 template< typename T >
147 OStringBuffer( const T& value, typename libreoffice_internal::CharPtrDetector< T, libreoffice_internal::Dummy >::Type = libreoffice_internal::Dummy())
148 : pData(NULL)
150 sal_Int32 length = rtl_str_getLength( value );
151 nCapacity = length + 16;
152 rtl_stringbuffer_newFromStr_WithLength( &pData, value, length );
155 template< typename T >
156 OStringBuffer( T& value, typename libreoffice_internal::NonConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type = libreoffice_internal::Dummy())
157 : pData(NULL)
159 sal_Int32 length = rtl_str_getLength( value );
160 nCapacity = length + 16;
161 rtl_stringbuffer_newFromStr_WithLength( &pData, value, length );
165 Constructs a string buffer so that it represents the same
166 sequence of characters as the string literal.
168 If there are any embedded \0's in the string literal, the result is undefined.
169 Use the overload that explicitly accepts length.
171 @since LibreOffice 3.6
173 @param literal a string literal
175 template< typename T >
176 OStringBuffer( T& literal, typename libreoffice_internal::ConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type = libreoffice_internal::Dummy())
177 : pData(NULL)
178 , nCapacity( libreoffice_internal::ConstCharArrayDetector<T>::length + 16 )
180 assert(
181 libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
182 rtl_string_newFromLiteral(
183 &pData,
184 libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
185 libreoffice_internal::ConstCharArrayDetector<T>::length, 16);
186 #ifdef RTL_STRING_UNITTEST
187 rtl_string_unittest_const_literal = true;
188 #endif
192 Constructs a string buffer so that it represents the same
193 sequence of characters as the string argument.
195 The initial
196 capacity of the string buffer is <code>16</code> plus length
198 @param value a character array.
199 @param length the number of character which should be copied.
200 The character array length must be greater or
201 equal than this value.
203 OStringBuffer(const sal_Char * value, sal_Int32 length)
204 : pData(NULL)
205 , nCapacity( length + 16 )
207 rtl_stringbuffer_newFromStr_WithLength( &pData, value, length );
210 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
212 @overload
213 @internal
215 template< typename T1, typename T2 >
216 OStringBuffer( OStringConcat< T1, T2 >&& c )
218 const sal_Int32 l = c.length();
219 nCapacity = l + 16;
220 pData = rtl_string_alloc( nCapacity );
221 char* end = c.addData( pData->buffer );
222 *end = '\0';
223 pData->length = l;
225 #endif
227 /** Assign to this a copy of value.
229 OStringBuffer& operator = ( const OStringBuffer& value )
231 if (this != &value)
233 rtl_stringbuffer_newFromStringBuffer(&pData,
234 value.nCapacity,
235 value.pData);
236 nCapacity = value.nCapacity;
238 return *this;
241 /** Assign from a string.
243 @since LibreOffice 5.3
245 OStringBuffer & operator =(OString const & string) {
246 sal_Int32 n = string.getLength();
247 if (n >= nCapacity) {
248 ensureCapacity(n + 16); //TODO: check for overflow
250 std::memcpy(pData->buffer, string.pData->buffer, n + 1);
251 pData->length = n;
252 return *this;
255 /** Assign from a string literal.
257 @since LibreOffice 5.3
259 template<typename T>
260 typename
261 libreoffice_internal::ConstCharArrayDetector<T, OStringBuffer &>::Type
262 operator =(T & literal) {
263 assert(
264 libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
265 sal_Int32 const n
266 = libreoffice_internal::ConstCharArrayDetector<T>::length;
267 if (n >= nCapacity) {
268 ensureCapacity(n + 16); //TODO: check for overflow
270 std::memcpy(
271 pData->buffer,
272 libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
273 n + 1);
274 pData->length = n;
275 return *this;
278 #if defined LIBO_INTERNAL_ONLY
279 /** @overload @since LibreOffice 5.3 */
280 template<typename T1, typename T2>
281 OStringBuffer & operator =(OStringConcat<T1, T2> && concat) {
282 sal_Int32 const n = concat.length();
283 if (n >= nCapacity) {
284 ensureCapacity(n + 16); //TODO: check for overflow
286 *concat.addData(pData->buffer) = 0;
287 pData->length = n;
288 return *this;
290 #endif
293 Release the string data.
295 ~OStringBuffer()
297 rtl_string_release( pData );
301 Fill the string data in the new string and clear the buffer.
303 This method is more efficient than the constructor of the string. It does
304 not copy the buffer.
306 @return the string previously contained in the buffer.
308 SAL_WARN_UNUSED_RESULT OString makeStringAndClear()
310 OString aRet( pData );
311 rtl_string_new(&pData);
312 nCapacity = 0;
313 return aRet;
317 Returns the length (character count) of this string buffer.
319 @return the number of characters in this string buffer.
321 sal_Int32 getLength() const
323 return pData->length;
327 Checks if a string buffer is empty.
329 @return true if the string buffer is empty;
330 false, otherwise.
332 @since LibreOffice 4.1
334 bool isEmpty() const
336 return pData->length == 0;
340 Returns the current capacity of the String buffer.
342 The capacity
343 is the amount of storage available for newly inserted
344 characters. The real buffer size is 2 bytes longer, because
345 all strings are 0 terminated.
347 @return the current capacity of this string buffer.
349 sal_Int32 getCapacity() const
351 return nCapacity;
355 Ensures that the capacity of the buffer is at least equal to the
356 specified minimum.
358 The new capacity will be at least as large as the maximum of the current
359 length (so that no contents of the buffer is destroyed) and the given
360 minimumCapacity. If the given minimumCapacity is negative, nothing is
361 changed.
363 @param minimumCapacity the minimum desired capacity.
365 void ensureCapacity(sal_Int32 minimumCapacity)
367 rtl_stringbuffer_ensureCapacity( &pData, &nCapacity, minimumCapacity );
371 Sets the length of this String buffer.
373 If the <code>newLength</code> argument is less than the current
374 length of the string buffer, the string buffer is truncated to
375 contain exactly the number of characters given by the
376 <code>newLength</code> argument.
378 If the <code>newLength</code> argument is greater than or equal
379 to the current length, sufficient null characters
380 (<code>'&#92;u0000'</code>) are appended to the string buffer so that
381 length becomes the <code>newLength</code> argument.
383 The <code>newLength</code> argument must be greater than or equal
384 to <code>0</code>.
386 @param newLength the new length of the buffer.
388 void setLength(sal_Int32 newLength)
390 assert(newLength >= 0);
391 // Avoid modifications if pData points to const empty string:
392 if( newLength != pData->length )
394 if( newLength > nCapacity )
395 rtl_stringbuffer_ensureCapacity(&pData, &nCapacity, newLength);
396 else
397 pData->buffer[newLength] = '\0';
398 pData->length = newLength;
403 Returns the character at a specific index in this string buffer.
405 The first character of a string buffer is at index
406 <code>0</code>, the next at index <code>1</code>, and so on, for
407 array indexing.
409 The index argument must be greater than or equal to
410 <code>0</code>, and less than the length of this string buffer.
412 @param index the index of the desired character.
413 @return the character at the specified index of this string buffer.
415 SAL_DEPRECATED("use rtl::OStringBuffer::operator [] instead")
416 sal_Char charAt( sal_Int32 index )
418 assert(index >= 0 && index < pData->length);
419 return pData->buffer[ index ];
423 The character at the specified index of this string buffer is set
424 to <code>ch</code>.
426 The index argument must be greater than or equal to
427 <code>0</code>, and less than the length of this string buffer.
429 @param index the index of the character to modify.
430 @param ch the new character.
432 SAL_DEPRECATED("use rtl::OStringBuffer::operator [] instead")
433 OStringBuffer & setCharAt(sal_Int32 index, sal_Char ch)
435 assert(index >= 0 && index < pData->length);
436 pData->buffer[ index ] = ch;
437 return *this;
441 Return a null terminated character array.
443 const sal_Char* getStr() const SAL_RETURNS_NONNULL { return pData->buffer; }
446 Access to individual characters.
448 @param index must be non-negative and less than length.
450 @return a reference to the character at the given index.
452 @since LibreOffice 3.5
454 sal_Char & operator [](sal_Int32 index)
456 assert(index >= 0 && index < pData->length);
457 return pData->buffer[index];
461 Return a OString instance reflecting the current content
462 of this OStringBuffer.
464 const OString toString() const
466 return OString(pData->buffer, pData->length);
470 Appends the string to this string buffer.
472 The characters of the <code>String</code> argument are appended, in
473 order, to the contents of this string buffer, increasing the
474 length of this string buffer by the length of the argument.
476 @param str a string.
477 @return this string buffer.
479 OStringBuffer & append(const OString &str)
481 return append( str.getStr(), str.getLength() );
485 Appends the string representation of the <code>char</code> array
486 argument to this string buffer.
488 The characters of the array argument are appended, in order, to
489 the contents of this string buffer. The length of this string
490 buffer increases by the length of the argument.
492 @param str the characters to be appended.
493 @return this string buffer.
495 template< typename T >
496 typename libreoffice_internal::CharPtrDetector< T, OStringBuffer& >::Type append( const T& str )
498 return append( str, rtl_str_getLength( str ) );
501 template< typename T >
502 typename libreoffice_internal::NonConstCharArrayDetector< T, OStringBuffer& >::Type append( T& str )
504 return append( str, rtl_str_getLength( str ) );
508 @overload
509 This function accepts an ASCII string literal as its argument.
510 @since LibreOffice 3.6
512 template< typename T >
513 typename libreoffice_internal::ConstCharArrayDetector< T, OStringBuffer& >::Type append( T& literal )
515 RTL_STRING_CONST_FUNCTION
516 assert(
517 libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
518 rtl_stringbuffer_insert(
519 &pData, &nCapacity, getLength(),
520 libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
521 libreoffice_internal::ConstCharArrayDetector<T>::length);
522 return *this;
526 Appends the string representation of the <code>char</code> array
527 argument to this string buffer.
529 Characters of the character array <code>str</code> are appended,
530 in order, to the contents of this string buffer. The length of this
531 string buffer increases by the value of <code>len</code>.
533 @param str the characters to be appended; must be non-null, and must
534 point to at least len characters
535 @param len the number of characters to append; must be non-negative
536 @return this string buffer.
538 OStringBuffer & append( const sal_Char * str, sal_Int32 len)
540 assert( len == 0 || str != NULL ); // cannot assert that in rtl_stringbuffer_insert
541 rtl_stringbuffer_insert( &pData, &nCapacity, getLength(), str, len );
542 return *this;
545 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
547 @overload
548 @internal
550 template< typename T1, typename T2 >
551 OStringBuffer& append( OStringConcat< T1, T2 >&& c )
553 sal_Int32 l = c.length();
554 if( l == 0 )
555 return *this;
556 l += pData->length;
557 rtl_stringbuffer_ensureCapacity( &pData, &nCapacity, l );
558 char* end = c.addData( pData->buffer + pData->length );
559 *end = '\0';
560 pData->length = l;
561 return *this;
563 #endif
566 Appends the string representation of the <code>sal_Bool</code>
567 argument to the string buffer.
569 The argument is converted to a string as if by the method
570 <code>String.valueOf</code>, and the characters of that
571 string are then appended to this string buffer.
573 @param b a <code>sal_Bool</code>.
574 @return this string buffer.
576 OStringBuffer & append(sal_Bool b)
578 sal_Char sz[RTL_STR_MAX_VALUEOFBOOLEAN];
579 return append( sz, rtl_str_valueOfBoolean( sz, b ) );
583 Appends the string representation of the <code>bool</code>
584 argument to the string buffer.
586 The argument is converted to a string as if by the method
587 <code>String.valueOf</code>, and the characters of that
588 string are then appended to this string buffer.
590 @param b a <code>bool</code>.
591 @return this string buffer.
593 @since LibreOffice 4.3
595 OStringBuffer & append(bool b)
597 sal_Char sz[RTL_STR_MAX_VALUEOFBOOLEAN];
598 return append( sz, rtl_str_valueOfBoolean( sz, b ) );
601 /// @cond INTERNAL
602 // Pointer can be automatically converted to bool, which is unwanted here.
603 // Explicitly delete all pointer append() overloads to prevent this
604 // (except for char* overload, which is handled elsewhere).
605 template< typename T >
606 typename libreoffice_internal::Enable< void,
607 !libreoffice_internal::CharPtrDetector< T* >::ok >::Type
608 append( T* ) SAL_DELETED_FUNCTION;
609 /// @endcond
612 Appends the string representation of the <code>char</code>
613 argument to this string buffer.
615 The argument is appended to the contents of this string buffer.
616 The length of this string buffer increases by <code>1</code>.
618 @param c a <code>char</code>.
619 @return this string buffer.
621 OStringBuffer & append(sal_Char c)
623 return append( &c, 1 );
627 Appends the string representation of the <code>sal_Int32</code>
628 argument to this string buffer.
630 The argument is converted to a string as if by the method
631 <code>String.valueOf</code>, and the characters of that
632 string are then appended to this string buffer.
634 @param i an <code>sal_Int32</code>.
635 @param radix the radix
636 @return this string buffer.
638 OStringBuffer & append(sal_Int32 i, sal_Int16 radix = 10 )
640 sal_Char sz[RTL_STR_MAX_VALUEOFINT32];
641 return append( sz, rtl_str_valueOfInt32( sz, i, radix ) );
645 Appends the string representation of the <code>long</code>
646 argument to this string buffer.
648 The argument is converted to a string as if by the method
649 <code>String.valueOf</code>, and the characters of that
650 string are then appended to this string buffer.
652 @param l a <code>long</code>.
653 @param radix the radix
654 @return this string buffer.
656 OStringBuffer & append(sal_Int64 l, sal_Int16 radix = 10 )
658 sal_Char sz[RTL_STR_MAX_VALUEOFINT64];
659 return append( sz, rtl_str_valueOfInt64( sz, l, radix ) );
663 Appends the string representation of the <code>float</code>
664 argument to this string buffer.
666 The argument is converted to a string as if by the method
667 <code>String.valueOf</code>, and the characters of that
668 string are then appended to this string buffer.
670 @param f a <code>float</code>.
671 @return this string buffer.
673 OStringBuffer & append(float f)
675 sal_Char sz[RTL_STR_MAX_VALUEOFFLOAT];
676 return append( sz, rtl_str_valueOfFloat( sz, f ) );
680 Appends the string representation of the <code>double</code>
681 argument to this string buffer.
683 The argument is converted to a string as if by the method
684 <code>String.valueOf</code>, and the characters of that
685 string are then appended to this string buffer.
687 @param d a <code>double</code>.
688 @return this string buffer.
690 OStringBuffer & append(double d)
692 sal_Char sz[RTL_STR_MAX_VALUEOFDOUBLE];
693 return append( sz, rtl_str_valueOfDouble( sz, d ) );
697 Unsafe way to make space for a fixed amount of characters to be appended
698 into this OStringBuffer.
700 A call to this function must immediately be followed by code that
701 completely fills the uninitialized block pointed to by the return value.
703 @param length the length of the uninitialized block of char entities;
704 must be non-negative
706 @return a pointer to the start of the uninitialized block; only valid
707 until this OStringBuffer's capacity changes
709 @since LibreOffice 4.4
711 char * appendUninitialized(sal_Int32 length) SAL_RETURNS_NONNULL {
712 sal_Int32 n = getLength();
713 rtl_stringbuffer_insert(&pData, &nCapacity, n, NULL, length);
714 return pData->buffer + n;
718 Inserts the string into this string buffer.
720 The characters of the <code>String</code> argument are inserted, in
721 order, into this string buffer at the indicated offset. The length
722 of this string buffer is increased by the length of the argument.
724 The offset argument must be greater than or equal to
725 <code>0</code>, and less than or equal to the length of this
726 string buffer.
728 @param offset the offset.
729 @param str a string.
730 @return this string buffer.
732 OStringBuffer & insert(sal_Int32 offset, const OString & str)
734 return insert( offset, str.getStr(), str.getLength() );
738 Inserts the string representation of the <code>char</code> array
739 argument into this string buffer.
741 The characters of the array argument are inserted into the
742 contents of this string buffer at the position indicated by
743 <code>offset</code>. The length of this string buffer increases by
744 the length of the argument.
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 str a character array.
752 @return this string buffer.
754 template< typename T >
755 typename libreoffice_internal::CharPtrDetector< T, OStringBuffer& >::Type insert( sal_Int32 offset, const T& str )
757 return insert( offset, str, rtl_str_getLength( str ) );
760 template< typename T >
761 typename libreoffice_internal::NonConstCharArrayDetector< T, OStringBuffer& >::Type insert( sal_Int32 offset, T& str )
763 return insert( offset, str, rtl_str_getLength( str ) );
767 @overload
768 This function accepts an ASCII string literal as its argument.
769 @since LibreOffice 3.6
771 template< typename T >
772 typename libreoffice_internal::ConstCharArrayDetector< T, OStringBuffer& >::Type insert( sal_Int32 offset, T& literal )
774 RTL_STRING_CONST_FUNCTION
775 assert(
776 libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
777 rtl_stringbuffer_insert(
778 &pData, &nCapacity, offset,
779 libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
780 libreoffice_internal::ConstCharArrayDetector<T>::length);
781 return *this;
785 Inserts the string representation of the <code>char</code> array
786 argument into this string buffer.
788 The characters of the array argument are inserted into the
789 contents of this string buffer at the position indicated by
790 <code>offset</code>. The length of this string buffer increases by
791 the length of the argument.
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 str a character array.
799 @param len the number of characters to append.
800 @return this string buffer.
802 OStringBuffer & insert( sal_Int32 offset, const sal_Char * str, sal_Int32 len)
804 assert( len == 0 || str != NULL ); // cannot assert that in rtl_stringbuffer_insert
805 rtl_stringbuffer_insert( &pData, &nCapacity, offset, str, len );
806 return *this;
810 Inserts the string representation of the <code>sal_Bool</code>
811 argument into this string buffer.
813 The second argument is converted to a string as if by the method
814 <code>String.valueOf</code>, and the characters of that
815 string are then inserted into this string buffer at the indicated
816 offset.
818 The offset argument must be greater than or equal to
819 <code>0</code>, and less than or equal to the length of this
820 string buffer.
822 @param offset the offset.
823 @param b a <code>sal_Bool</code>.
824 @return this string buffer.
826 OStringBuffer & insert(sal_Int32 offset, sal_Bool b)
828 sal_Char sz[RTL_STR_MAX_VALUEOFBOOLEAN];
829 return insert( offset, sz, rtl_str_valueOfBoolean( sz, b ) );
833 Inserts the string representation of the <code>bool</code>
834 argument into this string buffer.
836 The second argument is converted to a string as if by the method
837 <code>OString::boolean</code>, and the characters of that
838 string are then inserted into this string buffer at the indicated
839 offset.
841 The offset argument must be greater than or equal to
842 <code>0</code>, and less than or equal to the length of this
843 string buffer.
845 @param offset the offset.
846 @param b a <code>bool</code>.
847 @return this string buffer.
849 @since LibreOffice 4.3
851 OStringBuffer & insert(sal_Int32 offset, bool b)
853 sal_Char sz[RTL_STR_MAX_VALUEOFBOOLEAN];
854 return insert( offset, sz, rtl_str_valueOfBoolean( sz, b ) );
858 Inserts the string representation of the <code>char</code>
859 argument into this string buffer.
861 The second argument is inserted into the contents of this string
862 buffer at the position indicated by <code>offset</code>. The length
863 of this string buffer increases by one.
865 The offset argument must be greater than or equal to
866 <code>0</code>, and less than or equal to the length of this
867 string buffer.
869 @param offset the offset.
870 @param c a <code>char</code>.
871 @return this string buffer.
873 OStringBuffer & insert(sal_Int32 offset, sal_Char c)
875 return insert( offset, &c, 1 );
879 Inserts the string representation of the second <code>sal_Int32</code>
880 argument into this string buffer.
882 The second argument is converted to a string as if by the method
883 <code>String.valueOf</code>, and the characters of that
884 string are then inserted into this string buffer at the indicated
885 offset.
887 The offset argument must be greater than or equal to
888 <code>0</code>, and less than or equal to the length of this
889 string buffer.
891 @param offset the offset.
892 @param i an <code>sal_Int32</code>.
893 @param radix the radix
894 @return this string buffer.
896 OStringBuffer & insert(sal_Int32 offset, sal_Int32 i, sal_Int16 radix = 10 )
898 sal_Char sz[RTL_STR_MAX_VALUEOFINT32];
899 return insert( offset, sz, rtl_str_valueOfInt32( sz, i, radix ) );
903 Inserts the string representation of the <code>long</code>
904 argument into this string buffer.
906 The second argument is converted to a string as if by the method
907 <code>String.valueOf</code>, and the characters of that
908 string are then inserted into this string buffer at the indicated
909 offset.
911 The offset argument must be greater than or equal to
912 <code>0</code>, and less than or equal to the length of this
913 string buffer.
915 @param offset the offset.
916 @param l a <code>long</code>.
917 @param radix the radix
918 @return this string buffer.
920 OStringBuffer & insert(sal_Int32 offset, sal_Int64 l, sal_Int16 radix = 10 )
922 sal_Char sz[RTL_STR_MAX_VALUEOFINT64];
923 return insert( offset, sz, rtl_str_valueOfInt64( sz, l, radix ) );
927 Inserts the string representation of the <code>float</code>
928 argument into this string buffer.
930 The second argument is converted to a string as if by the method
931 <code>String.valueOf</code>, and the characters of that
932 string are then inserted into this string buffer at the indicated
933 offset.
935 The offset argument must be greater than or equal to
936 <code>0</code>, and less than or equal to the length of this
937 string buffer.
939 @param offset the offset.
940 @param f a <code>float</code>.
941 @return this string buffer.
943 OStringBuffer insert(sal_Int32 offset, float f)
945 sal_Char sz[RTL_STR_MAX_VALUEOFFLOAT];
946 return insert( offset, sz, rtl_str_valueOfFloat( sz, f ) );
950 Inserts the string representation of the <code>double</code>
951 argument into this string buffer.
953 The second argument is converted to a string as if by the method
954 <code>String.valueOf</code>, and the characters of that
955 string are then inserted into this string buffer at the indicated
956 offset.
958 The offset argument must be greater than or equal to
959 <code>0</code>, and less than or equal to the length of this
960 string buffer.
962 @param offset the offset.
963 @param d a <code>double</code>.
964 @return this string buffer.
966 OStringBuffer & insert(sal_Int32 offset, double d)
968 sal_Char sz[RTL_STR_MAX_VALUEOFDOUBLE];
969 return insert( offset, sz, rtl_str_valueOfDouble( sz, d ) );
973 Removes the characters in a substring of this sequence.
975 The substring begins at the specified <code>start</code> and
976 is <code>len</code> characters long.
978 start must be >= 0 && <= getLength() && <= end
980 @param start The beginning index, inclusive
981 @param len The substring length
982 @return this string buffer.
984 OStringBuffer & remove( sal_Int32 start, sal_Int32 len )
986 rtl_stringbuffer_remove( &pData, start, len );
987 return *this;
990 /** Allows access to the internal data of this OStringBuffer, for effective
991 manipulation.
993 This function should be used with care. After you have called this
994 function, you may use the returned pInternalData and pInternalCapacity
995 only as long as you make no other calls on this OUStringBuffer.
997 @param pInternalData
998 This output parameter receives a pointer to the internal data
999 (rtl_String pointer). pInternalData itself must not be null.
1001 @param pInternalCapacity
1002 This output parameter receives a pointer to the internal capacity.
1003 pInternalCapacity itself must not be null.
1005 @since LibreOffice 5.4
1007 void accessInternals(
1008 rtl_String *** pInternalData, sal_Int32 ** pInternalCapacity)
1010 *pInternalData = &pData;
1011 *pInternalCapacity = &nCapacity;
1014 private:
1016 A pointer to the data structure which contains the data.
1018 rtl_String * pData;
1021 The len of the pData->buffer.
1023 sal_Int32 nCapacity;
1028 #ifdef RTL_STRING_UNITTEST
1029 namespace rtl
1031 typedef rtlunittest::OStringBuffer OStringBuffer;
1033 #undef RTL_STRING_CONST_FUNCTION
1034 #endif
1036 #if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST
1037 using ::rtl::OStringBuffer;
1038 #endif
1040 #endif // INCLUDED_RTL_STRBUF_HXX
1043 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */