20 #ifndef INCLUDED_RTL_USTRBUF_HXX
21 #define INCLUDED_RTL_USTRBUF_HXX
34 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
43 #ifdef RTL_STRING_UNITTEST
44 #define rtl rtlunittest
50 #ifdef RTL_STRING_UNITTEST
78 , nCapacity( value.nCapacity )
95 #if __cplusplus >= 201103L
100 #if SAL_TYPES_SIZEOFLONG == 4
102 explicit OUStringBuffer(
long length)
103 : OUStringBuffer(static_cast<int>(length))
106 explicit OUStringBuffer(
unsigned long length)
107 : OUStringBuffer(static_cast<int>(length))
112 explicit OUStringBuffer(
char) =
delete;
128 , nCapacity( value.getLength() + 16 )
133 template<
typename T >
136 , nCapacity( libreoffice_internal::ConstCharArrayDetector<T>::length + 16 )
144 #ifdef RTL_STRING_UNITTEST
145 rtl_string_unittest_const_literal =
true;
149 #if defined LIBO_INTERNAL_ONLY
158 nCapacity(libreoffice_internal::ConstCharArrayDetector<T>::length + 16)
167 #ifdef RTL_STRING_UNITTEST
172 template<
typename T >
173 OUStringBuffer( T&,
typename libreoffice_internal::ExceptConstCharArrayDetector< T >::Type = libreoffice_internal::Dummy() )
178 rtl_string_unittest_invalid_conversion =
true;
184 template<
typename T >
185 OUStringBuffer(
const T&,
typename libreoffice_internal::ExceptCharArrayDetector< T >::Type = libreoffice_internal::Dummy() )
190 rtl_string_unittest_invalid_conversion =
true;
194 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
199 template<
typename T1,
typename T2 >
200 OUStringBuffer(
const OUStringConcat< T1, T2 >& c )
202 const sal_Int32 l = c.length();
220 nCapacity = value.nCapacity;
231 if (n >= nCapacity) {
232 ensureCapacity(n + 16);
235 pData->buffer,
string.pData->buffer,
248 operator =(T & literal) {
253 if (n >= nCapacity) {
254 ensureCapacity(n + 16);
260 for (sal_Int32 i = 0; i <= n; ++i) {
267 #if defined LIBO_INTERNAL_ONLY
272 operator =(T & literal) {
275 if (n >= nCapacity) {
276 ensureCapacity(n + 16);
280 libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
287 #if defined LIBO_INTERNAL_ONLY
289 template<
typename T1,
typename T2>
290 OUStringBuffer & operator =(OUStringConcat<T1, T2>
const & concat) {
291 sal_Int32
const n = concat.length();
292 if (n >= nCapacity) {
293 ensureCapacity(n + 16);
295 *concat.addData(pData->buffer) = 0;
331 return pData->length;
344 return pData->length == 0;
398 assert(newLength >= 0);
400 if( newLength != pData->length )
402 if( newLength > nCapacity )
405 pData->buffer[newLength] = 0;
406 pData->length = newLength;
426 assert(index >= 0 && index < pData->length);
427 return pData->buffer[ index ];
443 assert(index >= 0 && index < pData->length);
444 pData->buffer[ index ] = ch;
464 assert(index >= 0 && index < pData->length);
465 return pData->buffer[index];
479 assert(index >= 0 && index < pData->length);
480 return pData->buffer[index];
489 return OUString(pData->buffer, pData->length);
559 assert( len == 0 || str != NULL );
569 template<
typename T >
575 &pData, &nCapacity, getLength(),
581 #if defined LIBO_INTERNAL_ONLY
586 append(T & literal) {
588 &pData, &nCapacity, getLength(),
595 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
600 template<
typename T1,
typename T2 >
601 OUStringBuffer& append(
const OUStringConcat< T1, T2 >& c )
603 sal_Int32 l = c.length();
608 sal_Unicode* end = c.addData( pData->buffer + pData->length );
683 template<
typename T >
730 assert(static_cast< unsigned char >(c) <= 0x7F);
746 return append( &c, 1 );
749 #if LIBO_INTERNAL_ONLY && \
750 (!defined SAL_W32 || defined __MINGW32__ || defined __clang__)
752 void append(sal_uInt16) =
delete;
839 return insertUtf32(getLength(), c);
858 sal_Int32 n = getLength();
860 return pData->buffer + n;
925 assert( len == 0 || str != NULL );
935 template<
typename T >
941 &pData, &nCapacity, offset,
947 #if defined LIBO_INTERNAL_ONLY
952 insert(sal_Int32 offset, T & literal) {
954 &pData, &nCapacity, offset,
1030 return insert( offset, &u, 1 );
1051 return insert( offset, &c, 1 );
1218 sal_Int32 index = 0;
1219 while((index = indexOf(oldChar, index)) >= 0)
1221 pData->buffer[ index ] = newChar;
1242 sal_Int32 ** pInternalCapacity)
1244 *pInternalData = &pData;
1245 *pInternalCapacity = &nCapacity;
1266 assert( fromIndex >= 0 && fromIndex <= pData->length );
1268 return (ret < 0 ? ret : ret+fromIndex);
1303 assert( fromIndex >= 0 && fromIndex <= pData->length );
1326 assert( fromIndex >= 0 && fromIndex <= pData->length );
1329 return (ret < 0 ? ret : ret+fromIndex);
1338 template<
typename T >
1344 pData->buffer + fromIndex, pData->length - fromIndex,
1347 return n < 0 ? n : n + fromIndex;
1350 #if defined LIBO_INTERNAL_ONLY
1352 template<
typename T>
1355 indexOf(T & literal, sal_Int32 fromIndex = 0)
const {
1356 assert(fromIndex >= 0);
1358 pData->buffer + fromIndex, pData->length - fromIndex,
1361 return n < 0 ? n : n + fromIndex;
1409 assert( fromIndex >= 0 && fromIndex <= pData->length );
1419 template<
typename T >
1425 pData->buffer, pData->length,
1430 #if defined LIBO_INTERNAL_ONLY
1432 template<
typename T>
1435 lastIndexOf(T & literal)
const {
1437 pData->buffer, pData->length,
1455 for(index = 0; index < getLength() ; index++)
1457 if(pData->buffer[ index ] != c)
1480 sal_Int32 result = getLength();
1482 for(index = getLength(); index > 0 ; index--)
1484 if(pData->buffer[ index - 1 ] != c)
1489 if(index < getLength())
1493 return result - getLength();
1506 return stripStart(c) + stripEnd(c);
1521 return copy( beginIndex, getLength() - beginIndex );
1539 assert(beginIndex >= 0 && beginIndex <= getLength());
1540 assert(count >= 0 && count <= getLength() - beginIndex);
1541 rtl_uString *pNew = NULL;
1550 nCapacity = capacity;
1556 rtl_uString * pData;
1561 sal_Int32 nCapacity;
1566 #ifdef RTL_STRING_UNITTEST
1569 typedef rtlunittest::OUStringBuffer OUStringBuffer;
1573 #if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST
1574 using ::rtl::OUStringBuffer;
1577 #endif // INCLUDED_RTL_USTRBUF_HXX
OUStringBuffer(const OUString &value)
Constructs a string buffer so that it represents the same sequence of characters as the string argume...
Definition: ustrbuf.hxx:126
void setLength(sal_Int32 newLength)
Sets the length of this String buffer.
Definition: ustrbuf.hxx:396
SAL_DLLPUBLIC sal_Int32 rtl_ustr_getLength(const sal_Unicode *str) SAL_THROW_EXTERN_C()
Return the length of a string.
OUStringBuffer copy(sal_Int32 beginIndex) const
Returns a new string buffer that is a substring of this string.
Definition: ustrbuf.hxx:1519
const sal_Unicode * getStr() const
Returns a pointer to the Unicode character buffer for this string.
Definition: ustring.hxx:628
sal_Int32 getLength() const
Returns the length of this string.
Definition: ustring.hxx:606
OUStringBuffer copy(sal_Int32 beginIndex, sal_Int32 count) const
Returns a new string buffer that is a substring of this string.
Definition: ustrbuf.hxx:1537
char sal_Char
A legacy synonym for char.
Definition: types.h:130
libreoffice_internal::ConstCharArrayDetector< T, OUStringBuffer & >::Type append(T &literal)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: ustrbuf.hxx:570
OUStringBuffer & insert(sal_Int32 offset, char c)
Inserts the string representation of the char argument into this string buffer.
Definition: ustrbuf.hxx:1027
OUStringBuffer & appendUtf32(sal_uInt32 c)
Appends a single UTF-32 character to this string buffer.
Definition: ustrbuf.hxx:838
SAL_DLLPUBLIC void rtl_uStringbuffer_insert_ascii(rtl_uString **This, sal_Int32 *capacity, sal_Int32 offset, const sal_Char *str, sal_Int32 len)
Inserts the 8-Bit ASCII string representation of the str array argument into this string buffer...
OUStringBuffer & append(const sal_Unicode *str)
Appends the string representation of the char array argument to this string buffer.
Definition: ustrbuf.hxx:539
OUStringBuffer & insert(sal_Int32 offset, double d)
Inserts the string representation of the double argument into this string buffer. ...
Definition: ustrbuf.hxx:1146
#define RTL_USTR_MAX_VALUEOFBOOLEAN
Definition: ustring.h:915
sal_Int32 lastIndexOf(const OUString &str) const
Returns the index within this string of the last occurrence of the specified substring, searching backward starting at the end.
Definition: ustrbuf.hxx:1382
#define SAL_DELETED_FUNCTION
short-circuit extra-verbose API namespaces
Definition: types.h:410
const sal_Unicode * getStr() const
Return a null terminated unicode character array.
Definition: ustrbuf.hxx:451
sal_Int32 getLength() const
Returns the length (character count) of this string buffer.
Definition: ustrbuf.hxx:329
#define SAL_WARN_UNUSED
Annotate classes where a compiler should warn if an instance is unused.
Definition: types.h:624
OUStringBuffer & append(sal_Unicode c)
Appends the string representation of the char argument to this string buffer.
Definition: ustrbuf.hxx:744
SAL_DLLPUBLIC rtl_uString * rtl_uStringBuffer_makeStringAndClear(rtl_uString **ppThis, sal_Int32 *nCapacity)
Returns an immutable rtl_uString object, while clearing the string buffer.
SAL_DLLPUBLIC sal_Int32 rtl_ustr_indexOfAscii_WithLength(sal_Unicode const *str, sal_Int32 len, char const *subStr, sal_Int32 subLen) SAL_THROW_EXTERN_C()
Search for the first occurrence of an ASCII substring within a string.
OUStringBuffer & append(bool b)
Appends the string representation of the bool argument to the string buffer.
Definition: ustrbuf.hxx:673
OUStringBuffer insert(sal_Int32 offset, float f)
Inserts the string representation of the float argument into this string buffer.
Definition: ustrbuf.hxx:1122
OUStringBuffer(const OUStringBuffer &value)
Allocates a new string buffer that contains the same sequence of characters as the string buffer argu...
Definition: ustrbuf.hxx:76
SAL_DLLPUBLIC sal_Int32 rtl_ustr_valueOfInt64(sal_Unicode *str, sal_Int64 l, sal_Int16 radix) SAL_THROW_EXTERN_C()
Create the string representation of a long integer.
Definition: stringutils.hxx:267
libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type lastIndexOf(T &literal) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: ustrbuf.hxx:1420
sal_Int32 strip(sal_Unicode c=(sal_Unicode)' ')
Strip the given character from the both end of the buffer.
Definition: ustrbuf.hxx:1504
Definition: stringutils.hxx:158
pData
Definition: ustring.hxx:239
sal_Unicode * appendUninitialized(sal_Int32 length)
Unsafe way to make space for a fixed amount of characters to be appended into this OUStringBuffer...
Definition: ustrbuf.hxx:857
void accessInternals(rtl_uString ***pInternalData, sal_Int32 **pInternalCapacity)
Allows access to the internal data of this OUStringBuffer, for effective manipulation.
Definition: ustrbuf.hxx:1241
sal_Int32 indexOf(sal_Unicode ch, sal_Int32 fromIndex=0) const
Returns the index within this string of the first occurrence of the specified character, starting the search at the specified index.
Definition: ustrbuf.hxx:1264
bool isEmpty() const
Checks if a string buffer is empty.
Definition: ustrbuf.hxx:342
SAL_DLLPUBLIC sal_Int32 rtl_ustr_valueOfInt32(sal_Unicode *str, sal_Int32 i, sal_Int16 radix) SAL_THROW_EXTERN_C()
Create the string representation of an integer.
#define RTL_USTR_MAX_VALUEOFINT32
Definition: ustring.h:957
OUStringBuffer & append(char c)
Appends the string representation of the ASCII char argument to this string buffer.
Definition: ustrbuf.hxx:728
OUStringBuffer & insert(sal_Int32 offset, bool b)
Inserts the string representation of the bool argument into this string buffer.
Definition: ustrbuf.hxx:1003
libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type indexOf(T &literal, sal_Int32 fromIndex=0) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: ustrbuf.hxx:1339
OUStringBuffer & insert(sal_Int32 offset, sal_Int32 i, sal_Int16 radix=10)
Inserts the string representation of the second sal_Int32 argument into this string buffer...
Definition: ustrbuf.hxx:1073
OUStringBuffer & insert(sal_Int32 offset, const OUString &str)
Inserts the string into this string buffer.
Definition: ustrbuf.hxx:878
sal_Int32 indexOf(const OUString &str, sal_Int32 fromIndex=0) const
Returns the index within this string of the first occurrence of the specified substring, starting at the specified index.
Definition: ustrbuf.hxx:1324
unsigned char sal_Bool
Definition: types.h:48
SAL_DLLPUBLIC sal_Int32 rtl_ustr_valueOfFloat(sal_Unicode *str, float f) SAL_THROW_EXTERN_C()
Create the string representation of a float.
SAL_DLLPUBLIC sal_Int32 rtl_ustr_lastIndexOfAscii_WithLength(sal_Unicode const *str, sal_Int32 len, char const *subStr, sal_Int32 subLen) SAL_THROW_EXTERN_C()
Search for the last occurrence of an ASCII substring within a string.
#define RTL_USTR_MAX_VALUEOFFLOAT
Definition: ustring.h:1022
OUStringBuffer()
Constructs a string buffer with no characters in it and an initial capacity of 16 characters...
Definition: ustrbuf.hxx:63
SAL_DLLPUBLIC void rtl_uString_release(rtl_uString *str) SAL_THROW_EXTERN_C() SAL_HOT
Decrement the reference count of a string.
OUStringBuffer & insert(sal_Int32 offset, const sal_Unicode *str)
Inserts the string representation of the char array argument into this string buffer.
Definition: ustrbuf.hxx:900
Definition: stringutils.hxx:117
OUStringBuffer & appendAscii(const sal_Char *str, sal_Int32 len)
Appends a 8-Bit ASCII character string to this string buffer.
Definition: ustrbuf.hxx:654
void ensureCapacity(sal_Int32 minimumCapacity)
Ensures that the capacity of the buffer is at least equal to the specified minimum.
Definition: ustrbuf.hxx:373
OUStringBuffer & insert(sal_Int32 offset, sal_Unicode c)
Inserts the string representation of the char argument into this string buffer.
Definition: ustrbuf.hxx:1049
sal_uInt16 sal_Unicode
Definition: types.h:155
~OUStringBuffer()
Release the string data.
Definition: ustrbuf.hxx:304
sal_Int32 getCapacity() const
Returns the current capacity of the String buffer.
Definition: ustrbuf.hxx:357
OUStringBuffer & append(sal_Int64 l, sal_Int16 radix=10)
Appends the string representation of the long argument to this string buffer.
Definition: ustrbuf.hxx:785
SAL_DLLPUBLIC sal_Int32 rtl_uStringbuffer_newFromStringBuffer(rtl_uString **newStr, sal_Int32 capacity, rtl_uString *oldStr)
Allocates a new String that contains the same sequence of characters as the string argument...
OUString makeStringAndClear()
Fill the string data in the new string and clear the buffer.
Definition: ustrbuf.hxx:317
OUStringBuffer & append(const OUString &str)
Appends the string to this string buffer.
Definition: ustrbuf.hxx:502
SAL_DLLPUBLIC void rtl_uStringbuffer_insertUtf32(rtl_uString **pThis, sal_Int32 *capacity, sal_Int32 offset, sal_uInt32 c) SAL_THROW_EXTERN_C()
Inserts a single UTF-32 character into this string buffer.
sal_Int32 lastIndexOf(const OUString &str, sal_Int32 fromIndex) const
Returns the index within this string of the last occurrence of the specified substring, searching backward starting before the specified index.
Definition: ustrbuf.hxx:1407
SAL_DLLPUBLIC void rtl_uStringbuffer_ensureCapacity(rtl_uString **This, sal_Int32 *capacity, sal_Int32 minimumCapacity)
Ensures that the capacity of the buffer is at least equal to the specified minimum.
OUStringBuffer & truncate(sal_Int32 start=0)
Removes the tail of a string buffer start at the indicate position.
Definition: ustrbuf.hxx:1200
OUStringBuffer & append(sal_Bool b)
Appends the string representation of the sal_Bool argument to the string buffer.
Definition: ustrbuf.hxx:710
This String class provides base functionality for C++ like Unicode character array handling...
Definition: ustring.hxx:106
definition of a no acquire enum for ctors
Definition: types.h:388
SAL_DLLPUBLIC void rtl_uStringbuffer_newFromStr_WithLength(rtl_uString **newStr, const sal_Unicode *value, sal_Int32 count)
Allocates a new String that contains characters from the character array argument.
#define RTL_USTR_MAX_VALUEOFDOUBLE
Definition: ustring.h:1041
#define SAL_DEPRECATED(message)
Use as follows: SAL_DEPRECATED("Don't use, it's evil.") void doit(int nPara);.
Definition: types.h:509
OUStringBuffer & replace(sal_Unicode oldChar, sal_Unicode newChar)
Replace all occurrences of oldChar in this string buffer with newChar.
Definition: ustrbuf.hxx:1216
OUStringBuffer & insert(sal_Int32 offset, sal_Bool b)
Inserts the string representation of the sal_Bool argument into this string buffer.
Definition: ustrbuf.hxx:978
sal_Int32 stripEnd(sal_Unicode c=(sal_Unicode)' ')
Strip the given character from the end of the buffer.
Definition: ustrbuf.hxx:1478
OUStringBuffer & insert(sal_Int32 offset, sal_Int64 l, sal_Int16 radix=10)
Inserts the string representation of the long argument into this string buffer.
Definition: ustrbuf.hxx:1098
SAL_DLLPUBLIC void rtl_uStringbuffer_remove(rtl_uString **This, sal_Int32 start, sal_Int32 len)
Removes the characters in a substring of this sequence.
SAL_DLLPUBLIC sal_Int32 rtl_ustr_valueOfBoolean(sal_Unicode *str, sal_Bool b) SAL_THROW_EXTERN_C()
Create the string representation of a boolean.
SAL_DLLPUBLIC void rtl_uString_newFromLiteral(rtl_uString **newStr, const sal_Char *value, sal_Int32 len, sal_Int32 allocExtra) SAL_THROW_EXTERN_C()
SAL_DLLPUBLIC sal_Int32 rtl_str_getLength(const sal_Char *str) SAL_THROW_EXTERN_C()
Return the length of a string.
OUStringBuffer & insertUtf32(sal_Int32 offset, sal_uInt32 c)
Inserts a single UTF-32 character into this string buffer.
Definition: ustrbuf.hxx:1167
sal_Int32 lastIndexOf(sal_Unicode ch) const
Returns the index within this string of the last occurrence of the specified character, searching backward starting at the end.
Definition: ustrbuf.hxx:1282
OUStringBuffer & append(const OUStringBuffer &str)
Appends the content of a stringbuffer to this string buffer.
Definition: ustrbuf.hxx:519
const OUString toString() const
Return a OUString instance reflecting the current content of this OUStringBuffer. ...
Definition: ustrbuf.hxx:487
OUStringBuffer & append(const sal_Unicode *str, sal_Int32 len)
Appends the string representation of the char array argument to this string buffer.
Definition: ustrbuf.hxx:557
Definition: stringutils.hxx:115
libreoffice_internal::ConstCharArrayDetector< T, OUStringBuffer & >::Type insert(sal_Int32 offset, T &literal)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: ustrbuf.hxx:936
sal_Int32 stripStart(sal_Unicode c=(sal_Unicode)' ')
Strip the given character from the start of the buffer.
Definition: ustrbuf.hxx:1452
SAL_DLLPUBLIC void rtl_uStringbuffer_insert(rtl_uString **This, sal_Int32 *capacity, sal_Int32 offset, const sal_Unicode *str, sal_Int32 len)
Inserts the string representation of the str array argument into this string buffer.
OUStringBuffer & append(float f)
Appends the string representation of the float argument to this string buffer.
Definition: ustrbuf.hxx:802
SAL_DLLPUBLIC sal_Int32 rtl_ustr_indexOfStr_WithLength(const sal_Unicode *str, sal_Int32 len, const sal_Unicode *subStr, sal_Int32 subLen) SAL_THROW_EXTERN_C()
Search for the first occurrence of a substring within a string.
Definition: stringutils.hxx:248
sal_Int32 lastIndexOf(sal_Unicode ch, sal_Int32 fromIndex) const
Returns the index within this string of the last occurrence of the specified character, searching backward starting before the specified index.
Definition: ustrbuf.hxx:1301
OUStringBuffer & appendAscii(const sal_Char *str)
Appends a 8-Bit ASCII character string to this string buffer.
Definition: ustrbuf.hxx:631
OUStringBuffer & append(sal_Int32 i, sal_Int16 radix=10)
Appends the string representation of the sal_Int32 argument to this string buffer.
Definition: ustrbuf.hxx:767
OUStringBuffer(int length)
Constructs a string buffer with no characters in it and an initial capacity specified by the length a...
Definition: ustrbuf.hxx:89
OUStringBuffer & append(double d)
Appends the string representation of the double argument to this string buffer.
Definition: ustrbuf.hxx:819
SAL_DLLPUBLIC sal_Int32 rtl_ustr_lastIndexOfStr_WithLength(const sal_Unicode *str, sal_Int32 len, const sal_Unicode *subStr, sal_Int32 subLen) SAL_THROW_EXTERN_C()
Search for the last occurrence of a substring within a string.
A string buffer implements a mutable sequence of characters.
Definition: ustrbuf.hxx:56
SAL_DLLPUBLIC sal_Int32 rtl_ustr_indexOfChar_WithLength(const sal_Unicode *str, sal_Int32 len, sal_Unicode ch) SAL_THROW_EXTERN_C()
Search for the first occurrence of a character within a string.
SAL_DLLPUBLIC sal_Int32 rtl_ustr_lastIndexOfChar_WithLength(const sal_Unicode *str, sal_Int32 len, sal_Unicode ch) SAL_THROW_EXTERN_C()
Search for the last occurrence of a character within a string.
SAL_DLLPUBLIC sal_Int32 rtl_ustr_valueOfDouble(sal_Unicode *str, double d) SAL_THROW_EXTERN_C()
Create the string representation of a double.
OUStringBuffer & insert(sal_Int32 offset, const sal_Unicode *str, sal_Int32 len)
Inserts the string representation of the char array argument into this string buffer.
Definition: ustrbuf.hxx:923
#define RTL_USTR_MAX_VALUEOFINT64
Definition: ustring.h:1003
SAL_DLLPUBLIC rtl_uString * rtl_uString_alloc(sal_Int32 nLen) SAL_THROW_EXTERN_C()
Allocate a new string containing space for a given number of characters.
SAL_DLLPUBLIC void rtl_uString_new_WithLength(rtl_uString **newStr, sal_Int32 nLen) SAL_THROW_EXTERN_C()
Allocate a new string containing space for a given number of characters.