16 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING" 17 #include "rtl/stringconcat.hxx" 18 #include <string_view> 19 #include <type_traits> 22 #ifdef RTL_STRING_UNITTEST 23 extern bool rtl_string_unittest_const_literal;
24 extern bool rtl_string_unittest_const_literal_function;
32 #ifdef RTL_STRING_UNITTEST 33 #define rtl rtlunittest 40 #ifdef RTL_STRING_UNITTEST 43 #define RTL_STRING_CONST_FUNCTION rtl_string_unittest_const_literal_function = true; 45 #define RTL_STRING_CONST_FUNCTION 73 , nCapacity( value.nCapacity )
90 #if defined LIBO_INTERNAL_ONLY 92 explicit OStringBuffer(T length, std::enable_if_t<std::is_integral_v<T>,
int> = 0)
97 &&
static_cast<std::make_unsigned_t<T>
>(length)
98 <=
static_cast<std::make_unsigned_t<sal_Int32>
>(
99 std::numeric_limits<sal_Int32>::max()));
105 #if defined __cpp_char8_t 122 #if defined LIBO_INTERNAL_ONLY 125 , nCapacity( sv.length() + 16 )
127 if (sv.size() > sal_uInt32(std::numeric_limits<sal_Int32>::max())) {
128 throw std::bad_alloc();
135 , nCapacity( value.getLength() + 16 )
145 template<
typename T >
150 nCapacity = length + 16;
154 template<
typename T >
159 nCapacity = length + 16;
163 #if __cplusplus > 202002L // C++23 P2266R3 "Simpler implicit move" 164 template<
typename T >
169 nCapacity = length + 16;
185 template<
typename T >
188 , nCapacity( libreoffice_internal::ConstCharArrayDetector<T>::length + 16 )
196 #ifdef RTL_STRING_UNITTEST 197 rtl_string_unittest_const_literal =
true;
215 , nCapacity( length + 16 )
220 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING" 225 template<
typename T1,
typename T2 >
228 const sal_Int32 l = c.length();
231 char* end = c.addData( pData->buffer );
240 template<
typename T, std::
size_t N >
242 : OStringBuffer( n.buf, n.length)
246 #if defined LIBO_INTERNAL_ONLY 247 operator std::string_view()
const {
return {getStr(), sal_uInt32(getLength())}; }
252 OStringBuffer& operator = (
const OStringBuffer& value )
259 nCapacity = value.nCapacity;
268 #if defined LIBO_INTERNAL_ONLY 269 OStringBuffer & operator =(std::string_view
string) {
270 sal_Int32 n =
string.length();
271 if (n >= nCapacity) {
272 ensureCapacity(n + 16);
274 std::memcpy(pData->buffer,
string.data(), n);
275 pData->buffer[n] =
'\0';
280 OStringBuffer & operator =(
OString const &
string) {
281 sal_Int32 n =
string.getLength();
282 if (n >= nCapacity) {
283 ensureCapacity(n + 16);
285 std::memcpy(pData->buffer,
string.pData->buffer, n + 1);
298 operator =(T & literal) {
303 if (n >= nCapacity) {
304 ensureCapacity(n + 16);
314 #if defined LIBO_INTERNAL_ONLY 316 template<
typename T1,
typename T2>
317 OStringBuffer & operator =(OStringConcat<T1, T2> && concat) {
318 sal_Int32
const n = concat.length();
319 if (n >= nCapacity) {
320 ensureCapacity(n + 16);
322 *concat.addData(pData->buffer) = 0;
328 template<
typename T, std::
size_t N>
329 OStringBuffer & operator =(StringNumberBase<char, T, N> && n)
331 *
this = OStringBuffer( std::move ( n ));
367 return pData->length;
380 return pData->length == 0;
434 assert(newLength >= 0);
436 if( newLength != pData->length )
438 if( newLength > nCapacity )
441 pData->buffer[newLength] =
'\0';
442 pData->length = newLength;
460 char charAt( sal_Int32 index )
462 assert(index >= 0 && index < pData->length);
463 return pData->buffer[ index ];
479 assert(index >= 0 && index < pData->length);
480 pData->buffer[ index ] = ch;
487 const char*
getStr() const SAL_RETURNS_NONNULL {
return pData->buffer; }
498 char & operator [](sal_Int32 index)
500 assert(index >= 0 && index < pData->length);
501 return pData->buffer[index];
510 return OString(pData->buffer, pData->length);
513 #if !defined LIBO_INTERNAL_ONLY 541 template<
typename T >
547 template<
typename T >
558 template<
typename T >
561 RTL_STRING_CONST_FUNCTION
584 assert( len == 0 || str != NULL );
589 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING" 594 template<
typename T1,
typename T2 >
597 sal_Int32 l = c.length();
602 char* end = c.addData( pData->buffer + pData->length );
612 template<
typename T, std::
size_t N >
615 return append( c.buf, c.length );
624 return append( s.data(), s.size() );
669 template<
typename T >
687 return append( &c, 1 );
776 sal_Int32 n = getLength();
778 return pData->buffer + n;
796 #if defined LIBO_INTERNAL_ONLY 797 OStringBuffer & insert(sal_Int32 offset, std::string_view str)
799 return insert( offset, str.data(), str.length() );
825 template<
typename T >
831 template<
typename T >
842 template<
typename T >
845 RTL_STRING_CONST_FUNCTION
874 assert( len == 0 || str != NULL );
945 return insert( offset, &c, 1 );
1078 rtl_String *** pInternalData, sal_Int32 ** pInternalCapacity)
1080 *pInternalData = &pData;
1081 *pInternalCapacity = &nCapacity;
1093 sal_Int32 nCapacity;
1096 #if defined LIBO_INTERNAL_ONLY 1097 template<>
struct ToStringHelper<OStringBuffer> {
1098 static std::size_t length(OStringBuffer
const & s) {
return s.
getLength(); }
1100 char * operator()(
char * buffer, OStringBuffer
const & s)
const SAL_RETURNS_NONNULL
1107 #ifdef RTL_STRING_UNITTEST 1112 #undef RTL_STRING_CONST_FUNCTION 1115 #if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST 1116 using ::rtl::OStringBuffer;
OStringBuffer & insert(sal_Int32 offset, const OString &str)
Inserts the string into this string buffer.
Definition: strbuf.hxx:802
sal_Int32 getLength() const
Returns the length of this string.
Definition: string.hxx:618
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:966
OStringBuffer & insert(sal_Int32 offset, bool b)
Inserts the string representation of the bool argument into this string buffer.
Definition: strbuf.hxx:921
void setLength(sal_Int32 newLength)
Sets the length of this String buffer.
Definition: strbuf.hxx:432
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:611
OStringBuffer & append(sal_Bool b)
Appends the string representation of the sal_Bool argument to the string buffer.
Definition: strbuf.hxx:640
#define RTL_STR_MAX_VALUEOFFLOAT
Definition: string.h:676
#define RTL_STR_MAX_VALUEOFINT64
Definition: string.h:634
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:644
OStringBuffer & append(const OString &str)
Appends the string to this string buffer.
Definition: strbuf.hxx:524
const char * getStr() const SAL_RETURNS_NONNULL
Return a null terminated character array.
Definition: strbuf.hxx:487
~OStringBuffer()
Release the string data.
Definition: strbuf.hxx:339
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:51
OStringBuffer & append(bool b)
Appends the string representation of the bool argument to the string buffer.
Definition: strbuf.hxx:659
OStringBuffer(sal_Int32 length)
Constructs a string buffer with no characters in it and an initial capacity specified by the length a...
Definition: strbuf.hxx:84
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:186
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:775
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:358
OStringBuffer insert(sal_Int32 offset, float f)
Inserts the string representation of the float argument into this string buffer.
Definition: strbuf.hxx:1013
OStringBuffer(const OString &value)
Constructs a string buffer so that it represents the same sequence of characters as the string argume...
Definition: strbuf.hxx:133
SAL_DLLPUBLIC void rtl_string_new(rtl_String **newStr) SAL_THROW_EXTERN_C()
Allocate a new string containing no characters.
Definition: stringutils.hxx:140
#define SAL_DEPRECATED(message)
Use as follows: SAL_DEPRECATED("Don't use, it's evil.") void doit(int nPara);.
Definition: types.h:454
#define SAL_WARN_UNUSED
Annotate classes where a compiler should warn if an instance is unused.
Definition: types.h:567
OStringBuffer & append(const char *str, sal_Int32 len)
Appends the string representation of the char array argument to this string buffer.
Definition: strbuf.hxx:582
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:213
Definition: stringutils.hxx:194
libreoffice_internal::NonConstCharArrayDetector< T, OStringBuffer &>::Type append(T &str)
Definition: strbuf.hxx:548
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:826
sal_Int32 getCapacity() const
Returns the current capacity of the String buffer.
Definition: strbuf.hxx:393
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:374
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:695
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:702
sal_Int32 getLength() const
Returns the length (character count) of this string buffer.
Definition: strbuf.hxx:365
void ensureCapacity(sal_Int32 minimumCapacity)
Ensures that the capacity of the buffer is at least equal to the specified minimum.
Definition: strbuf.hxx:409
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:872
unsigned char sal_Bool
Definition: types.h:18
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:569
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:843
OString toString() const
Return an OString instance reflecting the current content of this OStringBuffer.
Definition: strbuf.hxx:508
OStringBuffer()
Constructs a string buffer with no characters in it and an initial capacity of 16 characters...
Definition: strbuf.hxx:58
Definition: bootstrap.hxx:13
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:832
This String class provide base functionality for C++ like 8-Bit character array handling.
Definition: string.hxx:196
OStringBuffer & append(float f)
Appends the string representation of the float argument to this string buffer.
Definition: strbuf.hxx:737
OStringBuffer & insert(sal_Int32 offset, double d)
Inserts the string representation of the double argument into this string buffer. ...
Definition: strbuf.hxx:1036
OStringBuffer(T &value, typename libreoffice_internal::NonConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type=libreoffice_internal::Dummy())
Definition: strbuf.hxx:155
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:559
Definition: stringutils.hxx:166
OStringBuffer & insert(sal_Int32 offset, sal_Bool b)
Inserts the string representation of the sal_Bool argument into this string buffer.
Definition: strbuf.hxx:896
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:142
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:264
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:542
OStringBuffer & insert(sal_Int32 offset, char c)
Inserts the string representation of the char argument into this string buffer.
Definition: strbuf.hxx:943
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:990
OStringBuffer(const OStringBuffer &value)
Allocates a new string buffer that contains the same sequence of characters as the string buffer argu...
Definition: strbuf.hxx:71
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:754
bool isEmpty() const
Checks if a string buffer is empty.
Definition: strbuf.hxx:378
SAL_WARN_UNUSED_RESULT OString makeStringAndClear()
Fill the string data in the new string and clear the buffer.
Definition: strbuf.hxx:352
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:146
OStringBuffer & append(sal_Int64 l, sal_Int16 radix=10)
Appends the string representation of the long argument to this string buffer.
Definition: strbuf.hxx:720
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:1077
OStringBuffer & append(char c)
Appends the string representation of the char argument to this string buffer.
Definition: strbuf.hxx:685