LibreOffice
LibreOffice 5.3 SDK C/C++ API Reference
ustrbuf.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #ifndef INCLUDED_RTL_USTRBUF_HXX
21 #define INCLUDED_RTL_USTRBUF_HXX
22 
23 #include <sal/config.h>
24 
25 #include <cassert>
26 #include <cstddef>
27 #include <cstring>
28 
29 #include <rtl/ustrbuf.h>
30 #include <rtl/ustring.hxx>
31 #include <rtl/stringutils.hxx>
32 #include <sal/types.h>
33 
34 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
35 #include <rtl/stringconcat.hxx>
36 #endif
37 
38 // The unittest uses slightly different code to help check that the proper
39 // calls are made. The class is put into a different namespace to make
40 // sure the compiler generates a different (if generating also non-inline)
41 // copy of the function and does not merge them together. The class
42 // is "brought" into the proper rtl namespace by a typedef below.
43 #ifdef RTL_STRING_UNITTEST
44 #define rtl rtlunittest
45 #endif
46 
47 namespace rtl
48 {
49 
50 #ifdef RTL_STRING_UNITTEST
51 #undef rtl
52 #endif
53 
57 {
58 public:
64  : pData(NULL)
65  , nCapacity( 16 )
66  {
67  rtl_uString_new_WithLength( &pData, nCapacity );
68  }
69 
76  OUStringBuffer( const OUStringBuffer & value )
77  : pData(NULL)
78  , nCapacity( value.nCapacity )
79  {
80  rtl_uStringbuffer_newFromStringBuffer( &pData, value.nCapacity, value.pData );
81  }
82 
89  explicit OUStringBuffer(int length)
90  : pData(NULL)
91  , nCapacity( length )
92  {
93  rtl_uString_new_WithLength( &pData, length );
94  }
95 #if __cplusplus >= 201103L
96  explicit OUStringBuffer(unsigned int length)
97  : OUStringBuffer(static_cast<int>(length))
98  {
99  }
100 #if SAL_TYPES_SIZEOFLONG == 4
101  // additional overloads for sal_Int32 sal_uInt32
102  explicit OUStringBuffer(long length)
103  : OUStringBuffer(static_cast<int>(length))
104  {
105  }
106  explicit OUStringBuffer(unsigned long length)
107  : OUStringBuffer(static_cast<int>(length))
108  {
109  }
110 #endif
111  // avoid obvious bugs
112  explicit OUStringBuffer(char) = delete;
113  explicit OUStringBuffer(sal_Unicode) = delete;
114 #endif
115 
126  OUStringBuffer(const OUString& value)
127  : pData(NULL)
128  , nCapacity( value.getLength() + 16 )
129  {
130  rtl_uStringbuffer_newFromStr_WithLength( &pData, value.getStr(), value.getLength() );
131  }
132 
133  template< typename T >
135  : pData(NULL)
136  , nCapacity( libreoffice_internal::ConstCharArrayDetector<T>::length + 16 )
137  {
138  assert(
141  &pData,
144 #ifdef RTL_STRING_UNITTEST
145  rtl_string_unittest_const_literal = true;
146 #endif
147  }
148 
149 #if defined LIBO_INTERNAL_ONLY
150 
151  template<typename T>
153  T & literal,
155  T, libreoffice_internal::Dummy>::TypeUtf16
157  pData(nullptr),
159  {
161  &pData,
164  }
165 #endif
166 
167 #ifdef RTL_STRING_UNITTEST
168 
172  template< typename T >
174  {
175  pData = NULL;
176  nCapacity = 10;
177  rtl_uString_newFromLiteral( &pData, "!!br0ken!!", 10, 0 ); // set to garbage
178  rtl_string_unittest_invalid_conversion = true;
179  }
184  template< typename T >
186  {
187  pData = NULL;
188  nCapacity = 10;
189  rtl_uString_newFromLiteral( &pData, "!!br0ken!!", 10, 0 ); // set to garbage
190  rtl_string_unittest_invalid_conversion = true;
191  }
192 #endif
193 
194 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
195 
199  template< typename T1, typename T2 >
200  OUStringBuffer( const OUStringConcat< T1, T2 >& c )
201  {
202  const sal_Int32 l = c.length();
203  nCapacity = l + 16;
204  pData = rtl_uString_alloc( nCapacity );
205  sal_Unicode* end = c.addData( pData->buffer );
206  *end = '\0';
207  pData->length = l;
208  // TODO realloc in case pData->>length is noticeably smaller than l ?
209  }
210 #endif
211 
213  OUStringBuffer& operator = ( const OUStringBuffer& value )
214  {
215  if (this != &value)
216  {
218  value.nCapacity,
219  value.pData);
220  nCapacity = value.nCapacity;
221  }
222  return *this;
223  }
224 
229  OUStringBuffer & operator =(OUString const & string) {
230  sal_Int32 n = string.getLength();
231  if (n >= nCapacity) {
232  ensureCapacity(n + 16); //TODO: check for overflow
233  }
234  std::memcpy(
235  pData->buffer, string.pData->buffer,
236  (n + 1) * sizeof (sal_Unicode));
237  pData->length = n;
238  return *this;
239  }
240 
245  template<typename T>
246  typename
248  operator =(T & literal) {
249  assert(
251  sal_Int32 const n
253  if (n >= nCapacity) {
254  ensureCapacity(n + 16); //TODO: check for overflow
255  }
256  char const * from
258  literal);
259  sal_Unicode * to = pData->buffer;
260  for (sal_Int32 i = 0; i <= n; ++i) {
261  to[i] = from[i];
262  }
263  pData->length = n;
264  return *this;
265  }
266 
267 #if defined LIBO_INTERNAL_ONLY
268 
269  template<typename T>
271  T, OUStringBuffer &>::TypeUtf16
272  operator =(T & literal) {
273  sal_Int32 const n
275  if (n >= nCapacity) {
276  ensureCapacity(n + 16); //TODO: check for overflow
277  }
278  std::memcpy(
279  pData->buffer,
281  (n + 1) * sizeof (sal_Unicode)); //TODO: check for overflow
282  pData->length = n;
283  return *this;
284  }
285 #endif
286 
287 #if defined LIBO_INTERNAL_ONLY
288 
289  template<typename T1, typename T2>
290  OUStringBuffer & operator =(OUStringConcat<T1, T2> const & concat) {
291  sal_Int32 const n = concat.length();
292  if (n >= nCapacity) {
293  ensureCapacity(n + 16); //TODO: check for overflow
294  }
295  *concat.addData(pData->buffer) = 0;
296  pData->length = n;
297  return *this;
298  }
299 #endif
300 
305  {
306  rtl_uString_release( pData );
307  }
308 
318  {
319  return OUString(
320  rtl_uStringBuffer_makeStringAndClear( &pData, &nCapacity ),
321  SAL_NO_ACQUIRE );
322  }
323 
329  sal_Int32 getLength() const
330  {
331  return pData->length;
332  }
333 
342  bool isEmpty() const
343  {
344  return pData->length == 0;
345  }
346 
357  sal_Int32 getCapacity() const
358  {
359  return nCapacity;
360  }
361 
373  void ensureCapacity(sal_Int32 minimumCapacity)
374  {
375  rtl_uStringbuffer_ensureCapacity( &pData, &nCapacity, minimumCapacity );
376  }
377 
396  void setLength(sal_Int32 newLength)
397  {
398  assert(newLength >= 0);
399  // Avoid modifications if pData points to const empty string:
400  if( newLength != pData->length )
401  {
402  if( newLength > nCapacity )
403  rtl_uStringbuffer_ensureCapacity(&pData, &nCapacity, newLength);
404  else
405  pData->buffer[newLength] = 0;
406  pData->length = newLength;
407  }
408  }
409 
423  SAL_DEPRECATED("use rtl::OUStringBuffer::operator [] instead")
424  sal_Unicode charAt( sal_Int32 index ) const
425  {
426  assert(index >= 0 && index < pData->length);
427  return pData->buffer[ index ];
428  }
429 
440  SAL_DEPRECATED("use rtl::OUStringBuffer::operator [] instead")
441  OUStringBuffer & setCharAt(sal_Int32 index, sal_Unicode ch)
442  {
443  assert(index >= 0 && index < pData->length);
444  pData->buffer[ index ] = ch;
445  return *this;
446  }
447 
451  const sal_Unicode* getStr() const { return pData->buffer; }
452 
462  sal_Unicode & operator [](sal_Int32 index)
463  {
464  assert(index >= 0 && index < pData->length);
465  return pData->buffer[index];
466  }
467 
477  const sal_Unicode & operator [](sal_Int32 index) const
478  {
479  assert(index >= 0 && index < pData->length);
480  return pData->buffer[index];
481  }
482 
487  const OUString toString() const
488  {
489  return OUString(pData->buffer, pData->length);
490  }
491 
503  {
504  return append( str.getStr(), str.getLength() );
505  }
506 
520  {
521  if(!str.isEmpty())
522  {
523  append( str.getStr(), str.getLength() );
524  }
525  return *this;
526  }
527 
540  {
541  return append( str, rtl_ustr_getLength( str ) );
542  }
543 
557  OUStringBuffer & append( const sal_Unicode * str, sal_Int32 len)
558  {
559  assert( len == 0 || str != NULL ); // cannot assert that in rtl_uStringbuffer_insert
560  rtl_uStringbuffer_insert( &pData, &nCapacity, getLength(), str, len );
561  return *this;
562  }
563 
569  template< typename T >
571  {
572  assert(
575  &pData, &nCapacity, getLength(),
578  return *this;
579  }
580 
581 #if defined LIBO_INTERNAL_ONLY
582 
583  template<typename T>
585  T, OUStringBuffer &>::TypeUtf16
586  append(T & literal) {
588  &pData, &nCapacity, getLength(),
591  return *this;
592  }
593 #endif
594 
595 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
596 
600  template< typename T1, typename T2 >
601  OUStringBuffer& append( const OUStringConcat< T1, T2 >& c )
602  {
603  sal_Int32 l = c.length();
604  if( l == 0 )
605  return *this;
606  l += pData->length;
607  rtl_uStringbuffer_ensureCapacity( &pData, &nCapacity, l );
608  sal_Unicode* end = c.addData( pData->buffer + pData->length );
609  *end = '\0';
610  pData->length = l;
611  return *this;
612  }
613 #endif
614 
632  {
633  return appendAscii( str, rtl_str_getLength( str ) );
634  }
635 
654  OUStringBuffer & appendAscii( const sal_Char * str, sal_Int32 len)
655  {
656  rtl_uStringbuffer_insert_ascii( &pData, &nCapacity, getLength(), str, len );
657  return *this;
658  }
659 
674  {
676  return append( sz, rtl_ustr_valueOfBoolean( sz, b ) );
677  }
678 
680  // Pointer can be automatically converted to bool, which is unwanted here.
681  // Explicitly delete all pointer append() overloads to prevent this
682  // (except for char* and sal_Unicode* overloads, which are handled elsewhere).
683  template< typename T >
684  typename libreoffice_internal::Enable< void,
686  append( T* ) SAL_DELETED_FUNCTION;
688 
689  // This overload is needed because OUString has a ctor from rtl_uString*, but
690  // the bool overload above would be preferred to the conversion.
694  OUStringBuffer & append(rtl_uString* str)
695  {
696  return append( OUString( str ));
697  }
698 
711  {
713  return append( sz, rtl_ustr_valueOfBoolean( sz, b ) );
714  }
715 
729  {
730  assert(static_cast< unsigned char >(c) <= 0x7F);
731  return append(sal_Unicode(c));
732  }
733 
745  {
746  return append( &c, 1 );
747  }
748 
749 #if LIBO_INTERNAL_ONLY && \
750  (!defined SAL_W32 || defined __MINGW32__ || defined __clang__)
751  // cf. sal/types.h sal_Unicode
752  void append(sal_uInt16) = delete;
753 #endif
754 
767  OUStringBuffer & append(sal_Int32 i, sal_Int16 radix = 10 )
768  {
770  return append( sz, rtl_ustr_valueOfInt32( sz, i, radix ) );
771  }
772 
785  OUStringBuffer & append(sal_Int64 l, sal_Int16 radix = 10 )
786  {
788  return append( sz, rtl_ustr_valueOfInt64( sz, l, radix ) );
789  }
790 
803  {
805  return append( sz, rtl_ustr_valueOfFloat( sz, f ) );
806  }
807 
819  OUStringBuffer & append(double d)
820  {
822  return append( sz, rtl_ustr_valueOfDouble( sz, d ) );
823  }
824 
838  OUStringBuffer & appendUtf32(sal_uInt32 c) {
839  return insertUtf32(getLength(), c);
840  }
841 
857  sal_Unicode * appendUninitialized(sal_Int32 length) {
858  sal_Int32 n = getLength();
859  rtl_uStringbuffer_insert(&pData, &nCapacity, n, NULL, length);
860  return pData->buffer + n;
861  }
862 
878  OUStringBuffer & insert(sal_Int32 offset, const OUString & str)
879  {
880  return insert( offset, str.getStr(), str.getLength() );
881  }
882 
900  OUStringBuffer & insert( sal_Int32 offset, const sal_Unicode * str )
901  {
902  return insert( offset, str, rtl_ustr_getLength( str ) );
903  }
904 
923  OUStringBuffer & insert( sal_Int32 offset, const sal_Unicode * str, sal_Int32 len)
924  {
925  assert( len == 0 || str != NULL ); // cannot assert that in rtl_uStringbuffer_insert
926  rtl_uStringbuffer_insert( &pData, &nCapacity, offset, str, len );
927  return *this;
928  }
929 
935  template< typename T >
937  {
938  assert(
941  &pData, &nCapacity, offset,
944  return *this;
945  }
946 
947 #if defined LIBO_INTERNAL_ONLY
948 
949  template<typename T>
951  T, OUStringBuffer &>::TypeUtf16
952  insert(sal_Int32 offset, T & literal) {
954  &pData, &nCapacity, offset,
957  return *this;
958  }
959 #endif
960 
978  OUStringBuffer & insert(sal_Int32 offset, sal_Bool b)
979  {
981  return insert( offset, sz, rtl_ustr_valueOfBoolean( sz, b ) );
982  }
983 
1003  OUStringBuffer & insert(sal_Int32 offset, bool b)
1004  {
1006  return insert( offset, sz, rtl_ustr_valueOfBoolean( sz, b ) );
1007  }
1008 
1027  OUStringBuffer & insert(sal_Int32 offset, char c)
1028  {
1029  sal_Unicode u = c;
1030  return insert( offset, &u, 1 );
1031  }
1032 
1049  OUStringBuffer & insert(sal_Int32 offset, sal_Unicode c)
1050  {
1051  return insert( offset, &c, 1 );
1052  }
1053 
1073  OUStringBuffer & insert(sal_Int32 offset, sal_Int32 i, sal_Int16 radix = 10 )
1074  {
1076  return insert( offset, sz, rtl_ustr_valueOfInt32( sz, i, radix ) );
1077  }
1078 
1098  OUStringBuffer & insert(sal_Int32 offset, sal_Int64 l, sal_Int16 radix = 10 )
1099  {
1101  return insert( offset, sz, rtl_ustr_valueOfInt64( sz, l, radix ) );
1102  }
1103 
1122  OUStringBuffer insert(sal_Int32 offset, float f)
1123  {
1125  return insert( offset, sz, rtl_ustr_valueOfFloat( sz, f ) );
1126  }
1127 
1146  OUStringBuffer & insert(sal_Int32 offset, double d)
1147  {
1149  return insert( offset, sz, rtl_ustr_valueOfDouble( sz, d ) );
1150  }
1151 
1167  OUStringBuffer & insertUtf32(sal_Int32 offset, sal_uInt32 c) {
1168  rtl_uStringbuffer_insertUtf32(&pData, &nCapacity, offset, c);
1169  return *this;
1170  }
1171 
1184  OUStringBuffer & remove( sal_Int32 start, sal_Int32 len )
1185  {
1186  rtl_uStringbuffer_remove( &pData, start, len );
1187  return *this;
1188  }
1189 
1200  OUStringBuffer & truncate( sal_Int32 start = 0 )
1201  {
1202  rtl_uStringbuffer_remove( &pData, start, getLength() - start );
1203  return *this;
1204  }
1205 
1217  {
1218  sal_Int32 index = 0;
1219  while((index = indexOf(oldChar, index)) >= 0)
1220  {
1221  pData->buffer[ index ] = newChar;
1222  }
1223  return *this;
1224  }
1225 
1241  inline void accessInternals(rtl_uString *** pInternalData,
1242  sal_Int32 ** pInternalCapacity)
1243  {
1244  *pInternalData = &pData;
1245  *pInternalCapacity = &nCapacity;
1246  }
1247 
1248 
1264  sal_Int32 indexOf( sal_Unicode ch, sal_Int32 fromIndex = 0 ) const
1265  {
1266  assert( fromIndex >= 0 && fromIndex <= pData->length );
1267  sal_Int32 ret = rtl_ustr_indexOfChar_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, ch );
1268  return (ret < 0 ? ret : ret+fromIndex);
1269  }
1270 
1282  sal_Int32 lastIndexOf( sal_Unicode ch ) const
1283  {
1284  return rtl_ustr_lastIndexOfChar_WithLength( pData->buffer, pData->length, ch );
1285  }
1286 
1301  sal_Int32 lastIndexOf( sal_Unicode ch, sal_Int32 fromIndex ) const
1302  {
1303  assert( fromIndex >= 0 && fromIndex <= pData->length );
1304  return rtl_ustr_lastIndexOfChar_WithLength( pData->buffer, fromIndex, ch );
1305  }
1306 
1324  sal_Int32 indexOf( const OUString & str, sal_Int32 fromIndex = 0 ) const
1325  {
1326  assert( fromIndex >= 0 && fromIndex <= pData->length );
1327  sal_Int32 ret = rtl_ustr_indexOfStr_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
1328  str.pData->buffer, str.pData->length );
1329  return (ret < 0 ? ret : ret+fromIndex);
1330  }
1331 
1338  template< typename T >
1339  typename libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type indexOf( T& literal, sal_Int32 fromIndex = 0 ) const
1340  {
1341  assert(
1343  sal_Int32 n = rtl_ustr_indexOfAscii_WithLength(
1344  pData->buffer + fromIndex, pData->length - fromIndex,
1347  return n < 0 ? n : n + fromIndex;
1348  }
1349 
1350 #if defined LIBO_INTERNAL_ONLY
1351 
1352  template<typename T>
1353  typename
1355  indexOf(T & literal, sal_Int32 fromIndex = 0) const {
1356  assert(fromIndex >= 0);
1358  pData->buffer + fromIndex, pData->length - fromIndex,
1361  return n < 0 ? n : n + fromIndex;
1362  }
1363 #endif
1364 
1382  sal_Int32 lastIndexOf( const OUString & str ) const
1383  {
1384  return rtl_ustr_lastIndexOfStr_WithLength( pData->buffer, pData->length,
1385  str.pData->buffer, str.pData->length );
1386  }
1387 
1407  sal_Int32 lastIndexOf( const OUString & str, sal_Int32 fromIndex ) const
1408  {
1409  assert( fromIndex >= 0 && fromIndex <= pData->length );
1410  return rtl_ustr_lastIndexOfStr_WithLength( pData->buffer, fromIndex,
1411  str.pData->buffer, str.pData->length );
1412  }
1413 
1419  template< typename T >
1421  {
1422  assert(
1425  pData->buffer, pData->length,
1428  }
1429 
1430 #if defined LIBO_INTERNAL_ONLY
1431 
1432  template<typename T>
1433  typename
1435  lastIndexOf(T & literal) const {
1437  pData->buffer, pData->length,
1440  }
1441 #endif
1442 
1452  sal_Int32 stripStart(sal_Unicode c = (sal_Unicode)' ')
1453  {
1454  sal_Int32 index;
1455  for(index = 0; index < getLength() ; index++)
1456  {
1457  if(pData->buffer[ index ] != c)
1458  {
1459  break;
1460  }
1461  }
1462  if(index)
1463  {
1464  remove(0, index);
1465  }
1466  return index;
1467  }
1468 
1478  sal_Int32 stripEnd(sal_Unicode c = (sal_Unicode)' ')
1479  {
1480  sal_Int32 result = getLength();
1481  sal_Int32 index;
1482  for(index = getLength(); index > 0 ; index--)
1483  {
1484  if(pData->buffer[ index - 1 ] != c)
1485  {
1486  break;
1487  }
1488  }
1489  if(index < getLength())
1490  {
1491  truncate(index);
1492  }
1493  return result - getLength();
1494  }
1504  sal_Int32 strip(sal_Unicode c = (sal_Unicode)' ')
1505  {
1506  return stripStart(c) + stripEnd(c);
1507  }
1519  OUStringBuffer copy( sal_Int32 beginIndex ) const
1520  {
1521  return copy( beginIndex, getLength() - beginIndex );
1522  }
1523 
1537  OUStringBuffer copy( sal_Int32 beginIndex, sal_Int32 count ) const
1538  {
1539  assert(beginIndex >= 0 && beginIndex <= getLength());
1540  assert(count >= 0 && count <= getLength() - beginIndex);
1541  rtl_uString *pNew = NULL;
1542  rtl_uStringbuffer_newFromStr_WithLength( &pNew, getStr() + beginIndex, count );
1543  return OUStringBuffer( pNew, count + 16 );
1544  }
1545 
1546 private:
1547  OUStringBuffer( rtl_uString * value, const sal_Int32 capacity )
1548  {
1549  pData = value;
1550  nCapacity = capacity;
1551  }
1552 
1556  rtl_uString * pData;
1557 
1561  sal_Int32 nCapacity;
1562 };
1563 
1564 }
1565 
1566 #ifdef RTL_STRING_UNITTEST
1567 namespace rtl
1568 {
1569 typedef rtlunittest::OUStringBuffer OUStringBuffer;
1570 }
1571 #endif
1572 
1573 #if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST
1574 using ::rtl::OUStringBuffer;
1575 #endif
1576 
1577 #endif // INCLUDED_RTL_USTRBUF_HXX
1578 
1579 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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:1264
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.
sal_Int32 strip(sal_Unicode c=(sal_Unicode)' ')
Strip the given character from the both end of the buffer.
Definition: ustrbuf.hxx:1504
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 & insert(sal_Int32 offset, sal_Bool b)
Inserts the string representation of the sal_Bool argument into this string buffer.
Definition: ustrbuf.hxx:978
SAL_DLLPUBLIC sal_Int32 rtl_ustr_getLength(const sal_Unicode *str) SAL_THROW_EXTERN_C()
Return the length of a string.
OUStringBuffer()
Constructs a string buffer with no characters in it and an initial capacity of 16 characters...
Definition: ustrbuf.hxx:63
sal_Int32 stripEnd(sal_Unicode c=(sal_Unicode)' ')
Strip the given character from the end of the buffer.
Definition: ustrbuf.hxx:1478
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.
OUStringBuffer insert(sal_Int32 offset, float f)
Inserts the string representation of the float argument into this string buffer.
Definition: ustrbuf.hxx:1122
OUStringBuffer & append(double d)
Appends the string representation of the double argument to this string buffer.
Definition: ustrbuf.hxx:819
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:900
OUStringBuffer & append(sal_Int64 l, sal_Int16 radix=10)
Appends the string representation of the long argument to this string buffer.
Definition: ustrbuf.hxx:785
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:570
OUStringBuffer & insert(sal_Int32 offset, char c)
Inserts the string representation of the char argument into this string buffer.
Definition: ustrbuf.hxx:1027
SAL_DLLPUBLIC sal_Int32 rtl_ustr_valueOfFloat(sal_Unicode *str, float f) SAL_THROW_EXTERN_C()
Create the string representation of a float.
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:557
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 & appendAscii(const sal_Char *str)
Appends a 8-Bit ASCII character string to this string buffer.
Definition: ustrbuf.hxx:631
SAL_DLLPUBLIC rtl_uString * rtl_uStringBuffer_makeStringAndClear(rtl_uString **ppThis, sal_Int32 *nCapacity)
Returns an immutable rtl_uString object, while clearing the string buffer.
#define RTL_USTR_MAX_VALUEOFINT32
Definition: ustring.h:957
void ensureCapacity(sal_Int32 minimumCapacity)
Ensures that the capacity of the buffer is at least equal to the specified minimum.
Definition: ustrbuf.hxx:373
void setLength(sal_Int32 newLength)
Sets the length of this String buffer.
Definition: ustrbuf.hxx:396
#define SAL_DELETED_FUNCTION
short-circuit extra-verbose API namespaces
Definition: types.h:410
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_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.
OUStringBuffer & insert(sal_Int32 offset, bool b)
Inserts the string representation of the bool argument into this string buffer.
Definition: ustrbuf.hxx:1003
SAL_DLLPUBLIC void rtl_uStringbuffer_remove(rtl_uString **This, sal_Int32 start, sal_Int32 len)
Removes the characters in a substring of this sequence.
#define SAL_DEPRECATED(message)
Use as follows: SAL_DEPRECATED("Don&#39;t use, it&#39;s evil.") void doit(int nPara);.
Definition: types.h:509
#define SAL_WARN_UNUSED
Annotate classes where a compiler should warn if an instance is unused.
Definition: types.h:624
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_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, sal_Unicode c)
Inserts the string representation of the char argument into this string buffer.
Definition: ustrbuf.hxx:1049
Definition: stringutils.hxx:267
bool isEmpty() const
Checks if a string buffer is empty.
Definition: ustrbuf.hxx:342
OUStringBuffer & append(sal_Bool b)
Appends the string representation of the sal_Bool argument to the string buffer.
Definition: ustrbuf.hxx:710
void accessInternals(rtl_uString ***pInternalData, sal_Int32 **pInternalCapacity)
Allows access to the internal data of this OUStringBuffer, for effective manipulation.
Definition: ustrbuf.hxx:1241
#define RTL_USTR_MAX_VALUEOFBOOLEAN
Definition: ustring.h:915
SAL_DLLPUBLIC sal_Int32 rtl_ustr_valueOfDouble(sal_Unicode *str, double d) SAL_THROW_EXTERN_C()
Create the string representation of a double.
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:1301
sal_Int32 getLength() const
Returns the length (character count) of this string buffer.
Definition: ustrbuf.hxx:329
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:857
OUStringBuffer & truncate(sal_Int32 start=0)
Removes the tail of a string buffer start at the indicate position.
Definition: ustrbuf.hxx:1200
~OUStringBuffer()
Release the string data.
Definition: ustrbuf.hxx:304
OUStringBuffer & append(sal_Unicode c)
Appends the string representation of the char argument to this string buffer.
Definition: ustrbuf.hxx:744
sal_Int32 getCapacity() const
Returns the current capacity of the String buffer.
Definition: ustrbuf.hxx:357
OUStringBuffer & append(rtl_uString *str)
Definition: ustrbuf.hxx:694
OUStringBuffer & append(char c)
Appends the string representation of the ASCII char argument to this string buffer.
Definition: ustrbuf.hxx:728
OUStringBuffer & append(const sal_Unicode *str)
Appends the string representation of the char array argument to this string buffer.
Definition: ustrbuf.hxx:539
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:1407
const OUString toString() const
Return a OUString instance reflecting the current content of this OUStringBuffer. ...
Definition: ustrbuf.hxx:487
sal_uInt16 sal_Unicode
Definition: types.h:155
OUStringBuffer copy(sal_Int32 beginIndex) const
Returns a new string buffer that is a substring of this string.
Definition: ustrbuf.hxx:1519
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:1339
#define RTL_USTR_MAX_VALUEOFINT64
Definition: ustring.h:1003
unsigned char sal_Bool
Definition: types.h:48
OUStringBuffer & append(const OUString &str)
Appends the string to this string buffer.
Definition: ustrbuf.hxx:502
OUStringBuffer & replace(sal_Unicode oldChar, sal_Unicode newChar)
Replace all occurrences of oldChar in this string buffer with newChar.
Definition: ustrbuf.hxx:1216
OUStringBuffer & appendUtf32(sal_uInt32 c)
Appends a single UTF-32 character to this string buffer.
Definition: ustrbuf.hxx:838
OUStringBuffer(const OUStringBuffer &value)
Allocates a new string buffer that contains the same sequence of characters as the string buffer argu...
Definition: ustrbuf.hxx:76
Definition: stringutils.hxx:117
const sal_Unicode * getStr() const
Return a null terminated unicode character array.
Definition: ustrbuf.hxx:451
OUStringBuffer & append(const OUStringBuffer &str)
Appends the content of a stringbuffer to this string buffer.
Definition: ustrbuf.hxx:519
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:1382
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 copy(sal_Int32 beginIndex, sal_Int32 count) const
Returns a new string buffer that is a substring of this string.
Definition: ustrbuf.hxx:1537
OUStringBuffer & insertUtf32(sal_Int32 offset, sal_uInt32 c)
Inserts a single UTF-32 character into this string buffer.
Definition: ustrbuf.hxx:1167
OUStringBuffer & append(bool b)
Appends the string representation of the bool argument to the string buffer.
Definition: ustrbuf.hxx:673
SAL_DLLPUBLIC sal_Int32 rtl_str_getLength(const sal_Char *str) SAL_THROW_EXTERN_C()
Return the length of a string.
sal_Int32 stripStart(sal_Unicode c=(sal_Unicode)' ')
Strip the given character from the start of the buffer.
Definition: ustrbuf.hxx:1452
OUStringBuffer(T &literal, typename libreoffice_internal::ConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type=libreoffice_internal::Dummy())
Definition: ustrbuf.hxx:134
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...
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:936
definition of a no acquire enum for ctors
Definition: types.h:388
OUStringBuffer & appendAscii(const sal_Char *str, sal_Int32 len)
Appends a 8-Bit ASCII character string to this string buffer.
Definition: ustrbuf.hxx:654
SAL_DLLPUBLIC sal_Int32 rtl_ustr_valueOfBoolean(sal_Unicode *str, sal_Bool b) SAL_THROW_EXTERN_C()
Create the string representation of a boolean.
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:1098
This String class provides base functionality for C++ like Unicode character array handling...
Definition: ustring.hxx:106
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:1420
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_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.
OUStringBuffer & insert(sal_Int32 offset, double d)
Inserts the string representation of the double argument into this string buffer. ...
Definition: ustrbuf.hxx:1146
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:1073
OUStringBuffer(const OUString &value)
Constructs a string buffer so that it represents the same sequence of characters as the string argume...
Definition: ustrbuf.hxx:126
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:767
OUStringBuffer & insert(sal_Int32 offset, const OUString &str)
Inserts the string into this string buffer.
Definition: ustrbuf.hxx:878
OUStringBuffer(int length)
Constructs a string buffer with no characters in it and an initial capacity specified by the length a...
Definition: ustrbuf.hxx:89
char sal_Char
A legacy synonym for char.
Definition: types.h:130
#define RTL_USTR_MAX_VALUEOFFLOAT
Definition: ustring.h:1022
SAL_DLLPUBLIC void rtl_uString_newFromLiteral(rtl_uString **newStr, const sal_Char *value, sal_Int32 len, sal_Int32 allocExtra) SAL_THROW_EXTERN_C()
OUStringBuffer & append(float f)
Appends the string representation of the float argument to this string buffer.
Definition: ustrbuf.hxx:802
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:923
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...
#define RTL_USTR_MAX_VALUEOFDOUBLE
Definition: ustring.h:1041
Definition: stringutils.hxx:115
const sal_Unicode * getStr() const
Returns a pointer to the Unicode character buffer for this string.
Definition: ustring.hxx:628
A string buffer implements a mutable sequence of characters.
Definition: ustrbuf.hxx:56
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: bootstrap.hxx:29
SAL_DLLPUBLIC void rtl_uString_release(rtl_uString *str) SAL_THROW_EXTERN_C() SAL_HOT
Decrement the reference count of a string.
sal_Int32 getLength() const
Returns the length of this string.
Definition: ustring.hxx:606
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:1282
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.
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.
OUString makeStringAndClear()
Fill the string data in the new string and clear the buffer.
Definition: ustrbuf.hxx:317
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:1324