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 .
22 #include "sal/config.h"
27 #include "rtl/strbuf.h"
28 #include "rtl/string.hxx"
29 #include "rtl/stringutils.hxx"
31 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
32 #include "rtl/stringconcat.hxx"
35 #ifdef RTL_STRING_UNITTEST
36 extern bool rtl_string_unittest_const_literal
;
37 extern bool rtl_string_unittest_const_literal_function
;
40 // The unittest uses slightly different code to help check that the proper
41 // calls are made. The class is put into a different namespace to make
42 // sure the compiler generates a different (if generating also non-inline)
43 // copy of the function and does not merge them together. The class
44 // is "brought" into the proper rtl namespace by a typedef below.
45 #ifdef RTL_STRING_UNITTEST
46 #define rtl rtlunittest
53 #ifdef RTL_STRING_UNITTEST
55 // helper macro to make functions appear more readable
56 #define RTL_STRING_CONST_FUNCTION rtl_string_unittest_const_literal_function = true;
58 #define RTL_STRING_CONST_FUNCTION
62 /** A string buffer implements a mutable sequence of characters.
64 class SAL_WARN_UNUSED OStringBuffer
68 Constructs a string buffer with no characters in it and an
69 initial capacity of 16 characters.
75 rtl_string_new_WithLength( &pData
, nCapacity
);
79 Allocates a new string buffer that contains the same sequence of
80 characters as the string buffer argument.
82 @param value a <code>OStringBuffer</code>.
84 OStringBuffer( const OStringBuffer
& value
)
86 , nCapacity( value
.nCapacity
)
88 rtl_stringbuffer_newFromStringBuffer( &pData
, value
.nCapacity
, value
.pData
);
92 Constructs a string buffer with no characters in it and an
93 initial capacity specified by the <code>length</code> argument.
95 @param length the initial capacity.
97 explicit OStringBuffer(int length
)
101 rtl_string_new_WithLength( &pData
, length
);
103 #if __cplusplus >= 201103L
104 explicit OStringBuffer(unsigned int length
)
105 : OStringBuffer(static_cast<int>(length
))
108 #if SAL_TYPES_SIZEOFLONG == 4
109 // additional overloads for sal_Int32 sal_uInt32
110 explicit OStringBuffer(long length
)
111 : OStringBuffer(static_cast<int>(length
))
114 explicit OStringBuffer(unsigned long length
)
115 : OStringBuffer(static_cast<int>(length
))
119 // avoid obvious bugs
120 explicit OStringBuffer(char) = delete;
121 explicit OStringBuffer(sal_Unicode
) = delete;
125 Constructs a string buffer so that it represents the same
126 sequence of characters as the string argument.
129 capacity of the string buffer is <code>16</code> plus the length
130 of the string argument.
132 @param value the initial string value.
134 OStringBuffer(const OString
& value
)
136 , nCapacity( value
.getLength() + 16 )
138 rtl_stringbuffer_newFromStr_WithLength( &pData
, value
.getStr(), value
.getLength() );
143 @since LibreOffice 3.6
145 template< typename T
>
146 OStringBuffer( const T
& value
, typename
libreoffice_internal::CharPtrDetector
< T
, libreoffice_internal::Dummy
>::Type
= libreoffice_internal::Dummy())
149 sal_Int32 length
= rtl_str_getLength( value
);
150 nCapacity
= length
+ 16;
151 rtl_stringbuffer_newFromStr_WithLength( &pData
, value
, length
);
154 template< typename T
>
155 OStringBuffer( T
& value
, typename
libreoffice_internal::NonConstCharArrayDetector
< T
, libreoffice_internal::Dummy
>::Type
= libreoffice_internal::Dummy())
158 sal_Int32 length
= rtl_str_getLength( value
);
159 nCapacity
= length
+ 16;
160 rtl_stringbuffer_newFromStr_WithLength( &pData
, value
, length
);
164 Constructs a string buffer so that it represents the same
165 sequence of characters as the string literal.
167 If there are any embedded \0's in the string literal, the result is undefined.
168 Use the overload that explicitly accepts length.
170 @since LibreOffice 3.6
172 @param literal a string literal
174 template< typename T
>
175 OStringBuffer( T
& literal
, typename
libreoffice_internal::ConstCharArrayDetector
< T
, libreoffice_internal::Dummy
>::Type
= libreoffice_internal::Dummy())
177 , nCapacity( libreoffice_internal::ConstCharArrayDetector
<T
>::length
+ 16 )
180 libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(literal
));
181 rtl_string_newFromLiteral(
183 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(literal
),
184 libreoffice_internal::ConstCharArrayDetector
<T
>::length
, 16);
185 #ifdef RTL_STRING_UNITTEST
186 rtl_string_unittest_const_literal
= true;
191 Constructs a string buffer so that it represents the same
192 sequence of characters as the string argument.
195 capacity of the string buffer is <code>16</code> plus length
197 @param value a character array.
198 @param length the number of character which should be copied.
199 The character array length must be greater or
200 equal than this value.
202 OStringBuffer(const char * value
, sal_Int32 length
)
204 , nCapacity( length
+ 16 )
206 rtl_stringbuffer_newFromStr_WithLength( &pData
, value
, length
);
209 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
214 template< typename T1
, typename T2
>
215 OStringBuffer( OStringConcat
< T1
, T2
>&& c
)
217 const sal_Int32 l
= c
.length();
219 pData
= rtl_string_alloc( nCapacity
);
220 char* end
= c
.addData( pData
->buffer
);
229 template< typename T
>
230 OStringBuffer( OStringNumber
< T
>&& n
)
231 : OStringBuffer( OString( n
))
235 /** Assign to this a copy of value.
237 OStringBuffer
& operator = ( const OStringBuffer
& value
)
241 rtl_stringbuffer_newFromStringBuffer(&pData
,
244 nCapacity
= value
.nCapacity
;
249 /** Assign from a string.
251 @since LibreOffice 5.3
253 OStringBuffer
& operator =(OString
const & string
) {
254 sal_Int32 n
= string
.getLength();
255 if (n
>= nCapacity
) {
256 ensureCapacity(n
+ 16); //TODO: check for overflow
258 std::memcpy(pData
->buffer
, string
.pData
->buffer
, n
+ 1);
263 /** Assign from a string literal.
265 @since LibreOffice 5.3
269 libreoffice_internal::ConstCharArrayDetector
<T
, OStringBuffer
&>::Type
270 operator =(T
& literal
) {
272 libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(literal
));
274 = libreoffice_internal::ConstCharArrayDetector
<T
>::length
;
275 if (n
>= nCapacity
) {
276 ensureCapacity(n
+ 16); //TODO: check for overflow
280 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(literal
),
286 #if defined LIBO_INTERNAL_ONLY
287 /** @overload @since LibreOffice 5.3 */
288 template<typename T1
, typename T2
>
289 OStringBuffer
& operator =(OStringConcat
<T1
, T2
> && concat
) {
290 sal_Int32
const n
= concat
.length();
291 if (n
>= nCapacity
) {
292 ensureCapacity(n
+ 16); //TODO: check for overflow
294 *concat
.addData(pData
->buffer
) = 0;
299 /** @overload @internal */
301 OStringBuffer
& operator =(OStringNumber
<T
> && n
)
303 *this = OStringBuffer( std::move ( n
));
309 Release the string data.
313 rtl_string_release( pData
);
317 Fill the string data in the new string and clear the buffer.
319 This method is more efficient than the constructor of the string. It does
322 @return the string previously contained in the buffer.
324 SAL_WARN_UNUSED_RESULT OString
makeStringAndClear()
326 OString
aRet( pData
);
327 rtl_string_new(&pData
);
333 Returns the length (character count) of this string buffer.
335 @return the number of characters in this string buffer.
337 sal_Int32
getLength() const
339 return pData
->length
;
343 Checks if a string buffer is empty.
345 @return true if the string buffer is empty;
348 @since LibreOffice 4.1
352 return pData
->length
== 0;
356 Returns the current capacity of the String buffer.
359 is the amount of storage available for newly inserted
360 characters. The real buffer size is 2 bytes longer, because
361 all strings are 0 terminated.
363 @return the current capacity of this string buffer.
365 sal_Int32
getCapacity() const
371 Ensures that the capacity of the buffer is at least equal to the
374 The new capacity will be at least as large as the maximum of the current
375 length (so that no contents of the buffer is destroyed) and the given
376 minimumCapacity. If the given minimumCapacity is negative, nothing is
379 @param minimumCapacity the minimum desired capacity.
381 void ensureCapacity(sal_Int32 minimumCapacity
)
383 rtl_stringbuffer_ensureCapacity( &pData
, &nCapacity
, minimumCapacity
);
387 Sets the length of this String buffer.
389 If the <code>newLength</code> argument is less than the current
390 length of the string buffer, the string buffer is truncated to
391 contain exactly the number of characters given by the
392 <code>newLength</code> argument.
394 If the <code>newLength</code> argument is greater than or equal
395 to the current length, sufficient null characters
396 (<code>'\u0000'</code>) are appended to the string buffer so that
397 length becomes the <code>newLength</code> argument.
399 The <code>newLength</code> argument must be greater than or equal
402 @param newLength the new length of the buffer.
404 void setLength(sal_Int32 newLength
)
406 assert(newLength
>= 0);
407 // Avoid modifications if pData points to const empty string:
408 if( newLength
!= pData
->length
)
410 if( newLength
> nCapacity
)
411 rtl_stringbuffer_ensureCapacity(&pData
, &nCapacity
, newLength
);
413 pData
->buffer
[newLength
] = '\0';
414 pData
->length
= newLength
;
419 Returns the character at a specific index in this string buffer.
421 The first character of a string buffer is at index
422 <code>0</code>, the next at index <code>1</code>, and so on, for
425 The index argument must be greater than or equal to
426 <code>0</code>, and less than the length of this string buffer.
428 @param index the index of the desired character.
429 @return the character at the specified index of this string buffer.
431 SAL_DEPRECATED("use rtl::OStringBuffer::operator [] instead")
432 char charAt( sal_Int32 index
)
434 assert(index
>= 0 && index
< pData
->length
);
435 return pData
->buffer
[ index
];
439 The character at the specified index of this string buffer is set
442 The index argument must be greater than or equal to
443 <code>0</code>, and less than the length of this string buffer.
445 @param index the index of the character to modify.
446 @param ch the new character.
448 SAL_DEPRECATED("use rtl::OStringBuffer::operator [] instead")
449 OStringBuffer
& setCharAt(sal_Int32 index
, char ch
)
451 assert(index
>= 0 && index
< pData
->length
);
452 pData
->buffer
[ index
] = ch
;
457 Return a null terminated character array.
459 const char* getStr() const SAL_RETURNS_NONNULL
{ return pData
->buffer
; }
462 Access to individual characters.
464 @param index must be non-negative and less than length.
466 @return a reference to the character at the given index.
468 @since LibreOffice 3.5
470 char & operator [](sal_Int32 index
)
472 assert(index
>= 0 && index
< pData
->length
);
473 return pData
->buffer
[index
];
477 Return an OString instance reflecting the current content
478 of this OStringBuffer.
480 const OString
toString() const
482 return OString(pData
->buffer
, pData
->length
);
486 Appends the string to this string buffer.
488 The characters of the <code>String</code> argument are appended, in
489 order, to the contents of this string buffer, increasing the
490 length of this string buffer by the length of the argument.
493 @return this string buffer.
495 OStringBuffer
& append(const OString
&str
)
497 return append( str
.getStr(), str
.getLength() );
501 Appends the string representation of the <code>char</code> array
502 argument to this string buffer.
504 The characters of the array argument are appended, in order, to
505 the contents of this string buffer. The length of this string
506 buffer increases by the length of the argument.
508 @param str the characters to be appended.
509 @return this string buffer.
511 template< typename T
>
512 typename
libreoffice_internal::CharPtrDetector
< T
, OStringBuffer
& >::Type
append( const T
& str
)
514 return append( str
, rtl_str_getLength( str
) );
517 template< typename T
>
518 typename
libreoffice_internal::NonConstCharArrayDetector
< T
, OStringBuffer
& >::Type
append( T
& str
)
520 return append( str
, rtl_str_getLength( str
) );
525 This function accepts an ASCII string literal as its argument.
526 @since LibreOffice 3.6
528 template< typename T
>
529 typename
libreoffice_internal::ConstCharArrayDetector
< T
, OStringBuffer
& >::Type
append( T
& literal
)
531 RTL_STRING_CONST_FUNCTION
533 libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(literal
));
535 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(literal
),
536 libreoffice_internal::ConstCharArrayDetector
<T
>::length
);
540 Appends the string representation of the <code>char</code> array
541 argument to this string buffer.
543 Characters of the character array <code>str</code> are appended,
544 in order, to the contents of this string buffer. The length of this
545 string buffer increases by the value of <code>len</code>.
547 @param str the characters to be appended; must be non-null, and must
548 point to at least len characters
549 @param len the number of characters to append; must be non-negative
550 @return this string buffer.
552 OStringBuffer
& append( const char * str
, sal_Int32 len
)
554 assert( len
== 0 || str
!= NULL
); // cannot assert that in rtl_stringbuffer_insert
555 rtl_stringbuffer_insert( &pData
, &nCapacity
, getLength(), str
, len
);
559 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
564 template< typename T1
, typename T2
>
565 OStringBuffer
& append( OStringConcat
< T1
, T2
>&& c
)
567 sal_Int32 l
= c
.length();
571 rtl_stringbuffer_ensureCapacity( &pData
, &nCapacity
, l
);
572 char* end
= c
.addData( pData
->buffer
+ pData
->length
);
582 template< typename T
>
583 OStringBuffer
& append( OStringNumber
< T
>&& c
)
585 return append( c
.buf
, c
.length
);
591 Appends the string representation of the <code>sal_Bool</code>
592 argument to the string buffer.
594 The argument is converted to a string as if by the method
595 <code>String.valueOf</code>, and the characters of that
596 string are then appended to this string buffer.
598 @param b a <code>sal_Bool</code>.
599 @return this string buffer.
601 OStringBuffer
& append(sal_Bool b
)
603 char sz
[RTL_STR_MAX_VALUEOFBOOLEAN
];
604 return append( sz
, rtl_str_valueOfBoolean( sz
, b
) );
608 Appends the string representation of the <code>bool</code>
609 argument to the string buffer.
611 The argument is converted to a string as if by the method
612 <code>String.valueOf</code>, and the characters of that
613 string are then appended to this string buffer.
615 @param b a <code>bool</code>.
616 @return this string buffer.
618 @since LibreOffice 4.3
620 OStringBuffer
& append(bool b
)
622 char sz
[RTL_STR_MAX_VALUEOFBOOLEAN
];
623 return append( sz
, rtl_str_valueOfBoolean( sz
, b
) );
627 // Pointer can be automatically converted to bool, which is unwanted here.
628 // Explicitly delete all pointer append() overloads to prevent this
629 // (except for char* overload, which is handled elsewhere).
630 template< typename T
>
631 typename
libreoffice_internal::Enable
< void,
632 !libreoffice_internal::CharPtrDetector
< T
* >::ok
>::Type
633 append( T
* ) SAL_DELETED_FUNCTION
;
637 Appends the string representation of the <code>char</code>
638 argument to this string buffer.
640 The argument is appended to the contents of this string buffer.
641 The length of this string buffer increases by <code>1</code>.
643 @param c a <code>char</code>.
644 @return this string buffer.
646 OStringBuffer
& append(char c
)
648 return append( &c
, 1 );
652 Appends the string representation of the <code>sal_Int32</code>
653 argument to this string buffer.
655 The argument is converted to a string as if by the method
656 <code>String.valueOf</code>, and the characters of that
657 string are then appended to this string buffer.
659 @param i an <code>sal_Int32</code>.
660 @param radix the radix
661 @return this string buffer.
663 OStringBuffer
& append(sal_Int32 i
, sal_Int16 radix
= 10 )
665 char sz
[RTL_STR_MAX_VALUEOFINT32
];
666 return append( sz
, rtl_str_valueOfInt32( sz
, i
, radix
) );
670 Appends the string representation of the <code>long</code>
671 argument to this string buffer.
673 The argument is converted to a string as if by the method
674 <code>String.valueOf</code>, and the characters of that
675 string are then appended to this string buffer.
677 @param l a <code>long</code>.
678 @param radix the radix
679 @return this string buffer.
681 OStringBuffer
& append(sal_Int64 l
, sal_Int16 radix
= 10 )
683 char sz
[RTL_STR_MAX_VALUEOFINT64
];
684 return append( sz
, rtl_str_valueOfInt64( sz
, l
, radix
) );
688 Appends the string representation of the <code>float</code>
689 argument to this string buffer.
691 The argument is converted to a string as if by the method
692 <code>String.valueOf</code>, and the characters of that
693 string are then appended to this string buffer.
695 @param f a <code>float</code>.
696 @return this string buffer.
698 OStringBuffer
& append(float f
)
700 char sz
[RTL_STR_MAX_VALUEOFFLOAT
];
701 return append( sz
, rtl_str_valueOfFloat( sz
, f
) );
705 Appends the string representation of the <code>double</code>
706 argument to this string buffer.
708 The argument is converted to a string as if by the method
709 <code>String.valueOf</code>, and the characters of that
710 string are then appended to this string buffer.
712 @param d a <code>double</code>.
713 @return this string buffer.
715 OStringBuffer
& append(double d
)
717 char sz
[RTL_STR_MAX_VALUEOFDOUBLE
];
718 return append( sz
, rtl_str_valueOfDouble( sz
, d
) );
722 Unsafe way to make space for a fixed amount of characters to be appended
723 into this OStringBuffer.
725 A call to this function must immediately be followed by code that
726 completely fills the uninitialized block pointed to by the return value.
728 @param length the length of the uninitialized block of char entities;
731 @return a pointer to the start of the uninitialized block; only valid
732 until this OStringBuffer's capacity changes
734 @since LibreOffice 4.4
736 char * appendUninitialized(sal_Int32 length
) SAL_RETURNS_NONNULL
{
737 sal_Int32 n
= getLength();
738 rtl_stringbuffer_insert(&pData
, &nCapacity
, n
, NULL
, length
);
739 return pData
->buffer
+ n
;
743 Inserts the string into this string buffer.
745 The characters of the <code>String</code> argument are inserted, in
746 order, into this string buffer at the indicated offset. The length
747 of this string buffer is increased by the length of the argument.
749 The offset argument must be greater than or equal to
750 <code>0</code>, and less than or equal to the length of this
753 @param offset the offset.
755 @return this string buffer.
757 OStringBuffer
& insert(sal_Int32 offset
, const OString
& str
)
759 return insert( offset
, str
.getStr(), str
.getLength() );
763 Inserts the string representation of the <code>char</code> array
764 argument into this string buffer.
766 The characters of the array argument are inserted into the
767 contents of this string buffer at the position indicated by
768 <code>offset</code>. The length of this string buffer increases by
769 the length of the argument.
771 The offset argument must be greater than or equal to
772 <code>0</code>, and less than or equal to the length of this
775 @param offset the offset.
776 @param str a character array.
777 @return this string buffer.
779 template< typename T
>
780 typename
libreoffice_internal::CharPtrDetector
< T
, OStringBuffer
& >::Type
insert( sal_Int32 offset
, const T
& str
)
782 return insert( offset
, str
, rtl_str_getLength( str
) );
785 template< typename T
>
786 typename
libreoffice_internal::NonConstCharArrayDetector
< T
, OStringBuffer
& >::Type
insert( sal_Int32 offset
, T
& str
)
788 return insert( offset
, str
, rtl_str_getLength( str
) );
793 This function accepts an ASCII string literal as its argument.
794 @since LibreOffice 3.6
796 template< typename T
>
797 typename
libreoffice_internal::ConstCharArrayDetector
< T
, OStringBuffer
& >::Type
insert( sal_Int32 offset
, T
& literal
)
799 RTL_STRING_CONST_FUNCTION
801 libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(literal
));
804 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(literal
),
805 libreoffice_internal::ConstCharArrayDetector
<T
>::length
);
809 Inserts the string representation of the <code>char</code> array
810 argument into this string buffer.
812 The characters of the array argument are inserted into the
813 contents of this string buffer at the position indicated by
814 <code>offset</code>. The length of this string buffer increases by
815 the length of the argument.
817 The offset argument must be greater than or equal to
818 <code>0</code>, and less than or equal to the length of this
821 @param offset the offset.
822 @param str a character array.
823 @param len the number of characters to append.
824 @return this string buffer.
826 OStringBuffer
& insert( sal_Int32 offset
, const char * str
, sal_Int32 len
)
828 assert( len
== 0 || str
!= NULL
); // cannot assert that in rtl_stringbuffer_insert
829 rtl_stringbuffer_insert( &pData
, &nCapacity
, offset
, str
, len
);
834 Inserts the string representation of the <code>sal_Bool</code>
835 argument into this string buffer.
837 The second argument is converted to a string as if by the method
838 <code>String.valueOf</code>, and the characters of that
839 string are then inserted into this string buffer at the indicated
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
846 @param offset the offset.
847 @param b a <code>sal_Bool</code>.
848 @return this string buffer.
850 OStringBuffer
& insert(sal_Int32 offset
, sal_Bool b
)
852 char sz
[RTL_STR_MAX_VALUEOFBOOLEAN
];
853 return insert( offset
, sz
, rtl_str_valueOfBoolean( sz
, b
) );
857 Inserts the string representation of the <code>bool</code>
858 argument into this string buffer.
860 The second argument is converted to a string as if by the method
861 <code>OString::boolean</code>, and the characters of that
862 string are then inserted into this string buffer at the indicated
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
869 @param offset the offset.
870 @param b a <code>bool</code>.
871 @return this string buffer.
873 @since LibreOffice 4.3
875 OStringBuffer
& insert(sal_Int32 offset
, bool b
)
877 char sz
[RTL_STR_MAX_VALUEOFBOOLEAN
];
878 return insert( offset
, sz
, rtl_str_valueOfBoolean( sz
, b
) );
882 Inserts the string representation of the <code>char</code>
883 argument into this string buffer.
885 The second argument is inserted into the contents of this string
886 buffer at the position indicated by <code>offset</code>. The length
887 of this string buffer increases by one.
889 The offset argument must be greater than or equal to
890 <code>0</code>, and less than or equal to the length of this
893 @param offset the offset.
894 @param c a <code>char</code>.
895 @return this string buffer.
897 OStringBuffer
& insert(sal_Int32 offset
, char c
)
899 return insert( offset
, &c
, 1 );
903 Inserts the string representation of the second <code>sal_Int32</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
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
915 @param offset the offset.
916 @param i an <code>sal_Int32</code>.
917 @param radix the radix
918 @return this string buffer.
920 OStringBuffer
& insert(sal_Int32 offset
, sal_Int32 i
, sal_Int16 radix
= 10 )
922 char sz
[RTL_STR_MAX_VALUEOFINT32
];
923 return insert( offset
, sz
, rtl_str_valueOfInt32( sz
, i
, radix
) );
927 Inserts the string representation of the <code>long</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
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
939 @param offset the offset.
940 @param l a <code>long</code>.
941 @param radix the radix
942 @return this string buffer.
944 OStringBuffer
& insert(sal_Int32 offset
, sal_Int64 l
, sal_Int16 radix
= 10 )
946 char sz
[RTL_STR_MAX_VALUEOFINT64
];
947 return insert( offset
, sz
, rtl_str_valueOfInt64( sz
, l
, radix
) );
951 Inserts the string representation of the <code>float</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
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
963 @param offset the offset.
964 @param f a <code>float</code>.
965 @return this string buffer.
967 OStringBuffer
insert(sal_Int32 offset
, float f
)
969 char sz
[RTL_STR_MAX_VALUEOFFLOAT
];
970 return insert( offset
, sz
, rtl_str_valueOfFloat( sz
, f
) );
974 Inserts the string representation of the <code>double</code>
975 argument into this string buffer.
977 The second argument is converted to a string as if by the method
978 <code>String.valueOf</code>, and the characters of that
979 string are then inserted into this string buffer at the indicated
982 The offset argument must be greater than or equal to
983 <code>0</code>, and less than or equal to the length of this
986 @param offset the offset.
987 @param d a <code>double</code>.
988 @return this string buffer.
990 OStringBuffer
& insert(sal_Int32 offset
, double d
)
992 char sz
[RTL_STR_MAX_VALUEOFDOUBLE
];
993 return insert( offset
, sz
, rtl_str_valueOfDouble( sz
, d
) );
997 Removes the characters in a substring of this sequence.
999 The substring begins at the specified <code>start</code> and
1000 is <code>len</code> characters long.
1002 start must be >= 0 && <= getLength() && <= end
1004 @param start The beginning index, inclusive
1005 @param len The substring length
1006 @return this string buffer.
1008 OStringBuffer
& remove( sal_Int32 start
, sal_Int32 len
)
1010 rtl_stringbuffer_remove( &pData
, start
, len
);
1014 /** Allows access to the internal data of this OStringBuffer, for effective
1017 This function should be used with care. After you have called this
1018 function, you may use the returned pInternalData and pInternalCapacity
1019 only as long as you make no other calls on this OUStringBuffer.
1021 @param pInternalData
1022 This output parameter receives a pointer to the internal data
1023 (rtl_String pointer). pInternalData itself must not be null.
1025 @param pInternalCapacity
1026 This output parameter receives a pointer to the internal capacity.
1027 pInternalCapacity itself must not be null.
1029 @since LibreOffice 5.4
1031 void accessInternals(
1032 rtl_String
*** pInternalData
, sal_Int32
** pInternalCapacity
)
1034 *pInternalData
= &pData
;
1035 *pInternalCapacity
= &nCapacity
;
1040 A pointer to the data structure which contains the data.
1045 The len of the pData->buffer.
1047 sal_Int32 nCapacity
;
1050 #if defined LIBO_INTERNAL_ONLY
1051 template<> struct ToStringHelper
<OStringBuffer
> {
1052 static std::size_t length(OStringBuffer
const & s
) { return s
.getLength(); }
1054 static char * addData(char * buffer
, OStringBuffer
const & s
) SAL_RETURNS_NONNULL
1055 { return addDataHelper(buffer
, s
.getStr(), s
.getLength()); }
1057 static constexpr bool allowOStringConcat
= true;
1058 static constexpr bool allowOUStringConcat
= false;
1064 #ifdef RTL_STRING_UNITTEST
1067 typedef rtlunittest::OStringBuffer OStringBuffer
;
1069 #undef RTL_STRING_CONST_FUNCTION
1072 #if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST
1073 using ::rtl::OStringBuffer
;
1076 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */