LibreOffice
LibreOffice 6.3 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 #if defined LIBO_INTERNAL_ONLY
33 #include <string_view>
34 #endif
35 
36 #include "rtl/textenc.h"
37 #include "rtl/string.h"
38 #include "rtl/stringutils.hxx"
39 
40 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
41 #include "rtl/stringconcat.hxx"
42 #endif
43 
44 #ifdef RTL_STRING_UNITTEST
45 extern bool rtl_string_unittest_const_literal;
46 extern bool rtl_string_unittest_const_literal_function;
47 #endif
48 
49 // The unittest uses slightly different code to help check that the proper
50 // calls are made. The class is put into a different namespace to make
51 // sure the compiler generates a different (if generating also non-inline)
52 // copy of the function and does not merge them together. The class
53 // is "brought" into the proper rtl namespace by a typedef below.
54 #ifdef RTL_STRING_UNITTEST
55 #define rtl rtlunittest
56 #endif
57 
58 namespace rtl
59 {
60 
62 #ifdef RTL_STRING_UNITTEST
63 #undef rtl
64 // helper macro to make functions appear more readable
65 #define RTL_STRING_CONST_FUNCTION rtl_string_unittest_const_literal_function = true;
66 #else
67 #define RTL_STRING_CONST_FUNCTION
68 #endif
69 
71 /* ======================================================================= */
72 
97 class SAL_WARN_UNUSED SAL_DLLPUBLIC_RTTI OString
98 {
99 public:
101  rtl_String * pData;
103 
108  {
109  pData = NULL;
110  rtl_string_new( &pData );
111  }
112 
118  OString( const OString & str )
119  {
120  pData = str.pData;
121  rtl_string_acquire( pData );
122  }
123 
124 #ifndef _MSC_VER // TODO?
125 #if defined LIBO_INTERNAL_ONLY
126 
132  OString( OString && str )
133  {
134  pData = str.pData;
135  str.pData = nullptr;
136  rtl_string_new( &str.pData );
137  }
138 #endif
139 #endif
140 
146  OString( rtl_String * str )
147  {
148  pData = str;
149  rtl_string_acquire( pData );
150  }
151 
159  OString( rtl_String * str, __sal_NoAcquire )
160  {
161  pData = str;
162  }
163 
169  explicit OString( sal_Char value )
170  : pData (NULL)
171  {
172  rtl_string_newFromStr_WithLength( &pData, &value, 1 );
173  }
174 
183  template< typename T >
185  {
186  pData = NULL;
187  rtl_string_newFromStr( &pData, value );
188  }
189 
190  template< typename T >
192  {
193  pData = NULL;
194  rtl_string_newFromStr( &pData, value );
195  }
196 
207  template< typename T >
209  {
210  assert(
212  pData = NULL;
214  rtl_string_new(&pData);
215  } else {
217  &pData,
219  literal),
221  }
222 #ifdef RTL_STRING_UNITTEST
223  rtl_string_unittest_const_literal = true;
224 #endif
225  }
226 
235  OString( const sal_Char * value, sal_Int32 length )
236  {
237  pData = NULL;
238  rtl_string_newFromStr_WithLength( &pData, value, length );
239  }
240 
255  OString( const sal_Unicode * value, sal_Int32 length,
256  rtl_TextEncoding encoding,
257  sal_uInt32 convertFlags = OUSTRING_TO_OSTRING_CVTFLAGS )
258  {
259  pData = NULL;
260  rtl_uString2String( &pData, value, length, encoding, convertFlags );
261  if (pData == NULL) {
262  throw std::bad_alloc();
263  }
264  }
265 
266 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
267 
271  template< typename T1, typename T2 >
272  OString( OStringConcat< T1, T2 >&& c )
273  {
274  const sal_Int32 l = c.length();
275  pData = rtl_string_alloc( l );
276  if (l != 0)
277  {
278  char* end = c.addData( pData->buffer );
279  pData->length = l;
280  *end = '\0';
281  }
282  }
283 #endif
284 
285 #ifdef LIBO_INTERNAL_ONLY
286  OString(std::nullptr_t) = delete;
287 #endif
288 
293  {
294  rtl_string_release( pData );
295  }
296 
302  OString & operator=( const OString & str )
303  {
304  rtl_string_assign( &pData, str.pData );
305  return *this;
306  }
307 
308 #ifndef _MSC_VER // TODO?
309 #if defined LIBO_INTERNAL_ONLY
310 
316  OString & operator=( OString && str )
317  {
318  rtl_string_release( pData );
319  pData = str.pData;
320  str.pData = nullptr;
321  rtl_string_new( &str.pData );
322  return *this;
323  }
324 #endif
325 #endif
326 
332  template< typename T >
334  {
335  RTL_STRING_CONST_FUNCTION
336  assert(
339  rtl_string_new(&pData);
340  } else {
342  &pData,
344  literal),
346  }
347  return *this;
348  }
349 
355  OString & operator+=( const OString & str )
356 #if defined LIBO_INTERNAL_ONLY
357  &
358 #endif
359  {
360  rtl_string_newConcat( &pData, pData, str.pData );
361  return *this;
362  }
363 #if defined LIBO_INTERNAL_ONLY
364  void operator+=(OString const &) && = delete;
365 #endif
366 
367 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
368 
372  template< typename T1, typename T2 >
373  OString& operator+=( OStringConcat< T1, T2 >&& c ) & {
374  sal_Int32 l = c.length();
375  if( l == 0 )
376  return *this;
377  l += pData->length;
378  rtl_string_ensureCapacity( &pData, l );
379  char* end = c.addData( pData->buffer + pData->length );
380  *end = '\0';
381  pData->length = l;
382  return *this;
383  }
384  template<typename T1, typename T2> void operator +=(
385  OStringConcat<T1, T2> &&) && = delete;
386 #endif
387 
392  void clear()
393  {
394  rtl_string_new( &pData );
395  }
396 
405  sal_Int32 getLength() const { return pData->length; }
406 
415  bool isEmpty() const
416  {
417  return pData->length == 0;
418  }
419 
431  const sal_Char * getStr() const SAL_RETURNS_NONNULL { return pData->buffer; }
432 
442  sal_Char operator [](sal_Int32 index) const {
443  // silence spurious -Werror=strict-overflow warnings from GCC 4.8.2
444  assert(index >= 0 && static_cast<sal_uInt32>(index) < static_cast<sal_uInt32>(getLength()));
445  return getStr()[index];
446  }
447 
460  sal_Int32 compareTo( const OString & str ) const
461  {
462  return rtl_str_compare_WithLength( pData->buffer, pData->length,
463  str.pData->buffer, str.pData->length );
464  }
465 
479  sal_Int32 compareTo( const OString & rObj, sal_Int32 maxLength ) const
480  {
481  return rtl_str_shortenedCompare_WithLength( pData->buffer, pData->length,
482  rObj.pData->buffer, rObj.pData->length, maxLength );
483  }
484 
497  sal_Int32 reverseCompareTo( const OString & str ) const
498  {
499  return rtl_str_reverseCompare_WithLength( pData->buffer, pData->length,
500  str.pData->buffer, str.pData->length );
501  }
502 
514  bool equals( const OString & str ) const
515  {
516  if ( pData->length != str.pData->length )
517  return false;
518  if ( pData == str.pData )
519  return true;
520  return rtl_str_reverseCompare_WithLength( pData->buffer, pData->length,
521  str.pData->buffer, str.pData->length ) == 0;
522  }
523 
539  bool equalsL( const sal_Char* value, sal_Int32 length ) const
540  {
541  if ( pData->length != length )
542  return false;
543 
544  return rtl_str_reverseCompare_WithLength( pData->buffer, pData->length,
545  value, length ) == 0;
546  }
547 
562  bool equalsIgnoreAsciiCase( const OString & str ) const
563  {
564  if ( pData->length != str.pData->length )
565  return false;
566  if ( pData == str.pData )
567  return true;
568  return rtl_str_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
569  str.pData->buffer, str.pData->length ) == 0;
570  }
571 
593  template< typename T >
595  {
596  return rtl_str_compareIgnoreAsciiCase( pData->buffer, asciiStr ) == 0;
597  }
598 
599  template< typename T >
601  {
602  return rtl_str_compareIgnoreAsciiCase( pData->buffer, asciiStr ) == 0;
603  }
604 
610  template< typename T >
612  {
613  RTL_STRING_CONST_FUNCTION
614  assert(
616  return
617  (pData->length
620  pData->buffer, pData->length,
622  literal),
624  == 0);
625  }
626 
646  bool equalsIgnoreAsciiCaseL( const sal_Char * asciiStr, sal_Int32 asciiStrLength ) const
647  {
648  if ( pData->length != asciiStrLength )
649  return false;
650 
651  return rtl_str_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
652  asciiStr, asciiStrLength ) == 0;
653  }
654 
670  bool match( const OString & str, sal_Int32 fromIndex = 0 ) const
671  {
672  return rtl_str_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
673  str.pData->buffer, str.pData->length, str.pData->length ) == 0;
674  }
675 
681  template< typename T >
682  typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type match( T& literal, sal_Int32 fromIndex = 0 ) const
683  {
684  RTL_STRING_CONST_FUNCTION
685  assert(
687  return
689  pData->buffer + fromIndex, pData->length - fromIndex,
691  literal),
694  == 0;
695  }
696 
713  bool matchL(
714  char const * str, sal_Int32 strLength, sal_Int32 fromIndex = 0)
715  const
716  {
718  pData->buffer + fromIndex, pData->length - fromIndex,
719  str, strLength, strLength) == 0;
720  }
721 
722  // This overload is left undefined, to detect calls of matchL that
723  // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
724  // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
725  // platforms):
726 #if SAL_TYPES_SIZEOFLONG == 8
727  void matchL(char const *, sal_Int32, rtl_TextEncoding) const;
728 #endif
729 
748  bool matchIgnoreAsciiCase( const OString & str, sal_Int32 fromIndex = 0 ) const
749  {
750  return rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
751  str.pData->buffer, str.pData->length,
752  str.pData->length ) == 0;
753  }
754 
760  template< typename T >
761  typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type matchIgnoreAsciiCase( T& literal, sal_Int32 fromIndex = 0 ) const
762  {
763  RTL_STRING_CONST_FUNCTION
764  assert(
766  return
768  pData->buffer+fromIndex, pData->length-fromIndex,
770  literal),
773  == 0;
774  }
775 
790  bool startsWith(OString const & str, OString * rest = NULL) const {
791  bool b = match(str);
792  if (b && rest != NULL) {
793  *rest = copy(str.getLength());
794  }
795  return b;
796  }
797 
803  template< typename T >
805  T & literal, OString * rest = NULL) const
806  {
807  RTL_STRING_CONST_FUNCTION
808  bool b = match(literal, 0);
809  if (b && rest != NULL) {
810  *rest = copy(
812  }
813  return b;
814  }
815 
835  bool startsWithIgnoreAsciiCase(OString const & str, OString * rest = NULL)
836  const
837  {
838  bool b = matchIgnoreAsciiCase(str);
839  if (b && rest != NULL) {
840  *rest = copy(str.getLength());
841  }
842  return b;
843  }
844 
850  template< typename T >
852  startsWithIgnoreAsciiCase(T & literal, OString * rest = NULL) const
853  {
854  RTL_STRING_CONST_FUNCTION
855  assert(
857  bool b = matchIgnoreAsciiCase(literal);
858  if (b && rest != NULL) {
859  *rest = copy(
861  }
862  return b;
863  }
864 
879  bool endsWith(OString const & str, OString * rest = NULL) const {
880  bool b = str.getLength() <= getLength()
881  && match(str, getLength() - str.getLength());
882  if (b && rest != NULL) {
883  *rest = copy(0, getLength() - str.getLength());
884  }
885  return b;
886  }
887 
893  template< typename T >
895  T & literal, OString * rest = NULL) const
896  {
897  RTL_STRING_CONST_FUNCTION
898  assert(
900  bool b
902  <= sal_uInt32(getLength()))
903  && match(
905  literal),
906  (getLength()
908  if (b && rest != NULL) {
909  *rest = copy(
910  0,
911  (getLength()
913  }
914  return b;
915  }
916 
930  bool endsWithL(char const * str, sal_Int32 strLength) const {
931  return strLength <= getLength()
932  && matchL(str, strLength, getLength() - strLength);
933  }
934 
935  friend bool operator == ( const OString& rStr1, const OString& rStr2 )
936  { return rStr1.equals(rStr2); }
937  friend bool operator != ( const OString& rStr1, const OString& rStr2 )
938  { return !(operator == ( rStr1, rStr2 )); }
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  friend bool operator >= ( const OString& rStr1, const OString& rStr2 )
946  { return rStr1.compareTo( rStr2 ) >= 0; }
947 
948  template< typename T >
949  friend typename libreoffice_internal::CharPtrDetector< T, bool >::Type operator==( const OString& rStr1, const T& value )
950  {
951  return rStr1.compareTo( value ) == 0;
952  }
953 
954  template< typename T >
956  {
957  return rStr1.compareTo( value ) == 0;
958  }
959 
960  template< typename T >
961  friend typename libreoffice_internal::CharPtrDetector< T, bool >::Type operator==( const T& value, const OString& rStr2 )
962  {
963  return rStr2.compareTo( value ) == 0;
964  }
965 
966  template< typename T >
968  {
969  return rStr2.compareTo( value ) == 0;
970  }
971 
977  template< typename T >
979  {
980  RTL_STRING_CONST_FUNCTION
981  assert(
983  return
984  (rStr.getLength()
987  rStr.pData->buffer, rStr.pData->length,
989  literal),
991  == 0);
992  }
993 
999  template< typename T >
1001  {
1002  RTL_STRING_CONST_FUNCTION
1003  assert(
1005  return
1006  (rStr.getLength()
1009  rStr.pData->buffer, rStr.pData->length,
1011  literal),
1013  == 0);
1014  }
1015 
1016  template< typename T >
1017  friend typename libreoffice_internal::CharPtrDetector< T, bool >::Type operator!=( const OString& rStr1, const T& value )
1018  {
1019  return !(operator == ( rStr1, value ));
1020  }
1021 
1022  template< typename T >
1024  {
1025  return !(operator == ( rStr1, value ));
1026  }
1027 
1028  template< typename T >
1029  friend typename libreoffice_internal::CharPtrDetector< T, bool >::Type operator!=( const T& value, const OString& rStr2 )
1030  {
1031  return !(operator == ( value, rStr2 ));
1032  }
1033 
1034  template< typename T >
1036  {
1037  return !(operator == ( value, rStr2 ));
1038  }
1039 
1045  template< typename T >
1047  {
1048  return !( rStr == literal );
1049  }
1050 
1056  template< typename T >
1058  {
1059  return !( literal == rStr );
1060  }
1061 
1069  sal_Int32 hashCode() const
1070  {
1071  return rtl_str_hashCode_WithLength( pData->buffer, pData->length );
1072  }
1073 
1087  sal_Int32 indexOf( sal_Char ch, sal_Int32 fromIndex = 0 ) const
1088  {
1089  sal_Int32 ret = rtl_str_indexOfChar_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, ch );
1090  return (ret < 0 ? ret : ret+fromIndex);
1091  }
1092 
1102  sal_Int32 lastIndexOf( sal_Char ch ) const
1103  {
1104  return rtl_str_lastIndexOfChar_WithLength( pData->buffer, pData->length, ch );
1105  }
1106 
1119  sal_Int32 lastIndexOf( sal_Char ch, sal_Int32 fromIndex ) const
1120  {
1121  return rtl_str_lastIndexOfChar_WithLength( pData->buffer, fromIndex, ch );
1122  }
1123 
1139  sal_Int32 indexOf( const OString & str, sal_Int32 fromIndex = 0 ) const
1140  {
1141  sal_Int32 ret = rtl_str_indexOfStr_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
1142  str.pData->buffer, str.pData->length );
1143  return (ret < 0 ? ret : ret+fromIndex);
1144  }
1145 
1151  template< typename T >
1152  typename libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type indexOf( T& literal, sal_Int32 fromIndex = 0 ) const
1153  {
1154  RTL_STRING_CONST_FUNCTION
1155  assert(
1157  sal_Int32 n = rtl_str_indexOfStr_WithLength(
1158  pData->buffer + fromIndex, pData->length - fromIndex,
1161  return n < 0 ? n : n + fromIndex;
1162  }
1163 
1182  sal_Int32 indexOfL(char const * str, sal_Int32 len, sal_Int32 fromIndex = 0)
1183  const
1184  {
1185  sal_Int32 n = rtl_str_indexOfStr_WithLength(
1186  pData->buffer + fromIndex, pData->length - fromIndex, str, len);
1187  return n < 0 ? n : n + fromIndex;
1188  }
1189 
1190  // This overload is left undefined, to detect calls of indexOfL that
1191  // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
1192  // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
1193  // platforms):
1194 #if SAL_TYPES_SIZEOFLONG == 8
1195  void indexOfL(char const *, sal_Int32, rtl_TextEncoding) const;
1196 #endif
1197 
1213  sal_Int32 lastIndexOf( const OString & str ) const
1214  {
1215  return rtl_str_lastIndexOfStr_WithLength( pData->buffer, pData->length,
1216  str.pData->buffer, str.pData->length );
1217  }
1218 
1236  sal_Int32 lastIndexOf( const OString & str, sal_Int32 fromIndex ) const
1237  {
1238  return rtl_str_lastIndexOfStr_WithLength( pData->buffer, fromIndex,
1239  str.pData->buffer, str.pData->length );
1240  }
1241 
1252  SAL_WARN_UNUSED_RESULT OString copy( sal_Int32 beginIndex ) const
1253  {
1254  rtl_String *pNew = NULL;
1255  rtl_string_newFromSubString( &pNew, pData, beginIndex, getLength() - beginIndex );
1256  return OString( pNew, SAL_NO_ACQUIRE );
1257  }
1258 
1271  SAL_WARN_UNUSED_RESULT OString copy( sal_Int32 beginIndex, sal_Int32 count ) const
1272  {
1273  rtl_String *pNew = NULL;
1274  rtl_string_newFromSubString( &pNew, pData, beginIndex, count );
1275  return OString( pNew, SAL_NO_ACQUIRE );
1276  }
1277 
1287  {
1288  rtl_String* pNew = NULL;
1289  rtl_string_newConcat( &pNew, pData, str.pData );
1290  return OString( pNew, SAL_NO_ACQUIRE );
1291  }
1292 
1293 #ifndef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
1294  friend OString operator+( const OString & str1, const OString & str2 )
1295  {
1296  return str1.concat( str2 );
1297  }
1298 #endif
1299 
1313  SAL_WARN_UNUSED_RESULT OString replaceAt( sal_Int32 index, sal_Int32 count, const OString& newStr ) const
1314  {
1315  rtl_String* pNew = NULL;
1316  rtl_string_newReplaceStrAt( &pNew, pData, index, count, newStr.pData );
1317  return OString( pNew, SAL_NO_ACQUIRE );
1318  }
1319 
1334  {
1335  rtl_String* pNew = NULL;
1336  rtl_string_newReplace( &pNew, pData, oldChar, newChar );
1337  return OString( pNew, SAL_NO_ACQUIRE );
1338  }
1339 
1359  OString const & from, OString const & to, sal_Int32 * index = NULL) const
1360  {
1361  rtl_String * s = NULL;
1362  sal_Int32 i = 0;
1364  &s, pData, from.pData->buffer, from.pData->length,
1365  to.pData->buffer, to.pData->length, index == NULL ? &i : index);
1366  return OString(s, SAL_NO_ACQUIRE);
1367  }
1368 
1382  SAL_WARN_UNUSED_RESULT OString replaceAll(OString const & from, OString const & to) const {
1383  rtl_String * s = NULL;
1385  &s, pData, from.pData->buffer, from.pData->length,
1386  to.pData->buffer, to.pData->length);
1387  return OString(s, SAL_NO_ACQUIRE);
1388  }
1389 
1401  {
1402  rtl_String* pNew = NULL;
1403  rtl_string_newToAsciiLowerCase( &pNew, pData );
1404  return OString( pNew, SAL_NO_ACQUIRE );
1405  }
1406 
1418  {
1419  rtl_String* pNew = NULL;
1420  rtl_string_newToAsciiUpperCase( &pNew, pData );
1421  return OString( pNew, SAL_NO_ACQUIRE );
1422  }
1423 
1436  {
1437  rtl_String* pNew = NULL;
1438  rtl_string_newTrim( &pNew, pData );
1439  return OString( pNew, SAL_NO_ACQUIRE );
1440  }
1441 
1466  OString getToken( sal_Int32 token, sal_Char cTok, sal_Int32& index ) const
1467  {
1468  rtl_String * pNew = NULL;
1469  index = rtl_string_getToken( &pNew, pData, token, cTok, index );
1470  return OString( pNew, SAL_NO_ACQUIRE );
1471  }
1472 
1486  OString getToken(sal_Int32 count, char separator) const {
1487  sal_Int32 n = 0;
1488  return getToken(count, separator, n);
1489  }
1490 
1499  bool toBoolean() const
1500  {
1501  return rtl_str_toBoolean( pData->buffer );
1502  }
1503 
1511  {
1512  return pData->buffer[0];
1513  }
1514 
1525  sal_Int32 toInt32( sal_Int16 radix = 10 ) const
1526  {
1527  return rtl_str_toInt32( pData->buffer, radix );
1528  }
1529 
1542  sal_uInt32 toUInt32( sal_Int16 radix = 10 ) const
1543  {
1544  return rtl_str_toUInt32( pData->buffer, radix );
1545  }
1546 
1557  sal_Int64 toInt64( sal_Int16 radix = 10 ) const
1558  {
1559  return rtl_str_toInt64( pData->buffer, radix );
1560  }
1561 
1574  sal_uInt64 toUInt64( sal_Int16 radix = 10 ) const
1575  {
1576  return rtl_str_toUInt64( pData->buffer, radix );
1577  }
1578 
1587  float toFloat() const
1588  {
1589  return rtl_str_toFloat( pData->buffer );
1590  }
1591 
1600  double toDouble() const
1601  {
1602  return rtl_str_toDouble( pData->buffer );
1603  }
1604 
1615  static OString number( int i, sal_Int16 radix = 10 )
1616  {
1617  return number( static_cast< long long >( i ), radix );
1618  }
1621  static OString number( unsigned int i, sal_Int16 radix = 10 )
1622  {
1623  return number( static_cast< unsigned long long >( i ), radix );
1624  }
1627  static OString number( long i, sal_Int16 radix = 10 )
1628  {
1629  return number( static_cast< long long >( i ), radix );
1630  }
1633  static OString number( unsigned long i, sal_Int16 radix = 10 )
1634  {
1635  return number( static_cast< unsigned long long >( i ), radix );
1636  }
1639  static OString number( long long ll, sal_Int16 radix = 10 )
1640  {
1642  rtl_String* pNewData = NULL;
1643  rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfInt64( aBuf, ll, radix ) );
1644  return OString( pNewData, SAL_NO_ACQUIRE );
1645  }
1648  static OString number( unsigned long long ll, sal_Int16 radix = 10 )
1649  {
1651  rtl_String* pNewData = NULL;
1652  rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfUInt64( aBuf, ll, radix ) );
1653  return OString( pNewData, SAL_NO_ACQUIRE );
1654  }
1655 
1665  static OString number( float f )
1666  {
1668  rtl_String* pNewData = NULL;
1669  rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfFloat( aBuf, f ) );
1670  return OString( pNewData, SAL_NO_ACQUIRE );
1671  }
1672 
1682  static OString number( double d )
1683  {
1685  rtl_String* pNewData = NULL;
1686  rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfDouble( aBuf, d ) );
1687  return OString( pNewData, SAL_NO_ACQUIRE );
1688  }
1689 
1701  SAL_DEPRECATED("use boolean()") static OString valueOf( sal_Bool b )
1702  {
1703  return boolean(b);
1704  }
1705 
1717  static OString boolean( bool b )
1718  {
1720  rtl_String* pNewData = NULL;
1721  rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfBoolean( aBuf, b ) );
1722  return OString( pNewData, SAL_NO_ACQUIRE );
1723  }
1724 
1732  SAL_DEPRECATED("convert to OString or use directly") static OString valueOf( sal_Char c )
1733  {
1734  return OString( &c, 1 );
1735  }
1736 
1747  SAL_DEPRECATED("use number()") static OString valueOf( sal_Int32 i, sal_Int16 radix = 10 )
1748  {
1749  return number( i, radix );
1750  }
1751 
1762  SAL_DEPRECATED("use number()") static OString valueOf( sal_Int64 ll, sal_Int16 radix = 10 )
1763  {
1764  return number( ll, radix );
1765  }
1766 
1776  SAL_DEPRECATED("use number()") static OString valueOf( float f )
1777  {
1778  return number(f);
1779  }
1780 
1790  SAL_DEPRECATED("use number()") static OString valueOf( double d )
1791  {
1792  return number(d);
1793  }
1794 
1795 #if defined LIBO_INTERNAL_ONLY
1796  operator std::string_view() const { return {getStr(), sal_uInt32(getLength())}; }
1797 #endif
1798 };
1799 
1800 /* ======================================================================= */
1801 
1802 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
1803 
1811 struct SAL_WARN_UNUSED OStringLiteral
1812 {
1813  template< int N >
1814  explicit OStringLiteral( const char (&str)[ N ] ) : size( N - 1 ), data( str ) { assert( strlen( str ) == N - 1 ); }
1815 #if defined __cpp_char8_t
1816  template< int N >
1817  explicit OStringLiteral( const char8_t (&str)[ N ] ) : size( N - 1 ), data( reinterpret_cast<char const *>(str) ) { assert( strlen( data ) == N - 1 ); }
1818 #endif
1819  int size;
1820  const char* data;
1821 };
1822 
1826 template<>
1827 struct ToStringHelper< OString >
1828  {
1829  static int length( const OString& s ) { return s.getLength(); }
1830  static char* addData( char* buffer, const OString& s ) { return addDataHelper( buffer, s.getStr(), s.getLength()); }
1831  static const bool allowOStringConcat = true;
1832  static const bool allowOUStringConcat = false;
1833  };
1834 
1838 template<>
1839 struct ToStringHelper< OStringLiteral >
1840  {
1841  static int length( const OStringLiteral& str ) { return str.size; }
1842  static char* addData( char* buffer, const OStringLiteral& str ) { return addDataHelper( buffer, str.data, str.size ); }
1843  static const bool allowOStringConcat = true;
1844  static const bool allowOUStringConcat = false;
1845  };
1846 
1850 template< typename charT, typename traits, typename T1, typename T2 >
1851 inline std::basic_ostream<charT, traits> & operator <<(
1852  std::basic_ostream<charT, traits> & stream, OStringConcat< T1, T2 >&& concat)
1853 {
1854  return stream << OString( std::move(concat) );
1855 }
1856 #endif
1857 
1858 
1865 {
1875  size_t operator()( const OString& rString ) const
1876  { return static_cast<size_t>(rString.hashCode()); }
1877 };
1878 
1881 {
1882  bool operator()( const char* p1, const char* p2) const
1883  { return rtl_str_compare(p1, p2) == 0; }
1884 };
1885 
1888 {
1889  size_t operator()(const char* p) const
1890  { return rtl_str_hashCode(p); }
1891 };
1892 
1893 /* ======================================================================= */
1894 
1901 template< typename charT, typename traits > std::basic_ostream<charT, traits> &
1903  std::basic_ostream<charT, traits> & stream, OString const & rString)
1904 {
1905  return stream << rString.getStr();
1906  // best effort; potentially loses data due to embedded null characters
1907 }
1908 
1909 } /* Namespace */
1910 
1911 #ifdef RTL_STRING_UNITTEST
1912 namespace rtl
1913 {
1914 typedef rtlunittest::OString OString;
1915 }
1916 #undef RTL_STRING_CONST_FUNCTION
1917 #endif
1918 
1919 #if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST
1920 using ::rtl::OString;
1921 using ::rtl::OStringHash;
1922 using ::rtl::OStringLiteral;
1923 #endif
1924 
1926 
1931 #if defined LIBO_INTERNAL_ONLY
1932 namespace std {
1933 
1934 template<>
1935 struct hash<::rtl::OString>
1936 {
1937  std::size_t operator()(::rtl::OString const & s) const
1938  { return std::size_t(s.hashCode()); }
1939 };
1940 
1941 }
1942 
1943 #endif
1944 
1946 #endif // INCLUDED_RTL_STRING_HXX
1947 
1948 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define OUSTRING_TO_OSTRING_CVTFLAGS
Definition: string.h:1325
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.
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.
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,...
Definition: string.hxx:1182
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,...
Definition: string.hxx:1139
SAL_DLLPUBLIC sal_Int32 rtl_str_hashCode(const sal_Char *str) SAL_THROW_EXTERN_C()
Return a hash code for a string.
OString(rtl_String *str)
New string from OString data.
Definition: string.hxx:146
sal_uInt16 rtl_TextEncoding
The various supported text encodings.
Definition: textenc.h:33
float toFloat() const
Returns the float value from this string.
Definition: string.hxx:1587
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.
friend libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type operator!=(const OString &rStr1, T &value)
Definition: string.hxx:1023
OString(sal_Char value)
New string from a single character.
Definition: string.hxx:169
bool equals(const OString &str) const
Perform a comparison of two strings.
Definition: string.hxx:514
#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.
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:894
#define RTL_STR_MAX_VALUEOFUINT64
Definition: string.h:673
OString getToken(sal_Int32 token, sal_Char cTok, sal_Int32 &index) const
Returns a token in the string.
Definition: string.hxx:1466
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.
sal_Int32 getLength() const
Returns the length of this string.
Definition: string.hxx:405
bool operator()(const char *p1, const char *p2) const
Definition: string.hxx:1882
static OString number(int i, sal_Int16 radix=10)
Returns the string representation of the integer argument.
Definition: string.hxx:1615
#define RTL_STR_MAX_VALUEOFINT64
Definition: string.h:650
sal_uInt64 toUInt64(sal_Int16 radix=10) const
Returns the uint64 value from this string.
Definition: string.hxx:1574
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()
sal_Int32 compareTo(const OString &str) const
Compares two strings.
Definition: string.hxx:460
sal_Int32 lastIndexOf(const OString &str, sal_Int32 fromIndex) const
Returns the index within this string of the last occurrence of the specified substring,...
Definition: string.hxx:1236
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
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:804
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,...
Definition: string.hxx:1902
Definition: bootstrap.hxx:29
SAL_DLLPUBLIC sal_Int32 rtl_str_compare(const sal_Char *first, const sal_Char *second) SAL_THROW_EXTERN_C()
Compare two strings.
double toDouble() const
Returns the double value from this string.
Definition: string.hxx:1600
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:611
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.
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:1358
OString(const sal_Char *value, sal_Int32 length)
New string from a character buffer array.
Definition: string.hxx:235
bool equalsIgnoreAsciiCase(const OString &str) const
Perform a ASCII lowercase comparison of two strings.
Definition: string.hxx:562
sal_Int64 toInt64(sal_Int16 radix=10) const
Returns the int64 value from this string.
Definition: string.hxx:1557
sal_Int32 lastIndexOf(sal_Char ch) const
Returns the index within this string of the last occurrence of the specified character,...
Definition: string.hxx:1102
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.
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:333
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:1417
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.
SAL_WARN_UNUSED_RESULT OString copy(sal_Int32 beginIndex) const
Returns a new string that is a substring of this string.
Definition: string.hxx:1252
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:761
SAL_DLLPUBLIC void rtl_string_new(rtl_String **newStr) SAL_THROW_EXTERN_C()
Allocate a new string containing no characters.
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:1639
#define SAL_DEPRECATED(message)
Use as follows: SAL_DEPRECATED("Don't use, it's evil.") void doit(int nPara);.
Definition: types.h:465
#define SAL_WARN_UNUSED
Annotate classes where a compiler should warn if an instance is unused.
Definition: types.h:578
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:682
libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type equalsIgnoreAsciiCase(T &asciiStr) const
Definition: string.hxx:600
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:1057
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.
bool matchL(char const *str, sal_Int32 strLength, sal_Int32 fromIndex=0) const
Match against a substring appearing in this string.
Definition: string.hxx:713
friend libreoffice_internal::CharPtrDetector< T, bool >::Type operator!=(const T &value, const OString &rStr2)
Definition: string.hxx:1029
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.
sal_Int32 hashCode() const
Returns a hashcode for this string.
Definition: string.hxx:1069
friend libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type operator==(T &value, const OString &rStr2)
Definition: string.hxx:967
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.
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:748
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.
OString(const OString &str)
New string from OString.
Definition: string.hxx:118
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.
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,...
Definition: string.hxx:1087
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:1333
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:255
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.
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.
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:141
OString & operator+=(const OString &str)
Append a string to this string.
Definition: string.hxx:355
OString(T &value, typename libreoffice_internal::NonConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type=libreoffice_internal::Dummy())
Definition: string.hxx:191
unsigned char sal_Bool
Definition: types.h:38
sal_Int32 toInt32(sal_Int16 radix=10) const
Returns the int32 value from this string.
Definition: string.hxx:1525
#define RTL_STR_MAX_VALUEOFBOOLEAN
Definition: string.h:585
__sal_NoAcquire
Definition: types.h:370
libreoffice_internal::CharPtrDetector< T, bool >::Type equalsIgnoreAsciiCase(const T &asciiStr) const
Perform a ASCII lowercase comparison of two strings.
Definition: string.hxx:594
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:978
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:835
Hashing functor for classic c-strings (i.e., null-terminated char* strings).
Definition: string.hxx:1887
const sal_Char * getStr() const SAL_RETURNS_NONNULL
Returns a pointer to the characters of this string.
Definition: string.hxx:431
static OString number(double d)
Returns the string representation of the double argument.
Definition: string.hxx:1682
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.
bool operator>(const TTimeValue &rTimeA, const TTimeValue &rTimeB)
Definition: timer.hxx:100
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.
bool operator<(const TTimeValue &rTimeA, const TTimeValue &rTimeB)
Definition: timer.hxx:90
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.
bool endsWithL(char const *str, sal_Int32 strLength) const
Check whether this string ends with a given substring.
Definition: string.hxx:930
void clear()
Clears the string, i.e, makes a zero-character string.
Definition: string.hxx:392
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:1382
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:1152
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.
OString & operator=(const OString &str)
Assign a new string.
Definition: string.hxx:302
size_t operator()(const OString &rString) const
Compute a hash code for a string.
Definition: string.hxx:1875
friend libreoffice_internal::CharPtrDetector< T, bool >::Type operator==(const OString &rStr1, const T &value)
Definition: string.hxx:949
bool isEmpty() const
Checks if a string is empty.
Definition: string.hxx:415
SAL_DLLPUBLIC sal_Int32 rtl_str_valueOfBoolean(sal_Char *str, sal_Bool b) SAL_THROW_EXTERN_C()
Create the string representation of a boolean.
friend libreoffice_internal::CharPtrDetector< T, bool >::Type operator!=(const OString &rStr1, const T &value)
Definition: string.hxx:1017
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:374
sal_Int32 reverseCompareTo(const OString &str) const
Compares two strings in reverse order.
Definition: string.hxx:497
sal_Char toChar() const
Returns the first character from this string.
Definition: string.hxx:1510
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_uInt32 toUInt32(sal_Int16 radix=10) const
Returns the uint32 value from this string.
Definition: string.hxx:1542
SAL_DLLPUBLIC void rtl_string_assign(rtl_String **str, rtl_String *rightValue) SAL_THROW_EXTERN_C()
Assign a new value to a string.
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:1648
friend libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type operator!=(T &value, const OString &rStr2)
Definition: string.hxx:1035
bool startsWith(OString const &str, OString *rest=NULL) const
Check whether this string starts with a given substring.
Definition: string.hxx:790
bool equalsL(const sal_Char *value, sal_Int32 length) const
Perform a comparison of two strings.
Definition: string.hxx:539
OString(rtl_String *str, __sal_NoAcquire)
New string from OString data without acquiring it.
Definition: string.hxx:159
This String class provide base functionality for C++ like 8-Bit character array handling.
Definition: string.hxx:97
SAL_DLLPUBLIC sal_Bool rtl_str_toBoolean(const sal_Char *str) SAL_THROW_EXTERN_C()
Interpret a string as a boolean.
bool equalsIgnoreAsciiCaseL(const sal_Char *asciiStr, sal_Int32 asciiStrLength) const
Perform a ASCII lowercase comparison of two strings.
Definition: string.hxx:646
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:852
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.
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:302
char sal_Char
A legacy synonym for char.
Definition: types.h:120
friend libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type operator==(const OString &rStr1, T &value)
Definition: string.hxx:955
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:1313
friend OString operator+(const OString &str1, const OString &str2)
Definition: string.hxx:1294
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.
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:1627
bool toBoolean() const
Returns the Boolean value from this string.
Definition: string.hxx:1499
bool endsWith(OString const &str, OString *rest=NULL) const
Check whether this string ends with a given substring.
Definition: string.hxx:879
Definition: stringutils.hxx:105
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.
friend libreoffice_internal::CharPtrDetector< T, bool >::Type operator==(const T &value, const OString &rStr2)
Definition: string.hxx:961
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:1000
sal_Int32 lastIndexOf(const OString &str) const
Returns the index within this string of the last occurrence of the specified substring,...
Definition: string.hxx:1213
static OString boolean(bool b)
Returns the string representation of the boolean argument.
Definition: string.hxx:1717
SAL_DLLPUBLIC void rtl_string_acquire(rtl_String *str) SAL_THROW_EXTERN_C()
Increment the reference count of a string.
Equality functor for classic c-strings (i.e., null-terminated char* strings).
Definition: string.hxx:1880
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:1633
SAL_WARN_UNUSED_RESULT OString concat(const OString &str) const
Concatenates the specified string to the end of this string.
Definition: string.hxx:1286
SAL_DLLPUBLIC sal_Int32 rtl_str_valueOfFloat(sal_Char *str, float f) SAL_THROW_EXTERN_C()
Create the string representation of a float.
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:184
bool operator==(const TTimeValue &rTimeA, const TTimeValue &rTimeB)
Definition: timer.hxx:110
SAL_DLLPUBLIC sal_Int32 rtl_str_valueOfDouble(sal_Char *str, double d) SAL_THROW_EXTERN_C()
Create the string representation of a double.
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:1046
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:1435
sal_Int32 compareTo(const OString &rObj, sal_Int32 maxLength) const
Compares two strings with an maximum count of characters.
Definition: string.hxx:479
~OString()
Release the string data.
Definition: string.hxx:292
SAL_DLLPUBLIC sal_Int32 rtl_str_toInt32(const sal_Char *str, sal_Int16 radix) SAL_THROW_EXTERN_C()
Interpret a string as an integer.
OString()
New string containing no characters.
Definition: string.hxx:107
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:1400
Definition: stringutils.hxx:103
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.
bool match(const OString &str, sal_Int32 fromIndex=0) const
Match against a substring appearing in this string.
Definition: string.hxx:670
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.
A helper to use OStrings with hash maps.
Definition: string.hxx:1864
OString getToken(sal_Int32 count, char separator) const
Returns a token from the string.
Definition: string.hxx:1486
sal_Int32 lastIndexOf(sal_Char ch, sal_Int32 fromIndex) const
Returns the index within this string of the last occurrence of the specified character,...
Definition: string.hxx:1119
OString(T &literal, typename libreoffice_internal::ConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type=libreoffice_internal::Dummy())
New string from a string literal.
Definition: string.hxx:208
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:1271
size_t operator()(const char *p) const
Definition: string.hxx:1889
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:1621
static OString number(float f)
Returns the string representation of the float argument.
Definition: string.hxx:1665