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 && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
178 constexpr
179#endif
181 {
182#if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
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 && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
195 constexpr
196#endif
197 OUString( const OUString & str )
198 {
199 pData = str.pData;
200#if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
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#if !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
222 constexpr
223#endif
224 OUString( OUString && str ) noexcept
225 {
226 pData = str.pData;
227#if !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
228 if (std::is_constant_evaluated()) {
229 //TODO: We would want to
230 //
231 // assert(SAL_STRING_IS_STATIC(pData));
232 //
233 // here, but that wouldn't work because read of member `str` of OUStringLiteral's
234 // anonymous union with active member `more` is not allowed in a constant expression.
235 return;
236 }
237#endif
238 str.pData = nullptr;
239 rtl_uString_new( &str.pData );
240 }
241#endif
242#endif
243
249 OUString( rtl_uString * str )
250 {
251 pData = str;
252 rtl_uString_acquire( pData );
253 }
254
255#if defined LIBO_INTERNAL_ONLY
257 // Catch inadvertent conversions to the above ctor:
258 OUString(std::nullptr_t) = delete;
260#endif
261
270 OUString( rtl_uString * str, __sal_NoAcquire )
271 { pData = str; }
272
278 explicit OUString( sal_Unicode value )
279 : pData (NULL)
280 {
281 rtl_uString_newFromStr_WithLength( &pData, &value, 1 );
282 }
283
284#if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST_CONCAT
286 // Catch inadvertent conversions to the above ctor (but still allow
287 // construction from char literals):
288 OUString(int) = delete;
289 explicit OUString(char c):
290 OUString(sal_Unicode(static_cast<unsigned char>(c)))
291 {}
293#endif
294
295#if defined LIBO_INTERNAL_ONLY
296
297 template<typename T> explicit OUString(
298 T const & value,
299 typename libreoffice_internal::CharPtrDetector<T, libreoffice_internal::Dummy>::TypeUtf16
300 = libreoffice_internal::Dummy()):
301 pData(nullptr)
302 { rtl_uString_newFromStr(&pData, value); }
303
304 template<typename T> explicit OUString(
305 T & value,
306 typename
307 libreoffice_internal::NonConstCharArrayDetector<T, libreoffice_internal::Dummy>::TypeUtf16
308 = libreoffice_internal::Dummy()):
309 pData(nullptr)
310 { rtl_uString_newFromStr(&pData, value); }
311
312#else
313
319 OUString( const sal_Unicode * value )
320 {
321 pData = NULL;
322 rtl_uString_newFromStr( &pData, value );
323 }
324
325#endif
326
335 OUString( const sal_Unicode * value, sal_Int32 length )
336 {
337 pData = NULL;
338 rtl_uString_newFromStr_WithLength( &pData, value, length );
339 }
340
356 template< typename T >
358 {
359 assert(
361 pData = NULL;
363 rtl_uString_new(&pData);
364 } else {
366 &pData,
368 literal),
370 }
371#ifdef RTL_STRING_UNITTEST
372 rtl_string_unittest_const_literal = true;
373#endif
374 }
375
376#if defined LIBO_INTERNAL_ONLY
377 // Rather use a u""_ustr literal (but don't remove this entirely, to avoid implicit support for
378 // it via std::u16string_view from kicking in):
379 template<typename T> OUString(
380 T &,
382 T, libreoffice_internal::Dummy>::TypeUtf16
383 = libreoffice_internal::Dummy()) = delete;
384
385 OUString(OUStringChar c): pData(nullptr) { rtl_uString_newFromStr_WithLength(&pData, &c.c, 1); }
386#endif
387
388#if defined LIBO_INTERNAL_ONLY && defined RTL_STRING_UNITTEST
390
394 template< typename T >
395 OUString( T&, typename libreoffice_internal::ExceptConstCharArrayDetector< T >::Type = libreoffice_internal::Dummy() )
396 {
397 pData = NULL;
398 rtl_uString_newFromLiteral( &pData, "!!br0ken!!", 10, 0 ); // set to garbage
399 rtl_string_unittest_invalid_conversion = true;
400 }
405 template< typename T >
406 OUString( const T&, typename libreoffice_internal::ExceptCharArrayDetector< T >::Type = libreoffice_internal::Dummy() )
407 {
408 pData = NULL;
409 rtl_uString_newFromLiteral( &pData, "!!br0ken!!", 10, 0 ); // set to garbage
410 rtl_string_unittest_invalid_conversion = true;
411 }
413#endif
414
415#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
417
422 template<std::size_t N> constexpr OUString(OUStringLiteral<N> const & literal):
423 pData(const_cast<rtl_uString *>(&literal.str)) {}
424 template<std::size_t N> OUString(OUStringLiteral<N> &&) = delete;
426#endif
427
428#if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
429 // For operator ""_tstr:
430 template<OStringLiteral L> OUString(detail::OStringHolder<L> const & holder) {
431 pData = nullptr;
432 if (holder.literal.getLength() == 0) {
433 rtl_uString_new(&pData);
434 } else {
436 &pData, holder.literal.getStr(), holder.literal.getLength(), 0);
437 }
438 }
439#endif
440
455 OUString( const char * value, sal_Int32 length,
456 rtl_TextEncoding encoding,
457 sal_uInt32 convertFlags = OSTRING_TO_OUSTRING_CVTFLAGS )
458 {
459 pData = NULL;
460 rtl_string2UString( &pData, value, length, encoding, convertFlags );
461 if (pData == NULL) {
462 throw std::bad_alloc();
463 }
464 }
465
482 explicit OUString(
483 sal_uInt32 const * codePoints, sal_Int32 codePointCount):
484 pData(NULL)
485 {
486 rtl_uString_newFromCodePoints(&pData, codePoints, codePointCount);
487 if (pData == NULL) {
488 throw std::bad_alloc();
489 }
490 }
491
492#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
497 template< typename T1, typename T2 >
498 OUString( OUStringConcat< T1, T2 >&& c )
499 {
500 const sal_Int32 l = c.length();
501 pData = rtl_uString_alloc( l );
502 if (l != 0)
503 {
504 sal_Unicode* end = c.addData( pData->buffer );
505 pData->length = l;
506 *end = '\0';
507 }
508 }
509
514 template< std::size_t N >
515 OUString( OUStringNumber< N >&& n )
516 : OUString( n.buf, n.length )
517 {}
518#endif
519
520#if defined LIBO_INTERNAL_ONLY
521 explicit OUString(std::u16string_view sv) {
522 if (sv.size() > sal_uInt32(std::numeric_limits<sal_Int32>::max())) {
523 throw std::bad_alloc();
524 }
525 pData = nullptr;
526 rtl_uString_newFromStr_WithLength(&pData, sv.data(), sv.size());
527 }
528#endif
529
533#if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
534 constexpr
535#endif
537 {
538#if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
539 if (std::is_constant_evaluated()) {
540 //TODO: We would want to
541 //
542 // assert(SAL_STRING_IS_STATIC(pData));
543 //
544 // here, but that wouldn't work because read of member `str` of OUStringLiteral's
545 // anonymous union with active member `more` is not allowed in a constant expression.
546 } else
547#endif
548 rtl_uString_release( pData );
549 }
550
562 static OUString const & unacquired( rtl_uString * const * ppHandle )
563 { return * reinterpret_cast< OUString const * >( ppHandle ); }
564
565#if defined LIBO_INTERNAL_ONLY
578 static OUString const& unacquired(const OUStringBuffer& str);
579#endif
580
586 OUString & operator=( const OUString & str )
587 {
588 rtl_uString_assign( &pData, str.pData );
589 return *this;
590 }
591
592#if defined LIBO_INTERNAL_ONLY
593#if !defined(__COVERITY__) // suppress COPY_INSTEAD_OF_MOVE suggestions
600 OUString & operator=( OUString && str ) noexcept
601 {
602 std::swap(pData, str.pData);
603 return *this;
604 }
605#endif
606#endif
607
620 template< typename T >
636
637#if defined LIBO_INTERNAL_ONLY
638 // Rather assign from a u""_ustr literal (but don't remove this entirely, to avoid implicit
639 // support for it via std::u16string_view from kicking in):
640 template<typename T>
641 typename
643 operator =(T &) = delete;
644
645 OUString & operator =(OUStringChar c) {
646 rtl_uString_newFromStr_WithLength(&pData, &c.c, 1);
647 return *this;
648 }
649
651 template<std::size_t N> OUString & operator =(OUStringLiteral<N> const & literal) {
652 rtl_uString_release(pData);
653 pData = const_cast<rtl_uString *>(&literal.str);
654 return *this;
655 }
656 template<std::size_t N> OUString & operator =(OUStringLiteral<N> &&) = delete;
657
658 template <std::size_t N>
659 OUString & operator =(OUStringNumber<N> && n) {
660 // n.length should never be zero, so no need to add an optimization for that case
661 rtl_uString_newFromStr_WithLength(&pData, n.buf, n.length);
662 return *this;
663 }
664
665 OUString & operator =(std::u16string_view sv) {
666 if (sv.empty()) {
667 rtl_uString_new(&pData);
668 } else {
669 rtl_uString_newFromStr_WithLength(&pData, sv.data(), sv.size());
670 }
671 return *this;
672 }
673#endif
674
675#if defined LIBO_INTERNAL_ONLY
684 inline OUString & operator+=( const OUStringBuffer & str ) &;
685#endif
686
694 OUString & operator+=( const OUString & str )
695#if defined LIBO_INTERNAL_ONLY
696 &
697#endif
698 {
699 return internalAppend(str.pData);
700 }
701#if defined LIBO_INTERNAL_ONLY
702 void operator+=(OUString const &) && = delete;
703#endif
704
711 template<typename T>
713 operator +=(T & literal)
714#if defined LIBO_INTERNAL_ONLY
715 &
716#endif
717 {
718 assert(
721 &pData, pData,
724 return *this;
725 }
726#if defined LIBO_INTERNAL_ONLY
727 template<typename T>
729 operator +=(T &) && = delete;
730#endif
731
732#if defined LIBO_INTERNAL_ONLY
734 template<typename T>
735 typename
737 operator +=(T & literal) & {
739 &pData, pData,
742 return *this;
743 }
744 template<typename T>
745 typename
746 libreoffice_internal::ConstCharArrayDetector<T, OUString &>::TypeUtf16
747 operator +=(T &) && = delete;
748
750 template<std::size_t N> OUString & operator +=(OUStringLiteral<N> const & literal) & {
751 rtl_uString_newConcatUtf16L(&pData, pData, literal.getStr(), literal.getLength());
752 return *this;
753 }
754 template<std::size_t N> void operator +=(OUStringLiteral<N> const &) && = delete;
755
756 OUString & operator +=(std::u16string_view sv) & {
757 if (sv.size() > sal_uInt32(std::numeric_limits<sal_Int32>::max())) {
758 throw std::bad_alloc();
759 }
760 rtl_uString_newConcatUtf16L(&pData, pData, sv.data(), sv.size());
761 return *this;
762 }
763 void operator +=(std::u16string_view) && = delete;
764#endif
765
766#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
771 template< typename T1, typename T2 >
772 OUString& operator+=( OUStringConcat< T1, T2 >&& c ) & {
773 sal_Int32 l = c.length();
774 if( l == 0 )
775 return *this;
776 l += pData->length;
777 rtl_uString_ensureCapacity( &pData, l );
778 sal_Unicode* end = c.addData( pData->buffer + pData->length );
779 *end = '\0';
780 pData->length = l;
781 return *this;
782 }
783 template<typename T1, typename T2> void operator +=(
784 OUStringConcat<T1, T2> &&) && = delete;
785
790 template< std::size_t N >
791 OUString& operator+=( OUStringNumber< N >&& n ) & {
792 sal_Int32 l = n.length;
793 if( l == 0 )
794 return *this;
795 l += pData->length;
796 rtl_uString_ensureCapacity( &pData, l );
797 sal_Unicode* end = addDataHelper( pData->buffer + pData->length, n.buf, n.length );
798 *end = '\0';
799 pData->length = l;
800 return *this;
801 }
802 template<std::size_t N> void operator +=(
803 OUStringNumber<N> &&) && = delete;
804#endif
805
810 void clear()
811 {
812 rtl_uString_new( &pData );
813 }
814
823 sal_Int32 getLength() const { return pData->length; }
824
833 bool isEmpty() const
834 {
835 return pData->length == 0;
836 }
837
845 const sal_Unicode * getStr() const SAL_RETURNS_NONNULL { return pData->buffer; }
846
856 sal_Unicode operator [](sal_Int32 index) const {
857 // silence spurious -Werror=strict-overflow warnings from GCC 4.8.2
858 assert(index >= 0 && static_cast<sal_uInt32>(index) < static_cast<sal_uInt32>(getLength()));
859 return getStr()[index];
860 }
861
874#if defined LIBO_INTERNAL_ONLY
875 sal_Int32 compareTo( std::u16string_view str ) const
876 {
877 return rtl_ustr_compare_WithLength( pData->buffer, pData->length,
878 str.data(), str.length() );
879 }
880#else
881 sal_Int32 compareTo( const OUString & str ) const
882 {
883 return rtl_ustr_compare_WithLength( pData->buffer, pData->length,
884 str.pData->buffer, str.pData->length );
885 }
886#endif
887
903#if defined LIBO_INTERNAL_ONLY
904 sal_Int32 compareTo( std::u16string_view str, sal_Int32 maxLength ) const
905 {
906 return rtl_ustr_shortenedCompare_WithLength( pData->buffer, pData->length,
907 str.data(), str.length(), maxLength );
908 }
909#else
910 sal_Int32 compareTo( const OUString & str, sal_Int32 maxLength ) const
911 {
912 return rtl_ustr_shortenedCompare_WithLength( pData->buffer, pData->length,
913 str.pData->buffer, str.pData->length, maxLength );
914 }
915#endif
916
929#if defined LIBO_INTERNAL_ONLY
930 sal_Int32 reverseCompareTo(std::u16string_view sv) const {
932 pData->buffer, pData->length, sv.data(), sv.size());
933 }
934#else
935 sal_Int32 reverseCompareTo( const OUString & str ) const
936 {
937 return rtl_ustr_reverseCompare_WithLength( pData->buffer, pData->length,
938 str.pData->buffer, str.pData->length );
939 }
940#endif
941
947 template< typename T >
957
969 bool equals( const OUString & str ) const
970 {
971 if ( pData->length != str.pData->length )
972 return false;
973 if ( pData == str.pData )
974 return true;
975 return rtl_ustr_reverseCompare_WithLength( pData->buffer, pData->length,
976 str.pData->buffer, str.pData->length ) == 0;
977 }
978
993#if defined LIBO_INTERNAL_ONLY
994 bool equalsIgnoreAsciiCase(std::u16string_view sv) const {
995 if ( sal_uInt32(pData->length) != sv.size() )
996 return false;
997 if ( pData->buffer == sv.data() )
998 return true;
999 return
1001 pData->buffer, pData->length, sv.data(), sv.size())
1002 == 0;
1003 }
1004#else
1005 bool equalsIgnoreAsciiCase( const OUString & str ) const
1006 {
1007 if ( pData->length != str.pData->length )
1008 return false;
1009 if ( pData == str.pData )
1010 return true;
1011 return rtl_ustr_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
1012 str.pData->buffer, str.pData->length ) == 0;
1013 }
1014#endif
1015
1031#if defined LIBO_INTERNAL_ONLY
1032 sal_Int32 compareToIgnoreAsciiCase(std::u16string_view sv) const {
1034 pData->buffer, pData->length, sv.data(), sv.size());
1035 }
1036#else
1037 sal_Int32 compareToIgnoreAsciiCase( const OUString & str ) const
1038 {
1039 return rtl_ustr_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
1040 str.pData->buffer, str.pData->length );
1041 }
1042#endif
1043
1049 template< typename T >
1063
1079#if defined LIBO_INTERNAL_ONLY
1080 bool match(std::u16string_view sv, sal_Int32 fromIndex = 0) const {
1081 assert(fromIndex >= 0);
1082 return
1084 pData->buffer + fromIndex, pData->length - fromIndex, sv.data(), sv.size(),
1085 sv.size())
1086 == 0;
1087 }
1088#else
1089 bool match( const OUString & str, sal_Int32 fromIndex = 0 ) const
1090 {
1091 assert(fromIndex >= 0);
1092 return rtl_ustr_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
1093 str.pData->buffer, str.pData->length, str.pData->length ) == 0;
1094 }
1095#endif
1096
1102 template< typename T >
1103 typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type match( T& literal, sal_Int32 fromIndex = 0 ) const
1104 {
1105 assert(
1107 assert(fromIndex >= 0);
1108 return
1110 pData->buffer+fromIndex, pData->length-fromIndex,
1112 literal),
1114 == 0;
1115 }
1116
1135#if defined LIBO_INTERNAL_ONLY
1136 bool matchIgnoreAsciiCase(std::u16string_view sv, sal_Int32 fromIndex = 0) const {
1137 assert(fromIndex >= 0);
1138 return
1140 pData->buffer + fromIndex, pData->length - fromIndex, sv.data(), sv.size(),
1141 sv.size())
1142 == 0;
1143 }
1144#else
1145 bool matchIgnoreAsciiCase( const OUString & str, sal_Int32 fromIndex = 0 ) const
1146 {
1147 assert(fromIndex >= 0);
1148 return rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
1149 str.pData->buffer, str.pData->length,
1150 str.pData->length ) == 0;
1151 }
1152#endif
1153
1159 template< typename T >
1168
1185 sal_Int32 compareToAscii( const char* asciiStr ) const
1186 {
1187 return rtl_ustr_ascii_compare_WithLength( pData->buffer, pData->length, asciiStr );
1188 }
1189
1213 "replace s1.compareToAscii(s2, strlen(s2)) == 0 with s1.startsWith(s2)")
1214 sal_Int32 compareToAscii( const char * asciiStr, sal_Int32 maxLength ) const
1215 {
1216 return rtl_ustr_ascii_shortenedCompare_WithLength( pData->buffer, pData->length,
1217 asciiStr, maxLength );
1218 }
1219
1238 sal_Int32 reverseCompareToAsciiL( const char * asciiStr, sal_Int32 asciiStrLength ) const
1239 {
1240 return rtl_ustr_asciil_reverseCompare_WithLength( pData->buffer, pData->length,
1241 asciiStr, asciiStrLength );
1242 }
1243
1259 bool equalsAscii( const char* asciiStr ) const
1260 {
1261 return rtl_ustr_ascii_compare_WithLength( pData->buffer, pData->length,
1262 asciiStr ) == 0;
1263 }
1264
1281 bool equalsAsciiL( const char* asciiStr, sal_Int32 asciiStrLength ) const
1282 {
1283 if ( pData->length != asciiStrLength )
1284 return false;
1285
1287 pData->buffer, asciiStr, asciiStrLength );
1288 }
1289
1308 bool equalsIgnoreAsciiCaseAscii( const char * asciiStr ) const
1309 {
1310 return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, asciiStr ) == 0;
1311 }
1312
1313#if defined LIBO_INTERNAL_ONLY
1314 bool equalsIgnoreAsciiCaseAscii( std::string_view asciiStr ) const
1315 {
1316 return o3tl::make_unsigned(pData->length) == asciiStr.length()
1318 pData->buffer, pData->length, asciiStr.data(), asciiStr.length()) == 0;
1319 }
1320#endif
1321
1340 sal_Int32 compareToIgnoreAsciiCaseAscii( const char * asciiStr ) const
1341 {
1342 return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, asciiStr );
1343 }
1344
1345#if defined LIBO_INTERNAL_ONLY
1346 sal_Int32 compareToIgnoreAsciiCaseAscii( std::string_view asciiStr ) const
1347 {
1348 sal_Int32 nMax = std::min<size_t>(asciiStr.length(), std::numeric_limits<sal_Int32>::max());
1350 pData->buffer, pData->length, asciiStr.data(), nMax);
1351 if (result == 0 && o3tl::make_unsigned(pData->length) < asciiStr.length())
1352 result = -1;
1353 return result;
1354 }
1355#endif
1356
1376 bool equalsIgnoreAsciiCaseAsciiL( const char * asciiStr, sal_Int32 asciiStrLength ) const
1377 {
1378 if ( pData->length != asciiStrLength )
1379 return false;
1380
1381 return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, asciiStr ) == 0;
1382 }
1383
1404 bool matchAsciiL( const char* asciiStr, sal_Int32 asciiStrLength, sal_Int32 fromIndex = 0 ) const
1405 {
1406 assert(fromIndex >= 0);
1407 return rtl_ustr_ascii_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
1408 asciiStr, asciiStrLength ) == 0;
1409 }
1410
1411 // This overload is left undefined, to detect calls of matchAsciiL that
1412 // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
1413 // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
1414 // platforms):
1415#if SAL_TYPES_SIZEOFLONG == 8
1416 void matchAsciiL(char const *, sal_Int32, rtl_TextEncoding) const;
1417#endif
1418
1442 bool matchIgnoreAsciiCaseAsciiL( const char* asciiStr, sal_Int32 asciiStrLength, sal_Int32 fromIndex = 0 ) const
1443 {
1444 assert(fromIndex >= 0);
1445 return rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
1446 asciiStr, asciiStrLength ) == 0;
1447 }
1448
1449 // This overload is left undefined, to detect calls of
1450 // matchIgnoreAsciiCaseAsciiL that erroneously use
1451 // RTL_CONSTASCII_USTRINGPARAM instead of RTL_CONSTASCII_STRINGPARAM (but
1452 // would lead to ambiguities on 32 bit platforms):
1453#if SAL_TYPES_SIZEOFLONG == 8
1454 void matchIgnoreAsciiCaseAsciiL(char const *, sal_Int32, rtl_TextEncoding)
1455 const;
1456#endif
1457
1458#if defined LIBO_INTERNAL_ONLY
1469 bool startsWith(std::u16string_view sv) const {
1470 return match(sv);
1471 }
1486 bool startsWith(std::u16string_view sv, OUString * rest) const {
1487 assert(rest);
1488 auto const b = startsWith(sv);
1489 if (b) {
1490 *rest = copy(sv.size());
1491 }
1492 return b;
1493 }
1507 bool startsWith(std::u16string_view sv, std::u16string_view * rest) const {
1508 assert(rest);
1509 auto const b = startsWith(sv);
1510 if (b) {
1511 *rest = subView(sv.size());
1512 }
1513 return b;
1514 }
1515#else
1530 bool startsWith(OUString const & str, OUString * rest = NULL) const {
1531 bool b = match(str);
1532 if (b && rest != NULL) {
1533 *rest = copy(str.getLength());
1534 }
1535 return b;
1536 }
1537#endif
1538
1539#if defined LIBO_INTERNAL_ONLY
1544 template< typename T >
1546 T & literal) const
1547 {
1548 assert(
1550 bool b
1552 <= sal_uInt32(pData->length))
1554 pData->buffer,
1556 literal),
1558 return b;
1559 }
1565 template< typename T >
1566 typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type startsWith(
1567 T & literal, OUString * rest) const
1568 {
1569 assert(rest);
1570 bool b = startsWith(literal);
1571 if (b) {
1572 *rest = copy(
1573 libreoffice_internal::ConstCharArrayDetector<T>::length);
1574 }
1575 return b;
1576 }
1581 template< typename T >
1582 typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type startsWith(
1583 T & literal, std::u16string_view * rest) const
1584 {
1585 assert(rest);
1586 bool b = startsWith(literal);
1587 if (b) {
1588 *rest = subView(
1589 libreoffice_internal::ConstCharArrayDetector<T>::length);
1590 }
1591 return b;
1592 }
1593#else
1599 template< typename T >
1601 T & literal, OUString * rest = NULL) const
1602 {
1603 assert(
1605 bool b
1607 <= sal_uInt32(pData->length))
1609 pData->buffer,
1611 literal),
1613 if (b && rest != NULL) {
1614 *rest = copy(
1616 }
1617 return b;
1618 }
1619#endif
1620
1631 {
1632 return !isEmpty() && pData->buffer[0] == ch;
1633 }
1634
1647 bool startsWith(sal_Unicode ch, OUString* rest) const {
1648 assert(rest);
1649 bool b = startsWith(ch);
1650
1651 if (b)
1652 *rest = copy(1);
1653
1654 return b;
1655 }
1656
1657#if defined LIBO_INTERNAL_ONLY
1670 bool startsWith(sal_Unicode ch, std::u16string_view* rest) const {
1671 assert(rest);
1672 bool b = startsWith(ch);
1673
1674 if (b)
1675 *rest = subView(1);
1676
1677 return b;
1678 }
1679#endif
1680
1701#if defined LIBO_INTERNAL_ONLY
1702 bool startsWithIgnoreAsciiCase(std::u16string_view sv) const {
1703 return matchIgnoreAsciiCase(sv);
1704 }
1705 bool startsWithIgnoreAsciiCase(std::u16string_view sv, OUString * rest) const {
1706 assert(rest);
1707 auto const b = startsWithIgnoreAsciiCase(sv);
1708 if (b) {
1709 *rest = copy(sv.size());
1710 }
1711 return b;
1712 }
1713 bool startsWithIgnoreAsciiCase(std::u16string_view sv, std::u16string_view * rest) const {
1714 assert(rest);
1715 auto const b = startsWithIgnoreAsciiCase(sv);
1716 if (b) {
1717 *rest = subView(sv.size());
1718 }
1719 return b;
1720 }
1721#else
1722 bool startsWithIgnoreAsciiCase(OUString const & str, OUString * rest = NULL)
1723 const
1724 {
1725 bool b = matchIgnoreAsciiCase(str);
1726 if (b && rest != NULL) {
1727 *rest = copy(str.getLength());
1728 }
1729 return b;
1730 }
1731#endif
1732
1733#if defined LIBO_INTERNAL_ONLY
1739 template< typename T >
1741 startsWithIgnoreAsciiCase(T & literal) const
1742 {
1743 assert(
1745 bool b
1747 <= sal_uInt32(pData->length))
1749 pData->buffer,
1752 literal),
1754 == 0);
1755 return b;
1756 }
1762 template< typename T >
1763 typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
1764 startsWithIgnoreAsciiCase(T & literal, OUString * rest) const
1765 {
1766 assert(rest);
1767 bool b = startsWithIgnoreAsciiCase(literal);
1768 if (b) {
1769 *rest = copy(
1770 libreoffice_internal::ConstCharArrayDetector<T>::length);
1771 }
1772 return b;
1773 }
1778 template< typename T >
1779 typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
1780 startsWithIgnoreAsciiCase(T & literal, std::u16string_view * rest) const
1781 {
1782 assert(rest);
1783 bool b = startsWithIgnoreAsciiCase(literal);
1784 if (b) {
1785 *rest = subView(
1786 libreoffice_internal::ConstCharArrayDetector<T>::length);
1787 }
1788 return b;
1789 }
1790#else
1796 template< typename T >
1797 typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
1798 startsWithIgnoreAsciiCase(T & literal, OUString * rest = NULL) const
1799 {
1800 assert(
1802 bool b
1804 <= sal_uInt32(pData->length))
1806 pData->buffer,
1809 literal),
1811 == 0);
1812 if (b && rest != NULL) {
1813 *rest = copy(
1815 }
1816 return b;
1817 }
1818#endif
1819
1820#if defined LIBO_INTERNAL_ONLY
1831 bool endsWith(std::u16string_view sv) const {
1832 return sv.size() <= sal_uInt32(pData->length)
1833 && match(sv, pData->length - sv.size());
1834 }
1835 bool endsWith(std::u16string_view sv, OUString * rest) const {
1836 auto const b = endsWith(sv);
1837 if (b && rest != nullptr) {
1838 *rest = copy(0, (pData->length - sv.size()));
1839 }
1840 return b;
1841 }
1855 bool endsWith(std::u16string_view sv, std::u16string_view * rest) const {
1856 assert(rest);
1857 auto const b = endsWith(sv);
1858 if (b) {
1859 *rest = subView(0, (pData->length - sv.size()));
1860 }
1861 return b;
1862 }
1863#else
1878 bool endsWith(OUString const & str, OUString * rest = NULL) const {
1879 bool b = str.getLength() <= getLength()
1880 && match(str, getLength() - str.getLength());
1881 if (b && rest != NULL) {
1882 *rest = copy(0, getLength() - str.getLength());
1883 }
1884 return b;
1885 }
1886#endif
1887
1897 bool endsWith(sal_Unicode ch) const
1898 {
1899 return !isEmpty() && pData->buffer[pData->length - 1] == ch;
1900 }
1901
1914 bool endsWith(sal_Unicode ch, OUString* rest) const {
1915 assert(rest);
1916 bool b = endsWith(ch);
1917
1918 if (b)
1919 *rest = copy(0, pData->length - 1);
1920
1921 return b;
1922 }
1923
1924#if defined LIBO_INTERNAL_ONLY
1937 bool endsWith(sal_Unicode ch, std::u16string_view* rest) const {
1938 assert(rest);
1939 bool b = endsWith(ch);
1940
1941 if (b)
1942 *rest = subView(0, pData->length - 1);
1943
1944 return b;
1945 }
1946#endif
1947
1948#if defined LIBO_INTERNAL_ONLY
1954 template< typename T >
1955 typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
1956 endsWith(T & literal) const
1957 {
1958 assert(
1959 libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
1960 bool b
1961 = (libreoffice_internal::ConstCharArrayDetector<T>::length
1962 <= sal_uInt32(pData->length))
1964 (pData->buffer + pData->length
1965 - libreoffice_internal::ConstCharArrayDetector<T>::length),
1966 libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
1967 literal),
1968 libreoffice_internal::ConstCharArrayDetector<T>::length);
1969 return b;
1970 }
1971 template< typename T >
1972 typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
1973 endsWith(T & literal, OUString * rest) const
1974 {
1975 assert(rest);
1976 bool b = endsWith(literal);
1977 if (b) {
1978 *rest = copy(
1979 0,
1980 (getLength()
1981 - libreoffice_internal::ConstCharArrayDetector<T>::length));
1982 }
1983 return b;
1984 }
1985 template< typename T >
1986 typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
1987 endsWith(T & literal, std::u16string_view * rest) const
1988 {
1989 assert(rest);
1990 bool b = endsWith(literal);
1991 if (b) {
1992 *rest = subView(
1993 0,
1994 (getLength()
1995 - libreoffice_internal::ConstCharArrayDetector<T>::length));
1996 }
1997 return b;
1998 }
1999#else
2005 template< typename T >
2006 typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
2007 endsWith(T & literal, OUString * rest = NULL) const
2008 {
2009 assert(
2011 bool b
2013 <= sal_uInt32(pData->length))
2015 (pData->buffer + pData->length
2018 literal),
2020 if (b && rest != NULL) {
2021 *rest = copy(
2022 0,
2023 (getLength()
2025 }
2026 return b;
2027 }
2028#endif
2029
2041 bool endsWithAsciiL(char const * asciiStr, sal_Int32 asciiStrLength)
2042 const
2043 {
2044 return asciiStrLength <= pData->length
2046 pData->buffer + pData->length - asciiStrLength, asciiStr,
2047 asciiStrLength);
2048 }
2049
2050#if defined LIBO_INTERNAL_ONLY
2071 bool endsWithIgnoreAsciiCase(std::u16string_view sv) const {
2072 return sv.size() <= sal_uInt32(pData->length)
2073 && matchIgnoreAsciiCase(sv, pData->length - sv.size());
2074 }
2075 bool endsWithIgnoreAsciiCase(std::u16string_view sv, OUString * rest) const {
2076 auto const b = endsWithIgnoreAsciiCase(sv);
2077 if (b && rest != nullptr) {
2078 *rest = copy(0, pData->length - sv.size());
2079 }
2080 return b;
2081 }
2101 bool endsWithIgnoreAsciiCase(std::u16string_view sv, std::u16string_view * rest) const {
2102 assert(rest);
2103 auto const b = endsWithIgnoreAsciiCase(sv);
2104 if (b) {
2105 *rest = subView(0, pData->length - sv.size());
2106 }
2107 return b;
2108 }
2109#else
2130 bool endsWithIgnoreAsciiCase(OUString const & str, OUString * rest = NULL) const
2131 {
2132 bool b = str.getLength() <= getLength()
2133 && matchIgnoreAsciiCase(str, getLength() - str.getLength());
2134 if (b && rest != NULL) {
2135 *rest = copy(0, getLength() - str.getLength());
2136 }
2137 return b;
2138 }
2139#endif
2140
2141#if defined LIBO_INTERNAL_ONLY
2146 template< typename T >
2148 endsWithIgnoreAsciiCase(T & literal) const
2149 {
2150 assert(
2152 bool b
2154 <= sal_uInt32(pData->length))
2156 (pData->buffer + pData->length
2160 literal),
2162 == 0);
2163 return b;
2164 }
2169 template< typename T >
2170 typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
2171 endsWithIgnoreAsciiCase(T & literal, std::u16string_view * rest) const
2172 {
2173 assert(rest);
2174 bool b = endsWithIgnoreAsciiCase(literal);
2175 if (b) {
2176 *rest = subView(
2177 0,
2178 (getLength()
2179 - libreoffice_internal::ConstCharArrayDetector<T>::length));
2180 }
2181 return b;
2182 }
2183#else
2189 template< typename T >
2190 typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
2191 endsWithIgnoreAsciiCase(T & literal, OUString * rest = NULL) const
2192 {
2193 assert(
2195 bool b
2197 <= sal_uInt32(pData->length))
2199 (pData->buffer + pData->length
2203 literal),
2205 == 0);
2206 if (b && rest != NULL) {
2207 *rest = copy(
2208 0,
2209 (getLength()
2211 }
2212 return b;
2213 }
2214#endif
2215
2227 char const * asciiStr, sal_Int32 asciiStrLength) const
2228 {
2229 return asciiStrLength <= pData->length
2231 pData->buffer + pData->length - asciiStrLength,
2232 asciiStrLength, asciiStr, asciiStrLength)
2233 == 0);
2234 }
2235
2236 friend bool operator == ( const OUString& rStr1, const OUString& rStr2 )
2237 { return rStr1.equals(rStr2); }
2238
2239 friend bool operator != ( const OUString& rStr1, const OUString& rStr2 )
2240 { return !(operator == ( rStr1, rStr2 )); }
2241
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 friend bool operator <= ( const OUString& rStr1, const OUString& rStr2 )
2247 { return rStr1.compareTo( rStr2 ) <= 0; }
2248 friend bool operator >= ( const OUString& rStr1, const OUString& rStr2 )
2249 { return rStr1.compareTo( rStr2 ) >= 0; }
2250
2251#if defined LIBO_INTERNAL_ONLY
2252
2253 template<typename T> friend typename libreoffice_internal::CharPtrDetector<T, bool>::TypeUtf16
2254 operator ==(OUString const & s1, T const & s2) {
2256 == 0;
2257 }
2258
2259 template<typename T>
2260 friend typename libreoffice_internal::NonConstCharArrayDetector<T, bool>::TypeUtf16
2261 operator ==(OUString const & s1, T & s2) {
2262 return rtl_ustr_compare_WithLength(s1.getStr(), s1.getLength(), s2, rtl_ustr_getLength(s2))
2263 == 0;
2264 }
2265
2266 template<typename T> friend typename libreoffice_internal::CharPtrDetector<T, bool>::TypeUtf16
2267 operator ==(T const & s1, OUString const & s2) {
2268 return rtl_ustr_compare_WithLength(s1, rtl_ustr_getLength(s1), s2.getStr(), s2.getLength())
2269 == 0;
2270 }
2271
2272 template<typename T>
2273 friend typename libreoffice_internal::NonConstCharArrayDetector<T, bool>::TypeUtf16
2274 operator ==(T & s1, OUString const & s2) {
2275 return rtl_ustr_compare_WithLength(s1, rtl_ustr_getLength(s1), s2.getStr(), s2.getLength())
2276 == 0;
2277 }
2278
2279 template<typename T> friend typename libreoffice_internal::CharPtrDetector<T, bool>::TypeUtf16
2280 operator !=(OUString const & s1, T const & s2) { return !(s1 == s2); }
2281
2282 template<typename T>
2283 friend typename libreoffice_internal::NonConstCharArrayDetector<T, bool>::TypeUtf16
2284 operator !=(OUString const & s1, T & s2) { return !(s1 == s2); }
2285
2286 template<typename T> friend typename libreoffice_internal::CharPtrDetector<T, bool>::TypeUtf16
2287 operator !=(T const & s1, OUString const & s2) { return !(s1 == s2); }
2288
2289 template<typename T>
2290 friend typename libreoffice_internal::NonConstCharArrayDetector<T, bool>::TypeUtf16
2291 operator !=(T & s1, OUString const & s2) { return !(s1 == s2); }
2292
2293#else
2294
2295 friend bool operator == ( const OUString& rStr1, const sal_Unicode * pStr2 )
2296 { return rStr1.compareTo( pStr2 ) == 0; }
2297 friend bool operator == ( const sal_Unicode * pStr1, const OUString& rStr2 )
2298 { return OUString( pStr1 ).compareTo( rStr2 ) == 0; }
2299
2300 friend bool operator != ( const OUString& rStr1, const sal_Unicode * pStr2 )
2301 { return !(operator == ( rStr1, pStr2 )); }
2302 friend bool operator != ( const sal_Unicode * pStr1, const OUString& rStr2 )
2303 { return !(operator == ( pStr1, rStr2 )); }
2304
2305#endif
2306
2314 template< typename T >
2323
2330 template< typename T >
2339
2346 template< typename T >
2355
2362 template< typename T >
2371
2372#if defined LIBO_INTERNAL_ONLY
2374 template<typename T> friend typename libreoffice_internal::ConstCharArrayDetector<T, bool>::TypeUtf16
2375 operator ==(OUString const & string, T & literal) {
2376 return
2378 string.pData->buffer, string.pData->length,
2380 literal),
2382 == 0;
2383 }
2385 template<typename T> friend typename libreoffice_internal::ConstCharArrayDetector<T, bool>::TypeUtf16
2386 operator ==(T & literal, OUString const & string) {
2387 return
2389 libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
2390 literal),
2391 libreoffice_internal::ConstCharArrayDetector<T>::length,
2392 string.pData->buffer, string.pData->length)
2393 == 0;
2394 }
2396 template<typename T> friend typename libreoffice_internal::ConstCharArrayDetector<T, bool>::TypeUtf16
2397 operator !=(OUString const & string, T & literal) {
2398 return
2400 string.pData->buffer, string.pData->length,
2401 libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
2402 literal),
2403 libreoffice_internal::ConstCharArrayDetector<T>::length)
2404 != 0;
2405 }
2407 template<typename T> friend typename libreoffice_internal::ConstCharArrayDetector<T, bool>::TypeUtf16
2408 operator !=(T & literal, OUString const & string) {
2409 return
2411 libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
2412 literal),
2413 libreoffice_internal::ConstCharArrayDetector<T>::length,
2414 string.pData->buffer, string.pData->length)
2415 != 0;
2416 }
2417#endif
2418
2426 sal_Int32 hashCode() const
2427 {
2428 return rtl_ustr_hashCode_WithLength( pData->buffer, pData->length );
2429 }
2430
2444 sal_Int32 indexOf( sal_Unicode ch, sal_Int32 fromIndex = 0 ) const
2445 {
2446 assert(fromIndex >= 0);
2447 sal_Int32 ret = rtl_ustr_indexOfChar_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, ch );
2448 return (ret < 0 ? ret : ret+fromIndex);
2449 }
2450
2460 sal_Int32 lastIndexOf( sal_Unicode ch ) const
2461 {
2462 return rtl_ustr_lastIndexOfChar_WithLength( pData->buffer, pData->length, ch );
2463 }
2464
2477 sal_Int32 lastIndexOf( sal_Unicode ch, sal_Int32 fromIndex ) const
2478 {
2479 return rtl_ustr_lastIndexOfChar_WithLength( pData->buffer, fromIndex, ch );
2480 }
2481
2497#if defined LIBO_INTERNAL_ONLY
2498 sal_Int32 indexOf(std::u16string_view sv, sal_Int32 fromIndex = 0) const {
2499 assert(fromIndex >= 0);
2500 auto const n = rtl_ustr_indexOfStr_WithLength(
2501 pData->buffer + fromIndex, pData->length - fromIndex, sv.data(), sv.size());
2502 return n < 0 ? n : n + fromIndex;
2503 }
2504#else
2505 sal_Int32 indexOf( const OUString & str, sal_Int32 fromIndex = 0 ) const
2506 {
2507 assert(fromIndex >= 0);
2508 sal_Int32 ret = rtl_ustr_indexOfStr_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
2509 str.pData->buffer, str.pData->length );
2510 return (ret < 0 ? ret : ret+fromIndex);
2511 }
2512#endif
2513
2519 template< typename T >
2520 typename libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type indexOf( T& literal, sal_Int32 fromIndex = 0 ) const
2521 {
2522 assert(
2524 assert(fromIndex >= 0);
2526 pData->buffer + fromIndex, pData->length - fromIndex,
2529 return n < 0 ? n : n + fromIndex;
2530 }
2531
2555 sal_Int32 indexOfAsciiL(
2556 char const * str, sal_Int32 len, sal_Int32 fromIndex = 0) const
2557 {
2558 assert(fromIndex >= 0);
2559 sal_Int32 ret = rtl_ustr_indexOfAscii_WithLength(
2560 pData->buffer + fromIndex, pData->length - fromIndex, str, len);
2561 return ret < 0 ? ret : ret + fromIndex;
2562 }
2563
2564 // This overload is left undefined, to detect calls of indexOfAsciiL that
2565 // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
2566 // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
2567 // platforms):
2568#if SAL_TYPES_SIZEOFLONG == 8
2569 void indexOfAsciiL(char const *, sal_Int32 len, rtl_TextEncoding) const;
2570#endif
2571
2587#if defined LIBO_INTERNAL_ONLY
2588 sal_Int32 lastIndexOf(std::u16string_view sv) const {
2590 pData->buffer, pData->length, sv.data(), sv.size());
2591 }
2592#else
2593 sal_Int32 lastIndexOf( const OUString & str ) const
2594 {
2595 return rtl_ustr_lastIndexOfStr_WithLength( pData->buffer, pData->length,
2596 str.pData->buffer, str.pData->length );
2597 }
2598#endif
2599
2617#if defined LIBO_INTERNAL_ONLY
2618 sal_Int32 lastIndexOf(std::u16string_view sv, sal_Int32 fromIndex) const {
2619 return rtl_ustr_lastIndexOfStr_WithLength(pData->buffer, fromIndex, sv.data(), sv.size());
2620 }
2621#else
2622 sal_Int32 lastIndexOf( const OUString & str, sal_Int32 fromIndex ) const
2623 {
2624 return rtl_ustr_lastIndexOfStr_WithLength( pData->buffer, fromIndex,
2625 str.pData->buffer, str.pData->length );
2626 }
2627#endif
2628
2634 template< typename T >
2644
2664 sal_Int32 lastIndexOfAsciiL(char const * str, sal_Int32 len) const
2665 {
2667 pData->buffer, pData->length, str, len);
2668 }
2669
2680 SAL_WARN_UNUSED_RESULT OUString copy( sal_Int32 beginIndex ) const
2681 {
2682 return copy(beginIndex, getLength() - beginIndex);
2683 }
2684
2697 SAL_WARN_UNUSED_RESULT OUString copy( sal_Int32 beginIndex, sal_Int32 count ) const
2698 {
2699 rtl_uString *pNew = NULL;
2700 rtl_uString_newFromSubString( &pNew, pData, beginIndex, count );
2701 return OUString( pNew, SAL_NO_ACQUIRE );
2702 }
2703
2704#if defined LIBO_INTERNAL_ONLY
2715 SAL_WARN_UNUSED_RESULT std::u16string_view subView( sal_Int32 beginIndex ) const
2716 {
2717 assert(beginIndex >= 0);
2718 assert(beginIndex <= getLength());
2719 return subView(beginIndex, getLength() - beginIndex);
2720 }
2721
2734 SAL_WARN_UNUSED_RESULT std::u16string_view subView( sal_Int32 beginIndex, sal_Int32 count ) const
2735 {
2736 assert(beginIndex >= 0);
2737 assert(count >= 0);
2738 assert(beginIndex <= getLength());
2739 assert(count <= getLength() - beginIndex);
2740 return std::u16string_view(*this).substr(beginIndex, count);
2741 }
2742#endif
2743
2744#ifndef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
2754 {
2755 rtl_uString* pNew = NULL;
2756 rtl_uString_newConcat( &pNew, pData, str.pData );
2757 return OUString( pNew, SAL_NO_ACQUIRE );
2758 }
2759#endif
2760
2761#ifndef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
2762 friend OUString operator+( const OUString& rStr1, const OUString& rStr2 )
2763 {
2764 return rStr1.concat( rStr2 );
2765 }
2766#endif
2767
2781 SAL_WARN_UNUSED_RESULT OUString replaceAt( sal_Int32 index, sal_Int32 count, const OUString& newStr ) const
2782 {
2783 rtl_uString* pNew = NULL;
2784 rtl_uString_newReplaceStrAt( &pNew, pData, index, count, newStr.pData );
2785 return OUString( pNew, SAL_NO_ACQUIRE );
2786 }
2787
2788#ifdef LIBO_INTERNAL_ONLY
2789 SAL_WARN_UNUSED_RESULT OUString replaceAt( sal_Int32 index, sal_Int32 count, std::u16string_view newStr ) const
2790 {
2791 rtl_uString* pNew = NULL;
2792 rtl_uString_newReplaceStrAtUtf16L( &pNew, pData, index, count, newStr.data(), newStr.size() );
2793 return OUString( pNew, SAL_NO_ACQUIRE );
2794 }
2795 // Disambiguation
2796 template <std::size_t N>
2797 SAL_WARN_UNUSED_RESULT OUString replaceAt( sal_Int32 index, sal_Int32 count, const sal_Unicode (&newStr)[N] ) const
2798 {
2799 return replaceAt(index, count, std::u16string_view(newStr, N - 1));
2800 }
2801 template <class T, std::enable_if_t<std::is_convertible_v<T, std::u16string_view>, int> = 0>
2802 SAL_WARN_UNUSED_RESULT OUString replaceAt( sal_Int32 index, sal_Int32 count, const T& newStr ) const
2803 {
2804 return replaceAt(index, count, std::u16string_view(newStr));
2805 }
2806#endif
2807
2822 {
2823 rtl_uString* pNew = NULL;
2824 rtl_uString_newReplace( &pNew, pData, oldChar, newChar );
2825 return OUString( pNew, SAL_NO_ACQUIRE );
2826 }
2827
2846#if defined LIBO_INTERNAL_ONLY
2847 [[nodiscard]] OUString replaceFirst(
2848 std::u16string_view from, std::u16string_view to, sal_Int32 * index = nullptr) const
2849 {
2850 rtl_uString * s = nullptr;
2851 sal_Int32 i = 0;
2853 &s, pData, from.data(), from.size(), to.data(), to.size(),
2854 index == nullptr ? &i : index);
2855 return OUString(s, SAL_NO_ACQUIRE);
2856 }
2857#else
2859 OUString const & from, OUString const & to, sal_Int32 * index = NULL) const
2860 {
2861 rtl_uString * s = NULL;
2862 sal_Int32 i = 0;
2864 &s, pData, from.pData, to.pData, index == NULL ? &i : index);
2865 return OUString(s, SAL_NO_ACQUIRE);
2866 }
2867#endif
2868
2887#if defined LIBO_INTERNAL_ONLY
2888 template<typename T> [[nodiscard]]
2890 T & from, std::u16string_view to, sal_Int32 * index = nullptr) const
2891 {
2893 rtl_uString * s = nullptr;
2894 sal_Int32 i = 0;
2898 index == nullptr ? &i : index);
2899 return OUString(s, SAL_NO_ACQUIRE);
2900 }
2901#else
2902 template< typename T >
2904 sal_Int32 * index = NULL) const
2905 {
2907 rtl_uString * s = NULL;
2908 sal_Int32 i = 0;
2910 &s, pData,
2913 index == NULL ? &i : index);
2914 return OUString(s, SAL_NO_ACQUIRE);
2915 }
2916#endif
2917
2936#if defined LIBO_INTERNAL_ONLY
2937 template<typename T> [[nodiscard]]
2939 std::u16string_view from, T & to, sal_Int32 * index = nullptr) const
2940 {
2942 rtl_uString * s = nullptr;
2943 sal_Int32 i = 0;
2945 &s, pData, from.data(), from.size(),
2947 libreoffice_internal::ConstCharArrayDetector<T>::length, index == nullptr ? &i : index);
2948 return OUString(s, SAL_NO_ACQUIRE);
2949 }
2950#else
2951 template< typename T >
2953 sal_Int32 * index = NULL) const
2954 {
2956 rtl_uString * s = NULL;
2957 sal_Int32 i = 0;
2959 &s, pData, from.pData,
2962 index == NULL ? &i : index);
2963 return OUString(s, SAL_NO_ACQUIRE);
2964 }
2965#endif
2966
2985 template< typename T1, typename T2 >
3002
3018#if defined LIBO_INTERNAL_ONLY
3019 [[nodiscard]] OUString replaceAll(
3020 std::u16string_view from, std::u16string_view to, sal_Int32 fromIndex = 0) const
3021 {
3022 rtl_uString * s = nullptr;
3023 rtl_uString_newReplaceAllFromIndexUtf16LUtf16L(
3024 &s, pData, from.data(), from.size(), to.data(), to.size(), fromIndex);
3025 return OUString(s, SAL_NO_ACQUIRE);
3026 }
3027#else
3029 OUString const & from, OUString const & to, sal_Int32 fromIndex = 0) const
3030 {
3031 rtl_uString * s = NULL;
3032 rtl_uString_newReplaceAllFromIndex(&s, pData, from.pData, to.pData, fromIndex);
3033 return OUString(s, SAL_NO_ACQUIRE);
3034 }
3035#endif
3036
3050#if defined LIBO_INTERNAL_ONLY
3051 template<typename T> [[nodiscard]]
3053 T & from, std::u16string_view to) const
3054 {
3056 rtl_uString * s = nullptr;
3060 return OUString(s, SAL_NO_ACQUIRE);
3061 }
3062#else
3063 template< typename T >
3074#endif
3075
3089#if defined LIBO_INTERNAL_ONLY
3090 template<typename T> [[nodiscard]]
3092 std::u16string_view from, T & to) const
3093 {
3095 rtl_uString * s = nullptr;
3097 &s, pData, from.data(), from.size(),
3100 return OUString(s, SAL_NO_ACQUIRE);
3101 }
3102#else
3103 template< typename T >
3114#endif
3115
3129 template< typename T1, typename T2 >
3144
3156 {
3157 rtl_uString* pNew = NULL;
3158 rtl_uString_newToAsciiLowerCase( &pNew, pData );
3159 return OUString( pNew, SAL_NO_ACQUIRE );
3160 }
3161
3173 {
3174 rtl_uString* pNew = NULL;
3175 rtl_uString_newToAsciiUpperCase( &pNew, pData );
3176 return OUString( pNew, SAL_NO_ACQUIRE );
3177 }
3178
3193 {
3194 rtl_uString* pNew = NULL;
3195 rtl_uString_newTrim( &pNew, pData );
3196 return OUString( pNew, SAL_NO_ACQUIRE );
3197 }
3198
3223 OUString getToken( sal_Int32 token, sal_Unicode cTok, sal_Int32& index ) const
3224 {
3225 rtl_uString * pNew = NULL;
3226 index = rtl_uString_getToken( &pNew, pData, token, cTok, index );
3227 return OUString( pNew, SAL_NO_ACQUIRE );
3228 }
3229
3243 OUString getToken(sal_Int32 count, sal_Unicode separator) const {
3244 sal_Int32 n = 0;
3245 return getToken(count, separator, n);
3246 }
3247
3256 bool toBoolean() const
3257 {
3258 return rtl_ustr_toBoolean( pData->buffer );
3259 }
3260
3268 {
3269 return pData->buffer[0];
3270 }
3271
3282 sal_Int32 toInt32( sal_Int16 radix = 10 ) const
3283 {
3284 return rtl_ustr_toInt32( pData->buffer, radix );
3285 }
3286
3299 sal_uInt32 toUInt32( sal_Int16 radix = 10 ) const
3300 {
3301 return rtl_ustr_toUInt32( pData->buffer, radix );
3302 }
3303
3314 sal_Int64 toInt64( sal_Int16 radix = 10 ) const
3315 {
3316 return rtl_ustr_toInt64( pData->buffer, radix );
3317 }
3318
3331 sal_uInt64 toUInt64( sal_Int16 radix = 10 ) const
3332 {
3333 return rtl_ustr_toUInt64( pData->buffer, radix );
3334 }
3335
3344 float toFloat() const
3345 {
3346 return rtl_ustr_toFloat( pData->buffer );
3347 }
3348
3357 double toDouble() const
3358 {
3359 return rtl_ustr_toDouble( pData->buffer );
3360 }
3361
3362
3379 {
3380 rtl_uString * pNew = NULL;
3381 rtl_uString_intern( &pNew, pData );
3382 if (pNew == NULL) {
3383 throw std::bad_alloc();
3384 }
3385 return OUString( pNew, SAL_NO_ACQUIRE );
3386 }
3387
3413 static OUString intern( const char * value, sal_Int32 length,
3414 rtl_TextEncoding encoding,
3415 sal_uInt32 convertFlags = OSTRING_TO_OUSTRING_CVTFLAGS,
3416 sal_uInt32 *pInfo = NULL )
3417 {
3418 rtl_uString * pNew = NULL;
3419 rtl_uString_internConvert( &pNew, value, length, encoding,
3420 convertFlags, pInfo );
3421 if (pNew == NULL) {
3422 throw std::bad_alloc();
3423 }
3424 return OUString( pNew, SAL_NO_ACQUIRE );
3425 }
3426
3451 bool convertToString(OString * pTarget, rtl_TextEncoding nEncoding,
3452 sal_uInt32 nFlags) const
3453 {
3454 return rtl_convertUStringToString(&pTarget->pData, pData->buffer,
3455 pData->length, nEncoding, nFlags);
3456 }
3457
3510 sal_Int32 * indexUtf16, sal_Int32 incrementCodePoints = 1) const
3511 {
3513 pData, indexUtf16, incrementCodePoints);
3514 }
3515
3525#if defined LIBO_INTERNAL_ONLY
3526 static OUString fromUtf8(std::string_view rSource)
3527 {
3528 OUString aTarget;
3529 bool bSuccess = rtl_convertStringToUString(&aTarget.pData,
3530 rSource.data(),
3531 rSource.length(),
3534 (void) bSuccess;
3535 assert(bSuccess);
3536 return aTarget;
3537 }
3538#else
3539 static OUString fromUtf8(const OString& rSource)
3540 {
3541 OUString aTarget;
3542 bool bSuccess = rtl_convertStringToUString(&aTarget.pData,
3543 rSource.getStr(),
3544 rSource.getLength(),
3547 (void) bSuccess;
3548 assert(bSuccess);
3549 return aTarget;
3550 }
3551#endif
3552
3564 {
3565 OString aTarget;
3566 bool bSuccess = rtl_convertUStringToString(&aTarget.pData,
3567 getStr(),
3568 getLength(),
3571 (void) bSuccess;
3572 assert(bSuccess);
3573 return aTarget;
3574 }
3575
3576#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
3577
3578 static auto number( int i, sal_Int16 radix = 10 )
3579 {
3580 return OUStringNumber<RTL_USTR_MAX_VALUEOFINT32>(rtl_ustr_valueOfInt32, i, radix);
3581 }
3582 static auto number( long long ll, sal_Int16 radix = 10 )
3583 {
3584 return OUStringNumber<RTL_USTR_MAX_VALUEOFINT64>(rtl_ustr_valueOfInt64, ll, radix);
3585 }
3586 static auto number( unsigned long long ll, sal_Int16 radix = 10 )
3587 {
3588 return OUStringNumber<RTL_USTR_MAX_VALUEOFUINT64>(rtl_ustr_valueOfUInt64, ll, radix);
3589 }
3590 static auto number( unsigned int i, sal_Int16 radix = 10 )
3591 {
3592 return number( static_cast< unsigned long long >( i ), radix );
3593 }
3594 static auto number( long i, sal_Int16 radix = 10)
3595 {
3596 return number( static_cast< long long >( i ), radix );
3597 }
3598 static auto number( unsigned long i, sal_Int16 radix = 10 )
3599 {
3600 return number( static_cast< unsigned long long >( i ), radix );
3601 }
3602#else
3613 static OUString number( int i, sal_Int16 radix = 10 )
3614 {
3616 return OUString(aBuf, rtl_ustr_valueOfInt32(aBuf, i, radix));
3617 }
3618
3620 static OUString number( unsigned int i, sal_Int16 radix = 10 )
3621 {
3622 return number( static_cast< unsigned long long >( i ), radix );
3623 }
3624
3626 static OUString number( long i, sal_Int16 radix = 10)
3627 {
3628 return number( static_cast< long long >( i ), radix );
3629 }
3630
3632 static OUString number( unsigned long i, sal_Int16 radix = 10 )
3633 {
3634 return number( static_cast< unsigned long long >( i ), radix );
3635 }
3636
3638 static OUString number( long long ll, sal_Int16 radix = 10 )
3639 {
3641 return OUString(aBuf, rtl_ustr_valueOfInt64(aBuf, ll, radix));
3642 }
3643
3645 static OUString number( unsigned long long ll, sal_Int16 radix = 10 )
3646 {
3648 return OUString(aBuf, rtl_ustr_valueOfUInt64(aBuf, ll, radix));
3649 }
3650#endif
3651
3661 static OUString number( float f )
3662 {
3663 rtl_uString* pNew = NULL;
3664 // Same as rtl::str::valueOfFP, used for rtl_ustr_valueOfFloat
3666 RTL_USTR_MAX_VALUEOFFLOAT - SAL_N_ELEMENTS("-x.E-xxx") + 1, '.',
3667 NULL, 0, true);
3668 if (pNew == NULL)
3669 throw std::bad_alloc();
3670
3671 return OUString(pNew, SAL_NO_ACQUIRE);
3672 }
3673
3683 static OUString number( double d )
3684 {
3685 rtl_uString* pNew = NULL;
3686 // Same as rtl::str::valueOfFP, used for rtl_ustr_valueOfDouble
3688 RTL_USTR_MAX_VALUEOFDOUBLE - SAL_N_ELEMENTS("-x.E-xxx") + 1, '.',
3689 NULL, 0, true);
3690 if (pNew == NULL)
3691 throw std::bad_alloc();
3692
3693 return OUString(pNew, SAL_NO_ACQUIRE);
3694 }
3695
3696#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
3697 static auto boolean(bool b)
3698 {
3699 return OUStringNumber<RTL_USTR_MAX_VALUEOFBOOLEAN>(rtl_ustr_valueOfBoolean, b);
3700 }
3701#else
3713 SAL_DEPRECATED("use boolean()") static OUString valueOf( sal_Bool b )
3714 {
3715 return boolean(b);
3716 }
3717
3729 static OUString boolean( bool b )
3730 {
3732 return OUString(aBuf, rtl_ustr_valueOfBoolean(aBuf, b));
3733 }
3734#endif
3735
3743 SAL_DEPRECATED("convert to OUString or use directly") static OUString valueOf( sal_Unicode c )
3744 {
3745 return OUString( &c, 1 );
3746 }
3747
3758 SAL_DEPRECATED("use number()") static OUString valueOf( sal_Int32 i, sal_Int16 radix = 10 )
3759 {
3760 return number( i, radix );
3761 }
3762
3773 SAL_DEPRECATED("use number()") static OUString valueOf( sal_Int64 ll, sal_Int16 radix = 10 )
3774 {
3775 return number( ll, radix );
3776 }
3777
3787 SAL_DEPRECATED("use number()") static OUString valueOf( float f )
3788 {
3789 return number(f);
3790 }
3791
3801 SAL_DEPRECATED("use number()") static OUString valueOf( double d )
3802 {
3803 return number(d);
3804 }
3805
3821 static OUString createFromAscii( const char * value )
3822 {
3823 rtl_uString* pNew = NULL;
3824 rtl_uString_newFromAscii( &pNew, value );
3825 return OUString( pNew, SAL_NO_ACQUIRE );
3826 }
3827
3828#if defined LIBO_INTERNAL_ONLY
3829 static OUString createFromAscii(std::string_view value) {
3830 rtl_uString * p = nullptr;
3831 rtl_uString_newFromLiteral(&p, value.data(), value.size(), 0); //TODO: check for overflow
3832 return OUString(p, SAL_NO_ACQUIRE);
3833 }
3834 #endif
3835
3836#if defined LIBO_INTERNAL_ONLY
3837 operator std::u16string_view() const { return {getStr(), sal_uInt32(getLength())}; }
3838#endif
3839
3840#if defined LIBO_INTERNAL_ONLY
3841 // A wrapper for the first expression in an
3842 //
3843 // OUString::Concat(e1) + e2 + ...
3844 //
3845 // concatenation chain, when neither of the first two e1, e2 is one of our rtl string-related
3846 // classes (so something like
3847 //
3848 // OUString s = "a" + (b ? std::u16string_view(u"c") : std::u16string_view(u"dd"));
3849 //
3850 // would not compile):
3851 template<typename T> [[nodiscard]] static
3852 OUStringConcat<OUStringConcatMarker, T>
3853 Concat(T const & value) { return OUStringConcat<OUStringConcatMarker, T>(value); }
3854
3855 // This overload is needed so that an argument of type 'char const[N]' ends up as
3856 // 'OUStringConcat<rtl::OUStringConcatMarker, char const[N]>' rather than as
3857 // 'OUStringConcat<rtl::OUStringConcatMarker, char[N]>':
3858 template<typename T, std::size_t N> [[nodiscard]] static
3859 OUStringConcat<OUStringConcatMarker, T[N]>
3860 Concat(T (& value)[N]) { return OUStringConcat<OUStringConcatMarker, T[N]>(value); }
3861#endif
3862
3863private:
3864 OUString & internalAppend( rtl_uString* pOtherData )
3865 {
3866 rtl_uString* pNewData = NULL;
3867 rtl_uString_newConcat( &pNewData, pData, pOtherData );
3868 if (pNewData == NULL) {
3869 throw std::bad_alloc();
3870 }
3871 rtl_uString_assign(&pData, pNewData);
3872 rtl_uString_release(pNewData);
3873 return *this;
3874 }
3875
3876#if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
3877 static constexpr auto empty = OUStringLiteral(u""); // [-loplugin:ostr]
3878#endif
3879};
3880
3881#if defined LIBO_INTERNAL_ONLY
3882// Prevent the operator ==/!= overloads with 'sal_Unicode const *' parameter from
3883// being selected for nonsensical code like
3884//
3885// if (ouIdAttr == nullptr)
3886//
3887void operator ==(OUString const &, std::nullptr_t) = delete;
3888void operator ==(std::nullptr_t, OUString const &) = delete;
3889void operator !=(OUString const &, std::nullptr_t) = delete;
3890void operator !=(std::nullptr_t, OUString const &) = delete;
3891#endif
3892
3893#if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST
3894inline bool operator ==(OUString const & lhs, StringConcatenation<char16_t> const & rhs)
3895{ return lhs == std::u16string_view(rhs); }
3896inline bool operator !=(OUString const & lhs, StringConcatenation<char16_t> const & rhs)
3897{ return lhs != std::u16string_view(rhs); }
3898inline bool operator ==(StringConcatenation<char16_t> const & lhs, OUString const & rhs)
3899{ return std::u16string_view(lhs) == rhs; }
3900inline bool operator !=(StringConcatenation<char16_t> const & lhs, OUString const & rhs)
3901{ return std::u16string_view(lhs) != rhs; }
3902#endif
3903
3904#if defined LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
3906
3910template<>
3911struct ToStringHelper< OUString >
3912{
3913 static std::size_t length( const OUString& s ) { return s.getLength(); }
3914 sal_Unicode* operator() ( sal_Unicode* buffer, const OUString& s ) const { return addDataHelper( buffer, s.getStr(), s.getLength()); }
3915};
3916
3920template<std::size_t N>
3921struct ToStringHelper< OUStringLiteral<N> >
3922{
3923 static std::size_t length( const OUStringLiteral<N>& str ) { return str.getLength(); }
3924 sal_Unicode* operator()( sal_Unicode* buffer, const OUStringLiteral<N>& str ) const { return addDataHelper( buffer, str.getStr(), str.getLength() ); }
3925};
3926
3930template< typename charT, typename traits, typename T1, typename T2 >
3931inline std::basic_ostream<charT, traits> & operator <<(
3932 std::basic_ostream<charT, traits> & stream, OUStringConcat< T1, T2 >&& concat)
3933{
3934 return stream << OUString( std::move(concat) );
3935}
3936
3938#endif
3939
3946{
3956 size_t operator()(const OUString& rString) const
3957 { return static_cast<size_t>(rString.hashCode()); }
3958};
3959
3960/* ======================================================================= */
3961
3979#if defined LIBO_INTERNAL_ONLY
3980inline OUString OStringToOUString( std::string_view rStr,
3981 rtl_TextEncoding encoding,
3982 sal_uInt32 convertFlags = OSTRING_TO_OUSTRING_CVTFLAGS )
3983{
3984 return OUString( rStr.data(), rStr.length(), encoding, convertFlags );
3985}
3986#else
3988 rtl_TextEncoding encoding,
3989 sal_uInt32 convertFlags = OSTRING_TO_OUSTRING_CVTFLAGS )
3990{
3991 return OUString( rStr.getStr(), rStr.getLength(), encoding, convertFlags );
3992}
3993#endif
3994
4012#if defined LIBO_INTERNAL_ONLY
4013inline OString OUStringToOString( std::u16string_view rUnicode,
4014 rtl_TextEncoding encoding,
4015 sal_uInt32 convertFlags = OUSTRING_TO_OSTRING_CVTFLAGS )
4016{
4017 return OString( rUnicode.data(), rUnicode.length(), encoding, convertFlags );
4018}
4019#else
4020inline OString OUStringToOString( const OUString & rUnicode,
4021 rtl_TextEncoding encoding,
4022 sal_uInt32 convertFlags = OUSTRING_TO_OSTRING_CVTFLAGS )
4023{
4024 return OString( rUnicode.getStr(), rUnicode.getLength(), encoding, convertFlags );
4025}
4026#endif
4027
4028/* ======================================================================= */
4029
4038template< typename charT, typename traits >
4039inline std::basic_ostream<charT, traits> & operator <<(
4040 std::basic_ostream<charT, traits> & stream, OUString const & rString)
4041{
4042 return stream <<
4044 // best effort; potentially loses data due to conversion failures
4045 // (stray surrogate halves) and embedded null characters
4046}
4047
4048} // namespace
4049
4050#ifdef RTL_STRING_UNITTEST
4051namespace rtl
4052{
4053typedef rtlunittest::OUString OUString;
4054}
4055#endif
4056
4057// In internal code, allow to use classes like OUString without having to
4058// explicitly refer to the rtl namespace, which is kind of superfluous given
4059// that OUString itself is namespaced by its OU prefix:
4060#if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST
4061using ::rtl::OUString;
4062using ::rtl::OUStringHash;
4065using ::rtl::OUStringLiteral;
4066using ::rtl::OUStringChar;
4067using ::rtl::Concat2View;
4068using RepeatedUChar = ::rtl::RepeatedChar_t<sal_Unicode>;
4069#endif
4070
4071#if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
4072
4073template<
4074#if defined RTL_STRING_UNITTEST
4075 rtlunittest::
4076#endif
4077 OUStringLiteral L>
4078constexpr
4079#if defined RTL_STRING_UNITTEST
4080 rtlunittest::
4081#endif
4082 OUString
4083operator ""_ustr() { return L; }
4084
4085#endif
4086
4088
4093#if defined LIBO_INTERNAL_ONLY
4094namespace std {
4095
4096template<>
4097struct hash<::rtl::OUString>
4098{
4099 std::size_t operator()(::rtl::OUString const & s) const
4100 {
4101 if constexpr (sizeof(std::size_t) == 8)
4102 {
4103 // return a hash that uses the full 64-bit range instead of a 32-bit value
4104 size_t n = s.getLength();
4105 for (sal_Int32 i = 0, len = s.getLength(); i < len; ++i)
4106 n = 37 * n + s[i];
4107 return n;
4108 }
4109 else
4110 return std::size_t(s.hashCode());
4111 }
4112};
4113
4114}
4115
4116#if !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
4123static inline constexpr ::rtl::OUString EMPTY_OUSTRING = u""_ustr;
4124#endif
4125
4126#endif
4128
4129#endif /* _RTL_USTRING_HXX */
4130
4131/* 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
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
#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_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:2834
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:3987
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:4020
Definition stringutils.hxx:119
This String class provide base functionality for C++ like 8-Bit character array handling.
Definition string.hxx:193
const char * getStr() const SAL_RETURNS_NONNULL
Returns a pointer to the characters of this string.
Definition string.hxx:697
sal_Int32 getLength() const
Returns the length of this string.
Definition string.hxx:671
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:3613
OUString intern() const
Return a canonical representation for a string.
Definition ustring.hxx:3378
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:2520
bool startsWith(sal_Unicode ch) const
Check whether this string starts with a given character.
Definition ustring.hxx:1630
bool startsWith(sal_Unicode ch, OUString *rest) const
Check whether this string starts with a given character.
Definition ustring.hxx:1647
bool endsWith(OUString const &str, OUString *rest=NULL) const
Check whether this string ends with a given substring.
Definition ustring.hxx:1878
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:2226
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:3155
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:3064
const sal_Unicode * getStr() const SAL_RETURNS_NONNULL
Returns a pointer to the Unicode character buffer for this string.
Definition ustring.hxx:845
bool equalsIgnoreAsciiCase(const OUString &str) const
Perform an ASCII lowercase comparison of two strings.
Definition ustring.hxx:1005
bool endsWithAsciiL(char const *asciiStr, sal_Int32 asciiStrLength) const
Check whether this string ends with a given ASCII string.
Definition ustring.hxx:2041
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:3509
static OUString fromUtf8(const OString &rSource)
Convert an OString to an OUString, assuming that the OString is UTF-8-encoded.
Definition ustring.hxx:3539
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:1103
sal_Int32 toInt32(sal_Int16 radix=10) const
Returns the int32 value from this string.
Definition ustring.hxx:3282
void clear()
Clears the string, i.e, makes a zero-character string.
Definition ustring.hxx:810
bool equalsIgnoreAsciiCaseAsciiL(const char *asciiStr, sal_Int32 asciiStrLength) const
Perform an ASCII lowercase comparison of two strings.
Definition ustring.hxx:1376
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:3645
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:2555
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:3131
~OUString()
Release the string data.
Definition ustring.hxx:536
sal_Int32 compareTo(const OUString &str, sal_Int32 maxLength) const
Compares two strings with a maximum count of characters.
Definition ustring.hxx:910
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:2664
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:2444
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:3104
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:3638
bool matchAsciiL(const char *asciiStr, sal_Int32 asciiStrLength, sal_Int32 fromIndex=0) const
Match against a substring appearing in this string.
Definition ustring.hxx:1404
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:3028
float toFloat() const
Returns the float value from this string.
Definition ustring.hxx:3344
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:3632
static OUString createFromAscii(const char *value)
Returns an OUString copied without conversion from an ASCII character string.
Definition ustring.hxx:3821
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:2903
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:2987
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:2821
sal_Int32 hashCode() const
Returns a hashcode for this string.
Definition ustring.hxx:2426
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:948
friend libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator==(T &literal, const OUString &rString)
Compare string to an ASCII string literal.
Definition ustring.hxx:2331
friend libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator==(const OUString &rString, T &literal)
Compare string to an ASCII string literal.
Definition ustring.hxx:2315
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:3626
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:1050
sal_uInt64 toUInt64(sal_Int16 radix=10) const
Returns the uint64 value from this string.
Definition ustring.hxx:3331
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:1442
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:1798
OString toUtf8() const
Convert this string to an OString, assuming that the string can be UTF-8-encoded successfully.
Definition ustring.hxx:3563
sal_Int32 reverseCompareToAsciiL(const char *asciiStr, sal_Int32 asciiStrLength) const
Compares two strings in reverse order.
Definition ustring.hxx:1238
bool equalsAsciiL(const char *asciiStr, sal_Int32 asciiStrLength) const
Perform a comparison of two strings.
Definition ustring.hxx:1281
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:3620
bool endsWith(sal_Unicode ch) const
Check whether this string ends with a given character.
Definition ustring.hxx:1897
bool convertToString(OString *pTarget, rtl_TextEncoding nEncoding, sal_uInt32 nFlags) const
Converts to an OString, signalling failure.
Definition ustring.hxx:3451
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:1600
OUString(rtl_uString *str)
New string from OUString data.
Definition ustring.hxx:249
OUString(const sal_Unicode *value, sal_Int32 length)
New string from a Unicode character buffer array.
Definition ustring.hxx:335
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:2130
sal_Int32 compareTo(const OUString &str) const
Compares two strings.
Definition ustring.hxx:881
friend libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator!=(const OUString &rString, T &literal)
Compare string to an ASCII string literal.
Definition ustring.hxx:2347
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:621
bool startsWith(OUString const &str, OUString *rest=NULL) const
Check whether this string starts with a given substring.
Definition ustring.hxx:1530
sal_Int32 lastIndexOf(sal_Unicode ch) const
Returns the index within this string of the last occurrence of the specified character,...
Definition ustring.hxx:2460
sal_Int32 compareToIgnoreAsciiCaseAscii(const char *asciiStr) const
Compares two ASCII strings ignoring case.
Definition ustring.hxx:1340
bool endsWith(sal_Unicode ch, OUString *rest) const
Check whether this string ends with a given character.
Definition ustring.hxx:1914
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:2952
OUString(sal_Unicode value)
New string from a single Unicode character.
Definition ustring.hxx:278
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:2858
sal_Int64 toInt64(sal_Int16 radix=10) const
Returns the int64 value from this string.
Definition ustring.hxx:3314
sal_uInt32 toUInt32(sal_Int16 radix=10) const
Returns the uint32 value from this string.
Definition ustring.hxx:3299
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:1722
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:2622
static OUString const & unacquired(rtl_uString *const *ppHandle)
Provides an OUString const & passing a storage pointer of an rtl_uString * handle.
Definition ustring.hxx:562
double toDouble() const
Returns the double value from this string.
Definition ustring.hxx:3357
bool equalsAscii(const char *asciiStr) const
Perform a comparison of two strings.
Definition ustring.hxx:1259
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:1160
OUString getToken(sal_Int32 token, sal_Unicode cTok, sal_Int32 &index) const
Returns a token in the string.
Definition ustring.hxx:3223
sal_Int32 getLength() const
Returns the length of this string.
Definition ustring.hxx:823
bool equalsIgnoreAsciiCaseAscii(const char *asciiStr) const
Perform an ASCII lowercase comparison of two strings.
Definition ustring.hxx:1308
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:319
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:455
OUString & operator=(const OUString &str)
Assign a new string.
Definition ustring.hxx:586
static OUString number(float f)
Returns the string representation of the float argument.
Definition ustring.hxx:3661
static OUString valueOf(sal_Bool b)
Returns the string representation of the sal_Bool argument.
Definition ustring.hxx:3713
bool isEmpty() const
Checks if a string is empty.
Definition ustring.hxx:833
sal_Int32 compareToIgnoreAsciiCase(const OUString &str) const
Perform an ASCII lowercase comparison of two strings.
Definition ustring.hxx:1037
OUString(sal_uInt32 const *codePoints, sal_Int32 codePointCount)
Create a new string from an array of Unicode code points.
Definition ustring.hxx:482
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:2007
OUString & operator+=(const OUString &str)
Append a string to this string.
Definition ustring.hxx:694
sal_Unicode toChar() const
Returns the first character from this string.
Definition ustring.hxx:3267
OUString getToken(sal_Int32 count, sal_Unicode separator) const
Returns a token from the string.
Definition ustring.hxx:3243
static OUString boolean(bool b)
Returns the string representation of the boolean argument.
Definition ustring.hxx:3729
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:2635
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:2697
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:2191
OUString(rtl_uString *str, __sal_NoAcquire)
New OUString from OUString data without acquiring it.
Definition ustring.hxx:270
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:2477
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:3192
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:3172
SAL_WARN_UNUSED_RESULT OUString concat(const OUString &str) const
Concatenates the specified string to the end of this string.
Definition ustring.hxx:2753
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:2781
bool match(const OUString &str, sal_Int32 fromIndex=0) const
Match against a substring appearing in this string.
Definition ustring.hxx:1089
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:1145
sal_Int32 compareToAscii(const char *asciiStr) const
Compares two strings.
Definition ustring.hxx:1185
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:357
sal_Int32 reverseCompareTo(const OUString &str) const
Compares two strings in reverse order.
Definition ustring.hxx:935
static OUString number(double d)
Returns the string representation of the double argument.
Definition ustring.hxx:3683
friend OUString operator+(const OUString &rStr1, const OUString &rStr2)
Definition ustring.hxx:2762
SAL_WARN_UNUSED_RESULT OUString copy(sal_Int32 beginIndex) const
Returns a new string that is a substring of this string.
Definition ustring.hxx:2680
friend libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator!=(T &literal, const OUString &rString)
Compare string to an ASCII string literal.
Definition ustring.hxx:2363
bool equals(const OUString &str) const
Perform a comparison of two strings.
Definition ustring.hxx:969
sal_Int32 lastIndexOf(const OUString &str) const
Returns the index within this string of the last occurrence of the specified substring,...
Definition ustring.hxx:2593
bool toBoolean() const
Returns the Boolean value from this string.
Definition ustring.hxx:3256
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:2505
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:3413
A helper to use OUStrings with hash maps.
Definition ustring.hxx:3946
size_t operator()(const OUString &rString) const
Compute a hash code for a string.
Definition ustring.hxx:3956