LibreOffice
LibreOffice 6.0 SDK C/C++ API Reference
string.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_STRING_HXX
21 #define INCLUDED_RTL_STRING_HXX
22 
23 #include "sal/config.h"
24 
25 #include <cassert>
26 #include <cstddef>
27 #include <new>
28 #include <ostream>
29 #include <utility>
30 #include <string.h>
31 
32 #include "rtl/textenc.h"
33 #include "rtl/string.h"
34 #include "rtl/stringutils.hxx"
35 
36 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
37 #include "rtl/stringconcat.hxx"
38 #endif
39 
40 #include "sal/log.hxx"
41 
42 #ifdef RTL_STRING_UNITTEST
43 extern bool rtl_string_unittest_const_literal;
44 extern bool rtl_string_unittest_const_literal_function;
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 
60 #ifdef RTL_STRING_UNITTEST
61 #undef rtl
62 // helper macro to make functions appear more readable
63 #define RTL_STRING_CONST_FUNCTION rtl_string_unittest_const_literal_function = true;
64 #else
65 #define RTL_STRING_CONST_FUNCTION
66 #endif
67 
69 /* ======================================================================= */
70 
95 class SAL_WARN_UNUSED SAL_DLLPUBLIC_RTTI OString
96 {
97 public:
99  rtl_String * pData;
101 
106  {
107  pData = NULL;
108  rtl_string_new( &pData );
109  }
110 
116  OString( const OString & str )
117  {
118  pData = str.pData;
119  rtl_string_acquire( pData );
120  }
121 
122 #ifndef _MSC_VER // TODO?
123 #if defined LIBO_INTERNAL_ONLY
124 
130  OString( OString && str )
131  {
132  pData = str.pData;
133  str.pData = nullptr;
134  rtl_string_new( &str.pData );
135  }
136 #endif
137 #endif
138 
144  OString( rtl_String * str )
145  {
146  pData = str;
147  rtl_string_acquire( pData );
148  }
149 
157  OString( rtl_String * str, __sal_NoAcquire )
158  {
159  pData = str;
160  }
161 
167  explicit OString( sal_Char value )
168  : pData (NULL)
169  {
170  rtl_string_newFromStr_WithLength( &pData, &value, 1 );
171  }
172 
181  template< typename T >
183  {
184  pData = NULL;
185  rtl_string_newFromStr( &pData, value );
186  }
187 
188  template< typename T >
190  {
191  pData = NULL;
192  rtl_string_newFromStr( &pData, value );
193  }
194 
205  template< typename T >
207  {
208  assert(
210  pData = NULL;
212  rtl_string_new(&pData);
213  } else {
215  &pData,
217  literal),
219  }
220 #ifdef RTL_STRING_UNITTEST
221  rtl_string_unittest_const_literal = true;
222 #endif
223  }
224 
233  OString( const sal_Char * value, sal_Int32 length )
234  {
235  pData = NULL;
236  rtl_string_newFromStr_WithLength( &pData, value, length );
237  }
238 
253  OString( const sal_Unicode * value, sal_Int32 length,
254  rtl_TextEncoding encoding,
255  sal_uInt32 convertFlags = OUSTRING_TO_OSTRING_CVTFLAGS )
256  {
257  pData = NULL;
258  rtl_uString2String( &pData, value, length, encoding, convertFlags );
259  if (pData == NULL) {
260  throw std::bad_alloc();
261  }
262  }
263 
264 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
265 
269  template< typename T1, typename T2 >
270  OString( OStringConcat< T1, T2 >&& c )
271  {
272  const sal_Int32 l = c.length();
273  pData = rtl_string_alloc( l );
274  if (l != 0)
275  {
276  char* end = c.addData( pData->buffer );
277  pData->length = l;
278  *end = '\0';
279  }
280  }
281 #endif
282 
283 #ifdef LIBO_INTERNAL_ONLY
284  OString(std::nullptr_t) = delete;
285 #endif
286 
291  {
292  rtl_string_release( pData );
293  }
294 
300  OString & operator=( const OString & str )
301  {
302  rtl_string_assign( &pData, str.pData );
303  return *this;
304  }
305 
306 #ifndef _MSC_VER // TODO?
307 #if defined LIBO_INTERNAL_ONLY
308 
314  OString & operator=( OString && str )
315  {
316  rtl_string_release( pData );
317  pData = str.pData;
318  str.pData = nullptr;
319  rtl_string_new( &str.pData );
320  return *this;
321  }
322 #endif
323 #endif
324 
330  template< typename T >
332  {
333  RTL_STRING_CONST_FUNCTION
334  assert(
337  rtl_string_new(&pData);
338  } else {
340  &pData,
342  literal),
344  }
345  return *this;
346  }
347 
353  OString & operator+=( const OString & str )
354 #if defined LIBO_INTERNAL_ONLY
355  &
356 #endif
357  {
358  rtl_string_newConcat( &pData, pData, str.pData );
359  return *this;
360  }
361 #if defined LIBO_INTERNAL_ONLY
362  void operator+=(OString const &) && = delete;
363 #endif
364 
365 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
366 
370  template< typename T1, typename T2 >
371  OString& operator+=( OStringConcat< T1, T2 >&& c ) & {
372  sal_Int32 l = c.length();
373  if( l == 0 )
374  return *this;
375  l += pData->length;
376  rtl_string_ensureCapacity( &pData, l );
377  char* end = c.addData( pData->buffer + pData->length );
378  *end = '\0';
379  pData->length = l;
380  return *this;
381  }
382  template<typename T1, typename T2> void operator +=(
383  OStringConcat<T1, T2> &&) && = delete;
384 #endif
385 
390  void clear()
391  {
392  rtl_string_new( &pData );
393  }
394 
403  sal_Int32 getLength() const { return pData->length; }
404 
413  bool isEmpty() const
414  {
415  return pData->length == 0;
416  }
417 
429  const sal_Char * getStr() const SAL_RETURNS_NONNULL { return pData->buffer; }
430 
440  sal_Char operator [](sal_Int32 index) const {
441  // silence spurious -Werror=strict-overflow warnings from GCC 4.8.2
442  assert(index >= 0 && static_cast<sal_uInt32>(index) < static_cast<sal_uInt32>(getLength()));
443  return getStr()[index];
444  }
445 
458  sal_Int32 compareTo( const OString & str ) const
459  {
460  return rtl_str_compare_WithLength( pData->buffer, pData->length,
461  str.pData->buffer, str.pData->length );
462  }
463 
477  sal_Int32 compareTo( const OString & rObj, sal_Int32 maxLength ) const
478  {
479  return rtl_str_shortenedCompare_WithLength( pData->buffer, pData->length,
480  rObj.pData->buffer, rObj.pData->length, maxLength );
481  }
482 
495  sal_Int32 reverseCompareTo( const OString & str ) const
496  {
497  return rtl_str_reverseCompare_WithLength( pData->buffer, pData->length,
498  str.pData->buffer, str.pData->length );
499  }
500 
512  bool equals( const OString & str ) const
513  {
514  if ( pData->length != str.pData->length )
515  return false;
516  if ( pData == str.pData )
517  return true;
518  return rtl_str_reverseCompare_WithLength( pData->buffer, pData->length,
519  str.pData->buffer, str.pData->length ) == 0;
520  }
521 
537  bool equalsL( const sal_Char* value, sal_Int32 length ) const
538  {
539  if ( pData->length != length )
540  return false;
541 
542  return rtl_str_reverseCompare_WithLength( pData->buffer, pData->length,
543  value, length ) == 0;
544  }
545 
560  bool equalsIgnoreAsciiCase( const OString & str ) const
561  {
562  if ( pData->length != str.pData->length )
563  return false;
564  if ( pData == str.pData )
565  return true;
566  return rtl_str_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
567  str.pData->buffer, str.pData->length ) == 0;
568  }
569 
591  template< typename T >
593  {
594  return rtl_str_compareIgnoreAsciiCase( pData->buffer, asciiStr ) == 0;
595  }
596 
597  template< typename T >
599  {
600  return rtl_str_compareIgnoreAsciiCase( pData->buffer, asciiStr ) == 0;
601  }
602 
608  template< typename T >
610  {
611  RTL_STRING_CONST_FUNCTION
612  assert(
614  return
615  (pData->length
618  pData->buffer, pData->length,
620  literal),
622  == 0);
623  }
624 
644  bool equalsIgnoreAsciiCaseL( const sal_Char * asciiStr, sal_Int32 asciiStrLength ) const
645  {
646  if ( pData->length != asciiStrLength )
647  return false;
648 
649  return rtl_str_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
650  asciiStr, asciiStrLength ) == 0;
651  }
652 
668  bool match( const OString & str, sal_Int32 fromIndex = 0 ) const
669  {
670  return rtl_str_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
671  str.pData->buffer, str.pData->length, str.pData->length ) == 0;
672  }
673 
679  template< typename T >
680  typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type match( T& literal, sal_Int32 fromIndex = 0 ) const
681  {
682  RTL_STRING_CONST_FUNCTION
683  assert(
685  return
687  pData->buffer + fromIndex, pData->length - fromIndex,
689  literal),
692  == 0;
693  }
694 
711  bool matchL(
712  char const * str, sal_Int32 strLength, sal_Int32 fromIndex = 0)
713  const
714  {
716  pData->buffer + fromIndex, pData->length - fromIndex,
717  str, strLength, strLength) == 0;
718  }
719 
720  // This overload is left undefined, to detect calls of matchL that
721  // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
722  // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
723  // platforms):
724 #if SAL_TYPES_SIZEOFLONG == 8
725  void matchL(char const *, sal_Int32, rtl_TextEncoding) const;
726 #endif
727 
746  bool matchIgnoreAsciiCase( const OString & str, sal_Int32 fromIndex = 0 ) const
747  {
748  return rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
749  str.pData->buffer, str.pData->length,
750  str.pData->length ) == 0;
751  }
752 
758  template< typename T >
759  typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type matchIgnoreAsciiCase( T& literal, sal_Int32 fromIndex = 0 ) const
760  {
761  RTL_STRING_CONST_FUNCTION
762  assert(
764  return
766  pData->buffer+fromIndex, pData->length-fromIndex,
768  literal),
771  == 0;
772  }
773 
788  bool startsWith(OString const & str, OString * rest = NULL) const {
789  bool b = match(str);
790  if (b && rest != NULL) {
791  *rest = copy(str.getLength());
792  }
793  return b;
794  }
795 
801  template< typename T >
803  T & literal, OString * rest = NULL) const
804  {
805  RTL_STRING_CONST_FUNCTION
806  bool b = match(literal, 0);
807  if (b && rest != NULL) {
808  *rest = copy(
810  }
811  return b;
812  }
813 
833  bool startsWithIgnoreAsciiCase(OString const & str, OString * rest = NULL)
834  const
835  {
836  bool b = matchIgnoreAsciiCase(str);
837  if (b && rest != NULL) {
838  *rest = copy(str.getLength());
839  }
840  return b;
841  }
842 
848  template< typename T >
850  startsWithIgnoreAsciiCase(T & literal, OString * rest = NULL) const
851  {
852  RTL_STRING_CONST_FUNCTION
853  assert(
855  bool b = matchIgnoreAsciiCase(literal);
856  if (b && rest != NULL) {
857  *rest = copy(
859  }
860  return b;
861  }
862 
877  bool endsWith(OString const & str, OString * rest = NULL) const {
878  bool b = str.getLength() <= getLength()
879  && match(str, getLength() - str.getLength());
880  if (b && rest != NULL) {
881  *rest = copy(0, getLength() - str.getLength());
882  }
883  return b;
884  }
885 
891  template< typename T >
893  T & literal, OString * rest = NULL) const
894  {
895  RTL_STRING_CONST_FUNCTION
896  assert(
898  bool b
900  <= sal_uInt32(getLength()))
901  && match(
903  literal),
904  (getLength()
906  if (b && rest != NULL) {
907  *rest = copy(
908  0,
909  (getLength()
911  }
912  return b;
913  }
914 
928  bool endsWithL(char const * str, sal_Int32 strLength) const {
929  return strLength <= getLength()
930  && matchL(str, strLength, getLength() - strLength);
931  }
932 
933  friend bool operator == ( const OString& rStr1, const OString& rStr2 )
934  { return rStr1.equals(rStr2); }
935  friend bool operator != ( const OString& rStr1, const OString& rStr2 )
936  { return !(operator == ( rStr1, rStr2 )); }
937  friend bool operator < ( const OString& rStr1, const OString& rStr2 )
938  { return rStr1.compareTo( rStr2 ) < 0; }
939  friend bool operator > ( const OString& rStr1, const OString& rStr2 )
940  { return rStr1.compareTo( rStr2 ) > 0; }
941  friend bool operator <= ( const OString& rStr1, const OString& rStr2 )
942  { return rStr1.compareTo( rStr2 ) <= 0; }
943  friend bool operator >= ( const OString& rStr1, const OString& rStr2 )
944  { return rStr1.compareTo( rStr2 ) >= 0; }
945 
946  template< typename T >
947  friend typename libreoffice_internal::CharPtrDetector< T, bool >::Type operator==( const OString& rStr1, const T& value )
948  {
949  return rStr1.compareTo( value ) == 0;
950  }
951 
952  template< typename T >
954  {
955  return rStr1.compareTo( value ) == 0;
956  }
957 
958  template< typename T >
959  friend typename libreoffice_internal::CharPtrDetector< T, bool >::Type operator==( const T& value, const OString& rStr2 )
960  {
961  return rStr2.compareTo( value ) == 0;
962  }
963 
964  template< typename T >
966  {
967  return rStr2.compareTo( value ) == 0;
968  }
969 
975  template< typename T >
977  {
978  RTL_STRING_CONST_FUNCTION
979  assert(
981  return
982  (rStr.getLength()
985  rStr.pData->buffer, rStr.pData->length,
987  literal),
989  == 0);
990  }
991 
997  template< typename T >
999  {
1000  RTL_STRING_CONST_FUNCTION
1001  assert(
1003  return
1004  (rStr.getLength()
1007  rStr.pData->buffer, rStr.pData->length,
1009  literal),
1011  == 0);
1012  }
1013 
1014  template< typename T >
1015  friend typename libreoffice_internal::CharPtrDetector< T, bool >::Type operator!=( const OString& rStr1, const T& value )
1016  {
1017  return !(operator == ( rStr1, value ));
1018  }
1019 
1020  template< typename T >
1022  {
1023  return !(operator == ( rStr1, value ));
1024  }
1025 
1026  template< typename T >
1027  friend typename libreoffice_internal::CharPtrDetector< T, bool >::Type operator!=( const T& value, const OString& rStr2 )
1028  {
1029  return !(operator == ( value, rStr2 ));
1030  }
1031 
1032  template< typename T >
1034  {
1035  return !(operator == ( value, rStr2 ));
1036  }
1037 
1043  template< typename T >
1045  {
1046  return !( rStr == literal );
1047  }
1048 
1054  template< typename T >
1056  {
1057  return !( literal == rStr );
1058  }
1059 
1067  sal_Int32 hashCode() const
1068  {
1069  return rtl_str_hashCode_WithLength( pData->buffer, pData->length );
1070  }
1071 
1085  sal_Int32 indexOf( sal_Char ch, sal_Int32 fromIndex = 0 ) const
1086  {
1087  sal_Int32 ret = rtl_str_indexOfChar_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, ch );
1088  return (ret < 0 ? ret : ret+fromIndex);
1089  }
1090 
1100  sal_Int32 lastIndexOf( sal_Char ch ) const
1101  {
1102  return rtl_str_lastIndexOfChar_WithLength( pData->buffer, pData->length, ch );
1103  }
1104 
1117  sal_Int32 lastIndexOf( sal_Char ch, sal_Int32 fromIndex ) const
1118  {
1119  return rtl_str_lastIndexOfChar_WithLength( pData->buffer, fromIndex, ch );
1120  }
1121 
1137  sal_Int32 indexOf( const OString & str, sal_Int32 fromIndex = 0 ) const
1138  {
1139  sal_Int32 ret = rtl_str_indexOfStr_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
1140  str.pData->buffer, str.pData->length );
1141  return (ret < 0 ? ret : ret+fromIndex);
1142  }
1143 
1149  template< typename T >
1150  typename libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type indexOf( T& literal, sal_Int32 fromIndex = 0 ) const
1151  {
1152  RTL_STRING_CONST_FUNCTION
1153  assert(
1155  sal_Int32 n = rtl_str_indexOfStr_WithLength(
1156  pData->buffer + fromIndex, pData->length - fromIndex,
1159  return n < 0 ? n : n + fromIndex;
1160  }
1161 
1180  sal_Int32 indexOfL(char const * str, sal_Int32 len, sal_Int32 fromIndex = 0)
1181  const
1182  {
1183  sal_Int32 n = rtl_str_indexOfStr_WithLength(
1184  pData->buffer + fromIndex, pData->length - fromIndex, str, len);
1185  return n < 0 ? n : n + fromIndex;
1186  }
1187 
1188  // This overload is left undefined, to detect calls of indexOfL that
1189  // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
1190  // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
1191  // platforms):
1192 #if SAL_TYPES_SIZEOFLONG == 8
1193  void indexOfL(char const *, sal_Int32, rtl_TextEncoding) const;
1194 #endif
1195 
1211  sal_Int32 lastIndexOf( const OString & str ) const
1212  {
1213  return rtl_str_lastIndexOfStr_WithLength( pData->buffer, pData->length,
1214  str.pData->buffer, str.pData->length );
1215  }
1216 
1234  sal_Int32 lastIndexOf( const OString & str, sal_Int32 fromIndex ) const
1235  {
1236  return rtl_str_lastIndexOfStr_WithLength( pData->buffer, fromIndex,
1237  str.pData->buffer, str.pData->length );
1238  }
1239 
1250  SAL_WARN_UNUSED_RESULT OString copy( sal_Int32 beginIndex ) const
1251  {
1252  rtl_String *pNew = NULL;
1253  rtl_string_newFromSubString( &pNew, pData, beginIndex, getLength() - beginIndex );
1254  return OString( pNew, SAL_NO_ACQUIRE );
1255  }
1256 
1269  SAL_WARN_UNUSED_RESULT OString copy( sal_Int32 beginIndex, sal_Int32 count ) const
1270  {
1271  rtl_String *pNew = NULL;
1272  rtl_string_newFromSubString( &pNew, pData, beginIndex, count );
1273  return OString( pNew, SAL_NO_ACQUIRE );
1274  }
1275 
1285  {
1286  rtl_String* pNew = NULL;
1287  rtl_string_newConcat( &pNew, pData, str.pData );
1288  return OString( pNew, SAL_NO_ACQUIRE );
1289  }
1290 
1291 #ifndef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
1292  friend OString operator+( const OString & str1, const OString & str2 )
1293  {
1294  return str1.concat( str2 );
1295  }
1296 #endif
1297 
1311  SAL_WARN_UNUSED_RESULT OString replaceAt( sal_Int32 index, sal_Int32 count, const OString& newStr ) const
1312  {
1313  rtl_String* pNew = NULL;
1314  rtl_string_newReplaceStrAt( &pNew, pData, index, count, newStr.pData );
1315  return OString( pNew, SAL_NO_ACQUIRE );
1316  }
1317 
1332  {
1333  rtl_String* pNew = NULL;
1334  rtl_string_newReplace( &pNew, pData, oldChar, newChar );
1335  return OString( pNew, SAL_NO_ACQUIRE );
1336  }
1337 
1357  OString const & from, OString const & to, sal_Int32 * index = NULL) const
1358  {
1359  rtl_String * s = NULL;
1360  sal_Int32 i = 0;
1362  &s, pData, from.pData->buffer, from.pData->length,
1363  to.pData->buffer, to.pData->length, index == NULL ? &i : index);
1364  return OString(s, SAL_NO_ACQUIRE);
1365  }
1366 
1380  SAL_WARN_UNUSED_RESULT OString replaceAll(OString const & from, OString const & to) const {
1381  rtl_String * s = NULL;
1383  &s, pData, from.pData->buffer, from.pData->length,
1384  to.pData->buffer, to.pData->length);
1385  return OString(s, SAL_NO_ACQUIRE);
1386  }
1387 
1399  {
1400  rtl_String* pNew = NULL;
1401  rtl_string_newToAsciiLowerCase( &pNew, pData );
1402  return OString( pNew, SAL_NO_ACQUIRE );
1403  }
1404 
1416  {
1417  rtl_String* pNew = NULL;
1418  rtl_string_newToAsciiUpperCase( &pNew, pData );
1419  return OString( pNew, SAL_NO_ACQUIRE );
1420  }
1421 
1434  {
1435  rtl_String* pNew = NULL;
1436  rtl_string_newTrim( &pNew, pData );
1437  return OString( pNew, SAL_NO_ACQUIRE );
1438  }
1439 
1464  OString getToken( sal_Int32 token, sal_Char cTok, sal_Int32& index ) const
1465  {
1466  rtl_String * pNew = NULL;
1467  index = rtl_string_getToken( &pNew, pData, token, cTok, index );
1468  return OString( pNew, SAL_NO_ACQUIRE );
1469  }
1470 
1484  OString getToken(sal_Int32 count, char separator) const {
1485  sal_Int32 n = 0;
1486  return getToken(count, separator, n);
1487  }
1488 
1497  bool toBoolean() const
1498  {
1499  return rtl_str_toBoolean( pData->buffer );
1500  }
1501 
1509  {
1510  return pData->buffer[0];
1511  }
1512 
1523  sal_Int32 toInt32( sal_Int16 radix = 10 ) const
1524  {
1525  return rtl_str_toInt32( pData->buffer, radix );
1526  }
1527 
1540  sal_uInt32 toUInt32( sal_Int16 radix = 10 ) const
1541  {
1542  return rtl_str_toUInt32( pData->buffer, radix );
1543  }
1544 
1555  sal_Int64 toInt64( sal_Int16 radix = 10 ) const
1556  {
1557  return rtl_str_toInt64( pData->buffer, radix );
1558  }
1559 
1572  sal_uInt64 toUInt64( sal_Int16 radix = 10 ) const
1573  {
1574  return rtl_str_toUInt64( pData->buffer, radix );
1575  }
1576 
1585  float toFloat() const
1586  {
1587  return rtl_str_toFloat( pData->buffer );
1588  }
1589 
1598  double toDouble() const
1599  {
1600  return rtl_str_toDouble( pData->buffer );
1601  }
1602 
1613  static OString number( int i, sal_Int16 radix = 10 )
1614  {
1615  return number( static_cast< long long >( i ), radix );
1616  }
1619  static OString number( unsigned int i, sal_Int16 radix = 10 )
1620  {
1621  return number( static_cast< unsigned long long >( i ), radix );
1622  }
1625  static OString number( long i, sal_Int16 radix = 10 )
1626  {
1627  return number( static_cast< long long >( i ), radix );
1628  }
1631  static OString number( unsigned long i, sal_Int16 radix = 10 )
1632  {
1633  return number( static_cast< unsigned long long >( i ), radix );
1634  }
1637  static OString number( long long ll, sal_Int16 radix = 10 )
1638  {
1640  rtl_String* pNewData = NULL;
1641  rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfInt64( aBuf, ll, radix ) );
1642  return OString( pNewData, SAL_NO_ACQUIRE );
1643  }
1646  static OString number( unsigned long long ll, sal_Int16 radix = 10 )
1647  {
1649  rtl_String* pNewData = NULL;
1650  rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfUInt64( aBuf, ll, radix ) );
1651  return OString( pNewData, SAL_NO_ACQUIRE );
1652  }
1653 
1663  static OString number( float f )
1664  {
1666  rtl_String* pNewData = NULL;
1667  rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfFloat( aBuf, f ) );
1668  return OString( pNewData, SAL_NO_ACQUIRE );
1669  }
1670 
1680  static OString number( double d )
1681  {
1683  rtl_String* pNewData = NULL;
1684  rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfDouble( aBuf, d ) );
1685  return OString( pNewData, SAL_NO_ACQUIRE );
1686  }
1687 
1699  SAL_DEPRECATED("use boolean()") static OString valueOf( sal_Bool b )
1700  {
1701  return boolean(b);
1702  }
1703 
1715  static OString boolean( bool b )
1716  {
1718  rtl_String* pNewData = NULL;
1719  rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfBoolean( aBuf, b ) );
1720  return OString( pNewData, SAL_NO_ACQUIRE );
1721  }
1722 
1730  SAL_DEPRECATED("convert to OString or use directly") static OString valueOf( sal_Char c )
1731  {
1732  return OString( &c, 1 );
1733  }
1734 
1745  SAL_DEPRECATED("use number()") static OString valueOf( sal_Int32 i, sal_Int16 radix = 10 )
1746  {
1747  return number( i, radix );
1748  }
1749 
1760  SAL_DEPRECATED("use number()") static OString valueOf( sal_Int64 ll, sal_Int16 radix = 10 )
1761  {
1762  return number( ll, radix );
1763  }
1764 
1774  SAL_DEPRECATED("use number()") static OString valueOf( float f )
1775  {
1776  return number(f);
1777  }
1778 
1788  SAL_DEPRECATED("use number()") static OString valueOf( double d )
1789  {
1790  return number(d);
1791  }
1792 
1793 };
1794 
1795 /* ======================================================================= */
1796 
1797 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
1798 
1806 struct SAL_WARN_UNUSED OStringLiteral
1807 {
1808  template< int N >
1809  explicit OStringLiteral( const char (&str)[ N ] ) : size( N - 1 ), data( str ) { assert( strlen( str ) == N - 1 ); }
1810  int size;
1811  const char* data;
1812 };
1813 
1817 template<>
1818 struct ToStringHelper< OString >
1819  {
1820  static int length( const OString& s ) { return s.getLength(); }
1821  static char* addData( char* buffer, const OString& s ) { return addDataHelper( buffer, s.getStr(), s.getLength()); }
1822  static const bool allowOStringConcat = true;
1823  static const bool allowOUStringConcat = false;
1824  };
1825 
1829 template<>
1830 struct ToStringHelper< OStringLiteral >
1831  {
1832  static int length( const OStringLiteral& str ) { return str.size; }
1833  static char* addData( char* buffer, const OStringLiteral& str ) { return addDataHelper( buffer, str.data, str.size ); }
1834  static const bool allowOStringConcat = true;
1835  static const bool allowOUStringConcat = false;
1836  };
1837 
1841 template< typename charT, typename traits, typename T1, typename T2 >
1842 inline std::basic_ostream<charT, traits> & operator <<(
1843  std::basic_ostream<charT, traits> & stream, OStringConcat< T1, T2 >&& concat)
1844 {
1845  return stream << OString( std::move(concat) );
1846 }
1847 #endif
1848 
1849 
1856 {
1866  size_t operator()( const OString& rString ) const
1867  { return (size_t)rString.hashCode(); }
1868 };
1869 
1872 {
1873  bool operator()( const char* p1, const char* p2) const
1874  { return rtl_str_compare(p1, p2) == 0; }
1875 };
1876 
1879 {
1880  size_t operator()(const char* p) const
1881  { return rtl_str_hashCode(p); }
1882 };
1883 
1884 /* ======================================================================= */
1885 
1892 template< typename charT, typename traits > std::basic_ostream<charT, traits> &
1894  std::basic_ostream<charT, traits> & stream, OString const & rString)
1895 {
1896  return stream << rString.getStr();
1897  // best effort; potentially loses data due to embedded null characters
1898 }
1899 
1900 } /* Namespace */
1901 
1902 #ifdef RTL_STRING_UNITTEST
1903 namespace rtl
1904 {
1905 typedef rtlunittest::OString OString;
1906 }
1907 #undef RTL_STRING_CONST_FUNCTION
1908 #endif
1909 
1910 #if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST
1911 using ::rtl::OString;
1912 using ::rtl::OStringHash;
1913 using ::rtl::OStringLiteral;
1914 #endif
1915 
1917 
1922 #if defined LIBO_INTERNAL_ONLY
1923 namespace std {
1924 
1925 template<>
1926 struct hash<::rtl::OString>
1927 {
1928  std::size_t operator()(::rtl::OString const & s) const
1929  { return std::size_t(s.hashCode()); }
1930 };
1931 
1932 }
1933 
1934 #endif
1935 
1937 #endif // INCLUDED_RTL_STRING_HXX
1938 
1939 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
friend libreoffice_internal::CharPtrDetector< T, bool >::Type operator==(const T &value, const OString &rStr2)
Definition: string.hxx:959
#define OUSTRING_TO_OSTRING_CVTFLAGS
Definition: string.h:1324
friend libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator==(T &literal, const OString &rStr)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: string.hxx:998
SAL_DLLPUBLIC sal_Int32 rtl_string_getToken(rtl_String **newStr, rtl_String *str, sal_Int32 token, sal_Char cTok, sal_Int32 idx) SAL_THROW_EXTERN_C()
Create a new string by extracting a single token from another string.
static OString number(unsigned long i, sal_Int16 radix=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: string.hxx:1631
SAL_WARN_UNUSED_RESULT OString concat(const OString &str) const
Concatenates the specified string to the end of this string.
Definition: string.hxx:1284
sal_Int32 compareTo(const OString &str) const
Compares two strings.
Definition: string.hxx:458
std::basic_ostream< charT, traits > & operator<<(std::basic_ostream< charT, traits > &stream, OString const &rString)
Support for rtl::OString in std::ostream (and thus in CPPUNIT_ASSERT or SAL_INFO macros, for example).
Definition: string.hxx:1893
SAL_DLLPUBLIC sal_Int32 rtl_str_compareIgnoreAsciiCase_WithLength(const sal_Char *first, sal_Int32 firstLen, const sal_Char *second, sal_Int32 secondLen) SAL_THROW_EXTERN_C()
Compare two strings, ignoring the case of ASCII characters.
double toDouble() const
Returns the double value from this string.
Definition: string.hxx:1598
libreoffice_internal::ConstCharArrayDetector< T, bool >::Type equalsIgnoreAsciiCase(T &literal) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: string.hxx:609
SAL_DLLPUBLIC sal_Int32 rtl_str_hashCode(const sal_Char *str) SAL_THROW_EXTERN_C()
Return a hash code for a string.
friend libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator!=(const OString &rStr, T &literal)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: string.hxx:1044
sal_uInt16 rtl_TextEncoding
The various supported text encodings.
Definition: textenc.h:33
OString(const sal_Char *value, sal_Int32 length)
New string from a character buffer array.
Definition: string.hxx:233
~OString()
Release the string data.
Definition: string.hxx:290
sal_Int64 toInt64(sal_Int16 radix=10) const
Returns the int64 value from this string.
Definition: string.hxx:1555
SAL_DLLPUBLIC sal_Int32 rtl_str_compare_WithLength(const sal_Char *first, sal_Int32 firstLen, const sal_Char *second, sal_Int32 secondLen) SAL_THROW_EXTERN_C()
Compare two strings.
size_t operator()(const OString &rString) const
Compute a hash code for a string.
Definition: string.hxx:1866
libreoffice_internal::ConstCharArrayDetector< T, OString &>::Type operator=(T &literal)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: string.hxx:331
SAL_WARN_UNUSED_RESULT OString toAsciiUpperCase() const
Converts from this string all ASCII lowercase characters (97-122) to ASCII uppercase characters (65-9...
Definition: string.hxx:1415
#define RTL_STR_MAX_VALUEOFFLOAT
Definition: string.h:692
SAL_DLLPUBLIC sal_Int32 rtl_str_reverseCompare_WithLength(const sal_Char *first, sal_Int32 firstLen, const sal_Char *second, sal_Int32 secondLen) SAL_THROW_EXTERN_C()
Compare two strings from back to front.
#define RTL_STR_MAX_VALUEOFUINT64
Definition: string.h:673
SAL_WARN_UNUSED_RESULT OString toAsciiLowerCase() const
Converts from this string all ASCII uppercase characters (65-90) to ASCII lowercase characters (97-12...
Definition: string.hxx:1398
libreoffice_internal::ConstCharArrayDetector< T, bool >::Type matchIgnoreAsciiCase(T &literal, sal_Int32 fromIndex=0) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: string.hxx:759
bool operator==(const TTimeValue &rTimeA, const TTimeValue &rTimeB)
Definition: timer.hxx:116
static OString number(long long ll, sal_Int16 radix=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: string.hxx:1637
SAL_DLLPUBLIC sal_uInt64 rtl_str_toUInt64(const sal_Char *str, sal_Int16 radix) SAL_THROW_EXTERN_C()
Interpret a string as an unsigned long integer.
libreoffice_internal::ConstCharArrayDetector< T, bool >::Type match(T &literal, sal_Int32 fromIndex=0) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: string.hxx:680
libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type equalsIgnoreAsciiCase(T &asciiStr) const
Definition: string.hxx:598
OString getToken(sal_Int32 count, char separator) const
Returns a token from the string.
Definition: string.hxx:1484
SAL_WARN_UNUSED_RESULT OString copy(sal_Int32 beginIndex, sal_Int32 count) const
Returns a new string that is a substring of this string.
Definition: string.hxx:1269
#define RTL_STR_MAX_VALUEOFINT64
Definition: string.h:650
bool matchL(char const *str, sal_Int32 strLength, sal_Int32 fromIndex=0) const
Match against a substring appearing in this string.
Definition: string.hxx:711
friend libreoffice_internal::CharPtrDetector< T, bool >::Type operator!=(const T &value, const OString &rStr2)
Definition: string.hxx:1027
sal_Int32 hashCode() const
Returns a hashcode for this string.
Definition: string.hxx:1067
bool operator<(const TTimeValue &rTimeA, const TTimeValue &rTimeB)
Definition: timer.hxx:96
friend libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type operator==(T &value, const OString &rStr2)
Definition: string.hxx:965
static OString number(float f)
Returns the string representation of the float argument.
Definition: string.hxx:1663
bool matchIgnoreAsciiCase(const OString &str, sal_Int32 fromIndex=0) const
Match against a substring appearing in this string, ignoring the case of ASCII letters.
Definition: string.hxx:746
SAL_DLLPUBLIC sal_Int32 rtl_str_valueOfUInt64(sal_Char *str, sal_uInt64 l, sal_Int16 radix) SAL_THROW_EXTERN_C()
Create the string representation of an unsigned long integer.
SAL_DLLPUBLIC void rtl_string_newFromLiteral(rtl_String **newStr, const sal_Char *value, sal_Int32 len, sal_Int32 allocExtra) SAL_THROW_EXTERN_C()
OString(const OString &str)
New string from OString.
Definition: string.hxx:116
bool operator>(const TTimeValue &rTimeA, const TTimeValue &rTimeB)
Definition: timer.hxx:106
bool operator!=(const Any &rAny, const C &value)
Template unequality operator: compares set value of left side any to right side value.
Definition: Any.hxx:645
sal_Int32 indexOfL(char const *str, sal_Int32 len, 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: string.hxx:1180
SAL_DLLPUBLIC sal_Int32 rtl_str_compare(const sal_Char *first, const sal_Char *second) SAL_THROW_EXTERN_C()
Compare two strings.
OString(const sal_Unicode *value, sal_Int32 length, rtl_TextEncoding encoding, sal_uInt32 convertFlags=OUSTRING_TO_OSTRING_CVTFLAGS)
New string from a Unicode character buffer array.
Definition: string.hxx:253
SAL_DLLPUBLIC sal_Int32 rtl_str_shortenedCompare_WithLength(const sal_Char *first, sal_Int32 firstLen, const sal_Char *second, sal_Int32 secondLen, sal_Int32 shortenedLen) SAL_THROW_EXTERN_C()
Compare two strings with a maximum count of characters.
Hashing functor for classic c-strings (i.e., null-terminated char* strings).
Definition: string.hxx:1878
SAL_DLLPUBLIC sal_Int32 rtl_str_indexOfStr_WithLength(const sal_Char *str, sal_Int32 len, const sal_Char *subStr, sal_Int32 subLen) SAL_THROW_EXTERN_C()
Search for the first occurrence of a substring within a string.
This String class provide base functionality for C++ like 8-Bit character array handling.
Definition: string.hxx:95
bool equals(const OString &str) const
Perform a comparison of two strings.
Definition: string.hxx:512
OString(T &value, typename libreoffice_internal::NonConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type=libreoffice_internal::Dummy())
Definition: string.hxx:189
SAL_DLLPUBLIC float rtl_str_toFloat(const sal_Char *str) SAL_THROW_EXTERN_C()
Interpret a string as a float.
SAL_DLLPUBLIC double rtl_str_toDouble(const sal_Char *str) SAL_THROW_EXTERN_C()
Interpret a string as a double.
SAL_DLLPUBLIC void rtl_string_newToAsciiUpperCase(rtl_String **newStr, rtl_String *str) SAL_THROW_EXTERN_C()
Create a new string by converting all ASCII lowercase letters to uppercase within another string...
libreoffice_internal::ConstCharArrayDetector< T, bool >::Type endsWith(T &literal, OString *rest=NULL) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: string.hxx:892
SAL_DLLPUBLIC void rtl_string_new(rtl_String **newStr) SAL_THROW_EXTERN_C()
Allocate a new string containing no characters.
OString getToken(sal_Int32 token, sal_Char cTok, sal_Int32 &index) const
Returns a token in the string.
Definition: string.hxx:1464
friend libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator==(const OString &rStr, T &literal)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: string.hxx:976
#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
#define SAL_WARN_UNUSED
Annotate classes where a compiler should warn if an instance is unused.
Definition: types.h:606
SAL_DLLPUBLIC sal_Int32 rtl_str_indexOfChar_WithLength(const sal_Char *str, sal_Int32 len, sal_Char ch) SAL_THROW_EXTERN_C()
Search for the first occurrence of a character within a string.
SAL_DLLPUBLIC sal_uInt32 rtl_str_toUInt32(const sal_Char *str, sal_Int16 radix) SAL_THROW_EXTERN_C()
Interpret a string as an unsigned integer.
bool startsWithIgnoreAsciiCase(OString const &str, OString *rest=NULL) const
Check whether this string starts with a given string, ignoring the case of ASCII letters.
Definition: string.hxx:833
SAL_DLLPUBLIC sal_Int64 rtl_str_toInt64(const sal_Char *str, sal_Int16 radix) SAL_THROW_EXTERN_C()
Interpret a string as a long integer.
SAL_DLLPUBLIC void rtl_string_newFromSubString(rtl_String **newStr, const rtl_String *from, sal_Int32 beginIndex, sal_Int32 count) SAL_THROW_EXTERN_C()
Allocate a new string that is a substring of this string.
sal_uInt64 toUInt64(sal_Int16 radix=10) const
Returns the uint64 value from this string.
Definition: string.hxx:1572
SAL_DLLPUBLIC sal_Int32 rtl_str_hashCode_WithLength(const sal_Char *str, sal_Int32 len) SAL_THROW_EXTERN_C()
Return a hash code for a string.
static OString number(double d)
Returns the string representation of the double argument.
Definition: string.hxx:1680
Definition: stringutils.hxx:117
sal_Int32 lastIndexOf(const OString &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: string.hxx:1234
SAL_DLLPUBLIC void rtl_string_newReplace(rtl_String **newStr, rtl_String *str, sal_Char oldChar, sal_Char newChar) SAL_THROW_EXTERN_C()
Create a new string by replacing all occurrences of a single character within another string...
libreoffice_internal::ConstCharArrayDetector< T, bool >::Type startsWith(T &literal, OString *rest=NULL) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: string.hxx:802
Equality functor for classic c-strings (i.e., null-terminated char* strings).
Definition: string.hxx:1871
SAL_DLLPUBLIC sal_Int32 rtl_str_compareIgnoreAsciiCase(const sal_Char *first, const sal_Char *second) SAL_THROW_EXTERN_C()
Compare two strings, ignoring the case of ASCII characters.
SAL_DLLPUBLIC void rtl_uString2String(rtl_String **newStr, const sal_Unicode *str, sal_Int32 len, rtl_TextEncoding encoding, sal_uInt32 convertFlags) SAL_THROW_EXTERN_C()
Create a new byte string by converting a Unicode string, using a specific text encoding.
void clear()
Clears the string, i.e, makes a zero-character string.
Definition: string.hxx:390
SAL_WARN_UNUSED_RESULT OString replaceFirst(OString const &from, OString const &to, sal_Int32 *index=NULL) const
Returns a new string resulting from replacing the first occurrence of a given substring with another ...
Definition: string.hxx:1356
SAL_WARN_UNUSED_RESULT OString replaceAll(OString const &from, OString const &to) const
Returns a new string resulting from replacing all occurrences of a given substring with another subst...
Definition: string.hxx:1380
SAL_DLLPUBLIC void rtl_string_newTrim(rtl_String **newStr, rtl_String *str) SAL_THROW_EXTERN_C()
Create a new string by removing white space from both ends of another string.
bool equalsIgnoreAsciiCase(const OString &str) const
Perform a ASCII lowercase comparison of two strings.
Definition: string.hxx:560
SAL_DLLPUBLIC void rtl_string_release(rtl_String *str) SAL_THROW_EXTERN_C()
Decrement the reference count of a string.
#define RTL_STR_MAX_VALUEOFDOUBLE
Definition: string.h:711
sal_uInt16 sal_Unicode
Definition: types.h:142
friend libreoffice_internal::CharPtrDetector< T, bool >::Type operator==(const OString &rStr1, const T &value)
Definition: string.hxx:947
sal_Int32 lastIndexOf(sal_Char ch) const
Returns the index within this string of the last occurrence of the specified character, searching backward starting at the end.
Definition: string.hxx:1100
unsigned char sal_Bool
Definition: types.h:39
sal_Int32 reverseCompareTo(const OString &str) const
Compares two strings in reverse order.
Definition: string.hxx:495
sal_Char toChar() const
Returns the first character from this string.
Definition: string.hxx:1508
SAL_WARN_UNUSED_RESULT OString copy(sal_Int32 beginIndex) const
Returns a new string that is a substring of this string.
Definition: string.hxx:1250
#define RTL_STR_MAX_VALUEOFBOOLEAN
Definition: string.h:585
__sal_NoAcquire
Definition: types.h:376
static OString number(unsigned long long ll, sal_Int16 radix=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: string.hxx:1646
Definition: stringutils.hxx:115
friend libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator!=(T &literal, const OString &rStr)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: string.hxx:1055
bool equalsL(const sal_Char *value, sal_Int32 length) const
Perform a comparison of two strings.
Definition: string.hxx:537
OString(rtl_String *str, __sal_NoAcquire)
New string from OString data without acquiring it.
Definition: string.hxx:157
bool equalsIgnoreAsciiCaseL(const sal_Char *asciiStr, sal_Int32 asciiStrLength) const
Perform a ASCII lowercase comparison of two strings.
Definition: string.hxx:644
libreoffice_internal::ConstCharArrayDetector< T, bool >::Type startsWithIgnoreAsciiCase(T &literal, OString *rest=NULL) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: string.hxx:850
SAL_DLLPUBLIC sal_Int32 rtl_str_lastIndexOfChar_WithLength(const sal_Char *str, sal_Int32 len, sal_Char ch) SAL_THROW_EXTERN_C()
Search for the last occurrence of a character within a string.
Definition: bootstrap.hxx:29
SAL_DLLPUBLIC sal_Int32 rtl_str_shortenedCompareIgnoreAsciiCase_WithLength(const sal_Char *first, sal_Int32 firstLen, const sal_Char *second, sal_Int32 secondLen, sal_Int32 shortenedLen) SAL_THROW_EXTERN_C()
Compare two strings with a maximum count of characters, ignoring the case of ASCII characters...
sal_Int32 indexOf(sal_Char 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: string.hxx:1085
SAL_WARN_UNUSED_RESULT OString replace(sal_Char oldChar, sal_Char newChar) const
Returns a new string resulting from replacing all occurrences of oldChar in this string with newChar...
Definition: string.hxx:1331
friend libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type operator==(const OString &rStr1, T &value)
Definition: string.hxx:953
SAL_WARN_UNUSED_RESULT OString replaceAt(sal_Int32 index, sal_Int32 count, const OString &newStr) const
Returns a new string resulting from replacing n = count characters from position index in this string...
Definition: string.hxx:1311
SAL_DLLPUBLIC void rtl_string_ensureCapacity(rtl_String **str, sal_Int32 size) SAL_THROW_EXTERN_C()
Ensure a string has enough space for a given number of characters.
SAL_DLLPUBLIC void rtl_string_newConcat(rtl_String **newStr, rtl_String *left, rtl_String *right) SAL_THROW_EXTERN_C()
Create a new string that is the concatenation of two other strings.
static OString number(long i, sal_Int16 radix=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: string.hxx:1625
bool toBoolean() const
Returns the Boolean value from this string.
Definition: string.hxx:1497
bool endsWith(OString const &str, OString *rest=NULL) const
Check whether this string ends with a given substring.
Definition: string.hxx:877
OString & operator+=(const OString &str)
Append a string to this string.
Definition: string.hxx:353
SAL_DLLPUBLIC sal_Int32 rtl_str_valueOfBoolean(sal_Char *str, sal_Bool b) SAL_THROW_EXTERN_C()
Create the string representation of a boolean.
sal_Int32 lastIndexOf(const OString &str) const
Returns the index within this string of the last occurrence of the specified substring, searching backward starting at the end.
Definition: string.hxx:1211
static OString boolean(bool b)
Returns the string representation of the boolean argument.
Definition: string.hxx:1715
SAL_DLLPUBLIC void rtl_string_newReplaceAll(rtl_String **newStr, rtl_String *str, char const *from, sal_Int32 fromLength, char const *to, sal_Int32 toLength) SAL_THROW_EXTERN_C()
Create a new string by replacing all occurrences of a given substring with another substring...
SAL_DLLPUBLIC void rtl_string_newFromStr(rtl_String **newStr, const sal_Char *value) SAL_THROW_EXTERN_C()
Allocate a new string that contains a copy of a character array.
definition of a no acquire enum for ctors
Definition: types.h:380
OString(const T &value, typename libreoffice_internal::CharPtrDetector< T, libreoffice_internal::Dummy >::Type=libreoffice_internal::Dummy())
New string from a character buffer array.
Definition: string.hxx:182
SAL_DLLPUBLIC sal_Int32 rtl_str_lastIndexOfStr_WithLength(const sal_Char *str, sal_Int32 len, const sal_Char *subStr, sal_Int32 subLen) SAL_THROW_EXTERN_C()
Search for the last occurrence of a substring within a string.
sal_Int32 toInt32(sal_Int16 radix=10) const
Returns the int32 value from this string.
Definition: string.hxx:1523
SAL_DLLPUBLIC void rtl_string_assign(rtl_String **str, rtl_String *rightValue) SAL_THROW_EXTERN_C()
Assign a new value to a string.
libreoffice_internal::CharPtrDetector< T, bool >::Type equalsIgnoreAsciiCase(const T &asciiStr) const
Perform a ASCII lowercase comparison of two strings.
Definition: string.hxx:592
bool operator()(const char *p1, const char *p2) const
Definition: string.hxx:1873
SAL_WARN_UNUSED_RESULT OString trim() const
Returns a new string resulting from removing white space from both ends of the string.
Definition: string.hxx:1433
sal_Int32 compareTo(const OString &rObj, sal_Int32 maxLength) const
Compares two strings with an maximum count of characters.
Definition: string.hxx:477
SAL_DLLPUBLIC sal_Bool rtl_str_toBoolean(const sal_Char *str) SAL_THROW_EXTERN_C()
Interpret a string as a boolean.
const sal_Char * getStr() const SAL_RETURNS_NONNULL
Returns a pointer to the characters of this string.
Definition: string.hxx:429
SAL_DLLPUBLIC void rtl_string_newReplaceStrAt(rtl_String **newStr, rtl_String *str, sal_Int32 idx, sal_Int32 count, rtl_String *subStr) SAL_THROW_EXTERN_C()
Create a new string by replacing a substring of another string.
OString()
New string containing no characters.
Definition: string.hxx:105
SAL_DLLPUBLIC void rtl_string_newFromStr_WithLength(rtl_String **newStr, const sal_Char *value, sal_Int32 len) SAL_THROW_EXTERN_C()
Allocate a new string that contains a copy of a character array.
#define SAL_WARN_UNUSED_RESULT
Use this as markup for functions and methods whose return value must be checked.
Definition: types.h:307
char sal_Char
A legacy synonym for char.
Definition: types.h:121
bool match(const OString &str, sal_Int32 fromIndex=0) const
Match against a substring appearing in this string.
Definition: string.hxx:668
SAL_DLLPUBLIC void rtl_string_newReplaceFirst(rtl_String **newStr, rtl_String *str, char const *from, sal_Int32 fromLength, char const *to, sal_Int32 toLength, sal_Int32 *index) SAL_THROW_EXTERN_C()
Create a new string by replacing the first occurrence of a given substring with another substring...
bool endsWithL(char const *str, sal_Int32 strLength) const
Check whether this string ends with a given substring.
Definition: string.hxx:928
sal_Int32 lastIndexOf(sal_Char 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: string.hxx:1117
OString(T &literal, typename libreoffice_internal::ConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type=libreoffice_internal::Dummy())
New string from a string literal.
Definition: string.hxx:206
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: string.hxx:1150
size_t operator()(const char *p) const
Definition: string.hxx:1880
static OString number(unsigned int i, sal_Int16 radix=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: string.hxx:1619
SAL_DLLPUBLIC sal_Int32 rtl_str_valueOfInt64(sal_Char *str, sal_Int64 l, sal_Int16 radix) SAL_THROW_EXTERN_C()
Create the string representation of a long integer.
OString & operator=(const OString &str)
Assign a new string.
Definition: string.hxx:300
bool isEmpty() const
Checks if a string is empty.
Definition: string.hxx:413
SAL_DLLPUBLIC void rtl_string_acquire(rtl_String *str) SAL_THROW_EXTERN_C()
Increment the reference count of a string.
friend libreoffice_internal::CharPtrDetector< T, bool >::Type operator!=(const OString &rStr1, const T &value)
Definition: string.hxx:1015
SAL_DLLPUBLIC sal_Int32 rtl_str_valueOfFloat(sal_Char *str, float f) SAL_THROW_EXTERN_C()
Create the string representation of a float.
sal_uInt32 toUInt32(sal_Int16 radix=10) const
Returns the uint32 value from this string.
Definition: string.hxx:1540
sal_Int32 indexOf(const OString &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: string.hxx:1137
SAL_DLLPUBLIC sal_Int32 rtl_str_valueOfDouble(sal_Char *str, double d) SAL_THROW_EXTERN_C()
Create the string representation of a double.
OString(rtl_String *str)
New string from OString data.
Definition: string.hxx:144
friend libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type operator!=(T &value, const OString &rStr2)
Definition: string.hxx:1033
bool startsWith(OString const &str, OString *rest=NULL) const
Check whether this string starts with a given substring.
Definition: string.hxx:788
float toFloat() const
Returns the float value from this string.
Definition: string.hxx:1585
friend libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type operator!=(const OString &rStr1, T &value)
Definition: string.hxx:1021
OString(sal_Char value)
New string from a single character.
Definition: string.hxx:167
SAL_DLLPUBLIC sal_Int32 rtl_str_toInt32(const sal_Char *str, sal_Int16 radix) SAL_THROW_EXTERN_C()
Interpret a string as an integer.
SAL_DLLPUBLIC rtl_String * rtl_string_alloc(sal_Int32 nLen) SAL_THROW_EXTERN_C()
Allocate a new string containing space for a given number of characters.
friend OString operator+(const OString &str1, const OString &str2)
Definition: string.hxx:1292
SAL_DLLPUBLIC void rtl_string_newToAsciiLowerCase(rtl_String **newStr, rtl_String *str) SAL_THROW_EXTERN_C()
Create a new string by converting all ASCII uppercase letters to lowercase within another string...
sal_Int32 getLength() const
Returns the length of this string.
Definition: string.hxx:403
static OString number(int i, sal_Int16 radix=10)
Returns the string representation of the integer argument.
Definition: string.hxx:1613
A helper to use OStrings with hash maps.
Definition: string.hxx:1855