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 #if !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
152 
153 namespace detail {
154 
155 template<OStringLiteral L> struct OStringHolder {
156  static constexpr auto & literal = L;
157 };
158 
159 }
160 
161 #endif
162 
163 #endif
164 
165 /* ======================================================================= */
166 
191 // coverity[ missing_move_assignment : SUPPRESS] - don't report the suppressed move assignment
192 class SAL_WARN_UNUSED SAL_DLLPUBLIC_RTTI OString
193 {
194 public:
196  rtl_String * pData;
198 
202 #if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
203  constexpr
204 #endif
206  {
207 #if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
208  pData = const_cast<rtl_String *>(&empty.str);
209 #else
210  pData = NULL;
211  rtl_string_new( &pData );
212 #endif
213  }
214 
220 #if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
221  constexpr
222 #endif
223  OString( const OString & str )
224  {
225  pData = str.pData;
226 #if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
227  if (std::is_constant_evaluated()) {
228  //TODO: We would want to
229  //
230  // assert(SAL_STRING_IS_STATIC(pData));
231  //
232  // here, but that wouldn't work because read of member `str` of OUStringLiteral's
233  // anonymous union with active member `more` is not allowed in a constant expression.
234  } else
235 #endif
236  rtl_string_acquire( pData );
237  }
238 
239 #if defined LIBO_INTERNAL_ONLY
240 #if !defined(__COVERITY__) // suppress COPY_INSTEAD_OF_MOVE suggestions
247 #if !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
248  constexpr
249 #endif
250  OString( OString && str ) noexcept
251  {
252  pData = str.pData;
253 #if !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
254  if (std::is_constant_evaluated()) {
255  //TODO: We would want to
256  //
257  // assert(SAL_STRING_IS_STATIC(pData));
258  //
259  // here, but that wouldn't work because read of member `str` of OUStringLiteral's
260  // anonymous union with active member `more` is not allowed in a constant expression.
261  return;
262  }
263 #endif
264  str.pData = nullptr;
265  rtl_string_new( &str.pData );
266  }
267 #endif
268 #endif
269 
275  OString( rtl_String * str )
276  {
277  pData = str;
278  rtl_string_acquire( pData );
279  }
280 
288  OString( rtl_String * str, __sal_NoAcquire )
289  {
290  pData = str;
291  }
292 
298  explicit OString( char value )
299  : pData (NULL)
300  {
301  rtl_string_newFromStr_WithLength( &pData, &value, 1 );
302  }
303 
304 #if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST_CONCAT
305  // Catch inadvertent conversions to the above ctor (e.g., from sal_[u]Int8, aka [un]signed
306  // char):
307  OString(int) = delete;
308 #endif
309 
318  template< typename T >
320  {
321  pData = NULL;
322  rtl_string_newFromStr( &pData, value );
323  }
324 
325  template< typename T >
327  {
328  pData = NULL;
329  rtl_string_newFromStr( &pData, value );
330  }
331 
332 #if __cplusplus > 202002L // C++23 P2266R3 "Simpler implicit move"
333  template< typename T >
335  {
336  pData = NULL;
337  rtl_string_newFromStr( &pData, value );
338  }
339 #endif
340 
351  template< typename T >
353  {
354  assert(
356  pData = NULL;
358  rtl_string_new(&pData);
359  } else {
361  &pData,
363  literal),
365  }
366 #ifdef RTL_STRING_UNITTEST
367  rtl_string_unittest_const_literal = true;
368 #endif
369  }
370 
379  OString( const char * value, sal_Int32 length )
380  {
381  pData = NULL;
382  rtl_string_newFromStr_WithLength( &pData, value, length );
383  }
384 
385 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
387 
392  template<std::size_t N> constexpr OString(OStringLiteral<N> const & literal):
393  pData(const_cast<rtl_String *>(&literal.str)) {}
394  template<std::size_t N> OString(OStringLiteral<N> &&) = delete;
396 #endif
397 
398 #if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
399  // For operator ""_tstr:
400  template<OStringLiteral L> constexpr OString(detail::OStringHolder<L> const & holder):
401  pData(const_cast<rtl_String *>(&holder.literal.str)) {}
402 #endif
403 
404 #if defined LIBO_INTERNAL_ONLY
405  explicit OString(std::string_view sv) {
406  if (sv.size() > sal_uInt32(std::numeric_limits<sal_Int32>::max())) {
407  throw std::bad_alloc();
408  }
409  pData = nullptr;
410  rtl_string_newFromStr_WithLength(&pData, sv.data(), sv.size());
411  }
412 #endif
413 
428  OString( const sal_Unicode * value, sal_Int32 length,
429  rtl_TextEncoding encoding,
430  sal_uInt32 convertFlags = OUSTRING_TO_OSTRING_CVTFLAGS )
431  {
432  pData = NULL;
433  rtl_uString2String( &pData, value, length, encoding, convertFlags );
434  if (pData == NULL) {
435  throw std::bad_alloc();
436  }
437  }
438 
439 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
444  template< typename T1, typename T2 >
445  OString( OStringConcat< T1, T2 >&& c )
446  {
447  const sal_Int32 l = c.length();
448  pData = rtl_string_alloc( l );
449  if (l != 0)
450  {
451  char* end = c.addData( pData->buffer );
452  pData->length = l;
453  *end = '\0';
454  }
455  }
456 
461  template< std::size_t N >
462  OString( OStringNumber< N >&& n )
463  : OString( n.buf, n.length )
464  {}
465 #endif
466 
467 #ifdef LIBO_INTERNAL_ONLY
468  OString(std::nullptr_t) = delete;
469 #endif
470 
474 #if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
475  constexpr
476 #endif
478  {
479 #if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
480  if (std::is_constant_evaluated()) {
481  //TODO: We would want to
482  //
483  // assert(SAL_STRING_IS_STATIC(pData));
484  //
485  // here, but that wouldn't work because read of member `str` of OUStringLiteral's
486  // anonymous union with active member `more` is not allowed in a constant expression.
487  } else
488 #endif
489  rtl_string_release( pData );
490  }
491 
492 #if defined LIBO_INTERNAL_ONLY
504  static OString const & unacquired( rtl_String * const * ppHandle )
505  { return * reinterpret_cast< OString const * >( ppHandle ); }
506 #endif
507 
513  OString & operator=( const OString & str )
514  {
515  rtl_string_assign( &pData, str.pData );
516  return *this;
517  }
518 
519 #if defined LIBO_INTERNAL_ONLY
520 #if !defined(__COVERITY__) // suppress COPY_INSTEAD_OF_MOVE suggestions
527  OString & operator=( OString && str ) noexcept
528  {
529  rtl_string_release( pData );
530  pData = str.pData;
531  str.pData = nullptr;
532  rtl_string_new( &str.pData );
533  return *this;
534  }
535 #endif
536 #endif
537 
543  template< typename T >
545  {
546  RTL_STRING_CONST_FUNCTION
547  assert(
550  rtl_string_new(&pData);
551  } else {
553  &pData,
555  literal),
557  }
558  return *this;
559  }
560 
566  OString & operator+=( const OString & str )
567 #if defined LIBO_INTERNAL_ONLY
568  &
569 #endif
570  {
571  rtl_string_newConcat( &pData, pData, str.pData );
572  return *this;
573  }
574 #if defined LIBO_INTERNAL_ONLY
575  void operator+=(OString const &) && = delete;
576 #endif
577 
578 #if defined LIBO_INTERNAL_ONLY
580  operator +=(T const & value) & { return operator +=(std::string_view(value)); }
581  template<typename T> typename libreoffice_internal::CharPtrDetector<T, OString &>::Type
582  operator +=(T const &) && = delete;
583 
584  template<typename T>
585  typename libreoffice_internal::NonConstCharArrayDetector<T, OString &>::Type
586  operator +=(T & value) & { return operator +=(std::string_view(value)); }
587  template<typename T>
588  typename libreoffice_internal::NonConstCharArrayDetector<T, OString &>::Type operator +=(T &) &&
589  = delete;
590 
591  template<typename T> typename libreoffice_internal::ConstCharArrayDetector<T, OString &>::Type
592  operator +=(T & literal) & {
593  assert(libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
594  return operator +=(
595  std::string_view(
596  libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
597  libreoffice_internal::ConstCharArrayDetector<T>::length));
598  }
599  template<typename T> typename libreoffice_internal::ConstCharArrayDetector<T, OString &>::Type
600  operator +=(T &) && = delete;
601 
602  template<std::size_t N> OString & operator +=(OStringLiteral<N> const & literal) &
603  { return operator +=(std::string_view(literal.getStr(), literal.getLength())); }
604  template<std::size_t N> void operator +=(OStringLiteral<N> const &) && = delete;
605 
606  OString & operator +=(std::string_view sv) & {
607  if (sv.empty()) {
608  return *this;
609  }
610  if (sv.size() > sal_uInt32(std::numeric_limits<sal_Int32>::max() - pData->length)) {
611  throw std::bad_alloc();
612  }
613  auto const l = pData->length + sv.size();
614  rtl_string_ensureCapacity(&pData, l);
615  *addDataHelper(pData->buffer + pData->length, sv.data(), sv.size()) = '\0';
616  pData->length = l;
617  return *this;
618  }
619  void operator +=(std::string_view) && = delete;
620 #endif
621 
622 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
627  template< typename T1, typename T2 >
628  OString& operator+=( OStringConcat< T1, T2 >&& c ) & {
629  sal_Int32 l = c.length();
630  if( l == 0 )
631  return *this;
632  l += pData->length;
633  rtl_string_ensureCapacity( &pData, l );
634  char* end = c.addData( pData->buffer + pData->length );
635  *end = '\0';
636  pData->length = l;
637  return *this;
638  }
639  template<typename T1, typename T2> void operator +=(
640  OStringConcat<T1, T2> &&) && = delete;
641 
646  template< std::size_t N >
647  OString& operator+=( OStringNumber< N >&& n ) & {
648  return operator +=(std::string_view(n.buf, n.length));
649  }
650  template<std::size_t N> void operator +=(
651  OStringNumber<N> &&) && = delete;
652 #endif
653 
658  void clear()
659  {
660  rtl_string_new( &pData );
661  }
662 
671  sal_Int32 getLength() const { return pData->length; }
672 
681  bool isEmpty() const
682  {
683  return pData->length == 0;
684  }
685 
697  const char * getStr() const SAL_RETURNS_NONNULL { return pData->buffer; }
698 
708  char operator [](sal_Int32 index) const {
709  // silence spurious -Werror=strict-overflow warnings from GCC 4.8.2
710  assert(index >= 0 && static_cast<sal_uInt32>(index) < static_cast<sal_uInt32>(getLength()));
711  return getStr()[index];
712  }
713 
726  sal_Int32 compareTo( const OString & str ) const
727  {
728  return rtl_str_compare_WithLength( pData->buffer, pData->length,
729  str.pData->buffer, str.pData->length );
730  }
731 
745  sal_Int32 compareTo( const OString & rObj, sal_Int32 maxLength ) const
746  {
747  return rtl_str_shortenedCompare_WithLength( pData->buffer, pData->length,
748  rObj.pData->buffer, rObj.pData->length, maxLength );
749  }
750 
763  sal_Int32 reverseCompareTo( const OString & str ) const
764  {
765  return rtl_str_reverseCompare_WithLength( pData->buffer, pData->length,
766  str.pData->buffer, str.pData->length );
767  }
768 
780  bool equals( const OString & str ) const
781  {
782  if ( pData->length != str.pData->length )
783  return false;
784  if ( pData == str.pData )
785  return true;
786  return rtl_str_reverseCompare_WithLength( pData->buffer, pData->length,
787  str.pData->buffer, str.pData->length ) == 0;
788  }
789 
804  bool equalsL( const char* value, sal_Int32 length ) const
805  {
806  if ( pData->length != length )
807  return false;
808 
809  return rtl_str_reverseCompare_WithLength( pData->buffer, pData->length,
810  value, length ) == 0;
811  }
812 
827 #if defined LIBO_INTERNAL_ONLY
828  bool equalsIgnoreAsciiCase( std::string_view str ) const
829  {
830  if ( sal_uInt32(pData->length) != str.size() )
831  return false;
832  if ( pData->buffer == str.data() )
833  return true;
834  return rtl_str_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
835  str.data(), str.size() ) == 0;
836  }
837 #else
838  bool equalsIgnoreAsciiCase( const OString & str ) const
839  {
840  if ( pData->length != str.pData->length )
841  return false;
842  if ( pData == str.pData )
843  return true;
844  return rtl_str_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
845  str.pData->buffer, str.pData->length ) == 0;
846  }
847 #endif
848 
870  template< typename T >
872  {
873  return rtl_str_compareIgnoreAsciiCase( pData->buffer, asciiStr ) == 0;
874  }
875 
876  template< typename T >
878  {
879  return rtl_str_compareIgnoreAsciiCase( pData->buffer, asciiStr ) == 0;
880  }
881 
887  template< typename T >
889  {
890  RTL_STRING_CONST_FUNCTION
891  assert(
893  return
894  (pData->length
897  pData->buffer, pData->length,
899  literal),
901  == 0);
902  }
903 
923  bool equalsIgnoreAsciiCaseL( const char * asciiStr, sal_Int32 asciiStrLength ) const
924  {
925  if ( pData->length != asciiStrLength )
926  return false;
927 
928  return rtl_str_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
929  asciiStr, asciiStrLength ) == 0;
930  }
931 
947 #if defined LIBO_INTERNAL_ONLY
948  bool match( std::string_view str, sal_Int32 fromIndex = 0 ) const
949  {
950  assert(fromIndex >= 0);
951  return rtl_str_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
952  str.data(), str.size(), str.size() ) == 0;
953  }
954 #else
955  bool match( const OString & str, sal_Int32 fromIndex = 0 ) const
956  {
957  assert(fromIndex >= 0);
958  return rtl_str_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
959  str.pData->buffer, str.pData->length, str.pData->length ) == 0;
960  }
961 #endif
962 
968  template< typename T >
969  typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type match( T& literal, sal_Int32 fromIndex = 0 ) const
970  {
971  RTL_STRING_CONST_FUNCTION
972  assert(
974  assert(fromIndex >= 0);
975  return
977  pData->buffer + fromIndex, pData->length - fromIndex,
979  literal),
982  == 0;
983  }
984 
1001  bool matchL(
1002  char const * str, sal_Int32 strLength, sal_Int32 fromIndex = 0)
1003  const
1004  {
1005  assert(fromIndex >= 0);
1007  pData->buffer + fromIndex, pData->length - fromIndex,
1008  str, strLength, strLength) == 0;
1009  }
1010 
1011  // This overload is left undefined, to detect calls of matchL that
1012  // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
1013  // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
1014  // platforms):
1015 #if SAL_TYPES_SIZEOFLONG == 8
1016  void matchL(char const *, sal_Int32, rtl_TextEncoding) const;
1017 #endif
1018 
1037 #if defined LIBO_INTERNAL_ONLY
1038  bool matchIgnoreAsciiCase( std::string_view 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.data(), str.size(),
1043  str.size() ) == 0;
1044  }
1045 #else
1046  bool matchIgnoreAsciiCase( const OString & str, sal_Int32 fromIndex = 0 ) const
1047  {
1048  assert(fromIndex >= 0);
1049  return rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
1050  str.pData->buffer, str.pData->length,
1051  str.pData->length ) == 0;
1052  }
1053 #endif
1059  template< typename T >
1060  typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type matchIgnoreAsciiCase( T& literal, sal_Int32 fromIndex = 0 ) const
1061  {
1062  RTL_STRING_CONST_FUNCTION
1063  assert(
1065  assert(fromIndex >= 0);
1066  return
1068  pData->buffer+fromIndex, pData->length-fromIndex,
1070  literal),
1073  == 0;
1074  }
1075 
1076 #if defined LIBO_INTERNAL_ONLY
1087  bool startsWith(std::string_view str) const {
1088  return match(str);
1089  }
1103  bool startsWith(std::string_view str, OString * rest) const {
1104  assert(rest);
1105  bool b = startsWith(str);
1106  if (b) {
1107  *rest = copy(str.size());
1108  }
1109  return b;
1110  }
1124  bool startsWith(std::string_view str, std::string_view * rest) const {
1125  assert(rest);
1126  bool b = startsWith(str);
1127  if (b) {
1128  *rest = subView(str.size());
1129  }
1130  return b;
1131  }
1132 #else
1147  bool startsWith(OString const & str, OString * rest = NULL) const {
1148  bool b = match(str);
1149  if (b && rest != NULL) {
1150  *rest = copy(str.getLength());
1151  }
1152  return b;
1153  }
1154 #endif
1155 
1156 #if defined LIBO_INTERNAL_ONLY
1162  template< typename T >
1164  T & literal) const
1165  {
1166  RTL_STRING_CONST_FUNCTION
1167  return match(literal, 0);
1168  }
1174  template< typename T >
1175  typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type startsWith(
1176  T & literal, OString * rest) const
1177  {
1178  RTL_STRING_CONST_FUNCTION
1179  assert(rest);
1180  bool b = startsWith(literal);
1181  if (b) {
1182  *rest = copy(
1183  libreoffice_internal::ConstCharArrayDetector<T>::length);
1184  }
1185  return b;
1186  }
1191  template< typename T >
1192  typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type startsWith(
1193  T & literal, std::string_view * rest) const
1194  {
1195  RTL_STRING_CONST_FUNCTION
1196  assert(rest);
1197  bool b = startsWith(literal);
1198  if (b) {
1199  *rest = subView(
1200  libreoffice_internal::ConstCharArrayDetector<T>::length);
1201  }
1202  return b;
1203  }
1204 #else
1210  template< typename T >
1212  T & literal, OString * rest = NULL) const
1213  {
1214  RTL_STRING_CONST_FUNCTION
1215  bool b = match(literal, 0);
1216  if (b && rest != NULL) {
1217  *rest = copy(
1219  }
1220  return b;
1221  }
1222 #endif
1223 
1233  bool startsWith(char ch) const
1234  {
1235  return !isEmpty() && pData->buffer[0] == ch;
1236  }
1237 
1250  bool startsWith(char ch, OString* rest) const {
1251  assert(rest);
1252  bool b = startsWith(ch);
1253 
1254  if (b)
1255  *rest = copy(1);
1256 
1257  return b;
1258  }
1259 
1260 #if defined LIBO_INTERNAL_ONLY
1273  bool startsWith(char ch, std::string_view* rest) const {
1274  assert(rest);
1275  bool b = startsWith(ch);
1276 
1277  if (b)
1278  *rest = subView(1);
1279 
1280  return b;
1281  }
1282 #endif
1283 
1284 #if defined LIBO_INTERNAL_ONLY
1301  bool startsWithIgnoreAsciiCase(std::string_view str)
1302  const
1303  {
1304  return matchIgnoreAsciiCase(str);
1305  }
1325  bool startsWithIgnoreAsciiCase(std::string_view str, OString * rest)
1326  const
1327  {
1328  assert(rest);
1329  bool b = startsWithIgnoreAsciiCase(str);
1330  if (b) {
1331  *rest = copy(str.size());
1332  }
1333  return b;
1334  }
1354  bool startsWithIgnoreAsciiCase(std::string_view str, std::string_view * rest)
1355  const
1356  {
1357  assert(rest);
1358  bool b = startsWithIgnoreAsciiCase(str);
1359  if (b) {
1360  *rest = subView(str.size());
1361  }
1362  return b;
1363  }
1364 #else
1384  bool startsWithIgnoreAsciiCase(OString const & str, OString * rest = NULL)
1385  const
1386  {
1387  bool b = matchIgnoreAsciiCase(str);
1388  if (b && rest != NULL) {
1389  *rest = copy(str.getLength());
1390  }
1391  return b;
1392  }
1393 #endif
1394 
1395 #if defined LIBO_INTERNAL_ONLY
1401  template< typename T >
1403  startsWithIgnoreAsciiCase(T & literal) const
1404  {
1405  RTL_STRING_CONST_FUNCTION
1406  assert(
1408  return matchIgnoreAsciiCase(literal);
1409  }
1415  template< typename T >
1416  typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
1417  startsWithIgnoreAsciiCase(T & literal, OString * rest) const
1418  {
1419  RTL_STRING_CONST_FUNCTION
1420  assert(rest);
1421  bool b = startsWithIgnoreAsciiCase(literal);
1422  if (b) {
1423  *rest = copy(
1424  libreoffice_internal::ConstCharArrayDetector<T>::length);
1425  }
1426  return b;
1427  }
1428  template< typename T >
1429  typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
1430  startsWithIgnoreAsciiCase(T & literal, std::string_view * rest) const
1431  {
1432  RTL_STRING_CONST_FUNCTION
1433  assert(rest);
1434  bool b = startsWithIgnoreAsciiCase(literal);
1435  if (b) {
1436  *rest = subView(
1437  libreoffice_internal::ConstCharArrayDetector<T>::length);
1438  }
1439  return b;
1440  }
1441 #else
1447  template< typename T >
1448  typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
1449  startsWithIgnoreAsciiCase(T & literal, OString * rest = NULL) const
1450  {
1451  RTL_STRING_CONST_FUNCTION
1452  assert(
1454  bool b = matchIgnoreAsciiCase(literal);
1455  if (b && rest != NULL) {
1456  *rest = copy(
1458  }
1459  return b;
1460  }
1461 #endif
1462 
1463 #if defined LIBO_INTERNAL_ONLY
1474  bool endsWith(std::string_view str) const {
1475  return str.size() <= sal_uInt32(getLength())
1476  && match(str, getLength() - str.size());
1477  }
1492  bool endsWith(std::string_view str, OString * rest) const {
1493  assert(rest);
1494  bool b = endsWith(str);
1495  if (b) {
1496  *rest = copy(0, getLength() - str.size());
1497  }
1498  return b;
1499  }
1513  bool endsWith(std::string_view str, std::string_view * rest) const {
1514  assert(rest);
1515  bool b = endsWith(str);
1516  if (b) {
1517  *rest = subView(0, getLength() - str.size());
1518  }
1519  return b;
1520  }
1521 #else
1536  bool endsWith(OString const & str, OString * rest = NULL) const {
1537  bool b = str.getLength() <= getLength()
1538  && match(str, getLength() - str.getLength());
1539  if (b && rest != NULL) {
1540  *rest = copy(0, getLength() - str.getLength());
1541  }
1542  return b;
1543  }
1544 #endif
1545 
1546 #if defined LIBO_INTERNAL_ONLY
1552  template< typename T >
1554  T & literal) const
1555  {
1556  RTL_STRING_CONST_FUNCTION
1557  assert(
1559  bool b
1561  <= sal_uInt32(getLength()))
1562  && match(
1564  literal),
1565  (getLength()
1567  return b;
1568  }
1574  template< typename T >
1575  typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type endsWith(
1576  T & literal, OString * rest) const
1577  {
1578  RTL_STRING_CONST_FUNCTION
1579  assert(rest);
1580  bool b = endsWith(literal);
1581  if (b) {
1582  *rest = copy(
1583  0,
1584  (getLength()
1585  - libreoffice_internal::ConstCharArrayDetector<T>::length));
1586  }
1587  return b;
1588  }
1594  template< typename T >
1595  typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type endsWith(
1596  T & literal, std::string_view * rest) const
1597  {
1598  RTL_STRING_CONST_FUNCTION
1599  assert(rest);
1600  bool b = endsWith(literal);
1601  if (b) {
1602  *rest = subView(
1603  0,
1604  (getLength()
1605  - libreoffice_internal::ConstCharArrayDetector<T>::length));
1606  }
1607  return b;
1608  }
1609 #else
1615  template< typename T >
1617  T & literal, OString * rest = NULL) const
1618  {
1619  RTL_STRING_CONST_FUNCTION
1620  assert(
1622  bool b
1624  <= sal_uInt32(getLength()))
1625  && match(
1627  literal),
1628  (getLength()
1630  if (b && rest != NULL) {
1631  *rest = copy(
1632  0,
1633  (getLength()
1635  }
1636  return b;
1637  }
1638 #endif
1639 
1653  bool endsWithL(char const * str, sal_Int32 strLength) const {
1654  return strLength <= getLength()
1655  && matchL(str, strLength, getLength() - strLength);
1656  }
1657 
1667  bool endsWith(char ch) const
1668  {
1669  return !isEmpty() && pData->buffer[pData->length - 1] == ch;
1670  }
1671 
1684  bool endsWith(char ch, OString* rest) const {
1685  assert(rest);
1686  bool b = endsWith(ch);
1687 
1688  if (b)
1689  *rest = copy(0, pData->length - 1);
1690 
1691  return b;
1692  }
1693 
1694 #if defined LIBO_INTERNAL_ONLY
1707  bool endsWith(char ch, std::string_view* rest) const {
1708  assert(rest);
1709  bool b = endsWith(ch);
1710 
1711  if (b)
1712  *rest = subView(0, pData->length - 1);
1713 
1714  return b;
1715  }
1716 #endif
1717 
1718  friend bool operator == ( const OString& rStr1, const OString& rStr2 )
1719  { return rStr1.equals(rStr2); }
1720  friend bool operator != ( const OString& rStr1, const OString& rStr2 )
1721  { return !(operator == ( rStr1, rStr2 )); }
1722  friend bool operator < ( const OString& rStr1, const OString& rStr2 )
1723  { return rStr1.compareTo( rStr2 ) < 0; }
1724  friend bool operator > ( const OString& rStr1, const OString& rStr2 )
1725  { return rStr1.compareTo( rStr2 ) > 0; }
1726  friend bool operator <= ( const OString& rStr1, const OString& rStr2 )
1727  { return rStr1.compareTo( rStr2 ) <= 0; }
1728  friend bool operator >= ( const OString& rStr1, const OString& rStr2 )
1729  { return rStr1.compareTo( rStr2 ) >= 0; }
1730 
1731  template< typename T >
1732  friend typename libreoffice_internal::CharPtrDetector< T, bool >::Type operator==( const OString& rStr1, const T& value )
1733  {
1734  return
1736  rStr1.getStr(), rStr1.getLength(), value, rtl_str_getLength(value))
1737  == 0;
1738  }
1739 
1740  template< typename T >
1742  {
1743  return
1745  rStr1.getStr(), rStr1.getLength(), value, rtl_str_getLength(value))
1746  == 0;
1747  }
1748 
1749  template< typename T >
1750  friend typename libreoffice_internal::CharPtrDetector< T, bool >::Type operator==( const T& value, const OString& rStr2 )
1751  {
1752  return
1754  value, rtl_str_getLength(value), rStr2.getStr(), rStr2.getLength())
1755  == 0;
1756  }
1757 
1758  template< typename T >
1760  {
1761  return
1763  value, rtl_str_getLength(value), rStr2.getStr(), rStr2.getLength())
1764  == 0;
1765  }
1766 
1772  template< typename T >
1774  {
1775  RTL_STRING_CONST_FUNCTION
1776  assert(
1778  return
1779  (rStr.getLength()
1782  rStr.pData->buffer, rStr.pData->length,
1784  literal),
1786  == 0);
1787  }
1788 
1794  template< typename T >
1796  {
1797  RTL_STRING_CONST_FUNCTION
1798  assert(
1800  return
1801  (rStr.getLength()
1804  rStr.pData->buffer, rStr.pData->length,
1806  literal),
1808  == 0);
1809  }
1810 
1811  template< typename T >
1812  friend typename libreoffice_internal::CharPtrDetector< T, bool >::Type operator!=( const OString& rStr1, const T& value )
1813  {
1814  return !(operator == ( rStr1, value ));
1815  }
1816 
1817  template< typename T >
1819  {
1820  return !(operator == ( rStr1, value ));
1821  }
1822 
1823  template< typename T >
1824  friend typename libreoffice_internal::CharPtrDetector< T, bool >::Type operator!=( const T& value, const OString& rStr2 )
1825  {
1826  return !(operator == ( value, rStr2 ));
1827  }
1828 
1829  template< typename T >
1831  {
1832  return !(operator == ( value, rStr2 ));
1833  }
1834 
1840  template< typename T >
1842  {
1843  return !( rStr == literal );
1844  }
1845 
1851  template< typename T >
1853  {
1854  return !( literal == rStr );
1855  }
1856 
1864  sal_Int32 hashCode() const
1865  {
1866  return rtl_str_hashCode_WithLength( pData->buffer, pData->length );
1867  }
1868 
1882  sal_Int32 indexOf( char ch, sal_Int32 fromIndex = 0 ) const
1883  {
1884  assert(fromIndex >= 0);
1885  sal_Int32 ret = rtl_str_indexOfChar_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, ch );
1886  return (ret < 0 ? ret : ret+fromIndex);
1887  }
1888 
1898  sal_Int32 lastIndexOf( char ch ) const
1899  {
1900  return rtl_str_lastIndexOfChar_WithLength( pData->buffer, pData->length, ch );
1901  }
1902 
1915  sal_Int32 lastIndexOf( char ch, sal_Int32 fromIndex ) const
1916  {
1917  return rtl_str_lastIndexOfChar_WithLength( pData->buffer, fromIndex, ch );
1918  }
1919 
1935 #if defined LIBO_INTERNAL_ONLY
1936  sal_Int32 indexOf( std::string_view 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.data(), str.size() );
1941  return (ret < 0 ? ret : ret+fromIndex);
1942  }
1943 #else
1944  sal_Int32 indexOf( const OString & str, sal_Int32 fromIndex = 0 ) const
1945  {
1946  assert(fromIndex >= 0);
1947  sal_Int32 ret = rtl_str_indexOfStr_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
1948  str.pData->buffer, str.pData->length );
1949  return (ret < 0 ? ret : ret+fromIndex);
1950  }
1951 #endif
1957  template< typename T >
1958  typename libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type indexOf( T& literal, sal_Int32 fromIndex = 0 ) const
1959  {
1960  RTL_STRING_CONST_FUNCTION
1961  assert(
1963  assert(fromIndex >= 0);
1964  sal_Int32 n = rtl_str_indexOfStr_WithLength(
1965  pData->buffer + fromIndex, pData->length - fromIndex,
1968  return n < 0 ? n : n + fromIndex;
1969  }
1970 
1989  sal_Int32 indexOfL(char const * str, sal_Int32 len, sal_Int32 fromIndex = 0)
1990  const
1991  {
1992  assert(fromIndex >= 0);
1993  sal_Int32 n = rtl_str_indexOfStr_WithLength(
1994  pData->buffer + fromIndex, pData->length - fromIndex, str, len);
1995  return n < 0 ? n : n + fromIndex;
1996  }
1997 
1998  // This overload is left undefined, to detect calls of indexOfL that
1999  // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
2000  // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
2001  // platforms):
2002 #if SAL_TYPES_SIZEOFLONG == 8
2003  void indexOfL(char const *, sal_Int32, rtl_TextEncoding) const;
2004 #endif
2005 
2021 #if defined LIBO_INTERNAL_ONLY
2022  sal_Int32 lastIndexOf( std::string_view str ) const
2023  {
2024  return rtl_str_lastIndexOfStr_WithLength( pData->buffer, pData->length,
2025  str.data(), str.size() );
2026  }
2027 #else
2028  sal_Int32 lastIndexOf( const OString & str ) const
2029  {
2030  return rtl_str_lastIndexOfStr_WithLength( pData->buffer, pData->length,
2031  str.pData->buffer, str.pData->length );
2032  }
2033 #endif
2034 
2052 #if defined LIBO_INTERNAL_ONLY
2053  sal_Int32 lastIndexOf( std::string_view str, sal_Int32 fromIndex ) const
2054  {
2055  return rtl_str_lastIndexOfStr_WithLength( pData->buffer, fromIndex,
2056  str.data(), str.size() );
2057  }
2058 #else
2059  sal_Int32 lastIndexOf( const OString & str, sal_Int32 fromIndex ) const
2060  {
2061  return rtl_str_lastIndexOfStr_WithLength( pData->buffer, fromIndex,
2062  str.pData->buffer, str.pData->length );
2063  }
2064 #endif
2065 
2076  SAL_WARN_UNUSED_RESULT OString copy( sal_Int32 beginIndex ) const
2077  {
2078  return copy(beginIndex, getLength() - beginIndex);
2079  }
2080 
2093  SAL_WARN_UNUSED_RESULT OString copy( sal_Int32 beginIndex, sal_Int32 count ) const
2094  {
2095  rtl_String *pNew = NULL;
2096  rtl_string_newFromSubString( &pNew, pData, beginIndex, count );
2097  return OString( pNew, SAL_NO_ACQUIRE );
2098  }
2099 
2100 #if defined LIBO_INTERNAL_ONLY
2111  SAL_WARN_UNUSED_RESULT std::string_view subView( sal_Int32 beginIndex ) const
2112  {
2113  assert(beginIndex >= 0);
2114  assert(beginIndex <= getLength());
2115  return subView(beginIndex, getLength() - beginIndex);
2116  }
2117 
2130  SAL_WARN_UNUSED_RESULT std::string_view subView( sal_Int32 beginIndex, sal_Int32 count ) const
2131  {
2132  assert(beginIndex >= 0);
2133  assert(count >= 0);
2134  assert(beginIndex <= getLength());
2135  assert(count <= getLength() - beginIndex);
2136  return std::string_view(*this).substr(beginIndex, count);
2137  }
2138 #endif
2139 
2140 #ifndef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
2149  SAL_WARN_UNUSED_RESULT OString concat( const OString & str ) const
2150  {
2151  rtl_String* pNew = NULL;
2152  rtl_string_newConcat( &pNew, pData, str.pData );
2153  return OString( pNew, SAL_NO_ACQUIRE );
2154  }
2155 #endif
2156 
2157 #ifndef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
2158  friend OString operator+( const OString & str1, const OString & str2 )
2159  {
2160  return str1.concat( str2 );
2161  }
2162 #endif
2163 
2164 // hide this from internal code to avoid ambiguous lookup error
2165 #ifndef LIBO_INTERNAL_ONLY
2179  SAL_WARN_UNUSED_RESULT OString replaceAt( sal_Int32 index, sal_Int32 count, const OString& newStr ) const
2180  {
2181  rtl_String* pNew = NULL;
2182  rtl_string_newReplaceStrAt( &pNew, pData, index, count, newStr.pData );
2183  return OString( pNew, SAL_NO_ACQUIRE );
2184  }
2185 #endif
2186 
2187 #ifdef LIBO_INTERNAL_ONLY
2188  SAL_WARN_UNUSED_RESULT OString replaceAt( sal_Int32 index, sal_Int32 count, std::string_view newStr ) const
2189  {
2190  rtl_String* pNew = NULL;
2191  rtl_string_newReplaceStrAt_WithLength ( &pNew, pData, index, count, newStr.data(), newStr.size() );
2192  return OString( pNew, SAL_NO_ACQUIRE );
2193  }
2194 #endif
2195 
2209  SAL_WARN_UNUSED_RESULT OString replace( char oldChar, char newChar ) const
2210  {
2211  rtl_String* pNew = NULL;
2212  rtl_string_newReplace( &pNew, pData, oldChar, newChar );
2213  return OString( pNew, SAL_NO_ACQUIRE );
2214  }
2215 
2235  OString const & from, OString const & to, sal_Int32 * index = NULL) const
2236  {
2237  rtl_String * s = NULL;
2238  sal_Int32 i = 0;
2240  &s, pData, from.pData->buffer, from.pData->length,
2241  to.pData->buffer, to.pData->length, index == NULL ? &i : index);
2242  return OString(s, SAL_NO_ACQUIRE);
2243  }
2244 
2258  SAL_WARN_UNUSED_RESULT OString replaceAll(OString const & from, OString const & to) const {
2259  rtl_String * s = NULL;
2261  &s, pData, from.pData->buffer, from.pData->length,
2262  to.pData->buffer, to.pData->length);
2263  return OString(s, SAL_NO_ACQUIRE);
2264  }
2265 
2277  {
2278  rtl_String* pNew = NULL;
2279  rtl_string_newToAsciiLowerCase( &pNew, pData );
2280  return OString( pNew, SAL_NO_ACQUIRE );
2281  }
2282 
2294  {
2295  rtl_String* pNew = NULL;
2296  rtl_string_newToAsciiUpperCase( &pNew, pData );
2297  return OString( pNew, SAL_NO_ACQUIRE );
2298  }
2299 
2312  {
2313  rtl_String* pNew = NULL;
2314  rtl_string_newTrim( &pNew, pData );
2315  return OString( pNew, SAL_NO_ACQUIRE );
2316  }
2317 
2342  OString getToken( sal_Int32 token, char cTok, sal_Int32& index ) const
2343  {
2344  rtl_String * pNew = NULL;
2345  index = rtl_string_getToken( &pNew, pData, token, cTok, index );
2346  return OString( pNew, SAL_NO_ACQUIRE );
2347  }
2348 
2362  OString getToken(sal_Int32 count, char separator) const {
2363  sal_Int32 n = 0;
2364  return getToken(count, separator, n);
2365  }
2366 
2375  bool toBoolean() const
2376  {
2377  return rtl_str_toBoolean( pData->buffer );
2378  }
2379 
2386  char toChar() const
2387  {
2388  return pData->buffer[0];
2389  }
2390 
2401  sal_Int32 toInt32( sal_Int16 radix = 10 ) const
2402  {
2403  return rtl_str_toInt32( pData->buffer, radix );
2404  }
2405 
2418  sal_uInt32 toUInt32( sal_Int16 radix = 10 ) const
2419  {
2420  return rtl_str_toUInt32( pData->buffer, radix );
2421  }
2422 
2433  sal_Int64 toInt64( sal_Int16 radix = 10 ) const
2434  {
2435  return rtl_str_toInt64( pData->buffer, radix );
2436  }
2437 
2450  sal_uInt64 toUInt64( sal_Int16 radix = 10 ) const
2451  {
2452  return rtl_str_toUInt64( pData->buffer, radix );
2453  }
2454 
2463  float toFloat() const
2464  {
2465  return rtl_str_toFloat( pData->buffer );
2466  }
2467 
2476  double toDouble() const
2477  {
2478  return rtl_str_toDouble( pData->buffer );
2479  }
2480 
2481 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
2482 
2483  static auto number( int i, sal_Int16 radix = 10 )
2484  {
2485  return OStringNumber<RTL_STR_MAX_VALUEOFINT32>(rtl_str_valueOfInt32, i, radix);
2486  }
2487  static auto number( long long ll, sal_Int16 radix = 10 )
2488  {
2489  return OStringNumber<RTL_STR_MAX_VALUEOFINT64>(rtl_str_valueOfInt64, ll, radix);
2490  }
2491  static auto number( unsigned long long ll, sal_Int16 radix = 10 )
2492  {
2493  return OStringNumber<RTL_STR_MAX_VALUEOFUINT64>(rtl_str_valueOfUInt64, ll, radix);
2494  }
2495  static auto number( unsigned int i, sal_Int16 radix = 10 )
2496  {
2497  return number( static_cast< unsigned long long >( i ), radix );
2498  }
2499  static auto number( long i, sal_Int16 radix = 10)
2500  {
2501  return number( static_cast< long long >( i ), radix );
2502  }
2503  static auto number( unsigned long i, sal_Int16 radix = 10 )
2504  {
2505  return number( static_cast< unsigned long long >( i ), radix );
2506  }
2507 #else
2518  static OString number( int i, sal_Int16 radix = 10 )
2519  {
2520  char aBuf[RTL_STR_MAX_VALUEOFINT32];
2521  return OString(aBuf, rtl_str_valueOfInt32(aBuf, i, radix));
2522  }
2525  static OString number( unsigned int i, sal_Int16 radix = 10 )
2526  {
2527  return number( static_cast< unsigned long long >( i ), radix );
2528  }
2531  static OString number( long i, sal_Int16 radix = 10 )
2532  {
2533  return number( static_cast< long long >( i ), radix );
2534  }
2537  static OString number( unsigned long i, sal_Int16 radix = 10 )
2538  {
2539  return number( static_cast< unsigned long long >( i ), radix );
2540  }
2543  static OString number( long long ll, sal_Int16 radix = 10 )
2544  {
2545  char aBuf[RTL_STR_MAX_VALUEOFINT64];
2546  return OString(aBuf, rtl_str_valueOfInt64(aBuf, ll, radix));
2547  }
2550  static OString number( unsigned long long ll, sal_Int16 radix = 10 )
2551  {
2552  char aBuf[RTL_STR_MAX_VALUEOFUINT64];
2553  return OString(aBuf, rtl_str_valueOfUInt64(aBuf, ll, radix));
2554  }
2555 #endif
2556 
2566  static OString number( float f )
2567  {
2568  rtl_String* pNew = NULL;
2569  // Same as rtl::str::valueOfFP, used for rtl_str_valueOfFloat
2571  RTL_STR_MAX_VALUEOFFLOAT - SAL_N_ELEMENTS("-x.E-xxx") + 1, '.',
2572  NULL, 0, true);
2573  if (pNew == NULL)
2574  throw std::bad_alloc();
2575 
2576  return OString(pNew, SAL_NO_ACQUIRE);
2577  }
2578 
2588  static OString number( double d )
2589  {
2590  rtl_String* pNew = NULL;
2591  // Same as rtl::str::valueOfFP, used for rtl_str_valueOfDouble
2593  RTL_STR_MAX_VALUEOFDOUBLE - SAL_N_ELEMENTS("-x.E-xxx") + 1, '.',
2594  NULL, 0, true);
2595  if (pNew == NULL)
2596  throw std::bad_alloc();
2597 
2598  return OString(pNew, SAL_NO_ACQUIRE);
2599  }
2600 
2601 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
2602  static auto boolean(bool b)
2603  {
2604  return OStringNumber<RTL_STR_MAX_VALUEOFBOOLEAN>(rtl_str_valueOfBoolean, b);
2605  }
2606 #else
2618  SAL_DEPRECATED("use boolean()") static OString valueOf( sal_Bool b )
2619  {
2620  return boolean(b);
2621  }
2622 
2634  static OString boolean( bool b )
2635  {
2636  char aBuf[RTL_STR_MAX_VALUEOFBOOLEAN];
2637  return OString(aBuf, rtl_str_valueOfBoolean(aBuf, b));
2638  }
2639 #endif
2640 
2648  SAL_DEPRECATED("convert to OString or use directly") static OString valueOf( char c )
2649  {
2650  return OString( &c, 1 );
2651  }
2652 
2663  SAL_DEPRECATED("use number()") static OString valueOf( sal_Int32 i, sal_Int16 radix = 10 )
2664  {
2665  return number( i, radix );
2666  }
2667 
2678  SAL_DEPRECATED("use number()") static OString valueOf( sal_Int64 ll, sal_Int16 radix = 10 )
2679  {
2680  return number( ll, radix );
2681  }
2682 
2692  SAL_DEPRECATED("use number()") static OString valueOf( float f )
2693  {
2694  return number(f);
2695  }
2696 
2706  SAL_DEPRECATED("use number()") static OString valueOf( double d )
2707  {
2708  return number(d);
2709  }
2710 
2711 #if defined LIBO_INTERNAL_ONLY
2712  operator std::string_view() const { return {getStr(), sal_uInt32(getLength())}; }
2713 #endif
2714 
2715 #if defined LIBO_INTERNAL_ONLY
2716  // A wrapper for the first expression in an
2717  //
2718  // OString::Concat(e1) + e2 + ...
2719  //
2720  // concatenation chain, when neither of the first two e1, e2 is one of our rtl string-related
2721  // classes (so something like
2722  //
2723  // OString s = "a" + (b ? std::string_view("c") : std::string_view("dd"));
2724  //
2725  // would not compile):
2726  template<typename T> [[nodiscard]] static
2727  OStringConcat<OStringConcatMarker, T>
2728  Concat(T const & value) { return OStringConcat<OStringConcatMarker, T>(value); }
2729 
2730  // This overload is needed so that an argument of type 'char const[N]' ends up as
2731  // 'OStringConcat<rtl::OStringConcatMarker, char const[N]>' rather than as
2732  // 'OStringConcat<rtl::OStringConcatMarker, char[N]>':
2733  template<typename T, std::size_t N> [[nodiscard]] static
2734  OStringConcat<OStringConcatMarker, T[N]>
2735  Concat(T (& value)[N]) { return OStringConcat<OStringConcatMarker, T[N]>(value); }
2736 #endif
2737 
2738 private:
2739 #if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
2740  static constexpr auto empty = OStringLiteral(""); // [-loplugin:ostr]
2741 #endif
2742 };
2743 
2744 #if defined LIBO_INTERNAL_ONLY
2745 inline bool operator ==(OString const & lhs, StringConcatenation<char> const & rhs)
2746 { return lhs == std::string_view(rhs); }
2747 inline bool operator !=(OString const & lhs, StringConcatenation<char> const & rhs)
2748 { return lhs != std::string_view(rhs); }
2749 inline bool operator ==(StringConcatenation<char> const & lhs, OString const & rhs)
2750 { return std::string_view(lhs) == rhs; }
2751 inline bool operator !=(StringConcatenation<char> const & lhs, OString const & rhs)
2752 { return std::string_view(lhs) != rhs; }
2753 #endif
2754 
2755 /* ======================================================================= */
2756 
2757 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
2758 
2762 template<>
2763 struct ToStringHelper< OString >
2764 {
2765  static std::size_t length( const OString& s ) { return s.getLength(); }
2766  char* operator()( char* buffer, const OString& s ) const { return addDataHelper( buffer, s.getStr(), s.getLength()); }
2767 };
2768 
2772 template<std::size_t N>
2773 struct ToStringHelper< OStringLiteral<N> >
2774 {
2775  static constexpr std::size_t length( const OStringLiteral<N>& str ) { return str.getLength(); }
2776  char* operator()( char* buffer, const OStringLiteral<N>& str ) const { return addDataHelper( buffer, str.getStr(), str.getLength() ); }
2777 };
2778 
2782 template< typename charT, typename traits, typename T1, typename T2 >
2783 inline std::basic_ostream<charT, traits> & operator <<(
2784  std::basic_ostream<charT, traits> & stream, OStringConcat< T1, T2 >&& concat)
2785 {
2786  return stream << OString( std::move(concat) );
2787 }
2788 #endif
2789 
2790 
2797 {
2807  size_t operator()( const OString& rString ) const
2808  { return static_cast<size_t>(rString.hashCode()); }
2809 };
2810 
2813 {
2814  bool operator()( const char* p1, const char* p2) const
2815  { return rtl_str_compare(p1, p2) == 0; }
2816 };
2817 
2820 {
2821  size_t operator()(const char* p) const
2822  { return rtl_str_hashCode(p); }
2823 };
2824 
2825 /* ======================================================================= */
2826 
2833 template< typename charT, typename traits > std::basic_ostream<charT, traits> &
2834 operator <<(
2835  std::basic_ostream<charT, traits> & stream, OString const & rString)
2836 {
2837  return stream << rString.getStr();
2838  // best effort; potentially loses data due to embedded null characters
2839 }
2840 
2841 } /* Namespace */
2842 
2843 #ifdef RTL_STRING_UNITTEST
2844 namespace rtl
2845 {
2846 typedef rtlunittest::OString OString;
2847 }
2848 #undef RTL_STRING_CONST_FUNCTION
2849 #endif
2850 
2851 #if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST
2852 using ::rtl::OString;
2853 using ::rtl::OStringChar;
2854 using ::rtl::Concat2View;
2855 using ::rtl::OStringHash;
2856 using ::rtl::OStringLiteral;
2857 using RepeatedChar = ::rtl::RepeatedChar_t<char>;
2858 #endif
2859 
2860 #if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
2861 
2862 template<
2863 #if defined RTL_STRING_UNITTEST
2864  rtlunittest::
2865 #endif
2866  OStringLiteral L>
2867 constexpr
2868 #if defined RTL_STRING_UNITTEST
2869  rtlunittest::
2870 #endif
2871  OString
2872 operator ""_ostr() { return L; }
2873 
2874 template<
2875 #if defined RTL_STRING_UNITTEST
2876  rtlunittest::
2877 #endif
2878  OStringLiteral L>
2879 constexpr
2880 #if defined RTL_STRING_UNITTEST
2881 rtlunittest
2882 #else
2883 rtl
2884 #endif
2885 ::detail::OStringHolder<L> operator ""_tstr() {
2886  return
2887 #if defined RTL_STRING_UNITTEST
2888  rtlunittest
2889 #else
2890  rtl
2891 #endif
2892  ::detail::OStringHolder<L>();
2893 }
2894 
2895 #endif
2896 
2898 
2903 #if defined LIBO_INTERNAL_ONLY
2904 namespace std {
2905 
2906 template<>
2907 struct hash<::rtl::OString>
2908 {
2909  std::size_t operator()(::rtl::OString const & s) const
2910  {
2911  if constexpr (sizeof(std::size_t) == 8)
2912  {
2913  // return a hash that uses the full 64-bit range instead of a 32-bit value
2914  size_t n = s.getLength();
2915  for (sal_Int32 i = 0, len = s.getLength(); i < len; ++i)
2916  n = 37 * n + s[i];
2917  return n;
2918  }
2919  else
2920  return std::size_t(s.hashCode());
2921  }
2922 };
2923 
2924 }
2925 
2926 #endif
2928 
2929 #endif // INCLUDED_RTL_STRING_HXX
2930 
2931 /* 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:2834
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:193
SAL_WARN_UNUSED_RESULT OString concat(const OString &str) const
Concatenates the specified string to the end of this string.
Definition: string.hxx:2149
OString(T &literal, typename libreoffice_internal::ConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type=libreoffice_internal::Dummy())
New string from a string literal.
Definition: string.hxx:352
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:428
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:1616
OString & operator+=(const OString &str)
Append a string to this string.
Definition: string.hxx:566
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:2537
bool startsWith(OString const &str, OString *rest=NULL) const
Check whether this string starts with a given substring.
Definition: string.hxx:1147
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:1773
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:1211
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:1795
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:1958
OString(const char *value, sal_Int32 length)
New string from a character buffer array.
Definition: string.hxx:379
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:2550
static OString number(int i, sal_Int16 radix=10)
Returns the string representation of the integer argument.
Definition: string.hxx:2518
sal_uInt64 toUInt64(sal_Int16 radix=10) const
Returns the uint64 value from this string.
Definition: string.hxx:2450
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:1989
sal_Int32 compareTo(const OString &str) const
Compares two strings.
Definition: string.hxx:726
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:888
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:2293
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:1449
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:1852
char toChar() const
Returns the first character from this string.
Definition: string.hxx:2386
bool toBoolean() const
Returns the Boolean value from this string.
Definition: string.hxx:2375
friend OString operator+(const OString &str1, const OString &str2)
Definition: string.hxx:2158
SAL_WARN_UNUSED_RESULT OString copy(sal_Int32 beginIndex) const
Returns a new string that is a substring of this string.
Definition: string.hxx:2076
friend libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type operator!=(const OString &rStr1, T &value)
Definition: string.hxx:1818
OString(rtl_String *str)
New string from OString data.
Definition: string.hxx:275
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:1384
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:2543
sal_Int32 lastIndexOf(const OString &str) const
Returns the index within this string of the last occurrence of the specified substring,...
Definition: string.hxx:2028
void clear()
Clears the string, i.e, makes a zero-character string.
Definition: string.hxx:658
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:2234
OString getToken(sal_Int32 count, char separator) const
Returns a token from the string.
Definition: string.hxx:2362
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:2525
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:1060
sal_Int32 compareTo(const OString &rObj, sal_Int32 maxLength) const
Compares two strings with an maximum count of characters.
Definition: string.hxx:745
bool endsWith(char ch) const
Check whether this string ends with a given character.
Definition: string.hxx:1667
bool isEmpty() const
Checks if a string is empty.
Definition: string.hxx:681
friend libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type operator==(T &value, const OString &rStr2)
Definition: string.hxx:1759
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:319
OString getToken(sal_Int32 token, char cTok, sal_Int32 &index) const
Returns a token in the string.
Definition: string.hxx:2342
sal_Int32 reverseCompareTo(const OString &str) const
Compares two strings in reverse order.
Definition: string.hxx:763
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:2059
sal_Int32 lastIndexOf(char ch) const
Returns the index within this string of the last occurrence of the specified character,...
Definition: string.hxx:1898
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:2093
friend libreoffice_internal::CharPtrDetector< T, bool >::Type operator!=(const OString &rStr1, const T &value)
Definition: string.hxx:1812
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:2209
sal_Int32 hashCode() const
Returns a hashcode for this string.
Definition: string.hxx:1864
static OString boolean(bool b)
Returns the string representation of the boolean argument.
Definition: string.hxx:2634
bool matchL(char const *str, sal_Int32 strLength, sal_Int32 fromIndex=0) const
Match against a substring appearing in this string.
Definition: string.hxx:1001
bool equalsL(const char *value, sal_Int32 length) const
Perform a comparison of two strings.
Definition: string.hxx:804
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:2311
OString(const OString &str)
New string from OString.
Definition: string.hxx:223
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:2258
bool endsWithL(char const *str, sal_Int32 strLength) const
Check whether this string ends with a given substring.
Definition: string.hxx:1653
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:2276
bool match(const OString &str, sal_Int32 fromIndex=0) const
Match against a substring appearing in this string.
Definition: string.hxx:955
const char * getStr() const SAL_RETURNS_NONNULL
Returns a pointer to the characters of this string.
Definition: string.hxx:697
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:544
float toFloat() const
Returns the float value from this string.
Definition: string.hxx:2463
OString()
New string containing no characters.
Definition: string.hxx:205
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:969
friend libreoffice_internal::CharPtrDetector< T, bool >::Type operator==(const T &value, const OString &rStr2)
Definition: string.hxx:1750
OString(char value)
New string from a single character.
Definition: string.hxx:298
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:2531
bool startsWith(char ch, OString *rest) const
Check whether this string starts with a given character.
Definition: string.hxx:1250
bool equalsIgnoreAsciiCase(const OString &str) const
Perform an ASCII lowercase comparison of two strings.
Definition: string.hxx:838
sal_Int64 toInt64(sal_Int16 radix=10) const
Returns the int64 value from this string.
Definition: string.hxx:2433
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:1944
sal_Int32 toInt32(sal_Int16 radix=10) const
Returns the int32 value from this string.
Definition: string.hxx:2401
~OString()
Release the string data.
Definition: string.hxx:477
libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type equalsIgnoreAsciiCase(T &asciiStr) const
Definition: string.hxx:877
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:1841
OString & operator=(const OString &str)
Assign a new string.
Definition: string.hxx:513
bool startsWith(char ch) const
Check whether this string starts with a given character.
Definition: string.hxx:1233
libreoffice_internal::CharPtrDetector< T, bool >::Type equalsIgnoreAsciiCase(const T &asciiStr) const
Perform an ASCII lowercase comparison of two strings.
Definition: string.hxx:871
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:1882
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:2179
sal_Int32 getLength() const
Returns the length of this string.
Definition: string.hxx:671
double toDouble() const
Returns the double value from this string.
Definition: string.hxx:2476
static OString number(double d)
Returns the string representation of the double argument.
Definition: string.hxx:2588
bool endsWith(OString const &str, OString *rest=NULL) const
Check whether this string ends with a given substring.
Definition: string.hxx:1536
bool equals(const OString &str) const
Perform a comparison of two strings.
Definition: string.hxx:780
friend libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type operator==(const OString &rStr1, T &value)
Definition: string.hxx:1741
OString(rtl_String *str, __sal_NoAcquire)
New string from OString data without acquiring it.
Definition: string.hxx:288
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:1915
OString(T &value, typename libreoffice_internal::NonConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type=libreoffice_internal::Dummy())
Definition: string.hxx:326
friend libreoffice_internal::CharPtrDetector< T, bool >::Type operator==(const OString &rStr1, const T &value)
Definition: string.hxx:1732
sal_uInt32 toUInt32(sal_Int16 radix=10) const
Returns the uint32 value from this string.
Definition: string.hxx:2418
static OString number(float f)
Returns the string representation of the float argument.
Definition: string.hxx:2566
bool endsWith(char ch, OString *rest) const
Check whether this string ends with a given character.
Definition: string.hxx:1684
friend libreoffice_internal::CharPtrDetector< T, bool >::Type operator!=(const T &value, const OString &rStr2)
Definition: string.hxx:1824
bool equalsIgnoreAsciiCaseL(const char *asciiStr, sal_Int32 asciiStrLength) const
Perform an ASCII lowercase comparison of two strings.
Definition: string.hxx:923
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:1046
friend libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type operator!=(T &value, const OString &rStr2)
Definition: string.hxx:1830
A helper to use OStrings with hash maps.
Definition: string.hxx:2797
size_t operator()(const OString &rString) const
Compute a hash code for a string.
Definition: string.hxx:2807
Equality functor for classic c-strings (i.e., null-terminated char* strings).
Definition: string.hxx:2813
bool operator()(const char *p1, const char *p2) const
Definition: string.hxx:2814
Hashing functor for classic c-strings (i.e., null-terminated char* strings).
Definition: string.hxx:2820
size_t operator()(const char *p) const
Definition: string.hxx:2821
Definition: stringutils.hxx:178
Definition: stringutils.hxx:181