20 #ifndef INCLUDED_RTL_USTRBUF_HXX
21 #define INCLUDED_RTL_USTRBUF_HXX
33 #ifdef RTL_FAST_STRING
42 #ifdef RTL_STRING_UNITTEST
43 #define rtl rtlunittest
49 #ifdef RTL_STRING_UNITTEST
113 , nCapacity( value.nCapacity )
126 , nCapacity( length )
143 , nCapacity( value.getLength() + 16 )
148 template<
typename T >
151 , nCapacity( libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 + 16 )
155 #ifdef RTL_STRING_UNITTEST
156 rtl_string_unittest_const_literal =
true;
160 #ifdef RTL_STRING_UNITTEST
165 template<
typename T >
171 rtl_string_unittest_invalid_conversion =
true;
177 template<
typename T >
178 OUStringBuffer(
const T&,
typename libreoffice_internal::ExceptCharArrayDetector< T >::Type = libreoffice_internal::Dummy() )
183 rtl_string_unittest_invalid_conversion =
true;
187 #ifdef RTL_FAST_STRING
192 template<
typename T1,
typename T2 >
193 OUStringBuffer(
const OUStringConcat< T1, T2 >& c )
195 const sal_Int32 l = c.length();
200 pData->length = end - pData->buffer;
213 nCapacity = value.nCapacity;
248 return pData->length;
261 return pData->length == 0;
315 assert(newLength >= 0);
317 if( newLength != pData->length )
319 if( newLength > nCapacity )
322 pData->buffer[newLength] = 0;
323 pData->length = newLength;
343 assert(index >= 0 && index < pData->length);
344 return pData->buffer[ index ];
360 assert(index >= 0 && index < pData->length);
361 pData->buffer[ index ] = ch;
381 assert(index >= 0 && index < pData->length);
382 return pData->buffer[index];
396 assert(index >= 0 && index < pData->length);
397 return pData->buffer[index];
406 return OUString(pData->buffer, pData->length);
477 assert( len == 0 || str != 0 );
487 template<
typename T >
496 #ifdef RTL_FAST_STRING
501 template<
typename T1,
typename T2 >
504 const int l = c.length();
508 sal_Unicode* end = c.addData( pData->buffer + pData->length );
510 pData->length = end - pData->buffer;
584 template<
typename T >
631 assert(static_cast< unsigned char >(c) <= 0x7F);
647 return append( &c, 1 );
734 return insertUtf32(getLength(), c);
754 sal_Int32 n = getLength();
756 return pData->buffer + n;
821 assert( offset >= 0 && offset <= pData->length );
823 assert( len == 0 || str != 0 );
833 template<
typename T >
911 return insert( offset, &u, 1 );
932 return insert( offset, &c, 1 );
1067 assert( start >= 0 && start <= pData->length );
1085 assert( start >= 0 && start <= pData->length );
1102 sal_Int32 index = 0;
1103 while((index = indexOf(oldChar, index)) >= 0)
1105 pData->buffer[ index ] = newChar;
1126 sal_Int32 ** pInternalCapacity)
1128 *pInternalData = &pData;
1129 *pInternalCapacity = &nCapacity;
1150 assert( fromIndex >= 0 && fromIndex <= pData->length );
1152 return (ret < 0 ? ret : ret+fromIndex);
1187 assert( fromIndex >= 0 && fromIndex <= pData->length );
1210 assert( fromIndex >= 0 && fromIndex <= pData->length );
1212 str.pData->buffer, str.pData->length );
1213 return (ret < 0 ? ret : ret+fromIndex);
1222 template<
typename T >
1227 pData->buffer + fromIndex, pData->length - fromIndex, literal,
1229 return ret < 0 ? ret : ret + fromIndex;
1252 str.pData->buffer, str.pData->length );
1276 assert( fromIndex >= 0 && fromIndex <= pData->length );
1278 str.pData->buffer, str.pData->length );
1286 template<
typename T >
1306 for(index = 0; index < getLength() ; index++)
1308 if(pData->buffer[ index ] != c)
1331 sal_Int32 result = getLength();
1333 for(index = getLength(); index > 0 ; index--)
1335 if(pData->buffer[ index - 1 ] != c)
1340 if(index < getLength())
1344 return result - getLength();
1357 return stripStart(c) + stripEnd(c);
1372 assert(beginIndex >= 0 && beginIndex <= getLength());
1373 return copy( beginIndex, getLength() - beginIndex );
1391 assert(beginIndex >= 0 && beginIndex <= getLength());
1392 assert(count >= 0 && count <= getLength() - beginIndex);
1393 rtl_uString *pNew = 0;
1398 #ifdef LIBO_INTERNAL_ONLY
1401 #ifndef RTL_FAST_STRING
1414 OUStringBuffer( rtl_uString * value,
const sal_Int32 capacity )
1417 nCapacity = capacity;
1423 rtl_uString * pData;
1428 sal_Int32 nCapacity;
1431 #ifdef RTL_FAST_STRING
1436 struct ToStringHelper< OUStringBuffer >
1438 static int length(
const OUStringBuffer& s ) {
return s.
getLength(); }
1439 static sal_Unicode* addData(
sal_Unicode* buffer,
const OUStringBuffer& s ) {
return addDataHelper( buffer, s.getStr(), s.getLength()); }
1440 static const bool allowOStringConcat =
false;
1441 static const bool allowOUStringConcat =
true;
1447 #ifdef RTL_STRING_UNITTEST
1450 typedef rtlunittest::OUStringBuffer OUStringBuffer;
1455 using ::rtl::OUStringBuffer;
1458 #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:141
void setLength(sal_Int32 newLength)
Sets the length of this String buffer.
Definition: ustrbuf.hxx:313
definition of a no acquire enum for ctors
Definition: types.h:372
unsigned char sal_Bool
Definition: types.h:48
OUStringBuffer copy(sal_Int32 beginIndex) const
Returns a new string buffer that is a substring of this string.
Definition: ustrbuf.hxx:1370
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...
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.
const sal_Unicode * getStr() const
Returns a pointer to the Unicode character buffer for this string.
Definition: ustring.hxx:416
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.
sal_Int32 getLength() const
Returns the length of this string.
Definition: ustring.hxx:394
OUStringBuffer copy(sal_Int32 beginIndex, sal_Int32 count) const
Returns a new string buffer that is a substring of this string.
Definition: ustrbuf.hxx:1389
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:488
OUStringBuffer & insert(sal_Int32 offset, char c)
Inserts the string representation of the char argument into this string buffer.
Definition: ustrbuf.hxx:908
OUStringBuffer & appendUtf32(sal_uInt32 c)
Appends a single UTF-32 character to this string buffer.
Definition: ustrbuf.hxx:733
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.
OUStringBuffer & append(const sal_Unicode *str)
Appends the string representation of the char array argument to this string buffer.
Definition: ustrbuf.hxx:456
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.
OUStringBuffer & insert(sal_Int32 offset, double d)
Inserts the string representation of the double argument into this string buffer. ...
Definition: ustrbuf.hxx:1027
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.
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:1249
const sal_Unicode * getStr() const
Return a null terminated unicode character array.
Definition: ustrbuf.hxx:368
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.
Definition: stringutils.hxx:68
sal_Int32 getLength() const
Returns the length (character count) of this string buffer.
Definition: ustrbuf.hxx:246
SAL_DLLPUBLIC sal_Int32 rtl_ustr_valueOfFloat(sal_Unicode *str, float f) SAL_THROW_EXTERN_C()
Create the string representation of a float.
#define RTL_USTR_MAX_VALUEOFFLOAT
Definition: ustring.h:1022
OUStringBuffer & append(sal_Unicode c)
Appends the string representation of the char argument to this string buffer.
Definition: ustrbuf.hxx:645
OUStringBuffer & append(bool b)
Appends the string representation of the bool argument to the string buffer.
Definition: ustrbuf.hxx:574
OUStringBuffer insert(sal_Int32 offset, float f)
Inserts the string representation of the float argument into this string buffer.
Definition: ustrbuf.hxx:1003
OUStringBuffer(T &literal, typename libreoffice_internal::ConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type=libreoffice_internal::Dummy())
Definition: ustrbuf.hxx:149
OUStringBuffer(const OUStringBuffer &value)
Allocates a new string buffer that contains the same sequence of characters as the string buffer argu...
Definition: ustrbuf.hxx:111
SAL_WARN_UNUSED_RESULT OUString concat(const OUString &str) const
Concatenates the specified string to the end of this string.
Definition: ustring.hxx:1501
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:1287
sal_Int32 strip(sal_Unicode c=(sal_Unicode)' ')
Strip the given character from the both end of the buffer.
Definition: ustrbuf.hxx:1355
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:752
SAL_DLLPUBLIC sal_Int32 rtl_str_getLength(const sal_Char *str) SAL_THROW_EXTERN_C()
Return the length of a string.
void accessInternals(rtl_uString ***pInternalData, sal_Int32 **pInternalCapacity)
Allows access to the internal data of this OUStringBuffer, for effective manipulation.
Definition: ustrbuf.hxx:1125
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:1148
bool isEmpty() const
Checks if a string buffer is empty.
Definition: ustrbuf.hxx:259
OUStringBuffer & append(char c)
Appends the string representation of the ASCII char argument to this string buffer.
Definition: ustrbuf.hxx:629
OUStringBuffer & insert(sal_Int32 offset, bool b)
Inserts the string representation of the bool argument into this string buffer.
Definition: ustrbuf.hxx:884
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:1223
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:954
OUStringBuffer & insert(sal_Int32 offset, const OUString &str)
Inserts the string into this string buffer.
Definition: ustrbuf.hxx:774
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:1208
char sal_Char
A legacy synonym for char.
Definition: types.h:130
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.
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()
Constructs a string buffer with no characters in it and an initial capacity of 16 characters...
Definition: ustrbuf.hxx:98
#define SAL_DELETED_FUNCTION
short-circuit extra-verbose API namespaces
Definition: types.h:394
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 & insert(sal_Int32 offset, const sal_Unicode *str)
Inserts the string representation of the char array argument into this string buffer.
Definition: ustrbuf.hxx:796
#define RTL_USTR_MAX_VALUEOFINT32
Definition: ustring.h:957
OUStringBuffer & appendAscii(const sal_Char *str, sal_Int32 len)
Appends a 8-Bit ASCII character string to this string buffer.
Definition: ustrbuf.hxx:554
void ensureCapacity(sal_Int32 minimumCapacity)
Ensures that the capacity of the buffer is at least equal to the specified minimum.
Definition: ustrbuf.hxx:290
OUStringBuffer & insert(sal_Int32 offset, sal_Unicode c)
Inserts the string representation of the char argument into this string buffer.
Definition: ustrbuf.hxx:930
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.
~OUStringBuffer()
Release the string data.
Definition: ustrbuf.hxx:221
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_Int32 getCapacity() const
Returns the current capacity of the String buffer.
Definition: ustrbuf.hxx:274
OUStringBuffer & append(sal_Int64 l, sal_Int16 radix=10)
Appends the string representation of the long argument to this string buffer.
Definition: ustrbuf.hxx:680
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...
OUString makeStringAndClear()
Fill the string data in the new string and clear the buffer.
Definition: ustrbuf.hxx:234
OUStringBuffer & append(const OUString &str)
Appends the string to this string buffer.
Definition: ustrbuf.hxx:419
Definition: stringutils.hxx:171
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:1274
Definition: stringutils.hxx:111
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.
OUStringBuffer & truncate(sal_Int32 start=0)
Removes the tail of a string buffer start at the indicate position.
Definition: ustrbuf.hxx:1083
SAL_DLLPUBLIC void rtl_uString_release(rtl_uString *str) SAL_THROW_EXTERN_C()
Decrement the reference count of a string.
OUStringBuffer & append(sal_Bool b)
Appends the string representation of the sal_Bool argument to the string buffer.
Definition: ustrbuf.hxx:611
This String class provides base functionality for C++ like Unicode character array handling...
Definition: ustring.hxx:81
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.
OUStringBuffer & replace(sal_Unicode oldChar, sal_Unicode newChar)
Replace all occurrences of oldChar in this string buffer with newChar.
Definition: ustrbuf.hxx:1100
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, sal_Bool b)
Inserts the string representation of the sal_Bool argument into this string buffer.
Definition: ustrbuf.hxx:859
Definition: stringutils.hxx:70
sal_Int32 stripEnd(sal_Unicode c=(sal_Unicode)' ')
Strip the given character from the end of the buffer.
Definition: ustrbuf.hxx:1329
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:979
#define RTL_USTR_MAX_VALUEOFINT64
Definition: ustring.h:1003
SAL_DLLPUBLIC rtl_uString * rtl_uStringBuffer_makeStringAndClear(rtl_uString **ppThis, sal_Int32 *nCapacity)
Returns an immutable rtl_uString object, while clearing the string buffer.
OUStringBuffer & insertUtf32(sal_Int32 offset, sal_uInt32 c)
Inserts a single UTF-32 character into this string buffer.
Definition: ustrbuf.hxx:1048
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.
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:1166
sal_uInt16 sal_Unicode
Definition: types.h:152
OUStringBuffer & append(const OUStringBuffer &str)
Appends the content of a stringbuffer to this string buffer.
Definition: ustrbuf.hxx:436
const OUString toString() const
Return a OUString instance reflecting the current content of this OUStringBuffer. ...
Definition: ustrbuf.hxx:404
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:474
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:834
sal_Int32 stripStart(sal_Unicode c=(sal_Unicode)' ')
Strip the given character from the start of the buffer.
Definition: ustrbuf.hxx:1303
OUStringBuffer & append(float f)
Appends the string representation of the float argument to this string buffer.
Definition: ustrbuf.hxx:697
Definition: stringutils.hxx:152
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:1185
OUStringBuffer & appendAscii(const sal_Char *str)
Appends a 8-Bit ASCII character string to this string buffer.
Definition: ustrbuf.hxx:531
SAL_DLLPUBLIC sal_Int32 rtl_ustr_getLength(const sal_Unicode *str) SAL_THROW_EXTERN_C()
Return the length of a string.
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:662
OUStringBuffer(int length)
Constructs a string buffer with no characters in it and an initial capacity specified by the length a...
Definition: ustrbuf.hxx:124
OUStringBuffer & append(double d)
Appends the string representation of the double argument to this string buffer.
Definition: ustrbuf.hxx:714
A string buffer implements a mutable sequence of characters.
Definition: ustrbuf.hxx:91
#define RTL_USTR_MAX_VALUEOFDOUBLE
Definition: ustring.h:1041
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:819
SAL_DLLPUBLIC void rtl_uString_newFromLiteral(rtl_uString **newStr, const sal_Char *value, sal_Int32 len, sal_Int32 allocExtra) SAL_THROW_EXTERN_C()
#define SAL_WARN_UNUSED
Annotate classes where a compiler should warn if an instance is unused.
Definition: types.h:588
#define SAL_DEPRECATED(message)
Use as follows: SAL_DEPRECATED("Dont use, its evil.") void doit(int nPara);.
Definition: types.h:475
#define RTL_USTR_MAX_VALUEOFBOOLEAN
Definition: ustring.h:915