AlterOffice
AlterOffice 3.4 SDK C/C++ API Reference
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
4 #ifndef INCLUDED_RTL_STRING_HXX
5 #define INCLUDED_RTL_STRING_HXX
6 
7 #include "sal/config.h"
8 
9 #include <cassert>
10 #include <cstddef>
11 #include <cstdlib>
12 #include <limits>
13 #include <new>
14 #include <ostream>
15 #include <utility>
16 #include <string.h>
17 #include <vector>
18 
19 #if defined LIBO_INTERNAL_ONLY
20 #include <string_view>
21 #include <type_traits>
22 #endif
23 
24 #include "rtl/textenc.h"
25 #include "rtl/string.h"
26 #include "rtl/stringutils.hxx"
27 
28 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
29 #include "config_global.h"
30 #include "rtl/stringconcat.hxx"
31 #endif
32 
33 #ifdef RTL_STRING_UNITTEST
34 extern bool rtl_string_unittest_const_literal;
35 extern bool rtl_string_unittest_const_literal_function;
36 #endif
37 
38 // The unittest uses slightly different code to help check that the proper
39 // calls are made. The class is put into a different namespace to make
40 // sure the compiler generates a different (if generating also non-inline)
41 // copy of the function and does not merge them together. The class
42 // is "brought" into the proper rtl namespace by a typedef below.
43 #ifdef RTL_STRING_UNITTEST
44 #define rtl rtlunittest
45 #endif
46 
47 namespace rtl
48 {
49 
51 #ifdef RTL_STRING_UNITTEST
52 #undef rtl
53 // helper macro to make functions appear more readable
54 #define RTL_STRING_CONST_FUNCTION rtl_string_unittest_const_literal_function = true;
55 #else
56 #define RTL_STRING_CONST_FUNCTION
57 #endif
58 
60 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
61 
68 template<std::size_t N> class SAL_WARN_UNUSED OStringLiteral {
69  static_assert(N != 0);
70  static_assert(N - 1 <= std::numeric_limits<sal_Int32>::max(), "literal too long");
71  friend class OString;
72  friend class OStringConstExpr;
73 
74 public:
75 #if HAVE_CPP_CONSTEVAL
76  consteval
77 #else
78  constexpr
79 #endif
80  OStringLiteral(char const (&literal)[N]) {
81  assertLayout();
82  assert(literal[N - 1] == '\0');
83  //TODO: Use C++20 constexpr std::copy_n (P0202R3):
84  for (std::size_t i = 0; i != N; ++i) {
85  more.buffer[i] = literal[i];
86  }
87  }
88 
89 #if defined __cpp_char8_t
90 #if HAVE_CPP_CONSTEVAL
91  consteval
92 #else
93  constexpr
94 #endif
95  explicit OStringLiteral(char8_t const (&literal)[N]) {
96  assertLayout();
97  assert(literal[N - 1] == '\0');
98  //TODO: Use C++20 constexpr std::copy_n (P0202R3):
99  for (std::size_t i = 0; i != N; ++i) {
100  more.buffer[i] = literal[i];
101  }
102  }
103 #endif
104 
105  constexpr sal_Int32 getLength() const { return more.length; }
106 
107  constexpr char const * getStr() const SAL_RETURNS_NONNULL { return more.buffer; }
108 
109  constexpr operator std::string_view() const { return {more.buffer, sal_uInt32(more.length)}; }
110 
111 private:
112  static constexpr void assertLayout() {
113  // These static_asserts verifying the layout compatibility with rtl_String cannot be class
114  // member declarations, as offsetof requires a complete type, so defer them to here:
115  static_assert(std::is_standard_layout_v<OStringLiteral>);
116  static_assert(offsetof(OStringLiteral, str.refCount) == offsetof(OStringLiteral, more.refCount));
117  static_assert(offsetof(OStringLiteral, str.length) == offsetof(OStringLiteral, more.length));
118  static_assert(offsetof(OStringLiteral, str.buffer) == offsetof(OStringLiteral, more.buffer));
119  }
120 
121  struct Data {
122  Data() = default;
123 
124  oslInterlockedCount refCount = 0x40000000; // SAL_STRING_STATIC_FLAG (sal/rtl/strimp.hxx)
125  sal_Int32 length = N - 1;
126  char buffer[N] = {}; //TODO: drop initialization for C++20 (P1331R2)
127  };
128 
129  union {
130  rtl_String str;
131  Data more = {};
132  };
133 };
134 
143 class OString;
144 class OStringConstExpr
145 {
146 public:
147  template<std::size_t N> constexpr OStringConstExpr(OStringLiteral<N> const & literal):
148  pData(const_cast<rtl_String *>(&literal.str)) {}
149 
150  // prevent mis-use
151  template<std::size_t N> constexpr OStringConstExpr(OStringLiteral<N> && literal)
152  = delete;
153 
154  // no destructor necessary because we know we are pointing at a compile-time
155  // constant OStringLiteral, which bypasses ref-counting.
156 
160  constexpr std::string_view asView() const { return std::string_view(pData->buffer, pData->length); }
161 
162  inline operator const OString&() const;
163 
164 private:
165  rtl_String* pData;
166 };
167 
168 #endif
169 
170 /* ======================================================================= */
171 
196 class SAL_WARN_UNUSED SAL_DLLPUBLIC_RTTI OString
197 {
198 public:
200  rtl_String * pData;
202 
207  {
208  pData = NULL;
209  rtl_string_new( &pData );
210  }
211 
217  OString( const OString & str )
218  {
219  pData = str.pData;
220  rtl_string_acquire( pData );
221  }
222 
223 #if defined LIBO_INTERNAL_ONLY
224 
230  OString( OString && str ) noexcept
231  {
232  pData = str.pData;
233  str.pData = nullptr;
234  rtl_string_new( &str.pData );
235  }
236 #endif
237 
243  OString( rtl_String * str )
244  {
245  pData = str;
246  rtl_string_acquire( pData );
247  }
248 
256  OString( rtl_String * str, __sal_NoAcquire )
257  {
258  pData = str;
259  }
260 
266  explicit OString( char value )
267  : pData (NULL)
268  {
269  rtl_string_newFromStr_WithLength( &pData, &value, 1 );
270  }
271 
272 #if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST_CONCAT
273  // Catch inadvertent conversions to the above ctor (e.g., from sal_[u]Int8, aka [un]signed
274  // char):
275  OString(int) = delete;
276 #endif
277 
286  template< typename T >
288  {
289  pData = NULL;
290  rtl_string_newFromStr( &pData, value );
291  }
292 
293  template< typename T >
295  {
296  pData = NULL;
297  rtl_string_newFromStr( &pData, value );
298  }
299 
300 #if __cplusplus > 202002L // C++23 P2266R3 "Simpler implicit move"
301  template< typename T >
302  OString( T&& value, typename libreoffice_internal::NonConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type = libreoffice_internal::Dummy() )
303  {
304  pData = NULL;
305  rtl_string_newFromStr( &pData, value );
306  }
307 #endif
308 
319  template< typename T >
320  OString( T& literal, typename libreoffice_internal::ConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type = libreoffice_internal::Dummy() )
321  {
322  assert(
323  libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
324  pData = NULL;
326  rtl_string_new(&pData);
327  } else {
329  &pData,
331  literal),
333  }
334 #ifdef RTL_STRING_UNITTEST
335  rtl_string_unittest_const_literal = true;
336 #endif
337  }
338 
347  OString( const char * value, sal_Int32 length )
348  {
349  pData = NULL;
350  rtl_string_newFromStr_WithLength( &pData, value, length );
351  }
352 
353 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
354 
360  template<std::size_t N> constexpr OString(OStringLiteral<N> const & literal):
361  pData(const_cast<rtl_String *>(&literal.str)) {}
362  template<std::size_t N> OString(OStringLiteral<N> &&) = delete;
364 #endif
365 
366 #if defined LIBO_INTERNAL_ONLY
367  explicit OString(std::string_view sv) {
368  if (sv.size() > sal_uInt32(std::numeric_limits<sal_Int32>::max())) {
369  throw std::bad_alloc();
370  }
371  pData = nullptr;
372  rtl_string_newFromStr_WithLength(&pData, sv.data(), sv.size());
373  }
374 #endif
375 
390  OString( const sal_Unicode * value, sal_Int32 length,
391  rtl_TextEncoding encoding,
392  sal_uInt32 convertFlags = OUSTRING_TO_OSTRING_CVTFLAGS )
393  {
394  pData = NULL;
395  rtl_uString2String( &pData, value, length, encoding, convertFlags );
396  if (pData == NULL) {
397  throw std::bad_alloc();
398  }
399  }
400 
401 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
402 
406  template< typename T1, typename T2 >
407  OString( OStringConcat< T1, T2 >&& c )
408  {
409  const sal_Int32 l = c.length();
410  pData = rtl_string_alloc( l );
411  if (l != 0)
412  {
413  char* end = c.addData( pData->buffer );
414  pData->length = l;
415  *end = '\0';
416  }
417  }
418 
423  template< typename T, std::size_t N >
424  OString( StringNumberBase< char, T, N >&& n )
425  : OString( n.buf, n.length )
426  {}
427 #endif
428 
429 #ifdef LIBO_INTERNAL_ONLY
430  OString(std::nullptr_t) = delete;
431 #endif
432 
437  {
438  rtl_string_release( pData );
439  }
440 
441 #if defined LIBO_INTERNAL_ONLY
442 
453  static OString const & unacquired( rtl_String * const * ppHandle )
454  { return * reinterpret_cast< OString const * >( ppHandle ); }
455 #endif
456 
462  OString & operator=( const OString & str )
463  {
464  rtl_string_assign( &pData, str.pData );
465  return *this;
466  }
467 
468 #if defined LIBO_INTERNAL_ONLY
469 
475  OString & operator=( OString && str ) noexcept
476  {
477  rtl_string_release( pData );
478  pData = str.pData;
479  str.pData = nullptr;
480  rtl_string_new( &str.pData );
481  return *this;
482  }
483 #endif
484 
490  template< typename T >
492  {
493  RTL_STRING_CONST_FUNCTION
494  assert(
497  rtl_string_new(&pData);
498  } else {
500  &pData,
502  literal),
504  }
505  return *this;
506  }
507 
513  OString & operator+=( const OString & str )
514 #if defined LIBO_INTERNAL_ONLY
515  &
516 #endif
517  {
518  rtl_string_newConcat( &pData, pData, str.pData );
519  return *this;
520  }
521 #if defined LIBO_INTERNAL_ONLY
522  void operator+=(OString const &) && = delete;
523 #endif
524 
525 #if defined LIBO_INTERNAL_ONLY
527  operator +=(T const & value) & { return operator +=(std::string_view(value)); }
528  template<typename T> typename libreoffice_internal::CharPtrDetector<T, OString &>::Type
529  operator +=(T const &) && = delete;
530 
531  template<typename T>
532  typename libreoffice_internal::NonConstCharArrayDetector<T, OString &>::Type
533  operator +=(T & value) & { return operator +=(std::string_view(value)); }
534  template<typename T>
535  typename libreoffice_internal::NonConstCharArrayDetector<T, OString &>::Type operator +=(T &) &&
536  = delete;
537 
538  template<typename T> typename libreoffice_internal::ConstCharArrayDetector<T, OString &>::Type
539  operator +=(T & literal) & {
540  assert(libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
541  return operator +=(
542  std::string_view(
543  libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
544  libreoffice_internal::ConstCharArrayDetector<T>::length));
545  }
546  template<typename T> typename libreoffice_internal::ConstCharArrayDetector<T, OString &>::Type
547  operator +=(T &) && = delete;
548 
549  template<std::size_t N> OString & operator +=(OStringLiteral<N> const & literal) &
550  { return operator +=(std::string_view(literal.getStr(), literal.getLength())); }
551  template<std::size_t N> void operator +=(OStringLiteral<N> const &) && = delete;
552 
553  OString & operator +=(std::string_view sv) & {
554  if (sv.empty()) {
555  return *this;
556  }
557  if (sv.size() > sal_uInt32(std::numeric_limits<sal_Int32>::max() - pData->length)) {
558  throw std::bad_alloc();
559  }
560  auto const l = pData->length + sv.size();
561  rtl_string_ensureCapacity(&pData, l);
562  *addDataHelper(pData->buffer + pData->length, sv.data(), sv.size()) = '\0';
563  pData->length = l;
564  return *this;
565  }
566  void operator +=(std::string_view) && = delete;
567 #endif
568 
569 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
570 
574  template< typename T1, typename T2 >
575  OString& operator+=( OStringConcat< T1, T2 >&& c ) & {
576  sal_Int32 l = c.length();
577  if( l == 0 )
578  return *this;
579  l += pData->length;
580  rtl_string_ensureCapacity( &pData, l );
581  char* end = c.addData( pData->buffer + pData->length );
582  *end = '\0';
583  pData->length = l;
584  return *this;
585  }
586  template<typename T1, typename T2> void operator +=(
587  OStringConcat<T1, T2> &&) && = delete;
588 
593  template< typename T, std::size_t N >
594  OString& operator+=( StringNumberBase< char, T, N >&& n ) & {
595  return operator +=(std::string_view(n.buf, n.length));
596  }
597  template<typename T, std::size_t N> void operator +=(
598  StringNumberBase<char, T, N> &&) && = delete;
599 #endif
600 
605  void clear()
606  {
607  rtl_string_new( &pData );
608  }
609 
618  sal_Int32 getLength() const { return pData->length; }
619 
628  bool isEmpty() const
629  {
630  return pData->length == 0;
631  }
632 
644  const char * getStr() const SAL_RETURNS_NONNULL { return pData->buffer; }
645 
655  char operator [](sal_Int32 index) const {
656  // silence spurious -Werror=strict-overflow warnings from GCC 4.8.2
657  assert(index >= 0 && static_cast<sal_uInt32>(index) < static_cast<sal_uInt32>(getLength()));
658  return getStr()[index];
659  }
660 
673  sal_Int32 compareTo( const OString & str ) const
674  {
675  return rtl_str_compare_WithLength( pData->buffer, pData->length,
676  str.pData->buffer, str.pData->length );
677  }
678 
692  sal_Int32 compareTo( const OString & rObj, sal_Int32 maxLength ) const
693  {
694  return rtl_str_shortenedCompare_WithLength( pData->buffer, pData->length,
695  rObj.pData->buffer, rObj.pData->length, maxLength );
696  }
697 
710  sal_Int32 reverseCompareTo( const OString & str ) const
711  {
712  return rtl_str_reverseCompare_WithLength( pData->buffer, pData->length,
713  str.pData->buffer, str.pData->length );
714  }
715 
727  bool equals( const OString & str ) const
728  {
729  if ( pData->length != str.pData->length )
730  return false;
731  if ( pData == str.pData )
732  return true;
733  return rtl_str_reverseCompare_WithLength( pData->buffer, pData->length,
734  str.pData->buffer, str.pData->length ) == 0;
735  }
736 
751  bool equalsL( const char* value, sal_Int32 length ) const
752  {
753  if ( pData->length != length )
754  return false;
755 
756  return rtl_str_reverseCompare_WithLength( pData->buffer, pData->length,
757  value, length ) == 0;
758  }
759 
774 #if defined LIBO_INTERNAL_ONLY
775  bool equalsIgnoreAsciiCase( std::string_view str ) const
776  {
777  if ( sal_uInt32(pData->length) != str.size() )
778  return false;
779  if ( pData->buffer == str.data() )
780  return true;
781  return rtl_str_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
782  str.data(), str.size() ) == 0;
783  }
784 #else
785  bool equalsIgnoreAsciiCase( const OString & str ) const
786  {
787  if ( pData->length != str.pData->length )
788  return false;
789  if ( pData == str.pData )
790  return true;
791  return rtl_str_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
792  str.pData->buffer, str.pData->length ) == 0;
793  }
794 #endif
795 
817  template< typename T >
819  {
820  return rtl_str_compareIgnoreAsciiCase( pData->buffer, asciiStr ) == 0;
821  }
822 
823  template< typename T >
825  {
826  return rtl_str_compareIgnoreAsciiCase( pData->buffer, asciiStr ) == 0;
827  }
828 
834  template< typename T >
836  {
837  RTL_STRING_CONST_FUNCTION
838  assert(
840  return
841  (pData->length
844  pData->buffer, pData->length,
846  literal),
848  == 0);
849  }
850 
870  bool equalsIgnoreAsciiCaseL( const char * asciiStr, sal_Int32 asciiStrLength ) const
871  {
872  if ( pData->length != asciiStrLength )
873  return false;
874 
875  return rtl_str_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
876  asciiStr, asciiStrLength ) == 0;
877  }
878 
894 #if defined LIBO_INTERNAL_ONLY
895  bool match( std::string_view str, sal_Int32 fromIndex = 0 ) const
896  {
897  return rtl_str_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
898  str.data(), str.size(), str.size() ) == 0;
899  }
900 #else
901  bool match( const OString & str, sal_Int32 fromIndex = 0 ) const
902  {
903  return rtl_str_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
904  str.pData->buffer, str.pData->length, str.pData->length ) == 0;
905  }
906 #endif
907 
913  template< typename T >
914  typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type match( T& literal, sal_Int32 fromIndex = 0 ) const
915  {
916  RTL_STRING_CONST_FUNCTION
917  assert(
919  return
921  pData->buffer + fromIndex, pData->length - fromIndex,
923  literal),
926  == 0;
927  }
928 
945  bool matchL(
946  char const * str, sal_Int32 strLength, sal_Int32 fromIndex = 0)
947  const
948  {
950  pData->buffer + fromIndex, pData->length - fromIndex,
951  str, strLength, strLength) == 0;
952  }
953 
954  // This overload is left undefined, to detect calls of matchL that
955  // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
956  // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
957  // platforms):
958 #if SAL_TYPES_SIZEOFLONG == 8
959  void matchL(char const *, sal_Int32, rtl_TextEncoding) const;
960 #endif
961 
980 #if defined LIBO_INTERNAL_ONLY
981  bool matchIgnoreAsciiCase( std::string_view str, sal_Int32 fromIndex = 0 ) const
982  {
983  return rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
984  str.data(), str.size(),
985  str.size() ) == 0;
986  }
987 #else
988  bool matchIgnoreAsciiCase( const OString & str, sal_Int32 fromIndex = 0 ) const
989  {
990  return rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
991  str.pData->buffer, str.pData->length,
992  str.pData->length ) == 0;
993  }
994 #endif
995 
1000  template< typename T >
1001  typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type matchIgnoreAsciiCase( T& literal, sal_Int32 fromIndex = 0 ) const
1002  {
1003  RTL_STRING_CONST_FUNCTION
1004  assert(
1006  return
1008  pData->buffer+fromIndex, pData->length-fromIndex,
1010  literal),
1013  == 0;
1014  }
1015 
1030 #if defined LIBO_INTERNAL_ONLY
1031  bool startsWith(std::string_view str, OString * rest = NULL) const {
1032  bool b = match(str);
1033  if (b && rest != NULL) {
1034  *rest = copy(str.size());
1035  }
1036  return b;
1037  }
1038 #else
1039  bool startsWith(OString const & str, OString * rest = NULL) const {
1040  bool b = match(str);
1041  if (b && rest != NULL) {
1042  *rest = copy(str.getLength());
1043  }
1044  return b;
1045  }
1046 #endif
1047 
1053  template< typename T >
1055  T & literal, OString * rest = NULL) const
1056  {
1057  RTL_STRING_CONST_FUNCTION
1058  bool b = match(literal, 0);
1059  if (b && rest != NULL) {
1060  *rest = copy(
1062  }
1063  return b;
1064  }
1065 
1085 #if defined LIBO_INTERNAL_ONLY
1086  bool startsWithIgnoreAsciiCase(std::string_view str, OString * rest = NULL)
1087  const
1088  {
1089  bool b = matchIgnoreAsciiCase(str);
1090  if (b && rest != NULL) {
1091  *rest = copy(str.size());
1092  }
1093  return b;
1094  }
1095 #else
1096  bool startsWithIgnoreAsciiCase(OString const & str, OString * rest = NULL)
1097  const
1098  {
1099  bool b = matchIgnoreAsciiCase(str);
1100  if (b && rest != NULL) {
1101  *rest = copy(str.getLength());
1102  }
1103  return b;
1104  }
1105 #endif
1106 
1112  template< typename T >
1114  startsWithIgnoreAsciiCase(T & literal, OString * rest = NULL) const
1115  {
1116  RTL_STRING_CONST_FUNCTION
1117  assert(
1119  bool b = matchIgnoreAsciiCase(literal);
1120  if (b && rest != NULL) {
1121  *rest = copy(
1123  }
1124  return b;
1125  }
1126 
1141 #if defined LIBO_INTERNAL_ONLY
1142  bool endsWith(std::string_view str, OString * rest = NULL) const {
1143  bool b = str.size() <= sal_uInt32(getLength())
1144  && match(str, getLength() - str.size());
1145  if (b && rest != NULL) {
1146  *rest = copy(0, getLength() - str.size());
1147  }
1148  return b;
1149  }
1150 #else
1151  bool endsWith(OString const & str, OString * rest = NULL) const {
1152  bool b = str.getLength() <= getLength()
1153  && match(str, getLength() - str.getLength());
1154  if (b && rest != NULL) {
1155  *rest = copy(0, getLength() - str.getLength());
1156  }
1157  return b;
1158  }
1159 #endif
1160 
1166  template< typename T >
1168  T & literal, OString * rest = NULL) const
1169  {
1170  RTL_STRING_CONST_FUNCTION
1171  assert(
1173  bool b
1175  <= sal_uInt32(getLength()))
1176  && match(
1178  literal),
1179  (getLength()
1181  if (b && rest != NULL) {
1182  *rest = copy(
1183  0,
1184  (getLength()
1186  }
1187  return b;
1188  }
1189 
1203  bool endsWithL(char const * str, sal_Int32 strLength) const {
1204  return strLength <= getLength()
1205  && matchL(str, strLength, getLength() - strLength);
1206  }
1207 
1208  friend bool operator == ( const OString& rStr1, const OString& rStr2 )
1209  { return rStr1.equals(rStr2); }
1210  friend bool operator != ( const OString& rStr1, const OString& rStr2 )
1211  { return !(operator == ( rStr1, rStr2 )); }
1212  friend bool operator < ( const OString& rStr1, const OString& rStr2 )
1213  { return rStr1.compareTo( rStr2 ) < 0; }
1214  friend bool operator > ( const OString& rStr1, const OString& rStr2 )
1215  { return rStr1.compareTo( rStr2 ) > 0; }
1216  friend bool operator <= ( const OString& rStr1, const OString& rStr2 )
1217  { return rStr1.compareTo( rStr2 ) <= 0; }
1218  friend bool operator >= ( const OString& rStr1, const OString& rStr2 )
1219  { return rStr1.compareTo( rStr2 ) >= 0; }
1220 
1221  template< typename T >
1222  friend typename libreoffice_internal::CharPtrDetector< T, bool >::Type operator==( const OString& rStr1, const T& value )
1223  {
1224  return
1226  rStr1.getStr(), rStr1.getLength(), value, rtl_str_getLength(value))
1227  == 0;
1228  }
1229 
1230  template< typename T >
1232  {
1233  return
1235  rStr1.getStr(), rStr1.getLength(), value, rtl_str_getLength(value))
1236  == 0;
1237  }
1238 
1239  template< typename T >
1240  friend typename libreoffice_internal::CharPtrDetector< T, bool >::Type operator==( const T& value, const OString& rStr2 )
1241  {
1242  return
1244  value, rtl_str_getLength(value), rStr2.getStr(), rStr2.getLength())
1245  == 0;
1246  }
1247 
1248  template< typename T >
1250  {
1251  return
1253  value, rtl_str_getLength(value), rStr2.getStr(), rStr2.getLength())
1254  == 0;
1255  }
1256 
1262  template< typename T >
1264  {
1265  RTL_STRING_CONST_FUNCTION
1266  assert(
1268  return
1269  (rStr.getLength()
1272  rStr.pData->buffer, rStr.pData->length,
1274  literal),
1276  == 0);
1277  }
1278 
1284  template< typename T >
1286  {
1287  RTL_STRING_CONST_FUNCTION
1288  assert(
1290  return
1291  (rStr.getLength()
1294  rStr.pData->buffer, rStr.pData->length,
1296  literal),
1298  == 0);
1299  }
1300 
1301  template< typename T >
1302  friend typename libreoffice_internal::CharPtrDetector< T, bool >::Type operator!=( const OString& rStr1, const T& value )
1303  {
1304  return !(operator == ( rStr1, value ));
1305  }
1306 
1307  template< typename T >
1309  {
1310  return !(operator == ( rStr1, value ));
1311  }
1312 
1313  template< typename T >
1314  friend typename libreoffice_internal::CharPtrDetector< T, bool >::Type operator!=( const T& value, const OString& rStr2 )
1315  {
1316  return !(operator == ( value, rStr2 ));
1317  }
1318 
1319  template< typename T >
1321  {
1322  return !(operator == ( value, rStr2 ));
1323  }
1324 
1330  template< typename T >
1332  {
1333  return !( rStr == literal );
1334  }
1335 
1341  template< typename T >
1343  {
1344  return !( literal == rStr );
1345  }
1346 
1354  sal_Int32 hashCode() const
1355  {
1356  return rtl_str_hashCode_WithLength( pData->buffer, pData->length );
1357  }
1358 
1372  sal_Int32 indexOf( char ch, sal_Int32 fromIndex = 0 ) const
1373  {
1374  sal_Int32 ret = rtl_str_indexOfChar_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, ch );
1375  return (ret < 0 ? ret : ret+fromIndex);
1376  }
1377 
1387  sal_Int32 lastIndexOf( char ch ) const
1388  {
1389  return rtl_str_lastIndexOfChar_WithLength( pData->buffer, pData->length, ch );
1390  }
1391 
1404  sal_Int32 lastIndexOf( char ch, sal_Int32 fromIndex ) const
1405  {
1406  return rtl_str_lastIndexOfChar_WithLength( pData->buffer, fromIndex, ch );
1407  }
1408 
1424 #if defined LIBO_INTERNAL_ONLY
1425  sal_Int32 indexOf( std::string_view str, sal_Int32 fromIndex = 0 ) const
1426  {
1427  sal_Int32 ret = rtl_str_indexOfStr_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
1428  str.data(), str.size() );
1429  return (ret < 0 ? ret : ret+fromIndex);
1430  }
1431 #else
1432  sal_Int32 indexOf( const OString & str, sal_Int32 fromIndex = 0 ) const
1433  {
1434  sal_Int32 ret = rtl_str_indexOfStr_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
1435  str.pData->buffer, str.pData->length );
1436  return (ret < 0 ? ret : ret+fromIndex);
1437  }
1438 #endif
1439 
1444  template< typename T >
1445  typename libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type indexOf( T& literal, sal_Int32 fromIndex = 0 ) const
1446  {
1447  RTL_STRING_CONST_FUNCTION
1448  assert(
1450  sal_Int32 n = rtl_str_indexOfStr_WithLength(
1451  pData->buffer + fromIndex, pData->length - fromIndex,
1454  return n < 0 ? n : n + fromIndex;
1455  }
1456 
1475  sal_Int32 indexOfL(char const * str, sal_Int32 len, sal_Int32 fromIndex = 0)
1476  const
1477  {
1478  sal_Int32 n = rtl_str_indexOfStr_WithLength(
1479  pData->buffer + fromIndex, pData->length - fromIndex, str, len);
1480  return n < 0 ? n : n + fromIndex;
1481  }
1482 
1483  // This overload is left undefined, to detect calls of indexOfL that
1484  // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
1485  // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
1486  // platforms):
1487 #if SAL_TYPES_SIZEOFLONG == 8
1488  void indexOfL(char const *, sal_Int32, rtl_TextEncoding) const;
1489 #endif
1490 
1506 #if defined LIBO_INTERNAL_ONLY
1507  sal_Int32 lastIndexOf( std::string_view str ) const
1508  {
1509  return rtl_str_lastIndexOfStr_WithLength( pData->buffer, pData->length,
1510  str.data(), str.size() );
1511  }
1512 #else
1513  sal_Int32 lastIndexOf( const OString & str ) const
1514  {
1515  return rtl_str_lastIndexOfStr_WithLength( pData->buffer, pData->length,
1516  str.pData->buffer, str.pData->length );
1517  }
1518 #endif
1519 
1537 #if defined LIBO_INTERNAL_ONLY
1538  sal_Int32 lastIndexOf( std::string_view str, sal_Int32 fromIndex ) const
1539  {
1540  return rtl_str_lastIndexOfStr_WithLength( pData->buffer, fromIndex,
1541  str.data(), str.size() );
1542  }
1543 #else
1544  sal_Int32 lastIndexOf( const OString & str, sal_Int32 fromIndex ) const
1545  {
1546  return rtl_str_lastIndexOfStr_WithLength( pData->buffer, fromIndex,
1547  str.pData->buffer, str.pData->length );
1548  }
1549 #endif
1550 
1561  SAL_WARN_UNUSED_RESULT OString copy( sal_Int32 beginIndex ) const
1562  {
1563  return copy(beginIndex, getLength() - beginIndex);
1564  }
1565 
1578  SAL_WARN_UNUSED_RESULT OString copy( sal_Int32 beginIndex, sal_Int32 count ) const
1579  {
1580  rtl_String *pNew = NULL;
1581  rtl_string_newFromSubString( &pNew, pData, beginIndex, count );
1582  return OString( pNew, SAL_NO_ACQUIRE );
1583  }
1584 
1585 #if defined LIBO_INTERNAL_ONLY
1586 
1596  SAL_WARN_UNUSED_RESULT std::string_view subView( sal_Int32 beginIndex ) const
1597  {
1598  assert(beginIndex >= 0);
1599  assert(beginIndex <= getLength());
1600  return subView(beginIndex, getLength() - beginIndex);
1601  }
1602 
1615  SAL_WARN_UNUSED_RESULT std::string_view subView( sal_Int32 beginIndex, sal_Int32 count ) const
1616  {
1617  assert(beginIndex >= 0);
1618  assert(count >= 0);
1619  assert(beginIndex <= getLength());
1620  assert(count <= getLength() - beginIndex);
1621  return std::string_view(*this).substr(beginIndex, count);
1622  }
1623 
1630  SAL_WARN_UNUSED_RESULT std::vector<std::string_view> split(std::string_view separator = " ") const
1631  {
1632  std::vector<std::string_view> output;
1633  std::string_view stringView(*this);
1634  std::size_t index;
1635 
1636  do {
1637  index = stringView.find(separator);
1638  if (index != stringView.npos)
1639  {
1640  if (index != 0)
1641  output.push_back(stringView.substr(0, index));
1642 
1643  if (index != stringView.length() - separator.length())
1644  stringView = stringView.substr(index + separator.length(),
1645  stringView.length() - index - separator.length());
1646  else
1647  index = stringView.npos;
1648  }
1649  else
1650  output.push_back(stringView);
1651  } while (index != stringView.npos);
1652 
1653  return output;
1654  }
1655 #endif
1656 
1657 #ifndef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
1658 
1667  {
1668  rtl_String* pNew = NULL;
1669  rtl_string_newConcat( &pNew, pData, str.pData );
1670  return OString( pNew, SAL_NO_ACQUIRE );
1671  }
1672 #endif
1673 
1674 #ifndef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
1675  friend OString operator+( const OString & str1, const OString & str2 )
1676  {
1677  return str1.concat( str2 );
1678  }
1679 #endif
1680 
1681 // hide this from internal code to avoid ambiguous lookup error
1682 #ifndef LIBO_INTERNAL_ONLY
1683 
1696  SAL_WARN_UNUSED_RESULT OString replaceAt( sal_Int32 index, sal_Int32 count, const OString& newStr ) const
1697  {
1698  rtl_String* pNew = NULL;
1699  rtl_string_newReplaceStrAt( &pNew, pData, index, count, newStr.pData );
1700  return OString( pNew, SAL_NO_ACQUIRE );
1701  }
1702 #endif
1703 
1704 #ifdef LIBO_INTERNAL_ONLY
1705  SAL_WARN_UNUSED_RESULT OString replaceAt( sal_Int32 index, sal_Int32 count, std::string_view newStr ) const
1706  {
1707  rtl_String* pNew = NULL;
1708  rtl_string_newReplaceStrAt_WithLength ( &pNew, pData, index, count, newStr.data(), newStr.size() );
1709  return OString( pNew, SAL_NO_ACQUIRE );
1710  }
1711 #endif
1712 
1726  SAL_WARN_UNUSED_RESULT OString replace( char oldChar, char newChar ) const
1727  {
1728  rtl_String* pNew = NULL;
1729  rtl_string_newReplace( &pNew, pData, oldChar, newChar );
1730  return OString( pNew, SAL_NO_ACQUIRE );
1731  }
1732 
1752  OString const & from, OString const & to, sal_Int32 * index = NULL) const
1753  {
1754  rtl_String * s = NULL;
1755  sal_Int32 i = 0;
1757  &s, pData, from.pData->buffer, from.pData->length,
1758  to.pData->buffer, to.pData->length, index == NULL ? &i : index);
1759  return OString(s, SAL_NO_ACQUIRE);
1760  }
1761 
1775  SAL_WARN_UNUSED_RESULT OString replaceAll(OString const & from, OString const & to) const {
1776  rtl_String * s = NULL;
1778  &s, pData, from.pData->buffer, from.pData->length,
1779  to.pData->buffer, to.pData->length);
1780  return OString(s, SAL_NO_ACQUIRE);
1781  }
1782 
1794  {
1795  rtl_String* pNew = NULL;
1796  rtl_string_newToAsciiLowerCase( &pNew, pData );
1797  return OString( pNew, SAL_NO_ACQUIRE );
1798  }
1799 
1811  {
1812  rtl_String* pNew = NULL;
1813  rtl_string_newToAsciiUpperCase( &pNew, pData );
1814  return OString( pNew, SAL_NO_ACQUIRE );
1815  }
1816 
1829  {
1830  rtl_String* pNew = NULL;
1831  rtl_string_newTrim( &pNew, pData );
1832  return OString( pNew, SAL_NO_ACQUIRE );
1833  }
1834 
1859  OString getToken( sal_Int32 token, char cTok, sal_Int32& index ) const
1860  {
1861  rtl_String * pNew = NULL;
1862  index = rtl_string_getToken( &pNew, pData, token, cTok, index );
1863  return OString( pNew, SAL_NO_ACQUIRE );
1864  }
1865 
1879  OString getToken(sal_Int32 count, char separator) const {
1880  sal_Int32 n = 0;
1881  return getToken(count, separator, n);
1882  }
1883 
1892  bool toBoolean() const
1893  {
1894  return rtl_str_toBoolean( pData->buffer );
1895  }
1896 
1903  char toChar() const
1904  {
1905  return pData->buffer[0];
1906  }
1907 
1918  sal_Int32 toInt32( sal_Int16 radix = 10 ) const
1919  {
1920  return rtl_str_toInt32( pData->buffer, radix );
1921  }
1922 
1935  sal_uInt32 toUInt32( sal_Int16 radix = 10 ) const
1936  {
1937  return rtl_str_toUInt32( pData->buffer, radix );
1938  }
1939 
1950  sal_Int64 toInt64( sal_Int16 radix = 10 ) const
1951  {
1952  return rtl_str_toInt64( pData->buffer, radix );
1953  }
1954 
1967  sal_uInt64 toUInt64( sal_Int16 radix = 10 ) const
1968  {
1969  return rtl_str_toUInt64( pData->buffer, radix );
1970  }
1971 
1980  float toFloat() const
1981  {
1982  return rtl_str_toFloat( pData->buffer );
1983  }
1984 
1993  double toDouble() const
1994  {
1995  return rtl_str_toDouble( pData->buffer );
1996  }
1997 
1998 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
1999 
2000  static OStringNumber< int > number( int i, sal_Int16 radix = 10 )
2001  {
2002  return OStringNumber< int >( i, radix );
2003  }
2004  static OStringNumber< long long > number( long long ll, sal_Int16 radix = 10 )
2005  {
2006  return OStringNumber< long long >( ll, radix );
2007  }
2008  static OStringNumber< unsigned long long > number( unsigned long long ll, sal_Int16 radix = 10 )
2009  {
2010  return OStringNumber< unsigned long long >( ll, radix );
2011  }
2012  static OStringNumber< unsigned long long > number( unsigned int i, sal_Int16 radix = 10 )
2013  {
2014  return number( static_cast< unsigned long long >( i ), radix );
2015  }
2016  static OStringNumber< long long > number( long i, sal_Int16 radix = 10)
2017  {
2018  return number( static_cast< long long >( i ), radix );
2019  }
2020  static OStringNumber< unsigned long long > number( unsigned long i, sal_Int16 radix = 10 )
2021  {
2022  return number( static_cast< unsigned long long >( i ), radix );
2023  }
2024  static OStringNumber< float > number( float f )
2025  {
2026  return OStringNumber< float >( f );
2027  }
2028  static OStringNumber< double > number( double d )
2029  {
2030  return OStringNumber< double >( d );
2031  }
2032 #else
2033 
2043  static OString number( int i, sal_Int16 radix = 10 )
2044  {
2045  char aBuf[RTL_STR_MAX_VALUEOFINT32];
2046  return OString(aBuf, rtl_str_valueOfInt32(aBuf, i, radix));
2047  }
2050  static OString number( unsigned int i, sal_Int16 radix = 10 )
2051  {
2052  return number( static_cast< unsigned long long >( i ), radix );
2053  }
2056  static OString number( long i, sal_Int16 radix = 10 )
2057  {
2058  return number( static_cast< long long >( i ), radix );
2059  }
2062  static OString number( unsigned long i, sal_Int16 radix = 10 )
2063  {
2064  return number( static_cast< unsigned long long >( i ), radix );
2065  }
2068  static OString number( long long ll, sal_Int16 radix = 10 )
2069  {
2070  char aBuf[RTL_STR_MAX_VALUEOFINT64];
2071  return OString(aBuf, rtl_str_valueOfInt64(aBuf, ll, radix));
2072  }
2075  static OString number( unsigned long long ll, sal_Int16 radix = 10 )
2076  {
2077  char aBuf[RTL_STR_MAX_VALUEOFUINT64];
2078  return OString(aBuf, rtl_str_valueOfUInt64(aBuf, ll, radix));
2079  }
2080 
2090  static OString number( float f )
2091  {
2092  char aBuf[RTL_STR_MAX_VALUEOFFLOAT];
2093  return OString(aBuf, rtl_str_valueOfFloat(aBuf, f));
2094  }
2095 
2105  static OString number( double d )
2106  {
2107  char aBuf[RTL_STR_MAX_VALUEOFDOUBLE];
2108  return OString(aBuf, rtl_str_valueOfDouble(aBuf, d));
2109  }
2110 #endif
2111 
2123  SAL_DEPRECATED("use boolean()") static OString valueOf( sal_Bool b )
2124  {
2125  return boolean(b);
2126  }
2127 
2139  static OString boolean( bool b )
2140  {
2141  char aBuf[RTL_STR_MAX_VALUEOFBOOLEAN];
2142  return OString(aBuf, rtl_str_valueOfBoolean(aBuf, b));
2143  }
2144 
2152  SAL_DEPRECATED("convert to OString or use directly") static OString valueOf( char c )
2153  {
2154  return OString( &c, 1 );
2155  }
2156 
2167  SAL_DEPRECATED("use number()") static OString valueOf( sal_Int32 i, sal_Int16 radix = 10 )
2168  {
2169  return number( i, radix );
2170  }
2171 
2182  SAL_DEPRECATED("use number()") static OString valueOf( sal_Int64 ll, sal_Int16 radix = 10 )
2183  {
2184  return number( ll, radix );
2185  }
2186 
2196  SAL_DEPRECATED("use number()") static OString valueOf( float f )
2197  {
2198  return number(f);
2199  }
2200 
2210  SAL_DEPRECATED("use number()") static OString valueOf( double d )
2211  {
2212  return number(d);
2213  }
2214 
2215 #if defined LIBO_INTERNAL_ONLY
2216  operator std::string_view() const { return {getStr(), sal_uInt32(getLength())}; }
2217 #endif
2218 
2219 #if defined LIBO_INTERNAL_ONLY
2220  // A wrapper for the first expression in an
2221  //
2222  // OString::Concat(e1) + e2 + ...
2223  //
2224  // concatenation chain, when neither of the first two e1, e2 is one of our rtl string-related
2225  // classes (so something like
2226  //
2227  // OString s = "a" + (b ? std::string_view("c") : std::string_view("dd"));
2228  //
2229  // would not compile):
2230  template<typename T> [[nodiscard]] static
2231  OStringConcat<OStringConcatMarker, T>
2232  Concat(T const & value) { return OStringConcat<OStringConcatMarker, T>({}, value); }
2233 
2234  // This overload is needed so that an argument of type 'char const[N]' ends up as
2235  // 'OStringConcat<rtl::OStringConcatMarker, char const[N]>' rather than as
2236  // 'OStringConcat<rtl::OStringConcatMarker, char[N]>':
2237  template<typename T, std::size_t N> [[nodiscard]] static
2238  OStringConcat<OStringConcatMarker, T[N]>
2239  Concat(T (& value)[N]) { return OStringConcat<OStringConcatMarker, T[N]>({}, value); }
2240 #endif
2241 };
2242 
2243 #if defined LIBO_INTERNAL_ONLY
2244 // Can only define this after we define OString
2245 inline OStringConstExpr::operator const OString &() const { return OString::unacquired(&pData); }
2246 #endif
2247 
2248 #if defined LIBO_INTERNAL_ONLY
2249 inline bool operator ==(OString const & lhs, StringConcatenation<char> const & rhs)
2250 { return lhs == std::string_view(rhs); }
2251 inline bool operator !=(OString const & lhs, StringConcatenation<char> const & rhs)
2252 { return lhs != std::string_view(rhs); }
2253 inline bool operator ==(StringConcatenation<char> const & lhs, OString const & rhs)
2254 { return std::string_view(lhs) == rhs; }
2255 inline bool operator !=(StringConcatenation<char> const & lhs, OString const & rhs)
2256 { return std::string_view(lhs) != rhs; }
2257 #endif
2258 
2259 /* ======================================================================= */
2260 
2261 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
2262 
2266 template<>
2267 struct ToStringHelper< OString >
2268 {
2269  static std::size_t length( const OString& s ) { return s.getLength(); }
2270  char* operator()( char* buffer, const OString& s ) const { return addDataHelper( buffer, s.getStr(), s.getLength()); }
2271 };
2272 
2276 template<std::size_t N>
2277 struct ToStringHelper< OStringLiteral<N> >
2278 {
2279  static constexpr std::size_t length( const OStringLiteral<N>& str ) { return str.getLength(); }
2280  char* operator()( char* buffer, const OStringLiteral<N>& str ) const { return addDataHelper( buffer, str.getStr(), str.getLength() ); }
2281 };
2282 
2286 template< typename charT, typename traits, typename T1, typename T2 >
2287 inline std::basic_ostream<charT, traits> & operator <<(
2288  std::basic_ostream<charT, traits> & stream, OStringConcat< T1, T2 >&& concat)
2289 {
2290  return stream << OString( std::move(concat) );
2291 }
2292 #endif
2293 
2294 
2301 {
2311  size_t operator()( const OString& rString ) const
2312  { return static_cast<size_t>(rString.hashCode()); }
2313 };
2314 
2317 {
2318  bool operator()( const char* p1, const char* p2) const
2319  { return rtl_str_compare(p1, p2) == 0; }
2320 };
2321 
2324 {
2325  size_t operator()(const char* p) const
2326  { return rtl_str_hashCode(p); }
2327 };
2328 
2329 /* ======================================================================= */
2330 
2337 template< typename charT, typename traits > std::basic_ostream<charT, traits> &
2339  std::basic_ostream<charT, traits> & stream, OString const & rString)
2340 {
2341  return stream << rString.getStr();
2342  // best effort; potentially loses data due to embedded null characters
2343 }
2344 
2345 } /* Namespace */
2346 
2347 #ifdef RTL_STRING_UNITTEST
2348 namespace rtl
2349 {
2350 typedef rtlunittest::OString OString;
2351 }
2352 #undef RTL_STRING_CONST_FUNCTION
2353 #endif
2354 
2355 #if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST
2356 using ::rtl::OString;
2357 using ::rtl::OStringChar;
2358 using ::rtl::Concat2View;
2359 using ::rtl::OStringHash;
2360 using ::rtl::OStringLiteral;
2361 #endif
2362 
2364 
2369 #if defined LIBO_INTERNAL_ONLY
2370 namespace std {
2371 
2372 template<>
2373 struct hash<::rtl::OString>
2374 {
2375  std::size_t operator()(::rtl::OString const & s) const
2376  {
2377  if constexpr (sizeof(std::size_t) == 8)
2378  {
2379  // return a hash that uses the full 64-bit range instead of a 32-bit value
2380  size_t n = 0;
2381  for (sal_Int32 i = 0, len = s.getLength(); i < len; ++i)
2382  n = 31 * n + s[i];
2383  return n;
2384  }
2385  else
2386  return std::size_t(s.hashCode());
2387  }
2388 };
2389 
2390 }
2391 
2392 #endif
2393 
2395 #endif // INCLUDED_RTL_STRING_HXX
2396 
2397 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 lastIndexOf(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:1404
#define RTL_STR_MAX_VALUEOFUINT64
Definition: string.h:657
#define RTL_STR_MAX_VALUEOFINT32
Definition: string.h:611
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:1775
bool equalsIgnoreAsciiCase(const OString &str) const
Perform an ASCII lowercase comparison of two strings.
Definition: string.hxx:785
SAL_DLLPUBLIC void rtl_string_new(rtl_String **newStr) SAL_THROW_EXTERN_C()
Allocate a new string containing no characters.
friend libreoffice_internal::CharPtrDetector< T, bool >::Type operator==(const T &value, const OString &rStr2)
Definition: string.hxx:1240
static OString number(int i, sal_Int16 radix=10)
Returns the string representation of the integer argument.
Definition: string.hxx:2043
SAL_WARN_UNUSED_RESULT OString concat(const OString &str) const
Concatenates the specified string to the end of this string.
Definition: string.hxx:1666
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_DLLPUBLIC void rtl_string_newReplace(rtl_String **newStr, rtl_String *str, char oldChar, char newChar) SAL_THROW_EXTERN_C()
Create a new string by replacing all occurrences of a single character within another string...
libreoffice_internal::CharPtrDetector< T, bool >::Type equalsIgnoreAsciiCase(const T &asciiStr) const
Perform an ASCII lowercase comparison of two strings.
Definition: string.hxx:818
bool equalsL(const char *value, sal_Int32 length) const
Perform a comparison of two strings.
Definition: string.hxx:751
SAL_DLLPUBLIC sal_Int32 rtl_str_indexOfChar_WithLength(const char *str, sal_Int32 len, char ch) SAL_THROW_EXTERN_C()
Search for the first occurrence of a character within a string.
SAL_DLLPUBLIC void rtl_string_newFromLiteral(rtl_String **newStr, const char *value, sal_Int32 len, sal_Int32 allocExtra) SAL_THROW_EXTERN_C()
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:2050
SAL_DLLPUBLIC sal_Int32 rtl_string_getToken(rtl_String **newStr, rtl_String *str, sal_Int32 token, char cTok, sal_Int32 idx) SAL_THROW_EXTERN_C()
Create a new string by extracting a single token from another string.
friend libreoffice_internal::CharPtrDetector< T, bool >::Type operator==(const OString &rStr1, const T &value)
Definition: string.hxx:1222
unsigned char sal_Bool
Definition: types.h:18
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:1285
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_Int32 toInt32(sal_Int16 radix=10) const
Returns the int32 value from this string.
Definition: string.hxx:1918
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:2068
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_DLLPUBLIC sal_Int32 rtl_str_lastIndexOfStr_WithLength(const char *str, sal_Int32 len, const char *subStr, sal_Int32 subLen) SAL_THROW_EXTERN_C()
Search for the last occurrence of a substring 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:945
bool operator==(const TTimeValue &rTimeA, const TTimeValue &rTimeB)
Definition: timer.hxx:93
SAL_DLLPUBLIC sal_Int32 rtl_str_toInt32(const char *str, sal_Int16 radix) SAL_THROW_EXTERN_C()
Interpret a string as an 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:1096
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:1578
friend libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type operator==(T &value, const OString &rStr2)
Definition: string.hxx:1249
pData
New string from a character buffer array.
Definition: string.hxx:289
sal_uInt16 rtl_TextEncoding
The various supported text encodings.
Definition: textenc.h:17
bool endsWith(OString const &str, OString *rest=NULL) const
Check whether this string ends with a given substring.
Definition: string.hxx:1151
#define RTL_STR_MAX_VALUEOFINT64
Definition: string.h:634
bool toBoolean() const
Returns the Boolean value from this string.
Definition: string.hxx:1892
SAL_DLLPUBLIC sal_Int32 rtl_str_compare(const char *first, const char *second) SAL_THROW_EXTERN_C()
Compare two strings.
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_WARN_UNUSED_RESULT OString copy(sal_Int32 beginIndex) const
Returns a new string that is a substring of this string.
Definition: string.hxx:1561
OString()
New string containing no characters.
Definition: string.hxx:206
sal_Int32 compareTo(const OString &str) const
Compares two strings.
Definition: string.hxx:673
sal_Int32 hashCode() const
Returns a hashcode for this string.
Definition: string.hxx:1354
__sal_NoAcquire
Definition: types.h:332
bool startsWith(OString const &str, OString *rest=NULL) const
Check whether this string starts with a given substring.
Definition: string.hxx:1039
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.
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:1263
const char * getStr() const SAL_RETURNS_NONNULL
Returns a pointer to the characters of this string.
Definition: string.hxx:644
SAL_DLLPUBLIC sal_Int32 rtl_str_lastIndexOfChar_WithLength(const char *str, sal_Int32 len, char ch) SAL_THROW_EXTERN_C()
Search for the last occurrence of a character within a string.
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:1001
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:914
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:1342
sal_uInt16 sal_Unicode
Definition: types.h:103
SAL_DLLPUBLIC sal_Int32 rtl_str_compareIgnoreAsciiCase_WithLength(const char *first, sal_Int32 firstLen, const char *second, sal_Int32 secondLen) SAL_THROW_EXTERN_C()
Compare two strings, ignoring the case of ASCII characters.
bool operator<(const TTimeValue &rTimeA, const TTimeValue &rTimeB)
Definition: timer.hxx:73
#define OUSTRING_TO_OSTRING_CVTFLAGS
Definition: string.h:1338
double toDouble() const
Returns the double value from this string.
Definition: string.hxx:1993
sal_Int32 getLength() const
Returns the length of this string.
Definition: string.hxx:618
This String class provide base functionality for C++ like 8-Bit character array handling.
Definition: string.hxx:196
libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type equalsIgnoreAsciiCase(T &asciiStr) const
Definition: string.hxx:824
OString(rtl_String *str)
New string from OString data.
Definition: string.hxx:243
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:988
OString(rtl_String *str, __sal_NoAcquire)
New string from OString data without acquiring it.
Definition: string.hxx:256
SAL_DLLPUBLIC void rtl_string_newFromStr(rtl_String **newStr, const char *value) SAL_THROW_EXTERN_C()
Allocate a new string that contains a copy of a character array.
static OString number(float f)
Returns the string representation of the float argument.
Definition: string.hxx:2090
bool equals(const OString &str) const
Perform a comparison of two strings.
Definition: string.hxx:727
char toChar() const
Returns the first character from this string.
Definition: string.hxx:1903
bool operator>(const TTimeValue &rTimeA, const TTimeValue &rTimeB)
Definition: timer.hxx:83
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:491
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:2062
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:1114
SAL_DLLPUBLIC sal_Int32 rtl_str_hashCode_WithLength(const char *str, sal_Int32 len) SAL_THROW_EXTERN_C()
Return a hash code for a string.
SAL_DLLPUBLIC sal_Int32 rtl_str_reverseCompare_WithLength(const char *first, sal_Int32 firstLen, const char *second, sal_Int32 secondLen) SAL_THROW_EXTERN_C()
Compare two strings from back to front.
#define RTL_STR_MAX_VALUEOFDOUBLE
Definition: string.h:695
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:462
bool equalsIgnoreAsciiCaseL(const char *asciiStr, sal_Int32 asciiStrLength) const
Perform an ASCII lowercase comparison of two strings.
Definition: string.hxx:870
#define SAL_DEPRECATED(message)
Use as follows: SAL_DEPRECATED(&quot;Don&#39;t use, it&#39;s evil.&quot;) void doit(int nPara);.
Definition: types.h:454
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:1475
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:1696
#define RTL_STR_MAX_VALUEOFBOOLEAN
Definition: string.h:569
#define SAL_WARN_UNUSED
Annotate classes where a compiler should warn if an instance is unused.
Definition: types.h:567
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.
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:1331
float toFloat() const
Returns the float value from this string.
Definition: string.hxx:1980
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 sal_Int32 rtl_str_valueOfDouble(char *str, double d) SAL_THROW_EXTERN_C()
Create the string representation of a double.
OString(const OString &str)
New string from OString.
Definition: string.hxx:217
static OString boolean(bool b)
Returns the string representation of the boolean argument.
Definition: string.hxx:2139
sal_uInt64 toUInt64(sal_Int16 radix=10) const
Returns the uint64 value from this string.
Definition: string.hxx:1967
SAL_DLLPUBLIC sal_uInt64 rtl_str_toUInt64(const char *str, sal_Int16 radix) SAL_THROW_EXTERN_C()
Interpret a string as an unsigned long integer.
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:390
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:2075
Definition: stringutils.hxx:142
sal_Int32 reverseCompareTo(const OString &str) const
Compares two strings in reverse order.
Definition: string.hxx:710
bool endsWithL(char const *str, sal_Int32 strLength) const
Check whether this string ends with a given substring.
Definition: string.hxx:1203
bool operator()(const char *p1, const char *p2) const
Definition: string.hxx:2318
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:1810
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:1793
SAL_DLLPUBLIC double rtl_str_toDouble(const char *str) SAL_THROW_EXTERN_C()
Interpret a string as a double.
sal_Int32 compareTo(const OString &rObj, sal_Int32 maxLength) const
Compares two strings with an maximum count of characters.
Definition: string.hxx:692
sal_Int64 toInt64(sal_Int16 radix=10) const
Returns the int64 value from this string.
Definition: string.hxx:1950
definition of a no acquire enum for ctors
Definition: types.h:336
#define SAL_WARN_UNUSED_RESULT
Use this as markup for functions and methods whose return value must be checked.
Definition: types.h:264
OString getToken(sal_Int32 token, char cTok, sal_Int32 &index) const
Returns a token in the string.
Definition: string.hxx:1859
bool operator!=(const Any &rAny, const C &value)
Template inequality operator: compares set value of left side any to right side value.
Definition: Any.hxx:653
SAL_DLLPUBLIC sal_Int32 rtl_str_shortenedCompareIgnoreAsciiCase_WithLength(const char *first, sal_Int32 firstLen, const 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...
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:2338
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:835
void clear()
Clears the string, i.e, makes a zero-character string.
Definition: string.hxx:605
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:2056
friend OString operator+(const OString &str1, const OString &str2)
Definition: string.hxx:1675
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:1828
OString(char value)
New string from a single character.
Definition: string.hxx:266
sal_Int32 oslInterlockedCount
Definition: interlck.h:24
#define RTL_STR_MAX_VALUEOFFLOAT
Definition: string.h:676
SAL_DLLPUBLIC void rtl_string_assign(rtl_String **str, rtl_String *rightValue) SAL_THROW_EXTERN_C()
Assign a new value to a string.
SAL_DLLPUBLIC sal_uInt32 rtl_str_toUInt32(const char *str, sal_Int16 radix) SAL_THROW_EXTERN_C()
Interpret a string as an unsigned integer.
SAL_DLLPUBLIC sal_Int32 rtl_str_hashCode(const char *str) SAL_THROW_EXTERN_C()
Return a hash code for a string.
bool isEmpty() const
Checks if a string is empty.
Definition: string.hxx:628
SAL_DLLPUBLIC float rtl_str_toFloat(const char *str) SAL_THROW_EXTERN_C()
Interpret a string as a float.
size_t operator()(const OString &rString) const
Compute a hash code for a string.
Definition: string.hxx:2311
friend libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type operator==(const OString &rStr1, T &value)
Definition: string.hxx:1231
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:1544
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:1751
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...
SAL_DLLPUBLIC sal_Int32 rtl_str_valueOfBoolean(char *str, sal_Bool b) SAL_THROW_EXTERN_C()
Create the string representation of a boolean.
static OString number(double d)
Returns the string representation of the double argument.
Definition: string.hxx:2105
SAL_DLLPUBLIC void rtl_string_release(rtl_String *str) SAL_THROW_EXTERN_C()
Decrement the reference count of a string.
SAL_DLLPUBLIC sal_Bool rtl_str_toBoolean(const char *str) SAL_THROW_EXTERN_C()
Interpret a string as a boolean.
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:1054
friend libreoffice_internal::CharPtrDetector< T, bool >::Type operator!=(const OString &rStr1, const T &value)
Definition: string.hxx:1302
sal_Int32 lastIndexOf(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:1387
A helper to use OStrings with hash maps.
Definition: string.hxx:2300
SAL_DLLPUBLIC sal_Int32 rtl_str_valueOfInt32(char *str, sal_Int32 i, sal_Int16 radix) SAL_THROW_EXTERN_C()
Create the string representation of an integer.
Hashing functor for classic c-strings (i.e., null-terminated char* strings).
Definition: string.hxx:2323
SAL_DLLPUBLIC sal_Int32 rtl_str_valueOfFloat(char *str, float f) SAL_THROW_EXTERN_C()
Create the string representation of a float.
OString & operator+=(const OString &str)
Append a string to this string.
Definition: string.hxx:513
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:1445
~OString()
Release the string data.
Definition: string.hxx:436
friend libreoffice_internal::CharPtrDetector< T, bool >::Type operator!=(const T &value, const OString &rStr2)
Definition: string.hxx:1314
sal_uInt32 toUInt32(sal_Int16 radix=10) const
Returns the uint32 value from this string.
Definition: string.hxx:1935
Definition: stringutils.hxx:140
SAL_DLLPUBLIC sal_Int32 rtl_str_shortenedCompare_WithLength(const char *first, sal_Int32 firstLen, const char *second, sal_Int32 secondLen, sal_Int32 shortenedLen) SAL_THROW_EXTERN_C()
Compare two strings with a maximum count of characters.
SAL_DLLPUBLIC void rtl_string_newFromStr_WithLength(rtl_String **newStr, const char *value, sal_Int32 len) SAL_THROW_EXTERN_C()
Allocate a new string that contains a copy of a character array.
SAL_DLLPUBLIC sal_Int32 rtl_str_indexOfStr_WithLength(const char *str, sal_Int32 len, const char *subStr, sal_Int32 subLen) SAL_THROW_EXTERN_C()
Search for the first occurrence of a substring within a string.
SAL_DLLPUBLIC sal_Int32 rtl_str_getLength(const char *str) SAL_THROW_EXTERN_C()
Return the length of a string.
SAL_DLLPUBLIC sal_Int32 rtl_str_valueOfInt64(char *str, sal_Int64 l, sal_Int16 radix) SAL_THROW_EXTERN_C()
Create the string representation of a long integer.
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:1513
SAL_WARN_UNUSED_RESULT OString replace(char oldChar, char newChar) const
Returns a new string resulting from replacing all occurrences of oldChar in this string with newChar...
Definition: string.hxx:1726
SAL_DLLPUBLIC sal_Int64 rtl_str_toInt64(const char *str, sal_Int16 radix) SAL_THROW_EXTERN_C()
Interpret a string as a long integer.
SAL_DLLPUBLIC void rtl_string_acquire(rtl_String *str) SAL_THROW_EXTERN_C()
Increment the reference count of a 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:1167
SAL_DLLPUBLIC sal_Int32 rtl_str_compare_WithLength(const char *first, sal_Int32 firstLen, const char *second, sal_Int32 secondLen) SAL_THROW_EXTERN_C()
Compare two strings.
OString getToken(sal_Int32 count, char separator) const
Returns a token from the string.
Definition: string.hxx:1879
OString(const char *value, sal_Int32 length)
New string from a character buffer array.
Definition: string.hxx:347
sal_Int32 indexOf(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:1372
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:1432
size_t operator()(const char *p) const
Definition: string.hxx:2325
SAL_DLLPUBLIC sal_Int32 rtl_str_valueOfUInt64(char *str, sal_uInt64 l, sal_Int16 radix) SAL_THROW_EXTERN_C()
Create the string representation of an unsigned long integer.
friend libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type operator!=(const OString &rStr1, T &value)
Definition: string.hxx:1308
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...
bool match(const OString &str, sal_Int32 fromIndex=0) const
Match against a substring appearing in this string.
Definition: string.hxx:901
friend libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type operator!=(T &value, const OString &rStr2)
Definition: string.hxx:1320
SAL_DLLPUBLIC sal_Int32 rtl_str_compareIgnoreAsciiCase(const char *first, const char *second) SAL_THROW_EXTERN_C()
Compare two strings, ignoring the case of ASCII characters.
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.
Equality functor for classic c-strings (i.e., null-terminated char* strings).
Definition: string.hxx:2316