LibreOfficeDev
LibreOfficeDev 26.8 SDK C/C++ API Reference
Loading...
Searching...
No Matches
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 <ostream>
33#include <utility>
34
35#if defined LIBO_INTERNAL_ONLY
36#include <algorithm>
37#endif
38
39#include "rtl/math.h"
40#include "rtl/ustring.h"
41#include "rtl/string.hxx"
42#include "rtl/stringutils.hxx"
43#include "rtl/textenc.h"
44
45#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
46#include "config_global.h"
47#include "o3tl/safeint.hxx"
48#include "rtl/stringconcat.hxx"
49#endif
50
51#ifdef RTL_STRING_UNITTEST
52extern bool rtl_string_unittest_invalid_conversion;
53#endif
54
55// The unittest uses slightly different code to help check that the proper
56// calls are made. The class is put into a different namespace to make
57// sure the compiler generates a different (if generating also non-inline)
58// copy of the function and does not merge them together. The class
59// is "brought" into the proper rtl namespace by a typedef below.
60#ifdef RTL_STRING_UNITTEST
61#define rtl rtlunittest
62#endif
63
64namespace rtl
65{
66
67class OUStringBuffer;
68
69#ifdef RTL_STRING_UNITTEST
70#undef rtl
71#endif
72
73#if defined LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
75
82template<std::size_t N> class SAL_WARN_UNUSED OUStringLiteral {
83 static_assert(N != 0);
84 static_assert(N - 1 <= std::numeric_limits<sal_Int32>::max(), "literal too long");
85
86public:
87#if HAVE_CPP_CONSTEVAL
88 consteval
89#else
90 constexpr
91#endif
92 OUStringLiteral(char16_t const (&literal)[N]) {
93 assertLayout();
94 assert(literal[N - 1] == '\0');
95 std::copy_n(literal, N, more.buffer);
96 }
97
98 constexpr sal_Int32 getLength() const { return more.length; }
99
100 constexpr sal_Unicode const * getStr() const SAL_RETURNS_NONNULL { return more.buffer; }
101
102 constexpr operator std::u16string_view() const { return {more.buffer, sal_uInt32(more.length)}; }
103
104private:
105 static constexpr void assertLayout() {
106 // These static_asserts verifying the layout compatibility with rtl_uString cannot be class
107 // member declarations, as offsetof requires a complete type, so defer them to here:
108 static_assert(std::is_standard_layout_v<OUStringLiteral>);
109 static_assert(offsetof(OUStringLiteral, str.refCount) == offsetof(OUStringLiteral, more.refCount));
110 static_assert(offsetof(OUStringLiteral, str.length) == offsetof(OUStringLiteral, more.length));
111 static_assert(offsetof(OUStringLiteral, str.buffer) == offsetof(OUStringLiteral, more.buffer));
112 }
113
114 struct Data {
115 Data() = default;
116
117 oslInterlockedCount refCount = 0x40000000; // SAL_STRING_STATIC_FLAG (sal/rtl/strimp.hxx)
118 sal_Int32 length = N - 1;
119 sal_Unicode buffer[N];
120 };
121
122public:
123 // (Data members must be public so that OUStringLiteral is a structural type that can be used as
124 // a non-type template parameter type for operator ""_ustr:)
125 union {
126 rtl_uString str;
127 Data more = {};
128 };
129};
130
131#if defined RTL_STRING_UNITTEST
132namespace libreoffice_internal {
133template<std::size_t N> struct ExceptConstCharArrayDetector<OUStringLiteral<N>> {};
134template<std::size_t N> struct ExceptCharArrayDetector<OUStringLiteral<N>> {};
135}
136#endif
137
139#endif
140
141/* ======================================================================= */
142
165
166// coverity[ missing_move_assignment : SUPPRESS] - don't report the suppressed move assignment
167class SAL_WARN_UNUSED SAL_DLLPUBLIC_RTTI OUString
168{
169public:
171 rtl_uString * pData;
173
177#if defined LIBO_INTERNAL_ONLY
178 constexpr
179#endif
181 {
182#if defined LIBO_INTERNAL_ONLY
183 pData = const_cast<rtl_uString *>(&empty.str);
184#else
185 pData = NULL;
186 rtl_uString_new( &pData );
187#endif
188 }
189
194#if defined LIBO_INTERNAL_ONLY
195 constexpr
196#endif
197 OUString( const OUString & str )
198 {
199 pData = str.pData;
200#if defined LIBO_INTERNAL_ONLY
201 if (std::is_constant_evaluated()) {
202 //TODO: We would want to
203 //
204 // assert(SAL_STRING_IS_STATIC(pData));
205 //
206 // here, but that wouldn't work because read of member `str` of OUStringLiteral's
207 // anonymous union with active member `more` is not allowed in a constant expression.
208 } else
209#endif
210 rtl_uString_acquire( pData );
211 }
212
213#if defined LIBO_INTERNAL_ONLY
214#if !defined(__COVERITY__) // suppress COPY_INSTEAD_OF_MOVE suggestions
221 constexpr
222 OUString( OUString && str ) noexcept
223 {
224 pData = str.pData;
225 if (std::is_constant_evaluated()) {
226 //TODO: We would want to
227 //
228 // assert(SAL_STRING_IS_STATIC(pData));
229 //
230 // here, but that wouldn't work because read of member `str` of OUStringLiteral's
231 // anonymous union with active member `more` is not allowed in a constant expression.
232 return;
233 }
234 str.pData = nullptr;
235 rtl_uString_new( &str.pData );
236 }
237#endif
238#endif
239
245 OUString( rtl_uString * str )
246 {
247 pData = str;
248 rtl_uString_acquire( pData );
249 }
250
251#if defined LIBO_INTERNAL_ONLY
253 // Catch inadvertent conversions to the above ctor:
254 OUString(std::nullptr_t) = delete;
256#endif
257
266 OUString( rtl_uString * str, __sal_NoAcquire )
267 { pData = str; }
268
274 explicit OUString( sal_Unicode value )
275 : pData (NULL)
276 {
277 rtl_uString_newFromStr_WithLength( &pData, &value, 1 );
278 }
279
280#if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST_CONCAT
282 // Catch inadvertent conversions to the above ctor (but still allow
283 // construction from char literals):
284 OUString(int) = delete;
285 explicit OUString(char c):
286 OUString(sal_Unicode(static_cast<unsigned char>(c)))
287 {}
289#endif
290
291#if defined LIBO_INTERNAL_ONLY
292
293 template<typename T> explicit OUString(
294 T const & value,
295 typename libreoffice_internal::CharPtrDetector<T, libreoffice_internal::Dummy>::TypeUtf16
296 = libreoffice_internal::Dummy()):
297 pData(nullptr)
298 { rtl_uString_newFromStr(&pData, value); }
299
300 template<typename T> explicit OUString(
301 T & value,
302 typename
303 libreoffice_internal::NonConstCharArrayDetector<T, libreoffice_internal::Dummy>::TypeUtf16
304 = libreoffice_internal::Dummy()):
305 pData(nullptr)
306 { rtl_uString_newFromStr(&pData, value); }
307
308#else
309
315 OUString( const sal_Unicode * value )
316 {
317 pData = NULL;
318 rtl_uString_newFromStr( &pData, value );
319 }
320
321#endif
322
331 OUString( const sal_Unicode * value, sal_Int32 length )
332 {
333 pData = NULL;
334 rtl_uString_newFromStr_WithLength( &pData, value, length );
335 }
336
352 template< typename T >
354 {
355 assert(
357 pData = NULL;
359 rtl_uString_new(&pData);
360 } else {
362 &pData,
364 literal),
366 }
367#ifdef RTL_STRING_UNITTEST
368 rtl_string_unittest_const_literal = true;
369#endif
370 }
371
372#if defined LIBO_INTERNAL_ONLY
373 // Rather use a u""_ustr literal (but don't remove this entirely, to avoid implicit support for
374 // it via std::u16string_view from kicking in):
375 template<typename T> OUString(
376 T &,
378 T, libreoffice_internal::Dummy>::TypeUtf16
379 = libreoffice_internal::Dummy()) = delete;
380
381 OUString(OUStringChar c): pData(nullptr) { rtl_uString_newFromStr_WithLength(&pData, &c.c, 1); }
382#endif
383
384#if defined LIBO_INTERNAL_ONLY && defined RTL_STRING_UNITTEST
386
390 template< typename T >
391 OUString( T&, typename libreoffice_internal::ExceptConstCharArrayDetector< T >::Type = libreoffice_internal::Dummy() )
392 {
393 pData = NULL;
394 rtl_uString_newFromLiteral( &pData, "!!br0ken!!", 10, 0 ); // set to garbage
395 rtl_string_unittest_invalid_conversion = true;
396 }
401 template< typename T >
402 OUString( const T&, typename libreoffice_internal::ExceptCharArrayDetector< T >::Type = libreoffice_internal::Dummy() )
403 {
404 pData = NULL;
405 rtl_uString_newFromLiteral( &pData, "!!br0ken!!", 10, 0 ); // set to garbage
406 rtl_string_unittest_invalid_conversion = true;
407 }
409#endif
410
411#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
413
418 template<std::size_t N> constexpr OUString(OUStringLiteral<N> const & literal):
419 pData(const_cast<rtl_uString *>(&literal.str)) {}
420 template<std::size_t N> OUString(OUStringLiteral<N> &&) = delete;
422#endif
423
424#if defined LIBO_INTERNAL_ONLY
425 // For operator ""_tstr:
426 template<OStringLiteral L> OUString(detail::OStringHolder<L> const & holder) {
427 pData = nullptr;
428 if (holder.literal.getLength() == 0) {
429 rtl_uString_new(&pData);
430 } else {
432 &pData, holder.literal.getStr(), holder.literal.getLength(), 0);
433 }
434 }
435#endif
436
451 OUString( const char * value, sal_Int32 length,
452 rtl_TextEncoding encoding,
453 sal_uInt32 convertFlags = OSTRING_TO_OUSTRING_CVTFLAGS )
454 {
455 pData = NULL;
456 rtl_string2UString( &pData, value, length, encoding, convertFlags );
457 if (pData == NULL) {
458 throw std::bad_alloc();
459 }
460 }
461
478 explicit OUString(
479 sal_uInt32 const * codePoints, sal_Int32 codePointCount):
480 pData(NULL)
481 {
482 rtl_uString_newFromCodePoints(&pData, codePoints, codePointCount);
483 if (pData == NULL) {
484 throw std::bad_alloc();
485 }
486 }
487
488#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
493 template< typename T1, typename T2 >
494 OUString( OUStringConcat< T1, T2 >&& c )
495 {
496 const sal_Int32 l = c.length();
497 pData = rtl_uString_alloc( l );
498 if (l != 0)
499 {
500 sal_Unicode* end = c.addData( pData->buffer );
501 pData->length = l;
502 *end = '\0';
503 }
504 }
505
510 template< std::size_t N >
511 OUString( OUStringNumber< N >&& n )
512 : OUString( n.buf, n.length )
513 {}
514#endif
515
516#if defined LIBO_INTERNAL_ONLY
517 explicit OUString(std::u16string_view sv) {
518 if (sv.size() > sal_uInt32(std::numeric_limits<sal_Int32>::max())) {
519 throw std::bad_alloc();
520 }
521 pData = nullptr;
522 rtl_uString_newFromStr_WithLength(&pData, sv.data(), sv.size());
523 }
524#endif
525
529#if defined LIBO_INTERNAL_ONLY
530 constexpr
531#endif
533 {
534#if defined LIBO_INTERNAL_ONLY
535 if (std::is_constant_evaluated()) {
536 //TODO: We would want to
537 //
538 // assert(SAL_STRING_IS_STATIC(pData));
539 //
540 // here, but that wouldn't work because read of member `str` of OUStringLiteral's
541 // anonymous union with active member `more` is not allowed in a constant expression.
542 } else
543#endif
544 rtl_uString_release( pData );
545 }
546
558 static OUString const & unacquired( rtl_uString * const * ppHandle )
559 { return * reinterpret_cast< OUString const * >( ppHandle ); }
560
561#if defined LIBO_INTERNAL_ONLY
574 static OUString const& unacquired(const OUStringBuffer& str);
575#endif
576
582 OUString & operator=( const OUString & str )
583 {
584 rtl_uString_assign( &pData, str.pData );
585 return *this;
586 }
587
588#if defined LIBO_INTERNAL_ONLY
589#if !defined(__COVERITY__) // suppress COPY_INSTEAD_OF_MOVE suggestions
596 OUString & operator=( OUString && str ) noexcept
597 {
598 std::swap(pData, str.pData);
599 return *this;
600 }
601#endif
602#endif
603
616 template< typename T >
632
633#if defined LIBO_INTERNAL_ONLY
634 // Rather assign from a u""_ustr literal (but don't remove this entirely, to avoid implicit
635 // support for it via std::u16string_view from kicking in):
636 template<typename T>
637 typename
639 operator =(T &) = delete;
640
641 OUString & operator =(OUStringChar c) {
642 rtl_uString_newFromStr_WithLength(&pData, &c.c, 1);
643 return *this;
644 }
645
647 template<std::size_t N> OUString & operator =(OUStringLiteral<N> const & literal) {
648 rtl_uString_release(pData);
649 pData = const_cast<rtl_uString *>(&literal.str);
650 return *this;
651 }
652 template<std::size_t N> OUString & operator =(OUStringLiteral<N> &&) = delete;
653
654 template <std::size_t N>
655 OUString & operator =(OUStringNumber<N> && n) {
656 // n.length should never be zero, so no need to add an optimization for that case
657 rtl_uString_newFromStr_WithLength(&pData, n.buf, n.length);
658 return *this;
659 }
660
661 OUString & operator =(std::u16string_view sv) {
662 if (sv.empty()) {
663 rtl_uString_new(&pData);
664 } else {
665 rtl_uString_newFromStr_WithLength(&pData, sv.data(), sv.size());
666 }
667 return *this;
668 }
669#endif
670
671#if defined LIBO_INTERNAL_ONLY
680 inline OUString & operator+=( const OUStringBuffer & str ) &;
681#endif
682
690 OUString & operator+=( const OUString & str )
691#if defined LIBO_INTERNAL_ONLY
692 &
693#endif
694 {
695 return internalAppend(str.pData);
696 }
697#if defined LIBO_INTERNAL_ONLY
698 void operator+=(OUString const &) && = delete;
699#endif
700
707 template<typename T>
709 operator +=(T & literal)
710#if defined LIBO_INTERNAL_ONLY
711 &
712#endif
713 {
714 assert(
717 &pData, pData,
720 return *this;
721 }
722#if defined LIBO_INTERNAL_ONLY
723 template<typename T>
725 operator +=(T &) && = delete;
726#endif
727
728#if defined LIBO_INTERNAL_ONLY
730 template<typename T>
731 typename
733 operator +=(T & literal) & {
735 &pData, pData,
738 return *this;
739 }
740 template<typename T>
741 typename
742 libreoffice_internal::ConstCharArrayDetector<T, OUString &>::TypeUtf16
743 operator +=(T &) && = delete;
744
746 template<std::size_t N> OUString & operator +=(OUStringLiteral<N> const & literal) & {
747 rtl_uString_newConcatUtf16L(&pData, pData, literal.getStr(), literal.getLength());
748 return *this;
749 }
750 template<std::size_t N> void operator +=(OUStringLiteral<N> const &) && = delete;
751
752 OUString & operator +=(std::u16string_view sv) & {
753 if (sv.size() > sal_uInt32(std::numeric_limits<sal_Int32>::max())) {
754 throw std::bad_alloc();
755 }
756 rtl_uString_newConcatUtf16L(&pData, pData, sv.data(), sv.size());
757 return *this;
758 }
759 void operator +=(std::u16string_view) && = delete;
760#endif
761
762#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
767 template< typename T1, typename T2 >
768 OUString& operator+=( OUStringConcat< T1, T2 >&& c ) & {
769 sal_Int32 l = c.length();
770 if( l == 0 )
771 return *this;
772 l += pData->length;
773 rtl_uString_ensureCapacity( &pData, l );
774 sal_Unicode* end = c.addData( pData->buffer + pData->length );
775 *end = '\0';
776 pData->length = l;
777 return *this;
778 }
779 template<typename T1, typename T2> void operator +=(
780 OUStringConcat<T1, T2> &&) && = delete;
781
786 template< std::size_t N >
787 OUString& operator+=( OUStringNumber< N >&& n ) & {
788 sal_Int32 l = n.length;
789 if( l == 0 )
790 return *this;
791 l += pData->length;
792 rtl_uString_ensureCapacity( &pData, l );
793 sal_Unicode* end = addDataHelper( pData->buffer + pData->length, n.buf, n.length );
794 *end = '\0';
795 pData->length = l;
796 return *this;
797 }
798 template<std::size_t N> void operator +=(
799 OUStringNumber<N> &&) && = delete;
800#endif
801
806 void clear()
807 {
808 rtl_uString_new( &pData );
809 }
810
819 sal_Int32 getLength() const { return pData->length; }
820
829 bool isEmpty() const
830 {
831 return pData->length == 0;
832 }
833
841 const sal_Unicode * getStr() const SAL_RETURNS_NONNULL { return pData->buffer; }
842
852 sal_Unicode operator [](sal_Int32 index) const {
853 // silence spurious -Werror=strict-overflow warnings from GCC 4.8.2
854 assert(index >= 0 && static_cast<sal_uInt32>(index) < static_cast<sal_uInt32>(getLength()));
855 return getStr()[index];
856 }
857
870#if defined LIBO_INTERNAL_ONLY
871 sal_Int32 compareTo( std::u16string_view str ) const
872 {
873 return rtl_ustr_compare_WithLength( pData->buffer, pData->length,
874 str.data(), str.length() );
875 }
876#else
877 sal_Int32 compareTo( const OUString & str ) const
878 {
879 return rtl_ustr_compare_WithLength( pData->buffer, pData->length,
880 str.pData->buffer, str.pData->length );
881 }
882#endif
883
899#if defined LIBO_INTERNAL_ONLY
900 sal_Int32 compareTo( std::u16string_view str, sal_Int32 maxLength ) const
901 {
902 return rtl_ustr_shortenedCompare_WithLength( pData->buffer, pData->length,
903 str.data(), str.length(), maxLength );
904 }
905#else
906 sal_Int32 compareTo( const OUString & str, sal_Int32 maxLength ) const
907 {
908 return rtl_ustr_shortenedCompare_WithLength( pData->buffer, pData->length,
909 str.pData->buffer, str.pData->length, maxLength );
910 }
911#endif
912
925#if defined LIBO_INTERNAL_ONLY
926 sal_Int32 reverseCompareTo(std::u16string_view sv) const {
928 pData->buffer, pData->length, sv.data(), sv.size());
929 }
930#else
931 sal_Int32 reverseCompareTo( const OUString & str ) const
932 {
933 return rtl_ustr_reverseCompare_WithLength( pData->buffer, pData->length,
934 str.pData->buffer, str.pData->length );
935 }
936#endif
937
943 template< typename T >
953
965 bool equals( const OUString & str ) const
966 {
967 if ( pData->length != str.pData->length )
968 return false;
969 if ( pData == str.pData )
970 return true;
971 return rtl_ustr_reverseCompare_WithLength( pData->buffer, pData->length,
972 str.pData->buffer, str.pData->length ) == 0;
973 }
974
989#if defined LIBO_INTERNAL_ONLY
990 bool equalsIgnoreAsciiCase(std::u16string_view sv) const {
991 if ( sal_uInt32(pData->length) != sv.size() )
992 return false;
993 if ( pData->buffer == sv.data() )
994 return true;
995 return
997 pData->buffer, pData->length, sv.data(), sv.size())
998 == 0;
999 }
1000#else
1001 bool equalsIgnoreAsciiCase( const OUString & str ) const
1002 {
1003 if ( pData->length != str.pData->length )
1004 return false;
1005 if ( pData == str.pData )
1006 return true;
1007 return rtl_ustr_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
1008 str.pData->buffer, str.pData->length ) == 0;
1009 }
1010#endif
1011
1027#if defined LIBO_INTERNAL_ONLY
1028 sal_Int32 compareToIgnoreAsciiCase(std::u16string_view sv) const {
1030 pData->buffer, pData->length, sv.data(), sv.size());
1031 }
1032#else
1033 sal_Int32 compareToIgnoreAsciiCase( const OUString & str ) const
1034 {
1035 return rtl_ustr_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
1036 str.pData->buffer, str.pData->length );
1037 }
1038#endif
1039
1045 template< typename T >
1059
1075#if defined LIBO_INTERNAL_ONLY
1076 bool match(std::u16string_view sv, sal_Int32 fromIndex = 0) const {
1077 assert(fromIndex >= 0);
1078 return
1080 pData->buffer + fromIndex, pData->length - fromIndex, sv.data(), sv.size(),
1081 sv.size())
1082 == 0;
1083 }
1084#else
1085 bool match( const OUString & str, sal_Int32 fromIndex = 0 ) const
1086 {
1087 assert(fromIndex >= 0);
1088 return rtl_ustr_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
1089 str.pData->buffer, str.pData->length, str.pData->length ) == 0;
1090 }
1091#endif
1092
1098 template< typename T >
1099 typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type match( T& literal, sal_Int32 fromIndex = 0 ) const
1100 {
1101 assert(
1103 assert(fromIndex >= 0);
1104 return
1106 pData->buffer+fromIndex, pData->length-fromIndex,
1108 literal),
1110 == 0;
1111 }
1112
1131#if defined LIBO_INTERNAL_ONLY
1132 bool matchIgnoreAsciiCase(std::u16string_view sv, sal_Int32 fromIndex = 0) const {
1133 assert(fromIndex >= 0);
1134 return
1136 pData->buffer + fromIndex, pData->length - fromIndex, sv.data(), sv.size(),
1137 sv.size())
1138 == 0;
1139 }
1140#else
1141 bool matchIgnoreAsciiCase( const OUString & str, sal_Int32 fromIndex = 0 ) const
1142 {
1143 assert(fromIndex >= 0);
1144 return rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
1145 str.pData->buffer, str.pData->length,
1146 str.pData->length ) == 0;
1147 }
1148#endif
1149
1155 template< typename T >
1164
1181 sal_Int32 compareToAscii( const char* asciiStr ) const
1182 {
1183 return rtl_ustr_ascii_compare_WithLength( pData->buffer, pData->length, asciiStr );
1184 }
1185
1209 "replace s1.compareToAscii(s2, strlen(s2)) == 0 with s1.startsWith(s2)")
1210 sal_Int32 compareToAscii( const char * asciiStr, sal_Int32 maxLength ) const
1211 {
1212 return rtl_ustr_ascii_shortenedCompare_WithLength( pData->buffer, pData->length,
1213 asciiStr, maxLength );
1214 }
1215
1234 sal_Int32 reverseCompareToAsciiL( const char * asciiStr, sal_Int32 asciiStrLength ) const
1235 {
1236 return rtl_ustr_asciil_reverseCompare_WithLength( pData->buffer, pData->length,
1237 asciiStr, asciiStrLength );
1238 }
1239
1255 bool equalsAscii( const char* asciiStr ) const
1256 {
1257 return rtl_ustr_ascii_compare_WithLength( pData->buffer, pData->length,
1258 asciiStr ) == 0;
1259 }
1260
1277 bool equalsAsciiL( const char* asciiStr, sal_Int32 asciiStrLength ) const
1278 {
1279 if ( pData->length != asciiStrLength )
1280 return false;
1281
1283 pData->buffer, asciiStr, asciiStrLength );
1284 }
1285
1304 bool equalsIgnoreAsciiCaseAscii( const char * asciiStr ) const
1305 {
1306 return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, asciiStr ) == 0;
1307 }
1308
1309#if defined LIBO_INTERNAL_ONLY
1310 bool equalsIgnoreAsciiCaseAscii( std::string_view asciiStr ) const
1311 {
1312 return o3tl::make_unsigned(pData->length) == asciiStr.length()
1314 pData->buffer, pData->length, asciiStr.data(), asciiStr.length()) == 0;
1315 }
1316#endif
1317
1336 sal_Int32 compareToIgnoreAsciiCaseAscii( const char * asciiStr ) const
1337 {
1338 return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, asciiStr );
1339 }
1340
1341#if defined LIBO_INTERNAL_ONLY
1342 sal_Int32 compareToIgnoreAsciiCaseAscii( std::string_view asciiStr ) const
1343 {
1344 sal_Int32 nMax = std::min<size_t>(asciiStr.length(), std::numeric_limits<sal_Int32>::max());
1346 pData->buffer, pData->length, asciiStr.data(), nMax);
1347 if (result == 0 && o3tl::make_unsigned(pData->length) < asciiStr.length())
1348 result = -1;
1349 return result;
1350 }
1351#endif
1352
1372 bool equalsIgnoreAsciiCaseAsciiL( const char * asciiStr, sal_Int32 asciiStrLength ) const
1373 {
1374 if ( pData->length != asciiStrLength )
1375 return false;
1376
1377 return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, asciiStr ) == 0;
1378 }
1379
1400 bool matchAsciiL( const char* asciiStr, sal_Int32 asciiStrLength, sal_Int32 fromIndex = 0 ) const
1401 {
1402 assert(fromIndex >= 0);
1403 return rtl_ustr_ascii_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
1404 asciiStr, asciiStrLength ) == 0;
1405 }
1406
1407 // This overload is left undefined, to detect calls of matchAsciiL that
1408 // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
1409 // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
1410 // platforms):
1411#if SAL_TYPES_SIZEOFLONG == 8
1412 void matchAsciiL(char const *, sal_Int32, rtl_TextEncoding) const;
1413#endif
1414
1438 bool matchIgnoreAsciiCaseAsciiL( const char* asciiStr, sal_Int32 asciiStrLength, sal_Int32 fromIndex = 0 ) const
1439 {
1440 assert(fromIndex >= 0);
1441 return rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
1442 asciiStr, asciiStrLength ) == 0;
1443 }
1444
1445 // This overload is left undefined, to detect calls of
1446 // matchIgnoreAsciiCaseAsciiL that erroneously use
1447 // RTL_CONSTASCII_USTRINGPARAM instead of RTL_CONSTASCII_STRINGPARAM (but
1448 // would lead to ambiguities on 32 bit platforms):
1449#if SAL_TYPES_SIZEOFLONG == 8
1450 void matchIgnoreAsciiCaseAsciiL(char const *, sal_Int32, rtl_TextEncoding)
1451 const;
1452#endif
1453
1454#if defined LIBO_INTERNAL_ONLY
1465 bool startsWith(std::u16string_view sv) const {
1466 return match(sv);
1467 }
1482 bool startsWith(std::u16string_view sv, OUString * rest) const {
1483 assert(rest);
1484 auto const b = startsWith(sv);
1485 if (b) {
1486 *rest = copy(sv.size());
1487 }
1488 return b;
1489 }
1503 bool startsWith(std::u16string_view sv, std::u16string_view * rest) const {
1504 assert(rest);
1505 auto const b = startsWith(sv);
1506 if (b) {
1507 *rest = subView(sv.size());
1508 }
1509 return b;
1510 }
1511#else
1526 bool startsWith(OUString const & str, OUString * rest = NULL) const {
1527 bool b = match(str);
1528 if (b && rest != NULL) {
1529 *rest = copy(str.getLength());
1530 }
1531 return b;
1532 }
1533#endif
1534
1535#if defined LIBO_INTERNAL_ONLY
1540 template< typename T >
1542 T & literal) const
1543 {
1544 assert(
1546 bool b
1548 <= sal_uInt32(pData->length))
1550 pData->buffer,
1552 literal),
1554 return b;
1555 }
1561 template< typename T >
1562 typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type startsWith(
1563 T & literal, OUString * rest) const
1564 {
1565 assert(rest);
1566 bool b = startsWith(literal);
1567 if (b) {
1568 *rest = copy(
1569 libreoffice_internal::ConstCharArrayDetector<T>::length);
1570 }
1571 return b;
1572 }
1577 template< typename T >
1578 typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type startsWith(
1579 T & literal, std::u16string_view * rest) const
1580 {
1581 assert(rest);
1582 bool b = startsWith(literal);
1583 if (b) {
1584 *rest = subView(
1585 libreoffice_internal::ConstCharArrayDetector<T>::length);
1586 }
1587 return b;
1588 }
1589#else
1595 template< typename T >
1597 T & literal, OUString * rest = NULL) const
1598 {
1599 assert(
1601 bool b
1603 <= sal_uInt32(pData->length))
1605 pData->buffer,
1607 literal),
1609 if (b && rest != NULL) {
1610 *rest = copy(
1612 }
1613 return b;
1614 }
1615#endif
1616
1627 {
1628 return !isEmpty() && pData->buffer[0] == ch;
1629 }
1630
1643 bool startsWith(sal_Unicode ch, OUString* rest) const {
1644 assert(rest);
1645 bool b = startsWith(ch);
1646
1647 if (b)
1648 *rest = copy(1);
1649
1650 return b;
1651 }
1652
1653#if defined LIBO_INTERNAL_ONLY
1666 bool startsWith(sal_Unicode ch, std::u16string_view* rest) const {
1667 assert(rest);
1668 bool b = startsWith(ch);
1669
1670 if (b)
1671 *rest = subView(1);
1672
1673 return b;
1674 }
1675#endif
1676
1697#if defined LIBO_INTERNAL_ONLY
1698 bool startsWithIgnoreAsciiCase(std::u16string_view sv) const {
1699 return matchIgnoreAsciiCase(sv);
1700 }
1701 bool startsWithIgnoreAsciiCase(std::u16string_view sv, OUString * rest) const {
1702 assert(rest);
1703 auto const b = startsWithIgnoreAsciiCase(sv);
1704 if (b) {
1705 *rest = copy(sv.size());
1706 }
1707 return b;
1708 }
1709 bool startsWithIgnoreAsciiCase(std::u16string_view sv, std::u16string_view * rest) const {
1710 assert(rest);
1711 auto const b = startsWithIgnoreAsciiCase(sv);
1712 if (b) {
1713 *rest = subView(sv.size());
1714 }
1715 return b;
1716 }
1717#else
1718 bool startsWithIgnoreAsciiCase(OUString const & str, OUString * rest = NULL)
1719 const
1720 {
1721 bool b = matchIgnoreAsciiCase(str);
1722 if (b && rest != NULL) {
1723 *rest = copy(str.getLength());
1724 }
1725 return b;
1726 }
1727#endif
1728
1729#if defined LIBO_INTERNAL_ONLY
1735 template< typename T >
1737 startsWithIgnoreAsciiCase(T & literal) const
1738 {
1739 assert(
1741 bool b
1743 <= sal_uInt32(pData->length))
1745 pData->buffer,
1748 literal),
1750 == 0);
1751 return b;
1752 }
1758 template< typename T >
1759 typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
1760 startsWithIgnoreAsciiCase(T & literal, OUString * rest) const
1761 {
1762 assert(rest);
1763 bool b = startsWithIgnoreAsciiCase(literal);
1764 if (b) {
1765 *rest = copy(
1766 libreoffice_internal::ConstCharArrayDetector<T>::length);
1767 }
1768 return b;
1769 }
1774 template< typename T >
1775 typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
1776 startsWithIgnoreAsciiCase(T & literal, std::u16string_view * rest) const
1777 {
1778 assert(rest);
1779 bool b = startsWithIgnoreAsciiCase(literal);
1780 if (b) {
1781 *rest = subView(
1782 libreoffice_internal::ConstCharArrayDetector<T>::length);
1783 }
1784 return b;
1785 }
1786#else
1792 template< typename T >
1793 typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
1794 startsWithIgnoreAsciiCase(T & literal, OUString * rest = NULL) const
1795 {
1796 assert(
1798 bool b
1800 <= sal_uInt32(pData->length))
1802 pData->buffer,
1805 literal),
1807 == 0);
1808 if (b && rest != NULL) {
1809 *rest = copy(
1811 }
1812 return b;
1813 }
1814#endif
1815
1816#if defined LIBO_INTERNAL_ONLY
1827 bool endsWith(std::u16string_view sv) const {
1828 return sv.size() <= sal_uInt32(pData->length)
1829 && match(sv, pData->length - sv.size());
1830 }
1831 bool endsWith(std::u16string_view sv, OUString * rest) const {
1832 auto const b = endsWith(sv);
1833 if (b && rest != nullptr) {
1834 *rest = copy(0, (pData->length - sv.size()));
1835 }
1836 return b;
1837 }
1851 bool endsWith(std::u16string_view sv, std::u16string_view * rest) const {
1852 assert(rest);
1853 auto const b = endsWith(sv);
1854 if (b) {
1855 *rest = subView(0, (pData->length - sv.size()));
1856 }
1857 return b;
1858 }
1859#else
1874 bool endsWith(OUString const & str, OUString * rest = NULL) const {
1875 bool b = str.getLength() <= getLength()
1876 && match(str, getLength() - str.getLength());
1877 if (b && rest != NULL) {
1878 *rest = copy(0, getLength() - str.getLength());
1879 }
1880 return b;
1881 }
1882#endif
1883
1893 bool endsWith(sal_Unicode ch) const
1894 {
1895 return !isEmpty() && pData->buffer[pData->length - 1] == ch;
1896 }
1897
1910 bool endsWith(sal_Unicode ch, OUString* rest) const {
1911 assert(rest);
1912 bool b = endsWith(ch);
1913
1914 if (b)
1915 *rest = copy(0, pData->length - 1);
1916
1917 return b;
1918 }
1919
1920#if defined LIBO_INTERNAL_ONLY
1933 bool endsWith(sal_Unicode ch, std::u16string_view* rest) const {
1934 assert(rest);
1935 bool b = endsWith(ch);
1936
1937 if (b)
1938 *rest = subView(0, pData->length - 1);
1939
1940 return b;
1941 }
1942#endif
1943
1944#if defined LIBO_INTERNAL_ONLY
1950 template< typename T >
1951 typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
1952 endsWith(T & literal) const
1953 {
1954 assert(
1955 libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
1956 bool b
1957 = (libreoffice_internal::ConstCharArrayDetector<T>::length
1958 <= sal_uInt32(pData->length))
1960 (pData->buffer + pData->length
1961 - libreoffice_internal::ConstCharArrayDetector<T>::length),
1962 libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
1963 literal),
1964 libreoffice_internal::ConstCharArrayDetector<T>::length);
1965 return b;
1966 }
1967 template< typename T >
1968 typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
1969 endsWith(T & literal, OUString * rest) const
1970 {
1971 assert(rest);
1972 bool b = endsWith(literal);
1973 if (b) {
1974 *rest = copy(
1975 0,
1976 (getLength()
1977 - libreoffice_internal::ConstCharArrayDetector<T>::length));
1978 }
1979 return b;
1980 }
1981 template< typename T >
1982 typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
1983 endsWith(T & literal, std::u16string_view * rest) const
1984 {
1985 assert(rest);
1986 bool b = endsWith(literal);
1987 if (b) {
1988 *rest = subView(
1989 0,
1990 (getLength()
1991 - libreoffice_internal::ConstCharArrayDetector<T>::length));
1992 }
1993 return b;
1994 }
1995#else
2001 template< typename T >
2002 typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
2003 endsWith(T & literal, OUString * rest = NULL) const
2004 {
2005 assert(
2007 bool b
2009 <= sal_uInt32(pData->length))
2011 (pData->buffer + pData->length
2014 literal),
2016 if (b && rest != NULL) {
2017 *rest = copy(
2018 0,
2019 (getLength()
2021 }
2022 return b;
2023 }
2024#endif
2025
2037 bool endsWithAsciiL(char const * asciiStr, sal_Int32 asciiStrLength)
2038 const
2039 {
2040 return asciiStrLength <= pData->length
2042 pData->buffer + pData->length - asciiStrLength, asciiStr,
2043 asciiStrLength);
2044 }
2045
2046#if defined LIBO_INTERNAL_ONLY
2067 bool endsWithIgnoreAsciiCase(std::u16string_view sv) const {
2068 return sv.size() <= sal_uInt32(pData->length)
2069 && matchIgnoreAsciiCase(sv, pData->length - sv.size());
2070 }
2071 bool endsWithIgnoreAsciiCase(std::u16string_view sv, OUString * rest) const {
2072 auto const b = endsWithIgnoreAsciiCase(sv);
2073 if (b && rest != nullptr) {
2074 *rest = copy(0, pData->length - sv.size());
2075 }
2076 return b;
2077 }
2097 bool endsWithIgnoreAsciiCase(std::u16string_view sv, std::u16string_view * rest) const {
2098 assert(rest);
2099 auto const b = endsWithIgnoreAsciiCase(sv);
2100 if (b) {
2101 *rest = subView(0, pData->length - sv.size());
2102 }
2103 return b;
2104 }
2105#else
2126 bool endsWithIgnoreAsciiCase(OUString const & str, OUString * rest = NULL) const
2127 {
2128 bool b = str.getLength() <= getLength()
2129 && matchIgnoreAsciiCase(str, getLength() - str.getLength());
2130 if (b && rest != NULL) {
2131 *rest = copy(0, getLength() - str.getLength());
2132 }
2133 return b;
2134 }
2135#endif
2136
2137#if defined LIBO_INTERNAL_ONLY
2142 template< typename T >
2144 endsWithIgnoreAsciiCase(T & literal) const
2145 {
2146 assert(
2148 bool b
2150 <= sal_uInt32(pData->length))
2152 (pData->buffer + pData->length
2156 literal),
2158 == 0);
2159 return b;
2160 }
2165 template< typename T >
2166 typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
2167 endsWithIgnoreAsciiCase(T & literal, std::u16string_view * rest) const
2168 {
2169 assert(rest);
2170 bool b = endsWithIgnoreAsciiCase(literal);
2171 if (b) {
2172 *rest = subView(
2173 0,
2174 (getLength()
2175 - libreoffice_internal::ConstCharArrayDetector<T>::length));
2176 }
2177 return b;
2178 }
2179#else
2185 template< typename T >
2186 typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
2187 endsWithIgnoreAsciiCase(T & literal, OUString * rest = NULL) const
2188 {
2189 assert(
2191 bool b
2193 <= sal_uInt32(pData->length))
2195 (pData->buffer + pData->length
2199 literal),
2201 == 0);
2202 if (b && rest != NULL) {
2203 *rest = copy(
2204 0,
2205 (getLength()
2207 }
2208 return b;
2209 }
2210#endif
2211
2223 char const * asciiStr, sal_Int32 asciiStrLength) const
2224 {
2225 return asciiStrLength <= pData->length
2227 pData->buffer + pData->length - asciiStrLength,
2228 asciiStrLength, asciiStr, asciiStrLength)
2229 == 0);
2230 }
2231
2232 friend bool operator == ( const OUString& rStr1, const OUString& rStr2 )
2233 { return rStr1.equals(rStr2); }
2234
2235 friend bool operator != ( const OUString& rStr1, const OUString& rStr2 )
2236 { return !(operator == ( rStr1, rStr2 )); }
2237
2238 friend bool operator < ( const OUString& rStr1, const OUString& rStr2 )
2239 { return rStr1.compareTo( rStr2 ) < 0; }
2240 friend bool operator > ( const OUString& rStr1, const OUString& rStr2 )
2241 { return rStr1.compareTo( rStr2 ) > 0; }
2242 friend bool operator <= ( const OUString& rStr1, const OUString& rStr2 )
2243 { return rStr1.compareTo( rStr2 ) <= 0; }
2244 friend bool operator >= ( const OUString& rStr1, const OUString& rStr2 )
2245 { return rStr1.compareTo( rStr2 ) >= 0; }
2246
2247#if defined LIBO_INTERNAL_ONLY
2248
2249 template<typename T> friend typename libreoffice_internal::CharPtrDetector<T, bool>::TypeUtf16
2250 operator ==(OUString const & s1, T const & s2) {
2252 == 0;
2253 }
2254
2255 template<typename T>
2256 friend typename libreoffice_internal::NonConstCharArrayDetector<T, bool>::TypeUtf16
2257 operator ==(OUString const & s1, T & s2) {
2258 return rtl_ustr_compare_WithLength(s1.getStr(), s1.getLength(), s2, rtl_ustr_getLength(s2))
2259 == 0;
2260 }
2261
2262 template<typename T> friend typename libreoffice_internal::CharPtrDetector<T, bool>::TypeUtf16
2263 operator ==(T const & s1, OUString const & s2) {
2264 return rtl_ustr_compare_WithLength(s1, rtl_ustr_getLength(s1), s2.getStr(), s2.getLength())
2265 == 0;
2266 }
2267
2268 template<typename T>
2269 friend typename libreoffice_internal::NonConstCharArrayDetector<T, bool>::TypeUtf16
2270 operator ==(T & s1, OUString const & s2) {
2271 return rtl_ustr_compare_WithLength(s1, rtl_ustr_getLength(s1), s2.getStr(), s2.getLength())
2272 == 0;
2273 }
2274
2275 template<typename T> friend typename libreoffice_internal::CharPtrDetector<T, bool>::TypeUtf16
2276 operator !=(OUString const & s1, T const & s2) { return !(s1 == s2); }
2277
2278 template<typename T>
2279 friend typename libreoffice_internal::NonConstCharArrayDetector<T, bool>::TypeUtf16
2280 operator !=(OUString const & s1, T & s2) { return !(s1 == s2); }
2281
2282 template<typename T> friend typename libreoffice_internal::CharPtrDetector<T, bool>::TypeUtf16
2283 operator !=(T const & s1, OUString const & s2) { return !(s1 == s2); }
2284
2285 template<typename T>
2286 friend typename libreoffice_internal::NonConstCharArrayDetector<T, bool>::TypeUtf16
2287 operator !=(T & s1, OUString const & s2) { return !(s1 == s2); }
2288
2289#else
2290
2291 friend bool operator == ( const OUString& rStr1, const sal_Unicode * pStr2 )
2292 { return rStr1.compareTo( pStr2 ) == 0; }
2293 friend bool operator == ( const sal_Unicode * pStr1, const OUString& rStr2 )
2294 { return OUString( pStr1 ).compareTo( rStr2 ) == 0; }
2295
2296 friend bool operator != ( const OUString& rStr1, const sal_Unicode * pStr2 )
2297 { return !(operator == ( rStr1, pStr2 )); }
2298 friend bool operator != ( const sal_Unicode * pStr1, const OUString& rStr2 )
2299 { return !(operator == ( pStr1, rStr2 )); }
2300
2301#endif
2302
2310 template< typename T >
2319
2326 template< typename T >
2335
2342 template< typename T >
2351
2358 template< typename T >
2367
2368#if defined LIBO_INTERNAL_ONLY
2370 template<typename T> friend typename libreoffice_internal::ConstCharArrayDetector<T, bool>::TypeUtf16
2371 operator ==(OUString const & string, T & literal) {
2372 return
2374 string.pData->buffer, string.pData->length,
2376 literal),
2378 == 0;
2379 }
2381 template<typename T> friend typename libreoffice_internal::ConstCharArrayDetector<T, bool>::TypeUtf16
2382 operator ==(T & literal, OUString const & string) {
2383 return
2385 libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
2386 literal),
2387 libreoffice_internal::ConstCharArrayDetector<T>::length,
2388 string.pData->buffer, string.pData->length)
2389 == 0;
2390 }
2392 template<typename T> friend typename libreoffice_internal::ConstCharArrayDetector<T, bool>::TypeUtf16
2393 operator !=(OUString const & string, T & literal) {
2394 return
2396 string.pData->buffer, string.pData->length,
2397 libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
2398 literal),
2399 libreoffice_internal::ConstCharArrayDetector<T>::length)
2400 != 0;
2401 }
2403 template<typename T> friend typename libreoffice_internal::ConstCharArrayDetector<T, bool>::TypeUtf16
2404 operator !=(T & literal, OUString const & string) {
2405 return
2407 libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
2408 literal),
2409 libreoffice_internal::ConstCharArrayDetector<T>::length,
2410 string.pData->buffer, string.pData->length)
2411 != 0;
2412 }
2413#endif
2414
2422 sal_Int32 hashCode() const
2423 {
2424 return rtl_ustr_hashCode_WithLength( pData->buffer, pData->length );
2425 }
2426
2440 sal_Int32 indexOf( sal_Unicode ch, sal_Int32 fromIndex = 0 ) const
2441 {
2442 assert(fromIndex >= 0);
2443 sal_Int32 ret = rtl_ustr_indexOfChar_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, ch );
2444 return (ret < 0 ? ret : ret+fromIndex);
2445 }
2446
2456 sal_Int32 lastIndexOf( sal_Unicode ch ) const
2457 {
2458 return rtl_ustr_lastIndexOfChar_WithLength( pData->buffer, pData->length, ch );
2459 }
2460
2473 sal_Int32 lastIndexOf( sal_Unicode ch, sal_Int32 fromIndex ) const
2474 {
2475 return rtl_ustr_lastIndexOfChar_WithLength( pData->buffer, fromIndex, ch );
2476 }
2477
2493#if defined LIBO_INTERNAL_ONLY
2494 sal_Int32 indexOf(std::u16string_view sv, sal_Int32 fromIndex = 0) const {
2495 assert(fromIndex >= 0);
2496 auto const n = rtl_ustr_indexOfStr_WithLength(
2497 pData->buffer + fromIndex, pData->length - fromIndex, sv.data(), sv.size());
2498 return n < 0 ? n : n + fromIndex;
2499 }
2500#else
2501 sal_Int32 indexOf( const OUString & str, sal_Int32 fromIndex = 0 ) const
2502 {
2503 assert(fromIndex >= 0);
2504 sal_Int32 ret = rtl_ustr_indexOfStr_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
2505 str.pData->buffer, str.pData->length );
2506 return (ret < 0 ? ret : ret+fromIndex);
2507 }
2508#endif
2509
2515 template< typename T >
2516 typename libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type indexOf( T& literal, sal_Int32 fromIndex = 0 ) const
2517 {
2518 assert(
2520 assert(fromIndex >= 0);
2522 pData->buffer + fromIndex, pData->length - fromIndex,
2525 return n < 0 ? n : n + fromIndex;
2526 }
2527
2551 sal_Int32 indexOfAsciiL(
2552 char const * str, sal_Int32 len, sal_Int32 fromIndex = 0) const
2553 {
2554 assert(fromIndex >= 0);
2555 sal_Int32 ret = rtl_ustr_indexOfAscii_WithLength(
2556 pData->buffer + fromIndex, pData->length - fromIndex, str, len);
2557 return ret < 0 ? ret : ret + fromIndex;
2558 }
2559
2560 // This overload is left undefined, to detect calls of indexOfAsciiL that
2561 // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
2562 // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
2563 // platforms):
2564#if SAL_TYPES_SIZEOFLONG == 8
2565 void indexOfAsciiL(char const *, sal_Int32 len, rtl_TextEncoding) const;
2566#endif
2567
2583#if defined LIBO_INTERNAL_ONLY
2584 sal_Int32 lastIndexOf(std::u16string_view sv) const {
2586 pData->buffer, pData->length, sv.data(), sv.size());
2587 }
2588#else
2589 sal_Int32 lastIndexOf( const OUString & str ) const
2590 {
2591 return rtl_ustr_lastIndexOfStr_WithLength( pData->buffer, pData->length,
2592 str.pData->buffer, str.pData->length );
2593 }
2594#endif
2595
2613#if defined LIBO_INTERNAL_ONLY
2614 sal_Int32 lastIndexOf(std::u16string_view sv, sal_Int32 fromIndex) const {
2615 return rtl_ustr_lastIndexOfStr_WithLength(pData->buffer, fromIndex, sv.data(), sv.size());
2616 }
2617#else
2618 sal_Int32 lastIndexOf( const OUString & str, sal_Int32 fromIndex ) const
2619 {
2620 return rtl_ustr_lastIndexOfStr_WithLength( pData->buffer, fromIndex,
2621 str.pData->buffer, str.pData->length );
2622 }
2623#endif
2624
2630 template< typename T >
2640
2660 sal_Int32 lastIndexOfAsciiL(char const * str, sal_Int32 len) const
2661 {
2663 pData->buffer, pData->length, str, len);
2664 }
2665
2676 SAL_WARN_UNUSED_RESULT OUString copy( sal_Int32 beginIndex ) const
2677 {
2678 return copy(beginIndex, getLength() - beginIndex);
2679 }
2680
2693 SAL_WARN_UNUSED_RESULT OUString copy( sal_Int32 beginIndex, sal_Int32 count ) const
2694 {
2695 rtl_uString *pNew = NULL;
2696 rtl_uString_newFromSubString( &pNew, pData, beginIndex, count );
2697 return OUString( pNew, SAL_NO_ACQUIRE );
2698 }
2699
2700#if defined LIBO_INTERNAL_ONLY
2711 SAL_WARN_UNUSED_RESULT std::u16string_view subView( sal_Int32 beginIndex ) const
2712 {
2713 assert(beginIndex >= 0);
2714 assert(beginIndex <= getLength());
2715 return subView(beginIndex, getLength() - beginIndex);
2716 }
2717
2730 SAL_WARN_UNUSED_RESULT std::u16string_view subView( sal_Int32 beginIndex, sal_Int32 count ) const
2731 {
2732 assert(beginIndex >= 0);
2733 assert(count >= 0);
2734 assert(beginIndex <= getLength());
2735 assert(count <= getLength() - beginIndex);
2736 return std::u16string_view(*this).substr(beginIndex, count);
2737 }
2738#endif
2739
2740#ifndef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
2750 {
2751 rtl_uString* pNew = NULL;
2752 rtl_uString_newConcat( &pNew, pData, str.pData );
2753 return OUString( pNew, SAL_NO_ACQUIRE );
2754 }
2755#endif
2756
2757#ifndef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
2758 friend OUString operator+( const OUString& rStr1, const OUString& rStr2 )
2759 {
2760 return rStr1.concat( rStr2 );
2761 }
2762#endif
2763
2777 SAL_WARN_UNUSED_RESULT OUString replaceAt( sal_Int32 index, sal_Int32 count, const OUString& newStr ) const
2778 {
2779 rtl_uString* pNew = NULL;
2780 rtl_uString_newReplaceStrAt( &pNew, pData, index, count, newStr.pData );
2781 return OUString( pNew, SAL_NO_ACQUIRE );
2782 }
2783
2784#ifdef LIBO_INTERNAL_ONLY
2785 SAL_WARN_UNUSED_RESULT OUString replaceAt( sal_Int32 index, sal_Int32 count, std::u16string_view newStr ) const
2786 {
2787 rtl_uString* pNew = NULL;
2788 rtl_uString_newReplaceStrAtUtf16L( &pNew, pData, index, count, newStr.data(), newStr.size() );
2789 return OUString( pNew, SAL_NO_ACQUIRE );
2790 }
2791 // Disambiguation
2792 template <std::size_t N>
2793 SAL_WARN_UNUSED_RESULT OUString replaceAt( sal_Int32 index, sal_Int32 count, const sal_Unicode (&newStr)[N] ) const
2794 {
2795 return replaceAt(index, count, std::u16string_view(newStr, N - 1));
2796 }
2797 template <class T, std::enable_if_t<std::is_convertible_v<T, std::u16string_view>, int> = 0>
2798 SAL_WARN_UNUSED_RESULT OUString replaceAt( sal_Int32 index, sal_Int32 count, const T& newStr ) const
2799 {
2800 return replaceAt(index, count, std::u16string_view(newStr));
2801 }
2802#endif
2803
2818 {
2819 rtl_uString* pNew = NULL;
2820 rtl_uString_newReplace( &pNew, pData, oldChar, newChar );
2821 return OUString( pNew, SAL_NO_ACQUIRE );
2822 }
2823
2842#if defined LIBO_INTERNAL_ONLY
2843 [[nodiscard]] OUString replaceFirst(
2844 std::u16string_view from, std::u16string_view to, sal_Int32 * index = nullptr) const
2845 {
2846 rtl_uString * s = nullptr;
2847 sal_Int32 i = 0;
2849 &s, pData, from.data(), from.size(), to.data(), to.size(),
2850 index == nullptr ? &i : index);
2851 return OUString(s, SAL_NO_ACQUIRE);
2852 }
2853#else
2855 OUString const & from, OUString const & to, sal_Int32 * index = NULL) const
2856 {
2857 rtl_uString * s = NULL;
2858 sal_Int32 i = 0;
2860 &s, pData, from.pData, to.pData, index == NULL ? &i : index);
2861 return OUString(s, SAL_NO_ACQUIRE);
2862 }
2863#endif
2864
2883#if defined LIBO_INTERNAL_ONLY
2884 template<typename T> [[nodiscard]]
2886 T & from, std::u16string_view to, sal_Int32 * index = nullptr) const
2887 {
2889 rtl_uString * s = nullptr;
2890 sal_Int32 i = 0;
2894 index == nullptr ? &i : index);
2895 return OUString(s, SAL_NO_ACQUIRE);
2896 }
2897#else
2898 template< typename T >
2900 sal_Int32 * index = NULL) const
2901 {
2903 rtl_uString * s = NULL;
2904 sal_Int32 i = 0;
2906 &s, pData,
2909 index == NULL ? &i : index);
2910 return OUString(s, SAL_NO_ACQUIRE);
2911 }
2912#endif
2913
2932#if defined LIBO_INTERNAL_ONLY
2933 template<typename T> [[nodiscard]]
2935 std::u16string_view from, T & to, sal_Int32 * index = nullptr) const
2936 {
2938 rtl_uString * s = nullptr;
2939 sal_Int32 i = 0;
2941 &s, pData, from.data(), from.size(),
2943 libreoffice_internal::ConstCharArrayDetector<T>::length, index == nullptr ? &i : index);
2944 return OUString(s, SAL_NO_ACQUIRE);
2945 }
2946#else
2947 template< typename T >
2949 sal_Int32 * index = NULL) const
2950 {
2952 rtl_uString * s = NULL;
2953 sal_Int32 i = 0;
2955 &s, pData, from.pData,
2958 index == NULL ? &i : index);
2959 return OUString(s, SAL_NO_ACQUIRE);
2960 }
2961#endif
2962
2981 template< typename T1, typename T2 >
2998
3014#if defined LIBO_INTERNAL_ONLY
3015 [[nodiscard]] OUString replaceAll(
3016 std::u16string_view from, std::u16string_view to, sal_Int32 fromIndex = 0) const
3017 {
3018 rtl_uString * s = nullptr;
3019 rtl_uString_newReplaceAllFromIndexUtf16LUtf16L(
3020 &s, pData, from.data(), from.size(), to.data(), to.size(), fromIndex);
3021 return OUString(s, SAL_NO_ACQUIRE);
3022 }
3023#else
3025 OUString const & from, OUString const & to, sal_Int32 fromIndex = 0) const
3026 {
3027 rtl_uString * s = NULL;
3028 rtl_uString_newReplaceAllFromIndex(&s, pData, from.pData, to.pData, fromIndex);
3029 return OUString(s, SAL_NO_ACQUIRE);
3030 }
3031#endif
3032
3046#if defined LIBO_INTERNAL_ONLY
3047 template<typename T> [[nodiscard]]
3049 T & from, std::u16string_view to) const
3050 {
3052 rtl_uString * s = nullptr;
3056 return OUString(s, SAL_NO_ACQUIRE);
3057 }
3058#else
3059 template< typename T >
3070#endif
3071
3085#if defined LIBO_INTERNAL_ONLY
3086 template<typename T> [[nodiscard]]
3088 std::u16string_view from, T & to) const
3089 {
3091 rtl_uString * s = nullptr;
3093 &s, pData, from.data(), from.size(),
3096 return OUString(s, SAL_NO_ACQUIRE);
3097 }
3098#else
3099 template< typename T >
3110#endif
3111
3125 template< typename T1, typename T2 >
3140
3152 {
3153 rtl_uString* pNew = NULL;
3154 rtl_uString_newToAsciiLowerCase( &pNew, pData );
3155 return OUString( pNew, SAL_NO_ACQUIRE );
3156 }
3157
3169 {
3170 rtl_uString* pNew = NULL;
3171 rtl_uString_newToAsciiUpperCase( &pNew, pData );
3172 return OUString( pNew, SAL_NO_ACQUIRE );
3173 }
3174
3189 {
3190 rtl_uString* pNew = NULL;
3191 rtl_uString_newTrim( &pNew, pData );
3192 return OUString( pNew, SAL_NO_ACQUIRE );
3193 }
3194
3219 OUString getToken( sal_Int32 token, sal_Unicode cTok, sal_Int32& index ) const
3220 {
3221 rtl_uString * pNew = NULL;
3222 index = rtl_uString_getToken( &pNew, pData, token, cTok, index );
3223 return OUString( pNew, SAL_NO_ACQUIRE );
3224 }
3225
3239 OUString getToken(sal_Int32 count, sal_Unicode separator) const {
3240 sal_Int32 n = 0;
3241 return getToken(count, separator, n);
3242 }
3243
3252 bool toBoolean() const
3253 {
3254 return rtl_ustr_toBoolean( pData->buffer );
3255 }
3256
3264 {
3265 return pData->buffer[0];
3266 }
3267
3278 sal_Int32 toInt32( sal_Int16 radix = 10 ) const
3279 {
3280 return rtl_ustr_toInt32( pData->buffer, radix );
3281 }
3282
3295 sal_uInt32 toUInt32( sal_Int16 radix = 10 ) const
3296 {
3297 return rtl_ustr_toUInt32( pData->buffer, radix );
3298 }
3299
3310 sal_Int64 toInt64( sal_Int16 radix = 10 ) const
3311 {
3312 return rtl_ustr_toInt64( pData->buffer, radix );
3313 }
3314
3327 sal_uInt64 toUInt64( sal_Int16 radix = 10 ) const
3328 {
3329 return rtl_ustr_toUInt64( pData->buffer, radix );
3330 }
3331
3340 float toFloat() const
3341 {
3342 return rtl_ustr_toFloat( pData->buffer );
3343 }
3344
3353 double toDouble() const
3354 {
3355 return rtl_ustr_toDouble( pData->buffer );
3356 }
3357
3358
3375 {
3376 rtl_uString * pNew = NULL;
3377 rtl_uString_intern( &pNew, pData );
3378 if (pNew == NULL) {
3379 throw std::bad_alloc();
3380 }
3381 return OUString( pNew, SAL_NO_ACQUIRE );
3382 }
3383
3409 static OUString intern( const char * value, sal_Int32 length,
3410 rtl_TextEncoding encoding,
3411 sal_uInt32 convertFlags = OSTRING_TO_OUSTRING_CVTFLAGS,
3412 sal_uInt32 *pInfo = NULL )
3413 {
3414 rtl_uString * pNew = NULL;
3415 rtl_uString_internConvert( &pNew, value, length, encoding,
3416 convertFlags, pInfo );
3417 if (pNew == NULL) {
3418 throw std::bad_alloc();
3419 }
3420 return OUString( pNew, SAL_NO_ACQUIRE );
3421 }
3422
3447 bool convertToString(OString * pTarget, rtl_TextEncoding nEncoding,
3448 sal_uInt32 nFlags) const
3449 {
3450 return rtl_convertUStringToString(&pTarget->pData, pData->buffer,
3451 pData->length, nEncoding, nFlags);
3452 }
3453
3506 sal_Int32 * indexUtf16, sal_Int32 incrementCodePoints = 1) const
3507 {
3509 pData, indexUtf16, incrementCodePoints);
3510 }
3511
3521#if defined LIBO_INTERNAL_ONLY
3522 static OUString fromUtf8(std::string_view rSource)
3523 {
3524 OUString aTarget;
3525 bool bSuccess = rtl_convertStringToUString(&aTarget.pData,
3526 rSource.data(),
3527 rSource.length(),
3530 (void) bSuccess;
3531 assert(bSuccess);
3532 return aTarget;
3533 }
3534#else
3535 static OUString fromUtf8(const OString& rSource)
3536 {
3537 OUString aTarget;
3538 bool bSuccess = rtl_convertStringToUString(&aTarget.pData,
3539 rSource.getStr(),
3540 rSource.getLength(),
3543 (void) bSuccess;
3544 assert(bSuccess);
3545 return aTarget;
3546 }
3547#endif
3548
3560 {
3561 OString aTarget;
3562 bool bSuccess = rtl_convertUStringToString(&aTarget.pData,
3563 getStr(),
3564 getLength(),
3567 (void) bSuccess;
3568 assert(bSuccess);
3569 return aTarget;
3570 }
3571
3572#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
3573
3574 static auto number( int i, sal_Int16 radix = 10 )
3575 {
3576 return OUStringNumber<RTL_USTR_MAX_VALUEOFINT32>(rtl_ustr_valueOfInt32, i, radix);
3577 }
3578 static auto number( long long ll, sal_Int16 radix = 10 )
3579 {
3580 return OUStringNumber<RTL_USTR_MAX_VALUEOFINT64>(rtl_ustr_valueOfInt64, ll, radix);
3581 }
3582 static auto number( unsigned long long ll, sal_Int16 radix = 10 )
3583 {
3584 return OUStringNumber<RTL_USTR_MAX_VALUEOFUINT64>(rtl_ustr_valueOfUInt64, ll, radix);
3585 }
3586 static auto number( unsigned int i, sal_Int16 radix = 10 )
3587 {
3588 return number( static_cast< unsigned long long >( i ), radix );
3589 }
3590 static auto number( long i, sal_Int16 radix = 10)
3591 {
3592 return number( static_cast< long long >( i ), radix );
3593 }
3594 static auto number( unsigned long i, sal_Int16 radix = 10 )
3595 {
3596 return number( static_cast< unsigned long long >( i ), radix );
3597 }
3598#else
3609 static OUString number( int i, sal_Int16 radix = 10 )
3610 {
3612 return OUString(aBuf, rtl_ustr_valueOfInt32(aBuf, i, radix));
3613 }
3614
3616 static OUString number( unsigned int i, sal_Int16 radix = 10 )
3617 {
3618 return number( static_cast< unsigned long long >( i ), radix );
3619 }
3620
3622 static OUString number( long i, sal_Int16 radix = 10)
3623 {
3624 return number( static_cast< long long >( i ), radix );
3625 }
3626
3628 static OUString number( unsigned long i, sal_Int16 radix = 10 )
3629 {
3630 return number( static_cast< unsigned long long >( i ), radix );
3631 }
3632
3634 static OUString number( long long ll, sal_Int16 radix = 10 )
3635 {
3637 return OUString(aBuf, rtl_ustr_valueOfInt64(aBuf, ll, radix));
3638 }
3639
3641 static OUString number( unsigned long long ll, sal_Int16 radix = 10 )
3642 {
3644 return OUString(aBuf, rtl_ustr_valueOfUInt64(aBuf, ll, radix));
3645 }
3646#endif
3647
3657 static OUString number( float f )
3658 {
3659 rtl_uString* pNew = NULL;
3660 // Same as rtl::str::valueOfFP, used for rtl_ustr_valueOfFloat
3662 RTL_USTR_MAX_VALUEOFFLOAT - SAL_N_ELEMENTS("-x.E-xxx") + 1, '.',
3663 NULL, 0, true);
3664 if (pNew == NULL)
3665 throw std::bad_alloc();
3666
3667 return OUString(pNew, SAL_NO_ACQUIRE);
3668 }
3669
3679 static OUString number( double d )
3680 {
3681 rtl_uString* pNew = NULL;
3682 // Same as rtl::str::valueOfFP, used for rtl_ustr_valueOfDouble
3684 RTL_USTR_MAX_VALUEOFDOUBLE - SAL_N_ELEMENTS("-x.E-xxx") + 1, '.',
3685 NULL, 0, true);
3686 if (pNew == NULL)
3687 throw std::bad_alloc();
3688
3689 return OUString(pNew, SAL_NO_ACQUIRE);
3690 }
3691
3692#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
3693 static auto boolean(bool b)
3694 {
3695 return OUStringNumber<RTL_USTR_MAX_VALUEOFBOOLEAN>(rtl_ustr_valueOfBoolean, b);
3696 }
3697#else
3709 SAL_DEPRECATED("use boolean()") static OUString valueOf( sal_Bool b )
3710 {
3711 return boolean(b);
3712 }
3713
3725 static OUString boolean( bool b )
3726 {
3728 return OUString(aBuf, rtl_ustr_valueOfBoolean(aBuf, b));
3729 }
3730#endif
3731
3739 SAL_DEPRECATED("convert to OUString or use directly") static OUString valueOf( sal_Unicode c )
3740 {
3741 return OUString( &c, 1 );
3742 }
3743
3754 SAL_DEPRECATED("use number()") static OUString valueOf( sal_Int32 i, sal_Int16 radix = 10 )
3755 {
3756 return number( i, radix );
3757 }
3758
3769 SAL_DEPRECATED("use number()") static OUString valueOf( sal_Int64 ll, sal_Int16 radix = 10 )
3770 {
3771 return number( ll, radix );
3772 }
3773
3783 SAL_DEPRECATED("use number()") static OUString valueOf( float f )
3784 {
3785 return number(f);
3786 }
3787
3797 SAL_DEPRECATED("use number()") static OUString valueOf( double d )
3798 {
3799 return number(d);
3800 }
3801
3817 static OUString createFromAscii( const char * value )
3818 {
3819 rtl_uString* pNew = NULL;
3820 rtl_uString_newFromAscii( &pNew, value );
3821 return OUString( pNew, SAL_NO_ACQUIRE );
3822 }
3823
3824#if defined LIBO_INTERNAL_ONLY
3825 static OUString createFromAscii(std::string_view value) {
3826 rtl_uString * p = nullptr;
3827 rtl_uString_newFromLiteral(&p, value.data(), value.size(), 0); //TODO: check for overflow
3828 return OUString(p, SAL_NO_ACQUIRE);
3829 }
3830 #endif
3831
3832#if defined LIBO_INTERNAL_ONLY
3833 operator std::u16string_view() const { return {getStr(), sal_uInt32(getLength())}; }
3834#endif
3835
3836#if defined LIBO_INTERNAL_ONLY
3837 // A wrapper for the first expression in an
3838 //
3839 // OUString::Concat(e1) + e2 + ...
3840 //
3841 // concatenation chain, when neither of the first two e1, e2 is one of our rtl string-related
3842 // classes (so something like
3843 //
3844 // OUString s = "a" + (b ? std::u16string_view(u"c") : std::u16string_view(u"dd"));
3845 //
3846 // would not compile):
3847 template<typename T> [[nodiscard]] static
3848 OUStringConcat<OUStringConcatMarker, T>
3849 Concat(T const & value) { return OUStringConcat<OUStringConcatMarker, T>(value); }
3850
3851 // This overload is needed so that an argument of type 'char const[N]' ends up as
3852 // 'OUStringConcat<rtl::OUStringConcatMarker, char const[N]>' rather than as
3853 // 'OUStringConcat<rtl::OUStringConcatMarker, char[N]>':
3854 template<typename T, std::size_t N> [[nodiscard]] static
3855 OUStringConcat<OUStringConcatMarker, T[N]>
3856 Concat(T (& value)[N]) { return OUStringConcat<OUStringConcatMarker, T[N]>(value); }
3857#endif
3858
3859private:
3860 OUString & internalAppend( rtl_uString* pOtherData )
3861 {
3862 rtl_uString* pNewData = NULL;
3863 rtl_uString_newConcat( &pNewData, pData, pOtherData );
3864 if (pNewData == NULL) {
3865 throw std::bad_alloc();
3866 }
3867 rtl_uString_assign(&pData, pNewData);
3868 rtl_uString_release(pNewData);
3869 return *this;
3870 }
3871
3872#if defined LIBO_INTERNAL_ONLY
3873 static constexpr auto empty = OUStringLiteral(u""); // [-loplugin:ostr]
3874#endif
3875};
3876
3877#if defined LIBO_INTERNAL_ONLY
3878// Prevent the operator ==/!= overloads with 'sal_Unicode const *' parameter from
3879// being selected for nonsensical code like
3880//
3881// if (ouIdAttr == nullptr)
3882//
3883void operator ==(OUString const &, std::nullptr_t) = delete;
3884void operator ==(std::nullptr_t, OUString const &) = delete;
3885void operator !=(OUString const &, std::nullptr_t) = delete;
3886void operator !=(std::nullptr_t, OUString const &) = delete;
3887#endif
3888
3889#if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST
3890inline bool operator ==(OUString const & lhs, StringConcatenation<char16_t> const & rhs)
3891{ return lhs == std::u16string_view(rhs); }
3892inline bool operator !=(OUString const & lhs, StringConcatenation<char16_t> const & rhs)
3893{ return lhs != std::u16string_view(rhs); }
3894inline bool operator ==(StringConcatenation<char16_t> const & lhs, OUString const & rhs)
3895{ return std::u16string_view(lhs) == rhs; }
3896inline bool operator !=(StringConcatenation<char16_t> const & lhs, OUString const & rhs)
3897{ return std::u16string_view(lhs) != rhs; }
3898#endif
3899
3900#if defined LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
3902
3906template<>
3907struct ToStringHelper< OUString >
3908{
3909 static std::size_t length( const OUString& s ) { return s.getLength(); }
3910 sal_Unicode* operator() ( sal_Unicode* buffer, const OUString& s ) const { return addDataHelper( buffer, s.getStr(), s.getLength()); }
3911};
3912
3916template<std::size_t N>
3917struct ToStringHelper< OUStringLiteral<N> >
3918{
3919 static std::size_t length( const OUStringLiteral<N>& str ) { return str.getLength(); }
3920 sal_Unicode* operator()( sal_Unicode* buffer, const OUStringLiteral<N>& str ) const { return addDataHelper( buffer, str.getStr(), str.getLength() ); }
3921};
3922
3926template< typename charT, typename traits, typename T1, typename T2 >
3927inline std::basic_ostream<charT, traits> & operator <<(
3928 std::basic_ostream<charT, traits> & stream, OUStringConcat< T1, T2 >&& concat)
3929{
3930 return stream << OUString( std::move(concat) );
3931}
3932
3934#endif
3935
3942{
3952 size_t operator()(const OUString& rString) const
3953 { return static_cast<size_t>(rString.hashCode()); }
3954};
3955
3956/* ======================================================================= */
3957
3975#if defined LIBO_INTERNAL_ONLY
3976inline OUString OStringToOUString( std::string_view rStr,
3977 rtl_TextEncoding encoding,
3978 sal_uInt32 convertFlags = OSTRING_TO_OUSTRING_CVTFLAGS )
3979{
3980 return OUString( rStr.data(), rStr.length(), encoding, convertFlags );
3981}
3982#else
3984 rtl_TextEncoding encoding,
3985 sal_uInt32 convertFlags = OSTRING_TO_OUSTRING_CVTFLAGS )
3986{
3987 return OUString( rStr.getStr(), rStr.getLength(), encoding, convertFlags );
3988}
3989#endif
3990
4008#if defined LIBO_INTERNAL_ONLY
4009inline OString OUStringToOString( std::u16string_view rUnicode,
4010 rtl_TextEncoding encoding,
4011 sal_uInt32 convertFlags = OUSTRING_TO_OSTRING_CVTFLAGS )
4012{
4013 return OString( rUnicode.data(), rUnicode.length(), encoding, convertFlags );
4014}
4015#else
4016inline OString OUStringToOString( const OUString & rUnicode,
4017 rtl_TextEncoding encoding,
4018 sal_uInt32 convertFlags = OUSTRING_TO_OSTRING_CVTFLAGS )
4019{
4020 return OString( rUnicode.getStr(), rUnicode.getLength(), encoding, convertFlags );
4021}
4022#endif
4023
4024/* ======================================================================= */
4025
4034template< typename charT, typename traits >
4035inline std::basic_ostream<charT, traits> & operator <<(
4036 std::basic_ostream<charT, traits> & stream, OUString const & rString)
4037{
4038 return stream <<
4040 // best effort; potentially loses data due to conversion failures
4041 // (stray surrogate halves) and embedded null characters
4042}
4043
4044} // namespace
4045
4046#ifdef RTL_STRING_UNITTEST
4047namespace rtl
4048{
4049typedef rtlunittest::OUString OUString;
4050}
4051#endif
4052
4053// In internal code, allow to use classes like OUString without having to
4054// explicitly refer to the rtl namespace, which is kind of superfluous given
4055// that OUString itself is namespaced by its OU prefix:
4056#if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST
4057using ::rtl::OUString;
4058using ::rtl::OUStringHash;
4061using ::rtl::OUStringLiteral;
4062using ::rtl::OUStringChar;
4063using ::rtl::Concat2View;
4064using RepeatedUChar = ::rtl::RepeatedChar_t<sal_Unicode>;
4065#endif
4066
4067#if defined LIBO_INTERNAL_ONLY
4068
4069template<
4070#if defined RTL_STRING_UNITTEST
4071 rtlunittest::
4072#endif
4073 OUStringLiteral L>
4074constexpr
4075#if defined RTL_STRING_UNITTEST
4076 rtlunittest::
4077#endif
4078 OUString
4079operator ""_ustr() { return L; }
4080
4081#endif
4082
4084
4089#if defined LIBO_INTERNAL_ONLY
4090namespace std {
4091
4092template<>
4093struct hash<::rtl::OUString>
4094{
4095 std::size_t operator()(::rtl::OUString const & s) const
4096 {
4097 if constexpr (sizeof(std::size_t) == 8)
4098 {
4099 // return a hash that uses the full 64-bit range instead of a 32-bit value
4100 size_t n = s.getLength();
4101 for (sal_Int32 i = 0, len = s.getLength(); i < len; ++i)
4102 n = 37 * n + s[i];
4103 return n;
4104 }
4105 else
4106 return std::size_t(s.hashCode());
4107 }
4108};
4109
4110}
4111
4118static inline constexpr ::rtl::OUString EMPTY_OUSTRING = u""_ustr;
4119
4120#endif
4122
4123#endif /* _RTL_USTRING_HXX */
4124
4125/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define SAL_DEPRECATED(message)
Use as follows: SAL_DEPRECATED("Don't use, it's evil.") void doit(int nPara);.
Definition types.h:492
__sal_NoAcquire
Definition types.h:371
@ SAL_NO_ACQUIRE
definition of a no acquire enum for ctors
Definition types.h:374
unsigned char sal_Bool
Definition types.h:38
#define SAL_CONSTEXPR
C++11 "constexpr" feature.
Definition types.h:422
sal_uInt16 sal_Unicode
Definition types.h:123
#define SAL_WARN_UNUSED_RESULT
Use this as markup for functions and methods whose return value must be used.
Definition types.h:288
#define SAL_WARN_UNUSED
Annotate classes where a compiler should warn if an instance is unused.
Definition types.h:611
#define SAL_N_ELEMENTS(arr)
Definition macros.h:51
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 void rtl_uString_assign(rtl_uString **str, rtl_uString *rightValue) SAL_THROW_EXTERN_C()
Assign a new value to a string.
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 float rtl_ustr_toFloat(const sal_Unicode *str) SAL_THROW_EXTERN_C()
Interpret a string as a float.
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.
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
#define RTL_USTR_MAX_VALUEOFFLOAT
Definition ustring.h:1026
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.
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_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_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 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_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.
#define RTL_USTR_MAX_VALUEOFDOUBLE
Definition ustring.h:1045
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_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 void rtl_uString_newFromLiteral(rtl_uString **newStr, const char *value, sal_Int32 len, sal_Int32 allocExtra) SAL_THROW_EXTERN_C()
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.
SAL_DLLPUBLIC sal_Int32 rtl_ustr_valueOfBoolean(sal_Unicode *str, sal_Bool b) SAL_THROW_EXTERN_C()
Create the string representation of a boolean.
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_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 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.
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.
#define RTL_USTR_MAX_VALUEOFINT64
Definition ustring.h:984
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.
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.
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_DLLPUBLIC void rtl_uString_acquire(rtl_uString *str) SAL_THROW_EXTERN_C() SAL_HOT
Increment the reference count of a string.
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.
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.
#define RTL_USTR_MAX_VALUEOFUINT64
Definition ustring.h:1007
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.
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.
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.
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 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 void rtl_uString_release(rtl_uString *str) SAL_THROW_EXTERN_C() SAL_HOT
Decrement the reference count of a string.
SAL_DLLPUBLIC sal_Int32 rtl_ustr_getLength(const sal_Unicode *str) SAL_THROW_EXTERN_C()
Return the length of a string.
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_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_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 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_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.
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.
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.
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.
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.
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.
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.
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.
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_DLLPUBLIC void rtl_uString_intern(rtl_uString **newStr, rtl_uString *str) SAL_THROW_EXTERN_C()
Return a canonical representation for a string.
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 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_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_Int32 rtl_ustr_ascii_compare_WithLength(const sal_Unicode *first, sal_Int32 firstLen, const char *second) SAL_THROW_EXTERN_C()
Compare two strings.
#define RTL_USTR_MAX_VALUEOFBOOLEAN
Definition ustring.h:919
SAL_DLLPUBLIC sal_Int32 rtl_ustr_toInt32(const sal_Unicode *str, sal_Int16 radix) SAL_THROW_EXTERN_C()
Interpret a string as an integer.
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_valueOfUInt64(sal_Unicode *str, sal_uInt64 l, sal_Int16 radix) SAL_THROW_EXTERN_C()
Create the string representation of an unsigned long integer.
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.
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.
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.
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_valueOfInt32(sal_Unicode *str, sal_Int32 i, sal_Int16 radix) SAL_THROW_EXTERN_C()
Create the string representation of an integer.
SAL_DLLPUBLIC sal_Bool rtl_ustr_toBoolean(const sal_Unicode *str) SAL_THROW_EXTERN_C()
Interpret a string as a boolean.
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.
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.
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_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.
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.
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_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.
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.
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.
#define RTL_USTR_MAX_VALUEOFINT32
Definition ustring.h:961
#define RTL_TEXTENCODING_UTF8
Definition textenc.h:117
sal_uInt16 rtl_TextEncoding
The various supported text encodings.
Definition textenc.h:37
#define RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR
Definition textcvt.h:151
#define RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR
Definition textcvt.h:75
#define RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR
Definition textcvt.h:72
#define RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR
Definition textcvt.h:68
#define RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR
Definition textcvt.h:145
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.
#define OUSTRING_TO_OSTRING_CVTFLAGS
Definition string.h:1350
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.
@ rtl_math_StringFormat_G
Like sprintf() G, 'F' or 'E' format is used depending on which one is more compact.
Definition math.h:53
sal_Int32 oslInterlockedCount
Definition interlck.h:44
Definition bootstrap.hxx:34
std::basic_ostream< charT, traits > & operator<<(std::basic_ostream< charT, traits > &stream, OString const &rString)
Support for rtl::OString in std::ostream (and thus in CPPUNIT_ASSERT or SAL_INFO macros,...
Definition string.hxx:2826
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:3983
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:4016
Definition stringutils.hxx:119
This String class provide base functionality for C++ like 8-Bit character array handling.
Definition string.hxx:189
const char * getStr() const SAL_RETURNS_NONNULL
Returns a pointer to the characters of this string.
Definition string.hxx:689
sal_Int32 getLength() const
Returns the length of this string.
Definition string.hxx:663
Definition stringutils.hxx:178
Definition stringutils.hxx:181
A string buffer implements a mutable sequence of characters.
Definition ustrbuf.hxx:73
This String class provides base functionality for C++ like Unicode character array handling.
Definition ustring.hxx:168
static OUString number(int i, sal_Int16 radix=10)
Returns the string representation of the integer argument.
Definition ustring.hxx:3609
OUString intern() const
Return a canonical representation for a string.
Definition ustring.hxx:3374
libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type indexOf(T &literal, sal_Int32 fromIndex=0) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition ustring.hxx:2516
bool startsWith(sal_Unicode ch) const
Check whether this string starts with a given character.
Definition ustring.hxx:1626
bool startsWith(sal_Unicode ch, OUString *rest) const
Check whether this string starts with a given character.
Definition ustring.hxx:1643
bool endsWith(OUString const &str, OUString *rest=NULL) const
Check whether this string ends with a given substring.
Definition ustring.hxx:1874
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:2222
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:3151
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:3060
const sal_Unicode * getStr() const SAL_RETURNS_NONNULL
Returns a pointer to the Unicode character buffer for this string.
Definition ustring.hxx:841
bool equalsIgnoreAsciiCase(const OUString &str) const
Perform an ASCII lowercase comparison of two strings.
Definition ustring.hxx:1001
bool endsWithAsciiL(char const *asciiStr, sal_Int32 asciiStrLength) const
Check whether this string ends with a given ASCII string.
Definition ustring.hxx:2037
OUString(const OUString &str)
New string from OUString.
Definition ustring.hxx:197
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:3505
static OUString fromUtf8(const OString &rSource)
Convert an OString to an OUString, assuming that the OString is UTF-8-encoded.
Definition ustring.hxx:3535
libreoffice_internal::ConstCharArrayDetector< T, bool >::Type match(T &literal, sal_Int32 fromIndex=0) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition ustring.hxx:1099
sal_Int32 toInt32(sal_Int16 radix=10) const
Returns the int32 value from this string.
Definition ustring.hxx:3278
void clear()
Clears the string, i.e, makes a zero-character string.
Definition ustring.hxx:806
bool equalsIgnoreAsciiCaseAsciiL(const char *asciiStr, sal_Int32 asciiStrLength) const
Perform an ASCII lowercase comparison of two strings.
Definition ustring.hxx:1372
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:3641
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:2551
SAL_WARN_UNUSED_RESULT libreoffice_internal::ConstCharArrayDetector< T1, typenamelibreoffice_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:3127
~OUString()
Release the string data.
Definition ustring.hxx:532
sal_Int32 compareTo(const OUString &str, sal_Int32 maxLength) const
Compares two strings with a maximum count of characters.
Definition ustring.hxx:906
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:2660
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,...
Definition ustring.hxx:2440
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:3100
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:3634
bool matchAsciiL(const char *asciiStr, sal_Int32 asciiStrLength, sal_Int32 fromIndex=0) const
Match against a substring appearing in this string.
Definition ustring.hxx:1400
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:3024
float toFloat() const
Returns the float value from this string.
Definition ustring.hxx:3340
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:3628
static OUString createFromAscii(const char *value)
Returns an OUString copied without conversion from an ASCII character string.
Definition ustring.hxx:3817
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:2899
SAL_WARN_UNUSED_RESULT libreoffice_internal::ConstCharArrayDetector< T1, typenamelibreoffice_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:2983
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:2817
sal_Int32 hashCode() const
Returns a hashcode for this string.
Definition ustring.hxx:2422
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 o...
Definition ustring.hxx:944
friend libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator==(T &literal, const OUString &rString)
Compare string to an ASCII string literal.
Definition ustring.hxx:2327
friend libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator==(const OUString &rString, T &literal)
Compare string to an ASCII string literal.
Definition ustring.hxx:2311
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:3622
libreoffice_internal::ConstCharArrayDetector< T, bool >::Type equalsIgnoreAsciiCase(T &literal) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition ustring.hxx:1046
sal_uInt64 toUInt64(sal_Int16 radix=10) const
Returns the uint64 value from this string.
Definition ustring.hxx:3327
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:1438
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 o...
Definition ustring.hxx:1794
OString toUtf8() const
Convert this string to an OString, assuming that the string can be UTF-8-encoded successfully.
Definition ustring.hxx:3559
sal_Int32 reverseCompareToAsciiL(const char *asciiStr, sal_Int32 asciiStrLength) const
Compares two strings in reverse order.
Definition ustring.hxx:1234
bool equalsAsciiL(const char *asciiStr, sal_Int32 asciiStrLength) const
Perform a comparison of two strings.
Definition ustring.hxx:1277
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:3616
bool endsWith(sal_Unicode ch) const
Check whether this string ends with a given character.
Definition ustring.hxx:1893
bool convertToString(OString *pTarget, rtl_TextEncoding nEncoding, sal_uInt32 nFlags) const
Converts to an OString, signalling failure.
Definition ustring.hxx:3447
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 o...
Definition ustring.hxx:1596
OUString(rtl_uString *str)
New string from OUString data.
Definition ustring.hxx:245
OUString(const sal_Unicode *value, sal_Int32 length)
New string from a Unicode character buffer array.
Definition ustring.hxx:331
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:2126
sal_Int32 compareTo(const OUString &str) const
Compares two strings.
Definition ustring.hxx:877
friend libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator!=(const OUString &rString, T &literal)
Compare string to an ASCII string literal.
Definition ustring.hxx:2343
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:617
bool startsWith(OUString const &str, OUString *rest=NULL) const
Check whether this string starts with a given substring.
Definition ustring.hxx:1526
sal_Int32 lastIndexOf(sal_Unicode ch) const
Returns the index within this string of the last occurrence of the specified character,...
Definition ustring.hxx:2456
sal_Int32 compareToIgnoreAsciiCaseAscii(const char *asciiStr) const
Compares two ASCII strings ignoring case.
Definition ustring.hxx:1336
bool endsWith(sal_Unicode ch, OUString *rest) const
Check whether this string ends with a given character.
Definition ustring.hxx:1910
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:2948
OUString(sal_Unicode value)
New string from a single Unicode character.
Definition ustring.hxx:274
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:2854
sal_Int64 toInt64(sal_Int16 radix=10) const
Returns the int64 value from this string.
Definition ustring.hxx:3310
sal_uInt32 toUInt32(sal_Int16 radix=10) const
Returns the uint32 value from this string.
Definition ustring.hxx:3295
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:1718
sal_Int32 lastIndexOf(const OUString &str, sal_Int32 fromIndex) const
Returns the index within this string of the last occurrence of the specified substring,...
Definition ustring.hxx:2618
static OUString const & unacquired(rtl_uString *const *ppHandle)
Provides an OUString const & passing a storage pointer of an rtl_uString * handle.
Definition ustring.hxx:558
double toDouble() const
Returns the double value from this string.
Definition ustring.hxx:3353
bool equalsAscii(const char *asciiStr) const
Perform a comparison of two strings.
Definition ustring.hxx:1255
libreoffice_internal::ConstCharArrayDetector< T, bool >::Type matchIgnoreAsciiCase(T &literal, sal_Int32 fromIndex=0) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition ustring.hxx:1156
OUString getToken(sal_Int32 token, sal_Unicode cTok, sal_Int32 &index) const
Returns a token in the string.
Definition ustring.hxx:3219
sal_Int32 getLength() const
Returns the length of this string.
Definition ustring.hxx:819
bool equalsIgnoreAsciiCaseAscii(const char *asciiStr) const
Perform an ASCII lowercase comparison of two strings.
Definition ustring.hxx:1304
OUString()
New string containing no characters.
Definition ustring.hxx:180
OUString(const sal_Unicode *value)
New string from a Unicode character buffer array.
Definition ustring.hxx:315
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:451
OUString & operator=(const OUString &str)
Assign a new string.
Definition ustring.hxx:582
static OUString number(float f)
Returns the string representation of the float argument.
Definition ustring.hxx:3657
static OUString valueOf(sal_Bool b)
Returns the string representation of the sal_Bool argument.
Definition ustring.hxx:3709
bool isEmpty() const
Checks if a string is empty.
Definition ustring.hxx:829
sal_Int32 compareToIgnoreAsciiCase(const OUString &str) const
Perform an ASCII lowercase comparison of two strings.
Definition ustring.hxx:1033
OUString(sal_uInt32 const *codePoints, sal_Int32 codePointCount)
Create a new string from an array of Unicode code points.
Definition ustring.hxx:478
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 o...
Definition ustring.hxx:2003
OUString & operator+=(const OUString &str)
Append a string to this string.
Definition ustring.hxx:690
sal_Unicode toChar() const
Returns the first character from this string.
Definition ustring.hxx:3263
OUString getToken(sal_Int32 count, sal_Unicode separator) const
Returns a token from the string.
Definition ustring.hxx:3239
static OUString boolean(bool b)
Returns the string representation of the boolean argument.
Definition ustring.hxx:3725
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 o...
Definition ustring.hxx:2631
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:2693
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 o...
Definition ustring.hxx:2187
OUString(rtl_uString *str, __sal_NoAcquire)
New OUString from OUString data without acquiring it.
Definition ustring.hxx:266
sal_Int32 lastIndexOf(sal_Unicode ch, sal_Int32 fromIndex) const
Returns the index within this string of the last occurrence of the specified character,...
Definition ustring.hxx:2473
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:3188
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:3168
SAL_WARN_UNUSED_RESULT OUString concat(const OUString &str) const
Concatenates the specified string to the end of this string.
Definition ustring.hxx:2749
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:2777
bool match(const OUString &str, sal_Int32 fromIndex=0) const
Match against a substring appearing in this string.
Definition ustring.hxx:1085
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:1141
sal_Int32 compareToAscii(const char *asciiStr) const
Compares two strings.
Definition ustring.hxx:1181
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:353
sal_Int32 reverseCompareTo(const OUString &str) const
Compares two strings in reverse order.
Definition ustring.hxx:931
static OUString number(double d)
Returns the string representation of the double argument.
Definition ustring.hxx:3679
friend OUString operator+(const OUString &rStr1, const OUString &rStr2)
Definition ustring.hxx:2758
SAL_WARN_UNUSED_RESULT OUString copy(sal_Int32 beginIndex) const
Returns a new string that is a substring of this string.
Definition ustring.hxx:2676
friend libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator!=(T &literal, const OUString &rString)
Compare string to an ASCII string literal.
Definition ustring.hxx:2359
bool equals(const OUString &str) const
Perform a comparison of two strings.
Definition ustring.hxx:965
sal_Int32 lastIndexOf(const OUString &str) const
Returns the index within this string of the last occurrence of the specified substring,...
Definition ustring.hxx:2589
bool toBoolean() const
Returns the Boolean value from this string.
Definition ustring.hxx:3252
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,...
Definition ustring.hxx:2501
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:3409
A helper to use OUStrings with hash maps.
Definition ustring.hxx:3942
size_t operator()(const OUString &rString) const
Compute a hash code for a string.
Definition ustring.hxx:3952