1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
21 * This file is part of LibreOffice published API.
26 #include "sal/config.h"
32 #include "rtl/strbuf.h"
33 #include "rtl/string.hxx"
34 #include "rtl/stringutils.hxx"
36 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
37 #include "rtl/stringconcat.hxx"
38 #include <string_view>
39 #include <type_traits>
42 #ifdef RTL_STRING_UNITTEST
43 extern bool rtl_string_unittest_const_literal
;
44 extern bool rtl_string_unittest_const_literal_function
;
47 // The unittest uses slightly different code to help check that the proper
48 // calls are made. The class is put into a different namespace to make
49 // sure the compiler generates a different (if generating also non-inline)
50 // copy of the function and does not merge them together. The class
51 // is "brought" into the proper rtl namespace by a typedef below.
52 #ifdef RTL_STRING_UNITTEST
53 #define rtl rtlunittest
60 #ifdef RTL_STRING_UNITTEST
62 // helper macro to make functions appear more readable
63 #define RTL_STRING_CONST_FUNCTION rtl_string_unittest_const_literal_function = true;
65 #define RTL_STRING_CONST_FUNCTION
69 /** A string buffer implements a mutable sequence of characters.
71 class SAL_WARN_UNUSED OStringBuffer
75 Constructs a string buffer with no characters in it and an
76 initial capacity of 16 characters.
82 rtl_string_new_WithLength( &pData
, nCapacity
);
86 Allocates a new string buffer that contains the same sequence of
87 characters as the string buffer argument.
89 @param value a <code>OStringBuffer</code>.
91 OStringBuffer( const OStringBuffer
& value
)
93 , nCapacity( value
.nCapacity
)
95 rtl_stringbuffer_newFromStringBuffer( &pData
, value
.nCapacity
, value
.pData
);
99 Constructs a string buffer with no characters in it and an
100 initial capacity specified by the <code>length</code> argument.
102 @param length the initial capacity.
104 explicit OStringBuffer(sal_Int32 length
)
106 , nCapacity( length
)
108 rtl_string_new_WithLength( &pData
, length
);
110 #if defined LIBO_INTERNAL_ONLY
112 explicit OStringBuffer(T length
, std::enable_if_t
<std::is_integral_v
<T
>, int> = 0)
113 : OStringBuffer(static_cast<sal_Int32
>(length
))
117 && static_cast<std::make_unsigned_t
<T
>>(length
)
118 <= static_cast<std::make_unsigned_t
<sal_Int32
>>(
119 std::numeric_limits
<sal_Int32
>::max()));
121 // avoid (obvious) bugs
122 explicit OStringBuffer(bool) = delete;
123 explicit OStringBuffer(char) = delete;
124 explicit OStringBuffer(wchar_t) = delete;
125 #if defined __cpp_char8_t
126 explicit OStringBuffer(char8_t
) = delete;
128 explicit OStringBuffer(char16_t
) = delete;
129 explicit OStringBuffer(char32_t
) = delete;
133 Constructs a string buffer so that it represents the same
134 sequence of characters as the string argument.
137 capacity of the string buffer is <code>16</code> plus the length
138 of the string argument.
140 @param value the initial string value.
142 #if defined LIBO_INTERNAL_ONLY
143 OStringBuffer(std::string_view sv
)
145 , nCapacity( sv
.length() + 16 )
147 if (sv
.size() > sal_uInt32(std::numeric_limits
<sal_Int32
>::max())) {
148 throw std::bad_alloc();
150 rtl_stringbuffer_newFromStr_WithLength( &pData
, sv
.data(), sv
.length() );
153 OStringBuffer(const OString
& value
)
155 , nCapacity( value
.getLength() + 16 )
157 rtl_stringbuffer_newFromStr_WithLength( &pData
, value
.getStr(), value
.getLength() );
163 @since LibreOffice 3.6
165 template< typename T
>
166 OStringBuffer( const T
& value
, typename
libreoffice_internal::CharPtrDetector
< T
, libreoffice_internal::Dummy
>::Type
= libreoffice_internal::Dummy())
169 sal_Int32 length
= rtl_str_getLength( value
);
170 nCapacity
= length
+ 16;
171 rtl_stringbuffer_newFromStr_WithLength( &pData
, value
, length
);
174 template< typename T
>
175 OStringBuffer( T
& value
, typename
libreoffice_internal::NonConstCharArrayDetector
< T
, libreoffice_internal::Dummy
>::Type
= libreoffice_internal::Dummy())
178 sal_Int32 length
= rtl_str_getLength( value
);
179 nCapacity
= length
+ 16;
180 rtl_stringbuffer_newFromStr_WithLength( &pData
, value
, length
);
183 #if __cplusplus > 202002L // C++23 P2266R3 "Simpler implicit move"
184 template< typename T
>
185 OStringBuffer( T
&& value
, typename
libreoffice_internal::NonConstCharArrayDetector
< T
, libreoffice_internal::Dummy
>::Type
= libreoffice_internal::Dummy())
188 sal_Int32 length
= rtl_str_getLength( value
);
189 nCapacity
= length
+ 16;
190 rtl_stringbuffer_newFromStr_WithLength( &pData
, value
, length
);
195 Constructs a string buffer so that it represents the same
196 sequence of characters as the string literal.
198 If there are any embedded \0's in the string literal, the result is undefined.
199 Use the overload that explicitly accepts length.
201 @since LibreOffice 3.6
203 @param literal a string literal
205 template< typename T
>
206 OStringBuffer( T
& literal
, typename
libreoffice_internal::ConstCharArrayDetector
< T
, libreoffice_internal::Dummy
>::Type
= libreoffice_internal::Dummy())
208 , nCapacity( libreoffice_internal::ConstCharArrayDetector
<T
>::length
+ 16 )
211 libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(literal
));
212 rtl_string_newFromLiteral(
214 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(literal
),
215 libreoffice_internal::ConstCharArrayDetector
<T
>::length
, 16);
216 #ifdef RTL_STRING_UNITTEST
217 rtl_string_unittest_const_literal
= true;
222 Constructs a string buffer so that it represents the same
223 sequence of characters as the string argument.
226 capacity of the string buffer is <code>16</code> plus length
228 @param value a character array.
229 @param length the number of character which should be copied.
230 The character array length must be greater or
231 equal than this value.
233 OStringBuffer(const char * value
, sal_Int32 length
)
235 , nCapacity( length
+ 16 )
237 rtl_stringbuffer_newFromStr_WithLength( &pData
, value
, length
);
240 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
245 template< typename T1
, typename T2
>
246 OStringBuffer( OStringConcat
< T1
, T2
>&& c
)
248 const sal_Int32 l
= c
.length();
250 pData
= rtl_string_alloc( nCapacity
);
251 char* end
= c
.addData( pData
->buffer
);
260 template< std::size_t N
>
261 OStringBuffer( OStringNumber
< N
>&& n
)
262 : OStringBuffer( n
.buf
, n
.length
)
266 #if defined LIBO_INTERNAL_ONLY
267 operator std::string_view() const { return {getStr(), sal_uInt32(getLength())}; }
270 /** Assign to this a copy of value.
272 OStringBuffer
& operator = ( const OStringBuffer
& value
)
276 rtl_stringbuffer_newFromStringBuffer(&pData
,
279 nCapacity
= value
.nCapacity
;
284 /** Assign from a string.
286 @since LibreOffice 5.3
288 #if defined LIBO_INTERNAL_ONLY
289 OStringBuffer
& operator =(std::string_view string
) {
290 sal_Int32 n
= string
.length();
291 if (n
>= nCapacity
) {
292 ensureCapacity(n
+ 16); //TODO: check for overflow
294 std::memcpy(pData
->buffer
, string
.data(), n
);
295 pData
->buffer
[n
] = '\0';
300 OStringBuffer
& operator =(OString
const & string
) {
301 sal_Int32 n
= string
.getLength();
302 if (n
>= nCapacity
) {
303 ensureCapacity(n
+ 16); //TODO: check for overflow
305 std::memcpy(pData
->buffer
, string
.pData
->buffer
, n
+ 1);
311 /** Assign from a string literal.
313 @since LibreOffice 5.3
317 libreoffice_internal::ConstCharArrayDetector
<T
, OStringBuffer
&>::Type
318 operator =(T
& literal
) {
320 libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(literal
));
322 = libreoffice_internal::ConstCharArrayDetector
<T
>::length
;
323 if (n
>= nCapacity
) {
324 ensureCapacity(n
+ 16); //TODO: check for overflow
328 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(literal
),
334 #if defined LIBO_INTERNAL_ONLY
335 /** @overload @since LibreOffice 5.3 */
336 template<typename T1
, typename T2
>
337 OStringBuffer
& operator =(OStringConcat
<T1
, T2
> && concat
) {
338 sal_Int32
const n
= concat
.length();
339 if (n
>= nCapacity
) {
340 ensureCapacity(n
+ 16); //TODO: check for overflow
342 *concat
.addData(pData
->buffer
) = 0;
347 /** @overload @internal */
348 template<std::size_t N
>
349 OStringBuffer
& operator =(OStringNumber
<N
> && n
)
351 return operator =(std::string_view(n
));
356 Release the string data.
360 rtl_string_release( pData
);
364 Fill the string data in the new string and clear the buffer.
366 This method is more efficient than the constructor of the string. It does
369 @return the string previously contained in the buffer.
371 SAL_WARN_UNUSED_RESULT OString
makeStringAndClear()
373 OString
aRet( pData
);
374 rtl_string_new(&pData
);
380 Returns the length (character count) of this string buffer.
382 @return the number of characters in this string buffer.
384 sal_Int32
getLength() const
386 return pData
->length
;
390 Checks if a string buffer is empty.
392 @return true if the string buffer is empty;
395 @since LibreOffice 4.1
399 return pData
->length
== 0;
403 Returns the current capacity of the String buffer.
406 is the amount of storage available for newly inserted
407 characters. The real buffer size is 1 byte longer, because
408 all strings are 0 terminated.
410 @return the current capacity of this string buffer.
412 sal_Int32
getCapacity() const
418 Ensures that the capacity of the buffer is at least equal to the
421 The new capacity will be at least as large as the maximum of the current
422 length (so that no contents of the buffer is destroyed) and the given
423 minimumCapacity. If the given minimumCapacity is negative, nothing is
426 @param minimumCapacity the minimum desired capacity.
428 void ensureCapacity(sal_Int32 minimumCapacity
)
430 rtl_stringbuffer_ensureCapacity( &pData
, &nCapacity
, minimumCapacity
);
434 Sets the length of this String buffer.
436 If the <code>newLength</code> argument is less than the current
437 length of the string buffer, the string buffer is truncated to
438 contain exactly the number of characters given by the
439 <code>newLength</code> argument.
441 If the <code>newLength</code> argument is greater than or equal
442 to the current length, sufficient null characters
443 (<code>'\u0000'</code>) are appended to the string buffer so that
444 length becomes the <code>newLength</code> argument.
446 The <code>newLength</code> argument must be greater than or equal
449 @param newLength the new length of the buffer.
451 void setLength(sal_Int32 newLength
)
453 assert(newLength
>= 0);
454 // Avoid modifications if pData points to const empty string:
455 if( newLength
!= pData
->length
)
457 if( newLength
> nCapacity
)
458 rtl_stringbuffer_ensureCapacity(&pData
, &nCapacity
, newLength
);
460 pData
->buffer
[newLength
] = '\0';
461 pData
->length
= newLength
;
466 Returns the character at a specific index in this string buffer.
468 The first character of a string buffer is at index
469 <code>0</code>, the next at index <code>1</code>, and so on, for
472 The index argument must be greater than or equal to
473 <code>0</code>, and less than the length of this string buffer.
475 @param index the index of the desired character.
476 @return the character at the specified index of this string buffer.
478 SAL_DEPRECATED("use rtl::OStringBuffer::operator [] instead")
479 char charAt( sal_Int32 index
)
481 assert(index
>= 0 && index
< pData
->length
);
482 return pData
->buffer
[ index
];
486 The character at the specified index of this string buffer is set
489 The index argument must be greater than or equal to
490 <code>0</code>, and less than the length of this string buffer.
492 @param index the index of the character to modify.
493 @param ch the new character.
495 SAL_DEPRECATED("use rtl::OStringBuffer::operator [] instead")
496 OStringBuffer
& setCharAt(sal_Int32 index
, char ch
)
498 assert(index
>= 0 && index
< pData
->length
);
499 pData
->buffer
[ index
] = ch
;
504 Return a null terminated character array.
506 const char* getStr() const SAL_RETURNS_NONNULL
{ return pData
->buffer
; }
509 Access to individual characters.
511 @param index must be non-negative and less than length.
513 @return a reference to the character at the given index.
515 @since LibreOffice 3.5
517 char & operator [](sal_Int32 index
)
519 assert(index
>= 0 && index
< pData
->length
);
520 return pData
->buffer
[index
];
524 Return an OString instance reflecting the current content
525 of this OStringBuffer.
527 OString
toString() const
529 return OString(pData
->buffer
, pData
->length
);
532 #if !defined LIBO_INTERNAL_ONLY
534 Appends the string to this string buffer.
536 The characters of the <code>String</code> argument are appended, in
537 order, to the contents of this string buffer, increasing the
538 length of this string buffer by the length of the argument.
541 @return this string buffer.
543 OStringBuffer
& append(const OString
&str
)
545 return insert(getLength(), str
);
550 Appends the string representation of the <code>char</code> array
551 argument to this string buffer.
553 The characters of the array argument are appended, in order, to
554 the contents of this string buffer. The length of this string
555 buffer increases by the length of the argument.
557 @param str the characters to be appended.
558 @return this string buffer.
560 template< typename T
>
561 typename
libreoffice_internal::CharPtrDetector
< T
, OStringBuffer
& >::Type
append( const T
& str
)
563 return insert(getLength(), str
);
566 template< typename T
>
567 typename
libreoffice_internal::NonConstCharArrayDetector
< T
, OStringBuffer
& >::Type
append( T
& str
)
569 return insert(getLength(), str
);
574 This function accepts an ASCII string literal as its argument.
575 @since LibreOffice 3.6
577 template< typename T
>
578 typename
libreoffice_internal::ConstCharArrayDetector
< T
, OStringBuffer
& >::Type
append( T
& literal
)
580 return insert(getLength(), literal
);
584 Appends the string representation of the <code>char</code> array
585 argument to this string buffer.
587 Characters of the character array <code>str</code> are appended,
588 in order, to the contents of this string buffer. The length of this
589 string buffer increases by the value of <code>len</code>.
591 @param str the characters to be appended; must be non-null, and must
592 point to at least len characters
593 @param len the number of characters to append; must be non-negative
594 @return this string buffer.
596 OStringBuffer
& append( const char * str
, sal_Int32 len
)
598 return insert(getLength(), str
, len
);
601 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
606 template< typename T1
, typename T2
>
607 OStringBuffer
& append( OStringConcat
< T1
, T2
>&& c
)
609 sal_Int32 l
= c
.length();
611 c
.addData(appendUninitialized(l
));
619 OStringBuffer
& append( std::string_view s
)
621 return insert(getLength(), s
);
627 Appends the string representation of the <code>sal_Bool</code>
628 argument to the 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 b a <code>sal_Bool</code>.
635 @return this string buffer.
637 OStringBuffer
& append(sal_Bool b
)
639 return insert(getLength(), b
);
643 Appends the string representation of the <code>bool</code>
644 argument to the string buffer.
646 The argument is converted to a string as if by the method
647 <code>String.valueOf</code>, and the characters of that
648 string are then appended to this string buffer.
650 @param b a <code>bool</code>.
651 @return this string buffer.
653 @since LibreOffice 4.3
655 OStringBuffer
& append(bool b
)
657 return insert(getLength(), b
);
661 // Pointer can be automatically converted to bool, which is unwanted here.
662 // Explicitly delete all pointer append() overloads to prevent this
663 // (except for char* overload, which is handled elsewhere).
664 template< typename T
>
665 typename
libreoffice_internal::Enable
< void,
666 !libreoffice_internal::CharPtrDetector
< T
* >::ok
>::Type
667 append( T
* ) SAL_DELETED_FUNCTION
;
671 Appends the string representation of the <code>char</code>
672 argument to this string buffer.
674 The argument is appended to the contents of this string buffer.
675 The length of this string buffer increases by <code>1</code>.
677 @param c a <code>char</code>.
678 @return this string buffer.
680 OStringBuffer
& append(char c
)
682 return insert(getLength(), c
);
686 Appends the string representation of the <code>sal_Int32</code>
687 argument to this string buffer.
689 The argument is converted to a string as if by the method
690 <code>String.valueOf</code>, and the characters of that
691 string are then appended to this string buffer.
693 @param i an <code>sal_Int32</code>.
694 @param radix the radix
695 @return this string buffer.
697 OStringBuffer
& append(sal_Int32 i
, sal_Int16 radix
= 10 )
699 return insert(getLength(), i
, radix
);
703 Appends the string representation of the <code>long</code>
704 argument to this string buffer.
706 The argument is converted to a string as if by the method
707 <code>String.valueOf</code>, and the characters of that
708 string are then appended to this string buffer.
710 @param l a <code>long</code>.
711 @param radix the radix
712 @return this string buffer.
714 OStringBuffer
& append(sal_Int64 l
, sal_Int16 radix
= 10 )
716 return insert(getLength(), l
, radix
);
720 Appends the string representation of the <code>float</code>
721 argument to this string buffer.
723 The argument is converted to a string as if by the method
724 <code>String.valueOf</code>, and the characters of that
725 string are then appended to this string buffer.
727 @param f a <code>float</code>.
728 @return this string buffer.
730 OStringBuffer
& append(float f
)
732 return insert(getLength(), f
);
736 Appends the string representation of the <code>double</code>
737 argument to this string buffer.
739 The argument is converted to a string as if by the method
740 <code>String.valueOf</code>, and the characters of that
741 string are then appended to this string buffer.
743 @param d a <code>double</code>.
744 @return this string buffer.
746 OStringBuffer
& append(double d
)
748 return insert(getLength(), d
);
752 Unsafe way to make space for a fixed amount of characters to be appended
753 into this OStringBuffer.
755 A call to this function must immediately be followed by code that
756 completely fills the uninitialized block pointed to by the return value.
758 @param length the length of the uninitialized block of char entities;
761 @return a pointer to the start of the uninitialized block; only valid
762 until this OStringBuffer's capacity changes
764 @since LibreOffice 4.4
766 char * appendUninitialized(sal_Int32 length
) SAL_RETURNS_NONNULL
{
767 sal_Int32 n
= getLength();
768 rtl_stringbuffer_insert(&pData
, &nCapacity
, n
, NULL
, length
);
769 return pData
->buffer
+ n
;
773 Inserts the string into this string buffer.
775 The characters of the <code>String</code> argument are inserted, in
776 order, into this string buffer at the indicated offset. The length
777 of this string buffer is increased by the length of the argument.
779 The offset argument must be greater than or equal to
780 <code>0</code>, and less than or equal to the length of this
783 @param offset the offset.
785 @return this string buffer.
787 #if defined LIBO_INTERNAL_ONLY
788 OStringBuffer
& insert(sal_Int32 offset
, std::string_view str
)
790 return insert( offset
, str
.data(), str
.length() );
793 OStringBuffer
& insert(sal_Int32 offset
, const OString
& str
)
795 return insert( offset
, str
.getStr(), str
.getLength() );
800 Inserts the string representation of the <code>char</code> array
801 argument into this string buffer.
803 The characters of the array argument are inserted into the
804 contents of this string buffer at the position indicated by
805 <code>offset</code>. The length of this string buffer increases by
806 the length of the argument.
808 The offset argument must be greater than or equal to
809 <code>0</code>, and less than or equal to the length of this
812 @param offset the offset.
813 @param str a character array.
814 @return this string buffer.
816 template< typename T
>
817 typename
libreoffice_internal::CharPtrDetector
< T
, OStringBuffer
& >::Type
insert( sal_Int32 offset
, const T
& str
)
819 return insert( offset
, str
, rtl_str_getLength( str
) );
822 template< typename T
>
823 typename
libreoffice_internal::NonConstCharArrayDetector
< T
, OStringBuffer
& >::Type
insert( sal_Int32 offset
, T
& str
)
825 return insert( offset
, str
, rtl_str_getLength( str
) );
830 This function accepts an ASCII string literal as its argument.
831 @since LibreOffice 3.6
833 template< typename T
>
834 typename
libreoffice_internal::ConstCharArrayDetector
< T
, OStringBuffer
& >::Type
insert( sal_Int32 offset
, T
& literal
)
836 RTL_STRING_CONST_FUNCTION
838 libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(literal
));
841 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(literal
),
842 libreoffice_internal::ConstCharArrayDetector
<T
>::length
);
846 Inserts the string representation of the <code>char</code> array
847 argument into this string buffer.
849 The characters of the array argument are inserted into the
850 contents of this string buffer at the position indicated by
851 <code>offset</code>. The length of this string buffer increases by
852 the length of the argument.
854 The offset argument must be greater than or equal to
855 <code>0</code>, and less than or equal to the length of this
858 @param offset the offset.
859 @param str a character array.
860 @param len the number of characters to append.
861 @return this string buffer.
863 OStringBuffer
& insert( sal_Int32 offset
, const char * str
, sal_Int32 len
)
865 assert( len
== 0 || str
!= NULL
); // cannot assert that in rtl_stringbuffer_insert
866 rtl_stringbuffer_insert( &pData
, &nCapacity
, offset
, str
, len
);
871 Inserts the string representation of the <code>sal_Bool</code>
872 argument into this string buffer.
874 The second argument is converted to a string as if by the method
875 <code>String.valueOf</code>, and the characters of that
876 string are then inserted into this string buffer at the indicated
879 The offset argument must be greater than or equal to
880 <code>0</code>, and less than or equal to the length of this
883 @param offset the offset.
884 @param b a <code>sal_Bool</code>.
885 @return this string buffer.
887 OStringBuffer
& insert(sal_Int32 offset
, sal_Bool b
)
889 char sz
[RTL_STR_MAX_VALUEOFBOOLEAN
];
890 return insert( offset
, sz
, rtl_str_valueOfBoolean( sz
, b
) );
894 Inserts the string representation of the <code>bool</code>
895 argument into this string buffer.
897 The second argument is converted to a string as if by the method
898 <code>OString::boolean</code>, and the characters of that
899 string are then inserted into this string buffer at the indicated
902 The offset argument must be greater than or equal to
903 <code>0</code>, and less than or equal to the length of this
906 @param offset the offset.
907 @param b a <code>bool</code>.
908 @return this string buffer.
910 @since LibreOffice 4.3
912 OStringBuffer
& insert(sal_Int32 offset
, bool b
)
914 char sz
[RTL_STR_MAX_VALUEOFBOOLEAN
];
915 return insert( offset
, sz
, rtl_str_valueOfBoolean( sz
, b
) );
919 Inserts the string representation of the <code>char</code>
920 argument into this string buffer.
922 The second argument is inserted into the contents of this string
923 buffer at the position indicated by <code>offset</code>. The length
924 of this string buffer increases by one.
926 The offset argument must be greater than or equal to
927 <code>0</code>, and less than or equal to the length of this
930 @param offset the offset.
931 @param c a <code>char</code>.
932 @return this string buffer.
934 OStringBuffer
& insert(sal_Int32 offset
, char c
)
936 return insert( offset
, &c
, 1 );
940 Inserts the string representation of the second <code>sal_Int32</code>
941 argument into this string buffer.
943 The second argument is converted to a string as if by the method
944 <code>String.valueOf</code>, and the characters of that
945 string are then inserted into this string buffer at the indicated
948 The offset argument must be greater than or equal to
949 <code>0</code>, and less than or equal to the length of this
952 @param offset the offset.
953 @param i an <code>sal_Int32</code>.
954 @param radix the radix
955 @return this string buffer.
957 OStringBuffer
& insert(sal_Int32 offset
, sal_Int32 i
, sal_Int16 radix
= 10 )
959 char sz
[RTL_STR_MAX_VALUEOFINT32
];
960 return insert( offset
, sz
, rtl_str_valueOfInt32( sz
, i
, radix
) );
964 Inserts the string representation of the <code>long</code>
965 argument into this string buffer.
967 The second argument is converted to a string as if by the method
968 <code>String.valueOf</code>, and the characters of that
969 string are then inserted into this string buffer at the indicated
972 The offset argument must be greater than or equal to
973 <code>0</code>, and less than or equal to the length of this
976 @param offset the offset.
977 @param l a <code>long</code>.
978 @param radix the radix
979 @return this string buffer.
981 OStringBuffer
& insert(sal_Int32 offset
, sal_Int64 l
, sal_Int16 radix
= 10 )
983 char sz
[RTL_STR_MAX_VALUEOFINT64
];
984 return insert( offset
, sz
, rtl_str_valueOfInt64( sz
, l
, radix
) );
988 Inserts the string representation of the <code>float</code>
989 argument into this string buffer.
991 The second argument is converted to a string as if by the method
992 <code>String.valueOf</code>, and the characters of that
993 string are then inserted into this string buffer at the indicated
996 The offset argument must be greater than or equal to
997 <code>0</code>, and less than or equal to the length of this
1000 @param offset the offset.
1001 @param f a <code>float</code>.
1002 @return this string buffer.
1004 OStringBuffer
& insert(sal_Int32 offset
, float f
)
1006 // Same as rtl::str::valueOfFP, used for rtl_str_valueOfFloat
1007 rtl_math_doubleToString(&pData
, &nCapacity
, offset
, f
, rtl_math_StringFormat_G
,
1008 RTL_STR_MAX_VALUEOFFLOAT
- SAL_N_ELEMENTS("-x.E-xxx") + 1, '.',
1014 Inserts the string representation of the <code>double</code>
1015 argument into this string buffer.
1017 The second argument is converted to a string as if by the method
1018 <code>String.valueOf</code>, and the characters of that
1019 string are then inserted into this string buffer at the indicated
1022 The offset argument must be greater than or equal to
1023 <code>0</code>, and less than or equal to the length of this
1026 @param offset the offset.
1027 @param d a <code>double</code>.
1028 @return this string buffer.
1030 OStringBuffer
& insert(sal_Int32 offset
, double d
)
1032 // Same as rtl::str::valueOfFP, used for rtl_str_valueOfDouble
1033 rtl_math_doubleToString(&pData
, &nCapacity
, offset
, d
, rtl_math_StringFormat_G
,
1034 RTL_STR_MAX_VALUEOFDOUBLE
- SAL_N_ELEMENTS("-x.E-xxx") + 1, '.',
1040 Removes the characters in a substring of this sequence.
1042 The substring begins at the specified <code>start</code> and
1043 is <code>len</code> characters long.
1045 start must be >= 0 && <= getLength() && <= end
1047 @param start The beginning index, inclusive
1048 @param len The substring length
1049 @return this string buffer.
1051 OStringBuffer
& remove( sal_Int32 start
, sal_Int32 len
)
1053 rtl_stringbuffer_remove( &pData
, start
, len
);
1057 /** Allows access to the internal data of this OStringBuffer, for effective
1060 This function should be used with care. After you have called this
1061 function, you may use the returned pInternalData and pInternalCapacity
1062 only as long as you make no other calls on this OStringBuffer.
1064 @param pInternalData
1065 This output parameter receives a pointer to the internal data
1066 (rtl_String pointer). pInternalData itself must not be null.
1068 @param pInternalCapacity
1069 This output parameter receives a pointer to the internal capacity.
1070 pInternalCapacity itself must not be null.
1072 @since LibreOffice 5.4
1074 void accessInternals(
1075 rtl_String
*** pInternalData
, sal_Int32
** pInternalCapacity
)
1077 *pInternalData
= &pData
;
1078 *pInternalCapacity
= &nCapacity
;
1083 A pointer to the data structure which contains the data.
1088 The len of the pData->buffer.
1090 sal_Int32 nCapacity
;
1093 #if defined LIBO_INTERNAL_ONLY
1094 template<> struct ToStringHelper
<OStringBuffer
> {
1095 static std::size_t length(OStringBuffer
const & s
) { return s
.getLength(); }
1097 char * operator()(char * buffer
, OStringBuffer
const & s
) const SAL_RETURNS_NONNULL
1098 { return addDataHelper(buffer
, s
.getStr(), s
.getLength()); }
1104 #ifdef RTL_STRING_UNITTEST
1107 typedef rtlunittest::OStringBuffer OStringBuffer
;
1109 #undef RTL_STRING_CONST_FUNCTION
1112 #if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST
1113 using ::rtl::OStringBuffer
;
1116 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */