LibreOffice
LibreOffice 25.2 SDK C/C++ API Reference
ustring.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_USTRING_HXX
25 #define INCLUDED_RTL_USTRING_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 
37 #if defined LIBO_INTERNAL_ONLY
38 #include <algorithm>
39 #include <string_view>
40 #include <type_traits>
41 #endif
42 
43 #include "rtl/math.h"
44 #include "rtl/ustring.h"
45 #include "rtl/string.hxx"
46 #include "rtl/stringutils.hxx"
47 #include "rtl/textenc.h"
48 
49 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
50 #include "config_global.h"
51 #include "o3tl/safeint.hxx"
52 #include "rtl/stringconcat.hxx"
53 #endif
54 
55 #ifdef RTL_STRING_UNITTEST
56 extern bool rtl_string_unittest_invalid_conversion;
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 
71 class OUStringBuffer;
72 
73 #ifdef RTL_STRING_UNITTEST
74 #undef rtl
75 #endif
76 
77 #if defined LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
78 
86 template<std::size_t N> class SAL_WARN_UNUSED OUStringLiteral {
87  static_assert(N != 0);
88  static_assert(N - 1 <= std::numeric_limits<sal_Int32>::max(), "literal too long");
89 
90 public:
91 #if HAVE_CPP_CONSTEVAL
92  consteval
93 #else
94  constexpr
95 #endif
96  OUStringLiteral(char16_t const (&literal)[N]) {
97  assertLayout();
98  assert(literal[N - 1] == '\0');
99  std::copy_n(literal, N, more.buffer);
100  }
101 
102  constexpr sal_Int32 getLength() const { return more.length; }
103 
104  constexpr sal_Unicode const * getStr() const SAL_RETURNS_NONNULL { return more.buffer; }
105 
106  constexpr operator std::u16string_view() const { return {more.buffer, sal_uInt32(more.length)}; }
107 
108 private:
109  static constexpr void assertLayout() {
110  // These static_asserts verifying the layout compatibility with rtl_uString cannot be class
111  // member declarations, as offsetof requires a complete type, so defer them to here:
112  static_assert(std::is_standard_layout_v<OUStringLiteral>);
113  static_assert(offsetof(OUStringLiteral, str.refCount) == offsetof(OUStringLiteral, more.refCount));
114  static_assert(offsetof(OUStringLiteral, str.length) == offsetof(OUStringLiteral, more.length));
115  static_assert(offsetof(OUStringLiteral, str.buffer) == offsetof(OUStringLiteral, more.buffer));
116  }
117 
118  struct Data {
119  Data() = default;
120 
121  oslInterlockedCount refCount = 0x40000000; // SAL_STRING_STATIC_FLAG (sal/rtl/strimp.hxx)
122  sal_Int32 length = N - 1;
123  sal_Unicode buffer[N];
124  };
125 
126 public:
127  // (Data members must be public so that OUStringLiteral is a structural type that can be used as
128  // a non-type template parameter type for operator ""_ustr:)
129  union {
130  rtl_uString str;
131  Data more = {};
132  };
133 };
134 
135 #if defined RTL_STRING_UNITTEST
136 namespace libreoffice_internal {
137 template<std::size_t N> struct ExceptConstCharArrayDetector<OUStringLiteral<N>> {};
138 template<std::size_t N> struct ExceptCharArrayDetector<OUStringLiteral<N>> {};
139 }
140 #endif
141 
143 #endif
144 
145 /* ======================================================================= */
146 
170 // coverity[ missing_move_assignment : SUPPRESS] - don't report the suppressed move assignment
171 class SAL_WARN_UNUSED SAL_DLLPUBLIC_RTTI OUString
172 {
173 public:
175  rtl_uString * pData;
177 
182  {
183  pData = NULL;
184  rtl_uString_new( &pData );
185  }
186 
192 #if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
193  constexpr
194 #endif
195  OUString( const OUString & str )
196  {
197  pData = str.pData;
198 #if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
199  if (std::is_constant_evaluated()) {
200  //TODO: We would want to
201  //
202  // assert(SAL_STRING_IS_STATIC(pData));
203  //
204  // here, but that wouldn't work because read of member `str` of OUStringLiteral's
205  // anonymous union with active member `more` is not allowed in a constant expression.
206  } else
207 #endif
208  rtl_uString_acquire( pData );
209  }
210 
211 #if defined LIBO_INTERNAL_ONLY
212 #if !defined(__COVERITY__) // suppress COPY_INSTEAD_OF_MOVE suggestions
213 
219 #if !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
220  constexpr
221 #endif
222  OUString( OUString && str ) noexcept
223  {
224  pData = str.pData;
225 #if !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
226  if (std::is_constant_evaluated()) {
227  //TODO: We would want to
228  //
229  // assert(SAL_STRING_IS_STATIC(pData));
230  //
231  // here, but that wouldn't work because read of member `str` of OUStringLiteral's
232  // anonymous union with active member `more` is not allowed in a constant expression.
233  return;
234  }
235 #endif
236  str.pData = nullptr;
237  rtl_uString_new( &str.pData );
238  }
239 #endif
240 #endif
241 
247  OUString( rtl_uString * str )
248  {
249  pData = str;
250  rtl_uString_acquire( pData );
251  }
252 
253 #if defined LIBO_INTERNAL_ONLY
254  // Catch inadvertent conversions to the above ctor:
256  OUString(std::nullptr_t) = delete;
258 #endif
259 
268  OUString( rtl_uString * str, __sal_NoAcquire )
269  { pData = str; }
270 
276  explicit OUString( sal_Unicode value )
277  : pData (NULL)
278  {
279  rtl_uString_newFromStr_WithLength( &pData, &value, 1 );
280  }
281 
282 #if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST_CONCAT
283  // Catch inadvertent conversions to the above ctor (but still allow
285  // construction from char literals):
286  OUString(int) = delete;
287  explicit OUString(char c):
288  OUString(sal_Unicode(static_cast<unsigned char>(c)))
289  {}
291 #endif
292 
293 #if defined LIBO_INTERNAL_ONLY
294 
295  template<typename T> explicit OUString(
296  T const & value,
297  typename libreoffice_internal::CharPtrDetector<T, libreoffice_internal::Dummy>::TypeUtf16
298  = libreoffice_internal::Dummy()):
299  pData(nullptr)
300  { rtl_uString_newFromStr(&pData, value); }
301 
302  template<typename T> explicit OUString(
303  T & value,
304  typename
305  libreoffice_internal::NonConstCharArrayDetector<T, libreoffice_internal::Dummy>::TypeUtf16
306  = libreoffice_internal::Dummy()):
307  pData(nullptr)
308  { rtl_uString_newFromStr(&pData, value); }
309 
310 #else
311 
317  OUString( const sal_Unicode * value )
318  {
319  pData = NULL;
320  rtl_uString_newFromStr( &pData, value );
321  }
322 
323 #endif
324 
333  OUString( const sal_Unicode * value, sal_Int32 length )
334  {
335  pData = NULL;
336  rtl_uString_newFromStr_WithLength( &pData, value, length );
337  }
338 
354  template< typename T >
356  {
357  assert(
359  pData = NULL;
361  rtl_uString_new(&pData);
362  } else {
364  &pData,
366  literal),
368  }
369 #ifdef RTL_STRING_UNITTEST
370  rtl_string_unittest_const_literal = true;
371 #endif
372  }
373 
374 #if defined LIBO_INTERNAL_ONLY
375  // Rather use a u""_ustr literal (but don't remove this entirely, to avoid implicit support for
376  // it via std::u16string_view from kicking in):
377  template<typename T> OUString(
378  T &,
380  T, libreoffice_internal::Dummy>::TypeUtf16
381  = libreoffice_internal::Dummy()) = delete;
382 
383  OUString(OUStringChar c): pData(nullptr) { rtl_uString_newFromStr_WithLength(&pData, &c.c, 1); }
384 #endif
385 
386 #if defined LIBO_INTERNAL_ONLY && defined RTL_STRING_UNITTEST
387 
392  template< typename T >
393  OUString( T&, typename libreoffice_internal::ExceptConstCharArrayDetector< T >::Type = libreoffice_internal::Dummy() )
394  {
395  pData = NULL;
396  rtl_uString_newFromLiteral( &pData, "!!br0ken!!", 10, 0 ); // set to garbage
397  rtl_string_unittest_invalid_conversion = true;
398  }
403  template< typename T >
404  OUString( const T&, typename libreoffice_internal::ExceptCharArrayDetector< T >::Type = libreoffice_internal::Dummy() )
405  {
406  pData = NULL;
407  rtl_uString_newFromLiteral( &pData, "!!br0ken!!", 10, 0 ); // set to garbage
408  rtl_string_unittest_invalid_conversion = true;
409  }
411 #endif
412 
413 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
414 
420  template<std::size_t N> constexpr OUString(OUStringLiteral<N> const & literal):
421  pData(const_cast<rtl_uString *>(&literal.str)) {}
422  template<std::size_t N> OUString(OUStringLiteral<N> &&) = delete;
424 #endif
425 
426 #if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
427  // For operator ""_tstr:
428  template<OStringLiteral L> OUString(detail::OStringHolder<L> const & holder) {
429  pData = nullptr;
430  if (holder.literal.getLength() == 0) {
431  rtl_uString_new(&pData);
432  } else {
434  &pData, holder.literal.getStr(), holder.literal.getLength(), 0);
435  }
436  }
437 #endif
438 
453  OUString( const char * value, sal_Int32 length,
454  rtl_TextEncoding encoding,
455  sal_uInt32 convertFlags = OSTRING_TO_OUSTRING_CVTFLAGS )
456  {
457  pData = NULL;
458  rtl_string2UString( &pData, value, length, encoding, convertFlags );
459  if (pData == NULL) {
460  throw std::bad_alloc();
461  }
462  }
463 
480  explicit OUString(
481  sal_uInt32 const * codePoints, sal_Int32 codePointCount):
482  pData(NULL)
483  {
484  rtl_uString_newFromCodePoints(&pData, codePoints, codePointCount);
485  if (pData == NULL) {
486  throw std::bad_alloc();
487  }
488  }
489 
490 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
491 
495  template< typename T1, typename T2 >
496  OUString( OUStringConcat< T1, T2 >&& c )
497  {
498  const sal_Int32 l = c.length();
499  pData = rtl_uString_alloc( l );
500  if (l != 0)
501  {
502  sal_Unicode* end = c.addData( pData->buffer );
503  pData->length = l;
504  *end = '\0';
505  }
506  }
507 
512  template< std::size_t N >
513  OUString( OUStringNumber< N >&& n )
514  : OUString( n.buf, n.length )
515  {}
516 #endif
517 
518 #if defined LIBO_INTERNAL_ONLY
519  explicit OUString(std::u16string_view sv) {
520  if (sv.size() > sal_uInt32(std::numeric_limits<sal_Int32>::max())) {
521  throw std::bad_alloc();
522  }
523  pData = nullptr;
524  rtl_uString_newFromStr_WithLength(&pData, sv.data(), sv.size());
525  }
526 #endif
527 
531 #if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
532  constexpr
533 #endif
535  {
536 #if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
537  if (std::is_constant_evaluated()) {
538  //TODO: We would want to
539  //
540  // assert(SAL_STRING_IS_STATIC(pData));
541  //
542  // here, but that wouldn't work because read of member `str` of OUStringLiteral's
543  // anonymous union with active member `more` is not allowed in a constant expression.
544  } else
545 #endif
546  rtl_uString_release( pData );
547  }
548 
560  static OUString const & unacquired( rtl_uString * const * ppHandle )
561  { return * reinterpret_cast< OUString const * >( ppHandle ); }
562 
563 #if defined LIBO_INTERNAL_ONLY
564 
576  static OUString const& unacquired(const OUStringBuffer& str);
577 #endif
578 
584  OUString & operator=( const OUString & str )
585  {
586  rtl_uString_assign( &pData, str.pData );
587  return *this;
588  }
589 
590 #if defined LIBO_INTERNAL_ONLY
591 #if !defined(__COVERITY__) // suppress COPY_INSTEAD_OF_MOVE suggestions
592 
598  OUString & operator=( OUString && str ) noexcept
599  {
600  std::swap(pData, str.pData);
601  return *this;
602  }
603 #endif
604 #endif
605 
618  template< typename T >
620  {
621  assert(
624  rtl_uString_new(&pData);
625  } else {
627  &pData,
629  literal),
631  }
632  return *this;
633  }
634 
635 #if defined LIBO_INTERNAL_ONLY
636  // Rather assign from a u""_ustr literal (but don't remove this entirely, to avoid implicit
637  // support for it via std::u16string_view from kicking in):
638  template<typename T>
639  typename
641  operator =(T &) = delete;
642 
643  OUString & operator =(OUStringChar c) {
644  rtl_uString_newFromStr_WithLength(&pData, &c.c, 1);
645  return *this;
646  }
647 
649  template<std::size_t N> OUString & operator =(OUStringLiteral<N> const & literal) {
650  rtl_uString_release(pData);
651  pData = const_cast<rtl_uString *>(&literal.str);
652  return *this;
653  }
654  template<std::size_t N> OUString & operator =(OUStringLiteral<N> &&) = delete;
655 
656  template <std::size_t N>
657  OUString & operator =(OUStringNumber<N> && n) {
658  // n.length should never be zero, so no need to add an optimization for that case
659  rtl_uString_newFromStr_WithLength(&pData, n.buf, n.length);
660  return *this;
661  }
662 
663  OUString & operator =(std::u16string_view sv) {
664  if (sv.empty()) {
665  rtl_uString_new(&pData);
666  } else {
667  rtl_uString_newFromStr_WithLength(&pData, sv.data(), sv.size());
668  }
669  return *this;
670  }
671 #endif
672 
673 #if defined LIBO_INTERNAL_ONLY
674 
682  inline OUString & operator+=( const OUStringBuffer & str ) &;
683 #endif
684 
692  OUString & operator+=( const OUString & str )
693 #if defined LIBO_INTERNAL_ONLY
694  &
695 #endif
696  {
697  return internalAppend(str.pData);
698  }
699 #if defined LIBO_INTERNAL_ONLY
700  void operator+=(OUString const &) && = delete;
701 #endif
702 
709  template<typename T>
711  operator +=(T & literal)
712 #if defined LIBO_INTERNAL_ONLY
713  &
714 #endif
715  {
716  assert(
719  &pData, pData,
722  return *this;
723  }
724 #if defined LIBO_INTERNAL_ONLY
725  template<typename T>
727  operator +=(T &) && = delete;
728 #endif
729 
730 #if defined LIBO_INTERNAL_ONLY
731 
732  template<typename T>
733  typename
735  operator +=(T & literal) & {
737  &pData, pData,
740  return *this;
741  }
742  template<typename T>
743  typename
744  libreoffice_internal::ConstCharArrayDetector<T, OUString &>::TypeUtf16
745  operator +=(T &) && = delete;
746 
748  template<std::size_t N> OUString & operator +=(OUStringLiteral<N> const & literal) & {
749  rtl_uString_newConcatUtf16L(&pData, pData, literal.getStr(), literal.getLength());
750  return *this;
751  }
752  template<std::size_t N> void operator +=(OUStringLiteral<N> const &) && = delete;
753 
754  OUString & operator +=(std::u16string_view sv) & {
755  if (sv.size() > sal_uInt32(std::numeric_limits<sal_Int32>::max())) {
756  throw std::bad_alloc();
757  }
758  rtl_uString_newConcatUtf16L(&pData, pData, sv.data(), sv.size());
759  return *this;
760  }
761  void operator +=(std::u16string_view) && = delete;
762 #endif
763 
764 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
765 
769  template< typename T1, typename T2 >
770  OUString& operator+=( OUStringConcat< T1, T2 >&& c ) & {
771  sal_Int32 l = c.length();
772  if( l == 0 )
773  return *this;
774  l += pData->length;
775  rtl_uString_ensureCapacity( &pData, l );
776  sal_Unicode* end = c.addData( pData->buffer + pData->length );
777  *end = '\0';
778  pData->length = l;
779  return *this;
780  }
781  template<typename T1, typename T2> void operator +=(
782  OUStringConcat<T1, T2> &&) && = delete;
783 
788  template< std::size_t N >
789  OUString& operator+=( OUStringNumber< N >&& n ) & {
790  sal_Int32 l = n.length;
791  if( l == 0 )
792  return *this;
793  l += pData->length;
794  rtl_uString_ensureCapacity( &pData, l );
795  sal_Unicode* end = addDataHelper( pData->buffer + pData->length, n.buf, n.length );
796  *end = '\0';
797  pData->length = l;
798  return *this;
799  }
800  template<std::size_t N> void operator +=(
801  OUStringNumber<N> &&) && = delete;
802 #endif
803 
808  void clear()
809  {
810  rtl_uString_new( &pData );
811  }
812 
821  sal_Int32 getLength() const { return pData->length; }
822 
831  bool isEmpty() const
832  {
833  return pData->length == 0;
834  }
835 
843  const sal_Unicode * getStr() const SAL_RETURNS_NONNULL { return pData->buffer; }
844 
854  sal_Unicode operator [](sal_Int32 index) const {
855  // silence spurious -Werror=strict-overflow warnings from GCC 4.8.2
856  assert(index >= 0 && static_cast<sal_uInt32>(index) < static_cast<sal_uInt32>(getLength()));
857  return getStr()[index];
858  }
859 
872 #if defined LIBO_INTERNAL_ONLY
873  sal_Int32 compareTo( std::u16string_view str ) const
874  {
875  return rtl_ustr_compare_WithLength( pData->buffer, pData->length,
876  str.data(), str.length() );
877  }
878 #else
879  sal_Int32 compareTo( const OUString & str ) const
880  {
881  return rtl_ustr_compare_WithLength( pData->buffer, pData->length,
882  str.pData->buffer, str.pData->length );
883  }
884 #endif
885 
901 #if defined LIBO_INTERNAL_ONLY
902  sal_Int32 compareTo( std::u16string_view str, sal_Int32 maxLength ) const
903  {
904  return rtl_ustr_shortenedCompare_WithLength( pData->buffer, pData->length,
905  str.data(), str.length(), maxLength );
906  }
907 #else
908  sal_Int32 compareTo( const OUString & str, sal_Int32 maxLength ) const
909  {
910  return rtl_ustr_shortenedCompare_WithLength( pData->buffer, pData->length,
911  str.pData->buffer, str.pData->length, maxLength );
912  }
913 #endif
914 
927 #if defined LIBO_INTERNAL_ONLY
928  sal_Int32 reverseCompareTo(std::u16string_view sv) const {
930  pData->buffer, pData->length, sv.data(), sv.size());
931  }
932 #else
933  sal_Int32 reverseCompareTo( const OUString & str ) const
934  {
935  return rtl_ustr_reverseCompare_WithLength( pData->buffer, pData->length,
936  str.pData->buffer, str.pData->length );
937  }
938 #endif
939 
945  template< typename T >
947  {
948  assert(
951  pData->buffer, pData->length,
954  }
955 
967  bool equals( const OUString & str ) const
968  {
969  if ( pData->length != str.pData->length )
970  return false;
971  if ( pData == str.pData )
972  return true;
973  return rtl_ustr_reverseCompare_WithLength( pData->buffer, pData->length,
974  str.pData->buffer, str.pData->length ) == 0;
975  }
976 
991 #if defined LIBO_INTERNAL_ONLY
992  bool equalsIgnoreAsciiCase(std::u16string_view sv) const {
993  if ( sal_uInt32(pData->length) != sv.size() )
994  return false;
995  if ( pData->buffer == sv.data() )
996  return true;
997  return
999  pData->buffer, pData->length, sv.data(), sv.size())
1000  == 0;
1001  }
1002 #else
1003  bool equalsIgnoreAsciiCase( const OUString & str ) const
1004  {
1005  if ( pData->length != str.pData->length )
1006  return false;
1007  if ( pData == str.pData )
1008  return true;
1009  return rtl_ustr_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
1010  str.pData->buffer, str.pData->length ) == 0;
1011  }
1012 #endif
1013 
1029 #if defined LIBO_INTERNAL_ONLY
1030  sal_Int32 compareToIgnoreAsciiCase(std::u16string_view sv) const {
1032  pData->buffer, pData->length, sv.data(), sv.size());
1033  }
1034 #else
1035  sal_Int32 compareToIgnoreAsciiCase( const OUString & str ) const
1036  {
1037  return rtl_ustr_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
1038  str.pData->buffer, str.pData->length );
1039  }
1040 #endif
1041 
1047  template< typename T >
1049  {
1050  assert(
1052  return
1053  (pData->length
1056  pData->buffer, pData->length,
1058  literal))
1059  == 0);
1060  }
1061 
1077 #if defined LIBO_INTERNAL_ONLY
1078  bool match(std::u16string_view sv, sal_Int32 fromIndex = 0) const {
1079  assert(fromIndex >= 0);
1080  return
1082  pData->buffer + fromIndex, pData->length - fromIndex, sv.data(), sv.size(),
1083  sv.size())
1084  == 0;
1085  }
1086 #else
1087  bool match( const OUString & str, sal_Int32 fromIndex = 0 ) const
1088  {
1089  assert(fromIndex >= 0);
1090  return rtl_ustr_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
1091  str.pData->buffer, str.pData->length, str.pData->length ) == 0;
1092  }
1093 #endif
1094 
1100  template< typename T >
1101  typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type match( T& literal, sal_Int32 fromIndex = 0 ) const
1102  {
1103  assert(
1105  assert(fromIndex >= 0);
1106  return
1108  pData->buffer+fromIndex, pData->length-fromIndex,
1110  literal),
1112  == 0;
1113  }
1114 
1133 #if defined LIBO_INTERNAL_ONLY
1134  bool matchIgnoreAsciiCase(std::u16string_view sv, sal_Int32 fromIndex = 0) const {
1135  assert(fromIndex >= 0);
1136  return
1138  pData->buffer + fromIndex, pData->length - fromIndex, sv.data(), sv.size(),
1139  sv.size())
1140  == 0;
1141  }
1142 #else
1143  bool matchIgnoreAsciiCase( const OUString & str, sal_Int32 fromIndex = 0 ) const
1144  {
1145  assert(fromIndex >= 0);
1146  return rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
1147  str.pData->buffer, str.pData->length,
1148  str.pData->length ) == 0;
1149  }
1150 #endif
1151 
1157  template< typename T >
1158  typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type matchIgnoreAsciiCase( T& literal, sal_Int32 fromIndex = 0 ) const
1159  {
1160  assert(
1162  return matchIgnoreAsciiCaseAsciiL(
1165  }
1166 
1183  sal_Int32 compareToAscii( const char* asciiStr ) const
1184  {
1185  return rtl_ustr_ascii_compare_WithLength( pData->buffer, pData->length, asciiStr );
1186  }
1187 
1211  "replace s1.compareToAscii(s2, strlen(s2)) == 0 with s1.startsWith(s2)")
1212  sal_Int32 compareToAscii( const char * asciiStr, sal_Int32 maxLength ) const
1213  {
1214  return rtl_ustr_ascii_shortenedCompare_WithLength( pData->buffer, pData->length,
1215  asciiStr, maxLength );
1216  }
1217 
1236  sal_Int32 reverseCompareToAsciiL( const char * asciiStr, sal_Int32 asciiStrLength ) const
1237  {
1238  return rtl_ustr_asciil_reverseCompare_WithLength( pData->buffer, pData->length,
1239  asciiStr, asciiStrLength );
1240  }
1241 
1257  bool equalsAscii( const char* asciiStr ) const
1258  {
1259  return rtl_ustr_ascii_compare_WithLength( pData->buffer, pData->length,
1260  asciiStr ) == 0;
1261  }
1262 
1279  bool equalsAsciiL( const char* asciiStr, sal_Int32 asciiStrLength ) const
1280  {
1281  if ( pData->length != asciiStrLength )
1282  return false;
1283 
1285  pData->buffer, asciiStr, asciiStrLength );
1286  }
1287 
1306  bool equalsIgnoreAsciiCaseAscii( const char * asciiStr ) const
1307  {
1308  return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, asciiStr ) == 0;
1309  }
1310 
1311 #if defined LIBO_INTERNAL_ONLY
1312  bool equalsIgnoreAsciiCaseAscii( std::string_view asciiStr ) const
1313  {
1314  return o3tl::make_unsigned(pData->length) == asciiStr.length()
1316  pData->buffer, pData->length, asciiStr.data(), asciiStr.length()) == 0;
1317  }
1318 #endif
1319 
1338  sal_Int32 compareToIgnoreAsciiCaseAscii( const char * asciiStr ) const
1339  {
1340  return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, asciiStr );
1341  }
1342 
1343 #if defined LIBO_INTERNAL_ONLY
1344  sal_Int32 compareToIgnoreAsciiCaseAscii( std::string_view asciiStr ) const
1345  {
1346  sal_Int32 nMax = std::min<size_t>(asciiStr.length(), std::numeric_limits<sal_Int32>::max());
1348  pData->buffer, pData->length, asciiStr.data(), nMax);
1349  if (result == 0 && o3tl::make_unsigned(pData->length) < asciiStr.length())
1350  result = -1;
1351  return result;
1352  }
1353 #endif
1354 
1374  bool equalsIgnoreAsciiCaseAsciiL( const char * asciiStr, sal_Int32 asciiStrLength ) const
1375  {
1376  if ( pData->length != asciiStrLength )
1377  return false;
1378 
1379  return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, asciiStr ) == 0;
1380  }
1381 
1402  bool matchAsciiL( const char* asciiStr, sal_Int32 asciiStrLength, sal_Int32 fromIndex = 0 ) const
1403  {
1404  assert(fromIndex >= 0);
1405  return rtl_ustr_ascii_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
1406  asciiStr, asciiStrLength ) == 0;
1407  }
1408 
1409  // This overload is left undefined, to detect calls of matchAsciiL that
1410  // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
1411  // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
1412  // platforms):
1413 #if SAL_TYPES_SIZEOFLONG == 8
1414  void matchAsciiL(char const *, sal_Int32, rtl_TextEncoding) const;
1415 #endif
1416 
1440  bool matchIgnoreAsciiCaseAsciiL( const char* asciiStr, sal_Int32 asciiStrLength, sal_Int32 fromIndex = 0 ) const
1441  {
1442  assert(fromIndex >= 0);
1443  return rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
1444  asciiStr, asciiStrLength ) == 0;
1445  }
1446 
1447  // This overload is left undefined, to detect calls of
1448  // matchIgnoreAsciiCaseAsciiL that erroneously use
1449  // RTL_CONSTASCII_USTRINGPARAM instead of RTL_CONSTASCII_STRINGPARAM (but
1450  // would lead to ambiguities on 32 bit platforms):
1451 #if SAL_TYPES_SIZEOFLONG == 8
1452  void matchIgnoreAsciiCaseAsciiL(char const *, sal_Int32, rtl_TextEncoding)
1453  const;
1454 #endif
1455 
1456 #if defined LIBO_INTERNAL_ONLY
1457 
1467  bool startsWith(std::u16string_view sv) const {
1468  return match(sv);
1469  }
1484  bool startsWith(std::u16string_view sv, OUString * rest) const {
1485  assert(rest);
1486  auto const b = startsWith(sv);
1487  if (b) {
1488  *rest = copy(sv.size());
1489  }
1490  return b;
1491  }
1505  bool startsWith(std::u16string_view sv, std::u16string_view * rest) const {
1506  assert(rest);
1507  auto const b = startsWith(sv);
1508  if (b) {
1509  *rest = subView(sv.size());
1510  }
1511  return b;
1512  }
1513 #else
1514 
1528  bool startsWith(OUString const & str, OUString * rest = NULL) const {
1529  bool b = match(str);
1530  if (b && rest != NULL) {
1531  *rest = copy(str.getLength());
1532  }
1533  return b;
1534  }
1535 #endif
1536 
1537 #if defined LIBO_INTERNAL_ONLY
1538 
1542  template< typename T >
1544  T & literal) const
1545  {
1546  assert(
1548  bool b
1550  <= sal_uInt32(pData->length))
1552  pData->buffer,
1554  literal),
1556  return b;
1557  }
1563  template< typename T >
1564  typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type startsWith(
1565  T & literal, OUString * rest) const
1566  {
1567  assert(rest);
1568  bool b = startsWith(literal);
1569  if (b) {
1570  *rest = copy(
1571  libreoffice_internal::ConstCharArrayDetector<T>::length);
1572  }
1573  return b;
1574  }
1579  template< typename T >
1580  typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type startsWith(
1581  T & literal, std::u16string_view * rest) const
1582  {
1583  assert(rest);
1584  bool b = startsWith(literal);
1585  if (b) {
1586  *rest = subView(
1587  libreoffice_internal::ConstCharArrayDetector<T>::length);
1588  }
1589  return b;
1590  }
1591 #else
1592 
1597  template< typename T >
1599  T & literal, OUString * rest = NULL) const
1600  {
1601  assert(
1603  bool b
1605  <= sal_uInt32(pData->length))
1607  pData->buffer,
1609  literal),
1611  if (b && rest != NULL) {
1612  *rest = copy(
1614  }
1615  return b;
1616  }
1617 #endif
1618 
1639 #if defined LIBO_INTERNAL_ONLY
1640  bool startsWithIgnoreAsciiCase(std::u16string_view sv) const {
1641  return matchIgnoreAsciiCase(sv);
1642  }
1643  bool startsWithIgnoreAsciiCase(std::u16string_view sv, OUString * rest) const {
1644  assert(rest);
1645  auto const b = startsWithIgnoreAsciiCase(sv);
1646  if (b) {
1647  *rest = copy(sv.size());
1648  }
1649  return b;
1650  }
1651  bool startsWithIgnoreAsciiCase(std::u16string_view sv, std::u16string_view * rest) const {
1652  assert(rest);
1653  auto const b = startsWithIgnoreAsciiCase(sv);
1654  if (b) {
1655  *rest = subView(sv.size());
1656  }
1657  return b;
1658  }
1659 #else
1660  bool startsWithIgnoreAsciiCase(OUString const & str, OUString * rest = NULL)
1661  const
1662  {
1663  bool b = matchIgnoreAsciiCase(str);
1664  if (b && rest != NULL) {
1665  *rest = copy(str.getLength());
1666  }
1667  return b;
1668  }
1669 #endif
1670 
1671 #if defined LIBO_INTERNAL_ONLY
1672 
1677  template< typename T >
1679  startsWithIgnoreAsciiCase(T & literal) const
1680  {
1681  assert(
1683  bool b
1685  <= sal_uInt32(pData->length))
1687  pData->buffer,
1690  literal),
1692  == 0);
1693  return b;
1694  }
1700  template< typename T >
1701  typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
1702  startsWithIgnoreAsciiCase(T & literal, OUString * rest) const
1703  {
1704  assert(rest);
1705  bool b = startsWithIgnoreAsciiCase(literal);
1706  if (b) {
1707  *rest = copy(
1708  libreoffice_internal::ConstCharArrayDetector<T>::length);
1709  }
1710  return b;
1711  }
1716  template< typename T >
1717  typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
1718  startsWithIgnoreAsciiCase(T & literal, std::u16string_view * rest) const
1719  {
1720  assert(rest);
1721  bool b = startsWithIgnoreAsciiCase(literal);
1722  if (b) {
1723  *rest = subView(
1724  libreoffice_internal::ConstCharArrayDetector<T>::length);
1725  }
1726  return b;
1727  }
1728 #else
1729 
1734  template< typename T >
1735  typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
1736  startsWithIgnoreAsciiCase(T & literal, OUString * rest = NULL) const
1737  {
1738  assert(
1740  bool b
1742  <= sal_uInt32(pData->length))
1744  pData->buffer,
1747  literal),
1749  == 0);
1750  if (b && rest != NULL) {
1751  *rest = copy(
1753  }
1754  return b;
1755  }
1756 #endif
1757 
1758 #if defined LIBO_INTERNAL_ONLY
1759 
1769  bool endsWith(std::u16string_view sv) const {
1770  return sv.size() <= sal_uInt32(pData->length)
1771  && match(sv, pData->length - sv.size());
1772  }
1773  bool endsWith(std::u16string_view sv, OUString * rest) const {
1774  auto const b = endsWith(sv);
1775  if (b && rest != nullptr) {
1776  *rest = copy(0, (pData->length - sv.size()));
1777  }
1778  return b;
1779  }
1793  bool endsWith(std::u16string_view sv, std::u16string_view * rest) const {
1794  assert(rest);
1795  auto const b = endsWith(sv);
1796  if (b) {
1797  *rest = subView(0, (pData->length - sv.size()));
1798  }
1799  return b;
1800  }
1801 #else
1802 
1816  bool endsWith(OUString const & str, OUString * rest = NULL) const {
1817  bool b = str.getLength() <= getLength()
1818  && match(str, getLength() - str.getLength());
1819  if (b && rest != NULL) {
1820  *rest = copy(0, getLength() - str.getLength());
1821  }
1822  return b;
1823  }
1824 #endif
1825 
1826 #if defined LIBO_INTERNAL_ONLY
1827 
1832  template< typename T >
1834  endsWith(T & literal) const
1835  {
1836  assert(
1838  bool b
1840  <= sal_uInt32(pData->length))
1842  (pData->buffer + pData->length
1845  literal),
1847  return b;
1848  }
1849  template< typename T >
1850  typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
1851  endsWith(T & literal, OUString * rest) const
1852  {
1853  assert(rest);
1854  bool b = endsWith(literal);
1855  if (b) {
1856  *rest = copy(
1857  0,
1858  (getLength()
1859  - libreoffice_internal::ConstCharArrayDetector<T>::length));
1860  }
1861  return b;
1862  }
1863  template< typename T >
1864  typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
1865  endsWith(T & literal, std::u16string_view * rest) const
1866  {
1867  assert(rest);
1868  bool b = endsWith(literal);
1869  if (b) {
1870  *rest = subView(
1871  0,
1872  (getLength()
1873  - libreoffice_internal::ConstCharArrayDetector<T>::length));
1874  }
1875  return b;
1876  }
1877 #else
1878 
1883  template< typename T >
1884  typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
1885  endsWith(T & literal, OUString * rest = NULL) const
1886  {
1887  assert(
1889  bool b
1891  <= sal_uInt32(pData->length))
1893  (pData->buffer + pData->length
1896  literal),
1898  if (b && rest != NULL) {
1899  *rest = copy(
1900  0,
1901  (getLength()
1903  }
1904  return b;
1905  }
1906 #endif
1907 
1919  bool endsWithAsciiL(char const * asciiStr, sal_Int32 asciiStrLength)
1920  const
1921  {
1922  return asciiStrLength <= pData->length
1924  pData->buffer + pData->length - asciiStrLength, asciiStr,
1925  asciiStrLength);
1926  }
1927 
1928 #if defined LIBO_INTERNAL_ONLY
1929 
1949  bool endsWithIgnoreAsciiCase(std::u16string_view sv) const {
1950  return sv.size() <= sal_uInt32(pData->length)
1951  && matchIgnoreAsciiCase(sv, pData->length - sv.size());
1952  }
1953  bool endsWithIgnoreAsciiCase(std::u16string_view sv, OUString * rest) const {
1954  auto const b = endsWithIgnoreAsciiCase(sv);
1955  if (b && rest != nullptr) {
1956  *rest = copy(0, pData->length - sv.size());
1957  }
1958  return b;
1959  }
1979  bool endsWithIgnoreAsciiCase(std::u16string_view sv, std::u16string_view * rest) const {
1980  assert(rest);
1981  auto const b = endsWithIgnoreAsciiCase(sv);
1982  if (b) {
1983  *rest = subView(0, pData->length - sv.size());
1984  }
1985  return b;
1986  }
1987 #else
1988 
2008  bool endsWithIgnoreAsciiCase(OUString const & str, OUString * rest = NULL) const
2009  {
2010  bool b = str.getLength() <= getLength()
2011  && matchIgnoreAsciiCase(str, getLength() - str.getLength());
2012  if (b && rest != NULL) {
2013  *rest = copy(0, getLength() - str.getLength());
2014  }
2015  return b;
2016  }
2017 #endif
2018 
2019 #if defined LIBO_INTERNAL_ONLY
2020 
2024  template< typename T >
2026  endsWithIgnoreAsciiCase(T & literal) const
2027  {
2028  assert(
2030  bool b
2032  <= sal_uInt32(pData->length))
2034  (pData->buffer + pData->length
2038  literal),
2040  == 0);
2041  return b;
2042  }
2047  template< typename T >
2048  typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
2049  endsWithIgnoreAsciiCase(T & literal, std::u16string_view * rest) const
2050  {
2051  assert(rest);
2052  bool b = endsWithIgnoreAsciiCase(literal);
2053  if (b) {
2054  *rest = subView(
2055  0,
2056  (getLength()
2057  - libreoffice_internal::ConstCharArrayDetector<T>::length));
2058  }
2059  return b;
2060  }
2061 #else
2062 
2067  template< typename T >
2068  typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
2069  endsWithIgnoreAsciiCase(T & literal, OUString * rest = NULL) const
2070  {
2071  assert(
2073  bool b
2075  <= sal_uInt32(pData->length))
2077  (pData->buffer + pData->length
2081  literal),
2083  == 0);
2084  if (b && rest != NULL) {
2085  *rest = copy(
2086  0,
2087  (getLength()
2089  }
2090  return b;
2091  }
2092 #endif
2093 
2105  char const * asciiStr, sal_Int32 asciiStrLength) const
2106  {
2107  return asciiStrLength <= pData->length
2109  pData->buffer + pData->length - asciiStrLength,
2110  asciiStrLength, asciiStr, asciiStrLength)
2111  == 0);
2112  }
2113 
2114  friend bool operator == ( const OUString& rStr1, const OUString& rStr2 )
2115  { return rStr1.equals(rStr2); }
2116 
2117  friend bool operator != ( const OUString& rStr1, const OUString& rStr2 )
2118  { return !(operator == ( rStr1, rStr2 )); }
2119 
2120  friend bool operator < ( const OUString& rStr1, const OUString& rStr2 )
2121  { return rStr1.compareTo( rStr2 ) < 0; }
2122  friend bool operator > ( const OUString& rStr1, const OUString& rStr2 )
2123  { return rStr1.compareTo( rStr2 ) > 0; }
2124  friend bool operator <= ( const OUString& rStr1, const OUString& rStr2 )
2125  { return rStr1.compareTo( rStr2 ) <= 0; }
2126  friend bool operator >= ( const OUString& rStr1, const OUString& rStr2 )
2127  { return rStr1.compareTo( rStr2 ) >= 0; }
2128 
2129 #if defined LIBO_INTERNAL_ONLY
2130 
2131  template<typename T> friend typename libreoffice_internal::CharPtrDetector<T, bool>::TypeUtf16
2132  operator ==(OUString const & s1, T const & s2) {
2134  == 0;
2135  }
2136 
2137  template<typename T>
2138  friend typename libreoffice_internal::NonConstCharArrayDetector<T, bool>::TypeUtf16
2139  operator ==(OUString const & s1, T & s2) {
2140  return rtl_ustr_compare_WithLength(s1.getStr(), s1.getLength(), s2, rtl_ustr_getLength(s2))
2141  == 0;
2142  }
2143 
2144  template<typename T> friend typename libreoffice_internal::CharPtrDetector<T, bool>::TypeUtf16
2145  operator ==(T const & s1, OUString const & s2) {
2146  return rtl_ustr_compare_WithLength(s1, rtl_ustr_getLength(s1), s2.getStr(), s2.getLength())
2147  == 0;
2148  }
2149 
2150  template<typename T>
2151  friend typename libreoffice_internal::NonConstCharArrayDetector<T, bool>::TypeUtf16
2152  operator ==(T & s1, OUString const & s2) {
2153  return rtl_ustr_compare_WithLength(s1, rtl_ustr_getLength(s1), s2.getStr(), s2.getLength())
2154  == 0;
2155  }
2156 
2157  template<typename T> friend typename libreoffice_internal::CharPtrDetector<T, bool>::TypeUtf16
2158  operator !=(OUString const & s1, T const & s2) { return !(s1 == s2); }
2159 
2160  template<typename T>
2161  friend typename libreoffice_internal::NonConstCharArrayDetector<T, bool>::TypeUtf16
2162  operator !=(OUString const & s1, T & s2) { return !(s1 == s2); }
2163 
2164  template<typename T> friend typename libreoffice_internal::CharPtrDetector<T, bool>::TypeUtf16
2165  operator !=(T const & s1, OUString const & s2) { return !(s1 == s2); }
2166 
2167  template<typename T>
2168  friend typename libreoffice_internal::NonConstCharArrayDetector<T, bool>::TypeUtf16
2169  operator !=(T & s1, OUString const & s2) { return !(s1 == s2); }
2170 
2171 #else
2172 
2173  friend bool operator == ( const OUString& rStr1, const sal_Unicode * pStr2 )
2174  { return rStr1.compareTo( pStr2 ) == 0; }
2175  friend bool operator == ( const sal_Unicode * pStr1, const OUString& rStr2 )
2176  { return OUString( pStr1 ).compareTo( rStr2 ) == 0; }
2177 
2178  friend bool operator != ( const OUString& rStr1, const sal_Unicode * pStr2 )
2179  { return !(operator == ( rStr1, pStr2 )); }
2180  friend bool operator != ( const sal_Unicode * pStr1, const OUString& rStr2 )
2181  { return !(operator == ( pStr1, rStr2 )); }
2182 
2183 #endif
2184 
2192  template< typename T >
2194  {
2195  assert(
2197  return rString.equalsAsciiL(
2200  }
2208  template< typename T >
2210  {
2211  assert(
2213  return rString.equalsAsciiL(
2216  }
2224  template< typename T >
2226  {
2227  assert(
2229  return !rString.equalsAsciiL(
2232  }
2240  template< typename T >
2242  {
2243  assert(
2245  return !rString.equalsAsciiL(
2248  }
2249 
2250 #if defined LIBO_INTERNAL_ONLY
2251 
2252  template<typename T> friend typename libreoffice_internal::ConstCharArrayDetector<T, bool>::TypeUtf16
2253  operator ==(OUString const & string, T & literal) {
2254  return
2256  string.pData->buffer, string.pData->length,
2258  literal),
2260  == 0;
2261  }
2263  template<typename T> friend typename libreoffice_internal::ConstCharArrayDetector<T, bool>::TypeUtf16
2264  operator ==(T & literal, OUString const & string) {
2265  return
2267  libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
2268  literal),
2269  libreoffice_internal::ConstCharArrayDetector<T>::length,
2270  string.pData->buffer, string.pData->length)
2271  == 0;
2272  }
2274  template<typename T> friend typename libreoffice_internal::ConstCharArrayDetector<T, bool>::TypeUtf16
2275  operator !=(OUString const & string, T & literal) {
2276  return
2278  string.pData->buffer, string.pData->length,
2279  libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
2280  literal),
2281  libreoffice_internal::ConstCharArrayDetector<T>::length)
2282  != 0;
2283  }
2285  template<typename T> friend typename libreoffice_internal::ConstCharArrayDetector<T, bool>::TypeUtf16
2286  operator !=(T & literal, OUString const & string) {
2287  return
2289  libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
2290  literal),
2291  libreoffice_internal::ConstCharArrayDetector<T>::length,
2292  string.pData->buffer, string.pData->length)
2293  != 0;
2294  }
2295 #endif
2296 
2304  sal_Int32 hashCode() const
2305  {
2306  return rtl_ustr_hashCode_WithLength( pData->buffer, pData->length );
2307  }
2308 
2322  sal_Int32 indexOf( sal_Unicode ch, sal_Int32 fromIndex = 0 ) const
2323  {
2324  assert(fromIndex >= 0);
2325  sal_Int32 ret = rtl_ustr_indexOfChar_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, ch );
2326  return (ret < 0 ? ret : ret+fromIndex);
2327  }
2328 
2338  sal_Int32 lastIndexOf( sal_Unicode ch ) const
2339  {
2340  return rtl_ustr_lastIndexOfChar_WithLength( pData->buffer, pData->length, ch );
2341  }
2342 
2355  sal_Int32 lastIndexOf( sal_Unicode ch, sal_Int32 fromIndex ) const
2356  {
2357  return rtl_ustr_lastIndexOfChar_WithLength( pData->buffer, fromIndex, ch );
2358  }
2359 
2375 #if defined LIBO_INTERNAL_ONLY
2376  sal_Int32 indexOf(std::u16string_view sv, sal_Int32 fromIndex = 0) const {
2377  assert(fromIndex >= 0);
2378  auto const n = rtl_ustr_indexOfStr_WithLength(
2379  pData->buffer + fromIndex, pData->length - fromIndex, sv.data(), sv.size());
2380  return n < 0 ? n : n + fromIndex;
2381  }
2382 #else
2383  sal_Int32 indexOf( const OUString & str, sal_Int32 fromIndex = 0 ) const
2384  {
2385  assert(fromIndex >= 0);
2386  sal_Int32 ret = rtl_ustr_indexOfStr_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
2387  str.pData->buffer, str.pData->length );
2388  return (ret < 0 ? ret : ret+fromIndex);
2389  }
2390 #endif
2391 
2397  template< typename T >
2398  typename libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type indexOf( T& literal, sal_Int32 fromIndex = 0 ) const
2399  {
2400  assert(
2402  assert(fromIndex >= 0);
2403  sal_Int32 n = rtl_ustr_indexOfAscii_WithLength(
2404  pData->buffer + fromIndex, pData->length - fromIndex,
2407  return n < 0 ? n : n + fromIndex;
2408  }
2409 
2433  sal_Int32 indexOfAsciiL(
2434  char const * str, sal_Int32 len, sal_Int32 fromIndex = 0) const
2435  {
2436  assert(fromIndex >= 0);
2437  sal_Int32 ret = rtl_ustr_indexOfAscii_WithLength(
2438  pData->buffer + fromIndex, pData->length - fromIndex, str, len);
2439  return ret < 0 ? ret : ret + fromIndex;
2440  }
2441 
2442  // This overload is left undefined, to detect calls of indexOfAsciiL that
2443  // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
2444  // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
2445  // platforms):
2446 #if SAL_TYPES_SIZEOFLONG == 8
2447  void indexOfAsciiL(char const *, sal_Int32 len, rtl_TextEncoding) const;
2448 #endif
2449 
2465 #if defined LIBO_INTERNAL_ONLY
2466  sal_Int32 lastIndexOf(std::u16string_view sv) const {
2468  pData->buffer, pData->length, sv.data(), sv.size());
2469  }
2470 #else
2471  sal_Int32 lastIndexOf( const OUString & str ) const
2472  {
2473  return rtl_ustr_lastIndexOfStr_WithLength( pData->buffer, pData->length,
2474  str.pData->buffer, str.pData->length );
2475  }
2476 #endif
2477 
2495 #if defined LIBO_INTERNAL_ONLY
2496  sal_Int32 lastIndexOf(std::u16string_view sv, sal_Int32 fromIndex) const {
2497  return rtl_ustr_lastIndexOfStr_WithLength(pData->buffer, fromIndex, sv.data(), sv.size());
2498  }
2499 #else
2500  sal_Int32 lastIndexOf( const OUString & str, sal_Int32 fromIndex ) const
2501  {
2502  return rtl_ustr_lastIndexOfStr_WithLength( pData->buffer, fromIndex,
2503  str.pData->buffer, str.pData->length );
2504  }
2505 #endif
2506 
2512  template< typename T >
2514  {
2515  assert(
2518  pData->buffer, pData->length,
2521  }
2522 
2542  sal_Int32 lastIndexOfAsciiL(char const * str, sal_Int32 len) const
2543  {
2545  pData->buffer, pData->length, str, len);
2546  }
2547 
2558  SAL_WARN_UNUSED_RESULT OUString copy( sal_Int32 beginIndex ) const
2559  {
2560  return copy(beginIndex, getLength() - beginIndex);
2561  }
2562 
2575  SAL_WARN_UNUSED_RESULT OUString copy( sal_Int32 beginIndex, sal_Int32 count ) const
2576  {
2577  rtl_uString *pNew = NULL;
2578  rtl_uString_newFromSubString( &pNew, pData, beginIndex, count );
2579  return OUString( pNew, SAL_NO_ACQUIRE );
2580  }
2581 
2582 #if defined LIBO_INTERNAL_ONLY
2583 
2593  SAL_WARN_UNUSED_RESULT std::u16string_view subView( sal_Int32 beginIndex ) const
2594  {
2595  assert(beginIndex >= 0);
2596  assert(beginIndex <= getLength());
2597  return subView(beginIndex, getLength() - beginIndex);
2598  }
2599 
2612  SAL_WARN_UNUSED_RESULT std::u16string_view subView( sal_Int32 beginIndex, sal_Int32 count ) const
2613  {
2614  assert(beginIndex >= 0);
2615  assert(count >= 0);
2616  assert(beginIndex <= getLength());
2617  assert(count <= getLength() - beginIndex);
2618  return std::u16string_view(*this).substr(beginIndex, count);
2619  }
2620 #endif
2621 
2622 #ifndef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
2623 
2632  {
2633  rtl_uString* pNew = NULL;
2634  rtl_uString_newConcat( &pNew, pData, str.pData );
2635  return OUString( pNew, SAL_NO_ACQUIRE );
2636  }
2637 #endif
2638 
2639 #ifndef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
2640  friend OUString operator+( const OUString& rStr1, const OUString& rStr2 )
2641  {
2642  return rStr1.concat( rStr2 );
2643  }
2644 #endif
2645 
2659  SAL_WARN_UNUSED_RESULT OUString replaceAt( sal_Int32 index, sal_Int32 count, const OUString& newStr ) const
2660  {
2661  rtl_uString* pNew = NULL;
2662  rtl_uString_newReplaceStrAt( &pNew, pData, index, count, newStr.pData );
2663  return OUString( pNew, SAL_NO_ACQUIRE );
2664  }
2665 
2666 #ifdef LIBO_INTERNAL_ONLY
2667  SAL_WARN_UNUSED_RESULT OUString replaceAt( sal_Int32 index, sal_Int32 count, std::u16string_view newStr ) const
2668  {
2669  rtl_uString* pNew = NULL;
2670  rtl_uString_newReplaceStrAtUtf16L( &pNew, pData, index, count, newStr.data(), newStr.size() );
2671  return OUString( pNew, SAL_NO_ACQUIRE );
2672  }
2673  // Disambiguation
2674  template <std::size_t N>
2675  SAL_WARN_UNUSED_RESULT OUString replaceAt( sal_Int32 index, sal_Int32 count, const sal_Unicode (&newStr)[N] ) const
2676  {
2677  return replaceAt(index, count, std::u16string_view(newStr, N - 1));
2678  }
2679  template <class T, std::enable_if_t<std::is_convertible_v<T, std::u16string_view>, int> = 0>
2680  SAL_WARN_UNUSED_RESULT OUString replaceAt( sal_Int32 index, sal_Int32 count, const T& newStr ) const
2681  {
2682  return replaceAt(index, count, std::u16string_view(newStr));
2683  }
2684 #endif
2685 
2700  {
2701  rtl_uString* pNew = NULL;
2702  rtl_uString_newReplace( &pNew, pData, oldChar, newChar );
2703  return OUString( pNew, SAL_NO_ACQUIRE );
2704  }
2705 
2724 #if defined LIBO_INTERNAL_ONLY
2725  [[nodiscard]] OUString replaceFirst(
2726  std::u16string_view from, std::u16string_view to, sal_Int32 * index = nullptr) const
2727  {
2728  rtl_uString * s = nullptr;
2729  sal_Int32 i = 0;
2731  &s, pData, from.data(), from.size(), to.data(), to.size(),
2732  index == nullptr ? &i : index);
2733  return OUString(s, SAL_NO_ACQUIRE);
2734  }
2735 #else
2737  OUString const & from, OUString const & to, sal_Int32 * index = NULL) const
2738  {
2739  rtl_uString * s = NULL;
2740  sal_Int32 i = 0;
2742  &s, pData, from.pData, to.pData, index == NULL ? &i : index);
2743  return OUString(s, SAL_NO_ACQUIRE);
2744  }
2745 #endif
2746 
2765 #if defined LIBO_INTERNAL_ONLY
2766  template<typename T> [[nodiscard]]
2768  T & from, std::u16string_view to, sal_Int32 * index = nullptr) const
2769  {
2771  rtl_uString * s = nullptr;
2772  sal_Int32 i = 0;
2776  index == nullptr ? &i : index);
2777  return OUString(s, SAL_NO_ACQUIRE);
2778  }
2779 #else
2780  template< typename T >
2782  sal_Int32 * index = NULL) const
2783  {
2785  rtl_uString * s = NULL;
2786  sal_Int32 i = 0;
2788  &s, pData,
2791  index == NULL ? &i : index);
2792  return OUString(s, SAL_NO_ACQUIRE);
2793  }
2794 #endif
2795 
2814 #if defined LIBO_INTERNAL_ONLY
2815  template<typename T> [[nodiscard]]
2817  std::u16string_view from, T & to, sal_Int32 * index = nullptr) const
2818  {
2820  rtl_uString * s = nullptr;
2821  sal_Int32 i = 0;
2823  &s, pData, from.data(), from.size(),
2825  libreoffice_internal::ConstCharArrayDetector<T>::length, index == nullptr ? &i : index);
2826  return OUString(s, SAL_NO_ACQUIRE);
2827  }
2828 #else
2829  template< typename T >
2831  sal_Int32 * index = NULL) const
2832  {
2834  rtl_uString * s = NULL;
2835  sal_Int32 i = 0;
2837  &s, pData, from.pData,
2840  index == NULL ? &i : index);
2841  return OUString(s, SAL_NO_ACQUIRE);
2842  }
2843 #endif
2844 
2863  template< typename T1, typename T2 >
2865  replaceFirst( T1& from, T2& to, sal_Int32 * index = NULL) const
2866  {
2869  rtl_uString * s = NULL;
2870  sal_Int32 i = 0;
2872  &s, pData,
2877  index == NULL ? &i : index);
2878  return OUString(s, SAL_NO_ACQUIRE);
2879  }
2880 
2896 #if defined LIBO_INTERNAL_ONLY
2897  [[nodiscard]] OUString replaceAll(
2898  std::u16string_view from, std::u16string_view to, sal_Int32 fromIndex = 0) const
2899  {
2900  rtl_uString * s = nullptr;
2901  rtl_uString_newReplaceAllFromIndexUtf16LUtf16L(
2902  &s, pData, from.data(), from.size(), to.data(), to.size(), fromIndex);
2903  return OUString(s, SAL_NO_ACQUIRE);
2904  }
2905 #else
2907  OUString const & from, OUString const & to, sal_Int32 fromIndex = 0) const
2908  {
2909  rtl_uString * s = NULL;
2910  rtl_uString_newReplaceAllFromIndex(&s, pData, from.pData, to.pData, fromIndex);
2911  return OUString(s, SAL_NO_ACQUIRE);
2912  }
2913 #endif
2914 
2928 #if defined LIBO_INTERNAL_ONLY
2929  template<typename T> [[nodiscard]]
2931  T & from, std::u16string_view to) const
2932  {
2934  rtl_uString * s = nullptr;
2938  return OUString(s, SAL_NO_ACQUIRE);
2939  }
2940 #else
2941  template< typename T >
2943  {
2945  rtl_uString * s = NULL;
2947  &s, pData,
2950  return OUString(s, SAL_NO_ACQUIRE);
2951  }
2952 #endif
2953 
2967 #if defined LIBO_INTERNAL_ONLY
2968  template<typename T> [[nodiscard]]
2970  std::u16string_view from, T & to) const
2971  {
2973  rtl_uString * s = nullptr;
2975  &s, pData, from.data(), from.size(),
2978  return OUString(s, SAL_NO_ACQUIRE);
2979  }
2980 #else
2981  template< typename T >
2983  {
2985  rtl_uString * s = NULL;
2987  &s, pData, from.pData,
2990  return OUString(s, SAL_NO_ACQUIRE);
2991  }
2992 #endif
2993 
3007  template< typename T1, typename T2 >
3009  replaceAll( T1& from, T2& to ) const
3010  {
3013  rtl_uString * s = NULL;
3015  &s, pData,
3020  return OUString(s, SAL_NO_ACQUIRE);
3021  }
3022 
3034  {
3035  rtl_uString* pNew = NULL;
3036  rtl_uString_newToAsciiLowerCase( &pNew, pData );
3037  return OUString( pNew, SAL_NO_ACQUIRE );
3038  }
3039 
3051  {
3052  rtl_uString* pNew = NULL;
3053  rtl_uString_newToAsciiUpperCase( &pNew, pData );
3054  return OUString( pNew, SAL_NO_ACQUIRE );
3055  }
3056 
3071  {
3072  rtl_uString* pNew = NULL;
3073  rtl_uString_newTrim( &pNew, pData );
3074  return OUString( pNew, SAL_NO_ACQUIRE );
3075  }
3076 
3101  OUString getToken( sal_Int32 token, sal_Unicode cTok, sal_Int32& index ) const
3102  {
3103  rtl_uString * pNew = NULL;
3104  index = rtl_uString_getToken( &pNew, pData, token, cTok, index );
3105  return OUString( pNew, SAL_NO_ACQUIRE );
3106  }
3107 
3121  OUString getToken(sal_Int32 count, sal_Unicode separator) const {
3122  sal_Int32 n = 0;
3123  return getToken(count, separator, n);
3124  }
3125 
3134  bool toBoolean() const
3135  {
3136  return rtl_ustr_toBoolean( pData->buffer );
3137  }
3138 
3146  {
3147  return pData->buffer[0];
3148  }
3149 
3160  sal_Int32 toInt32( sal_Int16 radix = 10 ) const
3161  {
3162  return rtl_ustr_toInt32( pData->buffer, radix );
3163  }
3164 
3177  sal_uInt32 toUInt32( sal_Int16 radix = 10 ) const
3178  {
3179  return rtl_ustr_toUInt32( pData->buffer, radix );
3180  }
3181 
3192  sal_Int64 toInt64( sal_Int16 radix = 10 ) const
3193  {
3194  return rtl_ustr_toInt64( pData->buffer, radix );
3195  }
3196 
3209  sal_uInt64 toUInt64( sal_Int16 radix = 10 ) const
3210  {
3211  return rtl_ustr_toUInt64( pData->buffer, radix );
3212  }
3213 
3222  float toFloat() const
3223  {
3224  return rtl_ustr_toFloat( pData->buffer );
3225  }
3226 
3235  double toDouble() const
3236  {
3237  return rtl_ustr_toDouble( pData->buffer );
3238  }
3239 
3240 
3257  {
3258  rtl_uString * pNew = NULL;
3259  rtl_uString_intern( &pNew, pData );
3260  if (pNew == NULL) {
3261  throw std::bad_alloc();
3262  }
3263  return OUString( pNew, SAL_NO_ACQUIRE );
3264  }
3265 
3291  static OUString intern( const char * value, sal_Int32 length,
3292  rtl_TextEncoding encoding,
3293  sal_uInt32 convertFlags = OSTRING_TO_OUSTRING_CVTFLAGS,
3294  sal_uInt32 *pInfo = NULL )
3295  {
3296  rtl_uString * pNew = NULL;
3297  rtl_uString_internConvert( &pNew, value, length, encoding,
3298  convertFlags, pInfo );
3299  if (pNew == NULL) {
3300  throw std::bad_alloc();
3301  }
3302  return OUString( pNew, SAL_NO_ACQUIRE );
3303  }
3304 
3329  bool convertToString(OString * pTarget, rtl_TextEncoding nEncoding,
3330  sal_uInt32 nFlags) const
3331  {
3332  return rtl_convertUStringToString(&pTarget->pData, pData->buffer,
3333  pData->length, nEncoding, nFlags);
3334  }
3335 
3387  sal_uInt32 iterateCodePoints(
3388  sal_Int32 * indexUtf16, sal_Int32 incrementCodePoints = 1) const
3389  {
3391  pData, indexUtf16, incrementCodePoints);
3392  }
3393 
3403 #if defined LIBO_INTERNAL_ONLY
3404  static OUString fromUtf8(std::string_view rSource)
3405  {
3406  OUString aTarget;
3407  bool bSuccess = rtl_convertStringToUString(&aTarget.pData,
3408  rSource.data(),
3409  rSource.length(),
3412  (void) bSuccess;
3413  assert(bSuccess);
3414  return aTarget;
3415  }
3416 #else
3417  static OUString fromUtf8(const OString& rSource)
3418  {
3419  OUString aTarget;
3420  bool bSuccess = rtl_convertStringToUString(&aTarget.pData,
3421  rSource.getStr(),
3422  rSource.getLength(),
3425  (void) bSuccess;
3426  assert(bSuccess);
3427  return aTarget;
3428  }
3429 #endif
3430 
3441  OString toUtf8() const
3442  {
3443  OString aTarget;
3444  bool bSuccess = rtl_convertUStringToString(&aTarget.pData,
3445  getStr(),
3446  getLength(),
3449  (void) bSuccess;
3450  assert(bSuccess);
3451  return aTarget;
3452  }
3453 
3454 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
3455 
3456  static auto number( int i, sal_Int16 radix = 10 )
3457  {
3458  return OUStringNumber<RTL_USTR_MAX_VALUEOFINT32>(rtl_ustr_valueOfInt32, i, radix);
3459  }
3460  static auto number( long long ll, sal_Int16 radix = 10 )
3461  {
3462  return OUStringNumber<RTL_USTR_MAX_VALUEOFINT64>(rtl_ustr_valueOfInt64, ll, radix);
3463  }
3464  static auto number( unsigned long long ll, sal_Int16 radix = 10 )
3465  {
3466  return OUStringNumber<RTL_USTR_MAX_VALUEOFUINT64>(rtl_ustr_valueOfUInt64, ll, radix);
3467  }
3468  static auto number( unsigned int i, sal_Int16 radix = 10 )
3469  {
3470  return number( static_cast< unsigned long long >( i ), radix );
3471  }
3472  static auto number( long i, sal_Int16 radix = 10)
3473  {
3474  return number( static_cast< long long >( i ), radix );
3475  }
3476  static auto number( unsigned long i, sal_Int16 radix = 10 )
3477  {
3478  return number( static_cast< unsigned long long >( i ), radix );
3479  }
3480 #else
3481 
3491  static OUString number( int i, sal_Int16 radix = 10 )
3492  {
3494  return OUString(aBuf, rtl_ustr_valueOfInt32(aBuf, i, radix));
3495  }
3498  static OUString number( unsigned int i, sal_Int16 radix = 10 )
3499  {
3500  return number( static_cast< unsigned long long >( i ), radix );
3501  }
3504  static OUString number( long i, sal_Int16 radix = 10)
3505  {
3506  return number( static_cast< long long >( i ), radix );
3507  }
3510  static OUString number( unsigned long i, sal_Int16 radix = 10 )
3511  {
3512  return number( static_cast< unsigned long long >( i ), radix );
3513  }
3516  static OUString number( long long ll, sal_Int16 radix = 10 )
3517  {
3519  return OUString(aBuf, rtl_ustr_valueOfInt64(aBuf, ll, radix));
3520  }
3523  static OUString number( unsigned long long ll, sal_Int16 radix = 10 )
3524  {
3526  return OUString(aBuf, rtl_ustr_valueOfUInt64(aBuf, ll, radix));
3527  }
3528 #endif
3529 
3539  static OUString number( float f )
3540  {
3541  rtl_uString* pNew = NULL;
3542  // Same as rtl::str::valueOfFP, used for rtl_ustr_valueOfFloat
3544  RTL_USTR_MAX_VALUEOFFLOAT - SAL_N_ELEMENTS("-x.E-xxx") + 1, '.',
3545  NULL, 0, true);
3546  if (pNew == NULL)
3547  throw std::bad_alloc();
3548 
3549  return OUString(pNew, SAL_NO_ACQUIRE);
3550  }
3551 
3561  static OUString number( double d )
3562  {
3563  rtl_uString* pNew = NULL;
3564  // Same as rtl::str::valueOfFP, used for rtl_ustr_valueOfDouble
3566  RTL_USTR_MAX_VALUEOFDOUBLE - SAL_N_ELEMENTS("-x.E-xxx") + 1, '.',
3567  NULL, 0, true);
3568  if (pNew == NULL)
3569  throw std::bad_alloc();
3570 
3571  return OUString(pNew, SAL_NO_ACQUIRE);
3572  }
3573 
3574 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
3575  static auto boolean(bool b)
3576  {
3577  return OUStringNumber<RTL_USTR_MAX_VALUEOFBOOLEAN>(rtl_ustr_valueOfBoolean, b);
3578  }
3579 #else
3580 
3591  SAL_DEPRECATED("use boolean()") static OUString valueOf( sal_Bool b )
3592  {
3593  return boolean(b);
3594  }
3595 
3607  static OUString boolean( bool b )
3608  {
3610  return OUString(aBuf, rtl_ustr_valueOfBoolean(aBuf, b));
3611  }
3612 #endif
3613 
3621  SAL_DEPRECATED("convert to OUString or use directly") static OUString valueOf( sal_Unicode c )
3622  {
3623  return OUString( &c, 1 );
3624  }
3625 
3636  SAL_DEPRECATED("use number()") static OUString valueOf( sal_Int32 i, sal_Int16 radix = 10 )
3637  {
3638  return number( i, radix );
3639  }
3640 
3651  SAL_DEPRECATED("use number()") static OUString valueOf( sal_Int64 ll, sal_Int16 radix = 10 )
3652  {
3653  return number( ll, radix );
3654  }
3655 
3665  SAL_DEPRECATED("use number()") static OUString valueOf( float f )
3666  {
3667  return number(f);
3668  }
3669 
3679  SAL_DEPRECATED("use number()") static OUString valueOf( double d )
3680  {
3681  return number(d);
3682  }
3683 
3699  static OUString createFromAscii( const char * value )
3700  {
3701  rtl_uString* pNew = NULL;
3702  rtl_uString_newFromAscii( &pNew, value );
3703  return OUString( pNew, SAL_NO_ACQUIRE );
3704  }
3705 
3706 #if defined LIBO_INTERNAL_ONLY
3707  static OUString createFromAscii(std::string_view value) {
3708  rtl_uString * p = nullptr;
3709  rtl_uString_newFromLiteral(&p, value.data(), value.size(), 0); //TODO: check for overflow
3710  return OUString(p, SAL_NO_ACQUIRE);
3711  }
3712  #endif
3713 
3714 #if defined LIBO_INTERNAL_ONLY
3715  operator std::u16string_view() const { return {getStr(), sal_uInt32(getLength())}; }
3716 #endif
3717 
3718 #if defined LIBO_INTERNAL_ONLY
3719  // A wrapper for the first expression in an
3720  //
3721  // OUString::Concat(e1) + e2 + ...
3722  //
3723  // concatenation chain, when neither of the first two e1, e2 is one of our rtl string-related
3724  // classes (so something like
3725  //
3726  // OUString s = "a" + (b ? std::u16string_view(u"c") : std::u16string_view(u"dd"));
3727  //
3728  // would not compile):
3729  template<typename T> [[nodiscard]] static
3730  OUStringConcat<OUStringConcatMarker, T>
3731  Concat(T const & value) { return OUStringConcat<OUStringConcatMarker, T>(value); }
3732 
3733  // This overload is needed so that an argument of type 'char const[N]' ends up as
3734  // 'OUStringConcat<rtl::OUStringConcatMarker, char const[N]>' rather than as
3735  // 'OUStringConcat<rtl::OUStringConcatMarker, char[N]>':
3736  template<typename T, std::size_t N> [[nodiscard]] static
3737  OUStringConcat<OUStringConcatMarker, T[N]>
3738  Concat(T (& value)[N]) { return OUStringConcat<OUStringConcatMarker, T[N]>(value); }
3739 #endif
3740 
3741 private:
3742  OUString & internalAppend( rtl_uString* pOtherData )
3743  {
3744  rtl_uString* pNewData = NULL;
3745  rtl_uString_newConcat( &pNewData, pData, pOtherData );
3746  if (pNewData == NULL) {
3747  throw std::bad_alloc();
3748  }
3749  rtl_uString_assign(&pData, pNewData);
3750  rtl_uString_release(pNewData);
3751  return *this;
3752  }
3753 
3754 };
3755 
3756 #if defined LIBO_INTERNAL_ONLY
3757 // Prevent the operator ==/!= overloads with 'sal_Unicode const *' parameter from
3758 // being selected for nonsensical code like
3759 //
3760 // if (ouIdAttr == nullptr)
3761 //
3762 void operator ==(OUString const &, std::nullptr_t) = delete;
3763 void operator ==(std::nullptr_t, OUString const &) = delete;
3764 void operator !=(OUString const &, std::nullptr_t) = delete;
3765 void operator !=(std::nullptr_t, OUString const &) = delete;
3766 #endif
3767 
3768 #if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST
3769 inline bool operator ==(OUString const & lhs, StringConcatenation<char16_t> const & rhs)
3770 { return lhs == std::u16string_view(rhs); }
3771 inline bool operator !=(OUString const & lhs, StringConcatenation<char16_t> const & rhs)
3772 { return lhs != std::u16string_view(rhs); }
3773 inline bool operator ==(StringConcatenation<char16_t> const & lhs, OUString const & rhs)
3774 { return std::u16string_view(lhs) == rhs; }
3775 inline bool operator !=(StringConcatenation<char16_t> const & lhs, OUString const & rhs)
3776 { return std::u16string_view(lhs) != rhs; }
3777 #endif
3778 
3779 #if defined LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
3780 
3785 template<>
3786 struct ToStringHelper< OUString >
3787 {
3788  static std::size_t length( const OUString& s ) { return s.getLength(); }
3789  sal_Unicode* operator() ( sal_Unicode* buffer, const OUString& s ) const { return addDataHelper( buffer, s.getStr(), s.getLength()); }
3790 };
3791 
3795 template<std::size_t N>
3796 struct ToStringHelper< OUStringLiteral<N> >
3797 {
3798  static std::size_t length( const OUStringLiteral<N>& str ) { return str.getLength(); }
3799  sal_Unicode* operator()( sal_Unicode* buffer, const OUStringLiteral<N>& str ) const { return addDataHelper( buffer, str.getStr(), str.getLength() ); }
3800 };
3801 
3805 template< typename charT, typename traits, typename T1, typename T2 >
3806 inline std::basic_ostream<charT, traits> & operator <<(
3807  std::basic_ostream<charT, traits> & stream, OUStringConcat< T1, T2 >&& concat)
3808 {
3809  return stream << OUString( std::move(concat) );
3810 }
3811 
3813 #endif
3814 
3821 {
3831  size_t operator()(const OUString& rString) const
3832  { return static_cast<size_t>(rString.hashCode()); }
3833 };
3834 
3835 /* ======================================================================= */
3836 
3854 #if defined LIBO_INTERNAL_ONLY
3855 inline OUString OStringToOUString( std::string_view rStr,
3856  rtl_TextEncoding encoding,
3857  sal_uInt32 convertFlags = OSTRING_TO_OUSTRING_CVTFLAGS )
3858 {
3859  return OUString( rStr.data(), rStr.length(), encoding, convertFlags );
3860 }
3861 #else
3862 inline OUString OStringToOUString( const OString & rStr,
3863  rtl_TextEncoding encoding,
3864  sal_uInt32 convertFlags = OSTRING_TO_OUSTRING_CVTFLAGS )
3865 {
3866  return OUString( rStr.getStr(), rStr.getLength(), encoding, convertFlags );
3867 }
3868 #endif
3869 
3887 #if defined LIBO_INTERNAL_ONLY
3888 inline OString OUStringToOString( std::u16string_view rUnicode,
3889  rtl_TextEncoding encoding,
3890  sal_uInt32 convertFlags = OUSTRING_TO_OSTRING_CVTFLAGS )
3891 {
3892  return OString( rUnicode.data(), rUnicode.length(), encoding, convertFlags );
3893 }
3894 #else
3895 inline OString OUStringToOString( const OUString & rUnicode,
3896  rtl_TextEncoding encoding,
3897  sal_uInt32 convertFlags = OUSTRING_TO_OSTRING_CVTFLAGS )
3898 {
3899  return OString( rUnicode.getStr(), rUnicode.getLength(), encoding, convertFlags );
3900 }
3901 #endif
3902 
3903 /* ======================================================================= */
3904 
3913 template< typename charT, typename traits >
3914 inline std::basic_ostream<charT, traits> & operator <<(
3915  std::basic_ostream<charT, traits> & stream, OUString const & rString)
3916 {
3917  return stream <<
3919  // best effort; potentially loses data due to conversion failures
3920  // (stray surrogate halves) and embedded null characters
3921 }
3922 
3923 } // namespace
3924 
3925 #ifdef RTL_STRING_UNITTEST
3926 namespace rtl
3927 {
3928 typedef rtlunittest::OUString OUString;
3929 }
3930 #endif
3931 
3932 // In internal code, allow to use classes like OUString without having to
3933 // explicitly refer to the rtl namespace, which is kind of superfluous given
3934 // that OUString itself is namespaced by its OU prefix:
3935 #if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST
3936 using ::rtl::OUString;
3937 using ::rtl::OUStringHash;
3940 using ::rtl::OUStringLiteral;
3941 using ::rtl::OUStringChar;
3942 using ::rtl::Concat2View;
3943 #endif
3944 
3945 #if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
3946 
3947 template<
3948 #if defined RTL_STRING_UNITTEST
3949  rtlunittest::
3950 #endif
3951  OUStringLiteral L>
3952 constexpr
3953 #if defined RTL_STRING_UNITTEST
3954  rtlunittest::
3955 #endif
3956  OUString
3957 operator ""_ustr() { return L; }
3958 
3959 #endif
3960 
3962 
3967 #if defined LIBO_INTERNAL_ONLY
3968 namespace std {
3969 
3970 template<>
3971 struct hash<::rtl::OUString>
3972 {
3973  std::size_t operator()(::rtl::OUString const & s) const
3974  {
3975  if constexpr (sizeof(std::size_t) == 8)
3976  {
3977  // return a hash that uses the full 64-bit range instead of a 32-bit value
3978  size_t n = s.getLength();
3979  for (sal_Int32 i = 0, len = s.getLength(); i < len; ++i)
3980  n = 37 * n + s[i];
3981  return n;
3982  }
3983  else
3984  return std::size_t(s.hashCode());
3985  }
3986 };
3987 
3988 }
3989 
3990 #if !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
3991 
3997 static inline constexpr ::rtl::OUString EMPTY_OUSTRING = u""_ustr;
3998 #endif
3999 
4000 #endif
4001 
4003 #endif /* _RTL_USTRING_HXX */
4004 
4005 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_WARN_UNUSED_RESULT OUString replaceAll(OUString const &from, OUString const &to, sal_Int32 fromIndex=0) const
Returns a new string resulting from replacing all occurrences of a given substring with another subst...
Definition: ustring.hxx:2906
#define OUSTRING_TO_OSTRING_CVTFLAGS
Definition: string.h:1350
SAL_DLLPUBLIC sal_Int32 rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength(const sal_Unicode *first, sal_Int32 firstLen, const char *second, sal_Int32 shortenedLen) SAL_THROW_EXTERN_C()
Compare two strings with a maximum count of characters, ignoring the case of ASCII characters...
sal_Int32 getLength() const
Returns the length of this string.
Definition: string.hxx:664
SAL_WARN_UNUSED_RESULT OUString concat(const OUString &str) const
Concatenates the specified string to the end of this string.
Definition: ustring.hxx:2631
OString OUStringToOString(const OUString &rUnicode, rtl_TextEncoding encoding, sal_uInt32 convertFlags=OUSTRING_TO_OSTRING_CVTFLAGS)
Convert an OUString to an OString, using a specific text encoding.
Definition: ustring.hxx:3895
sal_uInt64 toUInt64(sal_Int16 radix=10) const
Returns the uint64 value from this string.
Definition: ustring.hxx:3209
libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type reverseCompareTo(T &literal) const
This is an overloaded member function, provided for convenience. It differs from the above function ...
Definition: ustring.hxx:946
SAL_WARN_UNUSED_RESULT OUString copy(sal_Int32 beginIndex) const
Returns a new string that is a substring of this string.
Definition: ustring.hxx:2558
OUString()
New string containing no characters.
Definition: ustring.hxx:181
sal_Int32 getLength() const
Returns the length of this string.
Definition: ustring.hxx:821
#define RTL_TEXTENCODING_UTF8
Definition: textenc.h:117
SAL_DLLPUBLIC void rtl_uString_newReplaceAllFromIndex(rtl_uString **newStr, rtl_uString *str, rtl_uString const *from, rtl_uString const *to, sal_Int32 fromIndex) SAL_THROW_EXTERN_C()
Create a new string by replacing all occurrences of a given substring with another substring...
SAL_DLLPUBLIC void rtl_uString_intern(rtl_uString **newStr, rtl_uString *str) SAL_THROW_EXTERN_C()
Return a canonical representation for a string.
#define RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR
Definition: textcvt.h:68
SAL_DLLPUBLIC void rtl_uString_newTrim(rtl_uString **newStr, rtl_uString *str) SAL_THROW_EXTERN_C()
Create a new string by removing white space from both ends of another string.
OUString OStringToOUString(const OString &rStr, rtl_TextEncoding encoding, sal_uInt32 convertFlags=OSTRING_TO_OUSTRING_CVTFLAGS)
Convert an OString to an OUString, using a specific text encoding.
Definition: ustring.hxx:3862
static OUString 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: ustring.hxx:3523
SAL_DLLPUBLIC void rtl_uString_newReplaceFirstToAsciiL(rtl_uString **newStr, rtl_uString *str, rtl_uString const *from, 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...
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: ustring.hxx:2398
SAL_DLLPUBLIC void rtl_math_doubleToUString(rtl_uString **pResult, sal_Int32 *pResultCapacity, sal_Int32 nResultOffset, double fValue, enum rtl_math_StringFormat eFormat, sal_Int32 nDecPlaces, sal_Unicode cDecSeparator, sal_Int32 const *pGroups, sal_Unicode cGroupSeparator, sal_Bool bEraseTrailingDecZeros) SAL_THROW_EXTERN_C()
Conversions analogous to sprintf() using internal rounding.
sal_Int32 indexOf(const OUString &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: ustring.hxx:2383
SAL_DLLPUBLIC void rtl_uString_newToAsciiUpperCase(rtl_uString **newStr, rtl_uString *str) SAL_THROW_EXTERN_C()
Create a new string by converting all ASCII lowercase letters to uppercase within another string...
double toDouble() const
Returns the double value from this string.
Definition: ustring.hxx:3235
sal_Unicode toChar() const
Returns the first character from this string.
Definition: ustring.hxx:3145
bool matchIgnoreAsciiCase(const OUString &str, sal_Int32 fromIndex=0) const
Match against a substring appearing in this string, ignoring the case of ASCII letters.
Definition: ustring.hxx:1143
SAL_DLLPUBLIC sal_Int32 rtl_ustr_lastIndexOfChar_WithLength(const sal_Unicode *str, sal_Int32 len, sal_Unicode ch) SAL_THROW_EXTERN_C()
Search for the last occurrence of a character within a string.
bool equalsAscii(const char *asciiStr) const
Perform a comparison of two strings.
Definition: ustring.hxx:1257
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 void rtl_string2UString(rtl_uString **newStr, const char *str, sal_Int32 len, rtl_TextEncoding encoding, sal_uInt32 convertFlags) SAL_THROW_EXTERN_C()
Create a new Unicode string by converting a byte string, using a specific text encoding.
SAL_DLLPUBLIC sal_Int32 rtl_ustr_compare_WithLength(const sal_Unicode *first, sal_Int32 firstLen, const sal_Unicode *second, sal_Int32 secondLen) SAL_THROW_EXTERN_C()
Compare two strings.
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: ustring.hxx:1158
libreoffice_internal::ConstCharArrayDetector< T, bool >::Type startsWith(T &literal, OUString *rest=NULL) const
This is an overloaded member function, provided for convenience. It differs from the above function ...
Definition: ustring.hxx:1598
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: ustring.hxx:1101
#define RTL_USTR_MAX_VALUEOFFLOAT
Definition: ustring.h:1026
bool startsWith(OUString const &str, OUString *rest=NULL) const
Check whether this string starts with a given substring.
Definition: ustring.hxx:1528
static OUString const & unacquired(rtl_uString *const *ppHandle)
Provides an OUString const & passing a storage pointer of an rtl_uString * handle.
Definition: ustring.hxx:560
#define RTL_USTR_MAX_VALUEOFUINT64
Definition: ustring.h:1007
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: ustring.hxx:1048
SAL_DLLPUBLIC void rtl_uString_newReplaceFirstAsciiLAsciiL(rtl_uString **newStr, rtl_uString *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...
friend OUString operator+(const OUString &rStr1, const OUString &rStr2)
Definition: ustring.hxx:2640
sal_Int32 reverseCompareToAsciiL(const char *asciiStr, sal_Int32 asciiStrLength) const
Compares two strings in reverse order.
Definition: ustring.hxx:1236
static OUString fromUtf8(const OString &rSource)
Convert an OString to an OUString, assuming that the OString is UTF-8-encoded.
Definition: ustring.hxx:3417
SAL_DLLPUBLIC void rtl_uString_internConvert(rtl_uString **newStr, const char *str, sal_Int32 len, rtl_TextEncoding encoding, sal_uInt32 convertFlags, sal_uInt32 *pInfo) SAL_THROW_EXTERN_C()
Return a canonical representation for a string.
sal_uInt32 iterateCodePoints(sal_Int32 *indexUtf16, sal_Int32 incrementCodePoints=1) const
Iterate through this string based on code points instead of UTF-16 code units.
Definition: ustring.hxx:3387
SAL_DLLPUBLIC void rtl_uString_newReplaceStrAt(rtl_uString **newStr, rtl_uString *str, sal_Int32 idx, sal_Int32 count, rtl_uString *subStr) SAL_THROW_EXTERN_C()
Create a new string by replacing a substring of another string.
SAL_DLLPUBLIC sal_Int32 rtl_ustr_compareIgnoreAsciiCase_WithLength(const sal_Unicode *first, sal_Int32 firstLen, const sal_Unicode *second, sal_Int32 secondLen) SAL_THROW_EXTERN_C()
Compare two strings, ignoring the case of ASCII characters.
static OUString 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: ustring.hxx:3498
A string buffer implements a mutable sequence of characters.
Definition: ustrbuf.hxx:72
SAL_DLLPUBLIC sal_Int32 rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength(const sal_Unicode *first, sal_Int32 firstLen, const char *second) SAL_THROW_EXTERN_C()
Compare two strings, ignoring the case of ASCII characters.
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
const sal_Unicode * getStr() const SAL_RETURNS_NONNULL
Returns a pointer to the Unicode character buffer for this string.
Definition: ustring.hxx:843
bool operator<(const TTimeValue &rTimeA, const TTimeValue &rTimeB)
Definition: timer.hxx:93
friend libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator==(const OUString &rString, T &literal)
Compare string to an ASCII string literal.
Definition: ustring.hxx:2193
SAL_DLLPUBLIC void rtl_uString_newReplaceAllAsciiL(rtl_uString **newStr, rtl_uString *str, char const *from, sal_Int32 fromLength, rtl_uString const *to) SAL_THROW_EXTERN_C()
Create a new string by replacing all occurrences of a given substring with another substring...
SAL_DLLPUBLIC void rtl_uString_newToAsciiLowerCase(rtl_uString **newStr, rtl_uString *str) SAL_THROW_EXTERN_C()
Create a new string by converting all ASCII uppercase letters to lowercase within another string...
SAL_DLLPUBLIC sal_Bool rtl_ustr_asciil_reverseEquals_WithLength(const sal_Unicode *first, const char *second, sal_Int32 len) SAL_THROW_EXTERN_C()
Compare two strings from back to front for equality.
SAL_DLLPUBLIC sal_Int32 rtl_ustr_valueOfBoolean(sal_Unicode *str, sal_Bool b) SAL_THROW_EXTERN_C()
Create the string representation of a boolean.
libreoffice_internal::ConstCharArrayDetector< T, bool >::Type startsWithIgnoreAsciiCase(T &literal, OUString *rest=NULL) const
This is an overloaded member function, provided for convenience. It differs from the above function ...
Definition: ustring.hxx:1736
libreoffice_internal::ConstCharArrayDetector< T, bool >::Type endsWithIgnoreAsciiCase(T &literal, OUString *rest=NULL) const
This is an overloaded member function, provided for convenience. It differs from the above function ...
Definition: ustring.hxx:2069
bool operator>(const TTimeValue &rTimeA, const TTimeValue &rTimeB)
Definition: timer.hxx:103
bool equalsAsciiL(const char *asciiStr, sal_Int32 asciiStrLength) const
Perform a comparison of two strings.
Definition: ustring.hxx:1279
SAL_DLLPUBLIC sal_Int32 rtl_ustr_shortenedCompare_WithLength(const sal_Unicode *first, sal_Int32 firstLen, const sal_Unicode *second, sal_Int32 secondLen, sal_Int32 shortenedLen) SAL_THROW_EXTERN_C()
Compare two strings with a maximum count of characters.
SAL_DLLPUBLIC sal_Int32 rtl_ustr_lastIndexOfStr_WithLength(const sal_Unicode *str, sal_Int32 len, const sal_Unicode *subStr, sal_Int32 subLen) SAL_THROW_EXTERN_C()
Search for the last occurrence of a substring within a string.
SAL_DLLPUBLIC sal_Bool rtl_convertStringToUString(rtl_uString **target, char const *source, sal_Int32 length, rtl_TextEncoding encoding, sal_uInt32 flags) SAL_THROW_EXTERN_C()
Converts a byte string to a Unicode string, signalling failure.
bool operator==(const TTimeValue &rTimeA, const TTimeValue &rTimeB)
Definition: timer.hxx:113
SAL_DLLPUBLIC sal_uInt64 rtl_ustr_toUInt64(const sal_Unicode *str, sal_Int16 radix) SAL_THROW_EXTERN_C()
Interpret a string as an unsigned long integer.
Definition: stringutils.hxx:178
#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
sal_Int32 compareTo(const OUString &str) const
Compares two strings.
Definition: ustring.hxx:879
#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_ustr_toInt32(const sal_Unicode *str, sal_Int16 radix) SAL_THROW_EXTERN_C()
Interpret a string as an integer.
static OUString intern(const char *value, sal_Int32 length, rtl_TextEncoding encoding, sal_uInt32 convertFlags=OSTRING_TO_OUSTRING_CVTFLAGS, sal_uInt32 *pInfo=NULL)
Return a canonical representation for a converted string.
Definition: ustring.hxx:3291
sal_Int32 lastIndexOf(const OUString &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: ustring.hxx:2500
SAL_DLLPUBLIC void rtl_uString_newConcatUtf16L(rtl_uString **newString, rtl_uString *left, sal_Unicode const *right, sal_Int32 rightLength)
Create a new string that is the concatenation of two other strings.
SAL_WARN_UNUSED_RESULT libreoffice_internal::ConstCharArrayDetector< T1, typename libreoffice_internal::ConstCharArrayDetector< T2, OUString >::Type >::Type replaceAll(T1 &from, T2 &to) const
Returns a new string resulting from replacing all occurrences of a given substring with another subst...
Definition: ustring.hxx:3009
sal_Int32 compareToIgnoreAsciiCase(const OUString &str) const
Perform an ASCII lowercase comparison of two strings.
Definition: ustring.hxx:1035
SAL_DLLPUBLIC void rtl_uString_assign(rtl_uString **str, rtl_uString *rightValue) SAL_THROW_EXTERN_C()
Assign a new value to a string.
SAL_DLLPUBLIC float rtl_ustr_toFloat(const sal_Unicode *str) SAL_THROW_EXTERN_C()
Interpret a string as a float.
SAL_DLLPUBLIC void rtl_uString_acquire(rtl_uString *str) SAL_THROW_EXTERN_C() SAL_HOT
Increment the reference count of a string.
OUString getToken(sal_Int32 token, sal_Unicode cTok, sal_Int32 &index) const
Returns a token in the string.
Definition: ustring.hxx:3101
bool convertToString(OString *pTarget, rtl_TextEncoding nEncoding, sal_uInt32 nFlags) const
Converts to an OString, signalling failure.
Definition: ustring.hxx:3329
#define RTL_USTR_MAX_VALUEOFDOUBLE
Definition: ustring.h:1045
SAL_DLLPUBLIC void rtl_uString_newFromAscii(rtl_uString **newStr, const char *value) SAL_THROW_EXTERN_C()
Allocate a new string that contains a copy of a character array.
SAL_WARN_UNUSED_RESULT OUString toAsciiLowerCase() const
Converts from this string all ASCII uppercase characters (65-90) to ASCII lowercase characters (97-12...
Definition: ustring.hxx:3033
SAL_DLLPUBLIC sal_uInt32 rtl_ustr_toUInt32(const sal_Unicode *str, sal_Int16 radix) SAL_THROW_EXTERN_C()
Interpret a string as an unsigned integer.
sal_Int32 toInt32(sal_Int16 radix=10) const
Returns the int32 value from this string.
Definition: ustring.hxx:3160
#define RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR
Definition: textcvt.h:151
SAL_WARN_UNUSED_RESULT OUString copy(sal_Int32 beginIndex, sal_Int32 count) const
Returns a new string that is a substring of this string.
Definition: ustring.hxx:2575
SAL_DLLPUBLIC void rtl_uString_newFromStr_WithLength(rtl_uString **newStr, const sal_Unicode *value, sal_Int32 len) SAL_THROW_EXTERN_C()
Allocate a new string that contains a copy of a character array.
SAL_WARN_UNUSED_RESULT libreoffice_internal::ConstCharArrayDetector< T, OUString >::Type replaceAll(OUString const &from, T &to) const
Returns a new string resulting from replacing all occurrences of a given substring with another subst...
Definition: ustring.hxx:2982
sal_uInt16 sal_Unicode
Definition: types.h:123
SAL_DLLPUBLIC void rtl_uString_newConcat(rtl_uString **newStr, rtl_uString *left, rtl_uString *right) SAL_THROW_EXTERN_C()
Create a new string that is the concatenation of two other strings.
SAL_DLLPUBLIC void rtl_uString_newFromLiteral(rtl_uString **newStr, const char *value, sal_Int32 len, sal_Int32 allocExtra) SAL_THROW_EXTERN_C()
unsigned char sal_Bool
Definition: types.h:38
static OUString createFromAscii(const char *value)
Returns an OUString copied without conversion from an ASCII character string.
Definition: ustring.hxx:3699
sal_Int32 compareTo(const OUString &str, sal_Int32 maxLength) const
Compares two strings with a maximum count of characters.
Definition: ustring.hxx:908
SAL_WARN_UNUSED_RESULT OUString toAsciiUpperCase() const
Converts from this string all ASCII lowercase characters (97-122) to ASCII uppercase characters (65-9...
Definition: ustring.hxx:3050
__sal_NoAcquire
Definition: types.h:370
SAL_DLLPUBLIC void rtl_uString_release(rtl_uString *str) SAL_THROW_EXTERN_C() SAL_HOT
Decrement the reference count of a string.
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_Int32 indexOfAsciiL(char const *str, sal_Int32 len, sal_Int32 fromIndex=0) const
Returns the index within this string of the first occurrence of the specified ASCII substring...
Definition: ustring.hxx:2433
A helper to use OUStrings with hash maps.
Definition: ustring.hxx:3820
static OUString number(float f)
Returns the string representation of the float argument.
Definition: ustring.hxx:3539
sal_Int32 compareToAscii(const char *asciiStr) const
Compares two strings.
Definition: ustring.hxx:1183
SAL_DLLPUBLIC void rtl_uString_new(rtl_uString **newStr) SAL_THROW_EXTERN_C()
Allocate a new string containing no characters.
#define OSTRING_TO_OUSTRING_CVTFLAGS
Definition: ustring.h:2180
SAL_DLLPUBLIC sal_Bool rtl_ustr_toBoolean(const sal_Unicode *str) SAL_THROW_EXTERN_C()
Interpret a string as a boolean.
#define RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR
Definition: textcvt.h:75
SAL_WARN_UNUSED_RESULT libreoffice_internal::ConstCharArrayDetector< T, OUString >::Type replaceAll(T &from, OUString const &to) const
Returns a new string resulting from replacing all occurrences of a given substring with another subst...
Definition: ustring.hxx:2942
bool equalsIgnoreAsciiCaseAscii(const char *asciiStr) const
Perform an ASCII lowercase comparison of two strings.
Definition: ustring.hxx:1306
sal_Int32 indexOf(sal_Unicode 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: ustring.hxx:2322
SAL_DLLPUBLIC void rtl_uString_ensureCapacity(rtl_uString **str, sal_Int32 size) SAL_THROW_EXTERN_C()
Ensure a string has enough space for a given number of characters.
SAL_DLLPUBLIC rtl_uString * rtl_uString_alloc(sal_Int32 nLen) SAL_THROW_EXTERN_C()
Allocate a new string containing space for a given number of characters.
OUString(rtl_uString *str)
New string from OUString data.
Definition: ustring.hxx:247
SAL_DLLPUBLIC sal_Int32 rtl_ustr_hashCode_WithLength(const sal_Unicode *str, sal_Int32 len) SAL_THROW_EXTERN_C()
Return a hash code for a string.
libreoffice_internal::ConstCharArrayDetector< T, bool >::Type endsWith(T &literal, OUString *rest=NULL) const
This is an overloaded member function, provided for convenience. It differs from the above function ...
Definition: ustring.hxx:1885
SAL_DLLPUBLIC void rtl_uString_newReplaceFirstAsciiL(rtl_uString **newStr, rtl_uString *str, char const *from, sal_Int32 fromLength, rtl_uString const *to, sal_Int32 *index) SAL_THROW_EXTERN_C()
Create a new string by replacing the first occurrence of a given substring with another substring...
sal_uInt16 rtl_TextEncoding
The various supported text encodings.
Definition: textenc.h:37
SAL_DLLPUBLIC sal_Int32 rtl_uString_getToken(rtl_uString **newStr, rtl_uString *str, sal_Int32 token, sal_Unicode cTok, sal_Int32 idx) SAL_THROW_EXTERN_C()
Create a new string by extracting a single token from another string.
bool matchAsciiL(const char *asciiStr, sal_Int32 asciiStrLength, sal_Int32 fromIndex=0) const
Match against a substring appearing in this string.
Definition: ustring.hxx:1402
#define RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR
Definition: textcvt.h:145
SAL_DLLPUBLIC sal_Int64 rtl_ustr_toInt64(const sal_Unicode *str, sal_Int16 radix) SAL_THROW_EXTERN_C()
Interpret a string as a long integer.
Definition: bootstrap.hxx:33
SAL_WARN_UNUSED_RESULT OUString replace(sal_Unicode oldChar, sal_Unicode newChar) const
Returns a new string resulting from replacing all occurrences of oldChar in this string with newChar...
Definition: ustring.hxx:2699
SAL_DLLPUBLIC void rtl_uString_newReplace(rtl_uString **newStr, rtl_uString *str, sal_Unicode oldChar, sal_Unicode newChar) SAL_THROW_EXTERN_C()
Create a new string by replacing all occurrences of a single character within another string...
bool equalsIgnoreAsciiCase(const OUString &str) const
Perform an ASCII lowercase comparison of two strings.
Definition: ustring.hxx:1003
bool match(const OUString &str, sal_Int32 fromIndex=0) const
Match against a substring appearing in this string.
Definition: ustring.hxx:1087
SAL_WARN_UNUSED_RESULT libreoffice_internal::ConstCharArrayDetector< T, OUString >::Type replaceFirst(OUString const &from, T &to, sal_Int32 *index=NULL) const
Returns a new string resulting from replacing the first occurrence of a given substring with another ...
Definition: ustring.hxx:2830
SAL_DLLPUBLIC sal_Int32 rtl_ustr_asciil_reverseCompare_WithLength(const sal_Unicode *first, sal_Int32 firstLen, const char *second, sal_Int32 secondLen) SAL_THROW_EXTERN_C()
Compare two strings from back to front.
SAL_DLLPUBLIC sal_uInt32 rtl_uString_iterateCodePoints(rtl_uString const *string, sal_Int32 *indexUtf16, sal_Int32 incrementCodePoints)
Iterate through a string based on code points instead of UTF-16 code units.
friend libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator!=(const OUString &rString, T &literal)
Compare string to an ASCII string literal.
Definition: ustring.hxx:2225
sal_uInt32 toUInt32(sal_Int16 radix=10) const
Returns the uint32 value from this string.
Definition: ustring.hxx:3177
SAL_DLLPUBLIC void rtl_uString_newConcatAsciiL(rtl_uString **newString, rtl_uString *left, char const *right, sal_Int32 rightLength)
Create a new string that is the concatenation of two other strings.
bool equals(const OUString &str) const
Perform a comparison of two strings.
Definition: ustring.hxx:967
SAL_DLLPUBLIC sal_Int32 rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(sal_Unicode const *first, sal_Int32 firstLen, char const *second, sal_Int32 secondLen) SAL_THROW_EXTERN_C()
Compare two strings, ignoring the case of ASCII characters.
SAL_DLLPUBLIC sal_Int32 rtl_ustr_ascii_compare_WithLength(const sal_Unicode *first, sal_Int32 firstLen, const char *second) SAL_THROW_EXTERN_C()
Compare two strings.
bool matchIgnoreAsciiCaseAsciiL(const char *asciiStr, sal_Int32 asciiStrLength, sal_Int32 fromIndex=0) const
Match against a substring appearing in this string, ignoring the case of ASCII letters.
Definition: ustring.hxx:1440
static OUString number(int i, sal_Int16 radix=10)
Returns the string representation of the integer argument.
Definition: ustring.hxx:3491
SAL_DLLPUBLIC sal_Int32 rtl_ustr_indexOfStr_WithLength(const sal_Unicode *str, sal_Int32 len, const sal_Unicode *subStr, sal_Int32 subLen) SAL_THROW_EXTERN_C()
Search for the first occurrence of a substring within a string.
OUString & operator+=(const OUString &str)
Append a string to this string.
Definition: ustring.hxx:692
This String class provide base functionality for C++ like 8-Bit character array handling.
Definition: string.hxx:192
This String class provides base functionality for C++ like Unicode character array handling...
Definition: ustring.hxx:171
libreoffice_internal::ConstCharArrayDetector< T, OUString &>::Type operator=(T &literal)
Assign a new string from an 8-Bit string literal that is expected to contain only characters in the A...
Definition: ustring.hxx:619
definition of a no acquire enum for ctors
Definition: types.h:374
~OUString()
Release the string data.
Definition: ustring.hxx:534
OString toUtf8() const
Convert this string to an OString, assuming that the string can be UTF-8-encoded successfully.
Definition: ustring.hxx:3441
OUString(const char *value, sal_Int32 length, rtl_TextEncoding encoding, sal_uInt32 convertFlags=OSTRING_TO_OUSTRING_CVTFLAGS)
New string from an 8-Bit character buffer array.
Definition: ustring.hxx:453
SAL_WARN_UNUSED_RESULT libreoffice_internal::ConstCharArrayDetector< T, OUString >::Type replaceFirst(T &from, OUString const &to, sal_Int32 *index=NULL) const
Returns a new string resulting from replacing the first occurrence of a given substring with another ...
Definition: ustring.hxx:2781
#define SAL_N_ELEMENTS(arr)
Definition: macros.h:51
sal_Int32 lastIndexOf(const OUString &str) const
Returns the index within this string of the last occurrence of the specified substring, searching backward starting at the end.
Definition: ustring.hxx:2471
bool endsWithAsciiL(char const *asciiStr, sal_Int32 asciiStrLength) const
Check whether this string ends with a given ASCII string.
Definition: ustring.hxx:1919
SAL_DLLPUBLIC sal_Int32 rtl_ustr_lastIndexOfAscii_WithLength(sal_Unicode const *str, sal_Int32 len, char const *subStr, sal_Int32 subLen) SAL_THROW_EXTERN_C()
Search for the last occurrence of an ASCII substring within a string.
SAL_DLLPUBLIC sal_Int32 rtl_ustr_valueOfInt32(sal_Unicode *str, sal_Int32 i, sal_Int16 radix) SAL_THROW_EXTERN_C()
Create the string representation of an integer.
SAL_DLLPUBLIC sal_Int32 rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength(const sal_Unicode *first, sal_Int32 firstLen, const sal_Unicode *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...
OUString(rtl_uString *str, __sal_NoAcquire)
New OUString from OUString data without acquiring it.
Definition: ustring.hxx:268
SAL_DLLPUBLIC void rtl_uString_newReplaceAllUtf16LAsciiL(rtl_uString **newStr, rtl_uString *str, sal_Unicode 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...
static OUString boolean(bool b)
Returns the string representation of the boolean argument.
Definition: ustring.hxx:3607
SAL_DLLPUBLIC void rtl_uString_newReplaceAllAsciiLAsciiL(rtl_uString **newStr, rtl_uString *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_ustr_indexOfChar_WithLength(const sal_Unicode *str, sal_Int32 len, sal_Unicode ch) SAL_THROW_EXTERN_C()
Search for the first occurrence of a character within a string.
OUString(const sal_Unicode *value)
New string from a Unicode character buffer array.
Definition: ustring.hxx:317
SAL_DLLPUBLIC void rtl_uString_newReplaceFirst(rtl_uString **newStr, rtl_uString *str, rtl_uString const *from, rtl_uString const *to, sal_Int32 *index) SAL_THROW_EXTERN_C()
Create a new string by replacing the first occurrence of a given substring with another substring...
sal_Int32 oslInterlockedCount
Definition: interlck.h:44
SAL_DLLPUBLIC void rtl_uString_newReplaceFirstUtf16LAsciiL(rtl_uString **newStr, rtl_uString *str, sal_Unicode 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_ustr_getLength(const sal_Unicode *str) SAL_THROW_EXTERN_C()
Return the length of a string.
sal_Int32 lastIndexOf(sal_Unicode ch) const
Returns the index within this string of the last occurrence of the specified character, searching backward starting at the end.
Definition: ustring.hxx:2338
OUString(const OUString &str)
New string from OUString.
Definition: ustring.hxx:195
Definition: stringutils.hxx:180
sal_Int32 lastIndexOfAsciiL(char const *str, sal_Int32 len) const
Returns the index within this string of the last occurrence of the specified ASCII substring...
Definition: ustring.hxx:2542
SAL_DLLPUBLIC void rtl_uString_newFromStr(rtl_uString **newStr, const sal_Unicode *value) SAL_THROW_EXTERN_C()
Allocate a new string that contains a copy of a character array.
SAL_DLLPUBLIC sal_Int32 rtl_ustr_valueOfInt64(sal_Unicode *str, sal_Int64 l, sal_Int16 radix) SAL_THROW_EXTERN_C()
Create the string representation of a long integer.
SAL_WARN_UNUSED_RESULT OUString replaceAt(sal_Int32 index, sal_Int32 count, const OUString &newStr) const
Returns a new string resulting from replacing n = count characters from position index in this string...
Definition: ustring.hxx:2659
bool equalsIgnoreAsciiCaseAsciiL(const char *asciiStr, sal_Int32 asciiStrLength) const
Perform an ASCII lowercase comparison of two strings.
Definition: ustring.hxx:1374
SAL_DLLPUBLIC sal_Int32 rtl_ustr_reverseCompare_WithLength(const sal_Unicode *first, sal_Int32 firstLen, const sal_Unicode *second, sal_Int32 secondLen) SAL_THROW_EXTERN_C()
Compare two strings from back to front.
bool isEmpty() const
Checks if a string is empty.
Definition: ustring.hxx:831
SAL_DLLPUBLIC void rtl_uString_newReplaceFirstAsciiLUtf16L(rtl_uString **newStr, rtl_uString *str, char const *from, sal_Int32 fromLength, sal_Unicode 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...
#define SAL_CONSTEXPR
C++11 "constexpr" feature.
Definition: types.h:422
SAL_WARN_UNUSED_RESULT OUString trim() const
Returns a new string resulting from removing white space from both ends of the string.
Definition: ustring.hxx:3070
bool startsWithIgnoreAsciiCase(OUString const &str, OUString *rest=NULL) const
Check whether this string starts with a given string, ignoring the case of ASCII letters.
Definition: ustring.hxx:1660
#define SAL_WARN_UNUSED_RESULT
Use this as markup for functions and methods whose return value must be used.
Definition: types.h:288
sal_Int64 toInt64(sal_Int16 radix=10) const
Returns the int64 value from this string.
Definition: ustring.hxx:3192
OUString(const sal_Unicode *value, sal_Int32 length)
New string from a Unicode character buffer array.
Definition: ustring.hxx:333
SAL_DLLPUBLIC void rtl_uString_newFromCodePoints(rtl_uString **newString, sal_uInt32 const *codePoints, sal_Int32 codePointCount) SAL_THROW_EXTERN_C()
Allocate a new string from an array of Unicode code points.
OUString & operator=(const OUString &str)
Assign a new string.
Definition: ustring.hxx:584
#define RTL_USTR_MAX_VALUEOFBOOLEAN
Definition: ustring.h:919
SAL_DLLPUBLIC void rtl_uString_newFromSubString(rtl_uString **newStr, const rtl_uString *from, sal_Int32 beginIndex, sal_Int32 count) SAL_THROW_EXTERN_C()
Allocate a new string that is a substring of this string.
OUString(T &literal, typename libreoffice_internal::ConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type=libreoffice_internal::Dummy())
New string from an 8-Bit string literal that is expected to contain only characters in the ASCII set ...
Definition: ustring.hxx:355
SAL_DLLPUBLIC sal_Int32 rtl_ustr_ascii_shortenedCompare_WithLength(const sal_Unicode *first, sal_Int32 firstLen, const char *second, sal_Int32 shortenedLen) SAL_THROW_EXTERN_C()
Compare two strings with a maximum count of characters.
size_t operator()(const OUString &rString) const
Compute a hash code for a string.
Definition: ustring.hxx:3831
SAL_WARN_UNUSED_RESULT libreoffice_internal::ConstCharArrayDetector< T1, typename libreoffice_internal::ConstCharArrayDetector< T2, OUString >::Type >::Type replaceFirst(T1 &from, T2 &to, sal_Int32 *index=NULL) const
Returns a new string resulting from replacing the first occurrence of a given substring with another ...
Definition: ustring.hxx:2865
sal_Int32 compareToIgnoreAsciiCaseAscii(const char *asciiStr) const
Compares two ASCII strings ignoring case.
Definition: ustring.hxx:1338
SAL_DLLPUBLIC void rtl_uString_newReplaceAllAsciiLUtf16L(rtl_uString **newStr, rtl_uString *str, char const *from, sal_Int32 fromLength, sal_Unicode const *to, sal_Int32 toLength) SAL_THROW_EXTERN_C()
Create a new string by replacing all occurrences of a given substring with another substring...
libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type lastIndexOf(T &literal) const
This is an overloaded member function, provided for convenience. It differs from the above function ...
Definition: ustring.hxx:2513
SAL_DLLPUBLIC void rtl_uString_newReplaceFirstUtf16LUtf16L(rtl_uString **newStr, rtl_uString *str, sal_Unicode const *from, sal_Int32 fromLength, sal_Unicode 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_ustr_indexOfAscii_WithLength(sal_Unicode const *str, sal_Int32 len, char const *subStr, sal_Int32 subLen) SAL_THROW_EXTERN_C()
Search for the first occurrence of an ASCII substring within a string.
bool endsWithIgnoreAsciiCase(OUString const &str, OUString *rest=NULL) const
Check whether this string ends with a given string, ignoring the case of ASCII letters.
Definition: ustring.hxx:2008
static OUString 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: ustring.hxx:3516
friend libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator==(T &literal, const OUString &rString)
Compare string to an ASCII string literal.
Definition: ustring.hxx:2209
bool endsWith(OUString const &str, OUString *rest=NULL) const
Check whether this string ends with a given substring.
Definition: ustring.hxx:1816
#define RTL_USTR_MAX_VALUEOFINT32
Definition: ustring.h:961
SAL_DLLPUBLIC double rtl_ustr_toDouble(const sal_Unicode *str) SAL_THROW_EXTERN_C()
Interpret a string as a double.
SAL_DLLPUBLIC void rtl_uString_newReplaceAllToAsciiL(rtl_uString **newStr, rtl_uString *str, rtl_uString const *from, 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...
float toFloat() const
Returns the float value from this string.
Definition: ustring.hxx:3222
void clear()
Clears the string, i.e, makes a zero-character string.
Definition: ustring.hxx:808
#define RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR
Definition: textcvt.h:72
SAL_DLLPUBLIC sal_Int32 rtl_ustr_valueOfUInt64(sal_Unicode *str, sal_uInt64 l, sal_Int16 radix) SAL_THROW_EXTERN_C()
Create the string representation of an unsigned long integer.
OUString intern() const
Return a canonical representation for a string.
Definition: ustring.hxx:3256
static OUString number(long i, sal_Int16 radix=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: ustring.hxx:3504
#define RTL_USTR_MAX_VALUEOFINT64
Definition: ustring.h:984
static OUString number(double d)
Returns the string representation of the double argument.
Definition: ustring.hxx:3561
friend libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator!=(T &literal, const OUString &rString)
Compare string to an ASCII string literal.
Definition: ustring.hxx:2241
OUString(sal_uInt32 const *codePoints, sal_Int32 codePointCount)
Create a new string from an array of Unicode code points.
Definition: ustring.hxx:480
SAL_WARN_UNUSED_RESULT OUString replaceFirst(OUString const &from, OUString const &to, sal_Int32 *index=NULL) const
Returns a new string resulting from replacing the first occurrence of a given substring with another ...
Definition: ustring.hxx:2736
static OUString 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: ustring.hxx:3510
OUString getToken(sal_Int32 count, sal_Unicode separator) const
Returns a token from the string.
Definition: ustring.hxx:3121
sal_Int32 reverseCompareTo(const OUString &str) const
Compares two strings in reverse order.
Definition: ustring.hxx:933
OUString(sal_Unicode value)
New string from a single Unicode character.
Definition: ustring.hxx:276
sal_Int32 lastIndexOf(sal_Unicode 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: ustring.hxx:2355
bool endsWithIgnoreAsciiCaseAsciiL(char const *asciiStr, sal_Int32 asciiStrLength) const
Check whether this string ends with a given ASCII string, ignoring the case of ASCII letters...
Definition: ustring.hxx:2104
bool toBoolean() const
Returns the Boolean value from this string.
Definition: ustring.hxx:3134
SAL_DLLPUBLIC sal_Bool rtl_convertUStringToString(rtl_String **pTarget, sal_Unicode const *pSource, sal_Int32 nLength, rtl_TextEncoding nEncoding, sal_uInt32 nFlags) SAL_THROW_EXTERN_C()
Converts a Unicode string to a byte string, signalling failure.
sal_Int32 hashCode() const
Returns a hashcode for this string.
Definition: ustring.hxx:2304