LibreOffice
LibreOffice 6.4 SDK C/C++ API Reference
|
Go to the documentation of this file.
20 #ifndef INCLUDED_RTL_STRBUF_HXX
21 #define INCLUDED_RTL_STRBUF_HXX
32 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
33 #include "rtl/stringconcat.hxx"
36 #ifdef RTL_STRING_UNITTEST
37 extern bool rtl_string_unittest_const_literal;
38 extern bool rtl_string_unittest_const_literal_function;
46 #ifdef RTL_STRING_UNITTEST
47 #define rtl rtlunittest
54 #ifdef RTL_STRING_UNITTEST
57 #define RTL_STRING_CONST_FUNCTION rtl_string_unittest_const_literal_function = true;
59 #define RTL_STRING_CONST_FUNCTION
87 , nCapacity( value.nCapacity )
100 , nCapacity( length )
104 #if __cplusplus >= 201103L
109 #if SAL_TYPES_SIZEOFLONG == 4
111 explicit OStringBuffer(
long length)
112 : OStringBuffer(static_cast<int>(length))
115 explicit OStringBuffer(
unsigned long length)
116 : OStringBuffer(static_cast<int>(length))
121 explicit OStringBuffer(
char) =
delete;
137 , nCapacity( value.getLength() + 16 )
146 template<
typename T >
151 nCapacity = length + 16;
155 template<
typename T >
160 nCapacity = length + 16;
175 template<
typename T >
178 , nCapacity( libreoffice_internal::ConstCharArrayDetector<T>::length + 16 )
186 #ifdef RTL_STRING_UNITTEST
187 rtl_string_unittest_const_literal =
true;
205 , nCapacity( length + 16 )
210 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
215 template<
typename T1,
typename T2 >
218 const sal_Int32 l = c.length();
221 char* end = c.addData( pData->buffer );
230 template<
typename T >
231 OStringBuffer( OStringNumber< T >&& n )
232 : OStringBuffer( OString( n ))
245 nCapacity = value.nCapacity;
256 if (n >= nCapacity) {
257 ensureCapacity(n + 16);
259 std::memcpy(pData->buffer,
string.pData->buffer, n + 1);
271 operator =(T & literal) {
276 if (n >= nCapacity) {
277 ensureCapacity(n + 16);
287 #if defined LIBO_INTERNAL_ONLY
289 template<
typename T1,
typename T2>
290 OStringBuffer & operator =(OStringConcat<T1, T2> && concat) {
291 sal_Int32
const n = concat.length();
292 if (n >= nCapacity) {
293 ensureCapacity(n + 16);
295 *concat.addData(pData->buffer) = 0;
302 OStringBuffer & operator =(OStringNumber<T> && n)
304 return *
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;
434 assert(index >= 0 && index < pData->length);
435 return pData->buffer[ index ];
451 assert(index >= 0 && index < pData->length);
452 pData->buffer[ index ] = ch;
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;
1038 #if defined LIBO_INTERNAL_ONLY
1039 explicit operator OStringView()
const
1041 return OStringView(getStr(), getLength());
1054 sal_Int32 nCapacity;
1059 #ifdef RTL_STRING_UNITTEST
1062 typedef rtlunittest::OStringBuffer OStringBuffer;
1064 #undef RTL_STRING_CONST_FUNCTION
1067 #if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST
1068 using ::rtl::OStringBuffer;
1071 #endif // INCLUDED_RTL_STRBUF_HXX
OStringBuffer & append(sal_Char c)
Appends the string representation of the char argument to this string buffer.
Definition: strbuf.hxx:646
SAL_DLLPUBLIC void rtl_stringbuffer_newFromStr_WithLength(rtl_String **newStr, const sal_Char *value, sal_Int32 count)
Allocates a new String that contains characters from the character array argument.
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.
char sal_Char
A legacy synonym for char.
Definition: types.h:120
Definition: stringutils.hxx:133
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
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
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_Int32 getCapacity() const
Returns the current capacity of the String buffer.
Definition: strbuf.hxx:365
#define RTL_STR_MAX_VALUEOFDOUBLE
Definition: string.h:711
sal_Int32 getLength() const
Returns the length (character count) of this string buffer.
Definition: strbuf.hxx:337
This String class provide base functionality for C++ like 8-Bit character array handling.
Definition: string.hxx:98
#define RTL_STR_MAX_VALUEOFFLOAT
Definition: string.h:692
OStringBuffer & append(sal_Bool b)
Appends the string representation of the sal_Bool argument to the string buffer.
Definition: strbuf.hxx:601
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:147
SAL_DLLPUBLIC void rtl_string_new(rtl_String **newStr) SAL_THROW_EXTERN_C()
Allocate a new string containing no characters.
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.
#define SAL_WARN_UNUSED
Annotate classes where a compiler should warn if an instance is unused.
Definition: types.h:578
SAL_DLLPUBLIC sal_Int32 rtl_str_valueOfInt32(sal_Char *str, sal_Int32 i, sal_Int16 radix) SAL_THROW_EXTERN_C()
Create the string representation of an integer.
SAL_DLLPUBLIC sal_Int32 rtl_str_valueOfInt64(sal_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, const OString &str)
Inserts the string into this string buffer.
Definition: strbuf.hxx:757
OStringBuffer & insert(sal_Int32 offset, double d)
Inserts the string representation of the double argument into this string buffer.
Definition: strbuf.hxx:990
SAL_DLLPUBLIC sal_Int32 rtl_str_valueOfBoolean(sal_Char *str, sal_Bool b) SAL_THROW_EXTERN_C()
Create the string representation of a boolean.
void setLength(sal_Int32 newLength)
Sets the length of this String buffer.
Definition: strbuf.hxx:404
OStringBuffer & remove(sal_Int32 start, sal_Int32 len)
Removes the characters in a substring of this sequence.
Definition: strbuf.hxx:1008
OStringBuffer & append(double d)
Appends the string representation of the double argument to this string buffer.
Definition: strbuf.hxx:715
unsigned char sal_Bool
Definition: types.h:38
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
OStringBuffer(const OString &value)
Constructs a string buffer so that it represents the same sequence of characters as the string argume...
Definition: strbuf.hxx:135
#define RTL_STR_MAX_VALUEOFBOOLEAN
Definition: string.h:585
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
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
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.
#define RTL_STR_MAX_VALUEOFINT64
Definition: string.h:650
void accessInternals(rtl_String ***pInternalData, sal_Int32 **pInternalCapacity)
Allows access to the internal data of this OStringBuffer, for effective manipulation.
Definition: strbuf.hxx:1031
Definition: stringutils.hxx:338
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
OStringBuffer & append(const OString &str)
Appends the string to this string buffer.
Definition: strbuf.hxx:495
OStringBuffer(const sal_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:203
Definition: bootstrap.hxx:30
OStringBuffer(int length)
Constructs a string buffer with no characters in it and an initial capacity specified by the length a...
Definition: strbuf.hxx:98
~OStringBuffer()
Release the string data.
Definition: strbuf.hxx:311
SAL_WARN_UNUSED_RESULT OString makeStringAndClear()
Fill the string data in the new string and clear the buffer.
Definition: strbuf.hxx:324
SAL_DLLPUBLIC sal_Int32 rtl_str_valueOfDouble(sal_Char *str, double d) SAL_THROW_EXTERN_C()
Create the string representation of a double.
libreoffice_internal::NonConstCharArrayDetector< T, OStringBuffer & >::Type insert(sal_Int32 offset, T &str)
Definition: strbuf.hxx:786
OStringBuffer(T &value, typename libreoffice_internal::NonConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type=libreoffice_internal::Dummy())
Definition: strbuf.hxx:156
OStringBuffer & append(float f)
Appends the string representation of the float argument to this string buffer.
Definition: strbuf.hxx:698
OStringBuffer & insert(sal_Int32 offset, sal_Char c)
Inserts the string representation of the char argument into this string buffer.
Definition: strbuf.hxx:897
OStringBuffer & insert(sal_Int32 offset, const sal_Char *str, sal_Int32 len)
Inserts the string representation of the char array argument into this string buffer.
Definition: strbuf.hxx:826
OStringBuffer insert(sal_Int32 offset, float f)
Inserts the string representation of the float argument into this string buffer.
Definition: strbuf.hxx:967
#define SAL_DEPRECATED(message)
Use as follows: SAL_DEPRECATED("Don't use, it's evil.") void doit(int nPara);.
Definition: types.h:465
const sal_Char * getStr() const SAL_RETURNS_NONNULL
Returns a pointer to the characters of this string.
Definition: string.hxx:459
SAL_DLLPUBLIC void rtl_stringbuffer_insert(rtl_String **This, sal_Int32 *capacity, sal_Int32 offset, const sal_Char *str, sal_Int32 len)
Inserts the string representation of the char array argument into this string buffer.
Definition: stringutils.hxx:130
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 sal_Char * getStr() const SAL_RETURNS_NONNULL
Return a null terminated character array.
Definition: strbuf.hxx:459
Definition: stringutils.hxx:185
libreoffice_internal::NonConstCharArrayDetector< T, OStringBuffer & >::Type append(T &str)
Definition: strbuf.hxx:518
#define SAL_WARN_UNUSED_RESULT
Use this as markup for functions and methods whose return value must be checked.
Definition: types.h:302
sal_Int32 getLength() const
Returns the length of this string.
Definition: string.hxx:433
OStringBuffer & append(const sal_Char *str, sal_Int32 len)
Appends the string representation of the char array argument to this string buffer.
Definition: strbuf.hxx:552
SAL_DLLPUBLIC sal_Int32 rtl_str_valueOfFloat(sal_Char *str, float f) SAL_THROW_EXTERN_C()
Create the string representation of a float.
#define RTL_STR_MAX_VALUEOFINT32
Definition: string.h:627
bool isEmpty() const
Checks if a string buffer is empty.
Definition: strbuf.hxx:350
A string buffer implements a mutable sequence of characters.
Definition: strbuf.hxx:66
sal_uInt16 sal_Unicode
Definition: types.h:141
OStringBuffer & insert(sal_Int32 offset, bool b)
Inserts the string representation of the bool argument into this string buffer.
Definition: strbuf.hxx:875
SAL_DLLPUBLIC void rtl_stringbuffer_remove(rtl_String **This, sal_Int32 start, sal_Int32 len)
Removes the characters in a substring of this sequence.
void ensureCapacity(sal_Int32 minimumCapacity)
Ensures that the capacity of the buffer is at least equal to the specified minimum.
Definition: strbuf.hxx:381
#define SAL_DELETED_FUNCTION
short-circuit extra-verbose API namespaces
Definition: types.h:396
const OString toString() const
Return an OString instance reflecting the current content of this OStringBuffer.
Definition: strbuf.hxx:480
Definition: stringutils.hxx:157
OStringBuffer()
Constructs a string buffer with no characters in it and an initial capacity of 16 characters.
Definition: strbuf.hxx:72
OStringBuffer(const OStringBuffer &value)
Allocates a new string buffer that contains the same sequence of characters as the string buffer argu...
Definition: strbuf.hxx:85
SAL_DLLPUBLIC void rtl_string_newFromLiteral(rtl_String **newStr, const sal_Char *value, sal_Int32 len, sal_Int32 allocExtra) SAL_THROW_EXTERN_C()
OStringBuffer & append(bool b)
Appends the string representation of the bool argument to the string buffer.
Definition: strbuf.hxx:620
SAL_DLLPUBLIC void rtl_string_release(rtl_String *str) SAL_THROW_EXTERN_C()
Decrement the reference count of a string.
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
SAL_DLLPUBLIC sal_Int32 rtl_str_getLength(const sal_Char *str) SAL_THROW_EXTERN_C()
Return the length of a string.
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:176
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 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.