LibreOffice
LibreOffice 6.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 <cstring>
27 #include <limits>
28 #include <new>
29 
30 #if defined LIBO_INTERNAL_ONLY
31 #include <string_view>
32 #endif
33 
34 #include "rtl/ustrbuf.h"
35 #include "rtl/ustring.hxx"
36 #include "rtl/stringutils.hxx"
37 #include "sal/types.h"
38 
39 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
40 #include "rtl/stringconcat.hxx"
41 #endif
42 
43 #ifdef RTL_STRING_UNITTEST
44 extern bool rtl_string_unittest_invalid_conversion;
45 #endif
46 
47 // The unittest uses slightly different code to help check that the proper
48 // calls are made. The class is put into a different namespace to make
49 // sure the compiler generates a different (if generating also non-inline)
50 // copy of the function and does not merge them together. The class
51 // is "brought" into the proper rtl namespace by a typedef below.
52 #ifdef RTL_STRING_UNITTEST
53 #define rtl rtlunittest
54 #endif
55 
56 namespace rtl
57 {
58 
59 #ifdef RTL_STRING_UNITTEST
60 #undef rtl
61 #endif
62 
66 {
67 friend class OUString;
68 public:
74  : pData(NULL)
75  , nCapacity( 16 )
76  {
77  rtl_uString_new_WithLength( &pData, nCapacity );
78  }
79 
86  OUStringBuffer( const OUStringBuffer & value )
87  : pData(NULL)
88  , nCapacity( value.nCapacity )
89  {
90  rtl_uStringbuffer_newFromStringBuffer( &pData, value.nCapacity, value.pData );
91  }
92 
99  explicit OUStringBuffer(int length)
100  : pData(NULL)
101  , nCapacity( length )
102  {
103  rtl_uString_new_WithLength( &pData, length );
104  }
105 #if __cplusplus >= 201103L
106  explicit OUStringBuffer(unsigned int length)
107  : OUStringBuffer(static_cast<int>(length))
108  {
109  }
110 #if SAL_TYPES_SIZEOFLONG == 4
111  // additional overloads for sal_Int32 sal_uInt32
112  explicit OUStringBuffer(long length)
113  : OUStringBuffer(static_cast<int>(length))
114  {
115  }
116  explicit OUStringBuffer(unsigned long length)
117  : OUStringBuffer(static_cast<int>(length))
118  {
119  }
120 #endif
121  // avoid obvious bugs
122  explicit OUStringBuffer(char) = delete;
123  explicit OUStringBuffer(sal_Unicode) = delete;
124 #endif
125 
136  OUStringBuffer(const OUString& value)
137  : pData(NULL)
138  , nCapacity( value.getLength() + 16 )
139  {
140  rtl_uStringbuffer_newFromStr_WithLength( &pData, value.getStr(), value.getLength() );
141  }
142 
143  template< typename T >
145  : pData(NULL)
146  , nCapacity( libreoffice_internal::ConstCharArrayDetector<T>::length + 16 )
147  {
148  assert(
151  &pData,
154 #ifdef RTL_STRING_UNITTEST
155  rtl_string_unittest_const_literal = true;
156 #endif
157  }
158 
159 #if defined LIBO_INTERNAL_ONLY
160 
161  template<typename T>
163  T & literal,
165  T, libreoffice_internal::Dummy>::TypeUtf16
167  pData(nullptr),
168  nCapacity(libreoffice_internal::ConstCharArrayDetector<T>::length + 16)
169  {
171  &pData,
174  }
175 
177  OUStringBuffer(OUStringLiteral const & literal):
178  pData(nullptr), nCapacity(literal.size + 16) //TODO: check for overflow
179  {
180  rtl_uString_newFromLiteral(&pData, literal.data, literal.size, 16);
181  }
182 #endif
183 
184 #ifdef RTL_STRING_UNITTEST
185 
189  template< typename T >
190  OUStringBuffer( T&, typename libreoffice_internal::ExceptConstCharArrayDetector< T >::Type = libreoffice_internal::Dummy() )
191  {
192  pData = NULL;
193  nCapacity = 10;
194  rtl_uString_newFromLiteral( &pData, "!!br0ken!!", 10, 0 ); // set to garbage
195  rtl_string_unittest_invalid_conversion = true;
196  }
201  template< typename T >
202  OUStringBuffer( const T&, typename libreoffice_internal::ExceptCharArrayDetector< T >::Type = libreoffice_internal::Dummy() )
203  {
204  pData = NULL;
205  nCapacity = 10;
206  rtl_uString_newFromLiteral( &pData, "!!br0ken!!", 10, 0 ); // set to garbage
207  rtl_string_unittest_invalid_conversion = true;
208  }
209 #endif
210 
211 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
212 
216  template< typename T1, typename T2 >
217  OUStringBuffer( OUStringConcat< T1, T2 >&& c )
218  {
219  const sal_Int32 l = c.length();
220  nCapacity = l + 16;
221  pData = rtl_uString_alloc( nCapacity );
222  sal_Unicode* end = c.addData( pData->buffer );
223  *end = '\0';
224  pData->length = l;
225  // TODO realloc in case pData->>length is noticeably smaller than l ?
226  }
227 #endif
228 
230  OUStringBuffer& operator = ( const OUStringBuffer& value )
231  {
232  if (this != &value)
233  {
235  value.nCapacity,
236  value.pData);
237  nCapacity = value.nCapacity;
238  }
239  return *this;
240  }
241 
246  OUStringBuffer & operator =(OUString const & string) {
247  sal_Int32 n = string.getLength();
248  if (n >= nCapacity) {
249  ensureCapacity(n + 16); //TODO: check for overflow
250  }
251  std::memcpy(
252  pData->buffer, string.pData->buffer,
253  (n + 1) * sizeof (sal_Unicode));
254  pData->length = n;
255  return *this;
256  }
257 
262  template<typename T>
263  typename
265  operator =(T & literal) {
266  assert(
268  sal_Int32 const n
270  if (n >= nCapacity) {
271  ensureCapacity(n + 16); //TODO: check for overflow
272  }
273  char const * from
275  literal);
276  sal_Unicode * to = pData->buffer;
277  for (sal_Int32 i = 0; i <= n; ++i) {
278  to[i] = from[i];
279  }
280  pData->length = n;
281  return *this;
282  }
283 
284 #if defined LIBO_INTERNAL_ONLY
285 
286  template<typename T>
288  T, OUStringBuffer &>::TypeUtf16
289  operator =(T & literal) {
290  sal_Int32 const n
292  if (n >= nCapacity) {
293  ensureCapacity(n + 16); //TODO: check for overflow
294  }
295  std::memcpy(
296  pData->buffer,
297  libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
298  (n + 1) * sizeof (sal_Unicode)); //TODO: check for overflow
299  pData->length = n;
300  return *this;
301  }
302 
304  OUStringBuffer & operator =(OUStringLiteral const & literal) {
305  sal_Int32 const n = literal.size;
306  if (n >= nCapacity) {
307  ensureCapacity(n + 16); //TODO: check for overflow
308  }
309  char const * from = literal.data;
310  sal_Unicode * to = pData->buffer;
311  for (sal_Int32 i = 0; i <= n; ++i) {
312  to[i] = from[i];
313  }
314  pData->length = n;
315  return *this;
316  }
317 #endif
318 
319 #if defined LIBO_INTERNAL_ONLY
320 
321  template<typename T1, typename T2>
322  OUStringBuffer & operator =(OUStringConcat<T1, T2> && concat) {
323  sal_Int32 const n = concat.length();
324  if (n >= nCapacity) {
325  ensureCapacity(n + 16); //TODO: check for overflow
326  }
327  *concat.addData(pData->buffer) = 0;
328  pData->length = n;
329  return *this;
330  }
331 #endif
332 
337  {
338  rtl_uString_release( pData );
339  }
340 
350  {
351  return OUString(
352  rtl_uStringBuffer_makeStringAndClear( &pData, &nCapacity ),
353  SAL_NO_ACQUIRE );
354  }
355 
361  sal_Int32 getLength() const
362  {
363  return pData->length;
364  }
365 
374  bool isEmpty() const
375  {
376  return pData->length == 0;
377  }
378 
389  sal_Int32 getCapacity() const
390  {
391  return nCapacity;
392  }
393 
405  void ensureCapacity(sal_Int32 minimumCapacity)
406  {
407  rtl_uStringbuffer_ensureCapacity( &pData, &nCapacity, minimumCapacity );
408  }
409 
428  void setLength(sal_Int32 newLength)
429  {
430  assert(newLength >= 0);
431  // Avoid modifications if pData points to const empty string:
432  if( newLength != pData->length )
433  {
434  if( newLength > nCapacity )
435  rtl_uStringbuffer_ensureCapacity(&pData, &nCapacity, newLength);
436  else
437  pData->buffer[newLength] = 0;
438  pData->length = newLength;
439  }
440  }
441 
455  SAL_DEPRECATED("use rtl::OUStringBuffer::operator [] instead")
456  sal_Unicode charAt( sal_Int32 index ) const
457  {
458  assert(index >= 0 && index < pData->length);
459  return pData->buffer[ index ];
460  }
461 
472  SAL_DEPRECATED("use rtl::OUStringBuffer::operator [] instead")
473  OUStringBuffer & setCharAt(sal_Int32 index, sal_Unicode ch)
474  {
475  assert(index >= 0 && index < pData->length);
476  pData->buffer[ index ] = ch;
477  return *this;
478  }
479 
483  const sal_Unicode* getStr() const SAL_RETURNS_NONNULL { return pData->buffer; }
484 
494  sal_Unicode & operator [](sal_Int32 index)
495  {
496  assert(index >= 0 && index < pData->length);
497  return pData->buffer[index];
498  }
499 
509  const sal_Unicode & operator [](sal_Int32 index) const
510  {
511  assert(index >= 0 && index < pData->length);
512  return pData->buffer[index];
513  }
514 
519  const OUString toString() const
520  {
521  return OUString(pData->buffer, pData->length);
522  }
523 
535  {
536  return append( str.getStr(), str.getLength() );
537  }
538 
539 #if defined LIBO_INTERNAL_ONLY
540  OUStringBuffer & append(std::u16string_view sv) {
541  if (sv.size() > sal_uInt32(std::numeric_limits<sal_Int32>::max())) {
542  throw std::bad_alloc();
543  }
544  return append(sv.data(), sv.size());
545  }
546 #endif
547 
561  {
562  if(!str.isEmpty())
563  {
564  append( str.getStr(), str.getLength() );
565  }
566  return *this;
567  }
568 
581  {
582  return append( str, rtl_ustr_getLength( str ) );
583  }
584 
598  OUStringBuffer & append( const sal_Unicode * str, sal_Int32 len)
599  {
600  assert( len == 0 || str != NULL ); // cannot assert that in rtl_uStringbuffer_insert
601  rtl_uStringbuffer_insert( &pData, &nCapacity, getLength(), str, len );
602  return *this;
603  }
604 
610  template< typename T >
612  {
613  assert(
616  &pData, &nCapacity, getLength(),
619  return *this;
620  }
621 
622 #if defined LIBO_INTERNAL_ONLY
623 
624  template<typename T>
626  T, OUStringBuffer &>::TypeUtf16
627  append(T & literal) {
629  &pData, &nCapacity, getLength(),
632  return *this;
633  }
634 
636  OUStringBuffer & append(OUStringLiteral const & literal) {
638  &pData, &nCapacity, getLength(), literal.data, literal.size);
639  return *this;
640  }
641 #endif
642 
643 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
644 
648  template< typename T1, typename T2 >
649  OUStringBuffer& append( OUStringConcat< T1, T2 >&& c )
650  {
651  sal_Int32 l = c.length();
652  if( l == 0 )
653  return *this;
654  l += pData->length;
655  rtl_uStringbuffer_ensureCapacity( &pData, &nCapacity, l );
656  sal_Unicode* end = c.addData( pData->buffer + pData->length );
657  *end = '\0';
658  pData->length = l;
659  return *this;
660  }
661 #endif
662 
680  {
681  return appendAscii( str, rtl_str_getLength( str ) );
682  }
683 
702  OUStringBuffer & appendAscii( const sal_Char * str, sal_Int32 len)
703  {
704  rtl_uStringbuffer_insert_ascii( &pData, &nCapacity, getLength(), str, len );
705  return *this;
706  }
707 
722  {
724  return append( sz, rtl_ustr_valueOfBoolean( sz, b ) );
725  }
726 
728  // Pointer can be automatically converted to bool, which is unwanted here.
729  // Explicitly delete all pointer append() overloads to prevent this
730  // (except for char* and sal_Unicode* overloads, which are handled elsewhere).
731  template< typename T >
732  typename libreoffice_internal::Enable< void,
734  append( T* ) SAL_DELETED_FUNCTION;
736 
737  // This overload is needed because OUString has a ctor from rtl_uString*, but
738  // the bool overload above would be preferred to the conversion.
742  OUStringBuffer & append(rtl_uString* str)
743  {
744  return append( OUString( str ));
745  }
746 
759  {
761  return append( sz, rtl_ustr_valueOfBoolean( sz, b ) );
762  }
763 
777  {
778  assert(static_cast< unsigned char >(c) <= 0x7F);
779  return append(sal_Unicode(c));
780  }
781 
793  {
794  return append( &c, 1 );
795  }
796 
797 #if defined LIBO_INTERNAL_ONLY
798  void append(sal_uInt16) = delete;
799 #endif
800 
813  OUStringBuffer & append(sal_Int32 i, sal_Int16 radix = 10 )
814  {
816  return append( sz, rtl_ustr_valueOfInt32( sz, i, radix ) );
817  }
818 
831  OUStringBuffer & append(sal_Int64 l, sal_Int16 radix = 10 )
832  {
834  return append( sz, rtl_ustr_valueOfInt64( sz, l, radix ) );
835  }
836 
849  {
851  return append( sz, rtl_ustr_valueOfFloat( sz, f ) );
852  }
853 
865  OUStringBuffer & append(double d)
866  {
868  return append( sz, rtl_ustr_valueOfDouble( sz, d ) );
869  }
870 
884  OUStringBuffer & appendUtf32(sal_uInt32 c) {
885  return insertUtf32(getLength(), c);
886  }
887 
903  sal_Unicode * appendUninitialized(sal_Int32 length) SAL_RETURNS_NONNULL {
904  sal_Int32 n = getLength();
905  rtl_uStringbuffer_insert(&pData, &nCapacity, n, NULL, length);
906  return pData->buffer + n;
907  }
908 
924  OUStringBuffer & insert(sal_Int32 offset, const OUString & str)
925  {
926  return insert( offset, str.getStr(), str.getLength() );
927  }
928 
946  OUStringBuffer & insert( sal_Int32 offset, const sal_Unicode * str )
947  {
948  return insert( offset, str, rtl_ustr_getLength( str ) );
949  }
950 
969  OUStringBuffer & insert( sal_Int32 offset, const sal_Unicode * str, sal_Int32 len)
970  {
971  assert( len == 0 || str != NULL ); // cannot assert that in rtl_uStringbuffer_insert
972  rtl_uStringbuffer_insert( &pData, &nCapacity, offset, str, len );
973  return *this;
974  }
975 
981  template< typename T >
983  {
984  assert(
987  &pData, &nCapacity, offset,
990  return *this;
991  }
992 
993 #if defined LIBO_INTERNAL_ONLY
994 
995  template<typename T>
997  T, OUStringBuffer &>::TypeUtf16
998  insert(sal_Int32 offset, T & literal) {
1000  &pData, &nCapacity, offset,
1003  return *this;
1004  }
1005 
1007  OUStringBuffer & insert(sal_Int32 offset, OUStringLiteral const & literal) {
1009  &pData, &nCapacity, offset, literal.data, literal.size);
1010  return *this;
1011  }
1012 #endif
1013 
1031  OUStringBuffer & insert(sal_Int32 offset, sal_Bool b)
1032  {
1034  return insert( offset, sz, rtl_ustr_valueOfBoolean( sz, b ) );
1035  }
1036 
1056  OUStringBuffer & insert(sal_Int32 offset, bool b)
1057  {
1059  return insert( offset, sz, rtl_ustr_valueOfBoolean( sz, b ) );
1060  }
1061 
1080  OUStringBuffer & insert(sal_Int32 offset, char c)
1081  {
1082  sal_Unicode u = c;
1083  return insert( offset, &u, 1 );
1084  }
1085 
1102  OUStringBuffer & insert(sal_Int32 offset, sal_Unicode c)
1103  {
1104  return insert( offset, &c, 1 );
1105  }
1106 
1126  OUStringBuffer & insert(sal_Int32 offset, sal_Int32 i, sal_Int16 radix = 10 )
1127  {
1129  return insert( offset, sz, rtl_ustr_valueOfInt32( sz, i, radix ) );
1130  }
1131 
1151  OUStringBuffer & insert(sal_Int32 offset, sal_Int64 l, sal_Int16 radix = 10 )
1152  {
1154  return insert( offset, sz, rtl_ustr_valueOfInt64( sz, l, radix ) );
1155  }
1156 
1175  OUStringBuffer insert(sal_Int32 offset, float f)
1176  {
1178  return insert( offset, sz, rtl_ustr_valueOfFloat( sz, f ) );
1179  }
1180 
1199  OUStringBuffer & insert(sal_Int32 offset, double d)
1200  {
1202  return insert( offset, sz, rtl_ustr_valueOfDouble( sz, d ) );
1203  }
1204 
1220  OUStringBuffer & insertUtf32(sal_Int32 offset, sal_uInt32 c) {
1221  rtl_uStringbuffer_insertUtf32(&pData, &nCapacity, offset, c);
1222  return *this;
1223  }
1224 
1237  OUStringBuffer & remove( sal_Int32 start, sal_Int32 len )
1238  {
1239  rtl_uStringbuffer_remove( &pData, start, len );
1240  return *this;
1241  }
1242 
1253  OUStringBuffer & truncate( sal_Int32 start = 0 )
1254  {
1255  rtl_uStringbuffer_remove( &pData, start, getLength() - start );
1256  return *this;
1257  }
1258 
1270  {
1271  sal_Int32 index = 0;
1272  while((index = indexOf(oldChar, index)) >= 0)
1273  {
1274  pData->buffer[ index ] = newChar;
1275  }
1276  return *this;
1277  }
1278 
1294  void accessInternals(rtl_uString *** pInternalData,
1295  sal_Int32 ** pInternalCapacity)
1296  {
1297  *pInternalData = &pData;
1298  *pInternalCapacity = &nCapacity;
1299  }
1300 
1301 
1317  sal_Int32 indexOf( sal_Unicode ch, sal_Int32 fromIndex = 0 ) const
1318  {
1319  assert( fromIndex >= 0 && fromIndex <= pData->length );
1320  sal_Int32 ret = rtl_ustr_indexOfChar_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, ch );
1321  return (ret < 0 ? ret : ret+fromIndex);
1322  }
1323 
1335  sal_Int32 lastIndexOf( sal_Unicode ch ) const
1336  {
1337  return rtl_ustr_lastIndexOfChar_WithLength( pData->buffer, pData->length, ch );
1338  }
1339 
1354  sal_Int32 lastIndexOf( sal_Unicode ch, sal_Int32 fromIndex ) const
1355  {
1356  assert( fromIndex >= 0 && fromIndex <= pData->length );
1357  return rtl_ustr_lastIndexOfChar_WithLength( pData->buffer, fromIndex, ch );
1358  }
1359 
1377  sal_Int32 indexOf( const OUString & str, sal_Int32 fromIndex = 0 ) const
1378  {
1379  assert( fromIndex >= 0 && fromIndex <= pData->length );
1380  sal_Int32 ret = rtl_ustr_indexOfStr_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
1381  str.pData->buffer, str.pData->length );
1382  return (ret < 0 ? ret : ret+fromIndex);
1383  }
1384 
1391  template< typename T >
1392  typename libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type indexOf( T& literal, sal_Int32 fromIndex = 0 ) const
1393  {
1394  assert(
1396  sal_Int32 n = rtl_ustr_indexOfAscii_WithLength(
1397  pData->buffer + fromIndex, pData->length - fromIndex,
1400  return n < 0 ? n : n + fromIndex;
1401  }
1402 
1403 #if defined LIBO_INTERNAL_ONLY
1404 
1405  template<typename T>
1406  typename
1408  indexOf(T & literal, sal_Int32 fromIndex = 0) const {
1409  assert(fromIndex >= 0);
1411  pData->buffer + fromIndex, pData->length - fromIndex,
1414  return n < 0 ? n : n + fromIndex;
1415  }
1416 
1418  sal_Int32 indexOf(OUStringLiteral const & literal, sal_Int32 fromIndex = 0)
1419  const
1420  {
1421  sal_Int32 n = rtl_ustr_indexOfAscii_WithLength(
1422  pData->buffer + fromIndex, pData->length - fromIndex, literal.data,
1423  literal.size);
1424  return n < 0 ? n : n + fromIndex;
1425  }
1426 #endif
1427 
1445  sal_Int32 lastIndexOf( const OUString & str ) const
1446  {
1447  return rtl_ustr_lastIndexOfStr_WithLength( pData->buffer, pData->length,
1448  str.pData->buffer, str.pData->length );
1449  }
1450 
1470  sal_Int32 lastIndexOf( const OUString & str, sal_Int32 fromIndex ) const
1471  {
1472  assert( fromIndex >= 0 && fromIndex <= pData->length );
1473  return rtl_ustr_lastIndexOfStr_WithLength( pData->buffer, fromIndex,
1474  str.pData->buffer, str.pData->length );
1475  }
1476 
1482  template< typename T >
1484  {
1485  assert(
1488  pData->buffer, pData->length,
1491  }
1492 
1493 #if defined LIBO_INTERNAL_ONLY
1494 
1495  template<typename T>
1496  typename
1498  lastIndexOf(T & literal) const {
1500  pData->buffer, pData->length,
1503  }
1504 
1506  sal_Int32 lastIndexOf(OUStringLiteral const & literal) const {
1508  pData->buffer, pData->length, literal.data, literal.size);
1509  }
1510 #endif
1511 
1521  sal_Int32 stripStart(sal_Unicode c = ' ')
1522  {
1523  sal_Int32 index;
1524  for(index = 0; index < getLength() ; index++)
1525  {
1526  if(pData->buffer[ index ] != c)
1527  {
1528  break;
1529  }
1530  }
1531  if(index)
1532  {
1533  remove(0, index);
1534  }
1535  return index;
1536  }
1537 
1547  sal_Int32 stripEnd(sal_Unicode c = ' ')
1548  {
1549  sal_Int32 result = getLength();
1550  sal_Int32 index;
1551  for(index = getLength(); index > 0 ; index--)
1552  {
1553  if(pData->buffer[ index - 1 ] != c)
1554  {
1555  break;
1556  }
1557  }
1558  if(index < getLength())
1559  {
1560  truncate(index);
1561  }
1562  return result - getLength();
1563  }
1573  sal_Int32 strip(sal_Unicode c = ' ')
1574  {
1575  return stripStart(c) + stripEnd(c);
1576  }
1588  OUStringBuffer copy( sal_Int32 beginIndex ) const
1589  {
1590  return copy( beginIndex, getLength() - beginIndex );
1591  }
1592 
1606  OUStringBuffer copy( sal_Int32 beginIndex, sal_Int32 count ) const
1607  {
1608  assert(beginIndex >= 0 && beginIndex <= getLength());
1609  assert(count >= 0 && count <= getLength() - beginIndex);
1610  rtl_uString *pNew = NULL;
1611  rtl_uStringbuffer_newFromStr_WithLength( &pNew, getStr() + beginIndex, count );
1612  return OUStringBuffer( pNew, count + 16 );
1613  }
1614 
1615 private:
1616  OUStringBuffer( rtl_uString * value, const sal_Int32 capacity )
1617  {
1618  pData = value;
1619  nCapacity = capacity;
1620  }
1621 
1625  rtl_uString * pData;
1626 
1630  sal_Int32 nCapacity;
1631 };
1632 
1633 #if defined LIBO_INTERNAL_ONLY
1634  // Define this here to avoid circular includes
1635  inline OUString & OUString::operator+=( const OUStringBuffer & str ) &
1636  {
1637  // Call operator= if this is empty, otherwise rtl_uString_newConcat will attempt to
1638  // acquire() the str.pData buffer, which is part of the OUStringBuffer mutable state.
1639  if (isEmpty())
1640  return operator=(str.toString());
1641  else
1642  return internalAppend(str.pData);
1643  }
1644 #endif
1645 }
1646 
1647 #ifdef RTL_STRING_UNITTEST
1648 namespace rtl
1649 {
1650 typedef rtlunittest::OUStringBuffer OUStringBuffer;
1651 }
1652 #endif
1653 
1654 #if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST
1655 using ::rtl::OUStringBuffer;
1656 #endif
1657 
1658 #endif // INCLUDED_RTL_USTRBUF_HXX
1659 
1660 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUStringBuffer & append(char c)
Appends the string representation of the ASCII char argument to this string buffer.
Definition: ustrbuf.hxx:776
OUStringBuffer & append(const sal_Unicode *str)
Appends the string representation of the char array argument to this string buffer.
Definition: ustrbuf.hxx:580
const OUString toString() const
Return a OUString instance reflecting the current content of this OUStringBuffer.
Definition: ustrbuf.hxx:519
OUStringBuffer & replace(sal_Unicode oldChar, sal_Unicode newChar)
Replace all occurrences of oldChar in this string buffer with newChar.
Definition: ustrbuf.hxx:1269
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 indexOf(const OUString &str, sal_Int32 fromIndex=0) const
Returns the index within this string of the first occurrence of the specified substring,...
Definition: ustrbuf.hxx:1377
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,...
Definition: ustrbuf.hxx:1317
Dummy Type
Definition: stringutils.hxx:241
OUStringBuffer insert(sal_Int32 offset, float f)
Inserts the string representation of the float argument into this string buffer.
Definition: ustrbuf.hxx:1175
OUStringBuffer(const OUStringBuffer &value)
Allocates a new string buffer that contains the same sequence of characters as the string buffer argu...
Definition: ustrbuf.hxx:86
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.
sal_Int32 stripStart(sal_Unicode c=' ')
Strip the given character from the start of the buffer.
Definition: ustrbuf.hxx:1521
SAL_DLLPUBLIC sal_Int32 rtl_ustr_getLength(const sal_Unicode *str) SAL_THROW_EXTERN_C()
Return the length of a string.
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.
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:1483
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:813
OUStringBuffer(int length)
Constructs a string buffer with no characters in it and an initial capacity specified by the length a...
Definition: ustrbuf.hxx:99
OUStringBuffer & insert(sal_Int32 offset, sal_Bool b)
Inserts the string representation of the sal_Bool argument into this string buffer.
Definition: ustrbuf.hxx:1031
SAL_DLLPUBLIC sal_Int32 rtl_ustr_valueOfFloat(sal_Unicode *str, float f) SAL_THROW_EXTERN_C()
Create the string representation of a float.
SAL_WARN_UNUSED_RESULT OUString makeStringAndClear()
Fill the string data in the new string and clear the buffer.
Definition: ustrbuf.hxx:349
Definition: bootstrap.hxx:29
OUStringBuffer & insert(sal_Int32 offset, const OUString &str)
Inserts the string into this string buffer.
Definition: ustrbuf.hxx:924
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, sal_Int32 len)
Appends a 8-Bit ASCII character string to this string buffer.
Definition: ustrbuf.hxx:702
#define RTL_USTR_MAX_VALUEOFINT32
Definition: ustring.h:957
OUStringBuffer & insert(sal_Int32 offset, char c)
Inserts the string representation of the char argument into this string buffer.
Definition: ustrbuf.hxx:1080
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:1151
#define SAL_DELETED_FUNCTION
short-circuit extra-verbose API namespaces
Definition: types.h:396
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.
OUStringBuffer & insert(sal_Int32 offset, double d)
Inserts the string representation of the double argument into this string buffer.
Definition: ustrbuf.hxx:1199
OUStringBuffer(const OUString &value)
Constructs a string buffer so that it represents the same sequence of characters as the string argume...
Definition: ustrbuf.hxx:136
sal_Int32 strip(sal_Unicode c=' ')
Strip the given character from the both end of the buffer.
Definition: ustrbuf.hxx:1573
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 & truncate(sal_Int32 start=0)
Removes the tail of a string buffer start at the indicate position.
Definition: ustrbuf.hxx:1253
SAL_DLLPUBLIC void rtl_uStringbuffer_remove(rtl_uString **This, sal_Int32 start, sal_Int32 len)
Removes the characters in a substring of this sequence.
OUStringBuffer & append(const OUString &str)
Appends the string to this string buffer.
Definition: ustrbuf.hxx:534
#define SAL_DEPRECATED(message)
Use as follows: SAL_DEPRECATED("Don't use, it's evil.") void doit(int nPara);.
Definition: types.h:465
#define SAL_WARN_UNUSED
Annotate classes where a compiler should warn if an instance is unused.
Definition: types.h:578
OUStringBuffer & append(double d)
Appends the string representation of the double argument to this string buffer.
Definition: ustrbuf.hxx:865
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 & append(float f)
Appends the string representation of the float argument to this string buffer.
Definition: ustrbuf.hxx:848
#define RTL_USTR_MAX_VALUEOFBOOLEAN
Definition: ustring.h:915
sal_Int32 lastIndexOf(sal_Unicode ch) const
Returns the index within this string of the last occurrence of the specified character,...
Definition: ustrbuf.hxx:1335
SAL_DLLPUBLIC sal_Int32 rtl_ustr_valueOfDouble(sal_Unicode *str, double d) SAL_THROW_EXTERN_C()
Create the string representation of a double.
OUStringBuffer & insertUtf32(sal_Int32 offset, sal_uInt32 c)
Inserts a single UTF-32 character into this string buffer.
Definition: ustrbuf.hxx:1220
sal_uInt16 sal_Unicode
Definition: types.h:141
OUStringBuffer & append(sal_Unicode c)
Appends the string representation of the char argument to this string buffer.
Definition: ustrbuf.hxx:792
OUStringBuffer & append(const OUStringBuffer &str)
Appends the content of a stringbuffer to this string buffer.
Definition: ustrbuf.hxx:560
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:982
#define RTL_USTR_MAX_VALUEOFINT64
Definition: ustring.h:1003
unsigned char sal_Bool
Definition: types.h:38
sal_Int32 getCapacity() const
Returns the current capacity of the String buffer.
Definition: ustrbuf.hxx:389
OUStringBuffer()
Constructs a string buffer with no characters in it and an initial capacity of 16 characters.
Definition: ustrbuf.hxx:73
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 & appendUtf32(sal_uInt32 c)
Appends a single UTF-32 character to this string buffer.
Definition: ustrbuf.hxx:884
OUStringBuffer & append(rtl_uString *str)
Definition: ustrbuf.hxx:742
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:946
const sal_Unicode * getStr() const SAL_RETURNS_NONNULL
Return a null terminated unicode character array.
Definition: ustrbuf.hxx:483
SAL_DLLPUBLIC sal_Int32 rtl_str_getLength(const sal_Char *str) SAL_THROW_EXTERN_C()
Return the length of a string.
Definition: stringutils.hxx:299
OUStringBuffer & remove(sal_Int32 start, sal_Int32 len)
Removes the characters in a substring of this sequence.
Definition: ustrbuf.hxx:1237
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:969
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 append(T &literal)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: ustrbuf.hxx:611
OUStringBuffer copy(sal_Int32 beginIndex, sal_Int32 count) const
Returns a new string buffer that is a substring of this string.
Definition: ustrbuf.hxx:1606
definition of a no acquire enum for ctors
Definition: types.h:374
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:598
OUStringBuffer & append(bool b)
Appends the string representation of the bool argument to the string buffer.
Definition: ustrbuf.hxx:721
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(T &literal, typename libreoffice_internal::ConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type=libreoffice_internal::Dummy())
Definition: ustrbuf.hxx:144
OUString & operator+=(const OUString &str)
Append a string to this string.
Definition: ustring.hxx:553
OUStringBuffer & appendAscii(const sal_Char *str)
Appends a 8-Bit ASCII character string to this string buffer.
Definition: ustrbuf.hxx:679
OUStringBuffer & append(sal_Int64 l, sal_Int16 radix=10)
Appends the string representation of the long argument to this string buffer.
Definition: ustrbuf.hxx:831
sal_Unicode * appendUninitialized(sal_Int32 length) SAL_RETURNS_NONNULL
Unsafe way to make space for a fixed amount of characters to be appended into this OUStringBuffer.
Definition: ustrbuf.hxx:903
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.
sal_Int32 lastIndexOf(const OUString &str) const
Returns the index within this string of the last occurrence of the specified substring,...
Definition: ustrbuf.hxx:1445
void setLength(sal_Int32 newLength)
Sets the length of this String buffer.
Definition: ustrbuf.hxx:428
sal_Int32 stripEnd(sal_Unicode c=' ')
Strip the given character from the end of the buffer.
Definition: ustrbuf.hxx:1547
sal_Int32 getLength() const
Returns the length of this string.
Definition: ustring.hxx:654
#define SAL_WARN_UNUSED_RESULT
Use this as markup for functions and methods whose return value must be checked.
Definition: types.h:302
char sal_Char
A legacy synonym for char.
Definition: types.h:120
SAL_DLLPUBLIC rtl_uString * rtl_uStringBuffer_makeStringAndClear(rtl_uString **ppThis, sal_Int32 *nCapacity) SAL_RETURNS_NONNULL
Returns an immutable rtl_uString object, while clearing the string buffer.
#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()
void ensureCapacity(sal_Int32 minimumCapacity)
Ensures that the capacity of the buffer is at least equal to the specified minimum.
Definition: ustrbuf.hxx:405
bool isEmpty() const
Checks if a string buffer is empty.
Definition: ustrbuf.hxx:374
OUStringBuffer & append(sal_Bool b)
Appends the string representation of the sal_Bool argument to the string buffer.
Definition: ustrbuf.hxx:758
Definition: stringutils.hxx:105
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:1126
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
const sal_Unicode * getStr() const SAL_RETURNS_NONNULL
Returns a pointer to the Unicode character buffer for this string.
Definition: ustring.hxx:676
This String class provides base functionality for C++ like Unicode character array handling.
Definition: ustring.hxx:126
Dummy Type
Definition: stringutils.hxx:263
~OUStringBuffer()
Release the string data.
Definition: ustrbuf.hxx:336
void accessInternals(rtl_uString ***pInternalData, sal_Int32 **pInternalCapacity)
Allows access to the internal data of this OUStringBuffer, for effective manipulation.
Definition: ustrbuf.hxx:1294
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.
OUStringBuffer & insert(sal_Int32 offset, sal_Unicode c)
Inserts the string representation of the char argument into this string buffer.
Definition: ustrbuf.hxx:1102
OUStringBuffer & insert(sal_Int32 offset, bool b)
Inserts the string representation of the bool argument into this string buffer.
Definition: ustrbuf.hxx:1056
sal_Int32 lastIndexOf(const OUString &str, sal_Int32 fromIndex) const
Returns the index within this string of the last occurrence of the specified substring,...
Definition: ustrbuf.hxx:1470
OUStringBuffer copy(sal_Int32 beginIndex) const
Returns a new string buffer that is a substring of this string.
Definition: ustrbuf.hxx:1588
SAL_DLLPUBLIC void rtl_uString_release(rtl_uString *str) SAL_THROW_EXTERN_C() SAL_HOT
Decrement the reference count of a string.
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:1392
Definition: stringutils.hxx:103
sal_Int32 lastIndexOf(sal_Unicode ch, sal_Int32 fromIndex) const
Returns the index within this string of the last occurrence of the specified character,...
Definition: ustrbuf.hxx:1354
sal_Int32 getLength() const
Returns the length (character count) of this string buffer.
Definition: ustrbuf.hxx:361
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.
A string buffer implements a mutable sequence of characters.
Definition: ustrbuf.hxx:65
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.