Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / include / rtl / strbuf.hxx
blob791eb142f9dcce765210bbd44ab51818f693d30a
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 <cstddef>
27 #include <cstring>
29 #include <rtl/strbuf.h>
30 #include <rtl/string.hxx>
31 #include <rtl/stringutils.hxx>
33 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
34 #include <rtl/stringconcat.hxx>
35 #endif
37 #ifdef RTL_STRING_UNITTEST
38 extern bool rtl_string_unittest_const_literal;
39 extern bool rtl_string_unittest_const_literal_function;
40 #endif
42 // The unittest uses slightly different code to help check that the proper
43 // calls are made. The class is put into a different namespace to make
44 // sure the compiler generates a different (if generating also non-inline)
45 // copy of the function and does not merge them together. The class
46 // is "brought" into the proper rtl namespace by a typedef below.
47 #ifdef RTL_STRING_UNITTEST
48 #define rtl rtlunittest
49 #endif
51 namespace rtl
54 /// @cond INTERNAL
55 #ifdef RTL_STRING_UNITTEST
56 #undef rtl
57 // helper macro to make functions appear more readable
58 #define RTL_STRING_CONST_FUNCTION rtl_string_unittest_const_literal_function = true;
59 #else
60 #define RTL_STRING_CONST_FUNCTION
61 #endif
62 /// @endcond
64 /** A string buffer implements a mutable sequence of characters.
66 class SAL_WARN_UNUSED OStringBuffer
68 public:
69 /**
70 Constructs a string buffer with no characters in it and an
71 initial capacity of 16 characters.
73 OStringBuffer()
74 : pData(NULL)
75 , nCapacity( 16 )
77 rtl_string_new_WithLength( &pData, nCapacity );
80 /**
81 Allocates a new string buffer that contains the same sequence of
82 characters as the string buffer argument.
84 @param value a <code>OStringBuffer</code>.
86 OStringBuffer( const OStringBuffer & value )
87 : pData(NULL)
88 , nCapacity( value.nCapacity )
90 rtl_stringbuffer_newFromStringBuffer( &pData, value.nCapacity, value.pData );
93 /**
94 Constructs a string buffer with no characters in it and an
95 initial capacity specified by the <code>length</code> argument.
97 @param length the initial capacity.
99 explicit OStringBuffer(int length)
100 : pData(NULL)
101 , nCapacity( length )
103 rtl_string_new_WithLength( &pData, length );
105 #if __cplusplus >= 201103L
106 explicit OStringBuffer(unsigned int length)
107 : OStringBuffer(static_cast<int>(length))
110 #if SAL_TYPES_SIZEOFLONG == 4
111 // additional overloads for sal_Int32 sal_uInt32
112 explicit OStringBuffer(long length)
113 : OStringBuffer(static_cast<int>(length))
116 explicit OStringBuffer(unsigned long length)
117 : OStringBuffer(static_cast<int>(length))
120 #endif
121 // avoid obvious bugs
122 explicit OStringBuffer(char) = delete;
123 explicit OStringBuffer(sal_Unicode) = delete;
124 #endif
127 Constructs a string buffer so that it represents the same
128 sequence of characters as the string argument.
130 The initial
131 capacity of the string buffer is <code>16</code> plus the length
132 of the string argument.
134 @param value the initial string value.
136 OStringBuffer(const OString& value)
137 : pData(NULL)
138 , nCapacity( value.getLength() + 16 )
140 rtl_stringbuffer_newFromStr_WithLength( &pData, value.getStr(), value.getLength() );
144 @overload
145 @since LibreOffice 3.6
147 template< typename T >
148 OStringBuffer( const T& value, typename libreoffice_internal::CharPtrDetector< T, libreoffice_internal::Dummy >::Type = libreoffice_internal::Dummy())
149 : pData(NULL)
151 sal_Int32 length = rtl_str_getLength( value );
152 nCapacity = length + 16;
153 rtl_stringbuffer_newFromStr_WithLength( &pData, value, length );
156 template< typename T >
157 OStringBuffer( T& value, typename libreoffice_internal::NonConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type = libreoffice_internal::Dummy())
158 : pData(NULL)
160 sal_Int32 length = rtl_str_getLength( value );
161 nCapacity = length + 16;
162 rtl_stringbuffer_newFromStr_WithLength( &pData, value, length );
166 Constructs a string buffer so that it represents the same
167 sequence of characters as the string literal.
169 If there are any embedded \0's in the string literal, the result is undefined.
170 Use the overload that explicitly accepts length.
172 @since LibreOffice 3.6
174 @param literal a string literal
176 template< typename T >
177 OStringBuffer( T& literal, typename libreoffice_internal::ConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type = libreoffice_internal::Dummy())
178 : pData(NULL)
179 , nCapacity( libreoffice_internal::ConstCharArrayDetector<T>::length + 16 )
181 assert(
182 libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
183 rtl_string_newFromLiteral(
184 &pData,
185 libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
186 libreoffice_internal::ConstCharArrayDetector<T>::length, 16);
187 #ifdef RTL_STRING_UNITTEST
188 rtl_string_unittest_const_literal = true;
189 #endif
193 Constructs a string buffer so that it represents the same
194 sequence of characters as the string argument.
196 The initial
197 capacity of the string buffer is <code>16</code> plus length
199 @param value a character array.
200 @param length the number of character which should be copied.
201 The character array length must be greater or
202 equal than this value.
204 OStringBuffer(const sal_Char * value, sal_Int32 length)
205 : pData(NULL)
206 , nCapacity( length + 16 )
208 rtl_stringbuffer_newFromStr_WithLength( &pData, value, length );
211 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
213 @overload
214 @internal
216 template< typename T1, typename T2 >
217 OStringBuffer( const OStringConcat< T1, T2 >& c )
219 const sal_Int32 l = c.length();
220 nCapacity = l + 16;
221 pData = rtl_string_alloc( nCapacity );
222 char* end = c.addData( pData->buffer );
223 *end = '\0';
224 pData->length = l;
226 #endif
228 /** Assign to this a copy of value.
230 OStringBuffer& operator = ( const OStringBuffer& value )
232 if (this != &value)
234 rtl_stringbuffer_newFromStringBuffer(&pData,
235 value.nCapacity,
236 value.pData);
237 nCapacity = value.nCapacity;
239 return *this;
242 /** Assign from a string.
244 @since LibreOffice 5.3
246 OStringBuffer & operator =(OString const & string) {
247 sal_Int32 n = string.getLength();
248 if (n >= nCapacity) {
249 ensureCapacity(n + 16); //TODO: check for overflow
251 std::memcpy(pData->buffer, string.pData->buffer, n + 1);
252 pData->length = n;
253 return *this;
256 /** Assign from a string literal.
258 @since LibreOffice 5.3
260 template<typename T>
261 typename
262 libreoffice_internal::ConstCharArrayDetector<T, OStringBuffer &>::Type
263 operator =(T & literal) {
264 assert(
265 libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
266 sal_Int32 const n
267 = libreoffice_internal::ConstCharArrayDetector<T>::length;
268 if (n >= nCapacity) {
269 ensureCapacity(n + 16); //TODO: check for overflow
271 std::memcpy(
272 pData->buffer,
273 libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
274 n + 1);
275 pData->length = n;
276 return *this;
279 #if defined LIBO_INTERNAL_ONLY
280 /** @overload @since LibreOffice 5.3 */
281 template<typename T1, typename T2>
282 OStringBuffer & operator =(OStringConcat<T1, T2> const & concat) {
283 sal_Int32 const n = concat.length();
284 if (n >= nCapacity) {
285 ensureCapacity(n + 16); //TODO: check for overflow
287 *concat.addData(pData->buffer) = 0;
288 pData->length = n;
289 return *this;
291 #endif
294 Release the string data.
296 ~OStringBuffer()
298 rtl_string_release( pData );
302 Fill the string data in the new string and clear the buffer.
304 This method is more efficient than the constructor of the string. It does
305 not copy the buffer.
307 @return the string previously contained in the buffer.
309 SAL_WARN_UNUSED_RESULT OString makeStringAndClear()
311 OString aRet( pData );
312 rtl_string_new(&pData);
313 nCapacity = 0;
314 return aRet;
318 Returns the length (character count) of this string buffer.
320 @return the number of characters in this string buffer.
322 sal_Int32 getLength() const
324 return pData->length;
328 Checks if a string buffer is empty.
330 @return true if the string buffer is empty;
331 false, otherwise.
333 @since LibreOffice 4.1
335 bool isEmpty() const
337 return pData->length == 0;
341 Returns the current capacity of the String buffer.
343 The capacity
344 is the amount of storage available for newly inserted
345 characters. The real buffer size is 2 bytes longer, because
346 all strings are 0 terminated.
348 @return the current capacity of this string buffer.
350 sal_Int32 getCapacity() const
352 return nCapacity;
356 Ensures that the capacity of the buffer is at least equal to the
357 specified minimum.
359 The new capacity will be at least as large as the maximum of the current
360 length (so that no contents of the buffer is destroyed) and the given
361 minimumCapacity. If the given minimumCapacity is negative, nothing is
362 changed.
364 @param minimumCapacity the minimum desired capacity.
366 void ensureCapacity(sal_Int32 minimumCapacity)
368 rtl_stringbuffer_ensureCapacity( &pData, &nCapacity, minimumCapacity );
372 Sets the length of this String buffer.
374 If the <code>newLength</code> argument is less than the current
375 length of the string buffer, the string buffer is truncated to
376 contain exactly the number of characters given by the
377 <code>newLength</code> argument.
379 If the <code>newLength</code> argument is greater than or equal
380 to the current length, sufficient null characters
381 (<code>'&#92;u0000'</code>) are appended to the string buffer so that
382 length becomes the <code>newLength</code> argument.
384 The <code>newLength</code> argument must be greater than or equal
385 to <code>0</code>.
387 @param newLength the new length of the buffer.
389 void setLength(sal_Int32 newLength)
391 assert(newLength >= 0);
392 // Avoid modifications if pData points to const empty string:
393 if( newLength != pData->length )
395 if( newLength > nCapacity )
396 rtl_stringbuffer_ensureCapacity(&pData, &nCapacity, newLength);
397 else
398 pData->buffer[newLength] = '\0';
399 pData->length = newLength;
404 Returns the character at a specific index in this string buffer.
406 The first character of a string buffer is at index
407 <code>0</code>, the next at index <code>1</code>, and so on, for
408 array indexing.
410 The index argument must be greater than or equal to
411 <code>0</code>, and less than the length of this string buffer.
413 @param index the index of the desired character.
414 @return the character at the specified index of this string buffer.
416 SAL_DEPRECATED("use rtl::OStringBuffer::operator [] instead")
417 sal_Char charAt( sal_Int32 index )
419 assert(index >= 0 && index < pData->length);
420 return pData->buffer[ index ];
424 The character at the specified index of this string buffer is set
425 to <code>ch</code>.
427 The index argument must be greater than or equal to
428 <code>0</code>, and less than the length of this string buffer.
430 @param index the index of the character to modify.
431 @param ch the new character.
433 SAL_DEPRECATED("use rtl::OStringBuffer::operator [] instead")
434 OStringBuffer & setCharAt(sal_Int32 index, sal_Char ch)
436 assert(index >= 0 && index < pData->length);
437 pData->buffer[ index ] = ch;
438 return *this;
442 Return a null terminated character array.
444 const sal_Char* getStr() const { return pData->buffer; }
447 Access to individual characters.
449 @param index must be non-negative and less than length.
451 @return a reference to the character at the given index.
453 @since LibreOffice 3.5
455 sal_Char & operator [](sal_Int32 index)
457 assert(index >= 0 && index < pData->length);
458 return pData->buffer[index];
462 Return a OString instance reflecting the current content
463 of this OStringBuffer.
465 const OString toString() const
467 return OString(pData->buffer, pData->length);
471 Appends the string to this string buffer.
473 The characters of the <code>String</code> argument are appended, in
474 order, to the contents of this string buffer, increasing the
475 length of this string buffer by the length of the argument.
477 @param str a string.
478 @return this string buffer.
480 OStringBuffer & append(const OString &str)
482 return append( str.getStr(), str.getLength() );
486 Appends the string representation of the <code>char</code> array
487 argument to this string buffer.
489 The characters of the array argument are appended, in order, to
490 the contents of this string buffer. The length of this string
491 buffer increases by the length of the argument.
493 @param str the characters to be appended.
494 @return this string buffer.
496 template< typename T >
497 typename libreoffice_internal::CharPtrDetector< T, OStringBuffer& >::Type append( const T& str )
499 return append( str, rtl_str_getLength( str ) );
502 template< typename T >
503 typename libreoffice_internal::NonConstCharArrayDetector< T, OStringBuffer& >::Type append( T& str )
505 return append( str, rtl_str_getLength( str ) );
509 @overload
510 This function accepts an ASCII string literal as its argument.
511 @since LibreOffice 3.6
513 template< typename T >
514 typename libreoffice_internal::ConstCharArrayDetector< T, OStringBuffer& >::Type append( T& literal )
516 RTL_STRING_CONST_FUNCTION
517 assert(
518 libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
519 rtl_stringbuffer_insert(
520 &pData, &nCapacity, getLength(),
521 libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
522 libreoffice_internal::ConstCharArrayDetector<T>::length);
523 return *this;
527 Appends the string representation of the <code>char</code> array
528 argument to this string buffer.
530 Characters of the character array <code>str</code> are appended,
531 in order, to the contents of this string buffer. The length of this
532 string buffer increases by the value of <code>len</code>.
534 @param str the characters to be appended; must be non-null, and must
535 point to at least len characters
536 @param len the number of characters to append; must be non-negative
537 @return this string buffer.
539 OStringBuffer & append( const sal_Char * str, sal_Int32 len)
541 assert( len == 0 || str != NULL ); // cannot assert that in rtl_stringbuffer_insert
542 rtl_stringbuffer_insert( &pData, &nCapacity, getLength(), str, len );
543 return *this;
546 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
548 @overload
549 @internal
551 template< typename T1, typename T2 >
552 OStringBuffer& append( const OStringConcat< T1, T2 >& c )
554 sal_Int32 l = c.length();
555 if( l == 0 )
556 return *this;
557 l += pData->length;
558 rtl_stringbuffer_ensureCapacity( &pData, &nCapacity, l );
559 char* end = c.addData( pData->buffer + pData->length );
560 *end = '\0';
561 pData->length = l;
562 return *this;
564 #endif
567 Appends the string representation of the <code>sal_Bool</code>
568 argument to the string buffer.
570 The argument is converted to a string as if by the method
571 <code>String.valueOf</code>, and the characters of that
572 string are then appended to this string buffer.
574 @param b a <code>sal_Bool</code>.
575 @return this string buffer.
577 OStringBuffer & append(sal_Bool b)
579 sal_Char sz[RTL_STR_MAX_VALUEOFBOOLEAN];
580 return append( sz, rtl_str_valueOfBoolean( sz, b ) );
584 Appends the string representation of the <code>bool</code>
585 argument to the string buffer.
587 The argument is converted to a string as if by the method
588 <code>String.valueOf</code>, and the characters of that
589 string are then appended to this string buffer.
591 @param b a <code>bool</code>.
592 @return this string buffer.
594 @since LibreOffice 4.3
596 OStringBuffer & append(bool b)
598 sal_Char sz[RTL_STR_MAX_VALUEOFBOOLEAN];
599 return append( sz, rtl_str_valueOfBoolean( sz, b ) );
602 /// @cond INTERNAL
603 // Pointer can be automatically converted to bool, which is unwanted here.
604 // Explicitly delete all pointer append() overloads to prevent this
605 // (except for char* overload, which is handled elsewhere).
606 template< typename T >
607 typename libreoffice_internal::Enable< void,
608 !libreoffice_internal::CharPtrDetector< T* >::ok >::Type
609 append( T* ) SAL_DELETED_FUNCTION;
610 /// @endcond
613 Appends the string representation of the <code>char</code>
614 argument to this string buffer.
616 The argument is appended to the contents of this string buffer.
617 The length of this string buffer increases by <code>1</code>.
619 @param c a <code>char</code>.
620 @return this string buffer.
622 OStringBuffer & append(sal_Char c)
624 return append( &c, 1 );
628 Appends the string representation of the <code>sal_Int32</code>
629 argument to this string buffer.
631 The argument is converted to a string as if by the method
632 <code>String.valueOf</code>, and the characters of that
633 string are then appended to this string buffer.
635 @param i an <code>sal_Int32</code>.
636 @param radix the radix
637 @return this string buffer.
639 OStringBuffer & append(sal_Int32 i, sal_Int16 radix = 10 )
641 sal_Char sz[RTL_STR_MAX_VALUEOFINT32];
642 return append( sz, rtl_str_valueOfInt32( sz, i, radix ) );
646 Appends the string representation of the <code>long</code>
647 argument to this string buffer.
649 The argument is converted to a string as if by the method
650 <code>String.valueOf</code>, and the characters of that
651 string are then appended to this string buffer.
653 @param l a <code>long</code>.
654 @param radix the radix
655 @return this string buffer.
657 OStringBuffer & append(sal_Int64 l, sal_Int16 radix = 10 )
659 sal_Char sz[RTL_STR_MAX_VALUEOFINT64];
660 return append( sz, rtl_str_valueOfInt64( sz, l, radix ) );
664 Appends the string representation of the <code>float</code>
665 argument to this string buffer.
667 The argument is converted to a string as if by the method
668 <code>String.valueOf</code>, and the characters of that
669 string are then appended to this string buffer.
671 @param f a <code>float</code>.
672 @return this string buffer.
674 OStringBuffer & append(float f)
676 sal_Char sz[RTL_STR_MAX_VALUEOFFLOAT];
677 return append( sz, rtl_str_valueOfFloat( sz, f ) );
681 Appends the string representation of the <code>double</code>
682 argument to this string buffer.
684 The argument is converted to a string as if by the method
685 <code>String.valueOf</code>, and the characters of that
686 string are then appended to this string buffer.
688 @param d a <code>double</code>.
689 @return this string buffer.
691 OStringBuffer & append(double d)
693 sal_Char sz[RTL_STR_MAX_VALUEOFDOUBLE];
694 return append( sz, rtl_str_valueOfDouble( sz, d ) );
698 Unsafe way to make space for a fixed amount of characters to be appended
699 into this OStringBuffer.
701 A call to this function must immediately be followed by code that
702 completely fills the uninitialized block pointed to by the return value.
704 @param length the length of the uninitialized block of char entities;
705 must be non-negative
707 @return a pointer to the start of the uninitialized block; only valid
708 until this OStringBuffer's capacity changes
710 @since LibreOffice 4.4
712 char * appendUninitialized(sal_Int32 length) {
713 sal_Int32 n = getLength();
714 rtl_stringbuffer_insert(&pData, &nCapacity, n, NULL, length);
715 return pData->buffer + n;
719 Inserts the string into this string buffer.
721 The characters of the <code>String</code> argument are inserted, in
722 order, into this string buffer at the indicated offset. The length
723 of this string buffer is increased by the length of the argument.
725 The offset argument must be greater than or equal to
726 <code>0</code>, and less than or equal to the length of this
727 string buffer.
729 @param offset the offset.
730 @param str a string.
731 @return this string buffer.
733 OStringBuffer & insert(sal_Int32 offset, const OString & str)
735 return insert( offset, str.getStr(), str.getLength() );
739 Inserts the string representation of the <code>char</code> array
740 argument into this string buffer.
742 The characters of the array argument are inserted into the
743 contents of this string buffer at the position indicated by
744 <code>offset</code>. The length of this string buffer increases by
745 the length of the argument.
747 The offset argument must be greater than or equal to
748 <code>0</code>, and less than or equal to the length of this
749 string buffer.
751 @param offset the offset.
752 @param str a character array.
753 @return this string buffer.
755 template< typename T >
756 typename libreoffice_internal::CharPtrDetector< T, OStringBuffer& >::Type insert( sal_Int32 offset, const T& str )
758 return insert( offset, str, rtl_str_getLength( str ) );
761 template< typename T >
762 typename libreoffice_internal::NonConstCharArrayDetector< T, OStringBuffer& >::Type insert( sal_Int32 offset, T& str )
764 return insert( offset, str, rtl_str_getLength( str ) );
768 @overload
769 This function accepts an ASCII string literal as its argument.
770 @since LibreOffice 3.6
772 template< typename T >
773 typename libreoffice_internal::ConstCharArrayDetector< T, OStringBuffer& >::Type insert( sal_Int32 offset, T& literal )
775 RTL_STRING_CONST_FUNCTION
776 assert(
777 libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
778 rtl_stringbuffer_insert(
779 &pData, &nCapacity, offset,
780 libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
781 libreoffice_internal::ConstCharArrayDetector<T>::length);
782 return *this;
786 Inserts the string representation of the <code>char</code> array
787 argument into this string buffer.
789 The characters of the array argument are inserted into the
790 contents of this string buffer at the position indicated by
791 <code>offset</code>. The length of this string buffer increases by
792 the length of the argument.
794 The offset argument must be greater than or equal to
795 <code>0</code>, and less than or equal to the length of this
796 string buffer.
798 @param offset the offset.
799 @param str a character array.
800 @param len the number of characters to append.
801 @return this string buffer.
803 OStringBuffer & insert( sal_Int32 offset, const sal_Char * str, sal_Int32 len)
805 assert( len == 0 || str != NULL ); // cannot assert that in rtl_stringbuffer_insert
806 rtl_stringbuffer_insert( &pData, &nCapacity, offset, str, len );
807 return *this;
811 Inserts the string representation of the <code>sal_Bool</code>
812 argument into this string buffer.
814 The second argument is converted to a string as if by the method
815 <code>String.valueOf</code>, and the characters of that
816 string are then inserted into this string buffer at the indicated
817 offset.
819 The offset argument must be greater than or equal to
820 <code>0</code>, and less than or equal to the length of this
821 string buffer.
823 @param offset the offset.
824 @param b a <code>sal_Bool</code>.
825 @return this string buffer.
827 OStringBuffer & insert(sal_Int32 offset, sal_Bool b)
829 sal_Char sz[RTL_STR_MAX_VALUEOFBOOLEAN];
830 return insert( offset, sz, rtl_str_valueOfBoolean( sz, b ) );
834 Inserts the string representation of the <code>bool</code>
835 argument into this string buffer.
837 The second argument is converted to a string as if by the method
838 <code>OString::boolean</code>, and the characters of that
839 string are then inserted into this string buffer at the indicated
840 offset.
842 The offset argument must be greater than or equal to
843 <code>0</code>, and less than or equal to the length of this
844 string buffer.
846 @param offset the offset.
847 @param b a <code>bool</code>.
848 @return this string buffer.
850 @since LibreOffice 4.3
852 OStringBuffer & insert(sal_Int32 offset, bool b)
854 sal_Char sz[RTL_STR_MAX_VALUEOFBOOLEAN];
855 return insert( offset, sz, rtl_str_valueOfBoolean( sz, b ) );
859 Inserts the string representation of the <code>char</code>
860 argument into this string buffer.
862 The second argument is inserted into the contents of this string
863 buffer at the position indicated by <code>offset</code>. The length
864 of this string buffer increases by one.
866 The offset argument must be greater than or equal to
867 <code>0</code>, and less than or equal to the length of this
868 string buffer.
870 @param offset the offset.
871 @param c a <code>char</code>.
872 @return this string buffer.
874 OStringBuffer & insert(sal_Int32 offset, sal_Char c)
876 return insert( offset, &c, 1 );
880 Inserts the string representation of the second <code>sal_Int32</code>
881 argument into this string buffer.
883 The second argument is converted to a string as if by the method
884 <code>String.valueOf</code>, and the characters of that
885 string are then inserted into this string buffer at the indicated
886 offset.
888 The offset argument must be greater than or equal to
889 <code>0</code>, and less than or equal to the length of this
890 string buffer.
892 @param offset the offset.
893 @param i an <code>sal_Int32</code>.
894 @param radix the radix
895 @return this string buffer.
897 OStringBuffer & insert(sal_Int32 offset, sal_Int32 i, sal_Int16 radix = 10 )
899 sal_Char sz[RTL_STR_MAX_VALUEOFINT32];
900 return insert( offset, sz, rtl_str_valueOfInt32( sz, i, radix ) );
904 Inserts the string representation of the <code>long</code>
905 argument into this string buffer.
907 The second argument is converted to a string as if by the method
908 <code>String.valueOf</code>, and the characters of that
909 string are then inserted into this string buffer at the indicated
910 offset.
912 The offset argument must be greater than or equal to
913 <code>0</code>, and less than or equal to the length of this
914 string buffer.
916 @param offset the offset.
917 @param l a <code>long</code>.
918 @param radix the radix
919 @return this string buffer.
921 OStringBuffer & insert(sal_Int32 offset, sal_Int64 l, sal_Int16 radix = 10 )
923 sal_Char sz[RTL_STR_MAX_VALUEOFINT64];
924 return insert( offset, sz, rtl_str_valueOfInt64( sz, l, radix ) );
928 Inserts the string representation of the <code>float</code>
929 argument into this string buffer.
931 The second argument is converted to a string as if by the method
932 <code>String.valueOf</code>, and the characters of that
933 string are then inserted into this string buffer at the indicated
934 offset.
936 The offset argument must be greater than or equal to
937 <code>0</code>, and less than or equal to the length of this
938 string buffer.
940 @param offset the offset.
941 @param f a <code>float</code>.
942 @return this string buffer.
944 OStringBuffer insert(sal_Int32 offset, float f)
946 sal_Char sz[RTL_STR_MAX_VALUEOFFLOAT];
947 return insert( offset, sz, rtl_str_valueOfFloat( sz, f ) );
951 Inserts the string representation of the <code>double</code>
952 argument into this string buffer.
954 The second argument is converted to a string as if by the method
955 <code>String.valueOf</code>, and the characters of that
956 string are then inserted into this string buffer at the indicated
957 offset.
959 The offset argument must be greater than or equal to
960 <code>0</code>, and less than or equal to the length of this
961 string buffer.
963 @param offset the offset.
964 @param d a <code>double</code>.
965 @return this string buffer.
967 OStringBuffer & insert(sal_Int32 offset, double d)
969 sal_Char sz[RTL_STR_MAX_VALUEOFDOUBLE];
970 return insert( offset, sz, rtl_str_valueOfDouble( sz, d ) );
974 Removes the characters in a substring of this sequence.
976 The substring begins at the specified <code>start</code> and
977 is <code>len</code> characters long.
979 start must be >= 0 && <= getLength() && <= end
981 @param start The beginning index, inclusive
982 @param len The substring length
983 @return this string buffer.
985 OStringBuffer & remove( sal_Int32 start, sal_Int32 len )
987 rtl_stringbuffer_remove( &pData, start, len );
988 return *this;
991 /** Allows access to the internal data of this OStringBuffer, for effective
992 manipulation.
994 This function should be used with care. After you have called this
995 function, you may use the returned pInternalData and pInternalCapacity
996 only as long as you make no other calls on this OUStringBuffer.
998 @param pInternalData
999 This output parameter receives a pointer to the internal data
1000 (rtl_String pointer). pInternalData itself must not be null.
1002 @param pInternalCapacity
1003 This output parameter receives a pointer to the internal capacity.
1004 pInternalCapacity itself must not be null.
1006 @since LibreOffice 5.4
1008 void accessInternals(
1009 rtl_String *** pInternalData, sal_Int32 ** pInternalCapacity)
1011 *pInternalData = &pData;
1012 *pInternalCapacity = &nCapacity;
1015 private:
1017 A pointer to the data structure which contains the data.
1019 rtl_String * pData;
1022 The len of the pData->buffer.
1024 sal_Int32 nCapacity;
1029 #ifdef RTL_STRING_UNITTEST
1030 namespace rtl
1032 typedef rtlunittest::OStringBuffer OStringBuffer;
1034 #undef RTL_STRING_CONST_FUNCTION
1035 #endif
1037 #if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST
1038 using ::rtl::OStringBuffer;
1039 #endif
1041 #endif // INCLUDED_RTL_STRBUF_HXX
1044 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */