Bump version to 6.4-15
[LibreOffice.git] / include / rtl / ustrbuf.hxx
bloba1b477498f6e204b8407adf8cac6b67c6f341a3d
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_USTRBUF_HXX
21 #define INCLUDED_RTL_USTRBUF_HXX
23 #include "sal/config.h"
25 #include <cassert>
26 #include <cstring>
27 #include <limits>
28 #include <new>
30 #if defined LIBO_INTERNAL_ONLY
31 #include <string_view>
32 #endif
34 #include "rtl/ustrbuf.h"
35 #include "rtl/ustring.hxx"
36 #include "rtl/stringutils.hxx"
37 #include "sal/types.h"
39 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
40 #include "rtl/stringconcat.hxx"
41 #endif
43 #ifdef RTL_STRING_UNITTEST
44 extern bool rtl_string_unittest_invalid_conversion;
45 #endif
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
54 #endif
56 namespace rtl
59 #ifdef RTL_STRING_UNITTEST
60 #undef rtl
61 #endif
63 /** A string buffer implements a mutable sequence of characters.
65 class SAL_WARN_UNUSED OUStringBuffer
67 friend class OUString;
68 public:
69 /**
70 Constructs a string buffer with no characters in it and an
71 initial capacity of 16 characters.
73 OUStringBuffer()
74 : pData(NULL)
75 , nCapacity( 16 )
77 rtl_uString_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>OUStringBuffer</code>.
86 OUStringBuffer( const OUStringBuffer & value )
87 : pData(NULL)
88 , nCapacity( value.nCapacity )
90 rtl_uStringbuffer_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 OUStringBuffer(int length)
100 : pData(NULL)
101 , nCapacity( length )
103 rtl_uString_new_WithLength( &pData, length );
105 #if __cplusplus >= 201103L
106 explicit OUStringBuffer(unsigned int length)
107 : OUStringBuffer(static_cast<int>(length))
110 #if SAL_TYPES_SIZEOFLONG == 4
111 // additional overloads for sal_Int32 sal_uInt32
112 explicit OUStringBuffer(long length)
113 : OUStringBuffer(static_cast<int>(length))
116 explicit OUStringBuffer(unsigned long length)
117 : OUStringBuffer(static_cast<int>(length))
120 #endif
121 // avoid obvious bugs
122 explicit OUStringBuffer(char) = delete;
123 explicit OUStringBuffer(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 contents of the buffer.
136 OUStringBuffer(const OUString& value)
137 : pData(NULL)
138 , nCapacity( value.getLength() + 16 )
140 rtl_uStringbuffer_newFromStr_WithLength( &pData, value.getStr(), value.getLength() );
143 template< typename T >
144 OUStringBuffer( T& literal, typename libreoffice_internal::ConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type = libreoffice_internal::Dummy() )
145 : pData(NULL)
146 , nCapacity( libreoffice_internal::ConstCharArrayDetector<T>::length + 16 )
148 assert(
149 libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
150 rtl_uString_newFromLiteral(
151 &pData,
152 libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
153 libreoffice_internal::ConstCharArrayDetector<T>::length, 16);
154 #ifdef RTL_STRING_UNITTEST
155 rtl_string_unittest_const_literal = true;
156 #endif
159 #if defined LIBO_INTERNAL_ONLY
160 /** @overload @since LibreOffice 5.3 */
161 template<typename T>
162 OUStringBuffer(
163 T & literal,
164 typename libreoffice_internal::ConstCharArrayDetector<
165 T, libreoffice_internal::Dummy>::TypeUtf16
166 = libreoffice_internal::Dummy()):
167 pData(nullptr),
168 nCapacity(libreoffice_internal::ConstCharArrayDetector<T>::length + 16)
170 rtl_uStringbuffer_newFromStr_WithLength(
171 &pData,
172 libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
173 libreoffice_internal::ConstCharArrayDetector<T>::length);
176 /** @overload @since LibreOffice 5.4 */
177 OUStringBuffer(OUStringLiteral const & literal):
178 pData(nullptr), nCapacity(literal.size + 16) //TODO: check for overflow
180 rtl_uString_newFromLiteral(&pData, literal.data, literal.size, 16);
182 #endif
184 #ifdef RTL_STRING_UNITTEST
186 * Only used by unittests to detect incorrect conversions.
187 * @internal
189 template< typename T >
190 OUStringBuffer( T&, typename libreoffice_internal::ExceptConstCharArrayDetector< T >::Type = libreoffice_internal::Dummy() )
192 pData = NULL;
193 nCapacity = 10;
194 rtl_uString_newFromLiteral( &pData, "!!br0ken!!", 10, 0 ); // set to garbage
195 rtl_string_unittest_invalid_conversion = true;
198 * Only used by unittests to detect incorrect conversions.
199 * @internal
201 template< typename T >
202 OUStringBuffer( const T&, typename libreoffice_internal::ExceptCharArrayDetector< T >::Type = libreoffice_internal::Dummy() )
204 pData = NULL;
205 nCapacity = 10;
206 rtl_uString_newFromLiteral( &pData, "!!br0ken!!", 10, 0 ); // set to garbage
207 rtl_string_unittest_invalid_conversion = true;
209 #endif
211 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
213 @overload
214 @internal
216 template< typename T1, typename T2 >
217 OUStringBuffer( OUStringConcat< T1, T2 >&& c )
219 const sal_Int32 l = c.length();
220 nCapacity = l + 16;
221 pData = rtl_uString_alloc( nCapacity );
222 sal_Unicode* end = c.addData( pData->buffer );
223 *end = '\0';
224 pData->length = l;
225 // TODO realloc in case pData->>length is noticeably smaller than l ?
229 @overload
230 @internal
232 template< typename T >
233 OUStringBuffer( OUStringNumber< T >&& n )
234 : pData(NULL)
235 , nCapacity( n.length + 16 )
237 rtl_uStringbuffer_newFromStr_WithLength( &pData, n.buf, n.length );
239 #endif
240 /** Assign to this a copy of value.
242 OUStringBuffer& operator = ( const OUStringBuffer& value )
244 if (this != &value)
246 rtl_uStringbuffer_newFromStringBuffer(&pData,
247 value.nCapacity,
248 value.pData);
249 nCapacity = value.nCapacity;
251 return *this;
254 /** Assign from a string.
256 @since LibreOffice 5.3
258 OUStringBuffer & operator =(OUString const & string) {
259 sal_Int32 n = string.getLength();
260 if (n >= nCapacity) {
261 ensureCapacity(n + 16); //TODO: check for overflow
263 std::memcpy(
264 pData->buffer, string.pData->buffer,
265 (n + 1) * sizeof (sal_Unicode));
266 pData->length = n;
267 return *this;
270 /** Assign from a string literal.
272 @since LibreOffice 5.3
274 template<typename T>
275 typename
276 libreoffice_internal::ConstCharArrayDetector<T, OUStringBuffer &>::Type
277 operator =(T & literal) {
278 assert(
279 libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
280 sal_Int32 const n
281 = libreoffice_internal::ConstCharArrayDetector<T>::length;
282 if (n >= nCapacity) {
283 ensureCapacity(n + 16); //TODO: check for overflow
285 char const * from
286 = libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
287 literal);
288 sal_Unicode * to = pData->buffer;
289 for (sal_Int32 i = 0; i <= n; ++i) {
290 to[i] = from[i];
292 pData->length = n;
293 return *this;
296 #if defined LIBO_INTERNAL_ONLY
297 /** @overload @since LibreOffice 5.3 */
298 template<typename T>
299 typename libreoffice_internal::ConstCharArrayDetector<
300 T, OUStringBuffer &>::TypeUtf16
301 operator =(T & literal) {
302 sal_Int32 const n
303 = libreoffice_internal::ConstCharArrayDetector<T>::length;
304 if (n >= nCapacity) {
305 ensureCapacity(n + 16); //TODO: check for overflow
307 std::memcpy(
308 pData->buffer,
309 libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
310 (n + 1) * sizeof (sal_Unicode)); //TODO: check for overflow
311 pData->length = n;
312 return *this;
315 /** @overload @since LibreOffice 5.4 */
316 OUStringBuffer & operator =(OUStringLiteral const & literal) {
317 sal_Int32 const n = literal.size;
318 if (n >= nCapacity) {
319 ensureCapacity(n + 16); //TODO: check for overflow
321 char const * from = literal.data;
322 sal_Unicode * to = pData->buffer;
323 for (sal_Int32 i = 0; i <= n; ++i) {
324 to[i] = from[i];
326 pData->length = n;
327 return *this;
329 #endif
331 #if defined LIBO_INTERNAL_ONLY
332 /** @overload @since LibreOffice 5.3 */
333 template<typename T1, typename T2>
334 OUStringBuffer & operator =(OUStringConcat<T1, T2> && concat) {
335 sal_Int32 const n = concat.length();
336 if (n >= nCapacity) {
337 ensureCapacity(n + 16); //TODO: check for overflow
339 *concat.addData(pData->buffer) = 0;
340 pData->length = n;
341 return *this;
344 /** @overload @internal */
345 template<typename T>
346 OUStringBuffer & operator =(OUStringNumber<T> && n)
348 return *this = OUStringBuffer( std::move( n ));
350 #endif
353 Release the string data.
355 ~OUStringBuffer()
357 rtl_uString_release( pData );
361 Fill the string data in the new string and clear the buffer.
363 This method is more efficient than the constructor of the string. It does
364 not copy the buffer.
366 @return the string previously contained in the buffer.
368 SAL_WARN_UNUSED_RESULT OUString makeStringAndClear()
370 return OUString(
371 rtl_uStringBuffer_makeStringAndClear( &pData, &nCapacity ),
372 SAL_NO_ACQUIRE );
376 Returns the length (character count) of this string buffer.
378 @return the number of characters in this string buffer.
380 sal_Int32 getLength() const
382 return pData->length;
386 Checks if a string buffer is empty.
388 @return true if the string buffer is empty;
389 false, otherwise.
391 @since LibreOffice 4.1
393 bool isEmpty() const
395 return pData->length == 0;
399 Returns the current capacity of the String buffer.
401 The capacity
402 is the amount of storage available for newly inserted
403 characters. The real buffer size is 2 bytes longer, because
404 all strings are 0 terminated.
406 @return the current capacity of this string buffer.
408 sal_Int32 getCapacity() const
410 return nCapacity;
414 Ensures that the capacity of the buffer is at least equal to the
415 specified minimum.
417 The new capacity will be at least as large as the maximum of the current
418 length (so that no contents of the buffer is destroyed) and the given
419 minimumCapacity. If the given minimumCapacity is negative, nothing is
420 changed.
422 @param minimumCapacity the minimum desired capacity.
424 void ensureCapacity(sal_Int32 minimumCapacity)
426 rtl_uStringbuffer_ensureCapacity( &pData, &nCapacity, minimumCapacity );
430 Sets the length of this String buffer.
432 If the <code>newLength</code> argument is less than the current
433 length of the string buffer, the string buffer is truncated to
434 contain exactly the number of characters given by the
435 <code>newLength</code> argument.
437 If the <code>newLength</code> argument is greater than or equal
438 to the current length, sufficient null characters
439 (<code>'&#92;u0000'</code>) are appended to the string buffer so that
440 length becomes the <code>newLength</code> argument.
442 The <code>newLength</code> argument must be greater than or equal
443 to <code>0</code>.
445 @param newLength the new length of the buffer.
447 void setLength(sal_Int32 newLength)
449 assert(newLength >= 0);
450 // Avoid modifications if pData points to const empty string:
451 if( newLength != pData->length )
453 if( newLength > nCapacity )
454 rtl_uStringbuffer_ensureCapacity(&pData, &nCapacity, newLength);
455 else
456 pData->buffer[newLength] = 0;
457 pData->length = newLength;
462 Returns the character at a specific index in this string buffer.
464 The first character of a string buffer is at index
465 <code>0</code>, the next at index <code>1</code>, and so on, for
466 array indexing.
468 The index argument must be greater than or equal to
469 <code>0</code>, and less than the length of this string buffer.
471 @param index the index of the desired character.
472 @return the character at the specified index of this string buffer.
474 SAL_DEPRECATED("use rtl::OUStringBuffer::operator [] instead")
475 sal_Unicode charAt( sal_Int32 index ) const
477 assert(index >= 0 && index < pData->length);
478 return pData->buffer[ index ];
482 The character at the specified index of this string buffer is set
483 to <code>ch</code>.
485 The index argument must be greater than or equal to
486 <code>0</code>, and less than the length of this string buffer.
488 @param index the index of the character to modify.
489 @param ch the new character.
491 SAL_DEPRECATED("use rtl::OUStringBuffer::operator [] instead")
492 OUStringBuffer & setCharAt(sal_Int32 index, sal_Unicode ch)
494 assert(index >= 0 && index < pData->length);
495 pData->buffer[ index ] = ch;
496 return *this;
500 Return a null terminated unicode character array.
502 const sal_Unicode* getStr() const SAL_RETURNS_NONNULL { return pData->buffer; }
505 Access to individual characters.
507 @param index must be non-negative and less than length.
509 @return a reference to the character at the given index.
511 @since LibreOffice 3.5
513 sal_Unicode & operator [](sal_Int32 index)
515 assert(index >= 0 && index < pData->length);
516 return pData->buffer[index];
520 Access to individual characters.
522 @param index must be non-negative and less than length.
524 @return a reference to the character at the given index.
526 @since LibreOffice 4.2
528 const sal_Unicode & operator [](sal_Int32 index) const
530 assert(index >= 0 && index < pData->length);
531 return pData->buffer[index];
535 Return an OUString instance reflecting the current content
536 of this OUStringBuffer.
538 const OUString toString() const
540 return OUString(pData->buffer, pData->length);
544 Appends the string to this string buffer.
546 The characters of the <code>OUString</code> argument are appended, in
547 order, to the contents of this string buffer, increasing the
548 length of this string buffer by the length of the argument.
550 @param str a string.
551 @return this string buffer.
553 OUStringBuffer & append(const OUString &str)
555 return append( str.getStr(), str.getLength() );
558 #if defined LIBO_INTERNAL_ONLY
559 OUStringBuffer & append(std::u16string_view sv) {
560 if (sv.size() > sal_uInt32(std::numeric_limits<sal_Int32>::max())) {
561 throw std::bad_alloc();
563 return append(sv.data(), sv.size());
565 #endif
568 Appends the content of a stringbuffer to this string buffer.
570 The characters of the <code>OUStringBuffer</code> argument are appended, in
571 order, to the contents of this string buffer, increasing the
572 length of this string buffer by the length of the argument.
574 @param str a string.
575 @return this string buffer.
577 @since LibreOffice 4.0
579 OUStringBuffer & append(const OUStringBuffer &str)
581 if(!str.isEmpty())
583 append( str.getStr(), str.getLength() );
585 return *this;
589 Appends the string representation of the <code>char</code> array
590 argument to this string buffer.
592 The characters of the array argument are appended, in order, to
593 the contents of this string buffer. The length of this string
594 buffer increases by the length of the argument.
596 @param str the characters to be appended.
597 @return this string buffer.
599 #if defined LIBO_INTERNAL_ONLY
600 template<typename T>
601 typename libreoffice_internal::CharPtrDetector<T, OUStringBuffer &>::TypeUtf16
602 append(T const & str)
603 #else
604 OUStringBuffer & append( const sal_Unicode * str )
605 #endif
607 return append( str, rtl_ustr_getLength( str ) );
611 Appends the string representation of the <code>char</code> array
612 argument to this string buffer.
614 Characters of the character array <code>str</code> are appended,
615 in order, to the contents of this string buffer. The length of this
616 string buffer increases by the value of <code>len</code>.
618 @param str the characters to be appended; must be non-null, and must
619 point to at least len characters
620 @param len the number of characters to append; must be non-negative
621 @return this string buffer.
623 OUStringBuffer & append( const sal_Unicode * str, sal_Int32 len)
625 assert( len == 0 || str != NULL ); // cannot assert that in rtl_uStringbuffer_insert
626 rtl_uStringbuffer_insert( &pData, &nCapacity, getLength(), str, len );
627 return *this;
631 @overload
632 This function accepts an ASCII string literal as its argument.
633 @since LibreOffice 3.6
635 template< typename T >
636 typename libreoffice_internal::ConstCharArrayDetector< T, OUStringBuffer& >::Type append( T& literal )
638 assert(
639 libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
640 return appendAscii(
641 libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
642 libreoffice_internal::ConstCharArrayDetector<T>::length);
645 #if defined LIBO_INTERNAL_ONLY
646 template<typename T>
647 typename libreoffice_internal::NonConstCharArrayDetector<T, OUStringBuffer &>::TypeUtf16
648 append(T & value) { return append(static_cast<sal_Unicode *>(value)); }
650 /** @overload @since LibreOffice 5.3 */
651 template<typename T>
652 typename libreoffice_internal::ConstCharArrayDetector<
653 T, OUStringBuffer &>::TypeUtf16
654 append(T & literal) {
655 return append(
656 libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
657 libreoffice_internal::ConstCharArrayDetector<T>::length);
660 /** @overload @since LibreOffice 5.4 */
661 OUStringBuffer & append(OUStringLiteral const & literal) {
662 return appendAscii(literal.data, literal.size);
664 #endif
666 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
668 @overload
669 @internal
671 template< typename T1, typename T2 >
672 OUStringBuffer& append( OUStringConcat< T1, T2 >&& c )
674 sal_Int32 l = c.length();
675 if( l == 0 )
676 return *this;
677 l += pData->length;
678 rtl_uStringbuffer_ensureCapacity( &pData, &nCapacity, l );
679 sal_Unicode* end = c.addData( pData->buffer + pData->length );
680 *end = '\0';
681 pData->length = l;
682 return *this;
686 @overload
687 @internal
689 template< typename T >
690 OUStringBuffer& append( OUStringNumber< T >&& c )
692 return append( c.buf, c.length );
694 #endif
697 Appends a 8-Bit ASCII character string to this string buffer.
699 Since this method is optimized for performance. the ASCII
700 character values are not converted in any way. The caller
701 has to make sure that all ASCII characters are in the
702 allowed range between 0 and 127. The ASCII string must be
703 NULL-terminated.
705 The characters of the array argument are appended, in order, to
706 the contents of this string buffer. The length of this string
707 buffer increases by the length of the argument.
709 @param str the 8-Bit ASCII characters to be appended.
710 @return this string buffer.
712 OUStringBuffer & appendAscii( const sal_Char * str )
714 return appendAscii( str, rtl_str_getLength( str ) );
718 Appends a 8-Bit ASCII character string to this string buffer.
720 Since this method is optimized for performance. the ASCII
721 character values are not converted in any way. The caller
722 has to make sure that all ASCII characters are in the
723 allowed range between 0 and 127. The ASCII string must be
724 NULL-terminated.
726 Characters of the character array <code>str</code> are appended,
727 in order, to the contents of this string buffer. The length of this
728 string buffer increases by the value of <code>len</code>.
730 @param str the 8-Bit ASCII characters to be appended; must be non-null,
731 and must point to at least len characters
732 @param len the number of characters to append; must be non-negative
733 @return this string buffer.
735 OUStringBuffer & appendAscii( const sal_Char * str, sal_Int32 len)
737 rtl_uStringbuffer_insert_ascii( &pData, &nCapacity, getLength(), str, len );
738 return *this;
742 Appends the string representation of the <code>bool</code>
743 argument to the string buffer.
745 The argument is converted to a string as if by the method
746 <code>String.valueOf</code>, and the characters of that
747 string are then appended to this string buffer.
749 @param b a <code>bool</code>.
750 @return this string buffer.
752 @since LibreOffice 4.1
754 OUStringBuffer & append(bool b)
756 sal_Unicode sz[RTL_USTR_MAX_VALUEOFBOOLEAN];
757 return append( sz, rtl_ustr_valueOfBoolean( sz, b ) );
760 /// @cond INTERNAL
761 // Pointer can be automatically converted to bool, which is unwanted here.
762 // Explicitly delete all pointer append() overloads to prevent this
763 // (except for char* and sal_Unicode* overloads, which are handled elsewhere).
764 template< typename T >
765 typename libreoffice_internal::Enable< void,
766 !libreoffice_internal::CharPtrDetector< T* >::ok && !libreoffice_internal::SalUnicodePtrDetector< T* >::ok >::Type
767 append( T* ) SAL_DELETED_FUNCTION;
768 /// @endcond
770 // This overload is needed because OUString has a ctor from rtl_uString*, but
771 // the bool overload above would be preferred to the conversion.
773 @internal
775 OUStringBuffer & append(rtl_uString* str)
777 return append( OUString( str ));
781 Appends the string representation of the <code>sal_Bool</code>
782 argument to the string buffer.
784 The argument is converted to a string as if by the method
785 <code>String.valueOf</code>, and the characters of that
786 string are then appended to this string buffer.
788 @param b a <code>sal_Bool</code>.
789 @return this string buffer.
791 OUStringBuffer & append(sal_Bool b)
793 sal_Unicode sz[RTL_USTR_MAX_VALUEOFBOOLEAN];
794 return append( sz, rtl_ustr_valueOfBoolean( sz, b ) );
798 Appends the string representation of the ASCII <code>char</code>
799 argument to this string buffer.
801 The argument is appended to the contents of this string buffer.
802 The length of this string buffer increases by <code>1</code>.
804 @param c an ASCII <code>char</code>.
805 @return this string buffer.
807 @since LibreOffice 3.5
809 OUStringBuffer & append(char c)
811 assert(static_cast< unsigned char >(c) <= 0x7F);
812 return append(sal_Unicode(c));
816 Appends the string representation of the <code>char</code>
817 argument to this string buffer.
819 The argument is appended to the contents of this string buffer.
820 The length of this string buffer increases by <code>1</code>.
822 @param c a <code>char</code>.
823 @return this string buffer.
825 OUStringBuffer & append(sal_Unicode c)
827 return append( &c, 1 );
830 #if defined LIBO_INTERNAL_ONLY
831 void append(sal_uInt16) = delete;
832 #endif
835 Appends the string representation of the <code>sal_Int32</code>
836 argument to this string buffer.
838 The argument is converted to a string as if by the method
839 <code>String.valueOf</code>, and the characters of that
840 string are then appended to this string buffer.
842 @param i an <code>sal_Int32</code>.
843 @param radix the radix
844 @return this string buffer.
846 OUStringBuffer & append(sal_Int32 i, sal_Int16 radix = 10 )
848 sal_Unicode sz[RTL_USTR_MAX_VALUEOFINT32];
849 return append( sz, rtl_ustr_valueOfInt32( sz, i, radix ) );
853 Appends the string representation of the <code>long</code>
854 argument to this string buffer.
856 The argument is converted to a string as if by the method
857 <code>String.valueOf</code>, and the characters of that
858 string are then appended to this string buffer.
860 @param l a <code>long</code>.
861 @param radix the radix
862 @return this string buffer.
864 OUStringBuffer & append(sal_Int64 l, sal_Int16 radix = 10 )
866 sal_Unicode sz[RTL_USTR_MAX_VALUEOFINT64];
867 return append( sz, rtl_ustr_valueOfInt64( sz, l, radix ) );
871 Appends the string representation of the <code>float</code>
872 argument to this string buffer.
874 The 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 appended to this string buffer.
878 @param f a <code>float</code>.
879 @return this string buffer.
881 OUStringBuffer & append(float f)
883 sal_Unicode sz[RTL_USTR_MAX_VALUEOFFLOAT];
884 return append( sz, rtl_ustr_valueOfFloat( sz, f ) );
888 Appends the string representation of the <code>double</code>
889 argument to this string buffer.
891 The argument is converted to a string as if by the method
892 <code>String.valueOf</code>, and the characters of that
893 string are then appended to this string buffer.
895 @param d a <code>double</code>.
896 @return this string buffer.
898 OUStringBuffer & append(double d)
900 sal_Unicode sz[RTL_USTR_MAX_VALUEOFDOUBLE];
901 return append( sz, rtl_ustr_valueOfDouble( sz, d ) );
905 Appends a single UTF-32 character to this string buffer.
907 <p>The single UTF-32 character will be represented within the string
908 buffer as either one or two UTF-16 code units.</p>
910 @param c a well-formed UTF-32 code unit (that is, a value in the range
911 <code>0</code>&ndash;<code>0x10FFFF</code>, but excluding
912 <code>0xD800</code>&ndash;<code>0xDFFF</code>)
914 @return
915 this string buffer
917 OUStringBuffer & appendUtf32(sal_uInt32 c) {
918 return insertUtf32(getLength(), c);
922 Unsafe way to make space for a fixed amount of characters to be appended
923 into this OUStringBuffer.
925 A call to this function must immediately be followed by code that
926 completely fills the uninitialized block pointed to by the return value.
928 @param length the length of the uninitialized block of sal_Unicode
929 entities; must be non-negative
931 @return a pointer to the start of the uninitialized block; only valid
932 until this OUStringBuffer's capacity changes
934 @since LibreOffice 4.4
936 sal_Unicode * appendUninitialized(sal_Int32 length) SAL_RETURNS_NONNULL {
937 sal_Int32 n = getLength();
938 rtl_uStringbuffer_insert(&pData, &nCapacity, n, NULL, length);
939 return pData->buffer + n;
943 Inserts the string into this string buffer.
945 The characters of the <code>String</code> argument are inserted, in
946 order, into this string buffer at the indicated offset. The length
947 of this string buffer is increased by the length of the argument.
949 The offset argument must be greater than or equal to
950 <code>0</code>, and less than or equal to the length of this
951 string buffer.
953 @param offset the offset.
954 @param str a string.
955 @return this string buffer.
957 OUStringBuffer & insert(sal_Int32 offset, const OUString & str)
959 return insert( offset, str.getStr(), str.getLength() );
963 Inserts the string representation of the <code>char</code> array
964 argument into this string buffer.
966 The characters of the array argument are inserted into the
967 contents of this string buffer at the position indicated by
968 <code>offset</code>. The length of this string buffer increases by
969 the length of the argument.
971 The offset argument must be greater than or equal to
972 <code>0</code>, and less than or equal to the length of this
973 string buffer.
975 @param offset the offset.
976 @param str a character array.
977 @return this string buffer.
979 OUStringBuffer & insert( sal_Int32 offset, const sal_Unicode * str )
981 return insert( offset, str, rtl_ustr_getLength( str ) );
985 Inserts the string representation of the <code>char</code> array
986 argument into this string buffer.
988 The characters of the array argument are inserted into the
989 contents of this string buffer at the position indicated by
990 <code>offset</code>. The length of this string buffer increases by
991 the length of the argument.
993 The offset argument must be greater than or equal to
994 <code>0</code>, and less than or equal to the length of this
995 string buffer.
997 @param offset the offset.
998 @param str a character array.
999 @param len the number of characters to append.
1000 @return this string buffer.
1002 OUStringBuffer & insert( sal_Int32 offset, const sal_Unicode * str, sal_Int32 len)
1004 assert( len == 0 || str != NULL ); // cannot assert that in rtl_uStringbuffer_insert
1005 rtl_uStringbuffer_insert( &pData, &nCapacity, offset, str, len );
1006 return *this;
1010 @overload
1011 This function accepts an ASCII string literal as its argument.
1012 @since LibreOffice 3.6
1014 template< typename T >
1015 typename libreoffice_internal::ConstCharArrayDetector< T, OUStringBuffer& >::Type insert( sal_Int32 offset, T& literal )
1017 assert(
1018 libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
1019 rtl_uStringbuffer_insert_ascii(
1020 &pData, &nCapacity, offset,
1021 libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
1022 libreoffice_internal::ConstCharArrayDetector<T>::length);
1023 return *this;
1026 #if defined LIBO_INTERNAL_ONLY
1027 /** @overload @since LibreOffice 5.3 */
1028 template<typename T>
1029 typename libreoffice_internal::ConstCharArrayDetector<
1030 T, OUStringBuffer &>::TypeUtf16
1031 insert(sal_Int32 offset, T & literal) {
1032 return insert(
1033 offset,
1034 libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
1035 libreoffice_internal::ConstCharArrayDetector<T>::length);
1038 /** @overload @since LibreOffice 5.4 */
1039 OUStringBuffer & insert(sal_Int32 offset, OUStringLiteral const & literal) {
1040 rtl_uStringbuffer_insert_ascii(
1041 &pData, &nCapacity, offset, literal.data, literal.size);
1042 return *this;
1044 #endif
1047 Inserts the string representation of the <code>sal_Bool</code>
1048 argument into this string buffer.
1050 The second argument is converted to a string as if by the method
1051 <code>String.valueOf</code>, and the characters of that
1052 string are then inserted into this string buffer at the indicated
1053 offset.
1055 The offset argument must be greater than or equal to
1056 <code>0</code>, and less than or equal to the length of this
1057 string buffer.
1059 @param offset the offset.
1060 @param b a <code>sal_Bool</code>.
1061 @return this string buffer.
1063 OUStringBuffer & insert(sal_Int32 offset, sal_Bool b)
1065 sal_Unicode sz[RTL_USTR_MAX_VALUEOFBOOLEAN];
1066 return insert( offset, sz, rtl_ustr_valueOfBoolean( sz, b ) );
1070 Inserts the string representation of the <code>bool</code>
1071 argument into this string buffer.
1073 The second argument is converted to a string as if by the method
1074 <code>OUString::boolean</code>, and the characters of that
1075 string are then inserted into this string buffer at the indicated
1076 offset.
1078 The offset argument must be greater than or equal to
1079 <code>0</code>, and less than or equal to the length of this
1080 string buffer.
1082 @param offset the offset.
1083 @param b a <code>bool</code>.
1084 @return this string buffer.
1086 @since LibreOffice 4.3
1088 OUStringBuffer & insert(sal_Int32 offset, bool b)
1090 sal_Unicode sz[RTL_USTR_MAX_VALUEOFBOOLEAN];
1091 return insert( offset, sz, rtl_ustr_valueOfBoolean( sz, b ) );
1095 Inserts the string representation of the <code>char</code>
1096 argument into this string buffer.
1098 The second argument is inserted into the contents of this string
1099 buffer at the position indicated by <code>offset</code>. The length
1100 of this string buffer increases by one.
1102 The offset argument must be greater than or equal to
1103 <code>0</code>, and less than or equal to the length of this
1104 string buffer.
1106 @param offset the offset.
1107 @param c a <code>char</code>.
1108 @return this string buffer.
1110 @since LibreOffice 3.6
1112 OUStringBuffer & insert(sal_Int32 offset, char c)
1114 sal_Unicode u = c;
1115 return insert( offset, &u, 1 );
1119 Inserts the string representation of the <code>char</code>
1120 argument into this string buffer.
1122 The second argument is inserted into the contents of this string
1123 buffer at the position indicated by <code>offset</code>. The length
1124 of this string buffer increases by one.
1126 The offset argument must be greater than or equal to
1127 <code>0</code>, and less than or equal to the length of this
1128 string buffer.
1130 @param offset the offset.
1131 @param c a <code>char</code>.
1132 @return this string buffer.
1134 OUStringBuffer & insert(sal_Int32 offset, sal_Unicode c)
1136 return insert( offset, &c, 1 );
1140 Inserts the string representation of the second <code>sal_Int32</code>
1141 argument into this string buffer.
1143 The second argument is converted to a string as if by the method
1144 <code>String.valueOf</code>, and the characters of that
1145 string are then inserted into this string buffer at the indicated
1146 offset.
1148 The offset argument must be greater than or equal to
1149 <code>0</code>, and less than or equal to the length of this
1150 string buffer.
1152 @param offset the offset.
1153 @param i an <code>sal_Int32</code>.
1154 @param radix the radix.
1155 @return this string buffer.
1156 @exception StringIndexOutOfBoundsException if the offset is invalid.
1158 OUStringBuffer & insert(sal_Int32 offset, sal_Int32 i, sal_Int16 radix = 10 )
1160 sal_Unicode sz[RTL_USTR_MAX_VALUEOFINT32];
1161 return insert( offset, sz, rtl_ustr_valueOfInt32( sz, i, radix ) );
1165 Inserts the string representation of the <code>long</code>
1166 argument into this string buffer.
1168 The second argument is converted to a string as if by the method
1169 <code>String.valueOf</code>, and the characters of that
1170 string are then inserted into this string buffer at the indicated
1171 offset.
1173 The offset argument must be greater than or equal to
1174 <code>0</code>, and less than or equal to the length of this
1175 string buffer.
1177 @param offset the offset.
1178 @param l a <code>long</code>.
1179 @param radix the radix.
1180 @return this string buffer.
1181 @exception StringIndexOutOfBoundsException if the offset is invalid.
1183 OUStringBuffer & insert(sal_Int32 offset, sal_Int64 l, sal_Int16 radix = 10 )
1185 sal_Unicode sz[RTL_USTR_MAX_VALUEOFINT64];
1186 return insert( offset, sz, rtl_ustr_valueOfInt64( sz, l, radix ) );
1190 Inserts the string representation of the <code>float</code>
1191 argument into this string buffer.
1193 The second argument is converted to a string as if by the method
1194 <code>String.valueOf</code>, and the characters of that
1195 string are then inserted into this string buffer at the indicated
1196 offset.
1198 The offset argument must be greater than or equal to
1199 <code>0</code>, and less than or equal to the length of this
1200 string buffer.
1202 @param offset the offset.
1203 @param f a <code>float</code>.
1204 @return this string buffer.
1205 @exception StringIndexOutOfBoundsException if the offset is invalid.
1207 OUStringBuffer insert(sal_Int32 offset, float f)
1209 sal_Unicode sz[RTL_USTR_MAX_VALUEOFFLOAT];
1210 return insert( offset, sz, rtl_ustr_valueOfFloat( sz, f ) );
1214 Inserts the string representation of the <code>double</code>
1215 argument into this string buffer.
1217 The second argument is converted to a string as if by the method
1218 <code>String.valueOf</code>, and the characters of that
1219 string are then inserted into this string buffer at the indicated
1220 offset.
1222 The offset argument must be greater than or equal to
1223 <code>0</code>, and less than or equal to the length of this
1224 string buffer.
1226 @param offset the offset.
1227 @param d a <code>double</code>.
1228 @return this string buffer.
1229 @exception StringIndexOutOfBoundsException if the offset is invalid.
1231 OUStringBuffer & insert(sal_Int32 offset, double d)
1233 sal_Unicode sz[RTL_USTR_MAX_VALUEOFDOUBLE];
1234 return insert( offset, sz, rtl_ustr_valueOfDouble( sz, d ) );
1238 Inserts a single UTF-32 character into this string buffer.
1240 <p>The single UTF-32 character will be represented within the string
1241 buffer as either one or two UTF-16 code units.</p>
1243 @param offset the offset into this string buffer (from zero to the length
1244 of this string buffer, inclusive)
1246 @param c a well-formed UTF-32 code unit (that is, a value in the range
1247 <code>0</code>&ndash;<code>0x10FFFF</code>, but excluding
1248 <code>0xD800</code>&ndash;<code>0xDFFF</code>)
1250 @return this string buffer
1252 OUStringBuffer & insertUtf32(sal_Int32 offset, sal_uInt32 c) {
1253 rtl_uStringbuffer_insertUtf32(&pData, &nCapacity, offset, c);
1254 return *this;
1258 Removes the characters in a substring of this sequence.
1260 The substring begins at the specified <code>start</code> and
1261 is <code>len</code> characters long.
1263 start must be >= 0 && <= This->length
1265 @param start The beginning index, inclusive
1266 @param len The substring length
1267 @return this string buffer.
1269 OUStringBuffer & remove( sal_Int32 start, sal_Int32 len )
1271 rtl_uStringbuffer_remove( &pData, start, len );
1272 return *this;
1276 Removes the tail of a string buffer start at the indicate position
1278 start must be >= 0 && <= This->length
1280 @param start The beginning index, inclusive. default to 0
1281 @return this string buffer.
1283 @since LibreOffice 4.0
1285 OUStringBuffer & truncate( sal_Int32 start = 0 )
1287 rtl_uStringbuffer_remove( &pData, start, getLength() - start );
1288 return *this;
1292 Replace all occurrences of
1293 oldChar in this string buffer with newChar.
1295 @since LibreOffice 4.0
1297 @param oldChar the old character.
1298 @param newChar the new character.
1299 @return this string buffer
1301 OUStringBuffer& replace( sal_Unicode oldChar, sal_Unicode newChar )
1303 sal_Int32 index = 0;
1304 while((index = indexOf(oldChar, index)) >= 0)
1306 pData->buffer[ index ] = newChar;
1308 return *this;
1311 /** Allows access to the internal data of this OUStringBuffer, for effective
1312 manipulation.
1314 This method should be used with care. After you have called this
1315 method, you may use the returned pInternalData or pInternalCapacity only
1316 as long as you make no other method call on this OUStringBuffer.
1318 @param pInternalData
1319 This output parameter receives a pointer to the internal data
1320 (rtl_uString pointer). pInternalData itself must not be null.
1322 @param pInternalCapacity
1323 This output parameter receives a pointer to the internal capacity.
1324 pInternalCapacity itself must not be null.
1326 void accessInternals(rtl_uString *** pInternalData,
1327 sal_Int32 ** pInternalCapacity)
1329 *pInternalData = &pData;
1330 *pInternalCapacity = &nCapacity;
1335 Returns the index within this string of the first occurrence of the
1336 specified character, starting the search at the specified index.
1338 @since LibreOffice 4.0
1340 @param ch character to be located.
1341 @param fromIndex the index to start the search from.
1342 The index must be greater or equal than 0
1343 and less or equal as the string length.
1344 @return the index of the first occurrence of the character in the
1345 character sequence represented by this string that is
1346 greater than or equal to fromIndex, or
1347 -1 if the character does not occur.
1349 sal_Int32 indexOf( sal_Unicode ch, sal_Int32 fromIndex = 0 ) const
1351 assert( fromIndex >= 0 && fromIndex <= pData->length );
1352 sal_Int32 ret = rtl_ustr_indexOfChar_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, ch );
1353 return (ret < 0 ? ret : ret+fromIndex);
1357 Returns the index within this string of the last occurrence of the
1358 specified character, searching backward starting at the end.
1360 @since LibreOffice 4.0
1362 @param ch character to be located.
1363 @return the index of the last occurrence of the character in the
1364 character sequence represented by this string, or
1365 -1 if the character does not occur.
1367 sal_Int32 lastIndexOf( sal_Unicode ch ) const
1369 return rtl_ustr_lastIndexOfChar_WithLength( pData->buffer, pData->length, ch );
1373 Returns the index within this string of the last occurrence of the
1374 specified character, searching backward starting before the specified
1375 index.
1377 @since LibreOffice 4.0
1379 @param ch character to be located.
1380 @param fromIndex the index before which to start the search.
1381 @return the index of the last occurrence of the character in the
1382 character sequence represented by this string that
1383 is less than fromIndex, or -1
1384 if the character does not occur before that point.
1386 sal_Int32 lastIndexOf( sal_Unicode ch, sal_Int32 fromIndex ) const
1388 assert( fromIndex >= 0 && fromIndex <= pData->length );
1389 return rtl_ustr_lastIndexOfChar_WithLength( pData->buffer, fromIndex, ch );
1393 Returns the index within this string of the first occurrence of the
1394 specified substring, starting at the specified index.
1396 If str doesn't include any character, always -1 is
1397 returned. This is also the case, if both strings are empty.
1399 @since LibreOffice 4.0
1401 @param str the substring to search for.
1402 @param fromIndex the index to start the search from.
1403 @return If the string argument occurs one or more times as a substring
1404 within this string at the starting index, then the index
1405 of the first character of the first such substring is
1406 returned. If it does not occur as a substring starting
1407 at fromIndex or beyond, -1 is returned.
1409 sal_Int32 indexOf( const OUString & str, sal_Int32 fromIndex = 0 ) const
1411 assert( fromIndex >= 0 && fromIndex <= pData->length );
1412 sal_Int32 ret = rtl_ustr_indexOfStr_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
1413 str.pData->buffer, str.pData->length );
1414 return (ret < 0 ? ret : ret+fromIndex);
1418 @overload
1419 This function accepts an ASCII string literal as its argument.
1421 @since LibreOffice 4.0
1423 template< typename T >
1424 typename libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type indexOf( T& literal, sal_Int32 fromIndex = 0 ) const
1426 assert(
1427 libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
1428 sal_Int32 n = rtl_ustr_indexOfAscii_WithLength(
1429 pData->buffer + fromIndex, pData->length - fromIndex,
1430 libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
1431 libreoffice_internal::ConstCharArrayDetector<T>::length);
1432 return n < 0 ? n : n + fromIndex;
1435 #if defined LIBO_INTERNAL_ONLY
1436 /** @overload @since LibreOffice 5.3 */
1437 template<typename T>
1438 typename
1439 libreoffice_internal::ConstCharArrayDetector<T, sal_Int32>::TypeUtf16
1440 indexOf(T & literal, sal_Int32 fromIndex = 0) const {
1441 assert(fromIndex >= 0);
1442 auto n = rtl_ustr_indexOfStr_WithLength(
1443 pData->buffer + fromIndex, pData->length - fromIndex,
1444 libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
1445 libreoffice_internal::ConstCharArrayDetector<T>::length);
1446 return n < 0 ? n : n + fromIndex;
1449 /** @overload @since LibreOffice 5.4 */
1450 sal_Int32 indexOf(OUStringLiteral const & literal, sal_Int32 fromIndex = 0)
1451 const
1453 sal_Int32 n = rtl_ustr_indexOfAscii_WithLength(
1454 pData->buffer + fromIndex, pData->length - fromIndex, literal.data,
1455 literal.size);
1456 return n < 0 ? n : n + fromIndex;
1458 #endif
1461 Returns the index within this string of the last occurrence of
1462 the specified substring, searching backward starting at the end.
1464 The returned index indicates the starting index of the substring
1465 in this string.
1466 If str doesn't include any character, always -1 is
1467 returned. This is also the case, if both strings are empty.
1469 @since LibreOffice 4.0
1471 @param str the substring to search for.
1472 @return If the string argument occurs one or more times as a substring
1473 within this string, then the index of the first character of
1474 the last such substring is returned. If it does not occur as
1475 a substring, -1 is returned.
1477 sal_Int32 lastIndexOf( const OUString & str ) const
1479 return rtl_ustr_lastIndexOfStr_WithLength( pData->buffer, pData->length,
1480 str.pData->buffer, str.pData->length );
1484 Returns the index within this string of the last occurrence of
1485 the specified substring, searching backward starting before the specified
1486 index.
1488 The returned index indicates the starting index of the substring
1489 in this string.
1490 If str doesn't include any character, always -1 is
1491 returned. This is also the case, if both strings are empty.
1493 @since LibreOffice 4.0
1495 @param str the substring to search for.
1496 @param fromIndex the index before which to start the search.
1497 @return If the string argument occurs one or more times as a substring
1498 within this string before the starting index, then the index
1499 of the first character of the last such substring is
1500 returned. Otherwise, -1 is returned.
1502 sal_Int32 lastIndexOf( const OUString & str, sal_Int32 fromIndex ) const
1504 assert( fromIndex >= 0 && fromIndex <= pData->length );
1505 return rtl_ustr_lastIndexOfStr_WithLength( pData->buffer, fromIndex,
1506 str.pData->buffer, str.pData->length );
1510 @overload
1511 This function accepts an ASCII string literal as its argument.
1512 @since LibreOffice 4.0
1514 template< typename T >
1515 typename libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type lastIndexOf( T& literal ) const
1517 assert(
1518 libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
1519 return rtl_ustr_lastIndexOfAscii_WithLength(
1520 pData->buffer, pData->length,
1521 libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
1522 libreoffice_internal::ConstCharArrayDetector<T>::length);
1525 #if defined LIBO_INTERNAL_ONLY
1526 /** @overload @since LibreOffice 5.3 */
1527 template<typename T>
1528 typename
1529 libreoffice_internal::ConstCharArrayDetector<T, sal_Int32>::TypeUtf16
1530 lastIndexOf(T & literal) const {
1531 return rtl_ustr_lastIndexOfStr_WithLength(
1532 pData->buffer, pData->length,
1533 libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
1534 libreoffice_internal::ConstCharArrayDetector<T>::length);
1537 /** @overload @since LibreOffice 5.4 */
1538 sal_Int32 lastIndexOf(OUStringLiteral const & literal) const {
1539 return rtl_ustr_lastIndexOfAscii_WithLength(
1540 pData->buffer, pData->length, literal.data, literal.size);
1542 #endif
1545 Strip the given character from the start of the buffer.
1547 @since LibreOffice 4.0
1549 @param c the character to strip
1550 @return The number of characters stripped
1553 sal_Int32 stripStart(sal_Unicode c = ' ')
1555 sal_Int32 index;
1556 for(index = 0; index < getLength() ; index++)
1558 if(pData->buffer[ index ] != c)
1560 break;
1563 if(index)
1565 remove(0, index);
1567 return index;
1571 Strip the given character from the end of the buffer.
1573 @since LibreOffice 4.0
1575 @param c the character to strip
1576 @return The number of characters stripped
1579 sal_Int32 stripEnd(sal_Unicode c = ' ')
1581 sal_Int32 result = getLength();
1582 sal_Int32 index;
1583 for(index = getLength(); index > 0 ; index--)
1585 if(pData->buffer[ index - 1 ] != c)
1587 break;
1590 if(index < getLength())
1592 truncate(index);
1594 return result - getLength();
1597 Strip the given character from the both end of the buffer.
1599 @since LibreOffice 4.0
1601 @param c the character to strip
1602 @return The number of characters stripped
1605 sal_Int32 strip(sal_Unicode c = ' ')
1607 return stripStart(c) + stripEnd(c);
1610 Returns a new string buffer that is a substring of this string.
1612 The substring begins at the specified beginIndex. If
1613 beginIndex is negative or be greater than the length of
1614 this string, behaviour is undefined.
1616 @param beginIndex the beginning index, inclusive.
1617 @return the specified substring.
1618 @since LibreOffice 4.1
1620 OUStringBuffer copy( sal_Int32 beginIndex ) const
1622 return copy( beginIndex, getLength() - beginIndex );
1626 Returns a new string buffer that is a substring of this string.
1628 The substring begins at the specified beginIndex and contains count
1629 characters. If either beginIndex or count are negative,
1630 or beginIndex + count are greater than the length of this string
1631 then behaviour is undefined.
1633 @param beginIndex the beginning index, inclusive.
1634 @param count the number of characters.
1635 @return the specified substring.
1636 @since LibreOffice 4.1
1638 OUStringBuffer copy( sal_Int32 beginIndex, sal_Int32 count ) const
1640 assert(beginIndex >= 0 && beginIndex <= getLength());
1641 assert(count >= 0 && count <= getLength() - beginIndex);
1642 rtl_uString *pNew = NULL;
1643 rtl_uStringbuffer_newFromStr_WithLength( &pNew, getStr() + beginIndex, count );
1644 return OUStringBuffer( pNew, count + 16 );
1647 #if defined LIBO_INTERNAL_ONLY
1648 explicit operator OUStringView() const
1650 return OUStringView(getStr(), getLength());
1652 #endif
1654 private:
1655 OUStringBuffer( rtl_uString * value, const sal_Int32 capacity )
1657 pData = value;
1658 nCapacity = capacity;
1662 A pointer to the data structure which contains the data.
1664 rtl_uString * pData;
1667 The len of the pData->buffer.
1669 sal_Int32 nCapacity;
1672 #if defined LIBO_INTERNAL_ONLY
1673 // Define this here to avoid circular includes
1674 inline OUString & OUString::operator+=( const OUStringBuffer & str ) &
1676 // Call operator= if this is empty, otherwise rtl_uString_newConcat will attempt to
1677 // acquire() the str.pData buffer, which is part of the OUStringBuffer mutable state.
1678 if (isEmpty())
1679 return operator=(str.toString());
1680 else
1681 return internalAppend(str.pData);
1683 #endif
1686 #ifdef RTL_STRING_UNITTEST
1687 namespace rtl
1689 typedef rtlunittest::OUStringBuffer OUStringBuffer;
1691 #endif
1693 #if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST
1694 using ::rtl::OUStringBuffer;
1695 #endif
1697 #endif // INCLUDED_RTL_USTRBUF_HXX
1699 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */