35 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING" 36 #include "rtl/stringconcat.hxx" 37 #include <string_view> 40 #ifdef RTL_STRING_UNITTEST 41 extern bool rtl_string_unittest_const_literal;
42 extern bool rtl_string_unittest_const_literal_function;
50 #ifdef RTL_STRING_UNITTEST 51 #define rtl rtlunittest 58 #ifdef RTL_STRING_UNITTEST 61 #define RTL_STRING_CONST_FUNCTION rtl_string_unittest_const_literal_function = true; 63 #define RTL_STRING_CONST_FUNCTION 91 , nCapacity( value.nCapacity )
104 , nCapacity( length )
108 #if __cplusplus >= 201103L 113 #if SAL_TYPES_SIZEOFLONG == 4 115 explicit OStringBuffer(
long length)
116 : OStringBuffer(static_cast<int>(length))
119 explicit OStringBuffer(
unsigned long length)
120 : OStringBuffer(static_cast<int>(length))
125 explicit OStringBuffer(
char) =
delete;
139 #if defined LIBO_INTERNAL_ONLY 140 OStringBuffer(std::string_view sv)
142 , nCapacity( sv.length() + 16 )
144 if (sv.size() > sal_uInt32(std::numeric_limits<sal_Int32>::max())) {
145 throw std::bad_alloc();
152 , nCapacity( value.getLength() + 16 )
162 template<
typename T >
167 nCapacity = length + 16;
171 template<
typename T >
176 nCapacity = length + 16;
191 template<
typename T >
194 , nCapacity( libreoffice_internal::ConstCharArrayDetector<T>::length + 16 )
202 #ifdef RTL_STRING_UNITTEST 203 rtl_string_unittest_const_literal =
true;
221 , nCapacity( length + 16 )
226 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING" 231 template<
typename T1,
typename T2 >
234 const sal_Int32 l = c.length();
237 char* end = c.addData( pData->buffer );
246 template<
typename T >
247 OStringBuffer( OStringNumber< T >&& n )
248 : OStringBuffer( OString( n ))
252 #if defined LIBO_INTERNAL_ONLY 253 operator std::string_view()
const {
return {getStr(), sal_uInt32(getLength())}; }
265 nCapacity = value.nCapacity;
274 #if defined LIBO_INTERNAL_ONLY 276 sal_Int32 n =
string.length();
277 if (n >= nCapacity) {
278 ensureCapacity(n + 16);
280 std::memcpy(pData->buffer,
string.data(), n + 1);
287 if (n >= nCapacity) {
288 ensureCapacity(n + 16);
290 std::memcpy(pData->buffer,
string.pData->buffer, n + 1);
303 operator =(T & literal) {
308 if (n >= nCapacity) {
309 ensureCapacity(n + 16);
319 #if defined LIBO_INTERNAL_ONLY 321 template<
typename T1,
typename T2>
322 OStringBuffer & operator =(OStringConcat<T1, T2> && concat) {
323 sal_Int32
const n = concat.length();
324 if (n >= nCapacity) {
325 ensureCapacity(n + 16);
327 *concat.addData(pData->buffer) = 0;
334 OStringBuffer & operator =(OStringNumber<T> && n)
336 *
this = OStringBuffer( std::move ( n ));
372 return pData->length;
385 return pData->length == 0;
439 assert(newLength >= 0);
441 if( newLength != pData->length )
443 if( newLength > nCapacity )
446 pData->buffer[newLength] =
'\0';
447 pData->length = newLength;
465 char charAt( sal_Int32 index )
467 assert(index >= 0 && index < pData->length);
468 return pData->buffer[ index ];
484 assert(index >= 0 && index < pData->length);
485 pData->buffer[ index ] = ch;
492 const char*
getStr() const SAL_RETURNS_NONNULL {
return pData->buffer; }
503 char & operator [](sal_Int32 index)
505 assert(index >= 0 && index < pData->length);
506 return pData->buffer[index];
515 return OString(pData->buffer, pData->length);
518 #if !defined LIBO_INTERNAL_ONLY 546 template<
typename T >
552 template<
typename T >
563 template<
typename T >
566 RTL_STRING_CONST_FUNCTION
589 assert( len == 0 || str != NULL );
594 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING" 599 template<
typename T1,
typename T2 >
602 sal_Int32 l = c.length();
607 char* end = c.addData( pData->buffer + pData->length );
617 template<
typename T >
618 OStringBuffer& append( OStringNumber< T >&& c )
620 return append( c.buf, c.length );
627 OStringBuffer& append( std::string_view s )
629 return append( s.data(), s.size() );
674 template<
typename T >
692 return append( &c, 1 );
781 sal_Int32 n = getLength();
783 return pData->buffer + n;
801 #if defined LIBO_INTERNAL_ONLY 802 OStringBuffer & insert(sal_Int32 offset, std::string_view str)
804 return insert( offset, str.data(), str.length() );
830 template<
typename T >
836 template<
typename T >
847 template<
typename T >
850 RTL_STRING_CONST_FUNCTION
879 assert( len == 0 || str != NULL );
950 return insert( offset, &c, 1 );
1083 rtl_String *** pInternalData, sal_Int32 ** pInternalCapacity)
1085 *pInternalData = &pData;
1086 *pInternalCapacity = &nCapacity;
1098 sal_Int32 nCapacity;
1101 #if defined LIBO_INTERNAL_ONLY 1102 template<>
struct ToStringHelper<OStringBuffer> {
1103 static std::size_t length(OStringBuffer
const & s) {
return s.getLength(); }
1105 static char * addData(
char * buffer, OStringBuffer
const & s) SAL_RETURNS_NONNULL
1106 {
return addDataHelper(buffer, s.getStr(), s.getLength()); }
1108 static constexpr
bool allowOStringConcat =
true;
1109 static constexpr
bool allowOUStringConcat =
false;
1115 #ifdef RTL_STRING_UNITTEST 1118 typedef rtlunittest::OStringBuffer OStringBuffer;
1120 #undef RTL_STRING_CONST_FUNCTION 1123 #if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST 1124 using ::rtl::OStringBuffer;
OStringBuffer & insert(sal_Int32 offset, const OString &str)
Inserts the string into this string buffer.
Definition: strbuf.hxx:807
OStringBuffer(int length)
Constructs a string buffer with no characters in it and an initial capacity specified by the length a...
Definition: strbuf.hxx:102
sal_Int32 getLength() const
Returns the length of this string.
Definition: string.hxx:577
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:971
OStringBuffer & insert(sal_Int32 offset, bool b)
Inserts the string representation of the bool argument into this string buffer.
Definition: strbuf.hxx:926
void setLength(sal_Int32 newLength)
Sets the length of this String buffer.
Definition: strbuf.hxx:437
SAL_DLLPUBLIC sal_Int32 rtl_str_valueOfFloat(char *str, float f) SAL_THROW_EXTERN_C()
Create the string representation of a float.
#define RTL_STR_MAX_VALUEOFINT32
Definition: string.h:631
OStringBuffer & append(sal_Bool b)
Appends the string representation of the sal_Bool argument to the string buffer.
Definition: strbuf.hxx:645
#define RTL_STR_MAX_VALUEOFFLOAT
Definition: string.h:696
#define RTL_STR_MAX_VALUEOFINT64
Definition: string.h:654
SAL_DLLPUBLIC sal_Int32 rtl_str_valueOfBoolean(char *str, sal_Bool b) SAL_THROW_EXTERN_C()
Create the string representation of a boolean.
const char * getStr() const SAL_RETURNS_NONNULL
Returns a pointer to the characters of this string.
Definition: string.hxx:603
OStringBuffer & append(const OString &str)
Appends the string to this string buffer.
Definition: strbuf.hxx:529
const char * getStr() const SAL_RETURNS_NONNULL
Return a null terminated character array.
Definition: strbuf.hxx:492
~OStringBuffer()
Release the string data.
Definition: strbuf.hxx:344
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.
A string buffer implements a mutable sequence of characters.
Definition: strbuf.hxx:69
OStringBuffer & append(bool b)
Appends the string representation of the bool argument to the string buffer.
Definition: strbuf.hxx:664
OStringBuffer(T &literal, typename libreoffice_internal::ConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type=libreoffice_internal::Dummy())
Constructs a string buffer so that it represents the same sequence of characters as the string litera...
Definition: strbuf.hxx:192
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:780
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.
#define SAL_DELETED_FUNCTION
short-circuit extra-verbose API namespaces
Definition: types.h:378
OStringBuffer insert(sal_Int32 offset, float f)
Inserts the string representation of the float argument into this string buffer.
Definition: strbuf.hxx:1018
OStringBuffer(const OString &value)
Constructs a string buffer so that it represents the same sequence of characters as the string argume...
Definition: strbuf.hxx:150
SAL_DLLPUBLIC void rtl_string_new(rtl_String **newStr) SAL_THROW_EXTERN_C()
Allocate a new string containing no characters.
Definition: stringutils.hxx:136
#define SAL_DEPRECATED(message)
Use as follows: SAL_DEPRECATED("Don't use, it's evil.") void doit(int nPara);.
Definition: types.h:474
#define SAL_WARN_UNUSED
Annotate classes where a compiler should warn if an instance is unused.
Definition: types.h:587
OStringBuffer & append(const char *str, sal_Int32 len)
Appends the string representation of the char array argument to this string buffer.
Definition: strbuf.hxx:587
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:219
Definition: stringutils.hxx:190
libreoffice_internal::NonConstCharArrayDetector< T, OStringBuffer &>::Type append(T &str)
Definition: strbuf.hxx:553
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:831
sal_Int32 getCapacity() const
Returns the current capacity of the String buffer.
Definition: strbuf.hxx:398
SAL_DLLPUBLIC void rtl_stringbuffer_remove(rtl_String **This, sal_Int32 start, sal_Int32 len)
Removes the characters in a substring of this sequence.
Definition: stringutils.hxx:370
SAL_DLLPUBLIC void rtl_string_release(rtl_String *str) SAL_THROW_EXTERN_C()
Decrement the reference count of a string.
#define RTL_STR_MAX_VALUEOFDOUBLE
Definition: string.h:715
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:707
sal_uInt16 sal_Unicode
Definition: types.h:123
sal_Int32 getLength() const
Returns the length (character count) of this string buffer.
Definition: strbuf.hxx:370
void ensureCapacity(sal_Int32 minimumCapacity)
Ensures that the capacity of the buffer is at least equal to the specified minimum.
Definition: strbuf.hxx:414
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:877
unsigned char sal_Bool
Definition: types.h:38
SAL_DLLPUBLIC sal_Int32 rtl_str_valueOfDouble(char *str, double d) SAL_THROW_EXTERN_C()
Create the string representation of a double.
#define RTL_STR_MAX_VALUEOFBOOLEAN
Definition: string.h:589
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 ...
Definition: strbuf.hxx:848
OString toString() const
Return an OString instance reflecting the current content of this OStringBuffer.
Definition: strbuf.hxx:513
OStringBuffer()
Constructs a string buffer with no characters in it and an initial capacity of 16 characters...
Definition: strbuf.hxx:76
Definition: bootstrap.hxx:33
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.
libreoffice_internal::NonConstCharArrayDetector< T, OStringBuffer &>::Type insert(sal_Int32 offset, T &str)
Definition: strbuf.hxx:837
This String class provide base functionality for C++ like 8-Bit character array handling.
Definition: string.hxx:180
OStringBuffer & append(float f)
Appends the string representation of the float argument to this string buffer.
Definition: strbuf.hxx:742
OStringBuffer & insert(sal_Int32 offset, double d)
Inserts the string representation of the double argument into this string buffer. ...
Definition: strbuf.hxx:1041
OStringBuffer(T &value, typename libreoffice_internal::NonConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type=libreoffice_internal::Dummy())
Definition: strbuf.hxx:172
libreoffice_internal::ConstCharArrayDetector< T, OStringBuffer &>::Type append(T &literal)
This is an overloaded member function, provided for convenience. It differs from the above function ...
Definition: strbuf.hxx:564
Definition: stringutils.hxx:162
OStringBuffer & insert(sal_Int32 offset, sal_Bool b)
Inserts the string representation of the sal_Bool argument into this string buffer.
Definition: strbuf.hxx:901
SAL_DLLPUBLIC void rtl_string_newFromLiteral(rtl_String **newStr, const char *value, sal_Int32 len, sal_Int32 allocExtra) SAL_THROW_EXTERN_C()
Definition: stringutils.hxx:138
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...
SAL_DLLPUBLIC sal_Int32 rtl_str_getLength(const char *str) SAL_THROW_EXTERN_C()
Return the length of a string.
#define SAL_WARN_UNUSED_RESULT
Use this as markup for functions and methods whose return value must be checked.
Definition: types.h:284
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:547
OStringBuffer & insert(sal_Int32 offset, char c)
Inserts the string representation of the char argument into this string buffer.
Definition: strbuf.hxx:948
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 & 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:995
OStringBuffer(const OStringBuffer &value)
Allocates a new string buffer that contains the same sequence of characters as the string buffer argu...
Definition: strbuf.hxx:89
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.
OStringBuffer & append(double d)
Appends the string representation of the double argument to this string buffer.
Definition: strbuf.hxx:759
bool isEmpty() const
Checks if a string buffer is empty.
Definition: strbuf.hxx:383
SAL_WARN_UNUSED_RESULT OString makeStringAndClear()
Fill the string data in the new string and clear the buffer.
Definition: strbuf.hxx:357
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.
OStringBuffer(const T &value, typename libreoffice_internal::CharPtrDetector< T, libreoffice_internal::Dummy >::Type=libreoffice_internal::Dummy())
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: strbuf.hxx:163
OStringBuffer & append(sal_Int64 l, sal_Int16 radix=10)
Appends the string representation of the long argument to this string buffer.
Definition: strbuf.hxx:725
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.
void accessInternals(rtl_String ***pInternalData, sal_Int32 **pInternalCapacity)
Allows access to the internal data of this OStringBuffer, for effective manipulation.
Definition: strbuf.hxx:1082
OStringBuffer & append(char c)
Appends the string representation of the char argument to this string buffer.
Definition: strbuf.hxx:690