LibreOffice
LibreOffice 6.2 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 
28 #include "rtl/ustrbuf.h"
29 #include "rtl/ustring.hxx"
30 #include "rtl/stringutils.hxx"
31 #include "sal/types.h"
32 
33 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
34 #include "rtl/stringconcat.hxx"
35 #endif
36 
37 #ifdef RTL_STRING_UNITTEST
38 extern bool rtl_string_unittest_invalid_conversion;
39 #endif
40 
41 // The unittest uses slightly different code to help check that the proper
42 // calls are made. The class is put into a different namespace to make
43 // sure the compiler generates a different (if generating also non-inline)
44 // copy of the function and does not merge them together. The class
45 // is "brought" into the proper rtl namespace by a typedef below.
46 #ifdef RTL_STRING_UNITTEST
47 #define rtl rtlunittest
48 #endif
49 
50 namespace rtl
51 {
52 
53 #ifdef RTL_STRING_UNITTEST
54 #undef rtl
55 #endif
56 
60 {
61 friend class OUString;
62 public:
68  : pData(NULL)
69  , nCapacity( 16 )
70  {
71  rtl_uString_new_WithLength( &pData, nCapacity );
72  }
73 
80  OUStringBuffer( const OUStringBuffer & value )
81  : pData(NULL)
82  , nCapacity( value.nCapacity )
83  {
84  rtl_uStringbuffer_newFromStringBuffer( &pData, value.nCapacity, value.pData );
85  }
86 
93  explicit OUStringBuffer(int length)
94  : pData(NULL)
95  , nCapacity( length )
96  {
97  rtl_uString_new_WithLength( &pData, length );
98  }
99 #if __cplusplus >= 201103L
100  explicit OUStringBuffer(unsigned int length)
101  : OUStringBuffer(static_cast<int>(length))
102  {
103  }
104 #if SAL_TYPES_SIZEOFLONG == 4
105  // additional overloads for sal_Int32 sal_uInt32
106  explicit OUStringBuffer(long length)
107  : OUStringBuffer(static_cast<int>(length))
108  {
109  }
110  explicit OUStringBuffer(unsigned long length)
111  : OUStringBuffer(static_cast<int>(length))
112  {
113  }
114 #endif
115  // avoid obvious bugs
116  explicit OUStringBuffer(char) = delete;
117  explicit OUStringBuffer(sal_Unicode) = delete;
118 #endif
119 
130  OUStringBuffer(const OUString& value)
131  : pData(NULL)
132  , nCapacity( value.getLength() + 16 )
133  {
134  rtl_uStringbuffer_newFromStr_WithLength( &pData, value.getStr(), value.getLength() );
135  }
136 
137  template< typename T >
139  : pData(NULL)
140  , nCapacity( libreoffice_internal::ConstCharArrayDetector<T>::length + 16 )
141  {
142  assert(
145  &pData,
148 #ifdef RTL_STRING_UNITTEST
149  rtl_string_unittest_const_literal = true;
150 #endif
151  }
152 
153 #if defined LIBO_INTERNAL_ONLY
154 
155  template<typename T>
157  T & literal,
159  T, libreoffice_internal::Dummy>::TypeUtf16
161  pData(nullptr),
163  {
165  &pData,
168  }
169 
171  OUStringBuffer(OUStringLiteral const & literal):
172  pData(nullptr), nCapacity(literal.size + 16) //TODO: check for overflow
173  {
174  rtl_uString_newFromLiteral(&pData, literal.data, literal.size, 16);
175  }
176 #endif
177 
178 #ifdef RTL_STRING_UNITTEST
179 
183  template< typename T >
185  {
186  pData = NULL;
187  nCapacity = 10;
188  rtl_uString_newFromLiteral( &pData, "!!br0ken!!", 10, 0 ); // set to garbage
189  rtl_string_unittest_invalid_conversion = true;
190  }
195  template< typename T >
197  {
198  pData = NULL;
199  nCapacity = 10;
200  rtl_uString_newFromLiteral( &pData, "!!br0ken!!", 10, 0 ); // set to garbage
201  rtl_string_unittest_invalid_conversion = true;
202  }
203 #endif
204 
205 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
206 
210  template< typename T1, typename T2 >
211  OUStringBuffer( OUStringConcat< T1, T2 >&& c )
212  {
213  const sal_Int32 l = c.length();
214  nCapacity = l + 16;
215  pData = rtl_uString_alloc( nCapacity );
216  sal_Unicode* end = c.addData( pData->buffer );
217  *end = '\0';
218  pData->length = l;
219  // TODO realloc in case pData->>length is noticeably smaller than l ?
220  }
221 #endif
222 
224  OUStringBuffer& operator = ( const OUStringBuffer& value )
225  {
226  if (this != &value)
227  {
229  value.nCapacity,
230  value.pData);
231  nCapacity = value.nCapacity;
232  }
233  return *this;
234  }
235 
240  OUStringBuffer & operator =(OUString const & string) {
241  sal_Int32 n = string.getLength();
242  if (n >= nCapacity) {
243  ensureCapacity(n + 16); //TODO: check for overflow
244  }
245  std::memcpy(
246  pData->buffer, string.pData->buffer,
247  (n + 1) * sizeof (sal_Unicode));
248  pData->length = n;
249  return *this;
250  }
251 
256  template<typename T>
257  typename
259  operator =(T & literal) {
260  assert(
262  sal_Int32 const n
264  if (n >= nCapacity) {
265  ensureCapacity(n + 16); //TODO: check for overflow
266  }
267  char const * from
269  literal);
270  sal_Unicode * to = pData->buffer;
271  for (sal_Int32 i = 0; i <= n; ++i) {
272  to[i] = from[i];
273  }
274  pData->length = n;
275  return *this;
276  }
277 
278 #if defined LIBO_INTERNAL_ONLY
279 
280  template<typename T>
282  T, OUStringBuffer &>::TypeUtf16
283  operator =(T & literal) {
284  sal_Int32 const n
286  if (n >= nCapacity) {
287  ensureCapacity(n + 16); //TODO: check for overflow
288  }
289  std::memcpy(
290  pData->buffer,
292  (n + 1) * sizeof (sal_Unicode)); //TODO: check for overflow
293  pData->length = n;
294  return *this;
295  }
296 
298  OUStringBuffer & operator =(OUStringLiteral const & literal) {
299  sal_Int32 const n = literal.size;
300  if (n >= nCapacity) {
301  ensureCapacity(n + 16); //TODO: check for overflow
302  }
303  char const * from = literal.data;
304  sal_Unicode * to = pData->buffer;
305  for (sal_Int32 i = 0; i <= n; ++i) {
306  to[i] = from[i];
307  }
308  pData->length = n;
309  return *this;
310  }
311 #endif
312 
313 #if defined LIBO_INTERNAL_ONLY
314 
315  template<typename T1, typename T2>
316  OUStringBuffer & operator =(OUStringConcat<T1, T2> && concat) {
317  sal_Int32 const n = concat.length();
318  if (n >= nCapacity) {
319  ensureCapacity(n + 16); //TODO: check for overflow
320  }
321  *concat.addData(pData->buffer) = 0;
322  pData->length = n;
323  return *this;
324  }
325 #endif
326 
331  {
332  rtl_uString_release( pData );
333  }
334 
344  {
345  return OUString(
346  rtl_uStringBuffer_makeStringAndClear( &pData, &nCapacity ),
347  SAL_NO_ACQUIRE );
348  }
349 
355  sal_Int32 getLength() const
356  {
357  return pData->length;
358  }
359 
368  bool isEmpty() const
369  {
370  return pData->length == 0;
371  }
372 
383  sal_Int32 getCapacity() const
384  {
385  return nCapacity;
386  }
387 
399  void ensureCapacity(sal_Int32 minimumCapacity)
400  {
401  rtl_uStringbuffer_ensureCapacity( &pData, &nCapacity, minimumCapacity );
402  }
403 
422  void setLength(sal_Int32 newLength)
423  {
424  assert(newLength >= 0);
425  // Avoid modifications if pData points to const empty string:
426  if( newLength != pData->length )
427  {
428  if( newLength > nCapacity )
429  rtl_uStringbuffer_ensureCapacity(&pData, &nCapacity, newLength);
430  else
431  pData->buffer[newLength] = 0;
432  pData->length = newLength;
433  }
434  }
435 
449  SAL_DEPRECATED("use rtl::OUStringBuffer::operator [] instead")
450  sal_Unicode charAt( sal_Int32 index ) const
451  {
452  assert(index >= 0 && index < pData->length);
453  return pData->buffer[ index ];
454  }
455 
466  SAL_DEPRECATED("use rtl::OUStringBuffer::operator [] instead")
467  OUStringBuffer & setCharAt(sal_Int32 index, sal_Unicode ch)
468  {
469  assert(index >= 0 && index < pData->length);
470  pData->buffer[ index ] = ch;
471  return *this;
472  }
473 
477  const sal_Unicode* getStr() const SAL_RETURNS_NONNULL { return pData->buffer; }
478 
488  sal_Unicode & operator [](sal_Int32 index)
489  {
490  assert(index >= 0 && index < pData->length);
491  return pData->buffer[index];
492  }
493 
503  const sal_Unicode & operator [](sal_Int32 index) const
504  {
505  assert(index >= 0 && index < pData->length);
506  return pData->buffer[index];
507  }
508 
513  const OUString toString() const
514  {
515  return OUString(pData->buffer, pData->length);
516  }
517 
529  {
530  return append( str.getStr(), str.getLength() );
531  }
532 
533 #ifdef LIBO_INTERNAL_ONLY
534 
546  OUStringBuffer & appendCopy(const OUString &str, sal_Int32 beginIndex)
547  {
548  assert(beginIndex >=0 && beginIndex <= str.getLength());
549  return append( str.getStr() + beginIndex, str.getLength() - beginIndex );
550  }
551 
566  OUStringBuffer & appendCopy(const OUString &str, sal_Int32 beginIndex, sal_Int32 count)
567  {
568  assert(beginIndex >=0 && beginIndex <= str.getLength());
569  assert(count >=0 && count <= (str.getLength() - beginIndex));
570  return append( str.getStr() + beginIndex, count );
571  }
572 #endif // LIBO_INTERNAL_ONLY
573 
587  {
588  if(!str.isEmpty())
589  {
590  append( str.getStr(), str.getLength() );
591  }
592  return *this;
593  }
594 
607  {
608  return append( str, rtl_ustr_getLength( str ) );
609  }
610 
624  OUStringBuffer & append( const sal_Unicode * str, sal_Int32 len)
625  {
626  assert( len == 0 || str != NULL ); // cannot assert that in rtl_uStringbuffer_insert
627  rtl_uStringbuffer_insert( &pData, &nCapacity, getLength(), str, len );
628  return *this;
629  }
630 
636  template< typename T >
638  {
639  assert(
642  &pData, &nCapacity, getLength(),
645  return *this;
646  }
647 
648 #if defined LIBO_INTERNAL_ONLY
649 
650  template<typename T>
652  T, OUStringBuffer &>::TypeUtf16
653  append(T & literal) {
655  &pData, &nCapacity, getLength(),
658  return *this;
659  }
660 
662  OUStringBuffer & append(OUStringLiteral const & literal) {
664  &pData, &nCapacity, getLength(), literal.data, literal.size);
665  return *this;
666  }
667 #endif
668 
669 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
670 
674  template< typename T1, typename T2 >
675  OUStringBuffer& append( OUStringConcat< T1, T2 >&& c )
676  {
677  sal_Int32 l = c.length();
678  if( l == 0 )
679  return *this;
680  l += pData->length;
681  rtl_uStringbuffer_ensureCapacity( &pData, &nCapacity, l );
682  sal_Unicode* end = c.addData( pData->buffer + pData->length );
683  *end = '\0';
684  pData->length = l;
685  return *this;
686  }
687 #endif
688 
706  {
707  return appendAscii( str, rtl_str_getLength( str ) );
708  }
709 
728  OUStringBuffer & appendAscii( const sal_Char * str, sal_Int32 len)
729  {
730  rtl_uStringbuffer_insert_ascii( &pData, &nCapacity, getLength(), str, len );
731  return *this;
732  }
733 
748  {
750  return append( sz, rtl_ustr_valueOfBoolean( sz, b ) );
751  }
752 
754  // Pointer can be automatically converted to bool, which is unwanted here.
755  // Explicitly delete all pointer append() overloads to prevent this
756  // (except for char* and sal_Unicode* overloads, which are handled elsewhere).
757  template< typename T >
758  typename libreoffice_internal::Enable< void,
760  append( T* ) SAL_DELETED_FUNCTION;
762 
763  // This overload is needed because OUString has a ctor from rtl_uString*, but
764  // the bool overload above would be preferred to the conversion.
768  OUStringBuffer & append(rtl_uString* str)
769  {
770  return append( OUString( str ));
771  }
772 
785  {
787  return append( sz, rtl_ustr_valueOfBoolean( sz, b ) );
788  }
789 
803  {
804  assert(static_cast< unsigned char >(c) <= 0x7F);
805  return append(sal_Unicode(c));
806  }
807 
819  {
820  return append( &c, 1 );
821  }
822 
823 #if defined LIBO_INTERNAL_ONLY
824  void append(sal_uInt16) = delete;
825 #endif
826 
839  OUStringBuffer & append(sal_Int32 i, sal_Int16 radix = 10 )
840  {
842  return append( sz, rtl_ustr_valueOfInt32( sz, i, radix ) );
843  }
844 
857  OUStringBuffer & append(sal_Int64 l, sal_Int16 radix = 10 )
858  {
860  return append( sz, rtl_ustr_valueOfInt64( sz, l, radix ) );
861  }
862 
875  {
877  return append( sz, rtl_ustr_valueOfFloat( sz, f ) );
878  }
879 
891  OUStringBuffer & append(double d)
892  {
894  return append( sz, rtl_ustr_valueOfDouble( sz, d ) );
895  }
896 
910  OUStringBuffer & appendUtf32(sal_uInt32 c) {
911  return insertUtf32(getLength(), c);
912  }
913 
929  sal_Unicode * appendUninitialized(sal_Int32 length) SAL_RETURNS_NONNULL {
930  sal_Int32 n = getLength();
931  rtl_uStringbuffer_insert(&pData, &nCapacity, n, NULL, length);
932  return pData->buffer + n;
933  }
934 
950  OUStringBuffer & insert(sal_Int32 offset, const OUString & str)
951  {
952  return insert( offset, str.getStr(), str.getLength() );
953  }
954 
972  OUStringBuffer & insert( sal_Int32 offset, const sal_Unicode * str )
973  {
974  return insert( offset, str, rtl_ustr_getLength( str ) );
975  }
976 
995  OUStringBuffer & insert( sal_Int32 offset, const sal_Unicode * str, sal_Int32 len)
996  {
997  assert( len == 0 || str != NULL ); // cannot assert that in rtl_uStringbuffer_insert
998  rtl_uStringbuffer_insert( &pData, &nCapacity, offset, str, len );
999  return *this;
1000  }
1001 
1007  template< typename T >
1009  {
1010  assert(
1013  &pData, &nCapacity, offset,
1016  return *this;
1017  }
1018 
1019 #if defined LIBO_INTERNAL_ONLY
1020 
1021  template<typename T>
1023  T, OUStringBuffer &>::TypeUtf16
1024  insert(sal_Int32 offset, T & literal) {
1026  &pData, &nCapacity, offset,
1029  return *this;
1030  }
1031 
1033  OUStringBuffer & insert(sal_Int32 offset, OUStringLiteral const & literal) {
1035  &pData, &nCapacity, offset, literal.data, literal.size);
1036  return *this;
1037  }
1038 #endif
1039 
1057  OUStringBuffer & insert(sal_Int32 offset, sal_Bool b)
1058  {
1060  return insert( offset, sz, rtl_ustr_valueOfBoolean( sz, b ) );
1061  }
1062 
1082  OUStringBuffer & insert(sal_Int32 offset, bool b)
1083  {
1085  return insert( offset, sz, rtl_ustr_valueOfBoolean( sz, b ) );
1086  }
1087 
1106  OUStringBuffer & insert(sal_Int32 offset, char c)
1107  {
1108  sal_Unicode u = c;
1109  return insert( offset, &u, 1 );
1110  }
1111 
1128  OUStringBuffer & insert(sal_Int32 offset, sal_Unicode c)
1129  {
1130  return insert( offset, &c, 1 );
1131  }
1132 
1152  OUStringBuffer & insert(sal_Int32 offset, sal_Int32 i, sal_Int16 radix = 10 )
1153  {
1155  return insert( offset, sz, rtl_ustr_valueOfInt32( sz, i, radix ) );
1156  }
1157 
1177  OUStringBuffer & insert(sal_Int32 offset, sal_Int64 l, sal_Int16 radix = 10 )
1178  {
1180  return insert( offset, sz, rtl_ustr_valueOfInt64( sz, l, radix ) );
1181  }
1182 
1201  OUStringBuffer insert(sal_Int32 offset, float f)
1202  {
1204  return insert( offset, sz, rtl_ustr_valueOfFloat( sz, f ) );
1205  }
1206 
1225  OUStringBuffer & insert(sal_Int32 offset, double d)
1226  {
1228  return insert( offset, sz, rtl_ustr_valueOfDouble( sz, d ) );
1229  }
1230 
1246  OUStringBuffer & insertUtf32(sal_Int32 offset, sal_uInt32 c) {
1247  rtl_uStringbuffer_insertUtf32(&pData, &nCapacity, offset, c);
1248  return *this;
1249  }
1250 
1263  OUStringBuffer & remove( sal_Int32 start, sal_Int32 len )
1264  {
1265  rtl_uStringbuffer_remove( &pData, start, len );
1266  return *this;
1267  }
1268 
1279  OUStringBuffer & truncate( sal_Int32 start = 0 )
1280  {
1281  rtl_uStringbuffer_remove( &pData, start, getLength() - start );
1282  return *this;
1283  }
1284 
1296  {
1297  sal_Int32 index = 0;
1298  while((index = indexOf(oldChar, index)) >= 0)
1299  {
1300  pData->buffer[ index ] = newChar;
1301  }
1302  return *this;
1303  }
1304 
1320  void accessInternals(rtl_uString *** pInternalData,
1321  sal_Int32 ** pInternalCapacity)
1322  {
1323  *pInternalData = &pData;
1324  *pInternalCapacity = &nCapacity;
1325  }
1326 
1327 
1343  sal_Int32 indexOf( sal_Unicode ch, sal_Int32 fromIndex = 0 ) const
1344  {
1345  assert( fromIndex >= 0 && fromIndex <= pData->length );
1346  sal_Int32 ret = rtl_ustr_indexOfChar_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, ch );
1347  return (ret < 0 ? ret : ret+fromIndex);
1348  }
1349 
1361  sal_Int32 lastIndexOf( sal_Unicode ch ) const
1362  {
1363  return rtl_ustr_lastIndexOfChar_WithLength( pData->buffer, pData->length, ch );
1364  }
1365 
1380  sal_Int32 lastIndexOf( sal_Unicode ch, sal_Int32 fromIndex ) const
1381  {
1382  assert( fromIndex >= 0 && fromIndex <= pData->length );
1383  return rtl_ustr_lastIndexOfChar_WithLength( pData->buffer, fromIndex, ch );
1384  }
1385 
1403  sal_Int32 indexOf( const OUString & str, sal_Int32 fromIndex = 0 ) const
1404  {
1405  assert( fromIndex >= 0 && fromIndex <= pData->length );
1406  sal_Int32 ret = rtl_ustr_indexOfStr_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
1407  str.pData->buffer, str.pData->length );
1408  return (ret < 0 ? ret : ret+fromIndex);
1409  }
1410 
1417  template< typename T >
1418  typename libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type indexOf( T& literal, sal_Int32 fromIndex = 0 ) const
1419  {
1420  assert(
1422  sal_Int32 n = rtl_ustr_indexOfAscii_WithLength(
1423  pData->buffer + fromIndex, pData->length - fromIndex,
1426  return n < 0 ? n : n + fromIndex;
1427  }
1428 
1429 #if defined LIBO_INTERNAL_ONLY
1430 
1431  template<typename T>
1432  typename
1434  indexOf(T & literal, sal_Int32 fromIndex = 0) const {
1435  assert(fromIndex >= 0);
1437  pData->buffer + fromIndex, pData->length - fromIndex,
1440  return n < 0 ? n : n + fromIndex;
1441  }
1442 
1444  sal_Int32 indexOf(OUStringLiteral const & literal, sal_Int32 fromIndex = 0)
1445  const
1446  {
1447  sal_Int32 n = rtl_ustr_indexOfAscii_WithLength(
1448  pData->buffer + fromIndex, pData->length - fromIndex, literal.data,
1449  literal.size);
1450  return n < 0 ? n : n + fromIndex;
1451  }
1452 #endif
1453 
1471  sal_Int32 lastIndexOf( const OUString & str ) const
1472  {
1473  return rtl_ustr_lastIndexOfStr_WithLength( pData->buffer, pData->length,
1474  str.pData->buffer, str.pData->length );
1475  }
1476 
1496  sal_Int32 lastIndexOf( const OUString & str, sal_Int32 fromIndex ) const
1497  {
1498  assert( fromIndex >= 0 && fromIndex <= pData->length );
1499  return rtl_ustr_lastIndexOfStr_WithLength( pData->buffer, fromIndex,
1500  str.pData->buffer, str.pData->length );
1501  }
1502 
1508  template< typename T >
1510  {
1511  assert(
1514  pData->buffer, pData->length,
1517  }
1518 
1519 #if defined LIBO_INTERNAL_ONLY
1520 
1521  template<typename T>
1522  typename
1524  lastIndexOf(T & literal) const {
1526  pData->buffer, pData->length,
1529  }
1530 
1532  sal_Int32 lastIndexOf(OUStringLiteral const & literal) const {
1534  pData->buffer, pData->length, literal.data, literal.size);
1535  }
1536 #endif
1537 
1547  sal_Int32 stripStart(sal_Unicode c = ' ')
1548  {
1549  sal_Int32 index;
1550  for(index = 0; index < getLength() ; index++)
1551  {
1552  if(pData->buffer[ index ] != c)
1553  {
1554  break;
1555  }
1556  }
1557  if(index)
1558  {
1559  remove(0, index);
1560  }
1561  return index;
1562  }
1563 
1573  sal_Int32 stripEnd(sal_Unicode c = ' ')
1574  {
1575  sal_Int32 result = getLength();
1576  sal_Int32 index;
1577  for(index = getLength(); index > 0 ; index--)
1578  {
1579  if(pData->buffer[ index - 1 ] != c)
1580  {
1581  break;
1582  }
1583  }
1584  if(index < getLength())
1585  {
1586  truncate(index);
1587  }
1588  return result - getLength();
1589  }
1599  sal_Int32 strip(sal_Unicode c = ' ')
1600  {
1601  return stripStart(c) + stripEnd(c);
1602  }
1614  OUStringBuffer copy( sal_Int32 beginIndex ) const
1615  {
1616  return copy( beginIndex, getLength() - beginIndex );
1617  }
1618 
1632  OUStringBuffer copy( sal_Int32 beginIndex, sal_Int32 count ) const
1633  {
1634  assert(beginIndex >= 0 && beginIndex <= getLength());
1635  assert(count >= 0 && count <= getLength() - beginIndex);
1636  rtl_uString *pNew = NULL;
1637  rtl_uStringbuffer_newFromStr_WithLength( &pNew, getStr() + beginIndex, count );
1638  return OUStringBuffer( pNew, count + 16 );
1639  }
1640 
1641 private:
1642  OUStringBuffer( rtl_uString * value, const sal_Int32 capacity )
1643  {
1644  pData = value;
1645  nCapacity = capacity;
1646  }
1647 
1651  rtl_uString * pData;
1652 
1656  sal_Int32 nCapacity;
1657 };
1658 
1659 #if defined LIBO_INTERNAL_ONLY
1660  // Define this here to avoid circular includes
1661  inline OUString & OUString::operator+=( const OUStringBuffer & str ) &
1662  {
1663  // Call operator= if this is empty, otherwise rtl_uString_newConcat will attempt to
1664  // acquire() the str.pData buffer, which is part of the OUStringBuffer mutable state.
1665  if (isEmpty())
1666  return operator=(str.toString());
1667  else
1668  return internalAppend(str.pData);
1669  }
1670 #endif
1671 }
1672 
1673 #ifdef RTL_STRING_UNITTEST
1674 namespace rtl
1675 {
1676 typedef rtlunittest::OUStringBuffer OUStringBuffer;
1677 }
1678 #endif
1679 
1680 #if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST
1681 using ::rtl::OUStringBuffer;
1682 #endif
1683 
1684 #endif // INCLUDED_RTL_USTRBUF_HXX
1685 
1686 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUStringBuffer(const OUString &value)
Constructs a string buffer so that it represents the same sequence of characters as the string argume...
Definition: ustrbuf.hxx:130
void setLength(sal_Int32 newLength)
Sets the length of this String buffer.
Definition: ustrbuf.hxx:422
SAL_DLLPUBLIC sal_Int32 rtl_ustr_getLength(const sal_Unicode *str) SAL_THROW_EXTERN_C()
Return the length of a string.
OUStringBuffer copy(sal_Int32 beginIndex) const
Returns a new string buffer that is a substring of this string.
Definition: ustrbuf.hxx:1614
SAL_WARN_UNUSED_RESULT OUString makeStringAndClear()
Fill the string data in the new string and clear the buffer.
Definition: ustrbuf.hxx:343
sal_Int32 getLength() const
Returns the length of this string.
Definition: ustring.hxx:641
OUStringBuffer copy(sal_Int32 beginIndex, sal_Int32 count) const
Returns a new string buffer that is a substring of this string.
Definition: ustrbuf.hxx:1632
char sal_Char
A legacy synonym for char.
Definition: types.h:120
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:637
OUStringBuffer & insert(sal_Int32 offset, char c)
Inserts the string representation of the char argument into this string buffer.
Definition: ustrbuf.hxx:1106
OUStringBuffer & appendUtf32(sal_uInt32 c)
Appends a single UTF-32 character to this string buffer.
Definition: ustrbuf.hxx:910
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...
OUStringBuffer & append(const sal_Unicode *str)
Appends the string representation of the char array argument to this string buffer.
Definition: ustrbuf.hxx:606
OUStringBuffer & insert(sal_Int32 offset, double d)
Inserts the string representation of the double argument into this string buffer. ...
Definition: ustrbuf.hxx:1225
#define RTL_USTR_MAX_VALUEOFBOOLEAN
Definition: ustring.h:915
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:1471
#define SAL_DELETED_FUNCTION
short-circuit extra-verbose API namespaces
Definition: types.h:396
sal_Int32 getLength() const
Returns the length (character count) of this string buffer.
Definition: ustrbuf.hxx:355
#define SAL_WARN_UNUSED
Annotate classes where a compiler should warn if an instance is unused.
Definition: types.h:602
OUStringBuffer & append(sal_Unicode c)
Appends the string representation of the char argument to this string buffer.
Definition: ustrbuf.hxx:818
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 & append(bool b)
Appends the string representation of the bool argument to the string buffer.
Definition: ustrbuf.hxx:747
OUStringBuffer insert(sal_Int32 offset, float f)
Inserts the string representation of the float argument into this string buffer.
Definition: ustrbuf.hxx:1201
OUStringBuffer(T &literal, typename libreoffice_internal::ConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type=libreoffice_internal::Dummy())
Definition: ustrbuf.hxx:138
OUStringBuffer(const OUStringBuffer &value)
Allocates a new string buffer that contains the same sequence of characters as the string buffer argu...
Definition: ustrbuf.hxx:80
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.
Definition: stringutils.hxx:305
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:1509
void accessInternals(rtl_uString ***pInternalData, sal_Int32 **pInternalCapacity)
Allows access to the internal data of this OUStringBuffer, for effective manipulation.
Definition: ustrbuf.hxx:1320
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:1343
OUStringBuffer & append(rtl_uString *str)
Definition: ustrbuf.hxx:768
bool isEmpty() const
Checks if a string buffer is empty.
Definition: ustrbuf.hxx:368
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.
#define RTL_USTR_MAX_VALUEOFINT32
Definition: ustring.h:957
OUStringBuffer & append(char c)
Appends the string representation of the ASCII char argument to this string buffer.
Definition: ustrbuf.hxx:802
OUStringBuffer & insert(sal_Int32 offset, bool b)
Inserts the string representation of the bool argument into this string buffer.
Definition: ustrbuf.hxx:1082
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:1418
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:1152
OUStringBuffer & insert(sal_Int32 offset, const OUString &str)
Inserts the string into this string buffer.
Definition: ustrbuf.hxx:950
sal_Int32 stripStart(sal_Unicode c= ' ')
Strip the given character from the start of the buffer.
Definition: ustrbuf.hxx:1547
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:1403
unsigned char sal_Bool
Definition: types.h:38
SAL_DLLPUBLIC sal_Int32 rtl_ustr_valueOfFloat(sal_Unicode *str, float f) SAL_THROW_EXTERN_C()
Create the string representation of a float.
sal_Int32 strip(sal_Unicode c= ' ')
Strip the given character from the both end of the buffer.
Definition: ustrbuf.hxx:1599
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.
#define RTL_USTR_MAX_VALUEOFFLOAT
Definition: ustring.h:1022
sal_Int32 stripEnd(sal_Unicode c= ' ')
Strip the given character from the end of the buffer.
Definition: ustrbuf.hxx:1573
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.
OUStringBuffer()
Constructs a string buffer with no characters in it and an initial capacity of 16 characters...
Definition: ustrbuf.hxx:67
SAL_DLLPUBLIC void rtl_uString_release(rtl_uString *str) SAL_THROW_EXTERN_C() SAL_HOT
Decrement the reference count of a string.
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:972
#define SAL_WARN_UNUSED_RESULT
Use this as markup for functions and methods whose return value must be checked.
Definition: types.h:302
Definition: stringutils.hxx:120
OUStringBuffer & appendAscii(const sal_Char *str, sal_Int32 len)
Appends a 8-Bit ASCII character string to this string buffer.
Definition: ustrbuf.hxx:728
void ensureCapacity(sal_Int32 minimumCapacity)
Ensures that the capacity of the buffer is at least equal to the specified minimum.
Definition: ustrbuf.hxx:399
OUStringBuffer & insert(sal_Int32 offset, sal_Unicode c)
Inserts the string representation of the char argument into this string buffer.
Definition: ustrbuf.hxx:1128
sal_uInt16 sal_Unicode
Definition: types.h:141
const sal_Unicode * getStr() const SAL_RETURNS_NONNULL
Returns a pointer to the Unicode character buffer for this string.
Definition: ustring.hxx:663
~OUStringBuffer()
Release the string data.
Definition: ustrbuf.hxx:330
sal_Int32 getCapacity() const
Returns the current capacity of the String buffer.
Definition: ustrbuf.hxx:383
OUStringBuffer & append(sal_Int64 l, sal_Int16 radix=10)
Appends the string representation of the long argument to this string buffer.
Definition: ustrbuf.hxx:857
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...
OUStringBuffer & append(const OUString &str)
Appends the string to this string buffer.
Definition: ustrbuf.hxx:528
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.
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:1496
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.
Definition: bootstrap.hxx:29
OUStringBuffer & truncate(sal_Int32 start=0)
Removes the tail of a string buffer start at the indicate position.
Definition: ustrbuf.hxx:1279
OUStringBuffer & append(sal_Bool b)
Appends the string representation of the sal_Bool argument to the string buffer.
Definition: ustrbuf.hxx:784
This String class provides base functionality for C++ like Unicode character array handling...
Definition: ustring.hxx:123
definition of a no acquire enum for ctors
Definition: types.h:374
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.
#define RTL_USTR_MAX_VALUEOFDOUBLE
Definition: ustring.h:1041
#define SAL_DEPRECATED(message)
Use as follows: SAL_DEPRECATED("Don&#39;t use, it&#39;s evil.") void doit(int nPara);.
Definition: types.h:489
OUStringBuffer & replace(sal_Unicode oldChar, sal_Unicode newChar)
Replace all occurrences of oldChar in this string buffer with newChar.
Definition: ustrbuf.hxx:1295
OUStringBuffer & insert(sal_Int32 offset, sal_Bool b)
Inserts the string representation of the sal_Bool argument into this string buffer.
Definition: ustrbuf.hxx:1057
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:1177
SAL_DLLPUBLIC void rtl_uStringbuffer_remove(rtl_uString **This, sal_Int32 start, sal_Int32 len)
Removes the characters in a substring of this sequence.
SAL_DLLPUBLIC sal_Int32 rtl_ustr_valueOfBoolean(sal_Unicode *str, sal_Bool b) SAL_THROW_EXTERN_C()
Create the string representation of a boolean.
SAL_DLLPUBLIC void rtl_uString_newFromLiteral(rtl_uString **newStr, const sal_Char *value, sal_Int32 len, sal_Int32 allocExtra) SAL_THROW_EXTERN_C()
SAL_DLLPUBLIC sal_Int32 rtl_str_getLength(const sal_Char *str) SAL_THROW_EXTERN_C()
Return the length of a string.
OUStringBuffer & insertUtf32(sal_Int32 offset, sal_uInt32 c)
Inserts a single UTF-32 character into this string buffer.
Definition: ustrbuf.hxx:1246
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:1361
OUStringBuffer & append(const OUStringBuffer &str)
Appends the content of a stringbuffer to this string buffer.
Definition: ustrbuf.hxx:586
const OUString toString() const
Return a OUString instance reflecting the current content of this OUStringBuffer. ...
Definition: ustrbuf.hxx:513
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:624
Definition: stringutils.hxx:118
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:1008
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 & append(float f)
Appends the string representation of the float argument to this string buffer.
Definition: ustrbuf.hxx:874
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 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:1380
OUStringBuffer & appendAscii(const sal_Char *str)
Appends a 8-Bit ASCII character string to this string buffer.
Definition: ustrbuf.hxx:705
OUString & operator+=(const OUString &str)
Append a string to this string.
Definition: ustring.hxx:540
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:839
OUStringBuffer(int length)
Constructs a string buffer with no characters in it and an initial capacity specified by the length a...
Definition: ustrbuf.hxx:93
OUStringBuffer & append(double d)
Appends the string representation of the double argument to this string buffer.
Definition: ustrbuf.hxx:891
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.
A string buffer implements a mutable sequence of characters.
Definition: ustrbuf.hxx:59
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.
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.
SAL_DLLPUBLIC sal_Int32 rtl_ustr_valueOfDouble(sal_Unicode *str, double d) SAL_THROW_EXTERN_C()
Create the string representation of a double.
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:995
#define RTL_USTR_MAX_VALUEOFINT64
Definition: ustring.h:1003
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.
const sal_Unicode * getStr() const SAL_RETURNS_NONNULL
Return a null terminated unicode character array.
Definition: ustrbuf.hxx:477
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_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:929