31 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
32 #include "rtl/stringconcat.hxx"
35 #ifdef RTL_STRING_UNITTEST
36 extern bool rtl_string_unittest_const_literal;
37 extern bool rtl_string_unittest_const_literal_function;
45 #ifdef RTL_STRING_UNITTEST
46 #define rtl rtlunittest
53 #ifdef RTL_STRING_UNITTEST
56 #define RTL_STRING_CONST_FUNCTION rtl_string_unittest_const_literal_function = true;
58 #define RTL_STRING_CONST_FUNCTION
86 , nCapacity( value.nCapacity )
103 #if __cplusplus >= 201103L
108 #if SAL_TYPES_SIZEOFLONG == 4
110 explicit OStringBuffer(
long length)
111 : OStringBuffer(static_cast<int>(length))
114 explicit OStringBuffer(
unsigned long length)
115 : OStringBuffer(static_cast<int>(length))
120 explicit OStringBuffer(
char) =
delete;
136 , nCapacity( value.getLength() + 16 )
145 template<
typename T >
150 nCapacity = length + 16;
154 template<
typename T >
159 nCapacity = length + 16;
174 template<
typename T >
177 , nCapacity( libreoffice_internal::ConstCharArrayDetector<T>::length + 16 )
185 #ifdef RTL_STRING_UNITTEST
186 rtl_string_unittest_const_literal =
true;
204 , nCapacity( length + 16 )
209 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
214 template<
typename T1,
typename T2 >
217 const sal_Int32 l = c.length();
220 char* end = c.addData( pData->buffer );
229 template<
typename T >
230 OStringBuffer( OStringNumber< T >&& n )
231 : OStringBuffer( OString( n ))
255 if (n >= nCapacity) {
256 ensureCapacity(n + 16);
258 std::memcpy(pData->buffer,
string.pData->buffer, n + 1);
270 operator =(T & literal) {
275 if (n >= nCapacity) {
276 ensureCapacity(n + 16);
286 #if defined LIBO_INTERNAL_ONLY
288 template<
typename T1,
typename T2>
289 OStringBuffer & operator =(OStringConcat<T1, T2> && concat) {
290 sal_Int32
const n = concat.length();
291 if (n >= nCapacity) {
292 ensureCapacity(n + 16);
294 *concat.addData(pData->buffer) = 0;
301 OStringBuffer & operator =(OStringNumber<T> && n)
303 *
this = OStringBuffer( std::move ( n ));
339 return pData->length;
352 return pData->length == 0;
406 assert(newLength >= 0);
408 if( newLength != pData->length )
410 if( newLength > nCapacity )
413 pData->buffer[newLength] =
'\0';
414 pData->length = newLength;
432 char charAt( sal_Int32 index )
434 assert(index >= 0 && index < pData->length);
435 return pData->buffer[ index ];
451 assert(index >= 0 && index < pData->length);
452 pData->buffer[ index ] = ch;
459 const char*
getStr() const SAL_RETURNS_NONNULL {
return pData->buffer; }
470 char & operator [](sal_Int32 index)
472 assert(index >= 0 && index < pData->length);
473 return pData->buffer[index];
482 return OString(pData->buffer, pData->length);
511 template<
typename T >
517 template<
typename T >
528 template<
typename T >
531 RTL_STRING_CONST_FUNCTION
554 assert( len == 0 || str != NULL );
559 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
564 template<
typename T1,
typename T2 >
567 sal_Int32 l = c.length();
572 char* end = c.addData( pData->buffer + pData->length );
582 template<
typename T >
583 OStringBuffer& append( OStringNumber< T >&& c )
585 return append( c.buf, c.length );
630 template<
typename T >
648 return append( &c, 1 );
737 sal_Int32 n = getLength();
739 return pData->buffer + n;
779 template<
typename T >
785 template<
typename T >
796 template<
typename T >
799 RTL_STRING_CONST_FUNCTION
828 assert( len == 0 || str != NULL );
899 return insert( offset, &c, 1 );
1032 rtl_String *** pInternalData, sal_Int32 ** pInternalCapacity)
1034 *pInternalData = &pData;
1035 *pInternalCapacity = &nCapacity;
1047 sal_Int32 nCapacity;
1050 #if defined LIBO_INTERNAL_ONLY
1051 template<>
struct ToStringHelper<OStringBuffer> {
1052 static std::size_t length(OStringBuffer
const & s) {
return s.getLength(); }
1054 static char * addData(
char * buffer, OStringBuffer
const & s) SAL_RETURNS_NONNULL
1055 {
return addDataHelper(buffer, s.getStr(), s.getLength()); }
1057 static constexpr
bool allowOStringConcat =
true;
1058 static constexpr
bool allowOUStringConcat =
false;
1064 #ifdef RTL_STRING_UNITTEST
1067 typedef rtlunittest::OStringBuffer OStringBuffer;
1069 #undef RTL_STRING_CONST_FUNCTION
1072 #if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST
1073 using ::rtl::OStringBuffer;
OStringBuffer & insert(sal_Int32 offset, char c)
Inserts the string representation of the char argument into this string buffer.
Definition: strbuf.hxx:897
bool isEmpty() const
Checks if a string buffer is empty.
Definition: strbuf.hxx:350
OStringBuffer & append(sal_Bool b)
Appends the string representation of the sal_Bool argument to the string buffer.
Definition: strbuf.hxx:601
OStringBuffer & insert(sal_Int32 offset, bool b)
Inserts the string representation of the bool argument into this string buffer.
Definition: strbuf.hxx:875
OStringBuffer insert(sal_Int32 offset, float f)
Inserts the string representation of the float argument into this string buffer.
Definition: strbuf.hxx:967
sal_Int32 getLength() const
Returns the length (character count) of this string buffer.
Definition: strbuf.hxx:337
libreoffice_internal::NonConstCharArrayDetector< T, OStringBuffer & >::Type append(T &str)
Definition: strbuf.hxx:518
OStringBuffer & 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: strbuf.hxx:920
SAL_DLLPUBLIC void rtl_string_new(rtl_String **newStr) SAL_THROW_EXTERN_C()
Allocate a new string containing no characters.
#define SAL_DEPRECATED(message)
Use as follows: SAL_DEPRECATED("Don't use, it's evil.") void doit(int nPara);.
Definition: types.h:445
A string buffer implements a mutable sequence of characters.
Definition: strbuf.hxx:64
libreoffice_internal::NonConstCharArrayDetector< T, OStringBuffer & >::Type insert(sal_Int32 offset, T &str)
Definition: strbuf.hxx:786
SAL_DLLPUBLIC void rtl_string_newFromLiteral(rtl_String **newStr, const char *value, sal_Int32 len, sal_Int32 allocExtra) SAL_THROW_EXTERN_C()
void ensureCapacity(sal_Int32 minimumCapacity)
Ensures that the capacity of the buffer is at least equal to the specified minimum.
Definition: strbuf.hxx:381
OStringBuffer & insert(sal_Int32 offset, double d)
Inserts the string representation of the double argument into this string buffer. ...
Definition: strbuf.hxx:990
OStringBuffer & append(float f)
Appends the string representation of the float argument to this string buffer.
Definition: strbuf.hxx:698
#define RTL_STR_MAX_VALUEOFDOUBLE
Definition: string.h:711
void setLength(sal_Int32 newLength)
Sets the length of this String buffer.
Definition: strbuf.hxx:404
#define RTL_STR_MAX_VALUEOFINT64
Definition: string.h:650
const char * getStr() const SAL_RETURNS_NONNULL
Returns a pointer to the characters of this string.
Definition: string.hxx:551
OStringBuffer & insert(sal_Int32 offset, sal_Bool b)
Inserts the string representation of the sal_Bool argument into this string buffer.
Definition: strbuf.hxx:850
Definition: stringutils.hxx:365
#define SAL_WARN_UNUSED_RESULT
Use this as markup for functions and methods whose return value must be checked.
Definition: types.h:280
SAL_DLLPUBLIC void rtl_stringbuffer_insert(rtl_String **This, sal_Int32 *capacity, sal_Int32 offset, const char *str, sal_Int32 len)
Inserts the string representation of the char array argument into this string buffer.
Definition: stringutils.hxx:185
OStringBuffer(const char *value, sal_Int32 length)
Constructs a string buffer so that it represents the same sequence of characters as the string argume...
Definition: strbuf.hxx:202
OStringBuffer & insert(sal_Int32 offset, const char *str, sal_Int32 len)
Inserts the string representation of the char array argument into this string buffer.
Definition: strbuf.hxx:826
sal_Int32 getLength() const
Returns the length of this string.
Definition: string.hxx:525
This String class provide base functionality for C++ like 8-Bit character array handling.
Definition: string.hxx:170
rtl_stringbuffer_newFromStr_WithLength & pData
Definition: strbuf.hxx:151
SAL_DLLPUBLIC void rtl_stringbuffer_remove(rtl_String **This, sal_Int32 start, sal_Int32 len)
Removes the characters in a substring of this sequence.
SAL_DLLPUBLIC sal_Int32 rtl_stringbuffer_newFromStringBuffer(rtl_String **newStr, sal_Int32 capacity, rtl_String *oldStr)
Allocates a new String that contains the same sequence of characters as the string argument...
libreoffice_internal::ConstCharArrayDetector< T, OStringBuffer & >::Type insert(sal_Int32 offset, T &literal)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: strbuf.hxx:797
SAL_WARN_UNUSED_RESULT OString makeStringAndClear()
Fill the string data in the new string and clear the buffer.
Definition: strbuf.hxx:324
char * appendUninitialized(sal_Int32 length) SAL_RETURNS_NONNULL
Unsafe way to make space for a fixed amount of characters to be appended into this OStringBuffer...
Definition: strbuf.hxx:736
SAL_DLLPUBLIC sal_Int32 rtl_str_valueOfDouble(char *str, double d) SAL_THROW_EXTERN_C()
Create the string representation of a double.
Definition: stringutils.hxx:157
OStringBuffer & append(const OString &str)
Appends the string to this string buffer.
Definition: strbuf.hxx:495
#define RTL_STR_MAX_VALUEOFBOOLEAN
Definition: string.h:585
OStringBuffer & append(const char *str, sal_Int32 len)
Appends the string representation of the char array argument to this string buffer.
Definition: strbuf.hxx:552
SAL_DLLPUBLIC void rtl_stringbuffer_newFromStr_WithLength(rtl_String **newStr, const char *value, sal_Int32 count)
Allocates a new String that contains characters from the character array argument.
Definition: stringutils.hxx:133
SAL_DLLPUBLIC void rtl_stringbuffer_ensureCapacity(rtl_String **This, sal_Int32 *capacity, sal_Int32 minimumCapacity)
Ensures that the capacity of the buffer is at least equal to the specified minimum.
const OString toString() const
Return an OString instance reflecting the current content of this OStringBuffer.
Definition: strbuf.hxx:480
unsigned char sal_Bool
Definition: types.h:34
OStringBuffer & append(double d)
Appends the string representation of the double argument to this string buffer.
Definition: strbuf.hxx:715
libreoffice_internal::CharPtrDetector< T, OStringBuffer & >::Type append(const T &str)
Appends the string representation of the char array argument to this string buffer.
Definition: strbuf.hxx:512
const char * getStr() const SAL_RETURNS_NONNULL
Return a null terminated character array.
Definition: strbuf.hxx:459
nCapacity
Definition: strbuf.hxx:150
OStringBuffer()
Constructs a string buffer with no characters in it and an initial capacity of 16 characters...
Definition: strbuf.hxx:71
libreoffice_internal::CharPtrDetector< T, OStringBuffer & >::Type insert(sal_Int32 offset, const T &str)
Inserts the string representation of the char array argument into this string buffer.
Definition: strbuf.hxx:780
SAL_DLLPUBLIC sal_Int32 rtl_str_valueOfInt32(char *str, sal_Int32 i, sal_Int16 radix) SAL_THROW_EXTERN_C()
Create the string representation of an integer.
libreoffice_internal::ConstCharArrayDetector< T, OStringBuffer & >::Type append(T &literal)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: strbuf.hxx:529
~OStringBuffer()
Release the string data.
Definition: strbuf.hxx:311
SAL_DLLPUBLIC sal_Int32 rtl_str_valueOfFloat(char *str, float f) SAL_THROW_EXTERN_C()
Create the string representation of a float.
OStringBuffer & append(bool b)
Appends the string representation of the bool argument to the string buffer.
Definition: strbuf.hxx:620
#define SAL_DELETED_FUNCTION
short-circuit extra-verbose API namespaces
Definition: types.h:374
OStringBuffer & append(sal_Int64 l, sal_Int16 radix=10)
Appends the string representation of the long argument to this string buffer.
Definition: strbuf.hxx:681
SAL_DLLPUBLIC sal_Int32 rtl_str_valueOfBoolean(char *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: strbuf.hxx:365
#define SAL_WARN_UNUSED
Annotate classes where a compiler should warn if an instance is unused.
Definition: types.h:558
SAL_DLLPUBLIC void rtl_string_new_WithLength(rtl_String **newStr, sal_Int32 len) SAL_THROW_EXTERN_C()
Allocate a new string containing space for a given number of characters.
OStringBuffer(const OString &value)
Constructs a string buffer so that it represents the same sequence of characters as the string argume...
Definition: strbuf.hxx:134
Definition: stringutils.hxx:131
OStringBuffer & insert(sal_Int32 offset, const OString &str)
Inserts the string into this string buffer.
Definition: strbuf.hxx:757
OStringBuffer(const OStringBuffer &value)
Allocates a new string buffer that contains the same sequence of characters as the string buffer argu...
Definition: strbuf.hxx:84
void accessInternals(rtl_String ***pInternalData, sal_Int32 **pInternalCapacity)
Allows access to the internal data of this OStringBuffer, for effective manipulation.
Definition: strbuf.hxx:1031
OStringBuffer & append(sal_Int32 i, sal_Int16 radix=10)
Appends the string representation of the sal_Int32 argument to this string buffer.
Definition: strbuf.hxx:663
#define RTL_STR_MAX_VALUEOFFLOAT
Definition: string.h:692
SAL_DLLPUBLIC sal_Int32 rtl_str_getLength(const char *str) SAL_THROW_EXTERN_C()
Return the length of a string.
SAL_DLLPUBLIC sal_Int32 rtl_str_valueOfInt64(char *str, sal_Int64 l, sal_Int16 radix) SAL_THROW_EXTERN_C()
Create the string representation of a long integer.
OStringBuffer(int length)
Constructs a string buffer with no characters in it and an initial capacity specified by the length a...
Definition: strbuf.hxx:97
SAL_DLLPUBLIC rtl_String * rtl_string_alloc(sal_Int32 nLen) SAL_THROW_EXTERN_C()
Allocate a new string containing space for a given number of characters.
sal_uInt16 sal_Unicode
Definition: types.h:119
#define RTL_STR_MAX_VALUEOFINT32
Definition: string.h:627
SAL_DLLPUBLIC void rtl_string_release(rtl_String *str) SAL_THROW_EXTERN_C()
Decrement the reference count of a string.
OStringBuffer & insert(sal_Int32 offset, sal_Int64 l, sal_Int16 radix=10)
Inserts the string representation of the long argument into this string buffer.
Definition: strbuf.hxx:944