LibreOfficeDev
LibreOfficeDev 26.8 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 /*
21  * This file is part of LibreOffice published API.
22  */
23 
24 #ifndef INCLUDED_RTL_STRING_HXX
25 #define INCLUDED_RTL_STRING_HXX
26 
27 #include "sal/config.h"
28 
29 #include <cassert>
30 #include <cstddef>
31 #include <cstdlib>
32 #include <limits>
33 #include <new>
34 #include <ostream>
35 #include <utility>
36 #include <string.h>
37 
38 #if defined LIBO_INTERNAL_ONLY
39 #include <algorithm>
40 #include <string_view>
41 #include <type_traits>
42 #endif
43 
44 #include "rtl/math.h"
45 #include "rtl/textenc.h"
46 #include "rtl/string.h"
47 #include "rtl/stringutils.hxx"
48 
49 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
50 #include "config_global.h"
51 #include "rtl/stringconcat.hxx"
52 #endif
53 
54 #ifdef RTL_STRING_UNITTEST
55 extern bool rtl_string_unittest_const_literal;
56 extern bool rtl_string_unittest_const_literal_function;
57 #endif
58 
59 // The unittest uses slightly different code to help check that the proper
60 // calls are made. The class is put into a different namespace to make
61 // sure the compiler generates a different (if generating also non-inline)
62 // copy of the function and does not merge them together. The class
63 // is "brought" into the proper rtl namespace by a typedef below.
64 #ifdef RTL_STRING_UNITTEST
65 #define rtl rtlunittest
66 #endif
67 
68 namespace rtl
69 {
70 
72 #ifdef RTL_STRING_UNITTEST
73 #undef rtl
74 // helper macro to make functions appear more readable
75 #define RTL_STRING_CONST_FUNCTION rtl_string_unittest_const_literal_function = true;
76 #else
77 #define RTL_STRING_CONST_FUNCTION
78 #endif
80 
81 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
82 
89 template<std::size_t N> class SAL_WARN_UNUSED OStringLiteral {
90  static_assert(N != 0);
91  static_assert(N - 1 <= std::numeric_limits<sal_Int32>::max(), "literal too long");
92 
93 public:
94 #if HAVE_CPP_CONSTEVAL
95  consteval
96 #else
97  constexpr
98 #endif
99  OStringLiteral(char const (&literal)[N]) {
100  assertLayout();
101  assert(literal[N - 1] == '\0');
102  std::copy_n(literal, N, more.buffer);
103  }
104 
105 #if !(defined _MSC_VER && _MSC_VER >= 1930 && _MSC_VER <= 1939 && defined _MANAGED)
106 #if HAVE_CPP_CONSTEVAL
107  consteval
108 #else
109  constexpr
110 #endif
111  OStringLiteral(char8_t const (&literal)[N]) {
112  assertLayout();
113  assert(literal[N - 1] == '\0');
114  std::copy_n(literal, N, more.buffer);
115  }
116 #endif
117 
118  constexpr sal_Int32 getLength() const { return more.length; }
119 
120  constexpr char const * getStr() const SAL_RETURNS_NONNULL { return more.buffer; }
121 
122  constexpr operator std::string_view() const { return {more.buffer, sal_uInt32(more.length)}; }
123 
124 private:
125  static constexpr void assertLayout() {
126  // These static_asserts verifying the layout compatibility with rtl_String cannot be class
127  // member declarations, as offsetof requires a complete type, so defer them to here:
128  static_assert(std::is_standard_layout_v<OStringLiteral>);
129  static_assert(offsetof(OStringLiteral, str.refCount) == offsetof(OStringLiteral, more.refCount));
130  static_assert(offsetof(OStringLiteral, str.length) == offsetof(OStringLiteral, more.length));
131  static_assert(offsetof(OStringLiteral, str.buffer) == offsetof(OStringLiteral, more.buffer));
132  }
133 
134  struct Data {
135  Data() = default;
136 
137  oslInterlockedCount refCount = 0x40000000; // SAL_STRING_STATIC_FLAG (sal/rtl/strimp.hxx)
138  sal_Int32 length = N - 1;
139  char buffer[N];
140  };
141 
142 public:
143  // (Data members must be public so that OStringLiteral is a structural type that can be used as
144  // a non-type template parameter type for operator ""_ostr and rtl::detail::OStringHolder:)
145  union {
146  rtl_String str;
147  Data more = {};
148  };
149 };
150 
151 namespace detail {
152 
153 template<OStringLiteral L> struct OStringHolder {
154  static constexpr auto & literal = L;
155 };
156 
157 }
158 
159 #endif
160 
161 /* ======================================================================= */
162 
187 // coverity[ missing_move_assignment : SUPPRESS] - don't report the suppressed move assignment
188 class SAL_WARN_UNUSED SAL_DLLPUBLIC_RTTI OString
189 {
190 public:
192  rtl_String * pData;
194 
198 #if defined LIBO_INTERNAL_ONLY
199  constexpr
200 #endif
202  {
203 #if defined LIBO_INTERNAL_ONLY
204  pData = const_cast<rtl_String *>(&empty.str);
205 #else
206  pData = NULL;
207  rtl_string_new( &pData );
208 #endif
209  }
210 
216 #if defined LIBO_INTERNAL_ONLY
217  constexpr
218 #endif
219  OString( const OString & str )
220  {
221  pData = str.pData;
222 #if defined LIBO_INTERNAL_ONLY
223  if (std::is_constant_evaluated()) {
224  //TODO: We would want to
225  //
226  // assert(SAL_STRING_IS_STATIC(pData));
227  //
228  // here, but that wouldn't work because read of member `str` of OUStringLiteral's
229  // anonymous union with active member `more` is not allowed in a constant expression.
230  } else
231 #endif
232  rtl_string_acquire( pData );
233  }
234 
235 #if defined LIBO_INTERNAL_ONLY
236 #if !defined(__COVERITY__) // suppress COPY_INSTEAD_OF_MOVE suggestions
243  constexpr
244  OString( OString && str ) noexcept
245  {
246  pData = str.pData;
247  if (std::is_constant_evaluated()) {
248  //TODO: We would want to
249  //
250  // assert(SAL_STRING_IS_STATIC(pData));
251  //
252  // here, but that wouldn't work because read of member `str` of OUStringLiteral's
253  // anonymous union with active member `more` is not allowed in a constant expression.
254  return;
255  }
256  str.pData = nullptr;
257  rtl_string_new( &str.pData );
258  }
259 #endif
260 #endif
261 
267  OString( rtl_String * str )
268  {
269  pData = str;
270  rtl_string_acquire( pData );
271  }
272 
280  OString( rtl_String * str, __sal_NoAcquire )
281  {
282  pData = str;
283  }
284 
290  explicit OString( char value )
291  : pData (NULL)
292  {
293  rtl_string_newFromStr_WithLength( &pData, &value, 1 );
294  }
295 
296 #if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST_CONCAT
297  // Catch inadvertent conversions to the above ctor (e.g., from sal_[u]Int8, aka [un]signed
298  // char):
299  OString(int) = delete;
300 #endif
301 
310  template< typename T >
312  {
313  pData = NULL;
314  rtl_string_newFromStr( &pData, value );
315  }
316 
317  template< typename T >
319  {
320  pData = NULL;
321  rtl_string_newFromStr( &pData, value );
322  }
323 
324 #if __cplusplus > 202002L // C++23 P2266R3 "Simpler implicit move"
325  template< typename T >
327  {
328  pData = NULL;
329  rtl_string_newFromStr( &pData, value );
330  }
331 #endif
332 
343  template< typename T >
345  {
346  assert(
348  pData = NULL;
350  rtl_string_new(&pData);
351  } else {
353  &pData,
355  literal),
357  }
358 #ifdef RTL_STRING_UNITTEST
359  rtl_string_unittest_const_literal = true;
360 #endif
361  }
362 
371  OString( const char * value, sal_Int32 length )
372  {
373  pData = NULL;
374  rtl_string_newFromStr_WithLength( &pData, value, length );
375  }
376 
377 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
379 
384  template<std::size_t N> constexpr OString(OStringLiteral<N> const & literal):
385  pData(const_cast<rtl_String *>(&literal.str)) {}
386  template<std::size_t N> OString(OStringLiteral<N> &&) = delete;
388 #endif
389 
390 #if defined LIBO_INTERNAL_ONLY
391  // For operator ""_tstr:
392  template<OStringLiteral L> constexpr OString(detail::OStringHolder<L> const & holder):
393  pData(const_cast<rtl_String *>(&holder.literal.str)) {}
394 #endif
395 
396 #if defined LIBO_INTERNAL_ONLY
397  explicit OString(std::string_view sv) {
398  if (sv.size() > sal_uInt32(std::numeric_limits<sal_Int32>::max())) {
399  throw std::bad_alloc();
400  }
401  pData = nullptr;
402  rtl_string_newFromStr_WithLength(&pData, sv.data(), sv.size());
403  }
404 #endif
405 
420  OString( const sal_Unicode * value, sal_Int32 length,
421  rtl_TextEncoding encoding,
422  sal_uInt32 convertFlags = OUSTRING_TO_OSTRING_CVTFLAGS )
423  {
424  pData = NULL;
425  rtl_uString2String( &pData, value, length, encoding, convertFlags );
426  if (pData == NULL) {
427  throw std::bad_alloc();
428  }
429  }
430 
431 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
436  template< typename T1, typename T2 >
437  OString( OStringConcat< T1, T2 >&& c )
438  {
439  const sal_Int32 l = c.length();
440  pData = rtl_string_alloc( l );
441  if (l != 0)
442  {
443  char* end = c.addData( pData->buffer );
444  pData->length = l;
445  *end = '\0';
446  }
447  }
448 
453  template< std::size_t N >
454  OString( OStringNumber< N >&& n )
455  : OString( n.buf, n.length )
456  {}
457 #endif
458 
459 #ifdef LIBO_INTERNAL_ONLY
460  OString(std::nullptr_t) = delete;
461 #endif
462 
466 #if defined LIBO_INTERNAL_ONLY
467  constexpr
468 #endif
470  {
471 #if defined LIBO_INTERNAL_ONLY
472  if (std::is_constant_evaluated()) {
473  //TODO: We would want to
474  //
475  // assert(SAL_STRING_IS_STATIC(pData));
476  //
477  // here, but that wouldn't work because read of member `str` of OUStringLiteral's
478  // anonymous union with active member `more` is not allowed in a constant expression.
479  } else
480 #endif
481  rtl_string_release( pData );
482  }
483 
484 #if defined LIBO_INTERNAL_ONLY
496  static OString const & unacquired( rtl_String * const * ppHandle )
497  { return * reinterpret_cast< OString const * >( ppHandle ); }
498 #endif
499 
505  OString & operator=( const OString & str )
506  {
507  rtl_string_assign( &pData, str.pData );
508  return *this;
509  }
510 
511 #if defined LIBO_INTERNAL_ONLY
512 #if !defined(__COVERITY__) // suppress COPY_INSTEAD_OF_MOVE suggestions
519  OString & operator=( OString && str ) noexcept
520  {
521  rtl_string_release( pData );
522  pData = str.pData;
523  str.pData = nullptr;
524  rtl_string_new( &str.pData );
525  return *this;
526  }
527 #endif
528 #endif
529 
535  template< typename T >
537  {
538  RTL_STRING_CONST_FUNCTION
539  assert(
542  rtl_string_new(&pData);
543  } else {
545  &pData,
547  literal),
549  }
550  return *this;
551  }
552 
558  OString & operator+=( const OString & str )
559 #if defined LIBO_INTERNAL_ONLY
560  &
561 #endif
562  {
563  rtl_string_newConcat( &pData, pData, str.pData );
564  return *this;
565  }
566 #if defined LIBO_INTERNAL_ONLY
567  void operator+=(OString const &) && = delete;
568 #endif
569 
570 #if defined LIBO_INTERNAL_ONLY
572  operator +=(T const & value) & { return operator +=(std::string_view(value)); }
573  template<typename T> typename libreoffice_internal::CharPtrDetector<T, OString &>::Type
574  operator +=(T const &) && = delete;
575 
576  template<typename T>
577  typename libreoffice_internal::NonConstCharArrayDetector<T, OString &>::Type
578  operator +=(T & value) & { return operator +=(std::string_view(value)); }
579  template<typename T>
580  typename libreoffice_internal::NonConstCharArrayDetector<T, OString &>::Type operator +=(T &) &&
581  = delete;
582 
583  template<typename T> typename libreoffice_internal::ConstCharArrayDetector<T, OString &>::Type
584  operator +=(T & literal) & {
585  assert(libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
586  return operator +=(
587  std::string_view(
588  libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
589  libreoffice_internal::ConstCharArrayDetector<T>::length));
590  }
591  template<typename T> typename libreoffice_internal::ConstCharArrayDetector<T, OString &>::Type
592  operator +=(T &) && = delete;
593 
594  template<std::size_t N> OString & operator +=(OStringLiteral<N> const & literal) &
595  { return operator +=(std::string_view(literal.getStr(), literal.getLength())); }
596  template<std::size_t N> void operator +=(OStringLiteral<N> const &) && = delete;
597 
598  OString & operator +=(std::string_view sv) & {
599  if (sv.empty()) {
600  return *this;
601  }
602  if (sv.size() > sal_uInt32(std::numeric_limits<sal_Int32>::max() - pData->length)) {
603  throw std::bad_alloc();
604  }
605  auto const l = pData->length + sv.size();
606  rtl_string_ensureCapacity(&pData, l);
607  *addDataHelper(pData->buffer + pData->length, sv.data(), sv.size()) = '\0';
608  pData->length = l;
609  return *this;
610  }
611  void operator +=(std::string_view) && = delete;
612 #endif
613 
614 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
619  template< typename T1, typename T2 >
620  OString& operator+=( OStringConcat< T1, T2 >&& c ) & {
621  sal_Int32 l = c.length();
622  if( l == 0 )
623  return *this;
624  l += pData->length;
625  rtl_string_ensureCapacity( &pData, l );
626  char* end = c.addData( pData->buffer + pData->length );
627  *end = '\0';
628  pData->length = l;
629  return *this;
630  }
631  template<typename T1, typename T2> void operator +=(
632  OStringConcat<T1, T2> &&) && = delete;
633 
638  template< std::size_t N >
639  OString& operator+=( OStringNumber< N >&& n ) & {
640  return operator +=(std::string_view(n.buf, n.length));
641  }
642  template<std::size_t N> void operator +=(
643  OStringNumber<N> &&) && = delete;
644 #endif
645 
650  void clear()
651  {
652  rtl_string_new( &pData );
653  }
654 
663  sal_Int32 getLength() const { return pData->length; }
664 
673  bool isEmpty() const
674  {
675  return pData->length == 0;
676  }
677 
689  const char * getStr() const SAL_RETURNS_NONNULL { return pData->buffer; }
690 
700  char operator [](sal_Int32 index) const {
701  // silence spurious -Werror=strict-overflow warnings from GCC 4.8.2
702  assert(index >= 0 && static_cast<sal_uInt32>(index) < static_cast<sal_uInt32>(getLength()));
703  return getStr()[index];
704  }
705 
718  sal_Int32 compareTo( const OString & str ) const
719  {
720  return rtl_str_compare_WithLength( pData->buffer, pData->length,
721  str.pData->buffer, str.pData->length );
722  }
723 
737  sal_Int32 compareTo( const OString & rObj, sal_Int32 maxLength ) const
738  {
739  return rtl_str_shortenedCompare_WithLength( pData->buffer, pData->length,
740  rObj.pData->buffer, rObj.pData->length, maxLength );
741  }
742 
755  sal_Int32 reverseCompareTo( const OString & str ) const
756  {
757  return rtl_str_reverseCompare_WithLength( pData->buffer, pData->length,
758  str.pData->buffer, str.pData->length );
759  }
760 
772  bool equals( const OString & str ) const
773  {
774  if ( pData->length != str.pData->length )
775  return false;
776  if ( pData == str.pData )
777  return true;
778  return rtl_str_reverseCompare_WithLength( pData->buffer, pData->length,
779  str.pData->buffer, str.pData->length ) == 0;
780  }
781 
796  bool equalsL( const char* value, sal_Int32 length ) const
797  {
798  if ( pData->length != length )
799  return false;
800 
801  return rtl_str_reverseCompare_WithLength( pData->buffer, pData->length,
802  value, length ) == 0;
803  }
804 
819 #if defined LIBO_INTERNAL_ONLY
820  bool equalsIgnoreAsciiCase( std::string_view str ) const
821  {
822  if ( sal_uInt32(pData->length) != str.size() )
823  return false;
824  if ( pData->buffer == str.data() )
825  return true;
826  return rtl_str_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
827  str.data(), str.size() ) == 0;
828  }
829 #else
830  bool equalsIgnoreAsciiCase( const OString & str ) const
831  {
832  if ( pData->length != str.pData->length )
833  return false;
834  if ( pData == str.pData )
835  return true;
836  return rtl_str_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
837  str.pData->buffer, str.pData->length ) == 0;
838  }
839 #endif
840 
862  template< typename T >
864  {
865  return rtl_str_compareIgnoreAsciiCase( pData->buffer, asciiStr ) == 0;
866  }
867 
868  template< typename T >
870  {
871  return rtl_str_compareIgnoreAsciiCase( pData->buffer, asciiStr ) == 0;
872  }
873 
879  template< typename T >
881  {
882  RTL_STRING_CONST_FUNCTION
883  assert(
885  return
886  (pData->length
889  pData->buffer, pData->length,
891  literal),
893  == 0);
894  }
895 
915  bool equalsIgnoreAsciiCaseL( const char * asciiStr, sal_Int32 asciiStrLength ) const
916  {
917  if ( pData->length != asciiStrLength )
918  return false;
919 
920  return rtl_str_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
921  asciiStr, asciiStrLength ) == 0;
922  }
923 
939 #if defined LIBO_INTERNAL_ONLY
940  bool match( std::string_view str, sal_Int32 fromIndex = 0 ) const
941  {
942  assert(fromIndex >= 0);
943  return rtl_str_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
944  str.data(), str.size(), str.size() ) == 0;
945  }
946 #else
947  bool match( const OString & str, sal_Int32 fromIndex = 0 ) const
948  {
949  assert(fromIndex >= 0);
950  return rtl_str_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
951  str.pData->buffer, str.pData->length, str.pData->length ) == 0;
952  }
953 #endif
954 
960  template< typename T >
961  typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type match( T& literal, sal_Int32 fromIndex = 0 ) const
962  {
963  RTL_STRING_CONST_FUNCTION
964  assert(
966  assert(fromIndex >= 0);
967  return
969  pData->buffer + fromIndex, pData->length - fromIndex,
971  literal),
974  == 0;
975  }
976 
993  bool matchL(
994  char const * str, sal_Int32 strLength, sal_Int32 fromIndex = 0)
995  const
996  {
997  assert(fromIndex >= 0);
999  pData->buffer + fromIndex, pData->length - fromIndex,
1000  str, strLength, strLength) == 0;
1001  }
1002 
1003  // This overload is left undefined, to detect calls of matchL that
1004  // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
1005  // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
1006  // platforms):
1007 #if SAL_TYPES_SIZEOFLONG == 8
1008  void matchL(char const *, sal_Int32, rtl_TextEncoding) const;
1009 #endif
1010 
1029 #if defined LIBO_INTERNAL_ONLY
1030  bool matchIgnoreAsciiCase( std::string_view str, sal_Int32 fromIndex = 0 ) const
1031  {
1032  assert(fromIndex >= 0);
1033  return rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
1034  str.data(), str.size(),
1035  str.size() ) == 0;
1036  }
1037 #else
1038  bool matchIgnoreAsciiCase( const OString & str, sal_Int32 fromIndex = 0 ) const
1039  {
1040  assert(fromIndex >= 0);
1041  return rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
1042  str.pData->buffer, str.pData->length,
1043  str.pData->length ) == 0;
1044  }
1045 #endif
1051  template< typename T >
1052  typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type matchIgnoreAsciiCase( T& literal, sal_Int32 fromIndex = 0 ) const
1053  {
1054  RTL_STRING_CONST_FUNCTION
1055  assert(
1057  assert(fromIndex >= 0);
1058  return
1060  pData->buffer+fromIndex, pData->length-fromIndex,
1062  literal),
1065  == 0;
1066  }
1067 
1068 #if defined LIBO_INTERNAL_ONLY
1079  bool startsWith(std::string_view str) const {
1080  return match(str);
1081  }
1095  bool startsWith(std::string_view str, OString * rest) const {
1096  assert(rest);
1097  bool b = startsWith(str);
1098  if (b) {
1099  *rest = copy(str.size());
1100  }
1101  return b;
1102  }
1116  bool startsWith(std::string_view str, std::string_view * rest) const {
1117  assert(rest);
1118  bool b = startsWith(str);
1119  if (b) {
1120  *rest = subView(str.size());
1121  }
1122  return b;
1123  }
1124 #else
1139  bool startsWith(OString const & str, OString * rest = NULL) const {
1140  bool b = match(str);
1141  if (b && rest != NULL) {
1142  *rest = copy(str.getLength());
1143  }
1144  return b;
1145  }
1146 #endif
1147 
1148 #if defined LIBO_INTERNAL_ONLY
1154  template< typename T >
1156  T & literal) const
1157  {
1158  RTL_STRING_CONST_FUNCTION
1159  return match(literal, 0);
1160  }
1166  template< typename T >
1167  typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type startsWith(
1168  T & literal, OString * rest) const
1169  {
1170  RTL_STRING_CONST_FUNCTION
1171  assert(rest);
1172  bool b = startsWith(literal);
1173  if (b) {
1174  *rest = copy(
1175  libreoffice_internal::ConstCharArrayDetector<T>::length);
1176  }
1177  return b;
1178  }
1183  template< typename T >
1184  typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type startsWith(
1185  T & literal, std::string_view * rest) const
1186  {
1187  RTL_STRING_CONST_FUNCTION
1188  assert(rest);
1189  bool b = startsWith(literal);
1190  if (b) {
1191  *rest = subView(
1192  libreoffice_internal::ConstCharArrayDetector<T>::length);
1193  }
1194  return b;
1195  }
1196 #else
1202  template< typename T >
1204  T & literal, OString * rest = NULL) const
1205  {
1206  RTL_STRING_CONST_FUNCTION
1207  bool b = match(literal, 0);
1208  if (b && rest != NULL) {
1209  *rest = copy(
1211  }
1212  return b;
1213  }
1214 #endif
1215 
1225  bool startsWith(char ch) const
1226  {
1227  return !isEmpty() && pData->buffer[0] == ch;
1228  }
1229 
1242  bool startsWith(char ch, OString* rest) const {
1243  assert(rest);
1244  bool b = startsWith(ch);
1245 
1246  if (b)
1247  *rest = copy(1);
1248 
1249  return b;
1250  }
1251 
1252 #if defined LIBO_INTERNAL_ONLY
1265  bool startsWith(char ch, std::string_view* rest) const {
1266  assert(rest);
1267  bool b = startsWith(ch);
1268 
1269  if (b)
1270  *rest = subView(1);
1271 
1272  return b;
1273  }
1274 #endif
1275 
1276 #if defined LIBO_INTERNAL_ONLY
1293  bool startsWithIgnoreAsciiCase(std::string_view str)
1294  const
1295  {
1296  return matchIgnoreAsciiCase(str);
1297  }
1317  bool startsWithIgnoreAsciiCase(std::string_view str, OString * rest)
1318  const
1319  {
1320  assert(rest);
1321  bool b = startsWithIgnoreAsciiCase(str);
1322  if (b) {
1323  *rest = copy(str.size());
1324  }
1325  return b;
1326  }
1346  bool startsWithIgnoreAsciiCase(std::string_view str, std::string_view * rest)
1347  const
1348  {
1349  assert(rest);
1350  bool b = startsWithIgnoreAsciiCase(str);
1351  if (b) {
1352  *rest = subView(str.size());
1353  }
1354  return b;
1355  }
1356 #else
1376  bool startsWithIgnoreAsciiCase(OString const & str, OString * rest = NULL)
1377  const
1378  {
1379  bool b = matchIgnoreAsciiCase(str);
1380  if (b && rest != NULL) {
1381  *rest = copy(str.getLength());
1382  }
1383  return b;
1384  }
1385 #endif
1386 
1387 #if defined LIBO_INTERNAL_ONLY
1393  template< typename T >
1395  startsWithIgnoreAsciiCase(T & literal) const
1396  {
1397  RTL_STRING_CONST_FUNCTION
1398  assert(
1400  return matchIgnoreAsciiCase(literal);
1401  }
1407  template< typename T >
1408  typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
1409  startsWithIgnoreAsciiCase(T & literal, OString * rest) const
1410  {
1411  RTL_STRING_CONST_FUNCTION
1412  assert(rest);
1413  bool b = startsWithIgnoreAsciiCase(literal);
1414  if (b) {
1415  *rest = copy(
1416  libreoffice_internal::ConstCharArrayDetector<T>::length);
1417  }
1418  return b;
1419  }
1420  template< typename T >
1421  typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
1422  startsWithIgnoreAsciiCase(T & literal, std::string_view * rest) const
1423  {
1424  RTL_STRING_CONST_FUNCTION
1425  assert(rest);
1426  bool b = startsWithIgnoreAsciiCase(literal);
1427  if (b) {
1428  *rest = subView(
1429  libreoffice_internal::ConstCharArrayDetector<T>::length);
1430  }
1431  return b;
1432  }
1433 #else
1439  template< typename T >
1440  typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
1441  startsWithIgnoreAsciiCase(T & literal, OString * rest = NULL) const
1442  {
1443  RTL_STRING_CONST_FUNCTION
1444  assert(
1446  bool b = matchIgnoreAsciiCase(literal);
1447  if (b && rest != NULL) {
1448  *rest = copy(
1450  }
1451  return b;
1452  }
1453 #endif
1454 
1455 #if defined LIBO_INTERNAL_ONLY
1466  bool endsWith(std::string_view str) const {
1467  return str.size() <= sal_uInt32(getLength())
1468  && match(str, getLength() - str.size());
1469  }
1484  bool endsWith(std::string_view str, OString * rest) const {
1485  assert(rest);
1486  bool b = endsWith(str);
1487  if (b) {
1488  *rest = copy(0, getLength() - str.size());
1489  }
1490  return b;
1491  }
1505  bool endsWith(std::string_view str, std::string_view * rest) const {
1506  assert(rest);
1507  bool b = endsWith(str);
1508  if (b) {
1509  *rest = subView(0, getLength() - str.size());
1510  }
1511  return b;
1512  }
1513 #else
1528  bool endsWith(OString const & str, OString * rest = NULL) const {
1529  bool b = str.getLength() <= getLength()
1530  && match(str, getLength() - str.getLength());
1531  if (b && rest != NULL) {
1532  *rest = copy(0, getLength() - str.getLength());
1533  }
1534  return b;
1535  }
1536 #endif
1537 
1538 #if defined LIBO_INTERNAL_ONLY
1544  template< typename T >
1546  T & literal) const
1547  {
1548  RTL_STRING_CONST_FUNCTION
1549  assert(
1551  bool b
1553  <= sal_uInt32(getLength()))
1554  && match(
1556  literal),
1557  (getLength()
1559  return b;
1560  }
1566  template< typename T >
1567  typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type endsWith(
1568  T & literal, OString * rest) const
1569  {
1570  RTL_STRING_CONST_FUNCTION
1571  assert(rest);
1572  bool b = endsWith(literal);
1573  if (b) {
1574  *rest = copy(
1575  0,
1576  (getLength()
1577  - libreoffice_internal::ConstCharArrayDetector<T>::length));
1578  }
1579  return b;
1580  }
1586  template< typename T >
1587  typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type endsWith(
1588  T & literal, std::string_view * rest) const
1589  {
1590  RTL_STRING_CONST_FUNCTION
1591  assert(rest);
1592  bool b = endsWith(literal);
1593  if (b) {
1594  *rest = subView(
1595  0,
1596  (getLength()
1597  - libreoffice_internal::ConstCharArrayDetector<T>::length));
1598  }
1599  return b;
1600  }
1601 #else
1607  template< typename T >
1609  T & literal, OString * rest = NULL) const
1610  {
1611  RTL_STRING_CONST_FUNCTION
1612  assert(
1614  bool b
1616  <= sal_uInt32(getLength()))
1617  && match(
1619  literal),
1620  (getLength()
1622  if (b && rest != NULL) {
1623  *rest = copy(
1624  0,
1625  (getLength()
1627  }
1628  return b;
1629  }
1630 #endif
1631 
1645  bool endsWithL(char const * str, sal_Int32 strLength) const {
1646  return strLength <= getLength()
1647  && matchL(str, strLength, getLength() - strLength);
1648  }
1649 
1659  bool endsWith(char ch) const
1660  {
1661  return !isEmpty() && pData->buffer[pData->length - 1] == ch;
1662  }
1663 
1676  bool endsWith(char ch, OString* rest) const {
1677  assert(rest);
1678  bool b = endsWith(ch);
1679 
1680  if (b)
1681  *rest = copy(0, pData->length - 1);
1682 
1683  return b;
1684  }
1685 
1686 #if defined LIBO_INTERNAL_ONLY
1699  bool endsWith(char ch, std::string_view* rest) const {
1700  assert(rest);
1701  bool b = endsWith(ch);
1702 
1703  if (b)
1704  *rest = subView(0, pData->length - 1);
1705 
1706  return b;
1707  }
1708 #endif
1709 
1710  friend bool operator == ( const OString& rStr1, const OString& rStr2 )
1711  { return rStr1.equals(rStr2); }
1712  friend bool operator != ( const OString& rStr1, const OString& rStr2 )
1713  { return !(operator == ( rStr1, rStr2 )); }
1714  friend bool operator < ( const OString& rStr1, const OString& rStr2 )
1715  { return rStr1.compareTo( rStr2 ) < 0; }
1716  friend bool operator > ( const OString& rStr1, const OString& rStr2 )
1717  { return rStr1.compareTo( rStr2 ) > 0; }
1718  friend bool operator <= ( const OString& rStr1, const OString& rStr2 )
1719  { return rStr1.compareTo( rStr2 ) <= 0; }
1720  friend bool operator >= ( const OString& rStr1, const OString& rStr2 )
1721  { return rStr1.compareTo( rStr2 ) >= 0; }
1722 
1723  template< typename T >
1724  friend typename libreoffice_internal::CharPtrDetector< T, bool >::Type operator==( const OString& rStr1, const T& value )
1725  {
1726  return
1728  rStr1.getStr(), rStr1.getLength(), value, rtl_str_getLength(value))
1729  == 0;
1730  }
1731 
1732  template< typename T >
1734  {
1735  return
1737  rStr1.getStr(), rStr1.getLength(), value, rtl_str_getLength(value))
1738  == 0;
1739  }
1740 
1741  template< typename T >
1742  friend typename libreoffice_internal::CharPtrDetector< T, bool >::Type operator==( const T& value, const OString& rStr2 )
1743  {
1744  return
1746  value, rtl_str_getLength(value), rStr2.getStr(), rStr2.getLength())
1747  == 0;
1748  }
1749 
1750  template< typename T >
1752  {
1753  return
1755  value, rtl_str_getLength(value), rStr2.getStr(), rStr2.getLength())
1756  == 0;
1757  }
1758 
1764  template< typename T >
1766  {
1767  RTL_STRING_CONST_FUNCTION
1768  assert(
1770  return
1771  (rStr.getLength()
1774  rStr.pData->buffer, rStr.pData->length,
1776  literal),
1778  == 0);
1779  }
1780 
1786  template< typename T >
1788  {
1789  RTL_STRING_CONST_FUNCTION
1790  assert(
1792  return
1793  (rStr.getLength()
1796  rStr.pData->buffer, rStr.pData->length,
1798  literal),
1800  == 0);
1801  }
1802 
1803  template< typename T >
1804  friend typename libreoffice_internal::CharPtrDetector< T, bool >::Type operator!=( const OString& rStr1, const T& value )
1805  {
1806  return !(operator == ( rStr1, value ));
1807  }
1808 
1809  template< typename T >
1811  {
1812  return !(operator == ( rStr1, value ));
1813  }
1814 
1815  template< typename T >
1816  friend typename libreoffice_internal::CharPtrDetector< T, bool >::Type operator!=( const T& value, const OString& rStr2 )
1817  {
1818  return !(operator == ( value, rStr2 ));
1819  }
1820 
1821  template< typename T >
1823  {
1824  return !(operator == ( value, rStr2 ));
1825  }
1826 
1832  template< typename T >
1834  {
1835  return !( rStr == literal );
1836  }
1837 
1843  template< typename T >
1845  {
1846  return !( literal == rStr );
1847  }
1848 
1856  sal_Int32 hashCode() const
1857  {
1858  return rtl_str_hashCode_WithLength( pData->buffer, pData->length );
1859  }
1860 
1874  sal_Int32 indexOf( char ch, sal_Int32 fromIndex = 0 ) const
1875  {
1876  assert(fromIndex >= 0);
1877  sal_Int32 ret = rtl_str_indexOfChar_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, ch );
1878  return (ret < 0 ? ret : ret+fromIndex);
1879  }
1880 
1890  sal_Int32 lastIndexOf( char ch ) const
1891  {
1892  return rtl_str_lastIndexOfChar_WithLength( pData->buffer, pData->length, ch );
1893  }
1894 
1907  sal_Int32 lastIndexOf( char ch, sal_Int32 fromIndex ) const
1908  {
1909  return rtl_str_lastIndexOfChar_WithLength( pData->buffer, fromIndex, ch );
1910  }
1911 
1927 #if defined LIBO_INTERNAL_ONLY
1928  sal_Int32 indexOf( std::string_view str, sal_Int32 fromIndex = 0 ) const
1929  {
1930  assert(fromIndex >= 0);
1931  sal_Int32 ret = rtl_str_indexOfStr_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
1932  str.data(), str.size() );
1933  return (ret < 0 ? ret : ret+fromIndex);
1934  }
1935 #else
1936  sal_Int32 indexOf( const OString & str, sal_Int32 fromIndex = 0 ) const
1937  {
1938  assert(fromIndex >= 0);
1939  sal_Int32 ret = rtl_str_indexOfStr_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
1940  str.pData->buffer, str.pData->length );
1941  return (ret < 0 ? ret : ret+fromIndex);
1942  }
1943 #endif
1949  template< typename T >
1950  typename libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type indexOf( T& literal, sal_Int32 fromIndex = 0 ) const
1951  {
1952  RTL_STRING_CONST_FUNCTION
1953  assert(
1955  assert(fromIndex >= 0);
1956  sal_Int32 n = rtl_str_indexOfStr_WithLength(
1957  pData->buffer + fromIndex, pData->length - fromIndex,
1960  return n < 0 ? n : n + fromIndex;
1961  }
1962 
1981  sal_Int32 indexOfL(char const * str, sal_Int32 len, sal_Int32 fromIndex = 0)
1982  const
1983  {
1984  assert(fromIndex >= 0);
1985  sal_Int32 n = rtl_str_indexOfStr_WithLength(
1986  pData->buffer + fromIndex, pData->length - fromIndex, str, len);
1987  return n < 0 ? n : n + fromIndex;
1988  }
1989 
1990  // This overload is left undefined, to detect calls of indexOfL that
1991  // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
1992  // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
1993  // platforms):
1994 #if SAL_TYPES_SIZEOFLONG == 8
1995  void indexOfL(char const *, sal_Int32, rtl_TextEncoding) const;
1996 #endif
1997 
2013 #if defined LIBO_INTERNAL_ONLY
2014  sal_Int32 lastIndexOf( std::string_view str ) const
2015  {
2016  return rtl_str_lastIndexOfStr_WithLength( pData->buffer, pData->length,
2017  str.data(), str.size() );
2018  }
2019 #else
2020  sal_Int32 lastIndexOf( const OString & str ) const
2021  {
2022  return rtl_str_lastIndexOfStr_WithLength( pData->buffer, pData->length,
2023  str.pData->buffer, str.pData->length );
2024  }
2025 #endif
2026 
2044 #if defined LIBO_INTERNAL_ONLY
2045  sal_Int32 lastIndexOf( std::string_view str, sal_Int32 fromIndex ) const
2046  {
2047  return rtl_str_lastIndexOfStr_WithLength( pData->buffer, fromIndex,
2048  str.data(), str.size() );
2049  }
2050 #else
2051  sal_Int32 lastIndexOf( const OString & str, sal_Int32 fromIndex ) const
2052  {
2053  return rtl_str_lastIndexOfStr_WithLength( pData->buffer, fromIndex,
2054  str.pData->buffer, str.pData->length );
2055  }
2056 #endif
2057 
2068  SAL_WARN_UNUSED_RESULT OString copy( sal_Int32 beginIndex ) const
2069  {
2070  return copy(beginIndex, getLength() - beginIndex);
2071  }
2072 
2085  SAL_WARN_UNUSED_RESULT OString copy( sal_Int32 beginIndex, sal_Int32 count ) const
2086  {
2087  rtl_String *pNew = NULL;
2088  rtl_string_newFromSubString( &pNew, pData, beginIndex, count );
2089  return OString( pNew, SAL_NO_ACQUIRE );
2090  }
2091 
2092 #if defined LIBO_INTERNAL_ONLY
2103  SAL_WARN_UNUSED_RESULT std::string_view subView( sal_Int32 beginIndex ) const
2104  {
2105  assert(beginIndex >= 0);
2106  assert(beginIndex <= getLength());
2107  return subView(beginIndex, getLength() - beginIndex);
2108  }
2109 
2122  SAL_WARN_UNUSED_RESULT std::string_view subView( sal_Int32 beginIndex, sal_Int32 count ) const
2123  {
2124  assert(beginIndex >= 0);
2125  assert(count >= 0);
2126  assert(beginIndex <= getLength());
2127  assert(count <= getLength() - beginIndex);
2128  return std::string_view(*this).substr(beginIndex, count);
2129  }
2130 #endif
2131 
2132 #ifndef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
2141  SAL_WARN_UNUSED_RESULT OString concat( const OString & str ) const
2142  {
2143  rtl_String* pNew = NULL;
2144  rtl_string_newConcat( &pNew, pData, str.pData );
2145  return OString( pNew, SAL_NO_ACQUIRE );
2146  }
2147 #endif
2148 
2149 #ifndef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
2150  friend OString operator+( const OString & str1, const OString & str2 )
2151  {
2152  return str1.concat( str2 );
2153  }
2154 #endif
2155 
2156 // hide this from internal code to avoid ambiguous lookup error
2157 #ifndef LIBO_INTERNAL_ONLY
2171  SAL_WARN_UNUSED_RESULT OString replaceAt( sal_Int32 index, sal_Int32 count, const OString& newStr ) const
2172  {
2173  rtl_String* pNew = NULL;
2174  rtl_string_newReplaceStrAt( &pNew, pData, index, count, newStr.pData );
2175  return OString( pNew, SAL_NO_ACQUIRE );
2176  }
2177 #endif
2178 
2179 #ifdef LIBO_INTERNAL_ONLY
2180  SAL_WARN_UNUSED_RESULT OString replaceAt( sal_Int32 index, sal_Int32 count, std::string_view newStr ) const
2181  {
2182  rtl_String* pNew = NULL;
2183  rtl_string_newReplaceStrAt_WithLength ( &pNew, pData, index, count, newStr.data(), newStr.size() );
2184  return OString( pNew, SAL_NO_ACQUIRE );
2185  }
2186 #endif
2187 
2201  SAL_WARN_UNUSED_RESULT OString replace( char oldChar, char newChar ) const
2202  {
2203  rtl_String* pNew = NULL;
2204  rtl_string_newReplace( &pNew, pData, oldChar, newChar );
2205  return OString( pNew, SAL_NO_ACQUIRE );
2206  }
2207 
2227  OString const & from, OString const & to, sal_Int32 * index = NULL) const
2228  {
2229  rtl_String * s = NULL;
2230  sal_Int32 i = 0;
2232  &s, pData, from.pData->buffer, from.pData->length,
2233  to.pData->buffer, to.pData->length, index == NULL ? &i : index);
2234  return OString(s, SAL_NO_ACQUIRE);
2235  }
2236 
2250  SAL_WARN_UNUSED_RESULT OString replaceAll(OString const & from, OString const & to) const {
2251  rtl_String * s = NULL;
2253  &s, pData, from.pData->buffer, from.pData->length,
2254  to.pData->buffer, to.pData->length);
2255  return OString(s, SAL_NO_ACQUIRE);
2256  }
2257 
2269  {
2270  rtl_String* pNew = NULL;
2271  rtl_string_newToAsciiLowerCase( &pNew, pData );
2272  return OString( pNew, SAL_NO_ACQUIRE );
2273  }
2274 
2286  {
2287  rtl_String* pNew = NULL;
2288  rtl_string_newToAsciiUpperCase( &pNew, pData );
2289  return OString( pNew, SAL_NO_ACQUIRE );
2290  }
2291 
2304  {
2305  rtl_String* pNew = NULL;
2306  rtl_string_newTrim( &pNew, pData );
2307  return OString( pNew, SAL_NO_ACQUIRE );
2308  }
2309 
2334  OString getToken( sal_Int32 token, char cTok, sal_Int32& index ) const
2335  {
2336  rtl_String * pNew = NULL;
2337  index = rtl_string_getToken( &pNew, pData, token, cTok, index );
2338  return OString( pNew, SAL_NO_ACQUIRE );
2339  }
2340 
2354  OString getToken(sal_Int32 count, char separator) const {
2355  sal_Int32 n = 0;
2356  return getToken(count, separator, n);
2357  }
2358 
2367  bool toBoolean() const
2368  {
2369  return rtl_str_toBoolean( pData->buffer );
2370  }
2371 
2378  char toChar() const
2379  {
2380  return pData->buffer[0];
2381  }
2382 
2393  sal_Int32 toInt32( sal_Int16 radix = 10 ) const
2394  {
2395  return rtl_str_toInt32( pData->buffer, radix );
2396  }
2397 
2410  sal_uInt32 toUInt32( sal_Int16 radix = 10 ) const
2411  {
2412  return rtl_str_toUInt32( pData->buffer, radix );
2413  }
2414 
2425  sal_Int64 toInt64( sal_Int16 radix = 10 ) const
2426  {
2427  return rtl_str_toInt64( pData->buffer, radix );
2428  }
2429 
2442  sal_uInt64 toUInt64( sal_Int16 radix = 10 ) const
2443  {
2444  return rtl_str_toUInt64( pData->buffer, radix );
2445  }
2446 
2455  float toFloat() const
2456  {
2457  return rtl_str_toFloat( pData->buffer );
2458  }
2459 
2468  double toDouble() const
2469  {
2470  return rtl_str_toDouble( pData->buffer );
2471  }
2472 
2473 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
2474 
2475  static auto number( int i, sal_Int16 radix = 10 )
2476  {
2477  return OStringNumber<RTL_STR_MAX_VALUEOFINT32>(rtl_str_valueOfInt32, i, radix);
2478  }
2479  static auto number( long long ll, sal_Int16 radix = 10 )
2480  {
2481  return OStringNumber<RTL_STR_MAX_VALUEOFINT64>(rtl_str_valueOfInt64, ll, radix);
2482  }
2483  static auto number( unsigned long long ll, sal_Int16 radix = 10 )
2484  {
2485  return OStringNumber<RTL_STR_MAX_VALUEOFUINT64>(rtl_str_valueOfUInt64, ll, radix);
2486  }
2487  static auto number( unsigned int i, sal_Int16 radix = 10 )
2488  {
2489  return number( static_cast< unsigned long long >( i ), radix );
2490  }
2491  static auto number( long i, sal_Int16 radix = 10)
2492  {
2493  return number( static_cast< long long >( i ), radix );
2494  }
2495  static auto number( unsigned long i, sal_Int16 radix = 10 )
2496  {
2497  return number( static_cast< unsigned long long >( i ), radix );
2498  }
2499 #else
2510  static OString number( int i, sal_Int16 radix = 10 )
2511  {
2512  char aBuf[RTL_STR_MAX_VALUEOFINT32];
2513  return OString(aBuf, rtl_str_valueOfInt32(aBuf, i, radix));
2514  }
2517  static OString number( unsigned int i, sal_Int16 radix = 10 )
2518  {
2519  return number( static_cast< unsigned long long >( i ), radix );
2520  }
2523  static OString number( long i, sal_Int16 radix = 10 )
2524  {
2525  return number( static_cast< long long >( i ), radix );
2526  }
2529  static OString number( unsigned long i, sal_Int16 radix = 10 )
2530  {
2531  return number( static_cast< unsigned long long >( i ), radix );
2532  }
2535  static OString number( long long ll, sal_Int16 radix = 10 )
2536  {
2537  char aBuf[RTL_STR_MAX_VALUEOFINT64];
2538  return OString(aBuf, rtl_str_valueOfInt64(aBuf, ll, radix));
2539  }
2542  static OString number( unsigned long long ll, sal_Int16 radix = 10 )
2543  {
2544  char aBuf[RTL_STR_MAX_VALUEOFUINT64];
2545  return OString(aBuf, rtl_str_valueOfUInt64(aBuf, ll, radix));
2546  }
2547 #endif
2548 
2558  static OString number( float f )
2559  {
2560  rtl_String* pNew = NULL;
2561  // Same as rtl::str::valueOfFP, used for rtl_str_valueOfFloat
2563  RTL_STR_MAX_VALUEOFFLOAT - SAL_N_ELEMENTS("-x.E-xxx") + 1, '.',
2564  NULL, 0, true);
2565  if (pNew == NULL)
2566  throw std::bad_alloc();
2567 
2568  return OString(pNew, SAL_NO_ACQUIRE);
2569  }
2570 
2580  static OString number( double d )
2581  {
2582  rtl_String* pNew = NULL;
2583  // Same as rtl::str::valueOfFP, used for rtl_str_valueOfDouble
2585  RTL_STR_MAX_VALUEOFDOUBLE - SAL_N_ELEMENTS("-x.E-xxx") + 1, '.',
2586  NULL, 0, true);
2587  if (pNew == NULL)
2588  throw std::bad_alloc();
2589 
2590  return OString(pNew, SAL_NO_ACQUIRE);
2591  }
2592 
2593 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
2594  static auto boolean(bool b)
2595  {
2596  return OStringNumber<RTL_STR_MAX_VALUEOFBOOLEAN>(rtl_str_valueOfBoolean, b);
2597  }
2598 #else
2610  SAL_DEPRECATED("use boolean()") static OString valueOf( sal_Bool b )
2611  {
2612  return boolean(b);
2613  }
2614 
2626  static OString boolean( bool b )
2627  {
2628  char aBuf[RTL_STR_MAX_VALUEOFBOOLEAN];
2629  return OString(aBuf, rtl_str_valueOfBoolean(aBuf, b));
2630  }
2631 #endif
2632 
2640  SAL_DEPRECATED("convert to OString or use directly") static OString valueOf( char c )
2641  {
2642  return OString( &c, 1 );
2643  }
2644 
2655  SAL_DEPRECATED("use number()") static OString valueOf( sal_Int32 i, sal_Int16 radix = 10 )
2656  {
2657  return number( i, radix );
2658  }
2659 
2670  SAL_DEPRECATED("use number()") static OString valueOf( sal_Int64 ll, sal_Int16 radix = 10 )
2671  {
2672  return number( ll, radix );
2673  }
2674 
2684  SAL_DEPRECATED("use number()") static OString valueOf( float f )
2685  {
2686  return number(f);
2687  }
2688 
2698  SAL_DEPRECATED("use number()") static OString valueOf( double d )
2699  {
2700  return number(d);
2701  }
2702 
2703 #if defined LIBO_INTERNAL_ONLY
2704  operator std::string_view() const { return {getStr(), sal_uInt32(getLength())}; }
2705 #endif
2706 
2707 #if defined LIBO_INTERNAL_ONLY
2708  // A wrapper for the first expression in an
2709  //
2710  // OString::Concat(e1) + e2 + ...
2711  //
2712  // concatenation chain, when neither of the first two e1, e2 is one of our rtl string-related
2713  // classes (so something like
2714  //
2715  // OString s = "a" + (b ? std::string_view("c") : std::string_view("dd"));
2716  //
2717  // would not compile):
2718  template<typename T> [[nodiscard]] static
2719  OStringConcat<OStringConcatMarker, T>
2720  Concat(T const & value) { return OStringConcat<OStringConcatMarker, T>(value); }
2721 
2722  // This overload is needed so that an argument of type 'char const[N]' ends up as
2723  // 'OStringConcat<rtl::OStringConcatMarker, char const[N]>' rather than as
2724  // 'OStringConcat<rtl::OStringConcatMarker, char[N]>':
2725  template<typename T, std::size_t N> [[nodiscard]] static
2726  OStringConcat<OStringConcatMarker, T[N]>
2727  Concat(T (& value)[N]) { return OStringConcat<OStringConcatMarker, T[N]>(value); }
2728 #endif
2729 
2730 private:
2731 #if defined LIBO_INTERNAL_ONLY
2732  static constexpr auto empty = OStringLiteral(""); // [-loplugin:ostr]
2733 #endif
2734 };
2735 
2736 #if defined LIBO_INTERNAL_ONLY
2737 inline bool operator ==(OString const & lhs, StringConcatenation<char> const & rhs)
2738 { return lhs == std::string_view(rhs); }
2739 inline bool operator !=(OString const & lhs, StringConcatenation<char> const & rhs)
2740 { return lhs != std::string_view(rhs); }
2741 inline bool operator ==(StringConcatenation<char> const & lhs, OString const & rhs)
2742 { return std::string_view(lhs) == rhs; }
2743 inline bool operator !=(StringConcatenation<char> const & lhs, OString const & rhs)
2744 { return std::string_view(lhs) != rhs; }
2745 #endif
2746 
2747 /* ======================================================================= */
2748 
2749 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
2750 
2754 template<>
2755 struct ToStringHelper< OString >
2756 {
2757  static std::size_t length( const OString& s ) { return s.getLength(); }
2758  char* operator()( char* buffer, const OString& s ) const { return addDataHelper( buffer, s.getStr(), s.getLength()); }
2759 };
2760 
2764 template<std::size_t N>
2765 struct ToStringHelper< OStringLiteral<N> >
2766 {
2767  static constexpr std::size_t length( const OStringLiteral<N>& str ) { return str.getLength(); }
2768  char* operator()( char* buffer, const OStringLiteral<N>& str ) const { return addDataHelper( buffer, str.getStr(), str.getLength() ); }
2769 };
2770 
2774 template< typename charT, typename traits, typename T1, typename T2 >
2775 inline std::basic_ostream<charT, traits> & operator <<(
2776  std::basic_ostream<charT, traits> & stream, OStringConcat< T1, T2 >&& concat)
2777 {
2778  return stream << OString( std::move(concat) );
2779 }
2780 #endif
2781 
2782 
2789 {
2799  size_t operator()( const OString& rString ) const
2800  { return static_cast<size_t>(rString.hashCode()); }
2801 };
2802 
2805 {
2806  bool operator()( const char* p1, const char* p2) const
2807  { return rtl_str_compare(p1, p2) == 0; }
2808 };
2809 
2812 {
2813  size_t operator()(const char* p) const
2814  { return rtl_str_hashCode(p); }
2815 };
2816 
2817 /* ======================================================================= */
2818 
2825 template< typename charT, typename traits > std::basic_ostream<charT, traits> &
2826 operator <<(
2827  std::basic_ostream<charT, traits> & stream, OString const & rString)
2828 {
2829  return stream << rString.getStr();
2830  // best effort; potentially loses data due to embedded null characters
2831 }
2832 
2833 } /* Namespace */
2834 
2835 #ifdef RTL_STRING_UNITTEST
2836 namespace rtl
2837 {
2838 typedef rtlunittest::OString OString;
2839 }
2840 #undef RTL_STRING_CONST_FUNCTION
2841 #endif
2842 
2843 #if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST
2844 using ::rtl::OString;
2845 using ::rtl::OStringChar;
2846 using ::rtl::Concat2View;
2847 using ::rtl::OStringHash;
2848 using ::rtl::OStringLiteral;
2849 using RepeatedChar = ::rtl::RepeatedChar_t<char>;
2850 #endif
2851 
2852 #if defined LIBO_INTERNAL_ONLY
2853 
2854 template<
2855 #if defined RTL_STRING_UNITTEST
2856  rtlunittest::
2857 #endif
2858  OStringLiteral L>
2859 constexpr
2860 #if defined RTL_STRING_UNITTEST
2861  rtlunittest::
2862 #endif
2863  OString
2864 operator ""_ostr() { return L; }
2865 
2866 template<
2867 #if defined RTL_STRING_UNITTEST
2868  rtlunittest::
2869 #endif
2870  OStringLiteral L>
2871 constexpr
2872 #if defined RTL_STRING_UNITTEST
2873 rtlunittest
2874 #else
2875 rtl
2876 #endif
2877 ::detail::OStringHolder<L> operator ""_tstr() {
2878  return
2879 #if defined RTL_STRING_UNITTEST
2880  rtlunittest
2881 #else
2882  rtl
2883 #endif
2884  ::detail::OStringHolder<L>();
2885 }
2886 
2887 #endif
2888 
2890 
2895 #if defined LIBO_INTERNAL_ONLY
2896 namespace std {
2897 
2898 template<>
2899 struct hash<::rtl::OString>
2900 {
2901  std::size_t operator()(::rtl::OString const & s) const
2902  {
2903  if constexpr (sizeof(std::size_t) == 8)
2904  {
2905  // return a hash that uses the full 64-bit range instead of a 32-bit value
2906  size_t n = s.getLength();
2907  for (sal_Int32 i = 0, len = s.getLength(); i < len; ++i)
2908  n = 37 * n + s[i];
2909  return n;
2910  }
2911  else
2912  return std::size_t(s.hashCode());
2913  }
2914 };
2915 
2916 }
2917 
2918 #endif
2920 
2921 #endif // INCLUDED_RTL_STRING_HXX
2922 
2923 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define SAL_N_ELEMENTS(arr)
Definition: macros.h:51
#define SAL_DEPRECATED(message)
Use as follows: SAL_DEPRECATED("Don't use, it's evil.") void doit(int nPara);.
Definition: types.h:492
__sal_NoAcquire
Definition: types.h:371
@ SAL_NO_ACQUIRE
definition of a no acquire enum for ctors
Definition: types.h:374
unsigned char sal_Bool
Definition: types.h:38
sal_uInt16 sal_Unicode
Definition: types.h:123
#define SAL_WARN_UNUSED_RESULT
Use this as markup for functions and methods whose return value must be used.
Definition: types.h:288
#define SAL_WARN_UNUSED
Annotate classes where a compiler should warn if an instance is unused.
Definition: types.h:611
@ rtl_math_StringFormat_G
Like sprintf() G, 'F' or 'E' format is used depending on which one is more compact.
Definition: math.h:53
SAL_DLLPUBLIC void rtl_math_doubleToString(rtl_String **pResult, sal_Int32 *pResultCapacity, sal_Int32 nResultOffset, double fValue, enum rtl_math_StringFormat eFormat, sal_Int32 nDecPlaces, char cDecSeparator, sal_Int32 const *pGroups, char cGroupSeparator, sal_Bool bEraseTrailingDecZeros) SAL_THROW_EXTERN_C()
Conversions analogous to sprintf() using internal rounding.
SAL_DLLPUBLIC double rtl_str_toDouble(const char *str) SAL_THROW_EXTERN_C()
Interpret a string as a double.
SAL_DLLPUBLIC sal_Int32 rtl_str_compare(const char *first, const char *second) SAL_THROW_EXTERN_C()
Compare two strings.
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 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 sal_Bool rtl_str_toBoolean(const char *str) SAL_THROW_EXTERN_C()
Interpret a string as a boolean.
#define RTL_STR_MAX_VALUEOFDOUBLE
Definition: string.h:715
#define RTL_STR_MAX_VALUEOFINT32
Definition: string.h:631
SAL_DLLPUBLIC void rtl_string_acquire(rtl_String *str) SAL_THROW_EXTERN_C()
Increment the reference count of a string.
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.
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_compareIgnoreAsciiCase(const char *first, const char *second) SAL_THROW_EXTERN_C()
Compare two strings, ignoring the case of ASCII characters.
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_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.
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.
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_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.
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.
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.
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_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 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.
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_new(rtl_String **newStr) SAL_THROW_EXTERN_C()
Allocate a new string containing no characters.
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.
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_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 sal_Int32 rtl_str_valueOfBoolean(char *str, sal_Bool b) SAL_THROW_EXTERN_C()
Create the string representation of a boolean.
#define OUSTRING_TO_OSTRING_CVTFLAGS
Definition: string.h:1350
SAL_DLLPUBLIC void rtl_string_newFromLiteral(rtl_String **newStr, const char *value, sal_Int32 len, sal_Int32 allocExtra) SAL_THROW_EXTERN_C()
#define RTL_STR_MAX_VALUEOFBOOLEAN
Definition: string.h:589
#define RTL_STR_MAX_VALUEOFFLOAT
Definition: string.h:696
SAL_DLLPUBLIC sal_Int32 rtl_str_hashCode(const char *str) SAL_THROW_EXTERN_C()
Return a hash code for a string.
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.
SAL_DLLPUBLIC sal_Int32 rtl_str_getLength(const char *str) SAL_THROW_EXTERN_C()
Return the length of a string.
#define RTL_STR_MAX_VALUEOFUINT64
Definition: string.h:677
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 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 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 sal_Int32 rtl_str_toInt32(const char *str, sal_Int16 radix) SAL_THROW_EXTERN_C()
Interpret a string as an integer.
#define RTL_STR_MAX_VALUEOFINT64
Definition: string.h:654
SAL_DLLPUBLIC void rtl_string_ensureCapacity(rtl_String **str, sal_Int32 size) SAL_THROW_EXTERN_C()
Ensure a string has enough space for a given number of characters.
SAL_DLLPUBLIC void rtl_string_release(rtl_String *str) SAL_THROW_EXTERN_C()
Decrement the reference count of a string.
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 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_valueOfUInt64(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_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_DLLPUBLIC float rtl_str_toFloat(const char *str) SAL_THROW_EXTERN_C()
Interpret a string as a float.
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.
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 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.
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.
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.
sal_uInt16 rtl_TextEncoding
The various supported text encodings.
Definition: textenc.h:37
sal_Int32 oslInterlockedCount
Definition: interlck.h:44
bool operator<(const TTimeValue &rTimeA, const TTimeValue &rTimeB)
Definition: timer.hxx:93
bool operator>(const TTimeValue &rTimeA, const TTimeValue &rTimeB)
Definition: timer.hxx:103
bool operator==(const TTimeValue &rTimeA, const TTimeValue &rTimeB)
Definition: timer.hxx:113
Definition: bootstrap.hxx:34
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:2826
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:660
This String class provide base functionality for C++ like 8-Bit character array handling.
Definition: string.hxx:189
SAL_WARN_UNUSED_RESULT OString concat(const OString &str) const
Concatenates the specified string to the end of this string.
Definition: string.hxx:2141
OString(T &literal, typename libreoffice_internal::ConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type=libreoffice_internal::Dummy())
New string from a string literal.
Definition: string.hxx:344
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:420
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:1608
OString & operator+=(const OString &str)
Append a string to this string.
Definition: string.hxx:558
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:2529
bool startsWith(OString const &str, OString *rest=NULL) const
Check whether this string starts with a given substring.
Definition: string.hxx:1139
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:1765
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:1203
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:1787
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:1950
OString(const char *value, sal_Int32 length)
New string from a character buffer array.
Definition: string.hxx:371
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:2542
static OString number(int i, sal_Int16 radix=10)
Returns the string representation of the integer argument.
Definition: string.hxx:2510
sal_uInt64 toUInt64(sal_Int16 radix=10) const
Returns the uint64 value from this string.
Definition: string.hxx:2442
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:1981
sal_Int32 compareTo(const OString &str) const
Compares two strings.
Definition: string.hxx:718
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:880
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:2285
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:1441
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:1844
char toChar() const
Returns the first character from this string.
Definition: string.hxx:2378
bool toBoolean() const
Returns the Boolean value from this string.
Definition: string.hxx:2367
friend OString operator+(const OString &str1, const OString &str2)
Definition: string.hxx:2150
SAL_WARN_UNUSED_RESULT OString copy(sal_Int32 beginIndex) const
Returns a new string that is a substring of this string.
Definition: string.hxx:2068
friend libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type operator!=(const OString &rStr1, T &value)
Definition: string.hxx:1810
OString(rtl_String *str)
New string from OString data.
Definition: string.hxx:267
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:1376
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:2535
sal_Int32 lastIndexOf(const OString &str) const
Returns the index within this string of the last occurrence of the specified substring,...
Definition: string.hxx:2020
void clear()
Clears the string, i.e, makes a zero-character string.
Definition: string.hxx:650
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:2226
OString getToken(sal_Int32 count, char separator) const
Returns a token from the string.
Definition: string.hxx:2354
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:2517
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:1052
sal_Int32 compareTo(const OString &rObj, sal_Int32 maxLength) const
Compares two strings with an maximum count of characters.
Definition: string.hxx:737
bool endsWith(char ch) const
Check whether this string ends with a given character.
Definition: string.hxx:1659
bool isEmpty() const
Checks if a string is empty.
Definition: string.hxx:673
friend libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type operator==(T &value, const OString &rStr2)
Definition: string.hxx:1751
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:311
OString getToken(sal_Int32 token, char cTok, sal_Int32 &index) const
Returns a token in the string.
Definition: string.hxx:2334
sal_Int32 reverseCompareTo(const OString &str) const
Compares two strings in reverse order.
Definition: string.hxx:755
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:2051
sal_Int32 lastIndexOf(char ch) const
Returns the index within this string of the last occurrence of the specified character,...
Definition: string.hxx:1890
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:2085
friend libreoffice_internal::CharPtrDetector< T, bool >::Type operator!=(const OString &rStr1, const T &value)
Definition: string.hxx:1804
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:2201
sal_Int32 hashCode() const
Returns a hashcode for this string.
Definition: string.hxx:1856
static OString boolean(bool b)
Returns the string representation of the boolean argument.
Definition: string.hxx:2626
bool matchL(char const *str, sal_Int32 strLength, sal_Int32 fromIndex=0) const
Match against a substring appearing in this string.
Definition: string.hxx:993
bool equalsL(const char *value, sal_Int32 length) const
Perform a comparison of two strings.
Definition: string.hxx:796
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:2303
OString(const OString &str)
New string from OString.
Definition: string.hxx:219
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:2250
bool endsWithL(char const *str, sal_Int32 strLength) const
Check whether this string ends with a given substring.
Definition: string.hxx:1645
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:2268
bool match(const OString &str, sal_Int32 fromIndex=0) const
Match against a substring appearing in this string.
Definition: string.hxx:947
const char * getStr() const SAL_RETURNS_NONNULL
Returns a pointer to the characters of this string.
Definition: string.hxx:689
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:536
float toFloat() const
Returns the float value from this string.
Definition: string.hxx:2455
OString()
New string containing no characters.
Definition: string.hxx:201
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:961
friend libreoffice_internal::CharPtrDetector< T, bool >::Type operator==(const T &value, const OString &rStr2)
Definition: string.hxx:1742
OString(char value)
New string from a single character.
Definition: string.hxx:290
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:2523
bool startsWith(char ch, OString *rest) const
Check whether this string starts with a given character.
Definition: string.hxx:1242
bool equalsIgnoreAsciiCase(const OString &str) const
Perform an ASCII lowercase comparison of two strings.
Definition: string.hxx:830
sal_Int64 toInt64(sal_Int16 radix=10) const
Returns the int64 value from this string.
Definition: string.hxx:2425
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:1936
sal_Int32 toInt32(sal_Int16 radix=10) const
Returns the int32 value from this string.
Definition: string.hxx:2393
~OString()
Release the string data.
Definition: string.hxx:469
libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type equalsIgnoreAsciiCase(T &asciiStr) const
Definition: string.hxx:869
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:1833
OString & operator=(const OString &str)
Assign a new string.
Definition: string.hxx:505
bool startsWith(char ch) const
Check whether this string starts with a given character.
Definition: string.hxx:1225
libreoffice_internal::CharPtrDetector< T, bool >::Type equalsIgnoreAsciiCase(const T &asciiStr) const
Perform an ASCII lowercase comparison of two strings.
Definition: string.hxx:863
sal_Int32 indexOf(char ch, sal_Int32 fromIndex=0) const
Returns the index within this string of the first occurrence of the specified character,...
Definition: string.hxx:1874
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:2171
sal_Int32 getLength() const
Returns the length of this string.
Definition: string.hxx:663
double toDouble() const
Returns the double value from this string.
Definition: string.hxx:2468
static OString number(double d)
Returns the string representation of the double argument.
Definition: string.hxx:2580
bool endsWith(OString const &str, OString *rest=NULL) const
Check whether this string ends with a given substring.
Definition: string.hxx:1528
bool equals(const OString &str) const
Perform a comparison of two strings.
Definition: string.hxx:772
friend libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type operator==(const OString &rStr1, T &value)
Definition: string.hxx:1733
OString(rtl_String *str, __sal_NoAcquire)
New string from OString data without acquiring it.
Definition: string.hxx:280
sal_Int32 lastIndexOf(char ch, sal_Int32 fromIndex) const
Returns the index within this string of the last occurrence of the specified character,...
Definition: string.hxx:1907
OString(T &value, typename libreoffice_internal::NonConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type=libreoffice_internal::Dummy())
Definition: string.hxx:318
friend libreoffice_internal::CharPtrDetector< T, bool >::Type operator==(const OString &rStr1, const T &value)
Definition: string.hxx:1724
sal_uInt32 toUInt32(sal_Int16 radix=10) const
Returns the uint32 value from this string.
Definition: string.hxx:2410
static OString number(float f)
Returns the string representation of the float argument.
Definition: string.hxx:2558
bool endsWith(char ch, OString *rest) const
Check whether this string ends with a given character.
Definition: string.hxx:1676
friend libreoffice_internal::CharPtrDetector< T, bool >::Type operator!=(const T &value, const OString &rStr2)
Definition: string.hxx:1816
bool equalsIgnoreAsciiCaseL(const char *asciiStr, sal_Int32 asciiStrLength) const
Perform an ASCII lowercase comparison of two strings.
Definition: string.hxx:915
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:1038
friend libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type operator!=(T &value, const OString &rStr2)
Definition: string.hxx:1822
A helper to use OStrings with hash maps.
Definition: string.hxx:2789
size_t operator()(const OString &rString) const
Compute a hash code for a string.
Definition: string.hxx:2799
Equality functor for classic c-strings (i.e., null-terminated char* strings).
Definition: string.hxx:2805
bool operator()(const char *p1, const char *p2) const
Definition: string.hxx:2806
Hashing functor for classic c-strings (i.e., null-terminated char* strings).
Definition: string.hxx:2812
size_t operator()(const char *p) const
Definition: string.hxx:2813
Definition: stringutils.hxx:178
Definition: stringutils.hxx:181