1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 * This file is part of LibreOffice published API.
24 #ifndef INCLUDED_RTL_USTRING_HXX
25 #define INCLUDED_RTL_USTRING_HXX
27 #include "sal/config.h"
37 #if defined LIBO_INTERNAL_ONLY
39 #include <string_view>
40 #include <type_traits>
44 #include "rtl/ustring.h"
45 #include "rtl/string.hxx"
46 #include "rtl/stringutils.hxx"
47 #include "rtl/textenc.h"
49 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
50 #include "config_global.h"
51 #include "o3tl/safeint.hxx"
52 #include "rtl/stringconcat.hxx"
55 #ifdef RTL_STRING_UNITTEST
56 extern bool rtl_string_unittest_invalid_conversion
;
59 // The unittest uses slightly different code to help check that the proper
60 // calls are made. The class is put into a different namespace to make
61 // sure the compiler generates a different (if generating also non-inline)
62 // copy of the function and does not merge them together. The class
63 // is "brought" into the proper rtl namespace by a typedef below.
64 #ifdef RTL_STRING_UNITTEST
65 #define rtl rtlunittest
73 #ifdef RTL_STRING_UNITTEST
77 #if defined LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
81 A wrapper dressing a string literal as a static-refcount rtl_uString.
83 This class is not part of public API and is meant to be used only in LibreOffice code.
84 @since LibreOffice 4.0
86 template<std::size_t N
> class SAL_WARN_UNUSED OUStringLiteral
{
87 static_assert(N
!= 0);
88 static_assert(N
- 1 <= std::numeric_limits
<sal_Int32
>::max(), "literal too long");
91 #if HAVE_CPP_CONSTEVAL
96 OUStringLiteral(char16_t
const (&literal
)[N
]) {
98 assert(literal
[N
- 1] == '\0');
99 std::copy_n(literal
, N
, more
.buffer
);
102 constexpr sal_Int32
getLength() const { return more
.length
; }
104 constexpr sal_Unicode
const * getStr() const SAL_RETURNS_NONNULL
{ return more
.buffer
; }
106 constexpr operator std::u16string_view() const { return {more
.buffer
, sal_uInt32(more
.length
)}; }
109 static constexpr void assertLayout() {
110 // These static_asserts verifying the layout compatibility with rtl_uString cannot be class
111 // member declarations, as offsetof requires a complete type, so defer them to here:
112 static_assert(std::is_standard_layout_v
<OUStringLiteral
>);
113 static_assert(offsetof(OUStringLiteral
, str
.refCount
) == offsetof(OUStringLiteral
, more
.refCount
));
114 static_assert(offsetof(OUStringLiteral
, str
.length
) == offsetof(OUStringLiteral
, more
.length
));
115 static_assert(offsetof(OUStringLiteral
, str
.buffer
) == offsetof(OUStringLiteral
, more
.buffer
));
121 oslInterlockedCount refCount
= 0x40000000; // SAL_STRING_STATIC_FLAG (sal/rtl/strimp.hxx)
122 sal_Int32 length
= N
- 1;
123 sal_Unicode buffer
[N
];
127 // (Data members must be public so that OUStringLiteral is a structural type that can be used as
128 // a non-type template parameter type for operator ""_ustr:)
135 #if defined RTL_STRING_UNITTEST
136 namespace libreoffice_internal
{
137 template<std::size_t N
> struct ExceptConstCharArrayDetector
<OUStringLiteral
<N
>> {};
138 template<std::size_t N
> struct ExceptCharArrayDetector
<OUStringLiteral
<N
>> {};
145 /* ======================================================================= */
148 This String class provides base functionality for C++ like Unicode
149 character array handling. The advantage of this class is that it
150 handles all the memory management for you - and it does it
151 more efficiently. If you assign a string to another string, the
152 data of both strings are shared (without any copy operation or
153 memory allocation) as long as you do not change the string. This class
154 also stores the length of the string, so that many operations are
155 faster than the C-str-functions.
157 This class provides only readonly string handling. So you could create
158 a string and you could only query the content from this string.
159 It provides also functionality to change the string, but this results
160 in every case in a new string instance (in the most cases with a
161 memory allocation). You don't have functionality to change the
162 content of the string. If you want to change the string content, then
163 you should use the OStringBuffer class, which provides these
164 functionalities and avoids too much memory allocation.
166 The design of this class is similar to the string classes in Java so
167 less people should have understanding problems when they use this class.
170 // coverity[ missing_move_assignment : SUPPRESS] - don't report the suppressed move assignment
171 class SAL_WARN_UNUSED SAL_DLLPUBLIC_RTTI OUString
179 New string containing no characters.
184 rtl_uString_new( &pData
);
188 New string from OUString.
190 @param str an OUString.
192 #if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
195 OUString( const OUString
& str
)
198 #if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
199 if (std::is_constant_evaluated()) {
200 //TODO: We would want to
202 // assert(SAL_STRING_IS_STATIC(pData));
204 // here, but that wouldn't work because read of member `str` of OUStringLiteral's
205 // anonymous union with active member `more` is not allowed in a constant expression.
208 rtl_uString_acquire( pData
);
211 #if defined LIBO_INTERNAL_ONLY
212 #if !defined(__COVERITY__) // suppress COPY_INSTEAD_OF_MOVE suggestions
216 @param str an OUString.
217 @since LibreOffice 5.2
219 #if !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
222 OUString( OUString
&& str
) noexcept
225 #if !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
226 if (std::is_constant_evaluated()) {
227 //TODO: We would want to
229 // assert(SAL_STRING_IS_STATIC(pData));
231 // here, but that wouldn't work because read of member `str` of OUStringLiteral's
232 // anonymous union with active member `more` is not allowed in a constant expression.
237 rtl_uString_new( &str
.pData
);
243 New string from OUString data.
245 @param str an OUString data.
247 OUString( rtl_uString
* str
)
250 rtl_uString_acquire( pData
);
253 #if defined LIBO_INTERNAL_ONLY
255 // Catch inadvertent conversions to the above ctor:
256 OUString(std::nullptr_t
) = delete;
260 /** New OUString from OUString data without acquiring it. Takeover of ownership.
262 The SAL_NO_ACQUIRE dummy parameter is only there to distinguish this
263 from other constructors.
268 OUString( rtl_uString
* str
, __sal_NoAcquire
)
272 New string from a single Unicode character.
274 @param value a Unicode character.
276 explicit OUString( sal_Unicode value
)
279 rtl_uString_newFromStr_WithLength( &pData
, &value
, 1 );
282 #if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST_CONCAT
284 // Catch inadvertent conversions to the above ctor (but still allow
285 // construction from char literals):
286 OUString(int) = delete;
287 explicit OUString(char c
):
288 OUString(sal_Unicode(static_cast<unsigned char>(c
)))
293 #if defined LIBO_INTERNAL_ONLY
295 template<typename T
> explicit OUString(
297 typename
libreoffice_internal::CharPtrDetector
<T
, libreoffice_internal::Dummy
>::TypeUtf16
298 = libreoffice_internal::Dummy()):
300 { rtl_uString_newFromStr(&pData
, value
); }
302 template<typename T
> explicit OUString(
305 libreoffice_internal::NonConstCharArrayDetector
<T
, libreoffice_internal::Dummy
>::TypeUtf16
306 = libreoffice_internal::Dummy()):
308 { rtl_uString_newFromStr(&pData
, value
); }
313 New string from a Unicode character buffer array.
315 @param value a NULL-terminated Unicode character array.
317 OUString( const sal_Unicode
* value
)
320 rtl_uString_newFromStr( &pData
, value
);
326 New string from a Unicode character buffer array.
328 @param value a Unicode character array.
329 @param length the number of character which should be copied.
330 The character array length must be greater than
331 or equal to this value.
333 OUString( const sal_Unicode
* value
, sal_Int32 length
)
336 rtl_uString_newFromStr_WithLength( &pData
, value
, length
);
340 New string from an 8-Bit string literal that is expected to contain only
341 characters in the ASCII set (i.e. first 128 characters). This constructor
342 allows an efficient and convenient way to create OUString
343 instances from ASCII literals. When creating strings from data that
344 is not pure ASCII, it needs to be converted to OUString by explicitly
345 providing the encoding to use for the conversion.
347 If there are any embedded \0's in the string literal, the result is undefined.
348 Use the overload that explicitly accepts length.
350 @param literal the 8-bit ASCII string literal
352 @since LibreOffice 3.6
354 template< typename T
>
355 OUString( T
& literal
, typename
libreoffice_internal::ConstCharArrayDetector
< T
, libreoffice_internal::Dummy
>::Type
= libreoffice_internal::Dummy() )
358 libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(literal
));
360 if SAL_CONSTEXPR (libreoffice_internal::ConstCharArrayDetector
<T
>::length
== 0) {
361 rtl_uString_new(&pData
);
363 rtl_uString_newFromLiteral(
365 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(
367 libreoffice_internal::ConstCharArrayDetector
<T
>::length
, 0);
369 #ifdef RTL_STRING_UNITTEST
370 rtl_string_unittest_const_literal
= true;
374 #if defined LIBO_INTERNAL_ONLY
375 // Rather use a u""_ustr literal (but don't remove this entirely, to avoid implicit support for
376 // it via std::u16string_view from kicking in):
377 template<typename T
> OUString(
379 typename
libreoffice_internal::ConstCharArrayDetector
<
380 T
, libreoffice_internal::Dummy
>::TypeUtf16
381 = libreoffice_internal::Dummy()) = delete;
383 OUString(OUStringChar c
): pData(nullptr) { rtl_uString_newFromStr_WithLength(&pData
, &c
.c
, 1); }
386 #if defined LIBO_INTERNAL_ONLY && defined RTL_STRING_UNITTEST
389 * Only used by unittests to detect incorrect conversions.
392 template< typename T
>
393 OUString( T
&, typename
libreoffice_internal::ExceptConstCharArrayDetector
< T
>::Type
= libreoffice_internal::Dummy() )
396 rtl_uString_newFromLiteral( &pData
, "!!br0ken!!", 10, 0 ); // set to garbage
397 rtl_string_unittest_invalid_conversion
= true;
400 * Only used by unittests to detect incorrect conversions.
403 template< typename T
>
404 OUString( const T
&, typename
libreoffice_internal::ExceptCharArrayDetector
< T
>::Type
= libreoffice_internal::Dummy() )
407 rtl_uString_newFromLiteral( &pData
, "!!br0ken!!", 10, 0 ); // set to garbage
408 rtl_string_unittest_invalid_conversion
= true;
413 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
416 New string from a string literal.
418 @since LibreOffice 5.0
420 template<std::size_t N
> constexpr OUString(OUStringLiteral
<N
> const & literal
):
421 pData(const_cast<rtl_uString
*>(&literal
.str
)) {}
422 template<std::size_t N
> OUString(OUStringLiteral
<N
> &&) = delete;
426 #if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
427 // For operator ""_tstr:
428 template<OStringLiteral L
> OUString(detail::OStringHolder
<L
> const & holder
) {
430 if (holder
.literal
.getLength() == 0) {
431 rtl_uString_new(&pData
);
433 rtl_uString_newFromLiteral(
434 &pData
, holder
.literal
.getStr(), holder
.literal
.getLength(), 0);
440 New string from an 8-Bit character buffer array.
442 @param value An 8-Bit character array.
443 @param length The number of character which should be converted.
444 The 8-Bit character array length must be
445 greater than or equal to this value.
446 @param encoding The text encoding from which the 8-Bit character
447 sequence should be converted.
448 @param convertFlags Flags which control the conversion.
449 see RTL_TEXTTOUNICODE_FLAGS_...
451 @exception std::bad_alloc is thrown if an out-of-memory condition occurs
453 OUString( const char * value
, sal_Int32 length
,
454 rtl_TextEncoding encoding
,
455 sal_uInt32 convertFlags
= OSTRING_TO_OUSTRING_CVTFLAGS
)
458 rtl_string2UString( &pData
, value
, length
, encoding
, convertFlags
);
460 throw std::bad_alloc();
464 /** Create a new string from an array of Unicode code points.
467 an array of at least codePointCount code points, which each must be in
468 the range from 0 to 0x10FFFF, inclusive. May be null if codePointCount
471 @param codePointCount
472 the non-negative number of code points.
474 @exception std::bad_alloc
475 is thrown if either an out-of-memory condition occurs or the resulting
476 number of UTF-16 code units would have been larger than SAL_MAX_INT32.
481 sal_uInt32
const * codePoints
, sal_Int32 codePointCount
):
484 rtl_uString_newFromCodePoints(&pData
, codePoints
, codePointCount
);
486 throw std::bad_alloc();
490 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
495 template< typename T1
, typename T2
>
496 OUString( OUStringConcat
< T1
, T2
>&& c
)
498 const sal_Int32 l
= c
.length();
499 pData
= rtl_uString_alloc( l
);
502 sal_Unicode
* end
= c
.addData( pData
->buffer
);
512 template< std::size_t N
>
513 OUString( OUStringNumber
< N
>&& n
)
514 : OUString( n
.buf
, n
.length
)
518 #if defined LIBO_INTERNAL_ONLY
519 explicit OUString(std::u16string_view sv
) {
520 if (sv
.size() > sal_uInt32(std::numeric_limits
<sal_Int32
>::max())) {
521 throw std::bad_alloc();
524 rtl_uString_newFromStr_WithLength(&pData
, sv
.data(), sv
.size());
529 Release the string data.
531 #if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
536 #if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
537 if (std::is_constant_evaluated()) {
538 //TODO: We would want to
540 // assert(SAL_STRING_IS_STATIC(pData));
542 // here, but that wouldn't work because read of member `str` of OUStringLiteral's
543 // anonymous union with active member `more` is not allowed in a constant expression.
546 rtl_uString_release( pData
);
549 /** Provides an OUString const & passing a storage pointer of an
550 rtl_uString * handle.
551 It is more convenient to use C++ OUString member functions when dealing
552 with rtl_uString * handles. Using this function avoids unnecessary
553 acquire()/release() calls for a temporary OUString object.
558 OUString const & based on given storage
560 static OUString
const & unacquired( rtl_uString
* const * ppHandle
)
561 { return * reinterpret_cast< OUString
const * >( ppHandle
); }
563 #if defined LIBO_INTERNAL_ONLY
564 /** Provides an OUString const & passing an OUStringBuffer const reference.
565 It is more convenient to use C++ OUString member functions when checking
566 current buffer content. Use this function instead of toString (that
567 allocates a new OUString from buffer data) when the result is used in
573 OUString const & based on given storage
574 @since LibreOffice 7.4
576 static OUString
const& unacquired(const OUStringBuffer
& str
);
582 @param str an OUString.
584 OUString
& operator=( const OUString
& str
)
586 rtl_uString_assign( &pData
, str
.pData
);
590 #if defined LIBO_INTERNAL_ONLY
591 #if !defined(__COVERITY__) // suppress COPY_INSTEAD_OF_MOVE suggestions
593 Move assign a new string.
595 @param str an OUString.
596 @since LibreOffice 5.2
598 OUString
& operator=( OUString
&& str
) noexcept
600 std::swap(pData
, str
.pData
);
607 Assign a new string from an 8-Bit string literal that is expected to contain only
608 characters in the ASCII set (i.e. first 128 characters). This operator
609 allows an efficient and convenient way to assign OUString
610 instances from ASCII literals. When assigning strings from data that
611 is not pure ASCII, it needs to be converted to OUString by explicitly
612 providing the encoding to use for the conversion.
614 @param literal the 8-bit ASCII string literal
616 @since LibreOffice 3.6
618 template< typename T
>
619 typename
libreoffice_internal::ConstCharArrayDetector
< T
, OUString
& >::Type
operator=( T
& literal
)
622 libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(literal
));
623 if SAL_CONSTEXPR (libreoffice_internal::ConstCharArrayDetector
<T
>::length
== 0) {
624 rtl_uString_new(&pData
);
626 rtl_uString_newFromLiteral(
628 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(
630 libreoffice_internal::ConstCharArrayDetector
<T
>::length
, 0);
635 #if defined LIBO_INTERNAL_ONLY
636 // Rather assign from a u""_ustr literal (but don't remove this entirely, to avoid implicit
637 // support for it via std::u16string_view from kicking in):
640 libreoffice_internal::ConstCharArrayDetector
<T
, OUString
&>::TypeUtf16
641 operator =(T
&) = delete;
643 OUString
& operator =(OUStringChar c
) {
644 rtl_uString_newFromStr_WithLength(&pData
, &c
.c
, 1);
648 /** @overload @since LibreOffice 5.4 */
649 template<std::size_t N
> OUString
& operator =(OUStringLiteral
<N
> const & literal
) {
650 rtl_uString_release(pData
);
651 pData
= const_cast<rtl_uString
*>(&literal
.str
);
654 template<std::size_t N
> OUString
& operator =(OUStringLiteral
<N
> &&) = delete;
656 template <std::size_t N
>
657 OUString
& operator =(OUStringNumber
<N
> && n
) {
658 // n.length should never be zero, so no need to add an optimization for that case
659 rtl_uString_newFromStr_WithLength(&pData
, n
.buf
, n
.length
);
663 OUString
& operator =(std::u16string_view sv
) {
665 rtl_uString_new(&pData
);
667 rtl_uString_newFromStr_WithLength(&pData
, sv
.data(), sv
.size());
673 #if defined LIBO_INTERNAL_ONLY
675 Append the contents of an OUStringBuffer to this string.
677 @param str an OUStringBuffer.
679 @exception std::bad_alloc is thrown if an out-of-memory condition occurs
680 @since LibreOffice 6.2
682 inline OUString
& operator+=( const OUStringBuffer
& str
) &;
686 Append a string to this string.
688 @param str an OUString.
690 @exception std::bad_alloc is thrown if an out-of-memory condition occurs
692 OUString
& operator+=( const OUString
& str
)
693 #if defined LIBO_INTERNAL_ONLY
697 return internalAppend(str
.pData
);
699 #if defined LIBO_INTERNAL_ONLY
700 void operator+=(OUString
const &) && = delete;
703 /** Append an ASCII string literal to this string.
705 @param literal an 8-bit ASCII-only string literal
707 @since LibreOffice 5.1
710 typename
libreoffice_internal::ConstCharArrayDetector
<T
, OUString
&>::Type
711 operator +=(T
& literal
)
712 #if defined LIBO_INTERNAL_ONLY
717 libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(literal
));
718 rtl_uString_newConcatAsciiL(
720 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(literal
),
721 libreoffice_internal::ConstCharArrayDetector
<T
>::length
);
724 #if defined LIBO_INTERNAL_ONLY
726 typename
libreoffice_internal::ConstCharArrayDetector
<T
, OUString
&>::Type
727 operator +=(T
&) && = delete;
730 #if defined LIBO_INTERNAL_ONLY
731 /** @overload @since LibreOffice 5.3 */
734 libreoffice_internal::ConstCharArrayDetector
<T
, OUString
&>::TypeUtf16
735 operator +=(T
& literal
) & {
736 rtl_uString_newConcatUtf16L(
738 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(literal
),
739 libreoffice_internal::ConstCharArrayDetector
<T
>::length
);
744 libreoffice_internal::ConstCharArrayDetector
<T
, OUString
&>::TypeUtf16
745 operator +=(T
&) && = delete;
747 /** @overload @since LibreOffice 5.4 */
748 template<std::size_t N
> OUString
& operator +=(OUStringLiteral
<N
> const & literal
) & {
749 rtl_uString_newConcatUtf16L(&pData
, pData
, literal
.getStr(), literal
.getLength());
752 template<std::size_t N
> void operator +=(OUStringLiteral
<N
> const &) && = delete;
754 OUString
& operator +=(std::u16string_view sv
) & {
755 if (sv
.size() > sal_uInt32(std::numeric_limits
<sal_Int32
>::max())) {
756 throw std::bad_alloc();
758 rtl_uString_newConcatUtf16L(&pData
, pData
, sv
.data(), sv
.size());
761 void operator +=(std::u16string_view
) && = delete;
764 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
769 template< typename T1
, typename T2
>
770 OUString
& operator+=( OUStringConcat
< T1
, T2
>&& c
) & {
771 sal_Int32 l
= c
.length();
775 rtl_uString_ensureCapacity( &pData
, l
);
776 sal_Unicode
* end
= c
.addData( pData
->buffer
+ pData
->length
);
781 template<typename T1
, typename T2
> void operator +=(
782 OUStringConcat
<T1
, T2
> &&) && = delete;
788 template< std::size_t N
>
789 OUString
& operator+=( OUStringNumber
< N
>&& n
) & {
790 sal_Int32 l
= n
.length
;
794 rtl_uString_ensureCapacity( &pData
, l
);
795 sal_Unicode
* end
= addDataHelper( pData
->buffer
+ pData
->length
, n
.buf
, n
.length
);
800 template<std::size_t N
> void operator +=(
801 OUStringNumber
<N
> &&) && = delete;
805 Clears the string, i.e, makes a zero-character string
806 @since LibreOffice 4.4
810 rtl_uString_new( &pData
);
814 Returns the length of this string.
816 The length is equal to the number of Unicode characters in this string.
818 @return the length of the sequence of characters represented by this
821 sal_Int32
getLength() const { return pData
->length
; }
824 Checks if a string is empty.
826 @return true if the string is empty;
829 @since LibreOffice 3.4
833 return pData
->length
== 0;
837 Returns a pointer to the Unicode character buffer for this string.
839 It isn't necessarily NULL terminated.
841 @return a pointer to the Unicode characters buffer for this object.
843 const sal_Unicode
* getStr() const SAL_RETURNS_NONNULL
{ return pData
->buffer
; }
846 Access to individual characters.
848 @param index must be non-negative and less than length.
850 @return the character at the given index.
852 @since LibreOffice 3.5
854 sal_Unicode
operator [](sal_Int32 index
) const {
855 // silence spurious -Werror=strict-overflow warnings from GCC 4.8.2
856 assert(index
>= 0 && static_cast<sal_uInt32
>(index
) < static_cast<sal_uInt32
>(getLength()));
857 return getStr()[index
];
861 Compares two strings.
863 The comparison is based on the numeric value of each character in
864 the strings and return a value indicating their relationship.
865 This function can't be used for language specific sorting.
867 @param str the object to be compared.
868 @return 0 - if both strings are equal
869 < 0 - if this string is less than the string argument
870 > 0 - if this string is greater than the string argument
872 #if defined LIBO_INTERNAL_ONLY
873 sal_Int32
compareTo( std::u16string_view str
) const
875 return rtl_ustr_compare_WithLength( pData
->buffer
, pData
->length
,
876 str
.data(), str
.length() );
879 sal_Int32
compareTo( const OUString
& str
) const
881 return rtl_ustr_compare_WithLength( pData
->buffer
, pData
->length
,
882 str
.pData
->buffer
, str
.pData
->length
);
887 Compares two strings with a maximum count of characters.
889 The comparison is based on the numeric value of each character in
890 the strings and return a value indicating their relationship.
891 This function can't be used for language specific sorting.
893 @param str the object to be compared.
894 @param maxLength the maximum count of characters to be compared.
895 @return 0 - if both strings are equal
896 < 0 - if this string is less than the string argument
897 > 0 - if this string is greater than the string argument
901 #if defined LIBO_INTERNAL_ONLY
902 sal_Int32
compareTo( std::u16string_view str
, sal_Int32 maxLength
) const
904 return rtl_ustr_shortenedCompare_WithLength( pData
->buffer
, pData
->length
,
905 str
.data(), str
.length(), maxLength
);
908 sal_Int32
compareTo( const OUString
& str
, sal_Int32 maxLength
) const
910 return rtl_ustr_shortenedCompare_WithLength( pData
->buffer
, pData
->length
,
911 str
.pData
->buffer
, str
.pData
->length
, maxLength
);
916 Compares two strings in reverse order.
918 The comparison is based on the numeric value of each character in
919 the strings and return a value indicating their relationship.
920 This function can't be used for language specific sorting.
922 @param str the object to be compared.
923 @return 0 - if both strings are equal
924 < 0 - if this string is less than the string argument
925 > 0 - if this string is greater than the string argument
927 #if defined LIBO_INTERNAL_ONLY
928 sal_Int32
reverseCompareTo(std::u16string_view sv
) const {
929 return rtl_ustr_reverseCompare_WithLength(
930 pData
->buffer
, pData
->length
, sv
.data(), sv
.size());
933 sal_Int32
reverseCompareTo( const OUString
& str
) const
935 return rtl_ustr_reverseCompare_WithLength( pData
->buffer
, pData
->length
,
936 str
.pData
->buffer
, str
.pData
->length
);
942 This function accepts an ASCII string literal as its argument.
943 @since LibreOffice 4.1
945 template< typename T
>
946 typename
libreoffice_internal::ConstCharArrayDetector
< T
, sal_Int32
>::Type
reverseCompareTo( T
& literal
) const
949 libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(literal
));
950 return rtl_ustr_asciil_reverseCompare_WithLength(
951 pData
->buffer
, pData
->length
,
952 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(literal
),
953 libreoffice_internal::ConstCharArrayDetector
<T
>::length
);
957 Perform a comparison of two strings.
959 The result is true if and only if second string
960 represents the same sequence of characters as the first string.
961 This function can't be used for language specific comparison.
963 @param str the object to be compared.
964 @return true if the strings are equal;
967 bool equals( const OUString
& str
) const
969 if ( pData
->length
!= str
.pData
->length
)
971 if ( pData
== str
.pData
)
973 return rtl_ustr_reverseCompare_WithLength( pData
->buffer
, pData
->length
,
974 str
.pData
->buffer
, str
.pData
->length
) == 0;
978 Perform an ASCII lowercase comparison of two strings.
980 The result is true if and only if second string
981 represents the same sequence of characters as the first string,
983 Character values between 65 and 90 (ASCII A-Z) are interpreted as
984 values between 97 and 122 (ASCII a-z).
985 This function can't be used for language specific comparison.
987 @param str the object to be compared.
988 @return true if the strings are equal;
991 #if defined LIBO_INTERNAL_ONLY
992 bool equalsIgnoreAsciiCase(std::u16string_view sv
) const {
993 if ( sal_uInt32(pData
->length
) != sv
.size() )
995 if ( pData
->buffer
== sv
.data() )
998 rtl_ustr_compareIgnoreAsciiCase_WithLength(
999 pData
->buffer
, pData
->length
, sv
.data(), sv
.size())
1003 bool equalsIgnoreAsciiCase( const OUString
& str
) const
1005 if ( pData
->length
!= str
.pData
->length
)
1007 if ( pData
== str
.pData
)
1009 return rtl_ustr_compareIgnoreAsciiCase_WithLength( pData
->buffer
, pData
->length
,
1010 str
.pData
->buffer
, str
.pData
->length
) == 0;
1015 Perform an ASCII lowercase comparison of two strings.
1017 Compare the two strings with uppercase ASCII
1018 character values between 65 and 90 (ASCII A-Z) interpreted as
1019 values between 97 and 122 (ASCII a-z).
1020 This function can't be used for language specific comparison.
1022 @param str the object to be compared.
1023 @return 0 - if both strings are equal
1024 < 0 - if this string is less than the string argument
1025 > 0 - if this string is greater than the string argument
1027 @since LibreOffice 4.0
1029 #if defined LIBO_INTERNAL_ONLY
1030 sal_Int32
compareToIgnoreAsciiCase(std::u16string_view sv
) const {
1031 return rtl_ustr_compareIgnoreAsciiCase_WithLength(
1032 pData
->buffer
, pData
->length
, sv
.data(), sv
.size());
1035 sal_Int32
compareToIgnoreAsciiCase( const OUString
& str
) const
1037 return rtl_ustr_compareIgnoreAsciiCase_WithLength( pData
->buffer
, pData
->length
,
1038 str
.pData
->buffer
, str
.pData
->length
);
1044 This function accepts an ASCII string literal as its argument.
1045 @since LibreOffice 3.6
1047 template< typename T
>
1048 typename
libreoffice_internal::ConstCharArrayDetector
< T
, bool >::Type
equalsIgnoreAsciiCase( T
& literal
) const
1051 libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(literal
));
1054 == libreoffice_internal::ConstCharArrayDetector
<T
>::length
)
1055 && (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength(
1056 pData
->buffer
, pData
->length
,
1057 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(
1063 Match against a substring appearing in this string.
1065 The result is true if and only if the second string appears as a substring
1066 of this string, at the given position.
1067 This function can't be used for language specific comparison.
1069 @param str the object (substring) to be compared.
1070 @param fromIndex the index to start the comparison from.
1071 The index must be greater than or equal to 0
1072 and less or equal as the string length.
1073 @return true if str match with the characters in the string
1074 at the given position;
1077 #if defined LIBO_INTERNAL_ONLY
1078 bool match(std::u16string_view sv
, sal_Int32 fromIndex
= 0) const {
1079 assert(fromIndex
>= 0);
1081 rtl_ustr_shortenedCompare_WithLength(
1082 pData
->buffer
+ fromIndex
, pData
->length
- fromIndex
, sv
.data(), sv
.size(),
1087 bool match( const OUString
& str
, sal_Int32 fromIndex
= 0 ) const
1089 assert(fromIndex
>= 0);
1090 return rtl_ustr_shortenedCompare_WithLength( pData
->buffer
+fromIndex
, pData
->length
-fromIndex
,
1091 str
.pData
->buffer
, str
.pData
->length
, str
.pData
->length
) == 0;
1097 This function accepts an ASCII string literal as its argument.
1098 @since LibreOffice 3.6
1100 template< typename T
>
1101 typename
libreoffice_internal::ConstCharArrayDetector
< T
, bool >::Type
match( T
& literal
, sal_Int32 fromIndex
= 0 ) const
1104 libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(literal
));
1105 assert(fromIndex
>= 0);
1107 rtl_ustr_ascii_shortenedCompare_WithLength(
1108 pData
->buffer
+fromIndex
, pData
->length
-fromIndex
,
1109 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(
1111 libreoffice_internal::ConstCharArrayDetector
<T
>::length
)
1116 Match against a substring appearing in this string, ignoring the case of
1119 The result is true if and only if the second string appears as a substring
1120 of this string, at the given position.
1121 Character values between 65 and 90 (ASCII A-Z) are interpreted as
1122 values between 97 and 122 (ASCII a-z).
1123 This function can't be used for language specific comparison.
1125 @param str the object (substring) to be compared.
1126 @param fromIndex the index to start the comparison from.
1127 The index must be greater than or equal to 0
1128 and less than or equal to the string length.
1129 @return true if str match with the characters in the string
1130 at the given position;
1133 #if defined LIBO_INTERNAL_ONLY
1134 bool matchIgnoreAsciiCase(std::u16string_view sv
, sal_Int32 fromIndex
= 0) const {
1135 assert(fromIndex
>= 0);
1137 rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength(
1138 pData
->buffer
+ fromIndex
, pData
->length
- fromIndex
, sv
.data(), sv
.size(),
1143 bool matchIgnoreAsciiCase( const OUString
& str
, sal_Int32 fromIndex
= 0 ) const
1145 assert(fromIndex
>= 0);
1146 return rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( pData
->buffer
+fromIndex
, pData
->length
-fromIndex
,
1147 str
.pData
->buffer
, str
.pData
->length
,
1148 str
.pData
->length
) == 0;
1154 This function accepts an ASCII string literal as its argument.
1155 @since LibreOffice 3.6
1157 template< typename T
>
1158 typename
libreoffice_internal::ConstCharArrayDetector
< T
, bool >::Type
matchIgnoreAsciiCase( T
& literal
, sal_Int32 fromIndex
= 0 ) const
1161 libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(literal
));
1162 return matchIgnoreAsciiCaseAsciiL(
1163 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(literal
),
1164 libreoffice_internal::ConstCharArrayDetector
<T
>::length
, fromIndex
);
1168 Compares two strings.
1170 The comparison is based on the numeric value of each character in
1171 the strings and return a value indicating their relationship.
1172 Since this method is optimized for performance, the ASCII character
1173 values are not converted in any way. The caller has to make sure that
1174 all ASCII characters are in the allowed range between 0 and 127.
1175 The ASCII string must be NULL-terminated.
1176 This function can't be used for language specific sorting.
1178 @param asciiStr the 8-Bit ASCII character string to be compared.
1179 @return 0 - if both strings are equal
1180 < 0 - if this string is less than the string argument
1181 > 0 - if this string is greater than the string argument
1183 sal_Int32
compareToAscii( const char* asciiStr
) const
1185 return rtl_ustr_ascii_compare_WithLength( pData
->buffer
, pData
->length
, asciiStr
);
1189 Compares two strings with a maximum count of characters.
1191 The comparison is based on the numeric value of each character in
1192 the strings and return a value indicating their relationship.
1193 Since this method is optimized for performance, the ASCII character
1194 values are not converted in any way. The caller has to make sure that
1195 all ASCII characters are in the allowed range between 0 and 127.
1196 The ASCII string must be NULL-terminated.
1197 This function can't be used for language specific sorting.
1199 @deprecated This is a confusing overload with unexpectedly different
1200 semantics from the one-parameter form, so it is marked as deprecated.
1201 Practically all uses compare the return value against zero and can thus
1202 be replaced with uses of startsWith.
1204 @param asciiStr the 8-Bit ASCII character string to be compared.
1205 @param maxLength the maximum count of characters to be compared.
1206 @return 0 - if both strings are equal
1207 < 0 - if this string is less than the string argument
1208 > 0 - if this string is greater than the string argument
1211 "replace s1.compareToAscii(s2, strlen(s2)) == 0 with s1.startsWith(s2)")
1212 sal_Int32
compareToAscii( const char * asciiStr
, sal_Int32 maxLength
) const
1214 return rtl_ustr_ascii_shortenedCompare_WithLength( pData
->buffer
, pData
->length
,
1215 asciiStr
, maxLength
);
1219 Compares two strings in reverse order.
1221 This could be useful, if normally both strings start with the same
1222 content. The comparison is based on the numeric value of each character
1223 in the strings and return a value indicating their relationship.
1224 Since this method is optimized for performance, the ASCII character
1225 values are not converted in any way. The caller has to make sure that
1226 all ASCII characters are in the allowed range between 0 and 127.
1227 The ASCII string must be greater than or equal to asciiStrLength.
1228 This function can't be used for language specific sorting.
1230 @param asciiStr the 8-Bit ASCII character string to be compared.
1231 @param asciiStrLength the length of the ascii string
1232 @return 0 - if both strings are equal
1233 < 0 - if this string is less than the string argument
1234 > 0 - if this string is greater than the string argument
1236 sal_Int32
reverseCompareToAsciiL( const char * asciiStr
, sal_Int32 asciiStrLength
) const
1238 return rtl_ustr_asciil_reverseCompare_WithLength( pData
->buffer
, pData
->length
,
1239 asciiStr
, asciiStrLength
);
1243 Perform a comparison of two strings.
1245 The result is true if and only if second string
1246 represents the same sequence of characters as the first string.
1247 Since this method is optimized for performance, the ASCII character
1248 values are not converted in any way. The caller has to make sure that
1249 all ASCII characters are in the allowed range between 0 and 127.
1250 The ASCII string must be NULL-terminated.
1251 This function can't be used for language specific comparison.
1253 @param asciiStr the 8-Bit ASCII character string to be compared.
1254 @return true if the strings are equal;
1257 bool equalsAscii( const char* asciiStr
) const
1259 return rtl_ustr_ascii_compare_WithLength( pData
->buffer
, pData
->length
,
1264 Perform a comparison of two strings.
1266 The result is true if and only if second string
1267 represents the same sequence of characters as the first string.
1268 Since this method is optimized for performance, the ASCII character
1269 values are not converted in any way. The caller has to make sure that
1270 all ASCII characters are in the allowed range between 0 and 127.
1271 The ASCII string must be greater than or equal to asciiStrLength.
1272 This function can't be used for language specific comparison.
1274 @param asciiStr the 8-Bit ASCII character string to be compared.
1275 @param asciiStrLength the length of the ascii string
1276 @return true if the strings are equal;
1279 bool equalsAsciiL( const char* asciiStr
, sal_Int32 asciiStrLength
) const
1281 if ( pData
->length
!= asciiStrLength
)
1284 return rtl_ustr_asciil_reverseEquals_WithLength(
1285 pData
->buffer
, asciiStr
, asciiStrLength
);
1289 Perform an ASCII lowercase comparison of two strings.
1291 The result is true if and only if second string
1292 represents the same sequence of characters as the first string,
1294 Character values between 65 and 90 (ASCII A-Z) are interpreted as
1295 values between 97 and 122 (ASCII a-z).
1296 Since this method is optimized for performance, the ASCII character
1297 values are not converted in any way. The caller has to make sure that
1298 all ASCII characters are in the allowed range between 0 and 127.
1299 The ASCII string must be NULL-terminated.
1300 This function can't be used for language specific comparison.
1302 @param asciiStr the 8-Bit ASCII character string to be compared.
1303 @return true if the strings are equal;
1306 bool equalsIgnoreAsciiCaseAscii( const char * asciiStr
) const
1308 return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData
->buffer
, pData
->length
, asciiStr
) == 0;
1311 #if defined LIBO_INTERNAL_ONLY
1312 bool equalsIgnoreAsciiCaseAscii( std::string_view asciiStr
) const
1314 return o3tl::make_unsigned(pData
->length
) == asciiStr
.length()
1315 && rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(
1316 pData
->buffer
, pData
->length
, asciiStr
.data(), asciiStr
.length()) == 0;
1321 Compares two ASCII strings ignoring case
1323 The comparison is based on the numeric value of each character in
1324 the strings and return a value indicating their relationship.
1325 Since this method is optimized for performance, the ASCII character
1326 values are not converted in any way. The caller has to make sure that
1327 all ASCII characters are in the allowed range between 0 and 127.
1328 The ASCII string must be NULL-terminated.
1329 This function can't be used for language specific sorting.
1331 @param asciiStr the 8-Bit ASCII character string to be compared.
1332 @return 0 - if both strings are equal
1333 < 0 - if this string is less than the string argument
1334 > 0 - if this string is greater than the string argument
1336 @since LibreOffice 3.5
1338 sal_Int32
compareToIgnoreAsciiCaseAscii( const char * asciiStr
) const
1340 return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData
->buffer
, pData
->length
, asciiStr
);
1343 #if defined LIBO_INTERNAL_ONLY
1344 sal_Int32
compareToIgnoreAsciiCaseAscii( std::string_view asciiStr
) const
1346 sal_Int32 nMax
= std::min
<size_t>(asciiStr
.length(), std::numeric_limits
<sal_Int32
>::max());
1347 sal_Int32 result
= rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(
1348 pData
->buffer
, pData
->length
, asciiStr
.data(), nMax
);
1349 if (result
== 0 && o3tl::make_unsigned(pData
->length
) < asciiStr
.length())
1356 Perform an ASCII lowercase comparison of two strings.
1358 The result is true if and only if second string
1359 represents the same sequence of characters as the first string,
1361 Character values between 65 and 90 (ASCII A-Z) are interpreted as
1362 values between 97 and 122 (ASCII a-z).
1363 Since this method is optimized for performance, the ASCII character
1364 values are not converted in any way. The caller has to make sure that
1365 all ASCII characters are in the allowed range between 0 and 127.
1366 The ASCII string must be greater than or equal to asciiStrLength.
1367 This function can't be used for language specific comparison.
1369 @param asciiStr the 8-Bit ASCII character string to be compared.
1370 @param asciiStrLength the length of the ascii string
1371 @return true if the strings are equal;
1374 bool equalsIgnoreAsciiCaseAsciiL( const char * asciiStr
, sal_Int32 asciiStrLength
) const
1376 if ( pData
->length
!= asciiStrLength
)
1379 return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData
->buffer
, pData
->length
, asciiStr
) == 0;
1383 Match against a substring appearing in this string.
1385 The result is true if and only if the second string appears as a substring
1386 of this string, at the given position.
1387 Since this method is optimized for performance, the ASCII character
1388 values are not converted in any way. The caller has to make sure that
1389 all ASCII characters are in the allowed range between 0 and 127.
1390 The ASCII string must be greater than or equal to asciiStrLength.
1391 This function can't be used for language specific comparison.
1393 @param asciiStr the object (substring) to be compared.
1394 @param asciiStrLength the length of asciiStr.
1395 @param fromIndex the index to start the comparison from.
1396 The index must be greater than or equal to 0
1397 and less than or equal to the string length.
1398 @return true if str match with the characters in the string
1399 at the given position;
1402 bool matchAsciiL( const char* asciiStr
, sal_Int32 asciiStrLength
, sal_Int32 fromIndex
= 0 ) const
1404 assert(fromIndex
>= 0);
1405 return rtl_ustr_ascii_shortenedCompare_WithLength( pData
->buffer
+fromIndex
, pData
->length
-fromIndex
,
1406 asciiStr
, asciiStrLength
) == 0;
1409 // This overload is left undefined, to detect calls of matchAsciiL that
1410 // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
1411 // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
1413 #if SAL_TYPES_SIZEOFLONG == 8
1414 void matchAsciiL(char const *, sal_Int32
, rtl_TextEncoding
) const;
1418 Match against a substring appearing in this string, ignoring the case of
1421 The result is true if and only if the second string appears as a substring
1422 of this string, at the given position.
1423 Character values between 65 and 90 (ASCII A-Z) are interpreted as
1424 values between 97 and 122 (ASCII a-z).
1425 Since this method is optimized for performance, the ASCII character
1426 values are not converted in any way. The caller has to make sure that
1427 all ASCII characters are in the allowed range between 0 and 127.
1428 The ASCII string must be greater than or equal to asciiStrLength.
1429 This function can't be used for language specific comparison.
1431 @param asciiStr the 8-Bit ASCII character string to be compared.
1432 @param asciiStrLength the length of the ascii string
1433 @param fromIndex the index to start the comparison from.
1434 The index must be greater than or equal to 0
1435 and less than or equal to the string length.
1436 @return true if str match with the characters in the string
1437 at the given position;
1440 bool matchIgnoreAsciiCaseAsciiL( const char* asciiStr
, sal_Int32 asciiStrLength
, sal_Int32 fromIndex
= 0 ) const
1442 assert(fromIndex
>= 0);
1443 return rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( pData
->buffer
+fromIndex
, pData
->length
-fromIndex
,
1444 asciiStr
, asciiStrLength
) == 0;
1447 // This overload is left undefined, to detect calls of
1448 // matchIgnoreAsciiCaseAsciiL that erroneously use
1449 // RTL_CONSTASCII_USTRINGPARAM instead of RTL_CONSTASCII_STRINGPARAM (but
1450 // would lead to ambiguities on 32 bit platforms):
1451 #if SAL_TYPES_SIZEOFLONG == 8
1452 void matchIgnoreAsciiCaseAsciiL(char const *, sal_Int32
, rtl_TextEncoding
)
1456 #if defined LIBO_INTERNAL_ONLY
1458 Check whether this string starts with a given substring.
1460 @param str the substring to be compared
1462 @return true if and only if the given str appears as a substring at the
1463 start of this string
1465 @since LibreOffice 4.0
1467 bool startsWith(std::u16string_view sv
) const {
1471 Check whether this string starts with a given substring.
1473 @param str the substring to be compared
1475 @param rest if this function returns true, then assign a
1476 copy of the remainder of this string to *rest. Available since
1479 @return true if and only if the given str appears as a substring at the
1480 start of this string
1482 @since LibreOffice 4.0
1484 bool startsWith(std::u16string_view sv
, OUString
* rest
) const {
1486 auto const b
= startsWith(sv
);
1488 *rest
= copy(sv
.size());
1493 Check whether this string starts with a given substring.
1495 @param str the substring to be compared
1497 @param rest if this function returns true, then assign a
1498 copy of the remainder of this string to *rest.
1500 @return true if and only if the given str appears as a substring at the
1501 start of this string
1503 @since LibreOffice 25.2
1505 bool startsWith(std::u16string_view sv
, std::u16string_view
* rest
) const {
1507 auto const b
= startsWith(sv
);
1509 *rest
= subView(sv
.size());
1515 Check whether this string starts with a given substring.
1517 @param str the substring to be compared
1519 @param rest if non-null, and this function returns true, then assign a
1520 copy of the remainder of this string to *rest. Available since
1523 @return true if and only if the given str appears as a substring at the
1524 start of this string
1526 @since LibreOffice 4.0
1528 bool startsWith(OUString
const & str
, OUString
* rest
= NULL
) const {
1529 bool b
= match(str
);
1530 if (b
&& rest
!= NULL
) {
1531 *rest
= copy(str
.getLength());
1537 #if defined LIBO_INTERNAL_ONLY
1539 This function accepts an ASCII string literal as its argument.
1540 @since LibreOffice 25.2
1542 template< typename T
>
1543 typename
libreoffice_internal::ConstCharArrayDetector
< T
, bool >::Type
startsWith(
1547 libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(literal
));
1549 = (libreoffice_internal::ConstCharArrayDetector
<T
>::length
1550 <= sal_uInt32(pData
->length
))
1551 && rtl_ustr_asciil_reverseEquals_WithLength(
1553 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(
1555 libreoffice_internal::ConstCharArrayDetector
<T
>::length
);
1560 This function accepts an ASCII string literal as its argument.
1561 @since LibreOffice 4.0
1563 template< typename T
>
1564 typename
libreoffice_internal::ConstCharArrayDetector
< T
, bool >::Type
startsWith(
1565 T
& literal
, OUString
* rest
) const
1568 bool b
= startsWith(literal
);
1571 libreoffice_internal::ConstCharArrayDetector
<T
>::length
);
1576 This function accepts an ASCII string literal as its argument.
1577 @since LibreOffice 25.2
1579 template< typename T
>
1580 typename
libreoffice_internal::ConstCharArrayDetector
< T
, bool >::Type
startsWith(
1581 T
& literal
, std::u16string_view
* rest
) const
1584 bool b
= startsWith(literal
);
1587 libreoffice_internal::ConstCharArrayDetector
<T
>::length
);
1594 This function accepts an ASCII string literal as its argument.
1595 @since LibreOffice 4.0
1597 template< typename T
>
1598 typename
libreoffice_internal::ConstCharArrayDetector
< T
, bool >::Type
startsWith(
1599 T
& literal
, OUString
* rest
= NULL
) const
1602 libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(literal
));
1604 = (libreoffice_internal::ConstCharArrayDetector
<T
>::length
1605 <= sal_uInt32(pData
->length
))
1606 && rtl_ustr_asciil_reverseEquals_WithLength(
1608 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(
1610 libreoffice_internal::ConstCharArrayDetector
<T
>::length
);
1611 if (b
&& rest
!= NULL
) {
1613 libreoffice_internal::ConstCharArrayDetector
<T
>::length
);
1620 Check whether this string starts with a given string, ignoring the case of
1623 Character values between 65 and 90 (ASCII A-Z) are interpreted as
1624 values between 97 and 122 (ASCII a-z).
1625 This function can't be used for language specific comparison.
1627 @param str the substring to be compared
1629 @param rest if non-null, and this function returns true, then assign a
1630 copy of the remainder of this string to *rest. Available since
1633 @return true if and only if the given str appears as a substring at the
1634 start of this string, ignoring the case of ASCII letters ("A"--"Z" and
1637 @since LibreOffice 4.0
1639 #if defined LIBO_INTERNAL_ONLY
1640 bool startsWithIgnoreAsciiCase(std::u16string_view sv
) const {
1641 return matchIgnoreAsciiCase(sv
);
1643 bool startsWithIgnoreAsciiCase(std::u16string_view sv
, OUString
* rest
) const {
1645 auto const b
= startsWithIgnoreAsciiCase(sv
);
1647 *rest
= copy(sv
.size());
1651 bool startsWithIgnoreAsciiCase(std::u16string_view sv
, std::u16string_view
* rest
) const {
1653 auto const b
= startsWithIgnoreAsciiCase(sv
);
1655 *rest
= subView(sv
.size());
1660 bool startsWithIgnoreAsciiCase(OUString
const & str
, OUString
* rest
= NULL
)
1663 bool b
= matchIgnoreAsciiCase(str
);
1664 if (b
&& rest
!= NULL
) {
1665 *rest
= copy(str
.getLength());
1671 #if defined LIBO_INTERNAL_ONLY
1674 This function accepts an ASCII string literal as its argument.
1675 @since LibreOffice 4.0
1677 template< typename T
>
1678 typename
libreoffice_internal::ConstCharArrayDetector
< T
, bool >::Type
1679 startsWithIgnoreAsciiCase(T
& literal
) const
1682 libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(literal
));
1684 = (libreoffice_internal::ConstCharArrayDetector
<T
>::length
1685 <= sal_uInt32(pData
->length
))
1686 && (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(
1688 libreoffice_internal::ConstCharArrayDetector
<T
>::length
,
1689 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(
1691 libreoffice_internal::ConstCharArrayDetector
<T
>::length
)
1697 This function accepts an ASCII string literal as its argument.
1698 @since LibreOffice 4.0
1700 template< typename T
>
1701 typename
libreoffice_internal::ConstCharArrayDetector
< T
, bool >::Type
1702 startsWithIgnoreAsciiCase(T
& literal
, OUString
* rest
) const
1705 bool b
= startsWithIgnoreAsciiCase(literal
);
1708 libreoffice_internal::ConstCharArrayDetector
<T
>::length
);
1713 This function accepts an ASCII string literal as its argument.
1714 @since LibreOffice 25.2
1716 template< typename T
>
1717 typename
libreoffice_internal::ConstCharArrayDetector
< T
, bool >::Type
1718 startsWithIgnoreAsciiCase(T
& literal
, std::u16string_view
* rest
) const
1721 bool b
= startsWithIgnoreAsciiCase(literal
);
1724 libreoffice_internal::ConstCharArrayDetector
<T
>::length
);
1731 This function accepts an ASCII string literal as its argument.
1732 @since LibreOffice 4.0
1734 template< typename T
>
1735 typename
libreoffice_internal::ConstCharArrayDetector
< T
, bool >::Type
1736 startsWithIgnoreAsciiCase(T
& literal
, OUString
* rest
= NULL
) const
1739 libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(literal
));
1741 = (libreoffice_internal::ConstCharArrayDetector
<T
>::length
1742 <= sal_uInt32(pData
->length
))
1743 && (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(
1745 libreoffice_internal::ConstCharArrayDetector
<T
>::length
,
1746 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(
1748 libreoffice_internal::ConstCharArrayDetector
<T
>::length
)
1750 if (b
&& rest
!= NULL
) {
1752 libreoffice_internal::ConstCharArrayDetector
<T
>::length
);
1758 #if defined LIBO_INTERNAL_ONLY
1760 Check whether this string ends with a given substring.
1762 @param str the substring to be compared
1764 @return true if and only if the given str appears as a substring at the
1767 @since LibreOffice 3.6
1769 bool endsWith(std::u16string_view sv
) const {
1770 return sv
.size() <= sal_uInt32(pData
->length
)
1771 && match(sv
, pData
->length
- sv
.size());
1773 bool endsWith(std::u16string_view sv
, OUString
* rest
) const {
1774 auto const b
= endsWith(sv
);
1775 if (b
&& rest
!= nullptr) {
1776 *rest
= copy(0, (pData
->length
- sv
.size()));
1781 Check whether this string ends with a given substring.
1783 @param str the substring to be compared
1785 @param rest if this function returns true, then assign a
1786 copy of the remainder of this string to *rest.
1788 @return true if and only if the given str appears as a substring at the
1791 @since LibreOffice 25.2
1793 bool endsWith(std::u16string_view sv
, std::u16string_view
* rest
) const {
1795 auto const b
= endsWith(sv
);
1797 *rest
= subView(0, (pData
->length
- sv
.size()));
1803 Check whether this string ends with a given substring.
1805 @param str the substring to be compared
1807 @param rest if non-null, and this function returns true, then assign a
1808 copy of the remainder of this string to *rest. Available since
1811 @return true if and only if the given str appears as a substring at the
1814 @since LibreOffice 3.6
1816 bool endsWith(OUString
const & str
, OUString
* rest
= NULL
) const {
1817 bool b
= str
.getLength() <= getLength()
1818 && match(str
, getLength() - str
.getLength());
1819 if (b
&& rest
!= NULL
) {
1820 *rest
= copy(0, getLength() - str
.getLength());
1826 #if defined LIBO_INTERNAL_ONLY
1829 This function accepts an ASCII string literal as its argument.
1830 @since LibreOffice 25.2
1832 template< typename T
>
1833 typename
libreoffice_internal::ConstCharArrayDetector
< T
, bool >::Type
1834 endsWith(T
& literal
) const
1837 libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(literal
));
1839 = (libreoffice_internal::ConstCharArrayDetector
<T
>::length
1840 <= sal_uInt32(pData
->length
))
1841 && rtl_ustr_asciil_reverseEquals_WithLength(
1842 (pData
->buffer
+ pData
->length
1843 - libreoffice_internal::ConstCharArrayDetector
<T
>::length
),
1844 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(
1846 libreoffice_internal::ConstCharArrayDetector
<T
>::length
);
1849 template< typename T
>
1850 typename
libreoffice_internal::ConstCharArrayDetector
< T
, bool >::Type
1851 endsWith(T
& literal
, OUString
* rest
) const
1854 bool b
= endsWith(literal
);
1859 - libreoffice_internal::ConstCharArrayDetector
<T
>::length
));
1863 template< typename T
>
1864 typename
libreoffice_internal::ConstCharArrayDetector
< T
, bool >::Type
1865 endsWith(T
& literal
, std::u16string_view
* rest
) const
1868 bool b
= endsWith(literal
);
1873 - libreoffice_internal::ConstCharArrayDetector
<T
>::length
));
1880 This function accepts an ASCII string literal as its argument.
1881 @since LibreOffice 3.6
1883 template< typename T
>
1884 typename
libreoffice_internal::ConstCharArrayDetector
< T
, bool >::Type
1885 endsWith(T
& literal
, OUString
* rest
= NULL
) const
1888 libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(literal
));
1890 = (libreoffice_internal::ConstCharArrayDetector
<T
>::length
1891 <= sal_uInt32(pData
->length
))
1892 && rtl_ustr_asciil_reverseEquals_WithLength(
1893 (pData
->buffer
+ pData
->length
1894 - libreoffice_internal::ConstCharArrayDetector
<T
>::length
),
1895 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(
1897 libreoffice_internal::ConstCharArrayDetector
<T
>::length
);
1898 if (b
&& rest
!= NULL
) {
1902 - libreoffice_internal::ConstCharArrayDetector
<T
>::length
));
1909 Check whether this string ends with a given ASCII string.
1911 @param asciiStr a sequence of at least asciiStrLength ASCII characters
1912 (bytes in the range 0x00--0x7F)
1913 @param asciiStrLength the length of asciiStr; must be non-negative
1914 @return true if this string ends with asciiStr; otherwise, false is
1919 bool endsWithAsciiL(char const * asciiStr
, sal_Int32 asciiStrLength
)
1922 return asciiStrLength
<= pData
->length
1923 && rtl_ustr_asciil_reverseEquals_WithLength(
1924 pData
->buffer
+ pData
->length
- asciiStrLength
, asciiStr
,
1928 #if defined LIBO_INTERNAL_ONLY
1930 Check whether this string ends with a given string, ignoring the case of
1933 Character values between 65 and 90 (ASCII A-Z) are interpreted as
1934 values between 97 and 122 (ASCII a-z).
1935 This function can't be used for language specific comparison.
1937 @param str the substring to be compared
1939 @param rest if this function returns true, then assign a
1940 copy of the remainder of this string to *rest. Available since
1943 @return true if and only if the given str appears as a substring at the
1944 end of this string, ignoring the case of ASCII letters ("A"--"Z" and
1947 @since LibreOffice 3.6
1949 bool endsWithIgnoreAsciiCase(std::u16string_view sv
) const {
1950 return sv
.size() <= sal_uInt32(pData
->length
)
1951 && matchIgnoreAsciiCase(sv
, pData
->length
- sv
.size());
1953 bool endsWithIgnoreAsciiCase(std::u16string_view sv
, OUString
* rest
) const {
1954 auto const b
= endsWithIgnoreAsciiCase(sv
);
1955 if (b
&& rest
!= nullptr) {
1956 *rest
= copy(0, pData
->length
- sv
.size());
1961 Check whether this string ends with a given string, ignoring the case of
1964 Character values between 65 and 90 (ASCII A-Z) are interpreted as
1965 values between 97 and 122 (ASCII a-z).
1966 This function can't be used for language specific comparison.
1968 @param str the substring to be compared
1970 @param rest if this function returns true, then assign a
1971 copy of the remainder of this string to *rest.
1973 @return true if and only if the given str appears as a substring at the
1974 end of this string, ignoring the case of ASCII letters ("A"--"Z" and
1977 @since LibreOffice 24.2
1979 bool endsWithIgnoreAsciiCase(std::u16string_view sv
, std::u16string_view
* rest
) const {
1981 auto const b
= endsWithIgnoreAsciiCase(sv
);
1983 *rest
= subView(0, pData
->length
- sv
.size());
1989 Check whether this string ends with a given string, ignoring the case of
1992 Character values between 65 and 90 (ASCII A-Z) are interpreted as
1993 values between 97 and 122 (ASCII a-z).
1994 This function can't be used for language specific comparison.
1996 @param str the substring to be compared
1998 @param rest if non-null, and this function returns true, then assign a
1999 copy of the remainder of this string to *rest. Available since
2002 @return true if and only if the given str appears as a substring at the
2003 end of this string, ignoring the case of ASCII letters ("A"--"Z" and
2006 @since LibreOffice 3.6
2008 bool endsWithIgnoreAsciiCase(OUString
const & str
, OUString
* rest
= NULL
) const
2010 bool b
= str
.getLength() <= getLength()
2011 && matchIgnoreAsciiCase(str
, getLength() - str
.getLength());
2012 if (b
&& rest
!= NULL
) {
2013 *rest
= copy(0, getLength() - str
.getLength());
2019 #if defined LIBO_INTERNAL_ONLY
2021 This function accepts an ASCII string literal as its argument.
2022 @since LibreOffice 25.2
2024 template< typename T
>
2025 typename
libreoffice_internal::ConstCharArrayDetector
< T
, bool >::Type
2026 endsWithIgnoreAsciiCase(T
& literal
) const
2029 libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(literal
));
2031 = (libreoffice_internal::ConstCharArrayDetector
<T
>::length
2032 <= sal_uInt32(pData
->length
))
2033 && (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(
2034 (pData
->buffer
+ pData
->length
2035 - libreoffice_internal::ConstCharArrayDetector
<T
>::length
),
2036 libreoffice_internal::ConstCharArrayDetector
<T
>::length
,
2037 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(
2039 libreoffice_internal::ConstCharArrayDetector
<T
>::length
)
2044 This function accepts an ASCII string literal as its argument.
2045 @since LibreOffice 25.2
2047 template< typename T
>
2048 typename
libreoffice_internal::ConstCharArrayDetector
< T
, bool >::Type
2049 endsWithIgnoreAsciiCase(T
& literal
, std::u16string_view
* rest
) const
2052 bool b
= endsWithIgnoreAsciiCase(literal
);
2057 - libreoffice_internal::ConstCharArrayDetector
<T
>::length
));
2064 This function accepts an ASCII string literal as its argument.
2065 @since LibreOffice 3.6
2067 template< typename T
>
2068 typename
libreoffice_internal::ConstCharArrayDetector
< T
, bool >::Type
2069 endsWithIgnoreAsciiCase(T
& literal
, OUString
* rest
= NULL
) const
2072 libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(literal
));
2074 = (libreoffice_internal::ConstCharArrayDetector
<T
>::length
2075 <= sal_uInt32(pData
->length
))
2076 && (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(
2077 (pData
->buffer
+ pData
->length
2078 - libreoffice_internal::ConstCharArrayDetector
<T
>::length
),
2079 libreoffice_internal::ConstCharArrayDetector
<T
>::length
,
2080 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(
2082 libreoffice_internal::ConstCharArrayDetector
<T
>::length
)
2084 if (b
&& rest
!= NULL
) {
2088 - libreoffice_internal::ConstCharArrayDetector
<T
>::length
));
2095 Check whether this string ends with a given ASCII string, ignoring the
2096 case of ASCII letters.
2098 @param asciiStr a sequence of at least asciiStrLength ASCII characters
2099 (bytes in the range 0x00--0x7F)
2100 @param asciiStrLength the length of asciiStr; must be non-negative
2101 @return true if this string ends with asciiStr, ignoring the case of ASCII
2102 letters ("A"--"Z" and "a"--"z"); otherwise, false is returned
2104 bool endsWithIgnoreAsciiCaseAsciiL(
2105 char const * asciiStr
, sal_Int32 asciiStrLength
) const
2107 return asciiStrLength
<= pData
->length
2108 && (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(
2109 pData
->buffer
+ pData
->length
- asciiStrLength
,
2110 asciiStrLength
, asciiStr
, asciiStrLength
)
2114 friend bool operator == ( const OUString
& rStr1
, const OUString
& rStr2
)
2115 { return rStr1
.equals(rStr2
); }
2117 friend bool operator != ( const OUString
& rStr1
, const OUString
& rStr2
)
2118 { return !(operator == ( rStr1
, rStr2
)); }
2120 friend bool operator < ( const OUString
& rStr1
, const OUString
& rStr2
)
2121 { return rStr1
.compareTo( rStr2
) < 0; }
2122 friend bool operator > ( const OUString
& rStr1
, const OUString
& rStr2
)
2123 { return rStr1
.compareTo( rStr2
) > 0; }
2124 friend bool operator <= ( const OUString
& rStr1
, const OUString
& rStr2
)
2125 { return rStr1
.compareTo( rStr2
) <= 0; }
2126 friend bool operator >= ( const OUString
& rStr1
, const OUString
& rStr2
)
2127 { return rStr1
.compareTo( rStr2
) >= 0; }
2129 #if defined LIBO_INTERNAL_ONLY
2131 template<typename T
> friend typename
libreoffice_internal::CharPtrDetector
<T
, bool>::TypeUtf16
2132 operator ==(OUString
const & s1
, T
const & s2
) {
2133 return rtl_ustr_compare_WithLength(s1
.getStr(), s1
.getLength(), s2
, rtl_ustr_getLength(s2
))
2137 template<typename T
>
2138 friend typename
libreoffice_internal::NonConstCharArrayDetector
<T
, bool>::TypeUtf16
2139 operator ==(OUString
const & s1
, T
& s2
) {
2140 return rtl_ustr_compare_WithLength(s1
.getStr(), s1
.getLength(), s2
, rtl_ustr_getLength(s2
))
2144 template<typename T
> friend typename
libreoffice_internal::CharPtrDetector
<T
, bool>::TypeUtf16
2145 operator ==(T
const & s1
, OUString
const & s2
) {
2146 return rtl_ustr_compare_WithLength(s1
, rtl_ustr_getLength(s1
), s2
.getStr(), s2
.getLength())
2150 template<typename T
>
2151 friend typename
libreoffice_internal::NonConstCharArrayDetector
<T
, bool>::TypeUtf16
2152 operator ==(T
& s1
, OUString
const & s2
) {
2153 return rtl_ustr_compare_WithLength(s1
, rtl_ustr_getLength(s1
), s2
.getStr(), s2
.getLength())
2157 template<typename T
> friend typename
libreoffice_internal::CharPtrDetector
<T
, bool>::TypeUtf16
2158 operator !=(OUString
const & s1
, T
const & s2
) { return !(s1
== s2
); }
2160 template<typename T
>
2161 friend typename
libreoffice_internal::NonConstCharArrayDetector
<T
, bool>::TypeUtf16
2162 operator !=(OUString
const & s1
, T
& s2
) { return !(s1
== s2
); }
2164 template<typename T
> friend typename
libreoffice_internal::CharPtrDetector
<T
, bool>::TypeUtf16
2165 operator !=(T
const & s1
, OUString
const & s2
) { return !(s1
== s2
); }
2167 template<typename T
>
2168 friend typename
libreoffice_internal::NonConstCharArrayDetector
<T
, bool>::TypeUtf16
2169 operator !=(T
& s1
, OUString
const & s2
) { return !(s1
== s2
); }
2173 friend bool operator == ( const OUString
& rStr1
, const sal_Unicode
* pStr2
)
2174 { return rStr1
.compareTo( pStr2
) == 0; }
2175 friend bool operator == ( const sal_Unicode
* pStr1
, const OUString
& rStr2
)
2176 { return OUString( pStr1
).compareTo( rStr2
) == 0; }
2178 friend bool operator != ( const OUString
& rStr1
, const sal_Unicode
* pStr2
)
2179 { return !(operator == ( rStr1
, pStr2
)); }
2180 friend bool operator != ( const sal_Unicode
* pStr1
, const OUString
& rStr2
)
2181 { return !(operator == ( pStr1
, rStr2
)); }
2186 * Compare string to an ASCII string literal.
2188 * This operator is equal to calling equalsAsciiL().
2190 * @since LibreOffice 3.6
2192 template< typename T
>
2193 friend typename
libreoffice_internal::ConstCharArrayDetector
< T
, bool >::Type
operator==( const OUString
& rString
, T
& literal
)
2196 libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(literal
));
2197 return rString
.equalsAsciiL(
2198 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(literal
),
2199 libreoffice_internal::ConstCharArrayDetector
<T
>::length
);
2202 * Compare string to an ASCII string literal.
2204 * This operator is equal to calling equalsAsciiL().
2206 * @since LibreOffice 3.6
2208 template< typename T
>
2209 friend typename
libreoffice_internal::ConstCharArrayDetector
< T
, bool >::Type
operator==( T
& literal
, const OUString
& rString
)
2212 libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(literal
));
2213 return rString
.equalsAsciiL(
2214 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(literal
),
2215 libreoffice_internal::ConstCharArrayDetector
<T
>::length
);
2218 * Compare string to an ASCII string literal.
2220 * This operator is equal to calling !equalsAsciiL().
2222 * @since LibreOffice 3.6
2224 template< typename T
>
2225 friend typename
libreoffice_internal::ConstCharArrayDetector
< T
, bool >::Type
operator!=( const OUString
& rString
, T
& literal
)
2228 libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(literal
));
2229 return !rString
.equalsAsciiL(
2230 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(literal
),
2231 libreoffice_internal::ConstCharArrayDetector
<T
>::length
);
2234 * Compare string to an ASCII string literal.
2236 * This operator is equal to calling !equalsAsciiL().
2238 * @since LibreOffice 3.6
2240 template< typename T
>
2241 friend typename
libreoffice_internal::ConstCharArrayDetector
< T
, bool >::Type
operator!=( T
& literal
, const OUString
& rString
)
2244 libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(literal
));
2245 return !rString
.equalsAsciiL(
2246 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(literal
),
2247 libreoffice_internal::ConstCharArrayDetector
<T
>::length
);
2250 #if defined LIBO_INTERNAL_ONLY
2251 /** @overload @since LibreOffice 5.3 */
2252 template<typename T
> friend typename
libreoffice_internal::ConstCharArrayDetector
<T
, bool>::TypeUtf16
2253 operator ==(OUString
const & string
, T
& literal
) {
2255 rtl_ustr_reverseCompare_WithLength(
2256 string
.pData
->buffer
, string
.pData
->length
,
2257 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(
2259 libreoffice_internal::ConstCharArrayDetector
<T
>::length
)
2262 /** @overload @since LibreOffice 5.3 */
2263 template<typename T
> friend typename
libreoffice_internal::ConstCharArrayDetector
<T
, bool>::TypeUtf16
2264 operator ==(T
& literal
, OUString
const & string
) {
2266 rtl_ustr_reverseCompare_WithLength(
2267 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(
2269 libreoffice_internal::ConstCharArrayDetector
<T
>::length
,
2270 string
.pData
->buffer
, string
.pData
->length
)
2273 /** @overload @since LibreOffice 5.3 */
2274 template<typename T
> friend typename
libreoffice_internal::ConstCharArrayDetector
<T
, bool>::TypeUtf16
2275 operator !=(OUString
const & string
, T
& literal
) {
2277 rtl_ustr_reverseCompare_WithLength(
2278 string
.pData
->buffer
, string
.pData
->length
,
2279 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(
2281 libreoffice_internal::ConstCharArrayDetector
<T
>::length
)
2284 /** @overload @since LibreOffice 5.3 */
2285 template<typename T
> friend typename
libreoffice_internal::ConstCharArrayDetector
<T
, bool>::TypeUtf16
2286 operator !=(T
& literal
, OUString
const & string
) {
2288 rtl_ustr_reverseCompare_WithLength(
2289 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(
2291 libreoffice_internal::ConstCharArrayDetector
<T
>::length
,
2292 string
.pData
->buffer
, string
.pData
->length
)
2298 Returns a hashcode for this string.
2300 @return a hash code value for this object.
2302 @see rtl::OUStringHash for convenient use of std::unordered_map
2304 sal_Int32
hashCode() const
2306 return rtl_ustr_hashCode_WithLength( pData
->buffer
, pData
->length
);
2310 Returns the index within this string of the first occurrence of the
2311 specified character, starting the search at the specified index.
2313 @param ch character to be located.
2314 @param fromIndex the index to start the search from.
2315 The index must be greater than or equal to 0
2316 and less than or equal to the string length.
2317 @return the index of the first occurrence of the character in the
2318 character sequence represented by this string that is
2319 greater than or equal to fromIndex, or
2320 -1 if the character does not occur.
2322 sal_Int32
indexOf( sal_Unicode ch
, sal_Int32 fromIndex
= 0 ) const
2324 assert(fromIndex
>= 0);
2325 sal_Int32 ret
= rtl_ustr_indexOfChar_WithLength( pData
->buffer
+fromIndex
, pData
->length
-fromIndex
, ch
);
2326 return (ret
< 0 ? ret
: ret
+fromIndex
);
2330 Returns the index within this string of the last occurrence of the
2331 specified character, searching backward starting at the end.
2333 @param ch character to be located.
2334 @return the index of the last occurrence of the character in the
2335 character sequence represented by this string, or
2336 -1 if the character does not occur.
2338 sal_Int32
lastIndexOf( sal_Unicode ch
) const
2340 return rtl_ustr_lastIndexOfChar_WithLength( pData
->buffer
, pData
->length
, ch
);
2344 Returns the index within this string of the last occurrence of the
2345 specified character, searching backward starting before the specified
2348 @param ch character to be located.
2349 @param fromIndex the index before which to start the search.
2350 @return the index of the last occurrence of the character in the
2351 character sequence represented by this string that
2352 is less than fromIndex, or -1
2353 if the character does not occur before that point.
2355 sal_Int32
lastIndexOf( sal_Unicode ch
, sal_Int32 fromIndex
) const
2357 return rtl_ustr_lastIndexOfChar_WithLength( pData
->buffer
, fromIndex
, ch
);
2361 Returns the index within this string of the first occurrence of the
2362 specified substring, starting at the specified index.
2364 If str doesn't include any character, always -1 is
2365 returned. This is also the case, if both strings are empty.
2367 @param str the substring to search for.
2368 @param fromIndex the index to start the search from.
2369 @return If the string argument occurs one or more times as a substring
2370 within this string at the starting index, then the index
2371 of the first character of the first such substring is
2372 returned. If it does not occur as a substring starting
2373 at fromIndex or beyond, -1 is returned.
2375 #if defined LIBO_INTERNAL_ONLY
2376 sal_Int32
indexOf(std::u16string_view sv
, sal_Int32 fromIndex
= 0) const {
2377 assert(fromIndex
>= 0);
2378 auto const n
= rtl_ustr_indexOfStr_WithLength(
2379 pData
->buffer
+ fromIndex
, pData
->length
- fromIndex
, sv
.data(), sv
.size());
2380 return n
< 0 ? n
: n
+ fromIndex
;
2383 sal_Int32
indexOf( const OUString
& str
, sal_Int32 fromIndex
= 0 ) const
2385 assert(fromIndex
>= 0);
2386 sal_Int32 ret
= rtl_ustr_indexOfStr_WithLength( pData
->buffer
+fromIndex
, pData
->length
-fromIndex
,
2387 str
.pData
->buffer
, str
.pData
->length
);
2388 return (ret
< 0 ? ret
: ret
+fromIndex
);
2394 This function accepts an ASCII string literal as its argument.
2395 @since LibreOffice 3.6
2397 template< typename T
>
2398 typename
libreoffice_internal::ConstCharArrayDetector
< T
, sal_Int32
>::Type
indexOf( T
& literal
, sal_Int32 fromIndex
= 0 ) const
2401 libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(literal
));
2402 assert(fromIndex
>= 0);
2403 sal_Int32 n
= rtl_ustr_indexOfAscii_WithLength(
2404 pData
->buffer
+ fromIndex
, pData
->length
- fromIndex
,
2405 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(literal
),
2406 libreoffice_internal::ConstCharArrayDetector
<T
>::length
);
2407 return n
< 0 ? n
: n
+ fromIndex
;
2411 Returns the index within this string of the first occurrence of the
2412 specified ASCII substring, starting at the specified index.
2415 the substring to be searched for. Need not be null-terminated, but must
2416 be at least as long as the specified len. Must only contain characters
2417 in the ASCII range 0x00--7F.
2420 the length of the substring; must be non-negative.
2423 the index to start the search from. Must be in the range from zero to
2424 the length of this string, inclusive.
2427 the index (starting at 0) of the first character of the first occurrence
2428 of the substring within this string starting at the given fromIndex, or
2429 -1 if the substring does not occur. If len is zero, -1 is returned.
2433 sal_Int32
indexOfAsciiL(
2434 char const * str
, sal_Int32 len
, sal_Int32 fromIndex
= 0) const
2436 assert(fromIndex
>= 0);
2437 sal_Int32 ret
= rtl_ustr_indexOfAscii_WithLength(
2438 pData
->buffer
+ fromIndex
, pData
->length
- fromIndex
, str
, len
);
2439 return ret
< 0 ? ret
: ret
+ fromIndex
;
2442 // This overload is left undefined, to detect calls of indexOfAsciiL that
2443 // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
2444 // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
2446 #if SAL_TYPES_SIZEOFLONG == 8
2447 void indexOfAsciiL(char const *, sal_Int32 len
, rtl_TextEncoding
) const;
2451 Returns the index within this string of the last occurrence of
2452 the specified substring, searching backward starting at the end.
2454 The returned index indicates the starting index of the substring
2456 If str doesn't include any character, always -1 is
2457 returned. This is also the case, if both strings are empty.
2459 @param str the substring to search for.
2460 @return If the string argument occurs one or more times as a substring
2461 within this string, then the index of the first character of
2462 the last such substring is returned. If it does not occur as
2463 a substring, -1 is returned.
2465 #if defined LIBO_INTERNAL_ONLY
2466 sal_Int32
lastIndexOf(std::u16string_view sv
) const {
2467 return rtl_ustr_lastIndexOfStr_WithLength(
2468 pData
->buffer
, pData
->length
, sv
.data(), sv
.size());
2471 sal_Int32
lastIndexOf( const OUString
& str
) const
2473 return rtl_ustr_lastIndexOfStr_WithLength( pData
->buffer
, pData
->length
,
2474 str
.pData
->buffer
, str
.pData
->length
);
2479 Returns the index within this string of the last occurrence of
2480 the specified substring, searching backward starting before the specified
2483 The returned index indicates the starting index of the substring
2485 If str doesn't include any character, always -1 is
2486 returned. This is also the case, if both strings are empty.
2488 @param str the substring to search for.
2489 @param fromIndex the index before which to start the search.
2490 @return If the string argument occurs one or more times as a substring
2491 within this string before the starting index, then the index
2492 of the first character of the last such substring is
2493 returned. Otherwise, -1 is returned.
2495 #if defined LIBO_INTERNAL_ONLY
2496 sal_Int32
lastIndexOf(std::u16string_view sv
, sal_Int32 fromIndex
) const {
2497 return rtl_ustr_lastIndexOfStr_WithLength(pData
->buffer
, fromIndex
, sv
.data(), sv
.size());
2500 sal_Int32
lastIndexOf( const OUString
& str
, sal_Int32 fromIndex
) const
2502 return rtl_ustr_lastIndexOfStr_WithLength( pData
->buffer
, fromIndex
,
2503 str
.pData
->buffer
, str
.pData
->length
);
2509 This function accepts an ASCII string literal as its argument.
2510 @since LibreOffice 3.6
2512 template< typename T
>
2513 typename
libreoffice_internal::ConstCharArrayDetector
< T
, sal_Int32
>::Type
lastIndexOf( T
& literal
) const
2516 libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(literal
));
2517 return rtl_ustr_lastIndexOfAscii_WithLength(
2518 pData
->buffer
, pData
->length
,
2519 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(literal
),
2520 libreoffice_internal::ConstCharArrayDetector
<T
>::length
);
2524 Returns the index within this string of the last occurrence of the
2525 specified ASCII substring.
2528 the substring to be searched for. Need not be null-terminated, but must
2529 be at least as long as the specified len. Must only contain characters
2530 in the ASCII range 0x00--7F.
2533 the length of the substring; must be non-negative.
2536 the index (starting at 0) of the first character of the last occurrence
2537 of the substring within this string, or -1 if the substring does not
2538 occur. If len is zero, -1 is returned.
2542 sal_Int32
lastIndexOfAsciiL(char const * str
, sal_Int32 len
) const
2544 return rtl_ustr_lastIndexOfAscii_WithLength(
2545 pData
->buffer
, pData
->length
, str
, len
);
2549 Returns a new string that is a substring of this string.
2551 The substring begins at the specified beginIndex. If
2552 beginIndex is negative or be greater than the length of
2553 this string, behaviour is undefined.
2555 @param beginIndex the beginning index, inclusive.
2556 @return the specified substring.
2558 SAL_WARN_UNUSED_RESULT OUString
copy( sal_Int32 beginIndex
) const
2560 return copy(beginIndex
, getLength() - beginIndex
);
2564 Returns a new string that is a substring of this string.
2566 The substring begins at the specified beginIndex and contains count
2567 characters. If either beginIndex or count are negative,
2568 or beginIndex + count are greater than the length of this string
2569 then behaviour is undefined.
2571 @param beginIndex the beginning index, inclusive.
2572 @param count the number of characters.
2573 @return the specified substring.
2575 SAL_WARN_UNUSED_RESULT OUString
copy( sal_Int32 beginIndex
, sal_Int32 count
) const
2577 rtl_uString
*pNew
= NULL
;
2578 rtl_uString_newFromSubString( &pNew
, pData
, beginIndex
, count
);
2579 return OUString( pNew
, SAL_NO_ACQUIRE
);
2582 #if defined LIBO_INTERNAL_ONLY
2584 Returns a std::u16string_view that is a view of a substring of this string.
2586 The substring begins at the specified beginIndex. If
2587 beginIndex is negative or be greater than the length of
2588 this string, behaviour is undefined.
2590 @param beginIndex the beginning index, inclusive.
2591 @return the specified substring.
2593 SAL_WARN_UNUSED_RESULT
std::u16string_view
subView( sal_Int32 beginIndex
) const
2595 assert(beginIndex
>= 0);
2596 assert(beginIndex
<= getLength());
2597 return subView(beginIndex
, getLength() - beginIndex
);
2601 Returns a std::u16string_view that is a view of a substring of this string.
2603 The substring begins at the specified beginIndex and contains count
2604 characters. If either beginIndex or count are negative,
2605 or beginIndex + count are greater than the length of this string
2606 then behaviour is undefined.
2608 @param beginIndex the beginning index, inclusive.
2609 @param count the number of characters.
2610 @return the specified substring.
2612 SAL_WARN_UNUSED_RESULT
std::u16string_view
subView( sal_Int32 beginIndex
, sal_Int32 count
) const
2614 assert(beginIndex
>= 0);
2616 assert(beginIndex
<= getLength());
2617 assert(count
<= getLength() - beginIndex
);
2618 return std::u16string_view(*this).substr(beginIndex
, count
);
2622 #ifndef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
2624 Concatenates the specified string to the end of this string.
2626 @param str the string that is concatenated to the end
2628 @return a string that represents the concatenation of this string
2629 followed by the string argument.
2631 SAL_WARN_UNUSED_RESULT OUString
concat( const OUString
& str
) const
2633 rtl_uString
* pNew
= NULL
;
2634 rtl_uString_newConcat( &pNew
, pData
, str
.pData
);
2635 return OUString( pNew
, SAL_NO_ACQUIRE
);
2639 #ifndef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
2640 friend OUString
operator+( const OUString
& rStr1
, const OUString
& rStr2
)
2642 return rStr1
.concat( rStr2
);
2647 Returns a new string resulting from replacing n = count characters
2648 from position index in this string with newStr.
2650 @param index the replacing index in str.
2651 The index must be greater than or equal to 0 and
2652 less than or equal to the length of the string.
2653 @param count the count of characters that will be replaced
2654 The count must be greater than or equal to 0 and
2655 less than or equal to the length of the string minus index.
2656 @param newStr the new substring.
2657 @return the new string.
2659 SAL_WARN_UNUSED_RESULT OUString
replaceAt( sal_Int32 index
, sal_Int32 count
, const OUString
& newStr
) const
2661 rtl_uString
* pNew
= NULL
;
2662 rtl_uString_newReplaceStrAt( &pNew
, pData
, index
, count
, newStr
.pData
);
2663 return OUString( pNew
, SAL_NO_ACQUIRE
);
2666 #ifdef LIBO_INTERNAL_ONLY
2667 SAL_WARN_UNUSED_RESULT OUString
replaceAt( sal_Int32 index
, sal_Int32 count
, std::u16string_view newStr
) const
2669 rtl_uString
* pNew
= NULL
;
2670 rtl_uString_newReplaceStrAtUtf16L( &pNew
, pData
, index
, count
, newStr
.data(), newStr
.size() );
2671 return OUString( pNew
, SAL_NO_ACQUIRE
);
2674 template <std::size_t N
>
2675 SAL_WARN_UNUSED_RESULT OUString
replaceAt( sal_Int32 index
, sal_Int32 count
, const sal_Unicode (&newStr
)[N
] ) const
2677 return replaceAt(index
, count
, std::u16string_view(newStr
, N
- 1));
2679 template <class T
, std::enable_if_t
<std::is_convertible_v
<T
, std::u16string_view
>, int> = 0>
2680 SAL_WARN_UNUSED_RESULT OUString
replaceAt( sal_Int32 index
, sal_Int32 count
, const T
& newStr
) const
2682 return replaceAt(index
, count
, std::u16string_view(newStr
));
2687 Returns a new string resulting from replacing all occurrences of
2688 oldChar in this string with newChar.
2690 If the character oldChar does not occur in the character sequence
2691 represented by this object, then the string is assigned with
2694 @param oldChar the old character.
2695 @param newChar the new character.
2696 @return a string derived from this string by replacing every
2697 occurrence of oldChar with newChar.
2699 SAL_WARN_UNUSED_RESULT OUString
replace( sal_Unicode oldChar
, sal_Unicode newChar
) const
2701 rtl_uString
* pNew
= NULL
;
2702 rtl_uString_newReplace( &pNew
, pData
, oldChar
, newChar
);
2703 return OUString( pNew
, SAL_NO_ACQUIRE
);
2707 Returns a new string resulting from replacing the first occurrence of a
2708 given substring with another substring.
2710 @param from the substring to be replaced
2712 @param to the replacing substring
2714 @param[in,out] index pointer to a start index; if the pointer is
2715 non-null: upon entry to the function, its value is the index into this
2716 string at which to start searching for the \p from substring, the value
2717 must be non-negative and not greater than this string's length; upon exiting
2718 the function its value is the index into this string at which the
2719 replacement took place or -1 if no replacement took place; if the pointer
2720 is null, searching always starts at index 0
2722 @since LibreOffice 3.6
2724 #if defined LIBO_INTERNAL_ONLY
2725 [[nodiscard
]] OUString
replaceFirst(
2726 std::u16string_view from
, std::u16string_view to
, sal_Int32
* index
= nullptr) const
2728 rtl_uString
* s
= nullptr;
2730 rtl_uString_newReplaceFirstUtf16LUtf16L(
2731 &s
, pData
, from
.data(), from
.size(), to
.data(), to
.size(),
2732 index
== nullptr ? &i
: index
);
2733 return OUString(s
, SAL_NO_ACQUIRE
);
2736 SAL_WARN_UNUSED_RESULT OUString
replaceFirst(
2737 OUString
const & from
, OUString
const & to
, sal_Int32
* index
= NULL
) const
2739 rtl_uString
* s
= NULL
;
2741 rtl_uString_newReplaceFirst(
2742 &s
, pData
, from
.pData
, to
.pData
, index
== NULL
? &i
: index
);
2743 return OUString(s
, SAL_NO_ACQUIRE
);
2748 Returns a new string resulting from replacing the first occurrence of a
2749 given substring with another substring.
2751 @param from ASCII string literal, the substring to be replaced
2753 @param to the replacing substring
2755 @param[in,out] index pointer to a start index; if the pointer is
2756 non-null: upon entry to the function, its value is the index into the this
2757 string at which to start searching for the \p from substring, the value
2758 must be non-negative and not greater than this string's length; upon exiting
2759 the function its value is the index into this string at which the
2760 replacement took place or -1 if no replacement took place; if the pointer
2761 is null, searching always starts at index 0
2763 @since LibreOffice 3.6
2765 #if defined LIBO_INTERNAL_ONLY
2766 template<typename T
> [[nodiscard
]]
2767 typename
libreoffice_internal::ConstCharArrayDetector
<T
, OUString
>::Type
replaceFirst(
2768 T
& from
, std::u16string_view to
, sal_Int32
* index
= nullptr) const
2770 assert(libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(from
));
2771 rtl_uString
* s
= nullptr;
2773 rtl_uString_newReplaceFirstAsciiLUtf16L(
2774 &s
, pData
, libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(from
),
2775 libreoffice_internal::ConstCharArrayDetector
<T
>::length
, to
.data(), to
.size(),
2776 index
== nullptr ? &i
: index
);
2777 return OUString(s
, SAL_NO_ACQUIRE
);
2780 template< typename T
>
2781 SAL_WARN_UNUSED_RESULT typename
libreoffice_internal::ConstCharArrayDetector
< T
, OUString
>::Type
replaceFirst( T
& from
, OUString
const & to
,
2782 sal_Int32
* index
= NULL
) const
2784 assert(libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(from
));
2785 rtl_uString
* s
= NULL
;
2787 rtl_uString_newReplaceFirstAsciiL(
2789 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(from
),
2790 libreoffice_internal::ConstCharArrayDetector
<T
>::length
, to
.pData
,
2791 index
== NULL
? &i
: index
);
2792 return OUString(s
, SAL_NO_ACQUIRE
);
2797 Returns a new string resulting from replacing the first occurrence of a
2798 given substring with another substring.
2800 @param from the substring to be replaced
2802 @param to ASCII string literal, the replacing substring
2804 @param[in,out] index pointer to a start index; if the pointer is
2805 non-null: upon entry to the function, its value is the index into the this
2806 string at which to start searching for the \p from substring, the value
2807 must be non-negative and not greater than this string's length; upon exiting
2808 the function its value is the index into this string at which the
2809 replacement took place or -1 if no replacement took place; if the pointer
2810 is null, searching always starts at index 0
2812 @since LibreOffice 5.1
2814 #if defined LIBO_INTERNAL_ONLY
2815 template<typename T
> [[nodiscard
]]
2816 typename
libreoffice_internal::ConstCharArrayDetector
<T
, OUString
>::Type
replaceFirst(
2817 std::u16string_view from
, T
& to
, sal_Int32
* index
= nullptr) const
2819 assert(libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(to
));
2820 rtl_uString
* s
= nullptr;
2822 rtl_uString_newReplaceFirstUtf16LAsciiL(
2823 &s
, pData
, from
.data(), from
.size(),
2824 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(to
),
2825 libreoffice_internal::ConstCharArrayDetector
<T
>::length
, index
== nullptr ? &i
: index
);
2826 return OUString(s
, SAL_NO_ACQUIRE
);
2829 template< typename T
>
2830 SAL_WARN_UNUSED_RESULT typename
libreoffice_internal::ConstCharArrayDetector
< T
, OUString
>::Type
replaceFirst( OUString
const & from
, T
& to
,
2831 sal_Int32
* index
= NULL
) const
2833 assert(libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(to
));
2834 rtl_uString
* s
= NULL
;
2836 rtl_uString_newReplaceFirstToAsciiL(
2837 &s
, pData
, from
.pData
,
2838 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(to
),
2839 libreoffice_internal::ConstCharArrayDetector
<T
>::length
,
2840 index
== NULL
? &i
: index
);
2841 return OUString(s
, SAL_NO_ACQUIRE
);
2846 Returns a new string resulting from replacing the first occurrence of a
2847 given substring with another substring.
2849 @param from ASCII string literal, the substring to be replaced
2851 @param to ASCII string literal, the substring to be replaced
2853 @param[in,out] index pointer to a start index; if the pointer is
2854 non-null: upon entry to the function, its value is the index into the this
2855 string at which to start searching for the \p from substring, the value
2856 must be non-negative and not greater than this string's length; upon exiting
2857 the function its value is the index into this string at which the
2858 replacement took place or -1 if no replacement took place; if the pointer
2859 is null, searching always starts at index 0
2861 @since LibreOffice 3.6
2863 template< typename T1
, typename T2
>
2864 SAL_WARN_UNUSED_RESULT typename
libreoffice_internal::ConstCharArrayDetector
< T1
, typename
libreoffice_internal::ConstCharArrayDetector
< T2
, OUString
>::Type
>::Type
2865 replaceFirst( T1
& from
, T2
& to
, sal_Int32
* index
= NULL
) const
2867 assert(libreoffice_internal::ConstCharArrayDetector
<T1
>::isValid(from
));
2868 assert(libreoffice_internal::ConstCharArrayDetector
<T2
>::isValid(to
));
2869 rtl_uString
* s
= NULL
;
2871 rtl_uString_newReplaceFirstAsciiLAsciiL(
2873 libreoffice_internal::ConstCharArrayDetector
<T1
>::toPointer(from
),
2874 libreoffice_internal::ConstCharArrayDetector
<T1
>::length
,
2875 libreoffice_internal::ConstCharArrayDetector
<T2
>::toPointer(to
),
2876 libreoffice_internal::ConstCharArrayDetector
<T2
>::length
,
2877 index
== NULL
? &i
: index
);
2878 return OUString(s
, SAL_NO_ACQUIRE
);
2882 Returns a new string resulting from replacing all occurrences of a given
2883 substring with another substring.
2885 Replacing subsequent occurrences picks up only after a given replacement.
2886 That is, replacing from "xa" to "xx" in "xaa" results in "xxa", not "xxx".
2888 @param from the substring to be replaced
2890 @param to the replacing substring
2892 @param fromIndex the position in the string where we will begin searching
2894 @since LibreOffice 4.0
2896 #if defined LIBO_INTERNAL_ONLY
2897 [[nodiscard
]] OUString
replaceAll(
2898 std::u16string_view from
, std::u16string_view to
, sal_Int32 fromIndex
= 0) const
2900 rtl_uString
* s
= nullptr;
2901 rtl_uString_newReplaceAllFromIndexUtf16LUtf16L(
2902 &s
, pData
, from
.data(), from
.size(), to
.data(), to
.size(), fromIndex
);
2903 return OUString(s
, SAL_NO_ACQUIRE
);
2906 SAL_WARN_UNUSED_RESULT OUString
replaceAll(
2907 OUString
const & from
, OUString
const & to
, sal_Int32 fromIndex
= 0) const
2909 rtl_uString
* s
= NULL
;
2910 rtl_uString_newReplaceAllFromIndex(&s
, pData
, from
.pData
, to
.pData
, fromIndex
);
2911 return OUString(s
, SAL_NO_ACQUIRE
);
2916 Returns a new string resulting from replacing all occurrences of a given
2917 substring with another substring.
2919 Replacing subsequent occurrences picks up only after a given replacement.
2920 That is, replacing from "xa" to "xx" in "xaa" results in "xxa", not "xxx".
2922 @param from ASCII string literal, the substring to be replaced
2924 @param to the replacing substring
2926 @since LibreOffice 3.6
2928 #if defined LIBO_INTERNAL_ONLY
2929 template<typename T
> [[nodiscard
]]
2930 typename
libreoffice_internal::ConstCharArrayDetector
<T
, OUString
>::Type
replaceAll(
2931 T
& from
, std::u16string_view to
) const
2933 assert(libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(from
));
2934 rtl_uString
* s
= nullptr;
2935 rtl_uString_newReplaceAllAsciiLUtf16L(
2936 &s
, pData
, libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(from
),
2937 libreoffice_internal::ConstCharArrayDetector
<T
>::length
, to
.data(), to
.size());
2938 return OUString(s
, SAL_NO_ACQUIRE
);
2941 template< typename T
>
2942 SAL_WARN_UNUSED_RESULT typename
libreoffice_internal::ConstCharArrayDetector
< T
, OUString
>::Type
replaceAll( T
& from
, OUString
const & to
) const
2944 assert(libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(from
));
2945 rtl_uString
* s
= NULL
;
2946 rtl_uString_newReplaceAllAsciiL(
2948 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(from
),
2949 libreoffice_internal::ConstCharArrayDetector
<T
>::length
, to
.pData
);
2950 return OUString(s
, SAL_NO_ACQUIRE
);
2955 Returns a new string resulting from replacing all occurrences of a given
2956 substring with another substring.
2958 Replacing subsequent occurrences picks up only after a given replacement.
2959 That is, replacing from "xa" to "xx" in "xaa" results in "xxa", not "xxx".
2961 @param from the substring to be replaced
2963 @param to ASCII string literal, the replacing substring
2965 @since LibreOffice 5.1
2967 #if defined LIBO_INTERNAL_ONLY
2968 template<typename T
> [[nodiscard
]]
2969 typename
libreoffice_internal::ConstCharArrayDetector
<T
, OUString
>::Type
replaceAll(
2970 std::u16string_view from
, T
& to
) const
2972 assert(libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(to
));
2973 rtl_uString
* s
= nullptr;
2974 rtl_uString_newReplaceAllUtf16LAsciiL(
2975 &s
, pData
, from
.data(), from
.size(),
2976 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(to
),
2977 libreoffice_internal::ConstCharArrayDetector
<T
>::length
);
2978 return OUString(s
, SAL_NO_ACQUIRE
);
2981 template< typename T
>
2982 SAL_WARN_UNUSED_RESULT typename
libreoffice_internal::ConstCharArrayDetector
< T
, OUString
>::Type
replaceAll( OUString
const & from
, T
& to
) const
2984 assert(libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(to
));
2985 rtl_uString
* s
= NULL
;
2986 rtl_uString_newReplaceAllToAsciiL(
2987 &s
, pData
, from
.pData
,
2988 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(to
),
2989 libreoffice_internal::ConstCharArrayDetector
<T
>::length
);
2990 return OUString(s
, SAL_NO_ACQUIRE
);
2995 Returns a new string resulting from replacing all occurrences of a given
2996 substring with another substring.
2998 Replacing subsequent occurrences picks up only after a given replacement.
2999 That is, replacing from "xa" to "xx" in "xaa" results in "xxa", not "xxx".
3001 @param from ASCII string literal, the substring to be replaced
3003 @param to ASCII string literal, the substring to be replaced
3005 @since LibreOffice 3.6
3007 template< typename T1
, typename T2
>
3008 SAL_WARN_UNUSED_RESULT typename
libreoffice_internal::ConstCharArrayDetector
< T1
, typename
libreoffice_internal::ConstCharArrayDetector
< T2
, OUString
>::Type
>::Type
3009 replaceAll( T1
& from
, T2
& to
) const
3011 assert(libreoffice_internal::ConstCharArrayDetector
<T1
>::isValid(from
));
3012 assert(libreoffice_internal::ConstCharArrayDetector
<T2
>::isValid(to
));
3013 rtl_uString
* s
= NULL
;
3014 rtl_uString_newReplaceAllAsciiLAsciiL(
3016 libreoffice_internal::ConstCharArrayDetector
<T1
>::toPointer(from
),
3017 libreoffice_internal::ConstCharArrayDetector
<T1
>::length
,
3018 libreoffice_internal::ConstCharArrayDetector
<T2
>::toPointer(to
),
3019 libreoffice_internal::ConstCharArrayDetector
<T2
>::length
);
3020 return OUString(s
, SAL_NO_ACQUIRE
);
3024 Converts from this string all ASCII uppercase characters (65-90)
3025 to ASCII lowercase characters (97-122).
3027 This function can't be used for language specific conversion.
3028 If the string doesn't contain characters which must be converted,
3029 then the new string is assigned with str.
3031 @return the string, converted to ASCII lowercase.
3033 SAL_WARN_UNUSED_RESULT OUString
toAsciiLowerCase() const
3035 rtl_uString
* pNew
= NULL
;
3036 rtl_uString_newToAsciiLowerCase( &pNew
, pData
);
3037 return OUString( pNew
, SAL_NO_ACQUIRE
);
3041 Converts from this string all ASCII lowercase characters (97-122)
3042 to ASCII uppercase characters (65-90).
3044 This function can't be used for language specific conversion.
3045 If the string doesn't contain characters which must be converted,
3046 then the new string is assigned with str.
3048 @return the string, converted to ASCII uppercase.
3050 SAL_WARN_UNUSED_RESULT OUString
toAsciiUpperCase() const
3052 rtl_uString
* pNew
= NULL
;
3053 rtl_uString_newToAsciiUpperCase( &pNew
, pData
);
3054 return OUString( pNew
, SAL_NO_ACQUIRE
);
3058 Returns a new string resulting from removing white space from both ends
3061 All characters that have codes less than or equal to
3062 32 (the space character), and Unicode General Punctuation area Space
3063 and some Control characters are considered to be white space (see
3065 If the string doesn't contain white spaces at both ends,
3066 then the new string is assigned with str.
3068 @return the string, with white space removed from the front and end.
3070 SAL_WARN_UNUSED_RESULT OUString
trim() const
3072 rtl_uString
* pNew
= NULL
;
3073 rtl_uString_newTrim( &pNew
, pData
);
3074 return OUString( pNew
, SAL_NO_ACQUIRE
);
3078 Returns a token in the string.
3081 sal_Int32 nIndex = 0;
3085 OUString aToken = aStr.getToken( 0, ';', nIndex );
3088 while ( nIndex >= 0 );
3090 @param token the number of the token to return
3091 @param cTok the character which separate the tokens.
3092 @param index the position at which the token is searched in the
3094 The index must not be greater than the length of the
3096 This param is set to the position of the
3097 next token or to -1, if it is the last token.
3098 @return the token; if either token or index is negative, an empty token
3099 is returned (and index is set to -1)
3101 OUString
getToken( sal_Int32 token
, sal_Unicode cTok
, sal_Int32
& index
) const
3103 rtl_uString
* pNew
= NULL
;
3104 index
= rtl_uString_getToken( &pNew
, pData
, token
, cTok
, index
);
3105 return OUString( pNew
, SAL_NO_ACQUIRE
);
3109 Returns a token from the string.
3111 The same as getToken(sal_Int32, sal_Unicode, sal_Int32 &), but always
3112 passing in 0 as the start index in the third argument.
3114 @param count the number of the token to return, starting with 0
3115 @param separator the character which separates the tokens
3117 @return the given token, or an empty string
3119 @since LibreOffice 3.6
3121 OUString
getToken(sal_Int32 count
, sal_Unicode separator
) const {
3123 return getToken(count
, separator
, n
);
3127 Returns the Boolean value from this string.
3129 This function can't be used for language specific conversion.
3131 @return true, if the string is 1 or "True" in any ASCII case.
3132 false in any other case.
3134 bool toBoolean() const
3136 return rtl_ustr_toBoolean( pData
->buffer
);
3140 Returns the first character from this string.
3142 @return the first character from this string or 0, if this string
3145 sal_Unicode
toChar() const
3147 return pData
->buffer
[0];
3151 Returns the int32 value from this string.
3153 This function can't be used for language specific conversion.
3155 @param radix the radix (between 2 and 36)
3156 @return the int32 represented from this string.
3157 0 if this string represents no number or one of too large
3160 sal_Int32
toInt32( sal_Int16 radix
= 10 ) const
3162 return rtl_ustr_toInt32( pData
->buffer
, radix
);
3166 Returns the uint32 value from this string.
3168 This function can't be used for language specific conversion.
3170 @param radix the radix (between 2 and 36)
3171 @return the uint32 represented from this string.
3172 0 if this string represents no number or one of too large
3175 @since LibreOffice 4.2
3177 sal_uInt32
toUInt32( sal_Int16 radix
= 10 ) const
3179 return rtl_ustr_toUInt32( pData
->buffer
, radix
);
3183 Returns the int64 value from this string.
3185 This function can't be used for language specific conversion.
3187 @param radix the radix (between 2 and 36)
3188 @return the int64 represented from this string.
3189 0 if this string represents no number or one of too large
3192 sal_Int64
toInt64( sal_Int16 radix
= 10 ) const
3194 return rtl_ustr_toInt64( pData
->buffer
, radix
);
3198 Returns the uint64 value from this string.
3200 This function can't be used for language specific conversion.
3202 @param radix the radix (between 2 and 36)
3203 @return the uint64 represented from this string.
3204 0 if this string represents no number or one of too large
3207 @since LibreOffice 4.1
3209 sal_uInt64
toUInt64( sal_Int16 radix
= 10 ) const
3211 return rtl_ustr_toUInt64( pData
->buffer
, radix
);
3215 Returns the float value from this string.
3217 This function can't be used for language specific conversion.
3219 @return the float represented from this string.
3220 0.0 if this string represents no number.
3222 float toFloat() const
3224 return rtl_ustr_toFloat( pData
->buffer
);
3228 Returns the double value from this string.
3230 This function can't be used for language specific conversion.
3232 @return the double represented from this string.
3233 0.0 if this string represents no number.
3235 double toDouble() const
3237 return rtl_ustr_toDouble( pData
->buffer
);
3242 Return a canonical representation for a string.
3244 A pool of strings, initially empty is maintained privately
3245 by the string class. On invocation, if present in the pool
3246 the original string will be returned. Otherwise this string,
3247 or a copy thereof will be added to the pool and returned.
3250 a version of the string from the pool.
3252 @exception std::bad_alloc is thrown if an out-of-memory condition occurs
3256 OUString
intern() const
3258 rtl_uString
* pNew
= NULL
;
3259 rtl_uString_intern( &pNew
, pData
);
3261 throw std::bad_alloc();
3263 return OUString( pNew
, SAL_NO_ACQUIRE
);
3267 Return a canonical representation for a converted string.
3269 A pool of strings, initially empty is maintained privately
3270 by the string class. On invocation, if present in the pool
3271 the original string will be returned. Otherwise this string,
3272 or a copy thereof will be added to the pool and returned.
3274 @param value a 8-Bit character array.
3275 @param length the number of character which should be converted.
3276 The 8-Bit character array length must be
3277 greater than or equal to this value.
3278 @param encoding the text encoding from which the 8-Bit character
3279 sequence should be converted.
3280 @param convertFlags flags which controls the conversion.
3281 see RTL_TEXTTOUNICODE_FLAGS_...
3282 @param pInfo pointer to return conversion status or NULL.
3285 a version of the converted string from the pool.
3287 @exception std::bad_alloc is thrown if an out-of-memory condition occurs
3291 static OUString
intern( const char * value
, sal_Int32 length
,
3292 rtl_TextEncoding encoding
,
3293 sal_uInt32 convertFlags
= OSTRING_TO_OUSTRING_CVTFLAGS
,
3294 sal_uInt32
*pInfo
= NULL
)
3296 rtl_uString
* pNew
= NULL
;
3297 rtl_uString_internConvert( &pNew
, value
, length
, encoding
,
3298 convertFlags
, pInfo
);
3300 throw std::bad_alloc();
3302 return OUString( pNew
, SAL_NO_ACQUIRE
);
3306 Converts to an OString, signalling failure.
3309 An out parameter receiving the converted OString. Must not be null; the
3310 contents are not modified if conversion fails (convertToOString returns
3314 The text encoding to convert into. Must be an octet encoding (i.e.,
3315 rtl_isOctetTextEncoding(nEncoding) must return true).
3318 A combination of RTL_UNICODETOTEXT_FLAGS that detail how to do the
3319 conversion (see rtl_convertUnicodeToText). RTL_UNICODETOTEXT_FLAGS_FLUSH
3320 need not be included, it is implicitly assumed. Typical uses are either
3321 RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR |
3322 RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR (fail if a Unicode character cannot
3323 be converted to the target nEncoding) or OUSTRING_TO_OSTRING_CVTFLAGS
3324 (make a best efforts conversion).
3327 True if the conversion succeeded, false otherwise.
3329 bool convertToString(OString
* pTarget
, rtl_TextEncoding nEncoding
,
3330 sal_uInt32 nFlags
) const
3332 return rtl_convertUStringToString(&pTarget
->pData
, pData
->buffer
,
3333 pData
->length
, nEncoding
, nFlags
);
3336 /** Iterate through this string based on code points instead of UTF-16 code
3339 See Chapter 3 of The Unicode Standard 5.0 (Addison--Wesley, 2006) for
3340 definitions of the various terms used in this description.
3342 This string is interpreted as a sequence of zero or more UTF-16 code
3343 units. For each index into this sequence (from zero to one less than
3344 the length of the sequence, inclusive), a code point represented
3345 starting at the given index is computed as follows:
3347 - If the UTF-16 code unit addressed by the index constitutes a
3348 well-formed UTF-16 code unit sequence, the computed code point is the
3349 scalar value encoded by that UTF-16 code unit sequence.
3351 - Otherwise, if the index is at least two UTF-16 code units away from
3352 the end of the sequence, and the sequence of two UTF-16 code units
3353 addressed by the index constitutes a well-formed UTF-16 code unit
3354 sequence, the computed code point is the scalar value encoded by that
3355 UTF-16 code unit sequence.
3357 - Otherwise, the computed code point is the UTF-16 code unit addressed
3358 by the index. (This last case catches unmatched surrogates as well as
3359 indices pointing into the middle of surrogate pairs.)
3362 pointer to a UTF-16 based index into this string; must not be null. On
3363 entry, the index must be in the range from zero to the length of this
3364 string (in UTF-16 code units), inclusive. Upon successful return, the
3365 index will be updated to address the UTF-16 code unit that is the given
3366 incrementCodePoints away from the initial index.
3368 @param incrementCodePoints
3369 the number of code points to move the given *indexUtf16. If
3370 non-negative, moving is done after determining the code point at the
3371 index. If negative, moving is done before determining the code point
3372 at the (then updated) index. The value must be such that the resulting
3373 UTF-16 based index is in the range from zero to the length of this
3374 string (in UTF-16 code units), inclusive.
3377 the code point (an integer in the range from 0 to 0x10FFFF, inclusive)
3378 that is represented within this string starting at the index computed as
3379 follows: If incrementCodePoints is non-negative, the index is the
3380 initial value of *indexUtf16; if incrementCodePoints is negative, the
3381 index is the updated value of *indexUtf16. In either case, the computed
3382 index must be in the range from zero to one less than the length of this
3383 string (in UTF-16 code units), inclusive.
3387 sal_uInt32
iterateCodePoints(
3388 sal_Int32
* indexUtf16
, sal_Int32 incrementCodePoints
= 1) const
3390 return rtl_uString_iterateCodePoints(
3391 pData
, indexUtf16
, incrementCodePoints
);
3395 * Convert an OString to an OUString, assuming that the OString is
3399 * an OString to convert
3401 * @since LibreOffice 4.4
3403 #if defined LIBO_INTERNAL_ONLY
3404 static OUString
fromUtf8(std::string_view rSource
)
3407 bool bSuccess
= rtl_convertStringToUString(&aTarget
.pData
,
3410 RTL_TEXTENCODING_UTF8
,
3411 RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR
|RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR
|RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR
);
3417 static OUString
fromUtf8(const OString
& rSource
)
3420 bool bSuccess
= rtl_convertStringToUString(&aTarget
.pData
,
3422 rSource
.getLength(),
3423 RTL_TEXTENCODING_UTF8
,
3424 RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR
|RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR
|RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR
);
3432 * Convert this string to an OString, assuming that the string can be
3433 * UTF-8-encoded successfully.
3435 * In other words, you must not use this method on a random sequence of
3436 * UTF-16 code units, but only at places where it is assumed that the
3437 * content is a proper string.
3439 * @since LibreOffice 4.4
3441 OString
toUtf8() const
3444 bool bSuccess
= rtl_convertUStringToString(&aTarget
.pData
,
3447 RTL_TEXTENCODING_UTF8
,
3448 RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR
|RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR
);
3454 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
3456 static auto number( int i
, sal_Int16 radix
= 10 )
3458 return OUStringNumber
<RTL_USTR_MAX_VALUEOFINT32
>(rtl_ustr_valueOfInt32
, i
, radix
);
3460 static auto number( long long ll
, sal_Int16 radix
= 10 )
3462 return OUStringNumber
<RTL_USTR_MAX_VALUEOFINT64
>(rtl_ustr_valueOfInt64
, ll
, radix
);
3464 static auto number( unsigned long long ll
, sal_Int16 radix
= 10 )
3466 return OUStringNumber
<RTL_USTR_MAX_VALUEOFUINT64
>(rtl_ustr_valueOfUInt64
, ll
, radix
);
3468 static auto number( unsigned int i
, sal_Int16 radix
= 10 )
3470 return number( static_cast< unsigned long long >( i
), radix
);
3472 static auto number( long i
, sal_Int16 radix
= 10)
3474 return number( static_cast< long long >( i
), radix
);
3476 static auto number( unsigned long i
, sal_Int16 radix
= 10 )
3478 return number( static_cast< unsigned long long >( i
), radix
);
3482 Returns the string representation of the integer argument.
3484 This function can't be used for language specific conversion.
3486 @param i an integer value
3487 @param radix the radix (between 2 and 36)
3488 @return a string with the string representation of the argument.
3489 @since LibreOffice 4.1
3491 static OUString
number( int i
, sal_Int16 radix
= 10 )
3493 sal_Unicode aBuf
[RTL_USTR_MAX_VALUEOFINT32
];
3494 return OUString(aBuf
, rtl_ustr_valueOfInt32(aBuf
, i
, radix
));
3497 /// @since LibreOffice 4.1
3498 static OUString
number( unsigned int i
, sal_Int16 radix
= 10 )
3500 return number( static_cast< unsigned long long >( i
), radix
);
3503 /// @since LibreOffice 4.1
3504 static OUString
number( long i
, sal_Int16 radix
= 10)
3506 return number( static_cast< long long >( i
), radix
);
3509 /// @since LibreOffice 4.1
3510 static OUString
number( unsigned long i
, sal_Int16 radix
= 10 )
3512 return number( static_cast< unsigned long long >( i
), radix
);
3515 /// @since LibreOffice 4.1
3516 static OUString
number( long long ll
, sal_Int16 radix
= 10 )
3518 sal_Unicode aBuf
[RTL_USTR_MAX_VALUEOFINT64
];
3519 return OUString(aBuf
, rtl_ustr_valueOfInt64(aBuf
, ll
, radix
));
3522 /// @since LibreOffice 4.1
3523 static OUString
number( unsigned long long ll
, sal_Int16 radix
= 10 )
3525 sal_Unicode aBuf
[RTL_USTR_MAX_VALUEOFUINT64
];
3526 return OUString(aBuf
, rtl_ustr_valueOfUInt64(aBuf
, ll
, radix
));
3531 Returns the string representation of the float argument.
3533 This function can't be used for language specific conversion.
3536 @return a string with the decimal representation of the argument.
3537 @since LibreOffice 4.1
3539 static OUString
number( float f
)
3541 rtl_uString
* pNew
= NULL
;
3542 // Same as rtl::str::valueOfFP, used for rtl_ustr_valueOfFloat
3543 rtl_math_doubleToUString(&pNew
, NULL
, 0, f
, rtl_math_StringFormat_G
,
3544 RTL_USTR_MAX_VALUEOFFLOAT
- SAL_N_ELEMENTS("-x.E-xxx") + 1, '.',
3547 throw std::bad_alloc();
3549 return OUString(pNew
, SAL_NO_ACQUIRE
);
3553 Returns the string representation of the double argument.
3555 This function can't be used for language specific conversion.
3558 @return a string with the decimal representation of the argument.
3559 @since LibreOffice 4.1
3561 static OUString
number( double d
)
3563 rtl_uString
* pNew
= NULL
;
3564 // Same as rtl::str::valueOfFP, used for rtl_ustr_valueOfDouble
3565 rtl_math_doubleToUString(&pNew
, NULL
, 0, d
, rtl_math_StringFormat_G
,
3566 RTL_USTR_MAX_VALUEOFDOUBLE
- SAL_N_ELEMENTS("-x.E-xxx") + 1, '.',
3569 throw std::bad_alloc();
3571 return OUString(pNew
, SAL_NO_ACQUIRE
);
3574 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
3575 static auto boolean(bool b
)
3577 return OUStringNumber
<RTL_USTR_MAX_VALUEOFBOOLEAN
>(rtl_ustr_valueOfBoolean
, b
);
3581 Returns the string representation of the sal_Bool argument.
3583 If the sal_Bool is true, the string "true" is returned.
3584 If the sal_Bool is false, the string "false" is returned.
3585 This function can't be used for language specific conversion.
3587 @param b a sal_Bool.
3588 @return a string with the string representation of the argument.
3589 @deprecated use boolean()
3591 SAL_DEPRECATED("use boolean()") static OUString
valueOf( sal_Bool b
)
3597 Returns the string representation of the boolean argument.
3599 If the argument is true, the string "true" is returned.
3600 If the argument is false, the string "false" is returned.
3601 This function can't be used for language specific conversion.
3604 @return a string with the string representation of the argument.
3605 @since LibreOffice 4.1
3607 static OUString
boolean( bool b
)
3609 sal_Unicode aBuf
[RTL_USTR_MAX_VALUEOFBOOLEAN
];
3610 return OUString(aBuf
, rtl_ustr_valueOfBoolean(aBuf
, b
));
3615 Returns the string representation of the char argument.
3617 @param c a character.
3618 @return a string with the string representation of the argument.
3619 @deprecated use operator, function or constructor taking char or sal_Unicode argument
3621 SAL_DEPRECATED("convert to OUString or use directly") static OUString
valueOf( sal_Unicode c
)
3623 return OUString( &c
, 1 );
3627 Returns the string representation of the int argument.
3629 This function can't be used for language specific conversion.
3632 @param radix the radix (between 2 and 36)
3633 @return a string with the string representation of the argument.
3634 @deprecated use number()
3636 SAL_DEPRECATED("use number()") static OUString
valueOf( sal_Int32 i
, sal_Int16 radix
= 10 )
3638 return number( i
, radix
);
3642 Returns the string representation of the long argument.
3644 This function can't be used for language specific conversion.
3647 @param radix the radix (between 2 and 36)
3648 @return a string with the string representation of the argument.
3649 @deprecated use number()
3651 SAL_DEPRECATED("use number()") static OUString
valueOf( sal_Int64 ll
, sal_Int16 radix
= 10 )
3653 return number( ll
, radix
);
3657 Returns the string representation of the float argument.
3659 This function can't be used for language specific conversion.
3662 @return a string with the string representation of the argument.
3663 @deprecated use number()
3665 SAL_DEPRECATED("use number()") static OUString
valueOf( float f
)
3671 Returns the string representation of the double argument.
3673 This function can't be used for language specific conversion.
3676 @return a string with the string representation of the argument.
3677 @deprecated use number()
3679 SAL_DEPRECATED("use number()") static OUString
valueOf( double d
)
3685 Returns an OUString copied without conversion from an ASCII
3688 Since this method is optimized for performance, the ASCII character
3689 values are not converted in any way. The caller has to make sure that
3690 all ASCII characters are in the allowed range between 0 and 127.
3691 The ASCII string must be NULL-terminated.
3693 Note that for string literals it is simpler and more efficient
3694 to directly use the OUString constructor.
3696 @param value the 8-Bit ASCII character string
3697 @return a string with the string representation of the argument.
3699 static OUString
createFromAscii( const char * value
)
3701 rtl_uString
* pNew
= NULL
;
3702 rtl_uString_newFromAscii( &pNew
, value
);
3703 return OUString( pNew
, SAL_NO_ACQUIRE
);
3706 #if defined LIBO_INTERNAL_ONLY
3707 static OUString
createFromAscii(std::string_view value
) {
3708 rtl_uString
* p
= nullptr;
3709 rtl_uString_newFromLiteral(&p
, value
.data(), value
.size(), 0); //TODO: check for overflow
3710 return OUString(p
, SAL_NO_ACQUIRE
);
3714 #if defined LIBO_INTERNAL_ONLY
3715 operator std::u16string_view() const { return {getStr(), sal_uInt32(getLength())}; }
3718 #if defined LIBO_INTERNAL_ONLY
3719 // A wrapper for the first expression in an
3721 // OUString::Concat(e1) + e2 + ...
3723 // concatenation chain, when neither of the first two e1, e2 is one of our rtl string-related
3724 // classes (so something like
3726 // OUString s = "a" + (b ? std::u16string_view(u"c") : std::u16string_view(u"dd"));
3728 // would not compile):
3729 template<typename T
> [[nodiscard
]] static
3730 OUStringConcat
<OUStringConcatMarker
, T
>
3731 Concat(T
const & value
) { return OUStringConcat
<OUStringConcatMarker
, T
>(value
); }
3733 // This overload is needed so that an argument of type 'char const[N]' ends up as
3734 // 'OUStringConcat<rtl::OUStringConcatMarker, char const[N]>' rather than as
3735 // 'OUStringConcat<rtl::OUStringConcatMarker, char[N]>':
3736 template<typename T
, std::size_t N
> [[nodiscard
]] static
3737 OUStringConcat
<OUStringConcatMarker
, T
[N
]>
3738 Concat(T (& value
)[N
]) { return OUStringConcat
<OUStringConcatMarker
, T
[N
]>(value
); }
3742 OUString
& internalAppend( rtl_uString
* pOtherData
)
3744 rtl_uString
* pNewData
= NULL
;
3745 rtl_uString_newConcat( &pNewData
, pData
, pOtherData
);
3746 if (pNewData
== NULL
) {
3747 throw std::bad_alloc();
3749 rtl_uString_assign(&pData
, pNewData
);
3750 rtl_uString_release(pNewData
);
3756 #if defined LIBO_INTERNAL_ONLY
3757 // Prevent the operator ==/!= overloads with 'sal_Unicode const *' parameter from
3758 // being selected for nonsensical code like
3760 // if (ouIdAttr == nullptr)
3762 void operator ==(OUString
const &, std::nullptr_t
) = delete;
3763 void operator ==(std::nullptr_t
, OUString
const &) = delete;
3764 void operator !=(OUString
const &, std::nullptr_t
) = delete;
3765 void operator !=(std::nullptr_t
, OUString
const &) = delete;
3768 #if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST
3769 inline bool operator ==(OUString
const & lhs
, StringConcatenation
<char16_t
> const & rhs
)
3770 { return lhs
== std::u16string_view(rhs
); }
3771 inline bool operator !=(OUString
const & lhs
, StringConcatenation
<char16_t
> const & rhs
)
3772 { return lhs
!= std::u16string_view(rhs
); }
3773 inline bool operator ==(StringConcatenation
<char16_t
> const & lhs
, OUString
const & rhs
)
3774 { return std::u16string_view(lhs
) == rhs
; }
3775 inline bool operator !=(StringConcatenation
<char16_t
> const & lhs
, OUString
const & rhs
)
3776 { return std::u16string_view(lhs
) != rhs
; }
3779 #if defined LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
3786 struct ToStringHelper
< OUString
>
3788 static std::size_t length( const OUString
& s
) { return s
.getLength(); }
3789 sal_Unicode
* operator() ( sal_Unicode
* buffer
, const OUString
& s
) const { return addDataHelper( buffer
, s
.getStr(), s
.getLength()); }
3795 template<std::size_t N
>
3796 struct ToStringHelper
< OUStringLiteral
<N
> >
3798 static std::size_t length( const OUStringLiteral
<N
>& str
) { return str
.getLength(); }
3799 sal_Unicode
* operator()( sal_Unicode
* buffer
, const OUStringLiteral
<N
>& str
) const { return addDataHelper( buffer
, str
.getStr(), str
.getLength() ); }
3805 template< typename charT
, typename traits
, typename T1
, typename T2
>
3806 inline std::basic_ostream
<charT
, traits
> & operator <<(
3807 std::basic_ostream
<charT
, traits
> & stream
, OUStringConcat
< T1
, T2
>&& concat
)
3809 return stream
<< OUString( std::move(concat
) );
3815 /** A helper to use OUStrings with hash maps.
3817 Instances of this class are unary function objects that can be used as
3818 hash function arguments to std::unordered_map and similar constructs.
3822 /** Compute a hash code for a string.
3828 a hash code for the string. This hash code should not be stored
3829 persistently, as its computation may change in later revisions.
3831 size_t operator()(const OUString
& rString
) const
3832 { return static_cast<size_t>(rString
.hashCode()); }
3835 /* ======================================================================= */
3837 /** Convert an OString to an OUString, using a specific text encoding.
3839 The lengths of the two strings may differ (e.g., for double-byte
3840 encodings, UTF-7, UTF-8).
3843 an OString to convert.
3846 the text encoding to use for conversion.
3849 flags which control the conversion. Either use
3850 OSTRING_TO_OUSTRING_CVTFLAGS, or see
3851 <http://udk.openoffice.org/cpp/man/spec/textconversion.html> for more
3854 #if defined LIBO_INTERNAL_ONLY
3855 inline OUString
OStringToOUString( std::string_view rStr
,
3856 rtl_TextEncoding encoding
,
3857 sal_uInt32 convertFlags
= OSTRING_TO_OUSTRING_CVTFLAGS
)
3859 return OUString( rStr
.data(), rStr
.length(), encoding
, convertFlags
);
3862 inline OUString
OStringToOUString( const OString
& rStr
,
3863 rtl_TextEncoding encoding
,
3864 sal_uInt32 convertFlags
= OSTRING_TO_OUSTRING_CVTFLAGS
)
3866 return OUString( rStr
.getStr(), rStr
.getLength(), encoding
, convertFlags
);
3870 /** Convert an OUString to an OString, using a specific text encoding.
3872 The lengths of the two strings may differ (e.g., for double-byte
3873 encodings, UTF-7, UTF-8).
3876 an OUString to convert.
3879 the text encoding to use for conversion.
3882 flags which control the conversion. Either use
3883 OUSTRING_TO_OSTRING_CVTFLAGS, or see
3884 <http://udk.openoffice.org/cpp/man/spec/textconversion.html> for more
3887 #if defined LIBO_INTERNAL_ONLY
3888 inline OString
OUStringToOString( std::u16string_view rUnicode
,
3889 rtl_TextEncoding encoding
,
3890 sal_uInt32 convertFlags
= OUSTRING_TO_OSTRING_CVTFLAGS
)
3892 return OString( rUnicode
.data(), rUnicode
.length(), encoding
, convertFlags
);
3895 inline OString
OUStringToOString( const OUString
& rUnicode
,
3896 rtl_TextEncoding encoding
,
3897 sal_uInt32 convertFlags
= OUSTRING_TO_OSTRING_CVTFLAGS
)
3899 return OString( rUnicode
.getStr(), rUnicode
.getLength(), encoding
, convertFlags
);
3903 /* ======================================================================= */
3906 Support for rtl::OUString in std::ostream (and thus in
3907 CPPUNIT_ASSERT or SAL_INFO macros, for example).
3909 The rtl::OUString is converted to UTF-8.
3911 @since LibreOffice 3.5.
3913 template< typename charT
, typename traits
>
3914 inline std::basic_ostream
<charT
, traits
> & operator <<(
3915 std::basic_ostream
<charT
, traits
> & stream
, OUString
const & rString
)
3918 OUStringToOString(rString
, RTL_TEXTENCODING_UTF8
);
3919 // best effort; potentially loses data due to conversion failures
3920 // (stray surrogate halves) and embedded null characters
3925 #ifdef RTL_STRING_UNITTEST
3928 typedef rtlunittest::OUString OUString
;
3932 // In internal code, allow to use classes like OUString without having to
3933 // explicitly refer to the rtl namespace, which is kind of superfluous given
3934 // that OUString itself is namespaced by its OU prefix:
3935 #if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST
3936 using ::rtl::OUString
;
3937 using ::rtl::OUStringHash
;
3938 using ::rtl::OStringToOUString
;
3939 using ::rtl::OUStringToOString
;
3940 using ::rtl::OUStringLiteral
;
3941 using ::rtl::OUStringChar
;
3942 using ::rtl::Concat2View
;
3945 #if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
3948 #if defined RTL_STRING_UNITTEST
3953 #if defined RTL_STRING_UNITTEST
3957 operator ""_ustr() { return L
; }
3963 Make OUString hashable by default for use in STL containers.
3965 @since LibreOffice 6.0
3967 #if defined LIBO_INTERNAL_ONLY
3971 struct hash
<::rtl::OUString
>
3973 std::size_t operator()(::rtl::OUString
const & s
) const
3975 if constexpr (sizeof(std::size_t) == 8)
3977 // return a hash that uses the full 64-bit range instead of a 32-bit value
3978 size_t n
= s
.getLength();
3979 for (sal_Int32 i
= 0, len
= s
.getLength(); i
< len
; ++i
)
3984 return std::size_t(s
.hashCode());
3990 #if !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
3992 * static empty string object, handy for returning from functions where the function is
3993 * returning a "const OUString &"
3995 * @since LibreOffice 25.2
3997 static inline constexpr ::rtl::OUString EMPTY_OUSTRING
= u
""_ustr
;
4003 #endif /* _RTL_USTRING_HXX */
4005 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */