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
))
115 assert(libreoffice_internal::IsValidStrLen(length
));
117 // avoid (obvious) bugs
118 explicit OStringBuffer(bool) = delete;
119 explicit OStringBuffer(char) = delete;
120 explicit OStringBuffer(wchar_t) = delete;
121 #if !(defined _MSC_VER && _MSC_VER >= 1930 && _MSC_VER <= 1939 && defined _MANAGED)
122 explicit OStringBuffer(char8_t
) = delete;
124 explicit OStringBuffer(char16_t
) = delete;
125 explicit OStringBuffer(char32_t
) = delete;
129 Constructs a string buffer so that it represents the same
130 sequence of characters as the string argument.
133 capacity of the string buffer is <code>16</code> plus the length
134 of the string argument.
136 @param value the initial string value.
138 #if defined LIBO_INTERNAL_ONLY
139 OStringBuffer(std::string_view sv
)
141 , nCapacity(libreoffice_internal::ThrowIfInvalidStrLen(sv
.length(), 16) + 16)
143 rtl_stringbuffer_newFromStr_WithLength( &pData
, sv
.data(), sv
.length() );
146 OStringBuffer(const OString
& value
)
148 , nCapacity( value
.getLength() + 16 )
150 rtl_stringbuffer_newFromStr_WithLength( &pData
, value
.getStr(), value
.getLength() );
156 @since LibreOffice 3.6
158 template< typename T
>
159 OStringBuffer( const T
& value
, typename
libreoffice_internal::CharPtrDetector
< T
, libreoffice_internal::Dummy
>::Type
= libreoffice_internal::Dummy())
162 sal_Int32 length
= rtl_str_getLength( value
);
163 nCapacity
= length
+ 16;
164 rtl_stringbuffer_newFromStr_WithLength( &pData
, value
, length
);
167 template< typename T
>
168 OStringBuffer( T
& value
, typename
libreoffice_internal::NonConstCharArrayDetector
< T
, libreoffice_internal::Dummy
>::Type
= libreoffice_internal::Dummy())
171 sal_Int32 length
= rtl_str_getLength( value
);
172 nCapacity
= length
+ 16;
173 rtl_stringbuffer_newFromStr_WithLength( &pData
, value
, length
);
176 #if __cplusplus > 202002L // C++23 P2266R3 "Simpler implicit move"
177 template< typename T
>
178 OStringBuffer( T
&& value
, typename
libreoffice_internal::NonConstCharArrayDetector
< T
, libreoffice_internal::Dummy
>::Type
= libreoffice_internal::Dummy())
181 sal_Int32 length
= rtl_str_getLength( value
);
182 nCapacity
= length
+ 16;
183 rtl_stringbuffer_newFromStr_WithLength( &pData
, value
, length
);
188 Constructs a string buffer so that it represents the same
189 sequence of characters as the string literal.
191 If there are any embedded \0's in the string literal, the result is undefined.
192 Use the overload that explicitly accepts length.
194 @since LibreOffice 3.6
196 @param literal a string literal
198 template< typename T
>
199 OStringBuffer( T
& literal
, typename
libreoffice_internal::ConstCharArrayDetector
< T
, libreoffice_internal::Dummy
>::Type
= libreoffice_internal::Dummy())
201 , nCapacity( libreoffice_internal::ConstCharArrayDetector
<T
>::length
+ 16 )
204 libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(literal
));
205 rtl_string_newFromLiteral(
207 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(literal
),
208 libreoffice_internal::ConstCharArrayDetector
<T
>::length
, 16);
209 #ifdef RTL_STRING_UNITTEST
210 rtl_string_unittest_const_literal
= true;
215 Constructs a string buffer so that it represents the same
216 sequence of characters as the string argument.
219 capacity of the string buffer is <code>16</code> plus length
221 @param value a character array.
222 @param length the number of character which should be copied.
223 The character array length must be greater or
224 equal than this value.
226 OStringBuffer(const char * value
, sal_Int32 length
)
228 , nCapacity( length
+ 16 )
230 rtl_stringbuffer_newFromStr_WithLength( &pData
, value
, length
);
233 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
238 template< typename T1
, typename T2
>
239 OStringBuffer( OStringConcat
< T1
, T2
>&& c
)
241 const sal_Int32 l
= c
.length();
243 pData
= rtl_string_alloc( nCapacity
);
244 char* end
= c
.addData( pData
->buffer
);
253 template< std::size_t N
>
254 OStringBuffer( OStringNumber
< N
>&& n
)
255 : OStringBuffer( n
.buf
, n
.length
)
259 #if defined LIBO_INTERNAL_ONLY
260 operator std::string_view() const { return {getStr(), sal_uInt32(getLength())}; }
263 /** Assign to this a copy of value.
265 OStringBuffer
& operator = ( const OStringBuffer
& value
)
269 rtl_stringbuffer_newFromStringBuffer(&pData
,
272 nCapacity
= value
.nCapacity
;
277 /** Assign from a string.
279 @since LibreOffice 5.3
281 #if defined LIBO_INTERNAL_ONLY
282 OStringBuffer
& operator =(std::string_view string
) {
283 sal_Int32 n
= string
.length();
284 if (n
>= nCapacity
) {
285 ensureCapacity(n
+ 16); //TODO: check for overflow
287 std::memcpy(pData
->buffer
, string
.data(), n
);
288 pData
->buffer
[n
] = '\0';
293 OStringBuffer
& operator =(OString
const & string
) {
294 sal_Int32 n
= string
.getLength();
295 if (n
>= nCapacity
) {
296 ensureCapacity(n
+ 16); //TODO: check for overflow
298 std::memcpy(pData
->buffer
, string
.pData
->buffer
, n
+ 1);
304 /** Assign from a string literal.
306 @since LibreOffice 5.3
310 libreoffice_internal::ConstCharArrayDetector
<T
, OStringBuffer
&>::Type
311 operator =(T
& literal
) {
313 libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(literal
));
315 = libreoffice_internal::ConstCharArrayDetector
<T
>::length
;
316 if (n
>= nCapacity
) {
317 ensureCapacity(n
+ 16); //TODO: check for overflow
321 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(literal
),
327 #if defined LIBO_INTERNAL_ONLY
328 /** @overload @since LibreOffice 5.3 */
329 template<typename T1
, typename T2
>
330 OStringBuffer
& operator =(OStringConcat
<T1
, T2
> && concat
) {
331 sal_Int32
const n
= concat
.length();
332 if (n
>= nCapacity
) {
333 ensureCapacity(n
+ 16); //TODO: check for overflow
335 *concat
.addData(pData
->buffer
) = 0;
340 /** @overload @internal */
341 template<std::size_t N
>
342 OStringBuffer
& operator =(OStringNumber
<N
> && n
)
344 return operator =(std::string_view(n
));
349 Release the string data.
353 rtl_string_release( pData
);
357 Fill the string data in the new string and clear the buffer.
359 This method is more efficient than the constructor of the string. It does
362 @return the string previously contained in the buffer.
364 SAL_WARN_UNUSED_RESULT OString
makeStringAndClear()
366 OString
aRet( pData
);
367 rtl_string_new(&pData
);
373 Returns the length (character count) of this string buffer.
375 @return the number of characters in this string buffer.
377 sal_Int32
getLength() const
379 return pData
->length
;
383 Checks if a string buffer is empty.
385 @return true if the string buffer is empty;
388 @since LibreOffice 4.1
392 return pData
->length
== 0;
396 Returns the current capacity of the String buffer.
399 is the amount of storage available for newly inserted
400 characters. The real buffer size is 1 byte longer, because
401 all strings are 0 terminated.
403 @return the current capacity of this string buffer.
405 sal_Int32
getCapacity() const
411 Ensures that the capacity of the buffer is at least equal to the
414 The new capacity will be at least as large as the maximum of the current
415 length (so that no contents of the buffer is destroyed) and the given
416 minimumCapacity. If the given minimumCapacity is negative, nothing is
419 @param minimumCapacity the minimum desired capacity.
421 void ensureCapacity(sal_Int32 minimumCapacity
)
423 rtl_stringbuffer_ensureCapacity( &pData
, &nCapacity
, minimumCapacity
);
427 Sets the length of this String buffer.
429 If the <code>newLength</code> argument is less than the current
430 length of the string buffer, the string buffer is truncated to
431 contain exactly the number of characters given by the
432 <code>newLength</code> argument.
434 If the <code>newLength</code> argument is greater than or equal
435 to the current length, sufficient null characters
436 (<code>'\u0000'</code>) are appended to the string buffer so that
437 length becomes the <code>newLength</code> argument.
439 The <code>newLength</code> argument must be greater than or equal
442 @param newLength the new length of the buffer.
444 void setLength(sal_Int32 newLength
)
446 assert(newLength
>= 0);
447 // Avoid modifications if pData points to const empty string:
448 if( newLength
!= pData
->length
)
450 if( newLength
> nCapacity
)
451 rtl_stringbuffer_ensureCapacity(&pData
, &nCapacity
, newLength
);
453 pData
->buffer
[newLength
] = '\0';
454 pData
->length
= newLength
;
459 Returns the character at a specific index in this string buffer.
461 The first character of a string buffer is at index
462 <code>0</code>, the next at index <code>1</code>, and so on, for
465 The index argument must be greater than or equal to
466 <code>0</code>, and less than the length of this string buffer.
468 @param index the index of the desired character.
469 @return the character at the specified index of this string buffer.
471 SAL_DEPRECATED("use rtl::OStringBuffer::operator [] instead")
472 char charAt( sal_Int32 index
)
474 assert(index
>= 0 && index
< pData
->length
);
475 return pData
->buffer
[ index
];
479 The character at the specified index of this string buffer is set
482 The index argument must be greater than or equal to
483 <code>0</code>, and less than the length of this string buffer.
485 @param index the index of the character to modify.
486 @param ch the new character.
488 SAL_DEPRECATED("use rtl::OStringBuffer::operator [] instead")
489 OStringBuffer
& setCharAt(sal_Int32 index
, char ch
)
491 assert(index
>= 0 && index
< pData
->length
);
492 pData
->buffer
[ index
] = ch
;
497 Return a null terminated character array.
499 const char* getStr() const SAL_RETURNS_NONNULL
{ return pData
->buffer
; }
502 Access to individual characters.
504 @param index must be non-negative and less than length.
506 @return a reference to the character at the given index.
508 @since LibreOffice 3.5
510 char & operator [](sal_Int32 index
)
512 assert(index
>= 0 && index
< pData
->length
);
513 return pData
->buffer
[index
];
517 Return an OString instance reflecting the current content
518 of this OStringBuffer.
520 OString
toString() const
522 return OString(pData
->buffer
, pData
->length
);
525 #if !defined LIBO_INTERNAL_ONLY
527 Appends the string to this string buffer.
529 The characters of the <code>String</code> argument are appended, in
530 order, to the contents of this string buffer, increasing the
531 length of this string buffer by the length of the argument.
534 @return this string buffer.
536 OStringBuffer
& append(const OString
&str
)
538 return insert(getLength(), str
);
543 Appends the string representation of the <code>char</code> array
544 argument to this string buffer.
546 The characters of the array argument are appended, in order, to
547 the contents of this string buffer. The length of this string
548 buffer increases by the length of the argument.
550 @param str the characters to be appended.
551 @return this string buffer.
553 template< typename T
>
554 typename
libreoffice_internal::CharPtrDetector
< T
, OStringBuffer
& >::Type
append( const T
& str
)
556 return insert(getLength(), str
);
559 template< typename T
>
560 typename
libreoffice_internal::NonConstCharArrayDetector
< T
, OStringBuffer
& >::Type
append( T
& str
)
562 return insert(getLength(), str
);
567 This function accepts an ASCII string literal as its argument.
568 @since LibreOffice 3.6
570 template< typename T
>
571 typename
libreoffice_internal::ConstCharArrayDetector
< T
, OStringBuffer
& >::Type
append( T
& literal
)
573 return insert(getLength(), literal
);
577 Appends the string representation of the <code>char</code> array
578 argument to this string buffer.
580 Characters of the character array <code>str</code> are appended,
581 in order, to the contents of this string buffer. The length of this
582 string buffer increases by the value of <code>len</code>.
584 @param str the characters to be appended; must be non-null, and must
585 point to at least len characters
586 @param len the number of characters to append; must be non-negative
587 @return this string buffer.
589 OStringBuffer
& append( const char * str
, sal_Int32 len
)
591 return insert(getLength(), str
, len
);
594 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
599 template< typename T1
, typename T2
>
600 OStringBuffer
& append( OStringConcat
< T1
, T2
>&& c
)
602 sal_Int32 l
= c
.length();
604 c
.addData(appendUninitialized(l
));
612 OStringBuffer
& append( std::string_view s
)
614 return insert(getLength(), s
);
620 Appends the string representation of the <code>sal_Bool</code>
621 argument to the string buffer.
623 The argument is converted to a string as if by the method
624 <code>String.valueOf</code>, and the characters of that
625 string are then appended to this string buffer.
627 @param b a <code>sal_Bool</code>.
628 @return this string buffer.
630 OStringBuffer
& append(sal_Bool b
)
632 return insert(getLength(), b
);
636 Appends the string representation of the <code>bool</code>
637 argument to the string buffer.
639 The argument is converted to a string as if by the method
640 <code>String.valueOf</code>, and the characters of that
641 string are then appended to this string buffer.
643 @param b a <code>bool</code>.
644 @return this string buffer.
646 @since LibreOffice 4.3
648 OStringBuffer
& append(bool b
)
650 return insert(getLength(), b
);
654 // Pointer can be automatically converted to bool, which is unwanted here.
655 // Explicitly delete all pointer append() overloads to prevent this
656 // (except for char* overload, which is handled elsewhere).
657 template< typename T
>
658 typename
libreoffice_internal::Enable
< void,
659 !libreoffice_internal::CharPtrDetector
< T
* >::ok
>::Type
660 append( T
* ) SAL_DELETED_FUNCTION
;
664 Appends the string representation of the <code>char</code>
665 argument to this string buffer.
667 The argument is appended to the contents of this string buffer.
668 The length of this string buffer increases by <code>1</code>.
670 @param c a <code>char</code>.
671 @return this string buffer.
673 OStringBuffer
& append(char c
)
675 return insert(getLength(), c
);
679 Appends the string representation of the <code>sal_Int32</code>
680 argument to this string buffer.
682 The argument is converted to a string as if by the method
683 <code>String.valueOf</code>, and the characters of that
684 string are then appended to this string buffer.
686 @param i an <code>sal_Int32</code>.
687 @param radix the radix
688 @return this string buffer.
690 OStringBuffer
& append(sal_Int32 i
, sal_Int16 radix
= 10 )
692 return insert(getLength(), i
, radix
);
696 Appends the string representation of the <code>long</code>
697 argument to this string buffer.
699 The argument is converted to a string as if by the method
700 <code>String.valueOf</code>, and the characters of that
701 string are then appended to this string buffer.
703 @param l a <code>long</code>.
704 @param radix the radix
705 @return this string buffer.
707 OStringBuffer
& append(sal_Int64 l
, sal_Int16 radix
= 10 )
709 return insert(getLength(), l
, radix
);
713 Appends the string representation of the <code>float</code>
714 argument to this string buffer.
716 The argument is converted to a string as if by the method
717 <code>String.valueOf</code>, and the characters of that
718 string are then appended to this string buffer.
720 @param f a <code>float</code>.
721 @return this string buffer.
723 OStringBuffer
& append(float f
)
725 return insert(getLength(), f
);
729 Appends the string representation of the <code>double</code>
730 argument to this string buffer.
732 The argument is converted to a string as if by the method
733 <code>String.valueOf</code>, and the characters of that
734 string are then appended to this string buffer.
736 @param d a <code>double</code>.
737 @return this string buffer.
739 OStringBuffer
& append(double d
)
741 return insert(getLength(), d
);
745 Unsafe way to make space for a fixed amount of characters to be appended
746 into this OStringBuffer.
748 A call to this function must immediately be followed by code that
749 completely fills the uninitialized block pointed to by the return value.
751 @param length the length of the uninitialized block of char entities;
754 @return a pointer to the start of the uninitialized block; only valid
755 until this OStringBuffer's capacity changes
757 @since LibreOffice 4.4
759 char * appendUninitialized(sal_Int32 length
) SAL_RETURNS_NONNULL
{
760 sal_Int32 n
= getLength();
761 rtl_stringbuffer_insert(&pData
, &nCapacity
, n
, NULL
, length
);
762 return pData
->buffer
+ n
;
766 Inserts the string into this string buffer.
768 The characters of the <code>String</code> argument are inserted, in
769 order, into this string buffer at the indicated offset. The length
770 of this string buffer is increased by the length of the argument.
772 The offset argument must be greater than or equal to
773 <code>0</code>, and less than or equal to the length of this
776 @param offset the offset.
778 @return this string buffer.
780 #if defined LIBO_INTERNAL_ONLY
781 OStringBuffer
& insert(sal_Int32 offset
, std::string_view str
)
783 return insert( offset
, str
.data(), str
.length() );
786 OStringBuffer
& insert(sal_Int32 offset
, const OString
& str
)
788 return insert( offset
, str
.getStr(), str
.getLength() );
793 Inserts the string representation of the <code>char</code> array
794 argument into this string buffer.
796 The characters of the array argument are inserted into the
797 contents of this string buffer at the position indicated by
798 <code>offset</code>. The length of this string buffer increases by
799 the length of the argument.
801 The offset argument must be greater than or equal to
802 <code>0</code>, and less than or equal to the length of this
805 @param offset the offset.
806 @param str a character array.
807 @return this string buffer.
809 template< typename T
>
810 typename
libreoffice_internal::CharPtrDetector
< T
, OStringBuffer
& >::Type
insert( sal_Int32 offset
, const T
& str
)
812 return insert( offset
, str
, rtl_str_getLength( str
) );
815 template< typename T
>
816 typename
libreoffice_internal::NonConstCharArrayDetector
< T
, OStringBuffer
& >::Type
insert( sal_Int32 offset
, T
& str
)
818 return insert( offset
, str
, rtl_str_getLength( str
) );
823 This function accepts an ASCII string literal as its argument.
824 @since LibreOffice 3.6
826 template< typename T
>
827 typename
libreoffice_internal::ConstCharArrayDetector
< T
, OStringBuffer
& >::Type
insert( sal_Int32 offset
, T
& literal
)
829 RTL_STRING_CONST_FUNCTION
831 libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(literal
));
834 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(literal
),
835 libreoffice_internal::ConstCharArrayDetector
<T
>::length
);
839 Inserts the string representation of the <code>char</code> array
840 argument into this string buffer.
842 The characters of the array argument are inserted into the
843 contents of this string buffer at the position indicated by
844 <code>offset</code>. The length of this string buffer increases by
845 the length of the argument.
847 The offset argument must be greater than or equal to
848 <code>0</code>, and less than or equal to the length of this
851 @param offset the offset.
852 @param str a character array.
853 @param len the number of characters to append.
854 @return this string buffer.
856 OStringBuffer
& insert( sal_Int32 offset
, const char * str
, sal_Int32 len
)
858 assert( len
== 0 || str
!= NULL
); // cannot assert that in rtl_stringbuffer_insert
859 rtl_stringbuffer_insert( &pData
, &nCapacity
, offset
, str
, len
);
864 Inserts the string representation of the <code>sal_Bool</code>
865 argument into this string buffer.
867 The second argument is converted to a string as if by the method
868 <code>String.valueOf</code>, and the characters of that
869 string are then inserted into this string buffer at the indicated
872 The offset argument must be greater than or equal to
873 <code>0</code>, and less than or equal to the length of this
876 @param offset the offset.
877 @param b a <code>sal_Bool</code>.
878 @return this string buffer.
880 OStringBuffer
& insert(sal_Int32 offset
, sal_Bool b
)
882 char sz
[RTL_STR_MAX_VALUEOFBOOLEAN
];
883 return insert( offset
, sz
, rtl_str_valueOfBoolean( sz
, b
) );
887 Inserts the string representation of the <code>bool</code>
888 argument into this string buffer.
890 The second argument is converted to a string as if by the method
891 <code>OString::boolean</code>, and the characters of that
892 string are then inserted into this string buffer at the indicated
895 The offset argument must be greater than or equal to
896 <code>0</code>, and less than or equal to the length of this
899 @param offset the offset.
900 @param b a <code>bool</code>.
901 @return this string buffer.
903 @since LibreOffice 4.3
905 OStringBuffer
& insert(sal_Int32 offset
, bool b
)
907 char sz
[RTL_STR_MAX_VALUEOFBOOLEAN
];
908 return insert( offset
, sz
, rtl_str_valueOfBoolean( sz
, b
) );
912 Inserts the string representation of the <code>char</code>
913 argument into this string buffer.
915 The second argument is inserted into the contents of this string
916 buffer at the position indicated by <code>offset</code>. The length
917 of this string buffer increases by one.
919 The offset argument must be greater than or equal to
920 <code>0</code>, and less than or equal to the length of this
923 @param offset the offset.
924 @param c a <code>char</code>.
925 @return this string buffer.
927 OStringBuffer
& insert(sal_Int32 offset
, char c
)
929 return insert( offset
, &c
, 1 );
933 Inserts the string representation of the second <code>sal_Int32</code>
934 argument into this string buffer.
936 The second argument is converted to a string as if by the method
937 <code>String.valueOf</code>, and the characters of that
938 string are then inserted into this string buffer at the indicated
941 The offset argument must be greater than or equal to
942 <code>0</code>, and less than or equal to the length of this
945 @param offset the offset.
946 @param i an <code>sal_Int32</code>.
947 @param radix the radix
948 @return this string buffer.
950 OStringBuffer
& insert(sal_Int32 offset
, sal_Int32 i
, sal_Int16 radix
= 10 )
952 char sz
[RTL_STR_MAX_VALUEOFINT32
];
953 return insert( offset
, sz
, rtl_str_valueOfInt32( sz
, i
, radix
) );
957 Inserts the string representation of the <code>long</code>
958 argument into this string buffer.
960 The second argument is converted to a string as if by the method
961 <code>String.valueOf</code>, and the characters of that
962 string are then inserted into this string buffer at the indicated
965 The offset argument must be greater than or equal to
966 <code>0</code>, and less than or equal to the length of this
969 @param offset the offset.
970 @param l a <code>long</code>.
971 @param radix the radix
972 @return this string buffer.
974 OStringBuffer
& insert(sal_Int32 offset
, sal_Int64 l
, sal_Int16 radix
= 10 )
976 char sz
[RTL_STR_MAX_VALUEOFINT64
];
977 return insert( offset
, sz
, rtl_str_valueOfInt64( sz
, l
, radix
) );
981 Inserts the string representation of the <code>float</code>
982 argument into this string buffer.
984 The second argument is converted to a string as if by the method
985 <code>String.valueOf</code>, and the characters of that
986 string are then inserted into this string buffer at the indicated
989 The offset argument must be greater than or equal to
990 <code>0</code>, and less than or equal to the length of this
993 @param offset the offset.
994 @param f a <code>float</code>.
995 @return this string buffer.
997 OStringBuffer
& insert(sal_Int32 offset
, float f
)
999 // Same as rtl::str::valueOfFP, used for rtl_str_valueOfFloat
1000 rtl_math_doubleToString(&pData
, &nCapacity
, offset
, f
, rtl_math_StringFormat_G
,
1001 RTL_STR_MAX_VALUEOFFLOAT
- SAL_N_ELEMENTS("-x.E-xxx") + 1, '.',
1007 Inserts the string representation of the <code>double</code>
1008 argument into this string buffer.
1010 The second argument is converted to a string as if by the method
1011 <code>String.valueOf</code>, and the characters of that
1012 string are then inserted into this string buffer at the indicated
1015 The offset argument must be greater than or equal to
1016 <code>0</code>, and less than or equal to the length of this
1019 @param offset the offset.
1020 @param d a <code>double</code>.
1021 @return this string buffer.
1023 OStringBuffer
& insert(sal_Int32 offset
, double d
)
1025 // Same as rtl::str::valueOfFP, used for rtl_str_valueOfDouble
1026 rtl_math_doubleToString(&pData
, &nCapacity
, offset
, d
, rtl_math_StringFormat_G
,
1027 RTL_STR_MAX_VALUEOFDOUBLE
- SAL_N_ELEMENTS("-x.E-xxx") + 1, '.',
1033 Removes the characters in a substring of this sequence.
1035 The substring begins at the specified <code>start</code> and
1036 is <code>len</code> characters long.
1038 start must be >= 0 && <= getLength() && <= end
1040 @param start The beginning index, inclusive
1041 @param len The substring length
1042 @return this string buffer.
1044 OStringBuffer
& remove( sal_Int32 start
, sal_Int32 len
)
1046 rtl_stringbuffer_remove( &pData
, start
, len
);
1050 /** Allows access to the internal data of this OStringBuffer, for effective
1053 This function should be used with care. After you have called this
1054 function, you may use the returned pInternalData and pInternalCapacity
1055 only as long as you make no other calls on this OStringBuffer.
1057 @param pInternalData
1058 This output parameter receives a pointer to the internal data
1059 (rtl_String pointer). pInternalData itself must not be null.
1061 @param pInternalCapacity
1062 This output parameter receives a pointer to the internal capacity.
1063 pInternalCapacity itself must not be null.
1065 @since LibreOffice 5.4
1067 void accessInternals(
1068 rtl_String
*** pInternalData
, sal_Int32
** pInternalCapacity
)
1070 *pInternalData
= &pData
;
1071 *pInternalCapacity
= &nCapacity
;
1076 A pointer to the data structure which contains the data.
1081 The len of the pData->buffer.
1083 sal_Int32 nCapacity
;
1086 #if defined LIBO_INTERNAL_ONLY
1087 template<> struct ToStringHelper
<OStringBuffer
> {
1088 static std::size_t length(OStringBuffer
const & s
) { return s
.getLength(); }
1090 char * operator()(char * buffer
, OStringBuffer
const & s
) const SAL_RETURNS_NONNULL
1091 { return addDataHelper(buffer
, s
.getStr(), s
.getLength()); }
1097 #ifdef RTL_STRING_UNITTEST
1100 typedef rtlunittest::OStringBuffer OStringBuffer
;
1102 #undef RTL_STRING_CONST_FUNCTION
1105 #if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST
1106 using ::rtl::OStringBuffer
;
1109 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */