LibreOffice
LibreOffice 6.0 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 #ifdef RTL_STRING_UNITTEST
39 extern bool rtl_string_unittest_invalid_conversion;
40 #endif
41 
42 // The unittest uses slightly different code to help check that the proper
43 // calls are made. The class is put into a different namespace to make
44 // sure the compiler generates a different (if generating also non-inline)
45 // copy of the function and does not merge them together. The class
46 // is "brought" into the proper rtl namespace by a typedef below.
47 #ifdef RTL_STRING_UNITTEST
48 #define rtl rtlunittest
49 #endif
50 
51 namespace rtl
52 {
53 
54 #ifdef RTL_STRING_UNITTEST
55 #undef rtl
56 #endif
57 
61 {
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( const 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> const & 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 
546  {
547  if(!str.isEmpty())
548  {
549  append( str.getStr(), str.getLength() );
550  }
551  return *this;
552  }
553 
566  {
567  return append( str, rtl_ustr_getLength( str ) );
568  }
569 
583  OUStringBuffer & append( const sal_Unicode * str, sal_Int32 len)
584  {
585  assert( len == 0 || str != NULL ); // cannot assert that in rtl_uStringbuffer_insert
586  rtl_uStringbuffer_insert( &pData, &nCapacity, getLength(), str, len );
587  return *this;
588  }
589 
595  template< typename T >
597  {
598  assert(
601  &pData, &nCapacity, getLength(),
604  return *this;
605  }
606 
607 #if defined LIBO_INTERNAL_ONLY
608 
609  template<typename T>
611  T, OUStringBuffer &>::TypeUtf16
612  append(T & literal) {
614  &pData, &nCapacity, getLength(),
617  return *this;
618  }
619 
621  OUStringBuffer & append(OUStringLiteral const & literal) {
623  &pData, &nCapacity, getLength(), literal.data, literal.size);
624  return *this;
625  }
626 #endif
627 
628 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
629 
633  template< typename T1, typename T2 >
634  OUStringBuffer& append( const OUStringConcat< T1, T2 >& c )
635  {
636  sal_Int32 l = c.length();
637  if( l == 0 )
638  return *this;
639  l += pData->length;
640  rtl_uStringbuffer_ensureCapacity( &pData, &nCapacity, l );
641  sal_Unicode* end = c.addData( pData->buffer + pData->length );
642  *end = '\0';
643  pData->length = l;
644  return *this;
645  }
646 #endif
647 
665  {
666  return appendAscii( str, rtl_str_getLength( str ) );
667  }
668 
687  OUStringBuffer & appendAscii( const sal_Char * str, sal_Int32 len)
688  {
689  rtl_uStringbuffer_insert_ascii( &pData, &nCapacity, getLength(), str, len );
690  return *this;
691  }
692 
707  {
709  return append( sz, rtl_ustr_valueOfBoolean( sz, b ) );
710  }
711 
713  // Pointer can be automatically converted to bool, which is unwanted here.
714  // Explicitly delete all pointer append() overloads to prevent this
715  // (except for char* and sal_Unicode* overloads, which are handled elsewhere).
716  template< typename T >
717  typename libreoffice_internal::Enable< void,
719  append( T* ) SAL_DELETED_FUNCTION;
721 
722  // This overload is needed because OUString has a ctor from rtl_uString*, but
723  // the bool overload above would be preferred to the conversion.
727  OUStringBuffer & append(rtl_uString* str)
728  {
729  return append( OUString( str ));
730  }
731 
744  {
746  return append( sz, rtl_ustr_valueOfBoolean( sz, b ) );
747  }
748 
762  {
763  assert(static_cast< unsigned char >(c) <= 0x7F);
764  return append(sal_Unicode(c));
765  }
766 
778  {
779  return append( &c, 1 );
780  }
781 
782 #if defined LIBO_INTERNAL_ONLY
783  void append(sal_uInt16) = delete;
784 #endif
785 
798  OUStringBuffer & append(sal_Int32 i, sal_Int16 radix = 10 )
799  {
801  return append( sz, rtl_ustr_valueOfInt32( sz, i, radix ) );
802  }
803 
816  OUStringBuffer & append(sal_Int64 l, sal_Int16 radix = 10 )
817  {
819  return append( sz, rtl_ustr_valueOfInt64( sz, l, radix ) );
820  }
821 
834  {
836  return append( sz, rtl_ustr_valueOfFloat( sz, f ) );
837  }
838 
850  OUStringBuffer & append(double d)
851  {
853  return append( sz, rtl_ustr_valueOfDouble( sz, d ) );
854  }
855 
869  OUStringBuffer & appendUtf32(sal_uInt32 c) {
870  return insertUtf32(getLength(), c);
871  }
872 
888  sal_Unicode * appendUninitialized(sal_Int32 length) SAL_RETURNS_NONNULL {
889  sal_Int32 n = getLength();
890  rtl_uStringbuffer_insert(&pData, &nCapacity, n, NULL, length);
891  return pData->buffer + n;
892  }
893 
909  OUStringBuffer & insert(sal_Int32 offset, const OUString & str)
910  {
911  return insert( offset, str.getStr(), str.getLength() );
912  }
913 
931  OUStringBuffer & insert( sal_Int32 offset, const sal_Unicode * str )
932  {
933  return insert( offset, str, rtl_ustr_getLength( str ) );
934  }
935 
954  OUStringBuffer & insert( sal_Int32 offset, const sal_Unicode * str, sal_Int32 len)
955  {
956  assert( len == 0 || str != NULL ); // cannot assert that in rtl_uStringbuffer_insert
957  rtl_uStringbuffer_insert( &pData, &nCapacity, offset, str, len );
958  return *this;
959  }
960 
966  template< typename T >
968  {
969  assert(
972  &pData, &nCapacity, offset,
975  return *this;
976  }
977 
978 #if defined LIBO_INTERNAL_ONLY
979 
980  template<typename T>
982  T, OUStringBuffer &>::TypeUtf16
983  insert(sal_Int32 offset, T & literal) {
985  &pData, &nCapacity, offset,
988  return *this;
989  }
990 
992  OUStringBuffer & insert(sal_Int32 offset, OUStringLiteral const & literal) {
994  &pData, &nCapacity, offset, literal.data, literal.size);
995  return *this;
996  }
997 #endif
998 
1016  OUStringBuffer & insert(sal_Int32 offset, sal_Bool b)
1017  {
1019  return insert( offset, sz, rtl_ustr_valueOfBoolean( sz, b ) );
1020  }
1021 
1041  OUStringBuffer & insert(sal_Int32 offset, bool b)
1042  {
1044  return insert( offset, sz, rtl_ustr_valueOfBoolean( sz, b ) );
1045  }
1046 
1065  OUStringBuffer & insert(sal_Int32 offset, char c)
1066  {
1067  sal_Unicode u = c;
1068  return insert( offset, &u, 1 );
1069  }
1070 
1087  OUStringBuffer & insert(sal_Int32 offset, sal_Unicode c)
1088  {
1089  return insert( offset, &c, 1 );
1090  }
1091 
1111  OUStringBuffer & insert(sal_Int32 offset, sal_Int32 i, sal_Int16 radix = 10 )
1112  {
1114  return insert( offset, sz, rtl_ustr_valueOfInt32( sz, i, radix ) );
1115  }
1116 
1136  OUStringBuffer & insert(sal_Int32 offset, sal_Int64 l, sal_Int16 radix = 10 )
1137  {
1139  return insert( offset, sz, rtl_ustr_valueOfInt64( sz, l, radix ) );
1140  }
1141 
1160  OUStringBuffer insert(sal_Int32 offset, float f)
1161  {
1163  return insert( offset, sz, rtl_ustr_valueOfFloat( sz, f ) );
1164  }
1165 
1184  OUStringBuffer & insert(sal_Int32 offset, double d)
1185  {
1187  return insert( offset, sz, rtl_ustr_valueOfDouble( sz, d ) );
1188  }
1189 
1205  OUStringBuffer & insertUtf32(sal_Int32 offset, sal_uInt32 c) {
1206  rtl_uStringbuffer_insertUtf32(&pData, &nCapacity, offset, c);
1207  return *this;
1208  }
1209 
1222  OUStringBuffer & remove( sal_Int32 start, sal_Int32 len )
1223  {
1224  rtl_uStringbuffer_remove( &pData, start, len );
1225  return *this;
1226  }
1227 
1238  OUStringBuffer & truncate( sal_Int32 start = 0 )
1239  {
1240  rtl_uStringbuffer_remove( &pData, start, getLength() - start );
1241  return *this;
1242  }
1243 
1255  {
1256  sal_Int32 index = 0;
1257  while((index = indexOf(oldChar, index)) >= 0)
1258  {
1259  pData->buffer[ index ] = newChar;
1260  }
1261  return *this;
1262  }
1263 
1279  void accessInternals(rtl_uString *** pInternalData,
1280  sal_Int32 ** pInternalCapacity)
1281  {
1282  *pInternalData = &pData;
1283  *pInternalCapacity = &nCapacity;
1284  }
1285 
1286 
1302  sal_Int32 indexOf( sal_Unicode ch, sal_Int32 fromIndex = 0 ) const
1303  {
1304  assert( fromIndex >= 0 && fromIndex <= pData->length );
1305  sal_Int32 ret = rtl_ustr_indexOfChar_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, ch );
1306  return (ret < 0 ? ret : ret+fromIndex);
1307  }
1308 
1320  sal_Int32 lastIndexOf( sal_Unicode ch ) const
1321  {
1322  return rtl_ustr_lastIndexOfChar_WithLength( pData->buffer, pData->length, ch );
1323  }
1324 
1339  sal_Int32 lastIndexOf( sal_Unicode ch, sal_Int32 fromIndex ) const
1340  {
1341  assert( fromIndex >= 0 && fromIndex <= pData->length );
1342  return rtl_ustr_lastIndexOfChar_WithLength( pData->buffer, fromIndex, ch );
1343  }
1344 
1362  sal_Int32 indexOf( const OUString & str, sal_Int32 fromIndex = 0 ) const
1363  {
1364  assert( fromIndex >= 0 && fromIndex <= pData->length );
1365  sal_Int32 ret = rtl_ustr_indexOfStr_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
1366  str.pData->buffer, str.pData->length );
1367  return (ret < 0 ? ret : ret+fromIndex);
1368  }
1369 
1376  template< typename T >
1377  typename libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type indexOf( T& literal, sal_Int32 fromIndex = 0 ) const
1378  {
1379  assert(
1381  sal_Int32 n = rtl_ustr_indexOfAscii_WithLength(
1382  pData->buffer + fromIndex, pData->length - fromIndex,
1385  return n < 0 ? n : n + fromIndex;
1386  }
1387 
1388 #if defined LIBO_INTERNAL_ONLY
1389 
1390  template<typename T>
1391  typename
1393  indexOf(T & literal, sal_Int32 fromIndex = 0) const {
1394  assert(fromIndex >= 0);
1396  pData->buffer + fromIndex, pData->length - fromIndex,
1399  return n < 0 ? n : n + fromIndex;
1400  }
1401 
1403  sal_Int32 indexOf(OUStringLiteral const & literal, sal_Int32 fromIndex = 0)
1404  const
1405  {
1406  sal_Int32 n = rtl_ustr_indexOfAscii_WithLength(
1407  pData->buffer + fromIndex, pData->length - fromIndex, literal.data,
1408  literal.size);
1409  return n < 0 ? n : n + fromIndex;
1410  }
1411 #endif
1412 
1430  sal_Int32 lastIndexOf( const OUString & str ) const
1431  {
1432  return rtl_ustr_lastIndexOfStr_WithLength( pData->buffer, pData->length,
1433  str.pData->buffer, str.pData->length );
1434  }
1435 
1455  sal_Int32 lastIndexOf( const OUString & str, sal_Int32 fromIndex ) const
1456  {
1457  assert( fromIndex >= 0 && fromIndex <= pData->length );
1458  return rtl_ustr_lastIndexOfStr_WithLength( pData->buffer, fromIndex,
1459  str.pData->buffer, str.pData->length );
1460  }
1461 
1467  template< typename T >
1469  {
1470  assert(
1473  pData->buffer, pData->length,
1476  }
1477 
1478 #if defined LIBO_INTERNAL_ONLY
1479 
1480  template<typename T>
1481  typename
1483  lastIndexOf(T & literal) const {
1485  pData->buffer, pData->length,
1488  }
1489 
1491  sal_Int32 lastIndexOf(OUStringLiteral const & literal) const {
1493  pData->buffer, pData->length, literal.data, literal.size);
1494  }
1495 #endif
1496 
1506  sal_Int32 stripStart(sal_Unicode c = ' ')
1507  {
1508  sal_Int32 index;
1509  for(index = 0; index < getLength() ; index++)
1510  {
1511  if(pData->buffer[ index ] != c)
1512  {
1513  break;
1514  }
1515  }
1516  if(index)
1517  {
1518  remove(0, index);
1519  }
1520  return index;
1521  }
1522 
1532  sal_Int32 stripEnd(sal_Unicode c = ' ')
1533  {
1534  sal_Int32 result = getLength();
1535  sal_Int32 index;
1536  for(index = getLength(); index > 0 ; index--)
1537  {
1538  if(pData->buffer[ index - 1 ] != c)
1539  {
1540  break;
1541  }
1542  }
1543  if(index < getLength())
1544  {
1545  truncate(index);
1546  }
1547  return result - getLength();
1548  }
1558  sal_Int32 strip(sal_Unicode c = ' ')
1559  {
1560  return stripStart(c) + stripEnd(c);
1561  }
1573  OUStringBuffer copy( sal_Int32 beginIndex ) const
1574  {
1575  return copy( beginIndex, getLength() - beginIndex );
1576  }
1577 
1591  OUStringBuffer copy( sal_Int32 beginIndex, sal_Int32 count ) const
1592  {
1593  assert(beginIndex >= 0 && beginIndex <= getLength());
1594  assert(count >= 0 && count <= getLength() - beginIndex);
1595  rtl_uString *pNew = NULL;
1596  rtl_uStringbuffer_newFromStr_WithLength( &pNew, getStr() + beginIndex, count );
1597  return OUStringBuffer( pNew, count + 16 );
1598  }
1599 
1600 private:
1601  OUStringBuffer( rtl_uString * value, const sal_Int32 capacity )
1602  {
1603  pData = value;
1604  nCapacity = capacity;
1605  }
1606 
1610  rtl_uString * pData;
1611 
1615  sal_Int32 nCapacity;
1616 };
1617 
1618 }
1619 
1620 #ifdef RTL_STRING_UNITTEST
1621 namespace rtl
1622 {
1623 typedef rtlunittest::OUStringBuffer OUStringBuffer;
1624 }
1625 #endif
1626 
1627 #if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST
1628 using ::rtl::OUStringBuffer;
1629 #endif
1630 
1631 #endif // INCLUDED_RTL_USTRBUF_HXX
1632 
1633 /* 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:1573
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:633
OUStringBuffer copy(sal_Int32 beginIndex, sal_Int32 count) const
Returns a new string buffer that is a substring of this string.
Definition: ustrbuf.hxx:1591
char sal_Char
A legacy synonym for char.
Definition: types.h:121
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:596
OUStringBuffer & insert(sal_Int32 offset, char c)
Inserts the string representation of the char argument into this string buffer.
Definition: ustrbuf.hxx:1065
OUStringBuffer & appendUtf32(sal_uInt32 c)
Appends a single UTF-32 character to this string buffer.
Definition: ustrbuf.hxx:869
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:565
OUStringBuffer & insert(sal_Int32 offset, double d)
Inserts the string representation of the double argument into this string buffer. ...
Definition: ustrbuf.hxx:1184
#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:1430
#define SAL_DELETED_FUNCTION
short-circuit extra-verbose API namespaces
Definition: types.h:402
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:608
OUStringBuffer & append(sal_Unicode c)
Appends the string representation of the char argument to this string buffer.
Definition: ustrbuf.hxx:777
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:706
OUStringBuffer insert(sal_Int32 offset, float f)
Inserts the string representation of the float argument into this string buffer.
Definition: ustrbuf.hxx:1160
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:267
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:1468
void accessInternals(rtl_uString ***pInternalData, sal_Int32 **pInternalCapacity)
Allows access to the internal data of this OUStringBuffer, for effective manipulation.
Definition: ustrbuf.hxx:1279
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:1302
OUStringBuffer & append(rtl_uString *str)
Definition: ustrbuf.hxx:727
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:761
OUStringBuffer & insert(sal_Int32 offset, bool b)
Inserts the string representation of the bool argument into this string buffer.
Definition: ustrbuf.hxx:1041
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:1377
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:1111
OUStringBuffer & insert(sal_Int32 offset, const OUString &str)
Inserts the string into this string buffer.
Definition: ustrbuf.hxx:909
sal_Int32 stripStart(sal_Unicode c= ' ')
Strip the given character from the start of the buffer.
Definition: ustrbuf.hxx:1506
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:1362
unsigned char sal_Bool
Definition: types.h:39
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:1558
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:1532
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:931
#define SAL_WARN_UNUSED_RESULT
Use this as markup for functions and methods whose return value must be checked.
Definition: types.h:307
Definition: stringutils.hxx:117
OUStringBuffer & appendAscii(const sal_Char *str, sal_Int32 len)
Appends a 8-Bit ASCII character string to this string buffer.
Definition: ustrbuf.hxx:687
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:1087
sal_uInt16 sal_Unicode
Definition: types.h:142
const sal_Unicode * getStr() const SAL_RETURNS_NONNULL
Returns a pointer to the Unicode character buffer for this string.
Definition: ustring.hxx:655
~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:816
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:1455
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.
OUStringBuffer & truncate(sal_Int32 start=0)
Removes the tail of a string buffer start at the indicate position.
Definition: ustrbuf.hxx:1238
OUStringBuffer & append(sal_Bool b)
Appends the string representation of the sal_Bool argument to the string buffer.
Definition: ustrbuf.hxx:743
Definition: bootstrap.hxx:29
This String class provides base functionality for C++ like Unicode character array handling...
Definition: ustring.hxx:120
definition of a no acquire enum for ctors
Definition: types.h:380
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:493
OUStringBuffer & replace(sal_Unicode oldChar, sal_Unicode newChar)
Replace all occurrences of oldChar in this string buffer with newChar.
Definition: ustrbuf.hxx:1254
OUStringBuffer & insert(sal_Int32 offset, sal_Bool b)
Inserts the string representation of the sal_Bool argument into this string buffer.
Definition: ustrbuf.hxx:1016
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:1136
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:1205
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:1320
OUStringBuffer & append(const OUStringBuffer &str)
Appends the content of a stringbuffer to this string buffer.
Definition: ustrbuf.hxx:545
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:583
Definition: stringutils.hxx:115
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:967
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:833
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:1339
OUStringBuffer & appendAscii(const sal_Char *str)
Appends a 8-Bit ASCII character string to this string buffer.
Definition: ustrbuf.hxx:664
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:798
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:850
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:60
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:954
#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:888