LibreOffice
LibreOffice 25.2 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
79 
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 
203  {
204  pData = NULL;
205  rtl_string_new( &pData );
206  }
207 
213 #if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
214  constexpr
215 #endif
216  OString( const OString & str )
217  {
218  pData = str.pData;
219 #if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
220  if (std::is_constant_evaluated()) {
221  //TODO: We would want to
222  //
223  // assert(SAL_STRING_IS_STATIC(pData));
224  //
225  // here, but that wouldn't work because read of member `str` of OUStringLiteral's
226  // anonymous union with active member `more` is not allowed in a constant expression.
227  } else
228 #endif
229  rtl_string_acquire( pData );
230  }
231 
232 #if defined LIBO_INTERNAL_ONLY
233 #if !defined(__COVERITY__) // suppress COPY_INSTEAD_OF_MOVE suggestions
234 
240 #if !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
241  constexpr
242 #endif
243  OString( OString && str ) noexcept
244  {
245  pData = str.pData;
246 #if !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
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 #endif
257  str.pData = nullptr;
258  rtl_string_new( &str.pData );
259  }
260 #endif
261 #endif
262 
268  OString( rtl_String * str )
269  {
270  pData = str;
271  rtl_string_acquire( pData );
272  }
273 
281  OString( rtl_String * str, __sal_NoAcquire )
282  {
283  pData = str;
284  }
285 
291  explicit OString( char value )
292  : pData (NULL)
293  {
294  rtl_string_newFromStr_WithLength( &pData, &value, 1 );
295  }
296 
297 #if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST_CONCAT
298  // Catch inadvertent conversions to the above ctor (e.g., from sal_[u]Int8, aka [un]signed
299  // char):
300  OString(int) = delete;
301 #endif
302 
311  template< typename T >
313  {
314  pData = NULL;
315  rtl_string_newFromStr( &pData, value );
316  }
317 
318  template< typename T >
320  {
321  pData = NULL;
322  rtl_string_newFromStr( &pData, value );
323  }
324 
325 #if __cplusplus > 202002L // C++23 P2266R3 "Simpler implicit move"
326  template< typename T >
328  {
329  pData = NULL;
330  rtl_string_newFromStr( &pData, value );
331  }
332 #endif
333 
344  template< typename T >
346  {
347  assert(
349  pData = NULL;
351  rtl_string_new(&pData);
352  } else {
354  &pData,
356  literal),
358  }
359 #ifdef RTL_STRING_UNITTEST
360  rtl_string_unittest_const_literal = true;
361 #endif
362  }
363 
372  OString( const char * value, sal_Int32 length )
373  {
374  pData = NULL;
375  rtl_string_newFromStr_WithLength( &pData, value, length );
376  }
377 
378 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
379 
385  template<std::size_t N> constexpr OString(OStringLiteral<N> const & literal):
386  pData(const_cast<rtl_String *>(&literal.str)) {}
387  template<std::size_t N> OString(OStringLiteral<N> &&) = delete;
389 #endif
390 
391 #if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
392  // For operator ""_tstr:
393  template<OStringLiteral L> constexpr OString(detail::OStringHolder<L> const & holder):
394  pData(const_cast<rtl_String *>(&holder.literal.str)) {}
395 #endif
396 
397 #if defined LIBO_INTERNAL_ONLY
398  explicit OString(std::string_view sv) {
399  if (sv.size() > sal_uInt32(std::numeric_limits<sal_Int32>::max())) {
400  throw std::bad_alloc();
401  }
402  pData = nullptr;
403  rtl_string_newFromStr_WithLength(&pData, sv.data(), sv.size());
404  }
405 #endif
406 
421  OString( const sal_Unicode * value, sal_Int32 length,
422  rtl_TextEncoding encoding,
423  sal_uInt32 convertFlags = OUSTRING_TO_OSTRING_CVTFLAGS )
424  {
425  pData = NULL;
426  rtl_uString2String( &pData, value, length, encoding, convertFlags );
427  if (pData == NULL) {
428  throw std::bad_alloc();
429  }
430  }
431 
432 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
433 
437  template< typename T1, typename T2 >
438  OString( OStringConcat< T1, T2 >&& c )
439  {
440  const sal_Int32 l = c.length();
441  pData = rtl_string_alloc( l );
442  if (l != 0)
443  {
444  char* end = c.addData( pData->buffer );
445  pData->length = l;
446  *end = '\0';
447  }
448  }
449 
454  template< std::size_t N >
455  OString( OStringNumber< N >&& n )
456  : OString( n.buf, n.length )
457  {}
458 #endif
459 
460 #ifdef LIBO_INTERNAL_ONLY
461  OString(std::nullptr_t) = delete;
462 #endif
463 
467 #if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
468  constexpr
469 #endif
471  {
472 #if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
473  if (std::is_constant_evaluated()) {
474  //TODO: We would want to
475  //
476  // assert(SAL_STRING_IS_STATIC(pData));
477  //
478  // here, but that wouldn't work because read of member `str` of OUStringLiteral's
479  // anonymous union with active member `more` is not allowed in a constant expression.
480  } else
481 #endif
482  rtl_string_release( pData );
483  }
484 
485 #if defined LIBO_INTERNAL_ONLY
486 
497  static OString const & unacquired( rtl_String * const * ppHandle )
498  { return * reinterpret_cast< OString const * >( ppHandle ); }
499 #endif
500 
506  OString & operator=( const OString & str )
507  {
508  rtl_string_assign( &pData, str.pData );
509  return *this;
510  }
511 
512 #if defined LIBO_INTERNAL_ONLY
513 #if !defined(__COVERITY__) // suppress COPY_INSTEAD_OF_MOVE suggestions
514 
520  OString & operator=( OString && str ) noexcept
521  {
522  rtl_string_release( pData );
523  pData = str.pData;
524  str.pData = nullptr;
525  rtl_string_new( &str.pData );
526  return *this;
527  }
528 #endif
529 #endif
530 
536  template< typename T >
538  {
539  RTL_STRING_CONST_FUNCTION
540  assert(
543  rtl_string_new(&pData);
544  } else {
546  &pData,
548  literal),
550  }
551  return *this;
552  }
553 
559  OString & operator+=( const OString & str )
560 #if defined LIBO_INTERNAL_ONLY
561  &
562 #endif
563  {
564  rtl_string_newConcat( &pData, pData, str.pData );
565  return *this;
566  }
567 #if defined LIBO_INTERNAL_ONLY
568  void operator+=(OString const &) && = delete;
569 #endif
570 
571 #if defined LIBO_INTERNAL_ONLY
573  operator +=(T const & value) & { return operator +=(std::string_view(value)); }
574  template<typename T> typename libreoffice_internal::CharPtrDetector<T, OString &>::Type
575  operator +=(T const &) && = delete;
576 
577  template<typename T>
578  typename libreoffice_internal::NonConstCharArrayDetector<T, OString &>::Type
579  operator +=(T & value) & { return operator +=(std::string_view(value)); }
580  template<typename T>
581  typename libreoffice_internal::NonConstCharArrayDetector<T, OString &>::Type operator +=(T &) &&
582  = delete;
583 
584  template<typename T> typename libreoffice_internal::ConstCharArrayDetector<T, OString &>::Type
585  operator +=(T & literal) & {
586  assert(libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
587  return operator +=(
588  std::string_view(
589  libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
590  libreoffice_internal::ConstCharArrayDetector<T>::length));
591  }
592  template<typename T> typename libreoffice_internal::ConstCharArrayDetector<T, OString &>::Type
593  operator +=(T &) && = delete;
594 
595  template<std::size_t N> OString & operator +=(OStringLiteral<N> const & literal) &
596  { return operator +=(std::string_view(literal.getStr(), literal.getLength())); }
597  template<std::size_t N> void operator +=(OStringLiteral<N> const &) && = delete;
598 
599  OString & operator +=(std::string_view sv) & {
600  if (sv.empty()) {
601  return *this;
602  }
603  if (sv.size() > sal_uInt32(std::numeric_limits<sal_Int32>::max() - pData->length)) {
604  throw std::bad_alloc();
605  }
606  auto const l = pData->length + sv.size();
607  rtl_string_ensureCapacity(&pData, l);
608  *addDataHelper(pData->buffer + pData->length, sv.data(), sv.size()) = '\0';
609  pData->length = l;
610  return *this;
611  }
612  void operator +=(std::string_view) && = delete;
613 #endif
614 
615 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
616 
620  template< typename T1, typename T2 >
621  OString& operator+=( OStringConcat< T1, T2 >&& c ) & {
622  sal_Int32 l = c.length();
623  if( l == 0 )
624  return *this;
625  l += pData->length;
626  rtl_string_ensureCapacity( &pData, l );
627  char* end = c.addData( pData->buffer + pData->length );
628  *end = '\0';
629  pData->length = l;
630  return *this;
631  }
632  template<typename T1, typename T2> void operator +=(
633  OStringConcat<T1, T2> &&) && = delete;
634 
639  template< std::size_t N >
640  OString& operator+=( OStringNumber< N >&& n ) & {
641  return operator +=(std::string_view(n.buf, n.length));
642  }
643  template<std::size_t N> void operator +=(
644  OStringNumber<N> &&) && = delete;
645 #endif
646 
651  void clear()
652  {
653  rtl_string_new( &pData );
654  }
655 
664  sal_Int32 getLength() const { return pData->length; }
665 
674  bool isEmpty() const
675  {
676  return pData->length == 0;
677  }
678 
690  const char * getStr() const SAL_RETURNS_NONNULL { return pData->buffer; }
691 
701  char operator [](sal_Int32 index) const {
702  // silence spurious -Werror=strict-overflow warnings from GCC 4.8.2
703  assert(index >= 0 && static_cast<sal_uInt32>(index) < static_cast<sal_uInt32>(getLength()));
704  return getStr()[index];
705  }
706 
719  sal_Int32 compareTo( const OString & str ) const
720  {
721  return rtl_str_compare_WithLength( pData->buffer, pData->length,
722  str.pData->buffer, str.pData->length );
723  }
724 
738  sal_Int32 compareTo( const OString & rObj, sal_Int32 maxLength ) const
739  {
740  return rtl_str_shortenedCompare_WithLength( pData->buffer, pData->length,
741  rObj.pData->buffer, rObj.pData->length, maxLength );
742  }
743 
756  sal_Int32 reverseCompareTo( const OString & str ) const
757  {
758  return rtl_str_reverseCompare_WithLength( pData->buffer, pData->length,
759  str.pData->buffer, str.pData->length );
760  }
761 
773  bool equals( const OString & str ) const
774  {
775  if ( pData->length != str.pData->length )
776  return false;
777  if ( pData == str.pData )
778  return true;
779  return rtl_str_reverseCompare_WithLength( pData->buffer, pData->length,
780  str.pData->buffer, str.pData->length ) == 0;
781  }
782 
797  bool equalsL( const char* value, sal_Int32 length ) const
798  {
799  if ( pData->length != length )
800  return false;
801 
802  return rtl_str_reverseCompare_WithLength( pData->buffer, pData->length,
803  value, length ) == 0;
804  }
805 
820 #if defined LIBO_INTERNAL_ONLY
821  bool equalsIgnoreAsciiCase( std::string_view str ) const
822  {
823  if ( sal_uInt32(pData->length) != str.size() )
824  return false;
825  if ( pData->buffer == str.data() )
826  return true;
827  return rtl_str_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
828  str.data(), str.size() ) == 0;
829  }
830 #else
831  bool equalsIgnoreAsciiCase( const OString & str ) const
832  {
833  if ( pData->length != str.pData->length )
834  return false;
835  if ( pData == str.pData )
836  return true;
837  return rtl_str_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
838  str.pData->buffer, str.pData->length ) == 0;
839  }
840 #endif
841 
863  template< typename T >
865  {
866  return rtl_str_compareIgnoreAsciiCase( pData->buffer, asciiStr ) == 0;
867  }
868 
869  template< typename T >
871  {
872  return rtl_str_compareIgnoreAsciiCase( pData->buffer, asciiStr ) == 0;
873  }
874 
880  template< typename T >
882  {
883  RTL_STRING_CONST_FUNCTION
884  assert(
886  return
887  (pData->length
890  pData->buffer, pData->length,
892  literal),
894  == 0);
895  }
896 
916  bool equalsIgnoreAsciiCaseL( const char * asciiStr, sal_Int32 asciiStrLength ) const
917  {
918  if ( pData->length != asciiStrLength )
919  return false;
920 
921  return rtl_str_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
922  asciiStr, asciiStrLength ) == 0;
923  }
924 
940 #if defined LIBO_INTERNAL_ONLY
941  bool match( std::string_view str, sal_Int32 fromIndex = 0 ) const
942  {
943  assert(fromIndex >= 0);
944  return rtl_str_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
945  str.data(), str.size(), str.size() ) == 0;
946  }
947 #else
948  bool match( const OString & 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.pData->buffer, str.pData->length, str.pData->length ) == 0;
953  }
954 #endif
955 
961  template< typename T >
962  typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type match( T& literal, sal_Int32 fromIndex = 0 ) const
963  {
964  RTL_STRING_CONST_FUNCTION
965  assert(
967  assert(fromIndex >= 0);
968  return
970  pData->buffer + fromIndex, pData->length - fromIndex,
972  literal),
975  == 0;
976  }
977 
994  bool matchL(
995  char const * str, sal_Int32 strLength, sal_Int32 fromIndex = 0)
996  const
997  {
998  assert(fromIndex >= 0);
1000  pData->buffer + fromIndex, pData->length - fromIndex,
1001  str, strLength, strLength) == 0;
1002  }
1003 
1004  // This overload is left undefined, to detect calls of matchL that
1005  // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
1006  // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
1007  // platforms):
1008 #if SAL_TYPES_SIZEOFLONG == 8
1009  void matchL(char const *, sal_Int32, rtl_TextEncoding) const;
1010 #endif
1011 
1030 #if defined LIBO_INTERNAL_ONLY
1031  bool matchIgnoreAsciiCase( std::string_view str, sal_Int32 fromIndex = 0 ) const
1032  {
1033  assert(fromIndex >= 0);
1034  return rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
1035  str.data(), str.size(),
1036  str.size() ) == 0;
1037  }
1038 #else
1039  bool matchIgnoreAsciiCase( const OString & str, sal_Int32 fromIndex = 0 ) const
1040  {
1041  assert(fromIndex >= 0);
1042  return rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
1043  str.pData->buffer, str.pData->length,
1044  str.pData->length ) == 0;
1045  }
1046 #endif
1047 
1052  template< typename T >
1053  typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type matchIgnoreAsciiCase( T& literal, sal_Int32 fromIndex = 0 ) const
1054  {
1055  RTL_STRING_CONST_FUNCTION
1056  assert(
1058  assert(fromIndex >= 0);
1059  return
1061  pData->buffer+fromIndex, pData->length-fromIndex,
1063  literal),
1066  == 0;
1067  }
1068 
1069 #if defined LIBO_INTERNAL_ONLY
1070 
1080  bool startsWith(std::string_view str) const {
1081  return match(str);
1082  }
1096  bool startsWith(std::string_view str, OString * rest) const {
1097  assert(rest);
1098  bool b = startsWith(str);
1099  if (b) {
1100  *rest = copy(str.size());
1101  }
1102  return b;
1103  }
1117  bool startsWith(std::string_view str, std::string_view * rest) const {
1118  assert(rest);
1119  bool b = startsWith(str);
1120  if (b) {
1121  *rest = subView(str.size());
1122  }
1123  return b;
1124  }
1125 #else
1126 
1140  bool startsWith(OString const & str, OString * rest = NULL) const {
1141  bool b = match(str);
1142  if (b && rest != NULL) {
1143  *rest = copy(str.getLength());
1144  }
1145  return b;
1146  }
1147 #endif
1148 
1149 #if defined LIBO_INTERNAL_ONLY
1150 
1155  template< typename T >
1157  T & literal) const
1158  {
1159  RTL_STRING_CONST_FUNCTION
1160  return match(literal, 0);
1161  }
1167  template< typename T >
1168  typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type startsWith(
1169  T & literal, OString * rest) const
1170  {
1171  RTL_STRING_CONST_FUNCTION
1172  assert(rest);
1173  bool b = startsWith(literal);
1174  if (b) {
1175  *rest = copy(
1176  libreoffice_internal::ConstCharArrayDetector<T>::length);
1177  }
1178  return b;
1179  }
1184  template< typename T >
1185  typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type startsWith(
1186  T & literal, std::string_view * rest) const
1187  {
1188  RTL_STRING_CONST_FUNCTION
1189  assert(rest);
1190  bool b = startsWith(literal);
1191  if (b) {
1192  *rest = subView(
1193  libreoffice_internal::ConstCharArrayDetector<T>::length);
1194  }
1195  return b;
1196  }
1197 #else
1198 
1203  template< typename T >
1205  T & literal, OString * rest = NULL) const
1206  {
1207  RTL_STRING_CONST_FUNCTION
1208  bool b = match(literal, 0);
1209  if (b && rest != NULL) {
1210  *rest = copy(
1212  }
1213  return b;
1214  }
1215 #endif
1216 
1217 #if defined LIBO_INTERNAL_ONLY
1218 
1234  bool startsWithIgnoreAsciiCase(std::string_view str)
1235  const
1236  {
1237  return matchIgnoreAsciiCase(str);
1238  }
1258  bool startsWithIgnoreAsciiCase(std::string_view str, OString * rest)
1259  const
1260  {
1261  assert(rest);
1262  bool b = startsWithIgnoreAsciiCase(str);
1263  if (b) {
1264  *rest = copy(str.size());
1265  }
1266  return b;
1267  }
1287  bool startsWithIgnoreAsciiCase(std::string_view str, std::string_view * rest)
1288  const
1289  {
1290  assert(rest);
1291  bool b = startsWithIgnoreAsciiCase(str);
1292  if (b) {
1293  *rest = subView(str.size());
1294  }
1295  return b;
1296  }
1297 #else
1298 
1317  bool startsWithIgnoreAsciiCase(OString const & str, OString * rest = NULL)
1318  const
1319  {
1320  bool b = matchIgnoreAsciiCase(str);
1321  if (b && rest != NULL) {
1322  *rest = copy(str.getLength());
1323  }
1324  return b;
1325  }
1326 #endif
1327 
1328 #if defined LIBO_INTERNAL_ONLY
1329 
1334  template< typename T >
1336  startsWithIgnoreAsciiCase(T & literal) const
1337  {
1338  RTL_STRING_CONST_FUNCTION
1339  assert(
1341  return matchIgnoreAsciiCase(literal);
1342  }
1348  template< typename T >
1349  typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
1350  startsWithIgnoreAsciiCase(T & literal, OString * rest) const
1351  {
1352  RTL_STRING_CONST_FUNCTION
1353  assert(rest);
1354  bool b = startsWithIgnoreAsciiCase(literal);
1355  if (b) {
1356  *rest = copy(
1357  libreoffice_internal::ConstCharArrayDetector<T>::length);
1358  }
1359  return b;
1360  }
1361  template< typename T >
1362  typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
1363  startsWithIgnoreAsciiCase(T & literal, std::string_view * rest) const
1364  {
1365  RTL_STRING_CONST_FUNCTION
1366  assert(rest);
1367  bool b = startsWithIgnoreAsciiCase(literal);
1368  if (b) {
1369  *rest = subView(
1370  libreoffice_internal::ConstCharArrayDetector<T>::length);
1371  }
1372  return b;
1373  }
1374 #else
1375 
1380  template< typename T >
1381  typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
1382  startsWithIgnoreAsciiCase(T & literal, OString * rest = NULL) const
1383  {
1384  RTL_STRING_CONST_FUNCTION
1385  assert(
1387  bool b = matchIgnoreAsciiCase(literal);
1388  if (b && rest != NULL) {
1389  *rest = copy(
1391  }
1392  return b;
1393  }
1394 #endif
1395 
1396 #if defined LIBO_INTERNAL_ONLY
1397 
1407  bool endsWith(std::string_view str) const {
1408  return str.size() <= sal_uInt32(getLength())
1409  && match(str, getLength() - str.size());
1410  }
1425  bool endsWith(std::string_view str, OString * rest) const {
1426  assert(rest);
1427  bool b = endsWith(str);
1428  if (b) {
1429  *rest = copy(0, getLength() - str.size());
1430  }
1431  return b;
1432  }
1446  bool endsWith(std::string_view str, std::string_view * rest) const {
1447  assert(rest);
1448  bool b = endsWith(str);
1449  if (b) {
1450  *rest = subView(0, getLength() - str.size());
1451  }
1452  return b;
1453  }
1454 #else
1455 
1469  bool endsWith(OString const & str, OString * rest = NULL) const {
1470  bool b = str.getLength() <= getLength()
1471  && match(str, getLength() - str.getLength());
1472  if (b && rest != NULL) {
1473  *rest = copy(0, getLength() - str.getLength());
1474  }
1475  return b;
1476  }
1477 #endif
1478 
1479 #if defined LIBO_INTERNAL_ONLY
1480 
1485  template< typename T >
1487  T & literal) const
1488  {
1489  RTL_STRING_CONST_FUNCTION
1490  assert(
1492  bool b
1494  <= sal_uInt32(getLength()))
1495  && match(
1497  literal),
1498  (getLength()
1500  return b;
1501  }
1507  template< typename T >
1508  typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type endsWith(
1509  T & literal, OString * rest) const
1510  {
1511  RTL_STRING_CONST_FUNCTION
1512  assert(rest);
1513  bool b = endsWith(literal);
1514  if (b) {
1515  *rest = copy(
1516  0,
1517  (getLength()
1518  - libreoffice_internal::ConstCharArrayDetector<T>::length));
1519  }
1520  return b;
1521  }
1527  template< typename T >
1528  typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type endsWith(
1529  T & literal, std::string_view * rest) const
1530  {
1531  RTL_STRING_CONST_FUNCTION
1532  assert(rest);
1533  bool b = endsWith(literal);
1534  if (b) {
1535  *rest = subView(
1536  0,
1537  (getLength()
1538  - libreoffice_internal::ConstCharArrayDetector<T>::length));
1539  }
1540  return b;
1541  }
1542 #else
1543 
1548  template< typename T >
1550  T & literal, OString * rest = NULL) const
1551  {
1552  RTL_STRING_CONST_FUNCTION
1553  assert(
1555  bool b
1557  <= sal_uInt32(getLength()))
1558  && match(
1560  literal),
1561  (getLength()
1563  if (b && rest != NULL) {
1564  *rest = copy(
1565  0,
1566  (getLength()
1568  }
1569  return b;
1570  }
1571 #endif
1572 
1586  bool endsWithL(char const * str, sal_Int32 strLength) const {
1587  return strLength <= getLength()
1588  && matchL(str, strLength, getLength() - strLength);
1589  }
1590 
1591  friend bool operator == ( const OString& rStr1, const OString& rStr2 )
1592  { return rStr1.equals(rStr2); }
1593  friend bool operator != ( const OString& rStr1, const OString& rStr2 )
1594  { return !(operator == ( rStr1, rStr2 )); }
1595  friend bool operator < ( const OString& rStr1, const OString& rStr2 )
1596  { return rStr1.compareTo( rStr2 ) < 0; }
1597  friend bool operator > ( const OString& rStr1, const OString& rStr2 )
1598  { return rStr1.compareTo( rStr2 ) > 0; }
1599  friend bool operator <= ( const OString& rStr1, const OString& rStr2 )
1600  { return rStr1.compareTo( rStr2 ) <= 0; }
1601  friend bool operator >= ( const OString& rStr1, const OString& rStr2 )
1602  { return rStr1.compareTo( rStr2 ) >= 0; }
1603 
1604  template< typename T >
1605  friend typename libreoffice_internal::CharPtrDetector< T, bool >::Type operator==( const OString& rStr1, const T& value )
1606  {
1607  return
1609  rStr1.getStr(), rStr1.getLength(), value, rtl_str_getLength(value))
1610  == 0;
1611  }
1612 
1613  template< typename T >
1615  {
1616  return
1618  rStr1.getStr(), rStr1.getLength(), value, rtl_str_getLength(value))
1619  == 0;
1620  }
1621 
1622  template< typename T >
1623  friend typename libreoffice_internal::CharPtrDetector< T, bool >::Type operator==( const T& value, const OString& rStr2 )
1624  {
1625  return
1627  value, rtl_str_getLength(value), rStr2.getStr(), rStr2.getLength())
1628  == 0;
1629  }
1630 
1631  template< typename T >
1633  {
1634  return
1636  value, rtl_str_getLength(value), rStr2.getStr(), rStr2.getLength())
1637  == 0;
1638  }
1639 
1645  template< typename T >
1647  {
1648  RTL_STRING_CONST_FUNCTION
1649  assert(
1651  return
1652  (rStr.getLength()
1655  rStr.pData->buffer, rStr.pData->length,
1657  literal),
1659  == 0);
1660  }
1661 
1667  template< typename T >
1669  {
1670  RTL_STRING_CONST_FUNCTION
1671  assert(
1673  return
1674  (rStr.getLength()
1677  rStr.pData->buffer, rStr.pData->length,
1679  literal),
1681  == 0);
1682  }
1683 
1684  template< typename T >
1685  friend typename libreoffice_internal::CharPtrDetector< T, bool >::Type operator!=( const OString& rStr1, const T& value )
1686  {
1687  return !(operator == ( rStr1, value ));
1688  }
1689 
1690  template< typename T >
1692  {
1693  return !(operator == ( rStr1, value ));
1694  }
1695 
1696  template< typename T >
1697  friend typename libreoffice_internal::CharPtrDetector< T, bool >::Type operator!=( const T& value, const OString& rStr2 )
1698  {
1699  return !(operator == ( value, rStr2 ));
1700  }
1701 
1702  template< typename T >
1704  {
1705  return !(operator == ( value, rStr2 ));
1706  }
1707 
1713  template< typename T >
1715  {
1716  return !( rStr == literal );
1717  }
1718 
1724  template< typename T >
1726  {
1727  return !( literal == rStr );
1728  }
1729 
1737  sal_Int32 hashCode() const
1738  {
1739  return rtl_str_hashCode_WithLength( pData->buffer, pData->length );
1740  }
1741 
1755  sal_Int32 indexOf( char ch, sal_Int32 fromIndex = 0 ) const
1756  {
1757  assert(fromIndex >= 0);
1758  sal_Int32 ret = rtl_str_indexOfChar_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, ch );
1759  return (ret < 0 ? ret : ret+fromIndex);
1760  }
1761 
1771  sal_Int32 lastIndexOf( char ch ) const
1772  {
1773  return rtl_str_lastIndexOfChar_WithLength( pData->buffer, pData->length, ch );
1774  }
1775 
1788  sal_Int32 lastIndexOf( char ch, sal_Int32 fromIndex ) const
1789  {
1790  return rtl_str_lastIndexOfChar_WithLength( pData->buffer, fromIndex, ch );
1791  }
1792 
1808 #if defined LIBO_INTERNAL_ONLY
1809  sal_Int32 indexOf( std::string_view str, sal_Int32 fromIndex = 0 ) const
1810  {
1811  assert(fromIndex >= 0);
1812  sal_Int32 ret = rtl_str_indexOfStr_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
1813  str.data(), str.size() );
1814  return (ret < 0 ? ret : ret+fromIndex);
1815  }
1816 #else
1817  sal_Int32 indexOf( const OString & str, sal_Int32 fromIndex = 0 ) const
1818  {
1819  assert(fromIndex >= 0);
1820  sal_Int32 ret = rtl_str_indexOfStr_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
1821  str.pData->buffer, str.pData->length );
1822  return (ret < 0 ? ret : ret+fromIndex);
1823  }
1824 #endif
1825 
1830  template< typename T >
1831  typename libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type indexOf( T& literal, sal_Int32 fromIndex = 0 ) const
1832  {
1833  RTL_STRING_CONST_FUNCTION
1834  assert(
1836  assert(fromIndex >= 0);
1837  sal_Int32 n = rtl_str_indexOfStr_WithLength(
1838  pData->buffer + fromIndex, pData->length - fromIndex,
1841  return n < 0 ? n : n + fromIndex;
1842  }
1843 
1862  sal_Int32 indexOfL(char const * str, sal_Int32 len, sal_Int32 fromIndex = 0)
1863  const
1864  {
1865  assert(fromIndex >= 0);
1866  sal_Int32 n = rtl_str_indexOfStr_WithLength(
1867  pData->buffer + fromIndex, pData->length - fromIndex, str, len);
1868  return n < 0 ? n : n + fromIndex;
1869  }
1870 
1871  // This overload is left undefined, to detect calls of indexOfL that
1872  // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
1873  // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
1874  // platforms):
1875 #if SAL_TYPES_SIZEOFLONG == 8
1876  void indexOfL(char const *, sal_Int32, rtl_TextEncoding) const;
1877 #endif
1878 
1894 #if defined LIBO_INTERNAL_ONLY
1895  sal_Int32 lastIndexOf( std::string_view str ) const
1896  {
1897  return rtl_str_lastIndexOfStr_WithLength( pData->buffer, pData->length,
1898  str.data(), str.size() );
1899  }
1900 #else
1901  sal_Int32 lastIndexOf( const OString & str ) const
1902  {
1903  return rtl_str_lastIndexOfStr_WithLength( pData->buffer, pData->length,
1904  str.pData->buffer, str.pData->length );
1905  }
1906 #endif
1907 
1925 #if defined LIBO_INTERNAL_ONLY
1926  sal_Int32 lastIndexOf( std::string_view str, sal_Int32 fromIndex ) const
1927  {
1928  return rtl_str_lastIndexOfStr_WithLength( pData->buffer, fromIndex,
1929  str.data(), str.size() );
1930  }
1931 #else
1932  sal_Int32 lastIndexOf( const OString & str, sal_Int32 fromIndex ) const
1933  {
1934  return rtl_str_lastIndexOfStr_WithLength( pData->buffer, fromIndex,
1935  str.pData->buffer, str.pData->length );
1936  }
1937 #endif
1938 
1949  SAL_WARN_UNUSED_RESULT OString copy( sal_Int32 beginIndex ) const
1950  {
1951  return copy(beginIndex, getLength() - beginIndex);
1952  }
1953 
1966  SAL_WARN_UNUSED_RESULT OString copy( sal_Int32 beginIndex, sal_Int32 count ) const
1967  {
1968  rtl_String *pNew = NULL;
1969  rtl_string_newFromSubString( &pNew, pData, beginIndex, count );
1970  return OString( pNew, SAL_NO_ACQUIRE );
1971  }
1972 
1973 #if defined LIBO_INTERNAL_ONLY
1974 
1984  SAL_WARN_UNUSED_RESULT std::string_view subView( sal_Int32 beginIndex ) const
1985  {
1986  assert(beginIndex >= 0);
1987  assert(beginIndex <= getLength());
1988  return subView(beginIndex, getLength() - beginIndex);
1989  }
1990 
2003  SAL_WARN_UNUSED_RESULT std::string_view subView( sal_Int32 beginIndex, sal_Int32 count ) const
2004  {
2005  assert(beginIndex >= 0);
2006  assert(count >= 0);
2007  assert(beginIndex <= getLength());
2008  assert(count <= getLength() - beginIndex);
2009  return std::string_view(*this).substr(beginIndex, count);
2010  }
2011 #endif
2012 
2013 #ifndef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
2014 
2023  {
2024  rtl_String* pNew = NULL;
2025  rtl_string_newConcat( &pNew, pData, str.pData );
2026  return OString( pNew, SAL_NO_ACQUIRE );
2027  }
2028 #endif
2029 
2030 #ifndef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
2031  friend OString operator+( const OString & str1, const OString & str2 )
2032  {
2033  return str1.concat( str2 );
2034  }
2035 #endif
2036 
2037 // hide this from internal code to avoid ambiguous lookup error
2038 #ifndef LIBO_INTERNAL_ONLY
2039 
2052  SAL_WARN_UNUSED_RESULT OString replaceAt( sal_Int32 index, sal_Int32 count, const OString& newStr ) const
2053  {
2054  rtl_String* pNew = NULL;
2055  rtl_string_newReplaceStrAt( &pNew, pData, index, count, newStr.pData );
2056  return OString( pNew, SAL_NO_ACQUIRE );
2057  }
2058 #endif
2059 
2060 #ifdef LIBO_INTERNAL_ONLY
2061  SAL_WARN_UNUSED_RESULT OString replaceAt( sal_Int32 index, sal_Int32 count, std::string_view newStr ) const
2062  {
2063  rtl_String* pNew = NULL;
2064  rtl_string_newReplaceStrAt_WithLength ( &pNew, pData, index, count, newStr.data(), newStr.size() );
2065  return OString( pNew, SAL_NO_ACQUIRE );
2066  }
2067 #endif
2068 
2082  SAL_WARN_UNUSED_RESULT OString replace( char oldChar, char newChar ) const
2083  {
2084  rtl_String* pNew = NULL;
2085  rtl_string_newReplace( &pNew, pData, oldChar, newChar );
2086  return OString( pNew, SAL_NO_ACQUIRE );
2087  }
2088 
2108  OString const & from, OString const & to, sal_Int32 * index = NULL) const
2109  {
2110  rtl_String * s = NULL;
2111  sal_Int32 i = 0;
2113  &s, pData, from.pData->buffer, from.pData->length,
2114  to.pData->buffer, to.pData->length, index == NULL ? &i : index);
2115  return OString(s, SAL_NO_ACQUIRE);
2116  }
2117 
2131  SAL_WARN_UNUSED_RESULT OString replaceAll(OString const & from, OString const & to) const {
2132  rtl_String * s = NULL;
2134  &s, pData, from.pData->buffer, from.pData->length,
2135  to.pData->buffer, to.pData->length);
2136  return OString(s, SAL_NO_ACQUIRE);
2137  }
2138 
2150  {
2151  rtl_String* pNew = NULL;
2152  rtl_string_newToAsciiLowerCase( &pNew, pData );
2153  return OString( pNew, SAL_NO_ACQUIRE );
2154  }
2155 
2167  {
2168  rtl_String* pNew = NULL;
2169  rtl_string_newToAsciiUpperCase( &pNew, pData );
2170  return OString( pNew, SAL_NO_ACQUIRE );
2171  }
2172 
2185  {
2186  rtl_String* pNew = NULL;
2187  rtl_string_newTrim( &pNew, pData );
2188  return OString( pNew, SAL_NO_ACQUIRE );
2189  }
2190 
2215  OString getToken( sal_Int32 token, char cTok, sal_Int32& index ) const
2216  {
2217  rtl_String * pNew = NULL;
2218  index = rtl_string_getToken( &pNew, pData, token, cTok, index );
2219  return OString( pNew, SAL_NO_ACQUIRE );
2220  }
2221 
2235  OString getToken(sal_Int32 count, char separator) const {
2236  sal_Int32 n = 0;
2237  return getToken(count, separator, n);
2238  }
2239 
2248  bool toBoolean() const
2249  {
2250  return rtl_str_toBoolean( pData->buffer );
2251  }
2252 
2259  char toChar() const
2260  {
2261  return pData->buffer[0];
2262  }
2263 
2274  sal_Int32 toInt32( sal_Int16 radix = 10 ) const
2275  {
2276  return rtl_str_toInt32( pData->buffer, radix );
2277  }
2278 
2291  sal_uInt32 toUInt32( sal_Int16 radix = 10 ) const
2292  {
2293  return rtl_str_toUInt32( pData->buffer, radix );
2294  }
2295 
2306  sal_Int64 toInt64( sal_Int16 radix = 10 ) const
2307  {
2308  return rtl_str_toInt64( pData->buffer, radix );
2309  }
2310 
2323  sal_uInt64 toUInt64( sal_Int16 radix = 10 ) const
2324  {
2325  return rtl_str_toUInt64( pData->buffer, radix );
2326  }
2327 
2336  float toFloat() const
2337  {
2338  return rtl_str_toFloat( pData->buffer );
2339  }
2340 
2349  double toDouble() const
2350  {
2351  return rtl_str_toDouble( pData->buffer );
2352  }
2353 
2354 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
2355 
2356  static auto number( int i, sal_Int16 radix = 10 )
2357  {
2358  return OStringNumber<RTL_STR_MAX_VALUEOFINT32>(rtl_str_valueOfInt32, i, radix);
2359  }
2360  static auto number( long long ll, sal_Int16 radix = 10 )
2361  {
2362  return OStringNumber<RTL_STR_MAX_VALUEOFINT64>(rtl_str_valueOfInt64, ll, radix);
2363  }
2364  static auto number( unsigned long long ll, sal_Int16 radix = 10 )
2365  {
2366  return OStringNumber<RTL_STR_MAX_VALUEOFUINT64>(rtl_str_valueOfUInt64, ll, radix);
2367  }
2368  static auto number( unsigned int i, sal_Int16 radix = 10 )
2369  {
2370  return number( static_cast< unsigned long long >( i ), radix );
2371  }
2372  static auto number( long i, sal_Int16 radix = 10)
2373  {
2374  return number( static_cast< long long >( i ), radix );
2375  }
2376  static auto number( unsigned long i, sal_Int16 radix = 10 )
2377  {
2378  return number( static_cast< unsigned long long >( i ), radix );
2379  }
2380 #else
2381 
2391  static OString number( int i, sal_Int16 radix = 10 )
2392  {
2393  char aBuf[RTL_STR_MAX_VALUEOFINT32];
2394  return OString(aBuf, rtl_str_valueOfInt32(aBuf, i, radix));
2395  }
2398  static OString number( unsigned int i, sal_Int16 radix = 10 )
2399  {
2400  return number( static_cast< unsigned long long >( i ), radix );
2401  }
2404  static OString number( long i, sal_Int16 radix = 10 )
2405  {
2406  return number( static_cast< long long >( i ), radix );
2407  }
2410  static OString number( unsigned long i, sal_Int16 radix = 10 )
2411  {
2412  return number( static_cast< unsigned long long >( i ), radix );
2413  }
2416  static OString number( long long ll, sal_Int16 radix = 10 )
2417  {
2418  char aBuf[RTL_STR_MAX_VALUEOFINT64];
2419  return OString(aBuf, rtl_str_valueOfInt64(aBuf, ll, radix));
2420  }
2423  static OString number( unsigned long long ll, sal_Int16 radix = 10 )
2424  {
2425  char aBuf[RTL_STR_MAX_VALUEOFUINT64];
2426  return OString(aBuf, rtl_str_valueOfUInt64(aBuf, ll, radix));
2427  }
2428 #endif
2429 
2439  static OString number( float f )
2440  {
2441  rtl_String* pNew = NULL;
2442  // Same as rtl::str::valueOfFP, used for rtl_str_valueOfFloat
2444  RTL_STR_MAX_VALUEOFFLOAT - SAL_N_ELEMENTS("-x.E-xxx") + 1, '.',
2445  NULL, 0, true);
2446  if (pNew == NULL)
2447  throw std::bad_alloc();
2448 
2449  return OString(pNew, SAL_NO_ACQUIRE);
2450  }
2451 
2461  static OString number( double d )
2462  {
2463  rtl_String* pNew = NULL;
2464  // Same as rtl::str::valueOfFP, used for rtl_str_valueOfDouble
2466  RTL_STR_MAX_VALUEOFDOUBLE - SAL_N_ELEMENTS("-x.E-xxx") + 1, '.',
2467  NULL, 0, true);
2468  if (pNew == NULL)
2469  throw std::bad_alloc();
2470 
2471  return OString(pNew, SAL_NO_ACQUIRE);
2472  }
2473 
2474 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
2475  static auto boolean(bool b)
2476  {
2477  return OStringNumber<RTL_STR_MAX_VALUEOFBOOLEAN>(rtl_str_valueOfBoolean, b);
2478  }
2479 #else
2480 
2491  SAL_DEPRECATED("use boolean()") static OString valueOf( sal_Bool b )
2492  {
2493  return boolean(b);
2494  }
2495 
2507  static OString boolean( bool b )
2508  {
2509  char aBuf[RTL_STR_MAX_VALUEOFBOOLEAN];
2510  return OString(aBuf, rtl_str_valueOfBoolean(aBuf, b));
2511  }
2512 #endif
2513 
2521  SAL_DEPRECATED("convert to OString or use directly") static OString valueOf( char c )
2522  {
2523  return OString( &c, 1 );
2524  }
2525 
2536  SAL_DEPRECATED("use number()") static OString valueOf( sal_Int32 i, sal_Int16 radix = 10 )
2537  {
2538  return number( i, radix );
2539  }
2540 
2551  SAL_DEPRECATED("use number()") static OString valueOf( sal_Int64 ll, sal_Int16 radix = 10 )
2552  {
2553  return number( ll, radix );
2554  }
2555 
2565  SAL_DEPRECATED("use number()") static OString valueOf( float f )
2566  {
2567  return number(f);
2568  }
2569 
2579  SAL_DEPRECATED("use number()") static OString valueOf( double d )
2580  {
2581  return number(d);
2582  }
2583 
2584 #if defined LIBO_INTERNAL_ONLY
2585  operator std::string_view() const { return {getStr(), sal_uInt32(getLength())}; }
2586 #endif
2587 
2588 #if defined LIBO_INTERNAL_ONLY
2589  // A wrapper for the first expression in an
2590  //
2591  // OString::Concat(e1) + e2 + ...
2592  //
2593  // concatenation chain, when neither of the first two e1, e2 is one of our rtl string-related
2594  // classes (so something like
2595  //
2596  // OString s = "a" + (b ? std::string_view("c") : std::string_view("dd"));
2597  //
2598  // would not compile):
2599  template<typename T> [[nodiscard]] static
2600  OStringConcat<OStringConcatMarker, T>
2601  Concat(T const & value) { return OStringConcat<OStringConcatMarker, T>(value); }
2602 
2603  // This overload is needed so that an argument of type 'char const[N]' ends up as
2604  // 'OStringConcat<rtl::OStringConcatMarker, char const[N]>' rather than as
2605  // 'OStringConcat<rtl::OStringConcatMarker, char[N]>':
2606  template<typename T, std::size_t N> [[nodiscard]] static
2607  OStringConcat<OStringConcatMarker, T[N]>
2608  Concat(T (& value)[N]) { return OStringConcat<OStringConcatMarker, T[N]>(value); }
2609 #endif
2610 };
2611 
2612 #if defined LIBO_INTERNAL_ONLY
2613 inline bool operator ==(OString const & lhs, StringConcatenation<char> const & rhs)
2614 { return lhs == std::string_view(rhs); }
2615 inline bool operator !=(OString const & lhs, StringConcatenation<char> const & rhs)
2616 { return lhs != std::string_view(rhs); }
2617 inline bool operator ==(StringConcatenation<char> const & lhs, OString const & rhs)
2618 { return std::string_view(lhs) == rhs; }
2619 inline bool operator !=(StringConcatenation<char> const & lhs, OString const & rhs)
2620 { return std::string_view(lhs) != rhs; }
2621 #endif
2622 
2623 /* ======================================================================= */
2624 
2625 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
2626 
2630 template<>
2631 struct ToStringHelper< OString >
2632 {
2633  static std::size_t length( const OString& s ) { return s.getLength(); }
2634  char* operator()( char* buffer, const OString& s ) const { return addDataHelper( buffer, s.getStr(), s.getLength()); }
2635 };
2636 
2640 template<std::size_t N>
2641 struct ToStringHelper< OStringLiteral<N> >
2642 {
2643  static constexpr std::size_t length( const OStringLiteral<N>& str ) { return str.getLength(); }
2644  char* operator()( char* buffer, const OStringLiteral<N>& str ) const { return addDataHelper( buffer, str.getStr(), str.getLength() ); }
2645 };
2646 
2650 template< typename charT, typename traits, typename T1, typename T2 >
2651 inline std::basic_ostream<charT, traits> & operator <<(
2652  std::basic_ostream<charT, traits> & stream, OStringConcat< T1, T2 >&& concat)
2653 {
2654  return stream << OString( std::move(concat) );
2655 }
2656 #endif
2657 
2658 
2665 {
2675  size_t operator()( const OString& rString ) const
2676  { return static_cast<size_t>(rString.hashCode()); }
2677 };
2678 
2681 {
2682  bool operator()( const char* p1, const char* p2) const
2683  { return rtl_str_compare(p1, p2) == 0; }
2684 };
2685 
2688 {
2689  size_t operator()(const char* p) const
2690  { return rtl_str_hashCode(p); }
2691 };
2692 
2693 /* ======================================================================= */
2694 
2701 template< typename charT, typename traits > std::basic_ostream<charT, traits> &
2703  std::basic_ostream<charT, traits> & stream, OString const & rString)
2704 {
2705  return stream << rString.getStr();
2706  // best effort; potentially loses data due to embedded null characters
2707 }
2708 
2709 } /* Namespace */
2710 
2711 #ifdef RTL_STRING_UNITTEST
2712 namespace rtl
2713 {
2714 typedef rtlunittest::OString OString;
2715 }
2716 #undef RTL_STRING_CONST_FUNCTION
2717 #endif
2718 
2719 #if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST
2720 using ::rtl::OString;
2721 using ::rtl::OStringChar;
2722 using ::rtl::Concat2View;
2723 using ::rtl::OStringHash;
2724 using ::rtl::OStringLiteral;
2725 #endif
2726 
2727 #if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
2728 
2729 template<
2730 #if defined RTL_STRING_UNITTEST
2731  rtlunittest::
2732 #endif
2733  OStringLiteral L>
2734 constexpr
2735 #if defined RTL_STRING_UNITTEST
2736  rtlunittest::
2737 #endif
2738  OString
2739 operator ""_ostr() { return L; }
2740 
2741 template<
2742 #if defined RTL_STRING_UNITTEST
2743  rtlunittest::
2744 #endif
2745  OStringLiteral L>
2746 constexpr
2747 #if defined RTL_STRING_UNITTEST
2748 rtlunittest
2749 #else
2750 rtl
2751 #endif
2752 ::detail::OStringHolder<L> operator ""_tstr() {
2753  return
2754 #if defined RTL_STRING_UNITTEST
2755  rtlunittest
2756 #else
2757  rtl
2758 #endif
2759  ::detail::OStringHolder<L>();
2760 }
2761 
2762 #endif
2763 
2765 
2770 #if defined LIBO_INTERNAL_ONLY
2771 namespace std {
2772 
2773 template<>
2774 struct hash<::rtl::OString>
2775 {
2776  std::size_t operator()(::rtl::OString const & s) const
2777  {
2778  if constexpr (sizeof(std::size_t) == 8)
2779  {
2780  // return a hash that uses the full 64-bit range instead of a 32-bit value
2781  size_t n = s.getLength();
2782  for (sal_Int32 i = 0, len = s.getLength(); i < len; ++i)
2783  n = 37 * n + s[i];
2784  return n;
2785  }
2786  else
2787  return std::size_t(s.hashCode());
2788  }
2789 };
2790 
2791 }
2792 
2793 #endif
2794 
2796 #endif // INCLUDED_RTL_STRING_HXX
2797 
2798 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
double toDouble() const
Returns the double value from this string.
Definition: string.hxx:2349
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 ...
Definition: string.hxx:881
#define OUSTRING_TO_OSTRING_CVTFLAGS
Definition: string.h:1350
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 ...
Definition: string.hxx:1714
sal_Int32 getLength() const
Returns the length of this string.
Definition: string.hxx:664
size_t operator()(const char *p) const
Definition: string.hxx:2689
~OString()
Release the string data.
Definition: string.hxx:470
sal_Int64 toInt64(sal_Int16 radix=10) const
Returns the int64 value from this string.
Definition: string.hxx:2306
SAL_DLLPUBLIC sal_Int32 rtl_str_reverseCompare_WithLength(const char *first, sal_Int32 firstLen, const char *second, sal_Int32 secondLen) SAL_THROW_EXTERN_C()
Compare two strings from back to front.
#define RTL_STR_MAX_VALUEOFINT32
Definition: string.h:631
libreoffice_internal::ConstCharArrayDetector< T, OString &>::Type operator=(T &literal)
This is an overloaded member function, provided for convenience. It differs from the above function ...
Definition: string.hxx:537
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:2410
bool equals(const OString &str) const
Perform a comparison of two strings.
Definition: string.hxx:773
OString(T &value, typename libreoffice_internal::NonConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type=libreoffice_internal::Dummy())
Definition: string.hxx:319
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 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_Int32 indexOf(const OString &str, sal_Int32 fromIndex=0) const
Returns the index within this string of the first occurrence of the specified substring, starting at the specified index.
Definition: string.hxx:1817
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 ...
Definition: string.hxx:1646
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:1966
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.
#define RTL_STR_MAX_VALUEOFFLOAT
Definition: string.h:696
SAL_DLLPUBLIC sal_uInt32 rtl_str_toUInt32(const char *str, sal_Int16 radix) SAL_THROW_EXTERN_C()
Interpret a string as an unsigned integer.
#define RTL_STR_MAX_VALUEOFUINT64
Definition: string.h:677
OString(const OString &str)
New string from OString.
Definition: string.hxx:216
sal_Int32 lastIndexOf(const OString &str, sal_Int32 fromIndex) const
Returns the index within this string of the last occurrence of the specified substring, searching backward starting before the specified index.
Definition: string.hxx:1932
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:2166
#define RTL_STR_MAX_VALUEOFINT64
Definition: string.h:654
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.
bool equalsL(const char *value, sal_Int32 length) const
Perform a comparison of two strings.
Definition: string.hxx:797
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 ...
Definition: string.hxx:1204
std::basic_ostream< charT, traits > & operator<<(std::basic_ostream< charT, traits > &stream, OString const &rString)
Support for rtl::OString in std::ostream (and thus in CPPUNIT_ASSERT or SAL_INFO macros, for example).
Definition: string.hxx:2702
SAL_DLLPUBLIC sal_Int32 rtl_str_valueOfBoolean(char *str, sal_Bool b) SAL_THROW_EXTERN_C()
Create the string representation of a boolean.
const char * getStr() const SAL_RETURNS_NONNULL
Returns a pointer to the characters of this string.
Definition: string.hxx:690
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 ...
Definition: string.hxx:1053
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:421
OString getToken(sal_Int32 count, char separator) const
Returns a token from the string.
Definition: string.hxx:2235
OString getToken(sal_Int32 token, char cTok, sal_Int32 &index) const
Returns a token in the string.
Definition: string.hxx:2215
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.
friend libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type operator==(T &value, const OString &rStr2)
Definition: string.hxx:1632
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.
friend libreoffice_internal::CharPtrDetector< T, bool >::Type operator==(const OString &rStr1, const T &value)
Definition: string.hxx:1605
SAL_WARN_UNUSED_RESULT OString concat(const OString &str) const
Concatenates the specified string to the end of this string.
Definition: string.hxx:2022
sal_Int32 compareTo(const OString &str) const
Compares two strings.
Definition: string.hxx:719
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:677
SAL_DLLPUBLIC sal_Int64 rtl_str_toInt64(const char *str, sal_Int16 radix) SAL_THROW_EXTERN_C()
Interpret a string as a long integer.
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 ...
Definition: string.hxx:1549
sal_Int32 reverseCompareTo(const OString &str) const
Compares two strings in reverse order.
Definition: string.hxx:756
bool operator<(const TTimeValue &rTimeA, const TTimeValue &rTimeB)
Definition: timer.hxx:93
bool operator>(const TTimeValue &rTimeA, const TTimeValue &rTimeB)
Definition: timer.hxx:103
OString(rtl_String *str, __sal_NoAcquire)
New string from OString data without acquiring it.
Definition: string.hxx:281
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_uInt64 toUInt64(sal_Int16 radix=10) const
Returns the uint64 value from this string.
Definition: string.hxx:2323
SAL_DLLPUBLIC double rtl_str_toDouble(const char *str) SAL_THROW_EXTERN_C()
Interpret a string as a double.
SAL_DLLPUBLIC void rtl_string_new(rtl_String **newStr) SAL_THROW_EXTERN_C()
Allocate a new string containing no characters.
bool operator==(const TTimeValue &rTimeA, const TTimeValue &rTimeB)
Definition: timer.hxx:113
size_t operator()(const OString &rString) const
Compute a hash code for a string.
Definition: string.hxx:2675
Definition: stringutils.hxx:178
OString(char value)
New string from a single character.
Definition: string.hxx:291
#define SAL_DEPRECATED(message)
Use as follows: SAL_DEPRECATED("Don&#39;t use, it&#39;s evil.") void doit(int nPara);.
Definition: types.h:492
#define SAL_WARN_UNUSED
Annotate classes where a compiler should warn if an instance is unused.
Definition: types.h:611
SAL_DLLPUBLIC sal_Int32 rtl_str_hashCode(const char *str) SAL_THROW_EXTERN_C()
Return a hash code for a string.
A helper to use OStrings with hash maps.
Definition: string.hxx:2664
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.
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:2416
libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type equalsIgnoreAsciiCase(T &asciiStr) const
Definition: string.hxx:870
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:1317
bool equalsIgnoreAsciiCase(const OString &str) const
Perform an ASCII lowercase comparison of two strings.
Definition: string.hxx:831
static OString number(float f)
Returns the string representation of the float argument.
Definition: string.hxx:2439
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:1039
static OString number(double d)
Returns the string representation of the double argument.
Definition: string.hxx:2461
sal_Int32 lastIndexOf(const OString &str) const
Returns the index within this string of the last occurrence of the specified substring, searching backward starting at the end.
Definition: string.hxx:1901
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.
char toChar() const
Returns the first character from this string.
Definition: string.hxx:2259
SAL_DLLPUBLIC void rtl_string_newTrim(rtl_String **newStr, rtl_String *str) SAL_THROW_EXTERN_C()
Create a new string by removing white space from both ends of another string.
SAL_DLLPUBLIC void rtl_string_release(rtl_String *str) SAL_THROW_EXTERN_C()
Decrement the reference count of a string.
#define RTL_STR_MAX_VALUEOFDOUBLE
Definition: string.h:715
sal_Int32 toInt32(sal_Int16 radix=10) const
Returns the int32 value from this string.
Definition: string.hxx:2274
sal_uInt16 sal_Unicode
Definition: types.h:123
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_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:2107
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:2184
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:2131
unsigned char sal_Bool
Definition: types.h:38
#define RTL_STR_MAX_VALUEOFBOOLEAN
Definition: string.h:589
__sal_NoAcquire
Definition: types.h:370
Like sprintf() G, &#39;F&#39; or &#39;E&#39; format is used depending on which one is more compact.
Definition: math.h:53
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 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 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.
OString()
New string containing no characters.
Definition: string.hxx:202
SAL_DLLPUBLIC sal_Bool rtl_str_toBoolean(const char *str) SAL_THROW_EXTERN_C()
Interpret a string as a boolean.
SAL_WARN_UNUSED_RESULT OString copy(sal_Int32 beginIndex) const
Returns a new string that is a substring of this string.
Definition: string.hxx:1949
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.
friend libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type operator==(const OString &rStr1, T &value)
Definition: string.hxx:1614
bool operator()(const char *p1, const char *p2) const
Definition: string.hxx:2682
sal_uInt16 rtl_TextEncoding
The various supported text encodings.
Definition: textenc.h:37
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 ...
Definition: string.hxx:1725
sal_Int32 indexOf(char ch, sal_Int32 fromIndex=0) const
Returns the index within this string of the first occurrence of the specified character, starting the search at the specified index.
Definition: string.hxx:1755
Definition: bootstrap.hxx:33
bool endsWith(OString const &str, OString *rest=NULL) const
Check whether this string ends with a given substring.
Definition: string.hxx:1469
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_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.
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 ...
Definition: string.hxx:1382
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.
static OString boolean(bool b)
Returns the string representation of the boolean argument.
Definition: string.hxx:2507
Hashing functor for classic c-strings (i.e., null-terminated char* strings).
Definition: string.hxx:2687
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_uInt32 toUInt32(sal_Int16 radix=10) const
Returns the uint32 value from this string.
Definition: string.hxx:2291
libreoffice_internal::CharPtrDetector< T, bool >::Type equalsIgnoreAsciiCase(const T &asciiStr) const
Perform an ASCII lowercase comparison of two strings.
Definition: string.hxx:864
This String class provide base functionality for C++ like 8-Bit character array handling.
Definition: string.hxx:192
friend libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type operator!=(T &value, const OString &rStr2)
Definition: string.hxx:1703
void clear()
Clears the string, i.e, makes a zero-character string.
Definition: string.hxx:651
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_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:2082
definition of a no acquire enum for ctors
Definition: types.h:374
OString(const char *value, sal_Int32 length)
New string from a character buffer array.
Definition: string.hxx:372
#define SAL_N_ELEMENTS(arr)
Definition: macros.h:51
float toFloat() const
Returns the float value from this string.
Definition: string.hxx:2336
SAL_DLLPUBLIC void rtl_string_assign(rtl_String **str, rtl_String *rightValue) SAL_THROW_EXTERN_C()
Assign a new value to a string.
bool equalsIgnoreAsciiCaseL(const char *asciiStr, sal_Int32 asciiStrLength) const
Perform an ASCII lowercase comparison of two strings.
Definition: string.hxx:916
sal_Int32 oslInterlockedCount
Definition: interlck.h:44
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:312
SAL_DLLPUBLIC void rtl_string_newFromLiteral(rtl_String **newStr, const char *value, sal_Int32 len, sal_Int32 allocExtra) SAL_THROW_EXTERN_C()
Definition: stringutils.hxx:180
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:2423
bool endsWithL(char const *str, sal_Int32 strLength) const
Check whether this string ends with a given substring.
Definition: string.hxx:1586
OString(T &literal, typename libreoffice_internal::ConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type=libreoffice_internal::Dummy())
New string from a string literal.
Definition: string.hxx:345
static OString number(int i, sal_Int16 radix=10)
Returns the string representation of the integer argument.
Definition: string.hxx:2391
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.
Equality functor for classic c-strings (i.e., null-terminated char* strings).
Definition: string.hxx:2680
SAL_DLLPUBLIC sal_Int32 rtl_str_getLength(const char *str) SAL_THROW_EXTERN_C()
Return the length of a string.
sal_Int32 compareTo(const OString &rObj, sal_Int32 maxLength) const
Compares two strings with an maximum count of characters.
Definition: string.hxx:738
#define SAL_WARN_UNUSED_RESULT
Use this as markup for functions and methods whose return value must be used.
Definition: types.h:288
bool isEmpty() const
Checks if a string is empty.
Definition: string.hxx:674
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 ...
Definition: string.hxx:1668
SAL_DLLPUBLIC void rtl_string_newReplaceFirst(rtl_String **newStr, rtl_String *str, char const *from, sal_Int32 fromLength, char const *to, sal_Int32 toLength, sal_Int32 *index) SAL_THROW_EXTERN_C()
Create a new string by replacing the first occurrence of a given substring with another substring...
SAL_DLLPUBLIC sal_Int32 rtl_str_valueOfInt64(char *str, sal_Int64 l, sal_Int16 radix) SAL_THROW_EXTERN_C()
Create the string representation of a long integer.
friend libreoffice_internal::CharPtrDetector< T, bool >::Type operator!=(const OString &rStr1, const T &value)
Definition: string.hxx:1685
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_Int32 lastIndexOf(char ch, sal_Int32 fromIndex) const
Returns the index within this string of the last occurrence of the specified character, searching backward starting before the specified index.
Definition: string.hxx:1788
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_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:2052
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.
bool match(const OString &str, sal_Int32 fromIndex=0) const
Match against a substring appearing in this string.
Definition: string.hxx:948
OString(rtl_String *str)
New string from OString data.
Definition: string.hxx:268
SAL_DLLPUBLIC void rtl_string_acquire(rtl_String *str) SAL_THROW_EXTERN_C()
Increment the reference count of a string.
bool startsWith(OString const &str, OString *rest=NULL) const
Check whether this string starts with a given substring.
Definition: string.hxx:1140
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 ...
Definition: string.hxx:1831
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:2398
SAL_DLLPUBLIC sal_Int32 rtl_str_compare(const char *first, const char *second) SAL_THROW_EXTERN_C()
Compare two strings.
static OString number(long i, sal_Int16 radix=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: string.hxx:2404
bool toBoolean() const
Returns the Boolean value from this string.
Definition: string.hxx:2248
OString & operator=(const OString &str)
Assign a new string.
Definition: string.hxx:506
friend libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type operator!=(const OString &rStr1, T &value)
Definition: string.hxx:1691
OString & operator+=(const OString &str)
Append a string to this string.
Definition: string.hxx:559
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:2149
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 float rtl_str_toFloat(const char *str) SAL_THROW_EXTERN_C()
Interpret a string as a float.
friend OString operator+(const OString &str1, const OString &str2)
Definition: string.hxx:2031
sal_Int32 lastIndexOf(char ch) const
Returns the index within this string of the last occurrence of the specified character, searching backward starting at the end.
Definition: string.hxx:1771
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 ...
Definition: string.hxx:962
bool matchL(char const *str, sal_Int32 strLength, sal_Int32 fromIndex=0) const
Match against a substring appearing in this string.
Definition: string.hxx:994
friend libreoffice_internal::CharPtrDetector< T, bool >::Type operator!=(const T &value, const OString &rStr2)
Definition: string.hxx:1697
sal_Int32 hashCode() const
Returns a hashcode for this string.
Definition: string.hxx:1737
SAL_DLLPUBLIC sal_Int32 rtl_str_toInt32(const char *str, sal_Int16 radix) SAL_THROW_EXTERN_C()
Interpret a string as an integer.
SAL_DLLPUBLIC rtl_String * rtl_string_alloc(sal_Int32 nLen) SAL_THROW_EXTERN_C()
Allocate a new string containing space for a given number of characters.
friend libreoffice_internal::CharPtrDetector< T, bool >::Type operator==(const T &value, const OString &rStr2)
Definition: string.hxx:1623
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_newToAsciiLowerCase(rtl_String **newStr, rtl_String *str) SAL_THROW_EXTERN_C()
Create a new string by converting all ASCII uppercase letters to lowercase within another string...
sal_Int32 indexOfL(char const *str, sal_Int32 len, sal_Int32 fromIndex=0) const
Returns the index within this string of the first occurrence of the specified substring, starting at the specified index.
Definition: string.hxx:1862