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 .
20 #ifndef INCLUDED_RTL_USTRING_HXX
21 #define INCLUDED_RTL_USTRING_HXX
23 #include "sal/config.h"
32 #if defined LIBO_INTERNAL_ONLY
33 #include <string_view>
36 #include "rtl/ustring.h"
37 #include "rtl/string.hxx"
38 #include "rtl/stringutils.hxx"
39 #include "rtl/textenc.h"
41 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
42 #include "rtl/stringconcat.hxx"
45 #ifdef RTL_STRING_UNITTEST
46 extern bool rtl_string_unittest_invalid_conversion
;
49 // The unittest uses slightly different code to help check that the proper
50 // calls are made. The class is put into a different namespace to make
51 // sure the compiler generates a different (if generating also non-inline)
52 // copy of the function and does not merge them together. The class
53 // is "brought" into the proper rtl namespace by a typedef below.
54 #ifdef RTL_STRING_UNITTEST
55 #define rtl rtlunittest
63 #ifdef RTL_STRING_UNITTEST
67 #if defined LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
71 A simple wrapper around string literal.
73 This class is not part of public API and is meant to be used only in LibreOffice code.
74 @since LibreOffice 4.0
76 struct SAL_WARN_UNUSED OUStringLiteral
78 template<typename T
> constexpr OUStringLiteral(
80 typename
libreoffice_internal::ConstCharArrayDetector
<
81 T
, libreoffice_internal::Dummy
>::Type
82 = libreoffice_internal::Dummy()):
83 size(libreoffice_internal::ConstCharArrayDetector
<T
>::length
),
85 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(literal
))
88 libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(literal
));
94 // So we can use this struct in some places interchangeably with OUString
95 constexpr sal_Int32
getLength() const { return size
; }
101 /* ======================================================================= */
104 This String class provides base functionality for C++ like Unicode
105 character array handling. The advantage of this class is that it
106 handles all the memory management for you - and it does it
107 more efficiently. If you assign a string to another string, the
108 data of both strings are shared (without any copy operation or
109 memory allocation) as long as you do not change the string. This class
110 also stores the length of the string, so that many operations are
111 faster than the C-str-functions.
113 This class provides only readonly string handling. So you could create
114 a string and you could only query the content from this string.
115 It provides also functionality to change the string, but this results
116 in every case in a new string instance (in the most cases with a
117 memory allocation). You don't have functionality to change the
118 content of the string. If you want to change the string content, then
119 you should use the OStringBuffer class, which provides these
120 functionalities and avoids too much memory allocation.
122 The design of this class is similar to the string classes in Java so
123 less people should have understanding problems when they use this class.
126 class SAL_WARN_UNUSED SAL_DLLPUBLIC_RTTI OUString
134 New string containing no characters.
139 rtl_uString_new( &pData
);
143 New string from OUString.
145 @param str an OUString.
147 OUString( const OUString
& str
)
150 rtl_uString_acquire( pData
);
153 #ifndef _MSC_VER // TODO?
154 #if defined LIBO_INTERNAL_ONLY
158 @param str an OUString.
159 @since LibreOffice 5.2
161 OUString( OUString
&& str
) noexcept
165 rtl_uString_new( &str
.pData
);
171 New string from OUString data.
173 @param str an OUString data.
175 OUString( rtl_uString
* str
)
178 rtl_uString_acquire( pData
);
181 /** New OUString from OUString data without acquiring it. Takeover of ownership.
183 The SAL_NO_ACQUIRE dummy parameter is only there to distinguish this
184 from other constructors.
189 OUString( rtl_uString
* str
, __sal_NoAcquire
)
193 New string from a single Unicode character.
195 @param value a Unicode character.
197 explicit OUString( sal_Unicode value
)
200 rtl_uString_newFromStr_WithLength( &pData
, &value
, 1 );
203 #if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST_CONCAT
205 // Catch inadvertent conversions to the above ctor (but still allow
206 // construction from char literals):
207 OUString(int) = delete;
208 explicit OUString(char c
):
209 OUString(sal_Unicode(static_cast<unsigned char>(c
)))
215 New string from a Unicode character buffer array.
217 @param value a NULL-terminated Unicode character array.
219 OUString( const sal_Unicode
* value
)
222 rtl_uString_newFromStr( &pData
, value
);
226 New string from a Unicode character buffer array.
228 @param value a Unicode character array.
229 @param length the number of character which should be copied.
230 The character array length must be greater than
231 or equal to this value.
233 OUString( const sal_Unicode
* value
, sal_Int32 length
)
236 rtl_uString_newFromStr_WithLength( &pData
, value
, length
);
240 New string from an 8-Bit string literal that is expected to contain only
241 characters in the ASCII set (i.e. first 128 characters). This constructor
242 allows an efficient and convenient way to create OUString
243 instances from ASCII literals. When creating strings from data that
244 is not pure ASCII, it needs to be converted to OUString by explicitly
245 providing the encoding to use for the conversion.
247 If there are any embedded \0's in the string literal, the result is undefined.
248 Use the overload that explicitly accepts length.
250 @param literal the 8-bit ASCII string literal
252 @since LibreOffice 3.6
254 template< typename T
>
255 OUString( T
& literal
, typename
libreoffice_internal::ConstCharArrayDetector
< T
, libreoffice_internal::Dummy
>::Type
= libreoffice_internal::Dummy() )
258 libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(literal
));
260 if (libreoffice_internal::ConstCharArrayDetector
<T
>::length
== 0) {
261 rtl_uString_new(&pData
);
263 rtl_uString_newFromLiteral(
265 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(
267 libreoffice_internal::ConstCharArrayDetector
<T
>::length
, 0);
269 #ifdef RTL_STRING_UNITTEST
270 rtl_string_unittest_const_literal
= true;
274 #if defined LIBO_INTERNAL_ONLY
275 /** @overload @since LibreOffice 5.3 */
276 template<typename T
> OUString(
278 typename
libreoffice_internal::ConstCharArrayDetector
<
279 T
, libreoffice_internal::Dummy
>::TypeUtf16
280 = libreoffice_internal::Dummy()):
283 if (libreoffice_internal::ConstCharArrayDetector
<T
>::length
== 0) {
284 rtl_uString_new(&pData
);
286 rtl_uString_newFromStr_WithLength(
288 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(
290 libreoffice_internal::ConstCharArrayDetector
<T
>::length
);
295 #ifdef RTL_STRING_UNITTEST
297 * Only used by unittests to detect incorrect conversions.
300 template< typename T
>
301 OUString( T
&, typename
libreoffice_internal::ExceptConstCharArrayDetector
< T
>::Type
= libreoffice_internal::Dummy() )
304 rtl_uString_newFromLiteral( &pData
, "!!br0ken!!", 10, 0 ); // set to garbage
305 rtl_string_unittest_invalid_conversion
= true;
308 * Only used by unittests to detect incorrect conversions.
311 template< typename T
>
312 OUString( const T
&, typename
libreoffice_internal::ExceptCharArrayDetector
< T
>::Type
= libreoffice_internal::Dummy() )
315 rtl_uString_newFromLiteral( &pData
, "!!br0ken!!", 10, 0 ); // set to garbage
316 rtl_string_unittest_invalid_conversion
= true;
320 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
323 New string from an 8-Bit string literal that is expected to contain only
324 characters in the ASCII set (i.e. first 128 characters).
326 This constructor is similar to the "direct template" one, but can be
327 useful in cases where the latter does not work, like in
329 OUString(flag ? "a" : "bb")
333 OUString(flag ? OUStringLiteral("a") : OUStringLiteral("bb"))
335 @since LibreOffice 5.0
337 OUString(OUStringLiteral literal
): pData(NULL
) {
338 rtl_uString_newFromLiteral(&pData
, literal
.data
, literal
.size
, 0);
344 New string from an 8-Bit character buffer array.
346 @param value An 8-Bit character array.
347 @param length The number of character which should be converted.
348 The 8-Bit character array length must be
349 greater than or equal to this value.
350 @param encoding The text encoding from which the 8-Bit character
351 sequence should be converted.
352 @param convertFlags Flags which control the conversion.
353 see RTL_TEXTTOUNICODE_FLAGS_...
355 @exception std::bad_alloc is thrown if an out-of-memory condition occurs
357 OUString( const sal_Char
* value
, sal_Int32 length
,
358 rtl_TextEncoding encoding
,
359 sal_uInt32 convertFlags
= OSTRING_TO_OUSTRING_CVTFLAGS
)
362 rtl_string2UString( &pData
, value
, length
, encoding
, convertFlags
);
364 throw std::bad_alloc();
368 /** Create a new string from an array of Unicode code points.
371 an array of at least codePointCount code points, which each must be in
372 the range from 0 to 0x10FFFF, inclusive. May be null if codePointCount
375 @param codePointCount
376 the non-negative number of code points.
378 @exception std::bad_alloc
379 is thrown if either an out-of-memory condition occurs or the resulting
380 number of UTF-16 code units would have been larger than SAL_MAX_INT32.
385 sal_uInt32
const * codePoints
, sal_Int32 codePointCount
):
388 rtl_uString_newFromCodePoints(&pData
, codePoints
, codePointCount
);
390 throw std::bad_alloc();
394 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
399 template< typename T1
, typename T2
>
400 OUString( OUStringConcat
< T1
, T2
>&& c
)
402 const sal_Int32 l
= c
.length();
403 pData
= rtl_uString_alloc( l
);
406 sal_Unicode
* end
= c
.addData( pData
->buffer
);
409 // TODO realloc in case pData->length is noticeably smaller than l?
417 template< typename T
>
418 OUString( OUStringNumber
< T
>&& n
)
419 : OUString( n
.buf
, n
.length
)
423 #if defined LIBO_INTERNAL_ONLY
424 OUString(std::u16string_view sv
) {
425 if (sv
.size() > sal_uInt32(std::numeric_limits
<sal_Int32
>::max())) {
426 throw std::bad_alloc();
429 rtl_uString_newFromStr_WithLength(&pData
, sv
.data(), sv
.size());
434 Release the string data.
438 rtl_uString_release( pData
);
441 /** Provides an OUString const & passing a storage pointer of an
442 rtl_uString * handle.
443 It is more convenient to use C++ OUString member functions when dealing
444 with rtl_uString * handles. Using this function avoids unnecessary
445 acquire()/release() calls for a temporary OUString object.
450 OUString const & based on given storage
452 static OUString
const & unacquired( rtl_uString
* const * ppHandle
)
453 { return * reinterpret_cast< OUString
const * >( ppHandle
); }
458 @param str an OUString.
460 OUString
& operator=( const OUString
& str
)
462 rtl_uString_assign( &pData
, str
.pData
);
466 #ifndef _MSC_VER // TODO?
467 #if defined LIBO_INTERNAL_ONLY
469 Move assign a new string.
471 @param str an OUString.
472 @since LibreOffice 5.2
474 OUString
& operator=( OUString
&& str
) noexcept
476 rtl_uString_release( pData
);
479 rtl_uString_new( &str
.pData
);
486 Assign a new string from an 8-Bit string literal that is expected to contain only
487 characters in the ASCII set (i.e. first 128 characters). This operator
488 allows an efficient and convenient way to assign OUString
489 instances from ASCII literals. When assigning strings from data that
490 is not pure ASCII, it needs to be converted to OUString by explicitly
491 providing the encoding to use for the conversion.
493 @param literal the 8-bit ASCII string literal
495 @since LibreOffice 3.6
497 template< typename T
>
498 typename
libreoffice_internal::ConstCharArrayDetector
< T
, OUString
& >::Type
operator=( T
& literal
)
501 libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(literal
));
502 if (libreoffice_internal::ConstCharArrayDetector
<T
>::length
== 0) {
503 rtl_uString_new(&pData
);
505 rtl_uString_newFromLiteral(
507 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(
509 libreoffice_internal::ConstCharArrayDetector
<T
>::length
, 0);
514 #if defined LIBO_INTERNAL_ONLY
515 /** @overload @since LibreOffice 5.3 */
518 libreoffice_internal::ConstCharArrayDetector
<T
, OUString
&>::TypeUtf16
519 operator =(T
& literal
) {
520 if (libreoffice_internal::ConstCharArrayDetector
<T
>::length
== 0) {
521 rtl_uString_new(&pData
);
523 rtl_uString_newFromStr_WithLength(
525 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(
527 libreoffice_internal::ConstCharArrayDetector
<T
>::length
);
532 /** @overload @since LibreOffice 5.4 */
533 OUString
& operator =(OUStringLiteral
const & literal
) {
534 if (literal
.size
== 0) {
535 rtl_uString_new(&pData
);
537 rtl_uString_newFromLiteral(&pData
, literal
.data
, literal
.size
, 0);
543 #if defined LIBO_INTERNAL_ONLY
545 Append the contents of an OUStringBuffer to this string.
547 @param str an OUStringBuffer.
549 @exception std::bad_alloc is thrown if an out-of-memory condition occurs
550 @since LibreOffice 6.2
552 inline OUString
& operator+=( const OUStringBuffer
& str
) &;
556 Append a string to this string.
558 @param str an OUString.
560 @exception std::bad_alloc is thrown if an out-of-memory condition occurs
562 OUString
& operator+=( const OUString
& str
)
563 #if defined LIBO_INTERNAL_ONLY
567 return internalAppend(str
.pData
);
569 #if defined LIBO_INTERNAL_ONLY
570 void operator+=(OUString
const &) && = delete;
573 /** Append an ASCII string literal to this string.
575 @param literal an 8-bit ASCII-only string literal
577 @since LibreOffice 5.1
580 typename
libreoffice_internal::ConstCharArrayDetector
<T
, OUString
&>::Type
581 operator +=(T
& literal
)
582 #if defined LIBO_INTERNAL_ONLY
587 libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(literal
));
588 rtl_uString_newConcatAsciiL(
590 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(literal
),
591 libreoffice_internal::ConstCharArrayDetector
<T
>::length
);
594 #if defined LIBO_INTERNAL_ONLY
596 typename
libreoffice_internal::ConstCharArrayDetector
<T
, OUString
&>::Type
597 operator +=(T
&) && = delete;
600 #if defined LIBO_INTERNAL_ONLY
601 /** @overload @since LibreOffice 5.3 */
604 libreoffice_internal::ConstCharArrayDetector
<T
, OUString
&>::TypeUtf16
605 operator +=(T
& literal
) & {
606 rtl_uString_newConcatUtf16L(
608 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(literal
),
609 libreoffice_internal::ConstCharArrayDetector
<T
>::length
);
614 libreoffice_internal::ConstCharArrayDetector
<T
, OUString
&>::TypeUtf16
615 operator +=(T
&) && = delete;
617 /** @overload @since LibreOffice 5.4 */
618 OUString
& operator +=(OUStringLiteral
const & literal
) & {
619 rtl_uString_newConcatAsciiL(&pData
, pData
, literal
.data
, literal
.size
);
622 void operator +=(OUStringLiteral
const &) && = delete;
625 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
630 template< typename T1
, typename T2
>
631 OUString
& operator+=( OUStringConcat
< T1
, T2
>&& c
) & {
632 sal_Int32 l
= c
.length();
636 rtl_uString_ensureCapacity( &pData
, l
);
637 sal_Unicode
* end
= c
.addData( pData
->buffer
+ pData
->length
);
642 template<typename T1
, typename T2
> void operator +=(
643 OUStringConcat
<T1
, T2
> &&) && = delete;
649 template< typename T
>
650 OUString
& operator+=( OUStringNumber
< T
>&& n
) & {
651 sal_Int32 l
= n
.length
;
655 rtl_uString_ensureCapacity( &pData
, l
);
656 sal_Unicode
* end
= addDataHelper( pData
->buffer
+ pData
->length
, n
.buf
, n
.length
);
661 template<typename T
> void operator +=(
662 OUStringNumber
<T
> &&) && = delete;
666 Clears the string, i.e, makes a zero-character string
667 @since LibreOffice 4.4
671 rtl_uString_new( &pData
);
675 Returns the length of this string.
677 The length is equal to the number of Unicode characters in this string.
679 @return the length of the sequence of characters represented by this
682 sal_Int32
getLength() const { return pData
->length
; }
685 Checks if a string is empty.
687 @return true if the string is empty;
690 @since LibreOffice 3.4
694 return pData
->length
== 0;
698 Returns a pointer to the Unicode character buffer for this string.
700 It isn't necessarily NULL terminated.
702 @return a pointer to the Unicode characters buffer for this object.
704 const sal_Unicode
* getStr() const SAL_RETURNS_NONNULL
{ return pData
->buffer
; }
707 Access to individual characters.
709 @param index must be non-negative and less than length.
711 @return the character at the given index.
713 @since LibreOffice 3.5
715 sal_Unicode
operator [](sal_Int32 index
) const {
716 // silence spurious -Werror=strict-overflow warnings from GCC 4.8.2
717 assert(index
>= 0 && static_cast<sal_uInt32
>(index
) < static_cast<sal_uInt32
>(getLength()));
718 return getStr()[index
];
722 Compares two strings.
724 The comparison is based on the numeric value of each character in
725 the strings and return a value indicating their relationship.
726 This function can't be used for language specific sorting.
728 @param str the object to be compared.
729 @return 0 - if both strings are equal
730 < 0 - if this string is less than the string argument
731 > 0 - if this string is greater than the string argument
733 sal_Int32
compareTo( const OUString
& str
) const
735 return rtl_ustr_compare_WithLength( pData
->buffer
, pData
->length
,
736 str
.pData
->buffer
, str
.pData
->length
);
740 Compares two strings with a maximum count of characters.
742 The comparison is based on the numeric value of each character in
743 the strings and return a value indicating their relationship.
744 This function can't be used for language specific sorting.
746 @param str the object to be compared.
747 @param maxLength the maximum count of characters to be compared.
748 @return 0 - if both strings are equal
749 < 0 - if this string is less than the string argument
750 > 0 - if this string is greater than the string argument
754 sal_Int32
compareTo( const OUString
& str
, sal_Int32 maxLength
) const
756 return rtl_ustr_shortenedCompare_WithLength( pData
->buffer
, pData
->length
,
757 str
.pData
->buffer
, str
.pData
->length
, maxLength
);
761 Compares two strings in reverse order.
763 The comparison is based on the numeric value of each character in
764 the strings and return a value indicating their relationship.
765 This function can't be used for language specific sorting.
767 @param str the object to be compared.
768 @return 0 - if both strings are equal
769 < 0 - if this string is less than the string argument
770 > 0 - if this string is greater than the string argument
772 sal_Int32
reverseCompareTo( const OUString
& str
) const
774 return rtl_ustr_reverseCompare_WithLength( pData
->buffer
, pData
->length
,
775 str
.pData
->buffer
, str
.pData
->length
);
780 This function accepts an ASCII string literal as its argument.
781 @since LibreOffice 4.1
783 template< typename T
>
784 typename
libreoffice_internal::ConstCharArrayDetector
< T
, sal_Int32
>::Type
reverseCompareTo( T
& literal
) const
787 libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(literal
));
788 return rtl_ustr_asciil_reverseCompare_WithLength(
789 pData
->buffer
, pData
->length
,
790 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(literal
),
791 libreoffice_internal::ConstCharArrayDetector
<T
>::length
);
794 #if defined LIBO_INTERNAL_ONLY
795 /** @overload @since LibreOffice 5.3 */
798 libreoffice_internal::ConstCharArrayDetector
<T
, sal_Int32
>::TypeUtf16
799 reverseCompareTo(T
& literal
) const {
800 return rtl_ustr_reverseCompare_WithLength(
801 pData
->buffer
, pData
->length
,
802 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(literal
),
803 libreoffice_internal::ConstCharArrayDetector
<T
>::length
);
806 /** @overload @since LibreOffice 5.4 */
807 sal_Int32
reverseCompareTo(OUStringLiteral
const & literal
) const {
808 return rtl_ustr_asciil_reverseCompare_WithLength(
809 pData
->buffer
, pData
->length
, literal
.data
, literal
.size
);
814 Perform a comparison of two strings.
816 The result is true if and only if second string
817 represents the same sequence of characters as the first string.
818 This function can't be used for language specific comparison.
820 @param str the object to be compared.
821 @return true if the strings are equal;
824 bool equals( const OUString
& str
) const
826 if ( pData
->length
!= str
.pData
->length
)
828 if ( pData
== str
.pData
)
830 return rtl_ustr_reverseCompare_WithLength( pData
->buffer
, pData
->length
,
831 str
.pData
->buffer
, str
.pData
->length
) == 0;
835 Perform an ASCII lowercase comparison of two strings.
837 The result is true if and only if second string
838 represents the same sequence of characters as the first string,
840 Character values between 65 and 90 (ASCII A-Z) are interpreted as
841 values between 97 and 122 (ASCII a-z).
842 This function can't be used for language specific comparison.
844 @param str the object to be compared.
845 @return true if the strings are equal;
848 bool equalsIgnoreAsciiCase( const OUString
& str
) const
850 if ( pData
->length
!= str
.pData
->length
)
852 if ( pData
== str
.pData
)
854 return rtl_ustr_compareIgnoreAsciiCase_WithLength( pData
->buffer
, pData
->length
,
855 str
.pData
->buffer
, str
.pData
->length
) == 0;
859 Perform an ASCII lowercase comparison of two strings.
861 Compare the two strings with uppercase ASCII
862 character values between 65 and 90 (ASCII A-Z) interpreted as
863 values between 97 and 122 (ASCII a-z).
864 This function can't be used for language specific comparison.
866 @param str the object to be compared.
867 @return 0 - if both strings are equal
868 < 0 - if this string is less than the string argument
869 > 0 - if this string is greater than the string argument
871 @since LibreOffice 4.0
873 sal_Int32
compareToIgnoreAsciiCase( const OUString
& str
) const
875 return rtl_ustr_compareIgnoreAsciiCase_WithLength( pData
->buffer
, pData
->length
,
876 str
.pData
->buffer
, str
.pData
->length
);
882 This function accepts an ASCII string literal as its argument.
883 @since LibreOffice 3.6
885 template< typename T
>
886 typename
libreoffice_internal::ConstCharArrayDetector
< T
, bool >::Type
equalsIgnoreAsciiCase( T
& literal
) const
889 libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(literal
));
892 == libreoffice_internal::ConstCharArrayDetector
<T
>::length
)
893 && (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength(
894 pData
->buffer
, pData
->length
,
895 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(
900 #if defined LIBO_INTERNAL_ONLY
901 /** @overload @since LibreOffice 5.3 */
903 typename
libreoffice_internal::ConstCharArrayDetector
<T
, bool>::TypeUtf16
904 equalsIgnoreAsciiCase(T
& literal
) const {
906 rtl_ustr_compareIgnoreAsciiCase_WithLength(
907 pData
->buffer
, pData
->length
,
908 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(
910 libreoffice_internal::ConstCharArrayDetector
<T
>::length
)
914 /** @overload @since LibreOffice 5.4 */
915 bool equalsIgnoreAsciiCase(OUStringLiteral
const & literal
) const {
916 return pData
->length
== literal
.size
917 && (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength(
918 pData
->buffer
, pData
->length
, literal
.data
)
924 Match against a substring appearing in this string.
926 The result is true if and only if the second string appears as a substring
927 of this string, at the given position.
928 This function can't be used for language specific comparison.
930 @param str the object (substring) to be compared.
931 @param fromIndex the index to start the comparion from.
932 The index must be greater than or equal to 0
933 and less or equal as the string length.
934 @return true if str match with the characters in the string
935 at the given position;
938 bool match( const OUString
& str
, sal_Int32 fromIndex
= 0 ) const
940 return rtl_ustr_shortenedCompare_WithLength( pData
->buffer
+fromIndex
, pData
->length
-fromIndex
,
941 str
.pData
->buffer
, str
.pData
->length
, str
.pData
->length
) == 0;
946 This function accepts an ASCII string literal as its argument.
947 @since LibreOffice 3.6
949 template< typename T
>
950 typename
libreoffice_internal::ConstCharArrayDetector
< T
, bool >::Type
match( T
& literal
, sal_Int32 fromIndex
= 0 ) const
953 libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(literal
));
955 rtl_ustr_ascii_shortenedCompare_WithLength(
956 pData
->buffer
+fromIndex
, pData
->length
-fromIndex
,
957 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(
959 libreoffice_internal::ConstCharArrayDetector
<T
>::length
)
963 #if defined LIBO_INTERNAL_ONLY
964 /** @overload @since LibreOffice 5.3 */
966 typename
libreoffice_internal::ConstCharArrayDetector
<T
, bool>::TypeUtf16
967 match(T
& literal
, sal_Int32 fromIndex
= 0) const {
968 assert(fromIndex
>= 0);
970 rtl_ustr_shortenedCompare_WithLength(
971 pData
->buffer
+ fromIndex
, pData
->length
- fromIndex
,
972 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(
974 libreoffice_internal::ConstCharArrayDetector
<T
>::length
,
975 libreoffice_internal::ConstCharArrayDetector
<T
>::length
)
979 /** @overload @since LibreOffice 5.4 */
980 bool match(OUStringLiteral
const & literal
, sal_Int32 fromIndex
= 0) const {
982 rtl_ustr_ascii_shortenedCompare_WithLength(
983 pData
->buffer
+ fromIndex
, pData
->length
- fromIndex
,
984 literal
.data
, literal
.size
)
990 Match against a substring appearing in this string, ignoring the case of
993 The result is true if and only if the second string appears as a substring
994 of this string, at the given position.
995 Character values between 65 and 90 (ASCII A-Z) are interpreted as
996 values between 97 and 122 (ASCII a-z).
997 This function can't be used for language specific comparison.
999 @param str the object (substring) to be compared.
1000 @param fromIndex the index to start the comparion from.
1001 The index must be greater than or equal to 0
1002 and less than or equal to the string length.
1003 @return true if str match with the characters in the string
1004 at the given position;
1007 bool matchIgnoreAsciiCase( const OUString
& str
, sal_Int32 fromIndex
= 0 ) const
1009 return rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( pData
->buffer
+fromIndex
, pData
->length
-fromIndex
,
1010 str
.pData
->buffer
, str
.pData
->length
,
1011 str
.pData
->length
) == 0;
1016 This function accepts an ASCII string literal as its argument.
1017 @since LibreOffice 3.6
1019 template< typename T
>
1020 typename
libreoffice_internal::ConstCharArrayDetector
< T
, bool >::Type
matchIgnoreAsciiCase( T
& literal
, sal_Int32 fromIndex
= 0 ) const
1023 libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(literal
));
1025 rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength(
1026 pData
->buffer
+fromIndex
, pData
->length
-fromIndex
,
1027 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(
1029 libreoffice_internal::ConstCharArrayDetector
<T
>::length
)
1033 #if defined LIBO_INTERNAL_ONLY
1034 /** @overload @since LibreOffice 5.3 */
1035 template<typename T
>
1036 typename
libreoffice_internal::ConstCharArrayDetector
<T
, bool>::TypeUtf16
1037 matchIgnoreAsciiCase(T
& literal
, sal_Int32 fromIndex
= 0) const {
1038 assert(fromIndex
>= 0);
1040 rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength(
1041 pData
->buffer
+ fromIndex
, pData
->length
- fromIndex
,
1042 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(
1044 libreoffice_internal::ConstCharArrayDetector
<T
>::length
,
1045 libreoffice_internal::ConstCharArrayDetector
<T
>::length
)
1049 /** @overload @since LibreOffice 5.4 */
1050 bool matchIgnoreAsciiCase(
1051 OUStringLiteral
const & literal
, sal_Int32 fromIndex
= 0) const
1054 rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength(
1055 pData
->buffer
+fromIndex
, pData
->length
-fromIndex
, literal
.data
,
1062 Compares two strings.
1064 The comparison is based on the numeric value of each character in
1065 the strings and return a value indicating their relationship.
1066 Since this method is optimized for performance, the ASCII character
1067 values are not converted in any way. The caller has to make sure that
1068 all ASCII characters are in the allowed range between 0 and 127.
1069 The ASCII string must be NULL-terminated.
1070 This function can't be used for language specific sorting.
1072 @param asciiStr the 8-Bit ASCII character string to be compared.
1073 @return 0 - if both strings are equal
1074 < 0 - if this string is less than the string argument
1075 > 0 - if this string is greater than the string argument
1077 sal_Int32
compareToAscii( const sal_Char
* asciiStr
) const
1079 return rtl_ustr_ascii_compare_WithLength( pData
->buffer
, pData
->length
, asciiStr
);
1083 Compares two strings with a maximum count of characters.
1085 The comparison is based on the numeric value of each character in
1086 the strings and return a value indicating their relationship.
1087 Since this method is optimized for performance, the ASCII character
1088 values are not converted in any way. The caller has to make sure that
1089 all ASCII characters are in the allowed range between 0 and 127.
1090 The ASCII string must be NULL-terminated.
1091 This function can't be used for language specific sorting.
1093 @deprecated This is a confusing overload with unexpectedly different
1094 semantics from the one-parameter form, so it is marked as deprecated.
1095 Practically all uses compare the return value against zero and can thus
1096 be replaced with uses of startsWith.
1098 @param asciiStr the 8-Bit ASCII character string to be compared.
1099 @param maxLength the maximum count of characters to be compared.
1100 @return 0 - if both strings are equal
1101 < 0 - if this string is less than the string argument
1102 > 0 - if this string is greater than the string argument
1105 "replace s1.compareToAscii(s2, strlen(s2)) == 0 with s1.startsWith(s2)")
1106 sal_Int32
compareToAscii( const sal_Char
* asciiStr
, sal_Int32 maxLength
) const
1108 return rtl_ustr_ascii_shortenedCompare_WithLength( pData
->buffer
, pData
->length
,
1109 asciiStr
, maxLength
);
1113 Compares two strings in reverse order.
1115 This could be useful, if normally both strings start with the same
1116 content. The comparison is based on the numeric value of each character
1117 in the strings and return a value indicating their relationship.
1118 Since this method is optimized for performance, the ASCII character
1119 values are not converted in any way. The caller has to make sure that
1120 all ASCII characters are in the allowed range between 0 and 127.
1121 The ASCII string must be NULL-terminated and must be greater than
1122 or equal to asciiStrLength.
1123 This function can't be used for language specific sorting.
1125 @param asciiStr the 8-Bit ASCII character string to be compared.
1126 @param asciiStrLength the length of the ascii string
1127 @return 0 - if both strings are equal
1128 < 0 - if this string is less than the string argument
1129 > 0 - if this string is greater than the string argument
1131 sal_Int32
reverseCompareToAsciiL( const sal_Char
* asciiStr
, sal_Int32 asciiStrLength
) const
1133 return rtl_ustr_asciil_reverseCompare_WithLength( pData
->buffer
, pData
->length
,
1134 asciiStr
, asciiStrLength
);
1138 Perform a comparison of two strings.
1140 The result is true if and only if second string
1141 represents the same sequence of characters as the first string.
1142 Since this method is optimized for performance, the ASCII character
1143 values are not converted in any way. The caller has to make sure that
1144 all ASCII characters are in the allowed range between 0 and 127.
1145 The ASCII string must be NULL-terminated.
1146 This function can't be used for language specific comparison.
1148 @param asciiStr the 8-Bit ASCII character string to be compared.
1149 @return true if the strings are equal;
1152 bool equalsAscii( const sal_Char
* asciiStr
) const
1154 return rtl_ustr_ascii_compare_WithLength( pData
->buffer
, pData
->length
,
1159 Perform a comparison of two strings.
1161 The result is true if and only if second string
1162 represents the same sequence of characters as the first string.
1163 Since this method is optimized for performance, the ASCII character
1164 values are not converted in any way. The caller has to make sure that
1165 all ASCII characters are in the allowed range between 0 and 127.
1166 The ASCII string must be NULL-terminated and must be greater than
1167 or equal to asciiStrLength.
1168 This function can't be used for language specific comparison.
1170 @param asciiStr the 8-Bit ASCII character string to be compared.
1171 @param asciiStrLength the length of the ascii string
1172 @return true if the strings are equal;
1175 bool equalsAsciiL( const sal_Char
* asciiStr
, sal_Int32 asciiStrLength
) const
1177 if ( pData
->length
!= asciiStrLength
)
1180 return rtl_ustr_asciil_reverseEquals_WithLength(
1181 pData
->buffer
, asciiStr
, asciiStrLength
);
1185 Perform an ASCII lowercase comparison of two strings.
1187 The result is true if and only if second string
1188 represents the same sequence of characters as the first string,
1190 Character values between 65 and 90 (ASCII A-Z) are interpreted as
1191 values between 97 and 122 (ASCII a-z).
1192 Since this method is optimized for performance, the ASCII character
1193 values are not converted in any way. The caller has to make sure that
1194 all ASCII characters are in the allowed range between 0 and 127.
1195 The ASCII string must be NULL-terminated.
1196 This function can't be used for language specific comparison.
1198 @param asciiStr the 8-Bit ASCII character string to be compared.
1199 @return true if the strings are equal;
1202 bool equalsIgnoreAsciiCaseAscii( const sal_Char
* asciiStr
) const
1204 return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData
->buffer
, pData
->length
, asciiStr
) == 0;
1208 Compares two ASCII strings ignoring case
1210 The comparison is based on the numeric value of each character in
1211 the strings and return a value indicating their relationship.
1212 Since this method is optimized for performance, the ASCII character
1213 values are not converted in any way. The caller has to make sure that
1214 all ASCII characters are in the allowed range between 0 and 127.
1215 The ASCII string must be NULL-terminated.
1216 This function can't be used for language specific sorting.
1218 @param asciiStr the 8-Bit ASCII character string to be compared.
1219 @return 0 - if both strings are equal
1220 < 0 - if this string is less than the string argument
1221 > 0 - if this string is greater than the string argument
1223 @since LibreOffice 3.5
1225 sal_Int32
compareToIgnoreAsciiCaseAscii( const sal_Char
* asciiStr
) const
1227 return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData
->buffer
, pData
->length
, asciiStr
);
1231 Perform an ASCII lowercase comparison of two strings.
1233 The result is true if and only if second string
1234 represents the same sequence of characters as the first string,
1236 Character values between 65 and 90 (ASCII A-Z) are interpreted as
1237 values between 97 and 122 (ASCII a-z).
1238 Since this method is optimized for performance, the ASCII character
1239 values are not converted in any way. The caller has to make sure that
1240 all ASCII characters are in the allowed range between 0 and 127.
1241 The ASCII string must be NULL-terminated and must be greater than
1242 or equal to asciiStrLength.
1243 This function can't be used for language specific comparison.
1245 @param asciiStr the 8-Bit ASCII character string to be compared.
1246 @param asciiStrLength the length of the ascii string
1247 @return true if the strings are equal;
1250 bool equalsIgnoreAsciiCaseAsciiL( const sal_Char
* asciiStr
, sal_Int32 asciiStrLength
) const
1252 if ( pData
->length
!= asciiStrLength
)
1255 return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData
->buffer
, pData
->length
, asciiStr
) == 0;
1259 Match against a substring appearing in this string.
1261 The result is true if and only if the second string appears as a substring
1262 of this string, at the given position.
1263 Since this method is optimized for performance, the ASCII character
1264 values are not converted in any way. The caller has to make sure that
1265 all ASCII characters are in the allowed range between 0 and 127.
1266 The ASCII string must be NULL-terminated and must be greater than or
1267 equal to asciiStrLength.
1268 This function can't be used for language specific comparison.
1270 @param asciiStr the object (substring) to be compared.
1271 @param asciiStrLength the length of asciiStr.
1272 @param fromIndex the index to start the comparion from.
1273 The index must be greater than or equal to 0
1274 and less than or equal to the string length.
1275 @return true if str match with the characters in the string
1276 at the given position;
1279 bool matchAsciiL( const sal_Char
* asciiStr
, sal_Int32 asciiStrLength
, sal_Int32 fromIndex
= 0 ) const
1281 return rtl_ustr_ascii_shortenedCompare_WithLength( pData
->buffer
+fromIndex
, pData
->length
-fromIndex
,
1282 asciiStr
, asciiStrLength
) == 0;
1285 // This overload is left undefined, to detect calls of matchAsciiL that
1286 // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
1287 // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
1289 #if SAL_TYPES_SIZEOFLONG == 8
1290 void matchAsciiL(char const *, sal_Int32
, rtl_TextEncoding
) const;
1294 Match against a substring appearing in this string, ignoring the case of
1297 The result is true if and only if the second string appears as a substring
1298 of this string, at the given position.
1299 Character values between 65 and 90 (ASCII A-Z) are interpreted as
1300 values between 97 and 122 (ASCII a-z).
1301 Since this method is optimized for performance, the ASCII character
1302 values are not converted in any way. The caller has to make sure that
1303 all ASCII characters are in the allowed range between 0 and 127.
1304 The ASCII string must be NULL-terminated and must be greater than or
1305 equal to asciiStrLength.
1306 This function can't be used for language specific comparison.
1308 @param asciiStr the 8-Bit ASCII character string to be compared.
1309 @param asciiStrLength the length of the ascii string
1310 @param fromIndex the index to start the comparion from.
1311 The index must be greater than or equal to 0
1312 and less than or equal to the string length.
1313 @return true if str match with the characters in the string
1314 at the given position;
1317 bool matchIgnoreAsciiCaseAsciiL( const sal_Char
* asciiStr
, sal_Int32 asciiStrLength
, sal_Int32 fromIndex
= 0 ) const
1319 return rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( pData
->buffer
+fromIndex
, pData
->length
-fromIndex
,
1320 asciiStr
, asciiStrLength
) == 0;
1323 // This overload is left undefined, to detect calls of
1324 // matchIgnoreAsciiCaseAsciiL that erroneously use
1325 // RTL_CONSTASCII_USTRINGPARAM instead of RTL_CONSTASCII_STRINGPARAM (but
1326 // would lead to ambiguities on 32 bit platforms):
1327 #if SAL_TYPES_SIZEOFLONG == 8
1328 void matchIgnoreAsciiCaseAsciiL(char const *, sal_Int32
, rtl_TextEncoding
)
1333 Check whether this string starts with a given substring.
1335 @param str the substring to be compared
1337 @param rest if non-null, and this function returns true, then assign a
1338 copy of the remainder of this string to *rest. Available since
1341 @return true if and only if the given str appears as a substring at the
1342 start of this string
1344 @since LibreOffice 4.0
1346 bool startsWith(OUString
const & str
, OUString
* rest
= NULL
) const {
1347 bool b
= match(str
);
1348 if (b
&& rest
!= NULL
) {
1349 *rest
= copy(str
.getLength());
1356 This function accepts an ASCII string literal as its argument.
1357 @since LibreOffice 4.0
1359 template< typename T
>
1360 typename
libreoffice_internal::ConstCharArrayDetector
< T
, bool >::Type
startsWith(
1361 T
& literal
, OUString
* rest
= NULL
) const
1364 libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(literal
));
1366 = (libreoffice_internal::ConstCharArrayDetector
<T
>::length
1367 <= sal_uInt32(pData
->length
))
1368 && rtl_ustr_asciil_reverseEquals_WithLength(
1370 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(
1372 libreoffice_internal::ConstCharArrayDetector
<T
>::length
);
1373 if (b
&& rest
!= NULL
) {
1375 libreoffice_internal::ConstCharArrayDetector
<T
>::length
);
1380 #if defined LIBO_INTERNAL_ONLY
1381 /** @overload @since LibreOffice 5.3 */
1382 template<typename T
>
1383 typename
libreoffice_internal::ConstCharArrayDetector
<T
, bool>::TypeUtf16
1384 startsWith(T
& literal
, OUString
* rest
= nullptr) const {
1386 = (libreoffice_internal::ConstCharArrayDetector
<T
>::length
1387 <= sal_uInt32(pData
->length
))
1388 && (rtl_ustr_reverseCompare_WithLength(
1390 libreoffice_internal::ConstCharArrayDetector
<T
>::length
,
1391 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(
1393 libreoffice_internal::ConstCharArrayDetector
<T
>::length
)
1395 if (b
&& rest
!= nullptr) {
1397 libreoffice_internal::ConstCharArrayDetector
<T
>::length
);
1402 /** @overload @since LibreOffice 5.4 */
1403 bool startsWith(OUStringLiteral
const & literal
, OUString
* rest
= nullptr)
1406 bool b
= literal
.size
<= pData
->length
1407 && rtl_ustr_asciil_reverseEquals_WithLength(
1408 pData
->buffer
, literal
.data
, literal
.size
);
1409 if (b
&& rest
!= nullptr) {
1410 *rest
= copy(literal
.size
);
1417 Check whether this string starts with a given string, ignoring the case of
1420 Character values between 65 and 90 (ASCII A-Z) are interpreted as
1421 values between 97 and 122 (ASCII a-z).
1422 This function can't be used for language specific comparison.
1424 @param str the substring to be compared
1426 @param rest if non-null, and this function returns true, then assign a
1427 copy of the remainder of this string to *rest. Available since
1430 @return true if and only if the given str appears as a substring at the
1431 start of this string, ignoring the case of ASCII letters ("A"--"Z" and
1434 @since LibreOffice 4.0
1436 bool startsWithIgnoreAsciiCase(OUString
const & str
, OUString
* rest
= NULL
)
1439 bool b
= matchIgnoreAsciiCase(str
);
1440 if (b
&& rest
!= NULL
) {
1441 *rest
= copy(str
.getLength());
1448 This function accepts an ASCII string literal as its argument.
1449 @since LibreOffice 4.0
1451 template< typename T
>
1452 typename
libreoffice_internal::ConstCharArrayDetector
< T
, bool >::Type
1453 startsWithIgnoreAsciiCase(T
& literal
, OUString
* rest
= NULL
) const
1456 libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(literal
));
1458 = (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(
1460 libreoffice_internal::ConstCharArrayDetector
<T
>::length
,
1461 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(
1463 libreoffice_internal::ConstCharArrayDetector
<T
>::length
)
1465 if (b
&& rest
!= NULL
) {
1467 libreoffice_internal::ConstCharArrayDetector
<T
>::length
);
1472 #if defined LIBO_INTERNAL_ONLY
1473 /** @overload @since LibreOffice 5.3 */
1474 template<typename T
>
1475 typename
libreoffice_internal::ConstCharArrayDetector
<T
, bool>::TypeUtf16
1476 startsWithIgnoreAsciiCase(T
& literal
, OUString
* rest
= nullptr) const {
1478 = (libreoffice_internal::ConstCharArrayDetector
<T
>::length
1479 <= sal_uInt32(pData
->length
))
1480 && (rtl_ustr_compareIgnoreAsciiCase_WithLength(
1482 libreoffice_internal::ConstCharArrayDetector
<T
>::length
,
1483 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(
1485 libreoffice_internal::ConstCharArrayDetector
<T
>::length
)
1487 if (b
&& rest
!= nullptr) {
1489 libreoffice_internal::ConstCharArrayDetector
<T
>::length
);
1494 /** @overload @since LibreOffice 5.4 */
1495 bool startsWithIgnoreAsciiCase(
1496 OUStringLiteral
const & literal
, OUString
* rest
= nullptr) const
1499 = (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(
1500 pData
->buffer
, literal
.size
, literal
.data
, literal
.size
)
1502 if (b
&& rest
!= nullptr) {
1503 *rest
= copy(literal
.size
);
1510 Check whether this string ends with a given substring.
1512 @param str the substring to be compared
1514 @param rest if non-null, and this function returns true, then assign a
1515 copy of the remainder of this string to *rest. Available since
1518 @return true if and only if the given str appears as a substring at the
1521 @since LibreOffice 3.6
1523 bool endsWith(OUString
const & str
, OUString
* rest
= NULL
) const {
1524 bool b
= str
.getLength() <= getLength()
1525 && match(str
, getLength() - str
.getLength());
1526 if (b
&& rest
!= NULL
) {
1527 *rest
= copy(0, getLength() - str
.getLength());
1534 This function accepts an ASCII string literal as its argument.
1535 @since LibreOffice 3.6
1537 template< typename T
>
1538 typename
libreoffice_internal::ConstCharArrayDetector
< T
, bool >::Type
1539 endsWith(T
& literal
, OUString
* rest
= NULL
) const
1542 libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(literal
));
1544 = (libreoffice_internal::ConstCharArrayDetector
<T
>::length
1545 <= sal_uInt32(pData
->length
))
1546 && rtl_ustr_asciil_reverseEquals_WithLength(
1547 (pData
->buffer
+ pData
->length
1548 - libreoffice_internal::ConstCharArrayDetector
<T
>::length
),
1549 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(
1551 libreoffice_internal::ConstCharArrayDetector
<T
>::length
);
1552 if (b
&& rest
!= NULL
) {
1556 - libreoffice_internal::ConstCharArrayDetector
<T
>::length
));
1561 #if defined LIBO_INTERNAL_ONLY
1562 /** @overload @since LibreOffice 5.3 */
1563 template<typename T
>
1564 typename
libreoffice_internal::ConstCharArrayDetector
<T
, bool>::TypeUtf16
1565 endsWith(T
& literal
, OUString
* rest
= nullptr) const {
1567 = (libreoffice_internal::ConstCharArrayDetector
<T
>::length
1568 <= sal_uInt32(pData
->length
))
1569 && (rtl_ustr_reverseCompare_WithLength(
1570 (pData
->buffer
+ pData
->length
1571 - libreoffice_internal::ConstCharArrayDetector
<T
>::length
),
1572 libreoffice_internal::ConstCharArrayDetector
<T
>::length
,
1573 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(
1575 libreoffice_internal::ConstCharArrayDetector
<T
>::length
)
1577 if (b
&& rest
!= nullptr) {
1581 - libreoffice_internal::ConstCharArrayDetector
<T
>::length
));
1586 /** @overload @since LibreOffice 5.4 */
1587 bool endsWith(OUStringLiteral
const & literal
, OUString
* rest
= nullptr)
1590 bool b
= literal
.size
<= pData
->length
1591 && rtl_ustr_asciil_reverseEquals_WithLength(
1592 pData
->buffer
+ pData
->length
- literal
.size
,
1593 literal
.data
, literal
.size
);
1594 if (b
&& rest
!= nullptr) {
1595 *rest
= copy(0, (getLength() - literal
.size
));
1602 Check whether this string ends with a given ASCII string.
1604 @param asciiStr a sequence of at least asciiStrLength ASCII characters
1605 (bytes in the range 0x00--0x7F)
1606 @param asciiStrLength the length of asciiStr; must be non-negative
1607 @return true if this string ends with asciiStr; otherwise, false is
1612 bool endsWithAsciiL(char const * asciiStr
, sal_Int32 asciiStrLength
)
1615 return asciiStrLength
<= pData
->length
1616 && rtl_ustr_asciil_reverseEquals_WithLength(
1617 pData
->buffer
+ pData
->length
- asciiStrLength
, asciiStr
,
1622 Check whether this string ends with a given string, ignoring the case of
1625 Character values between 65 and 90 (ASCII A-Z) are interpreted as
1626 values between 97 and 122 (ASCII a-z).
1627 This function can't be used for language specific comparison.
1629 @param str the substring to be compared
1631 @param rest if non-null, and this function returns true, then assign a
1632 copy of the remainder of this string to *rest. Available since
1635 @return true if and only if the given str appears as a substring at the
1636 end of this string, ignoring the case of ASCII letters ("A"--"Z" and
1639 @since LibreOffice 3.6
1641 bool endsWithIgnoreAsciiCase(OUString
const & str
, OUString
* rest
= NULL
) const
1643 bool b
= str
.getLength() <= getLength()
1644 && matchIgnoreAsciiCase(str
, getLength() - str
.getLength());
1645 if (b
&& rest
!= NULL
) {
1646 *rest
= copy(0, getLength() - str
.getLength());
1653 This function accepts an ASCII string literal as its argument.
1654 @since LibreOffice 3.6
1656 template< typename T
>
1657 typename
libreoffice_internal::ConstCharArrayDetector
< T
, bool >::Type
1658 endsWithIgnoreAsciiCase(T
& literal
, OUString
* rest
= NULL
) const
1661 libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(literal
));
1663 = (libreoffice_internal::ConstCharArrayDetector
<T
>::length
1664 <= sal_uInt32(pData
->length
))
1665 && (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(
1666 (pData
->buffer
+ pData
->length
1667 - libreoffice_internal::ConstCharArrayDetector
<T
>::length
),
1668 libreoffice_internal::ConstCharArrayDetector
<T
>::length
,
1669 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(
1671 libreoffice_internal::ConstCharArrayDetector
<T
>::length
)
1673 if (b
&& rest
!= NULL
) {
1677 - libreoffice_internal::ConstCharArrayDetector
<T
>::length
));
1682 #if defined LIBO_INTERNAL_ONLY
1683 /** @overload @since LibreOffice 5.3 */
1684 template<typename T
>
1685 typename
libreoffice_internal::ConstCharArrayDetector
<T
, bool>::TypeUtf16
1686 endsWithIgnoreAsciiCase(T
& literal
, OUString
* rest
= nullptr) const {
1688 = (libreoffice_internal::ConstCharArrayDetector
<T
>::length
1689 <= sal_uInt32(pData
->length
))
1690 && (rtl_ustr_compareIgnoreAsciiCase_WithLength(
1691 (pData
->buffer
+ pData
->length
1692 - libreoffice_internal::ConstCharArrayDetector
<T
>::length
),
1693 libreoffice_internal::ConstCharArrayDetector
<T
>::length
,
1694 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(
1696 libreoffice_internal::ConstCharArrayDetector
<T
>::length
)
1698 if (b
&& rest
!= nullptr) {
1702 - libreoffice_internal::ConstCharArrayDetector
<T
>::length
));
1707 /** @overload @since LibreOffice 5.4 */
1708 bool endsWithIgnoreAsciiCase(
1709 OUStringLiteral
const & literal
, OUString
* rest
= nullptr) const
1711 bool b
= literal
.size
<= pData
->length
1712 && (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(
1713 pData
->buffer
+ pData
->length
- literal
.size
,
1714 literal
.size
, literal
.data
, literal
.size
)
1716 if (b
&& rest
!= nullptr) {
1717 *rest
= copy(0, getLength() - literal
.size
);
1724 Check whether this string ends with a given ASCII string, ignoring the
1725 case of ASCII letters.
1727 @param asciiStr a sequence of at least asciiStrLength ASCII characters
1728 (bytes in the range 0x00--0x7F)
1729 @param asciiStrLength the length of asciiStr; must be non-negative
1730 @return true if this string ends with asciiStr, ignoring the case of ASCII
1731 letters ("A"--"Z" and "a"--"z"); otherwise, false is returned
1733 bool endsWithIgnoreAsciiCaseAsciiL(
1734 char const * asciiStr
, sal_Int32 asciiStrLength
) const
1736 return asciiStrLength
<= pData
->length
1737 && (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(
1738 pData
->buffer
+ pData
->length
- asciiStrLength
,
1739 asciiStrLength
, asciiStr
, asciiStrLength
)
1743 friend bool operator == ( const OUString
& rStr1
, const OUString
& rStr2
)
1744 { return rStr1
.equals(rStr2
); }
1745 friend bool operator == ( const OUString
& rStr1
, const sal_Unicode
* pStr2
)
1746 { return rStr1
.compareTo( pStr2
) == 0; }
1747 friend bool operator == ( const sal_Unicode
* pStr1
, const OUString
& rStr2
)
1748 { return OUString( pStr1
).compareTo( rStr2
) == 0; }
1750 friend bool operator != ( const OUString
& rStr1
, const OUString
& rStr2
)
1751 { return !(operator == ( rStr1
, rStr2
)); }
1752 friend bool operator != ( const OUString
& rStr1
, const sal_Unicode
* pStr2
)
1753 { return !(operator == ( rStr1
, pStr2
)); }
1754 friend bool operator != ( const sal_Unicode
* pStr1
, const OUString
& rStr2
)
1755 { return !(operator == ( pStr1
, rStr2
)); }
1757 friend bool operator < ( const OUString
& rStr1
, const OUString
& rStr2
)
1758 { return rStr1
.compareTo( rStr2
) < 0; }
1759 friend bool operator > ( const OUString
& rStr1
, const OUString
& rStr2
)
1760 { return rStr1
.compareTo( rStr2
) > 0; }
1761 friend bool operator <= ( const OUString
& rStr1
, const OUString
& rStr2
)
1762 { return rStr1
.compareTo( rStr2
) <= 0; }
1763 friend bool operator >= ( const OUString
& rStr1
, const OUString
& rStr2
)
1764 { return rStr1
.compareTo( rStr2
) >= 0; }
1767 * Compare string to an ASCII string literal.
1769 * This operator is equal to calling equalsAsciiL().
1771 * @since LibreOffice 3.6
1773 template< typename T
>
1774 friend typename
libreoffice_internal::ConstCharArrayDetector
< T
, bool >::Type
operator==( const OUString
& rString
, T
& literal
)
1777 libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(literal
));
1778 return rString
.equalsAsciiL(
1779 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(literal
),
1780 libreoffice_internal::ConstCharArrayDetector
<T
>::length
);
1783 * Compare string to an ASCII string literal.
1785 * This operator is equal to calling equalsAsciiL().
1787 * @since LibreOffice 3.6
1789 template< typename T
>
1790 friend typename
libreoffice_internal::ConstCharArrayDetector
< T
, bool >::Type
operator==( T
& literal
, const OUString
& rString
)
1793 libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(literal
));
1794 return rString
.equalsAsciiL(
1795 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(literal
),
1796 libreoffice_internal::ConstCharArrayDetector
<T
>::length
);
1799 * Compare string to an ASCII string literal.
1801 * This operator is equal to calling !equalsAsciiL().
1803 * @since LibreOffice 3.6
1805 template< typename T
>
1806 friend typename
libreoffice_internal::ConstCharArrayDetector
< T
, bool >::Type
operator!=( const OUString
& rString
, T
& literal
)
1809 libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(literal
));
1810 return !rString
.equalsAsciiL(
1811 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(literal
),
1812 libreoffice_internal::ConstCharArrayDetector
<T
>::length
);
1815 * Compare string to an ASCII string literal.
1817 * This operator is equal to calling !equalsAsciiL().
1819 * @since LibreOffice 3.6
1821 template< typename T
>
1822 friend typename
libreoffice_internal::ConstCharArrayDetector
< T
, bool >::Type
operator!=( T
& literal
, const OUString
& rString
)
1825 libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(literal
));
1826 return !rString
.equalsAsciiL(
1827 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(literal
),
1828 libreoffice_internal::ConstCharArrayDetector
<T
>::length
);
1831 #if defined LIBO_INTERNAL_ONLY
1832 /** @overload @since LibreOffice 5.3 */
1833 template<typename T
> friend typename
libreoffice_internal::ConstCharArrayDetector
<T
, bool>::TypeUtf16
1834 operator ==(OUString
& string
, T
& literal
) {
1836 rtl_ustr_reverseCompare_WithLength(
1837 string
.pData
->buffer
, string
.pData
->length
,
1838 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(
1840 libreoffice_internal::ConstCharArrayDetector
<T
>::length
)
1843 /** @overload @since LibreOffice 5.3 */
1844 template<typename T
> friend typename
libreoffice_internal::ConstCharArrayDetector
<T
, bool>::TypeUtf16
1845 operator ==(T
& literal
, OUString
& string
) {
1847 rtl_ustr_reverseCompare_WithLength(
1848 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(
1850 libreoffice_internal::ConstCharArrayDetector
<T
>::length
,
1851 string
.pData
->buffer
, string
.pData
->length
)
1854 /** @overload @since LibreOffice 5.3 */
1855 template<typename T
> friend typename
libreoffice_internal::ConstCharArrayDetector
<T
, bool>::TypeUtf16
1856 operator !=(OUString
& string
, T
& literal
) {
1858 rtl_ustr_reverseCompare_WithLength(
1859 string
.pData
->buffer
, string
.pData
->length
,
1860 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(
1862 libreoffice_internal::ConstCharArrayDetector
<T
>::length
)
1865 /** @overload @since LibreOffice 5.3 */
1866 template<typename T
> friend typename
libreoffice_internal::ConstCharArrayDetector
<T
, bool>::TypeUtf16
1867 operator !=(T
& literal
, OUString
& string
) {
1869 rtl_ustr_reverseCompare_WithLength(
1870 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(
1872 libreoffice_internal::ConstCharArrayDetector
<T
>::length
,
1873 string
.pData
->buffer
, string
.pData
->length
)
1878 #if defined LIBO_INTERNAL_ONLY
1881 /* Comparison between OUString and OUStringLiteral.
1883 @since LibreOffice 5.0
1886 friend bool operator ==(OUString
const & lhs
, OUStringLiteral
const & rhs
) {
1887 return lhs
.equalsAsciiL(rhs
.data
, rhs
.size
);
1890 friend bool operator !=(OUString
const & lhs
, OUStringLiteral
const & rhs
) {
1891 return !lhs
.equalsAsciiL(rhs
.data
, rhs
.size
);
1894 friend bool operator <(OUString
const & lhs
, OUStringLiteral
const & rhs
) {
1896 (rtl_ustr_ascii_compare_WithLength(
1897 lhs
.pData
->buffer
, lhs
.pData
->length
, rhs
.data
))
1901 friend bool operator <=(OUString
const & lhs
, OUStringLiteral
const & rhs
) {
1903 (rtl_ustr_ascii_compare_WithLength(
1904 lhs
.pData
->buffer
, lhs
.pData
->length
, rhs
.data
))
1908 friend bool operator >(OUString
const & lhs
, OUStringLiteral
const & rhs
) {
1910 (rtl_ustr_ascii_compare_WithLength(
1911 lhs
.pData
->buffer
, lhs
.pData
->length
, rhs
.data
))
1915 friend bool operator >=(OUString
const & lhs
, OUStringLiteral
const & rhs
) {
1917 (rtl_ustr_ascii_compare_WithLength(
1918 lhs
.pData
->buffer
, lhs
.pData
->length
, rhs
.data
))
1922 friend bool operator ==(OUStringLiteral
const & lhs
, OUString
const & rhs
) {
1923 return rhs
.equalsAsciiL(lhs
.data
, lhs
.size
);
1926 friend bool operator !=(OUStringLiteral
const & lhs
, OUString
const & rhs
) {
1927 return !rhs
.equalsAsciiL(lhs
.data
, lhs
.size
);
1930 friend bool operator <(OUStringLiteral
const & lhs
, OUString
const & rhs
) {
1932 (rtl_ustr_ascii_compare_WithLength(
1933 rhs
.pData
->buffer
, rhs
.pData
->length
, lhs
.data
))
1937 friend bool operator <=(OUStringLiteral
const & lhs
, OUString
const & rhs
) {
1939 (rtl_ustr_ascii_compare_WithLength(
1940 rhs
.pData
->buffer
, rhs
.pData
->length
, lhs
.data
))
1944 friend bool operator >(OUStringLiteral
const & lhs
, OUString
const & rhs
) {
1946 (rtl_ustr_ascii_compare_WithLength(
1947 rhs
.pData
->buffer
, rhs
.pData
->length
, lhs
.data
))
1951 friend bool operator >=(OUStringLiteral
const & lhs
, OUString
const & rhs
) {
1953 (rtl_ustr_ascii_compare_WithLength(
1954 rhs
.pData
->buffer
, rhs
.pData
->length
, lhs
.data
))
1962 Returns a hashcode for this string.
1964 @return a hash code value for this object.
1966 @see rtl::OUStringHash for convenient use of std::unordered_map
1968 sal_Int32
hashCode() const
1970 return rtl_ustr_hashCode_WithLength( pData
->buffer
, pData
->length
);
1974 Returns the index within this string of the first occurrence of the
1975 specified character, starting the search at the specified index.
1977 @param ch character to be located.
1978 @param fromIndex the index to start the search from.
1979 The index must be greater than or equal to 0
1980 and less than or equal to the string length.
1981 @return the index of the first occurrence of the character in the
1982 character sequence represented by this string that is
1983 greater than or equal to fromIndex, or
1984 -1 if the character does not occur.
1986 sal_Int32
indexOf( sal_Unicode ch
, sal_Int32 fromIndex
= 0 ) const
1988 sal_Int32 ret
= rtl_ustr_indexOfChar_WithLength( pData
->buffer
+fromIndex
, pData
->length
-fromIndex
, ch
);
1989 return (ret
< 0 ? ret
: ret
+fromIndex
);
1993 Returns the index within this string of the last occurrence of the
1994 specified character, searching backward starting at the end.
1996 @param ch character to be located.
1997 @return the index of the last occurrence of the character in the
1998 character sequence represented by this string, or
1999 -1 if the character does not occur.
2001 sal_Int32
lastIndexOf( sal_Unicode ch
) const
2003 return rtl_ustr_lastIndexOfChar_WithLength( pData
->buffer
, pData
->length
, ch
);
2007 Returns the index within this string of the last occurrence of the
2008 specified character, searching backward starting before the specified
2011 @param ch character to be located.
2012 @param fromIndex the index before which to start the search.
2013 @return the index of the last occurrence of the character in the
2014 character sequence represented by this string that
2015 is less than fromIndex, or -1
2016 if the character does not occur before that point.
2018 sal_Int32
lastIndexOf( sal_Unicode ch
, sal_Int32 fromIndex
) const
2020 return rtl_ustr_lastIndexOfChar_WithLength( pData
->buffer
, fromIndex
, ch
);
2024 Returns the index within this string of the first occurrence of the
2025 specified substring, starting at the specified index.
2027 If str doesn't include any character, always -1 is
2028 returned. This is also the case, if both strings are empty.
2030 @param str the substring to search for.
2031 @param fromIndex the index to start the search from.
2032 @return If the string argument occurs one or more times as a substring
2033 within this string at the starting index, then the index
2034 of the first character of the first such substring is
2035 returned. If it does not occur as a substring starting
2036 at fromIndex or beyond, -1 is returned.
2038 sal_Int32
indexOf( const OUString
& str
, sal_Int32 fromIndex
= 0 ) const
2040 sal_Int32 ret
= rtl_ustr_indexOfStr_WithLength( pData
->buffer
+fromIndex
, pData
->length
-fromIndex
,
2041 str
.pData
->buffer
, str
.pData
->length
);
2042 return (ret
< 0 ? ret
: ret
+fromIndex
);
2047 This function accepts an ASCII string literal as its argument.
2048 @since LibreOffice 3.6
2050 template< typename T
>
2051 typename
libreoffice_internal::ConstCharArrayDetector
< T
, sal_Int32
>::Type
indexOf( T
& literal
, sal_Int32 fromIndex
= 0 ) const
2054 libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(literal
));
2055 sal_Int32 n
= rtl_ustr_indexOfAscii_WithLength(
2056 pData
->buffer
+ fromIndex
, pData
->length
- fromIndex
,
2057 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(literal
),
2058 libreoffice_internal::ConstCharArrayDetector
<T
>::length
);
2059 return n
< 0 ? n
: n
+ fromIndex
;
2062 #if defined LIBO_INTERNAL_ONLY
2063 /** @overload @since LibreOffice 5.3 */
2064 template<typename T
>
2066 libreoffice_internal::ConstCharArrayDetector
<T
, sal_Int32
>::TypeUtf16
2067 indexOf(T
& literal
, sal_Int32 fromIndex
= 0) const {
2068 assert(fromIndex
>= 0);
2069 auto n
= rtl_ustr_indexOfStr_WithLength(
2070 pData
->buffer
+ fromIndex
, pData
->length
- fromIndex
,
2071 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(literal
),
2072 libreoffice_internal::ConstCharArrayDetector
<T
>::length
);
2073 return n
< 0 ? n
: n
+ fromIndex
;
2076 /** @overload @since LibreOffice 5.4 */
2077 sal_Int32
indexOf(OUStringLiteral
const & literal
, sal_Int32 fromIndex
= 0)
2080 sal_Int32 n
= rtl_ustr_indexOfAscii_WithLength(
2081 pData
->buffer
+ fromIndex
, pData
->length
- fromIndex
, literal
.data
,
2083 return n
< 0 ? n
: n
+ fromIndex
;
2088 Returns the index within this string of the first occurrence of the
2089 specified ASCII substring, starting at the specified index.
2092 the substring to be searched for. Need not be null-terminated, but must
2093 be at least as long as the specified len. Must only contain characters
2094 in the ASCII range 0x00--7F.
2097 the length of the substring; must be non-negative.
2100 the index to start the search from. Must be in the range from zero to
2101 the length of this string, inclusive.
2104 the index (starting at 0) of the first character of the first occurrence
2105 of the substring within this string starting at the given fromIndex, or
2106 -1 if the substring does not occur. If len is zero, -1 is returned.
2110 sal_Int32
indexOfAsciiL(
2111 char const * str
, sal_Int32 len
, sal_Int32 fromIndex
= 0) const
2113 sal_Int32 ret
= rtl_ustr_indexOfAscii_WithLength(
2114 pData
->buffer
+ fromIndex
, pData
->length
- fromIndex
, str
, len
);
2115 return ret
< 0 ? ret
: ret
+ fromIndex
;
2118 // This overload is left undefined, to detect calls of indexOfAsciiL that
2119 // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
2120 // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
2122 #if SAL_TYPES_SIZEOFLONG == 8
2123 void indexOfAsciiL(char const *, sal_Int32 len
, rtl_TextEncoding
) const;
2127 Returns the index within this string of the last occurrence of
2128 the specified substring, searching backward starting at the end.
2130 The returned index indicates the starting index of the substring
2132 If str doesn't include any character, always -1 is
2133 returned. This is also the case, if both strings are empty.
2135 @param str the substring to search for.
2136 @return If the string argument occurs one or more times as a substring
2137 within this string, then the index of the first character of
2138 the last such substring is returned. If it does not occur as
2139 a substring, -1 is returned.
2141 sal_Int32
lastIndexOf( const OUString
& str
) const
2143 return rtl_ustr_lastIndexOfStr_WithLength( pData
->buffer
, pData
->length
,
2144 str
.pData
->buffer
, str
.pData
->length
);
2148 Returns the index within this string of the last occurrence of
2149 the specified substring, searching backward starting before the specified
2152 The returned index indicates the starting index of the substring
2154 If str doesn't include any character, always -1 is
2155 returned. This is also the case, if both strings are empty.
2157 @param str the substring to search for.
2158 @param fromIndex the index before which to start the search.
2159 @return If the string argument occurs one or more times as a substring
2160 within this string before the starting index, then the index
2161 of the first character of the last such substring is
2162 returned. Otherwise, -1 is returned.
2164 sal_Int32
lastIndexOf( const OUString
& str
, sal_Int32 fromIndex
) const
2166 return rtl_ustr_lastIndexOfStr_WithLength( pData
->buffer
, fromIndex
,
2167 str
.pData
->buffer
, str
.pData
->length
);
2172 This function accepts an ASCII string literal as its argument.
2173 @since LibreOffice 3.6
2175 template< typename T
>
2176 typename
libreoffice_internal::ConstCharArrayDetector
< T
, sal_Int32
>::Type
lastIndexOf( T
& literal
) const
2179 libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(literal
));
2180 return rtl_ustr_lastIndexOfAscii_WithLength(
2181 pData
->buffer
, pData
->length
,
2182 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(literal
),
2183 libreoffice_internal::ConstCharArrayDetector
<T
>::length
);
2186 #if defined LIBO_INTERNAL_ONLY
2187 /** @overload @since LibreOffice 5.3 */
2188 template<typename T
>
2190 libreoffice_internal::ConstCharArrayDetector
<T
, sal_Int32
>::TypeUtf16
2191 lastIndexOf(T
& literal
) const {
2192 return rtl_ustr_lastIndexOfStr_WithLength(
2193 pData
->buffer
, pData
->length
,
2194 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(literal
),
2195 libreoffice_internal::ConstCharArrayDetector
<T
>::length
);
2198 /** @overload @since LibreOffice 5.4 */
2199 sal_Int32
lastIndexOf(OUStringLiteral
const & literal
) const {
2200 return rtl_ustr_lastIndexOfAscii_WithLength(
2201 pData
->buffer
, pData
->length
, literal
.data
, literal
.size
);
2206 Returns the index within this string of the last occurrence of the
2207 specified ASCII substring.
2210 the substring to be searched for. Need not be null-terminated, but must
2211 be at least as long as the specified len. Must only contain characters
2212 in the ASCII range 0x00--7F.
2215 the length of the substring; must be non-negative.
2218 the index (starting at 0) of the first character of the last occurrence
2219 of the substring within this string, or -1 if the substring does not
2220 occur. If len is zero, -1 is returned.
2224 sal_Int32
lastIndexOfAsciiL(char const * str
, sal_Int32 len
) const
2226 return rtl_ustr_lastIndexOfAscii_WithLength(
2227 pData
->buffer
, pData
->length
, str
, len
);
2231 Returns a new string that is a substring of this string.
2233 The substring begins at the specified beginIndex. If
2234 beginIndex is negative or be greater than the length of
2235 this string, behaviour is undefined.
2237 @param beginIndex the beginning index, inclusive.
2238 @return the specified substring.
2240 SAL_WARN_UNUSED_RESULT OUString
copy( sal_Int32 beginIndex
) const
2242 return copy(beginIndex
, getLength() - beginIndex
);
2246 Returns a new string that is a substring of this string.
2248 The substring begins at the specified beginIndex and contains count
2249 characters. If either beginIndex or count are negative,
2250 or beginIndex + count are greater than the length of this string
2251 then behaviour is undefined.
2253 @param beginIndex the beginning index, inclusive.
2254 @param count the number of characters.
2255 @return the specified substring.
2257 SAL_WARN_UNUSED_RESULT OUString
copy( sal_Int32 beginIndex
, sal_Int32 count
) const
2259 rtl_uString
*pNew
= NULL
;
2260 rtl_uString_newFromSubString( &pNew
, pData
, beginIndex
, count
);
2261 return OUString( pNew
, SAL_NO_ACQUIRE
);
2265 Concatenates the specified string to the end of this string.
2267 @param str the string that is concatenated to the end
2269 @return a string that represents the concatenation of this string
2270 followed by the string argument.
2272 SAL_WARN_UNUSED_RESULT OUString
concat( const OUString
& str
) const
2274 rtl_uString
* pNew
= NULL
;
2275 rtl_uString_newConcat( &pNew
, pData
, str
.pData
);
2276 return OUString( pNew
, SAL_NO_ACQUIRE
);
2279 #ifndef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
2280 friend OUString
operator+( const OUString
& rStr1
, const OUString
& rStr2
)
2282 return rStr1
.concat( rStr2
);
2287 Returns a new string resulting from replacing n = count characters
2288 from position index in this string with newStr.
2290 @param index the replacing index in str.
2291 The index must be greater than or equal to 0 and
2292 less than or equal to the length of the string.
2293 @param count the count of characters that will be replaced
2294 The count must be greater than or equal to 0 and
2295 less than or equal to the length of the string minus index.
2296 @param newStr the new substring.
2297 @return the new string.
2299 SAL_WARN_UNUSED_RESULT OUString
replaceAt( sal_Int32 index
, sal_Int32 count
, const OUString
& newStr
) const
2301 rtl_uString
* pNew
= NULL
;
2302 rtl_uString_newReplaceStrAt( &pNew
, pData
, index
, count
, newStr
.pData
);
2303 return OUString( pNew
, SAL_NO_ACQUIRE
);
2307 Returns a new string resulting from replacing all occurrences of
2308 oldChar in this string with newChar.
2310 If the character oldChar does not occur in the character sequence
2311 represented by this object, then the string is assigned with
2314 @param oldChar the old character.
2315 @param newChar the new character.
2316 @return a string derived from this string by replacing every
2317 occurrence of oldChar with newChar.
2319 SAL_WARN_UNUSED_RESULT OUString
replace( sal_Unicode oldChar
, sal_Unicode newChar
) const
2321 rtl_uString
* pNew
= NULL
;
2322 rtl_uString_newReplace( &pNew
, pData
, oldChar
, newChar
);
2323 return OUString( pNew
, SAL_NO_ACQUIRE
);
2327 Returns a new string resulting from replacing the first occurrence of a
2328 given substring with another substring.
2330 @param from the substring to be replaced
2332 @param to the replacing substring
2334 @param[in,out] index pointer to a start index; if the pointer is
2335 non-null: upon entry to the function, its value is the index into this
2336 string at which to start searching for the \p from substring, the value
2337 must be non-negative and not greater than this string's length; upon exiting
2338 the function its value is the index into this string at which the
2339 replacement took place or -1 if no replacement took place; if the pointer
2340 is null, searching always starts at index 0
2342 @since LibreOffice 3.6
2344 SAL_WARN_UNUSED_RESULT OUString
replaceFirst(
2345 OUString
const & from
, OUString
const & to
, sal_Int32
* index
= NULL
) const
2347 rtl_uString
* s
= NULL
;
2349 rtl_uString_newReplaceFirst(
2350 &s
, pData
, from
.pData
, to
.pData
, index
== NULL
? &i
: index
);
2351 return OUString(s
, SAL_NO_ACQUIRE
);
2355 Returns a new string resulting from replacing the first occurrence of a
2356 given substring with another substring.
2358 @param from ASCII string literal, the substring to be replaced
2360 @param to the replacing substring
2362 @param[in,out] index pointer to a start index; if the pointer is
2363 non-null: upon entry to the function, its value is the index into the this
2364 string at which to start searching for the \p from substring, the value
2365 must be non-negative and not greater than this string's length; upon exiting
2366 the function its value is the index into this string at which the
2367 replacement took place or -1 if no replacement took place; if the pointer
2368 is null, searching always starts at index 0
2370 @since LibreOffice 3.6
2372 template< typename T
>
2373 SAL_WARN_UNUSED_RESULT typename
libreoffice_internal::ConstCharArrayDetector
< T
, OUString
>::Type
replaceFirst( T
& from
, OUString
const & to
,
2374 sal_Int32
* index
= NULL
) const
2376 assert(libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(from
));
2377 rtl_uString
* s
= NULL
;
2379 rtl_uString_newReplaceFirstAsciiL(
2381 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(from
),
2382 libreoffice_internal::ConstCharArrayDetector
<T
>::length
, to
.pData
,
2383 index
== NULL
? &i
: index
);
2384 return OUString(s
, SAL_NO_ACQUIRE
);
2388 Returns a new string resulting from replacing the first occurrence of a
2389 given substring with another substring.
2391 @param from the substring to be replaced
2393 @param to ASCII string literal, the replacing substring
2395 @param[in,out] index pointer to a start index; if the pointer is
2396 non-null: upon entry to the function, its value is the index into the this
2397 string at which to start searching for the \p from substring, the value
2398 must be non-negative and not greater than this string's length; upon exiting
2399 the function its value is the index into this string at which the
2400 replacement took place or -1 if no replacement took place; if the pointer
2401 is null, searching always starts at index 0
2403 @since LibreOffice 5.1
2405 template< typename T
>
2406 SAL_WARN_UNUSED_RESULT typename
libreoffice_internal::ConstCharArrayDetector
< T
, OUString
>::Type
replaceFirst( OUString
const & from
, T
& to
,
2407 sal_Int32
* index
= NULL
) const
2409 assert(libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(to
));
2410 rtl_uString
* s
= NULL
;
2412 rtl_uString_newReplaceFirstToAsciiL(
2413 &s
, pData
, from
.pData
,
2414 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(to
),
2415 libreoffice_internal::ConstCharArrayDetector
<T
>::length
,
2416 index
== NULL
? &i
: index
);
2417 return OUString(s
, SAL_NO_ACQUIRE
);
2421 Returns a new string resulting from replacing the first occurrence of a
2422 given substring with another substring.
2424 @param from ASCII string literal, the substring to be replaced
2426 @param to ASCII string literal, the substring to be replaced
2428 @param[in,out] index pointer to a start index; if the pointer is
2429 non-null: upon entry to the function, its value is the index into the this
2430 string at which to start searching for the \p from substring, the value
2431 must be non-negative and not greater than this string's length; upon exiting
2432 the function its value is the index into this string at which the
2433 replacement took place or -1 if no replacement took place; if the pointer
2434 is null, searching always starts at index 0
2436 @since LibreOffice 3.6
2438 template< typename T1
, typename T2
>
2439 SAL_WARN_UNUSED_RESULT typename
libreoffice_internal::ConstCharArrayDetector
< T1
, typename
libreoffice_internal::ConstCharArrayDetector
< T2
, OUString
>::Type
>::Type
2440 replaceFirst( T1
& from
, T2
& to
, sal_Int32
* index
= NULL
) const
2442 assert(libreoffice_internal::ConstCharArrayDetector
<T1
>::isValid(from
));
2443 assert(libreoffice_internal::ConstCharArrayDetector
<T2
>::isValid(to
));
2444 rtl_uString
* s
= NULL
;
2446 rtl_uString_newReplaceFirstAsciiLAsciiL(
2448 libreoffice_internal::ConstCharArrayDetector
<T1
>::toPointer(from
),
2449 libreoffice_internal::ConstCharArrayDetector
<T1
>::length
,
2450 libreoffice_internal::ConstCharArrayDetector
<T2
>::toPointer(to
),
2451 libreoffice_internal::ConstCharArrayDetector
<T2
>::length
,
2452 index
== NULL
? &i
: index
);
2453 return OUString(s
, SAL_NO_ACQUIRE
);
2456 #if defined LIBO_INTERNAL_ONLY
2457 /** @overload @since LibreOffice 5.3 */
2458 template<typename T
> [[nodiscard
]]
2460 libreoffice_internal::ConstCharArrayDetector
<T
, OUString
>::TypeUtf16
2461 replaceFirst(T
& from
, OUString
const & to
, sal_Int32
* index
= nullptr)
2464 rtl_uString
* s
= nullptr;
2466 rtl_uString_newReplaceFirstUtf16LUtf16L(
2468 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(from
),
2469 libreoffice_internal::ConstCharArrayDetector
<T
>::length
,
2470 to
.pData
->buffer
, to
.pData
->length
, index
== nullptr ? &i
: index
);
2472 throw std::bad_alloc();
2473 // should be std::length_error if resulting would be too large
2475 return OUString(s
, SAL_NO_ACQUIRE
);
2477 /** @overload @since LibreOffice 5.3 */
2478 template<typename T
> [[nodiscard
]]
2480 libreoffice_internal::ConstCharArrayDetector
<T
, OUString
>::TypeUtf16
2481 replaceFirst(OUString
const & from
, T
& to
, sal_Int32
* index
= nullptr)
2484 rtl_uString
* s
= nullptr;
2486 rtl_uString_newReplaceFirstUtf16LUtf16L(
2487 &s
, pData
, from
.pData
->buffer
, from
.pData
->length
,
2488 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(to
),
2489 libreoffice_internal::ConstCharArrayDetector
<T
>::length
,
2490 index
== nullptr ? &i
: index
);
2492 throw std::bad_alloc();
2493 // should be std::length_error if resulting would be too large
2495 return OUString(s
, SAL_NO_ACQUIRE
);
2497 /** @overload @since LibreOffice 5.3 */
2498 template<typename T1
, typename T2
> [[nodiscard
]]
2500 libreoffice_internal::ConstCharArrayDetector
<
2502 typename
libreoffice_internal::ConstCharArrayDetector
<
2503 T2
, OUString
>::TypeUtf16
2505 replaceFirst(T1
& from
, T2
& to
, sal_Int32
* index
= nullptr) const {
2506 rtl_uString
* s
= nullptr;
2508 rtl_uString_newReplaceFirstUtf16LUtf16L(
2510 libreoffice_internal::ConstCharArrayDetector
<T1
>::toPointer(from
),
2511 libreoffice_internal::ConstCharArrayDetector
<T1
>::length
,
2512 libreoffice_internal::ConstCharArrayDetector
<T2
>::toPointer(to
),
2513 libreoffice_internal::ConstCharArrayDetector
<T2
>::length
,
2514 index
== nullptr ? &i
: index
);
2516 throw std::bad_alloc();
2517 // should be std::length_error if resulting would be too large
2519 return OUString(s
, SAL_NO_ACQUIRE
);
2521 /** @overload @since LibreOffice 5.3 */
2522 template<typename T1
, typename T2
> [[nodiscard
]]
2524 libreoffice_internal::ConstCharArrayDetector
<
2526 typename
libreoffice_internal::ConstCharArrayDetector
<
2529 replaceFirst(T1
& from
, T2
& to
, sal_Int32
* index
= nullptr) const {
2530 rtl_uString
* s
= nullptr;
2532 rtl_uString_newReplaceFirstUtf16LAsciiL(
2534 libreoffice_internal::ConstCharArrayDetector
<T1
>::toPointer(from
),
2535 libreoffice_internal::ConstCharArrayDetector
<T1
>::length
,
2536 libreoffice_internal::ConstCharArrayDetector
<T2
>::toPointer(to
),
2537 libreoffice_internal::ConstCharArrayDetector
<T2
>::length
,
2538 index
== nullptr ? &i
: index
);
2540 throw std::bad_alloc();
2541 // should be std::length_error if resulting would be too large
2543 return OUString(s
, SAL_NO_ACQUIRE
);
2545 /** @overload @since LibreOffice 5.3 */
2546 template<typename T1
, typename T2
> [[nodiscard
]]
2548 libreoffice_internal::ConstCharArrayDetector
<
2550 typename
libreoffice_internal::ConstCharArrayDetector
<
2551 T2
, OUString
>::TypeUtf16
2553 replaceFirst(T1
& from
, T2
& to
, sal_Int32
* index
= nullptr) const {
2554 rtl_uString
* s
= nullptr;
2556 rtl_uString_newReplaceFirstAsciiLUtf16L(
2558 libreoffice_internal::ConstCharArrayDetector
<T1
>::toPointer(from
),
2559 libreoffice_internal::ConstCharArrayDetector
<T1
>::length
,
2560 libreoffice_internal::ConstCharArrayDetector
<T2
>::toPointer(to
),
2561 libreoffice_internal::ConstCharArrayDetector
<T2
>::length
,
2562 index
== nullptr ? &i
: index
);
2564 throw std::bad_alloc();
2565 // should be std::length_error if resulting would be too large
2567 return OUString(s
, SAL_NO_ACQUIRE
);
2570 /** @overload @since LibreOffice 5.4 */
2571 [[nodiscard
]] OUString
replaceFirst(
2572 OUStringLiteral
const & from
, OUString
const & to
,
2573 sal_Int32
* index
= nullptr) const
2575 rtl_uString
* s
= nullptr;
2577 rtl_uString_newReplaceFirstAsciiL(
2578 &s
, pData
, from
.data
, from
.size
, to
.pData
,
2579 index
== nullptr ? &i
: index
);
2580 return OUString(s
, SAL_NO_ACQUIRE
);
2582 /** @overload @since LibreOffice 5.4 */
2583 [[nodiscard
]] OUString
replaceFirst(
2584 OUString
const & from
, OUStringLiteral
const & to
,
2585 sal_Int32
* index
= nullptr) const
2587 rtl_uString
* s
= nullptr;
2589 rtl_uString_newReplaceFirstToAsciiL(
2590 &s
, pData
, from
.pData
, to
.data
, to
.size
,
2591 index
== nullptr ? &i
: index
);
2592 return OUString(s
, SAL_NO_ACQUIRE
);
2594 /** @overload @since LibreOffice 5.4 */
2595 [[nodiscard
]] OUString
replaceFirst(
2596 OUStringLiteral
const & from
, OUStringLiteral
const & to
,
2597 sal_Int32
* index
= nullptr) const
2599 rtl_uString
* s
= nullptr;
2601 rtl_uString_newReplaceFirstAsciiLAsciiL(
2602 &s
, pData
, from
.data
, from
.size
, to
.data
, to
.size
,
2603 index
== nullptr ? &i
: index
);
2604 return OUString(s
, SAL_NO_ACQUIRE
);
2606 /** @overload @since LibreOffice 5.4 */
2607 template<typename T
> [[nodiscard
]]
2608 typename
libreoffice_internal::ConstCharArrayDetector
<T
, OUString
>::Type
2610 OUStringLiteral
const & from
, T
& to
, sal_Int32
* index
= nullptr) const
2612 assert(libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(to
));
2613 rtl_uString
* s
= nullptr;
2615 rtl_uString_newReplaceFirstAsciiLAsciiL(
2616 &s
, pData
, from
.data
, from
.size
,
2617 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(to
),
2618 libreoffice_internal::ConstCharArrayDetector
<T
>::length
,
2619 index
== nullptr ? &i
: index
);
2620 return OUString(s
, SAL_NO_ACQUIRE
);
2622 /** @overload @since LibreOffice 5.4 */
2623 template<typename T
> [[nodiscard
]]
2624 typename
libreoffice_internal::ConstCharArrayDetector
<T
, OUString
>::Type
2626 T
& from
, OUStringLiteral
const & to
, sal_Int32
* index
= nullptr) const
2628 assert(libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(from
));
2629 rtl_uString
* s
= nullptr;
2631 rtl_uString_newReplaceFirstAsciiLAsciiL(
2633 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(from
),
2634 libreoffice_internal::ConstCharArrayDetector
<T
>::length
, to
.data
,
2635 to
.size
, index
== nullptr ? &i
: index
);
2636 return OUString(s
, SAL_NO_ACQUIRE
);
2638 /** @overload @since LibreOffice 5.4 */
2639 template<typename T
> [[nodiscard
]]
2641 libreoffice_internal::ConstCharArrayDetector
<T
, OUString
>::TypeUtf16
2643 OUStringLiteral
const & from
, T
& to
, sal_Int32
* index
= nullptr) const
2645 assert(libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(to
));
2646 rtl_uString
* s
= nullptr;
2648 rtl_uString_newReplaceFirstAsciiLUtf16L(
2649 &s
, pData
, from
.data
, from
.size
,
2650 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(to
),
2651 libreoffice_internal::ConstCharArrayDetector
<T
>::length
,
2652 index
== nullptr ? &i
: index
);
2653 return OUString(s
, SAL_NO_ACQUIRE
);
2655 /** @overload @since LibreOffice 5.4 */
2656 template<typename T
> [[nodiscard
]]
2658 libreoffice_internal::ConstCharArrayDetector
<T
, OUString
>::TypeUtf16
2660 T
& from
, OUStringLiteral
const & to
, sal_Int32
* index
= nullptr) const
2662 assert(libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(from
));
2663 rtl_uString
* s
= nullptr;
2665 rtl_uString_newReplaceFirstUtf16LAsciiL(
2667 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(from
),
2668 libreoffice_internal::ConstCharArrayDetector
<T
>::length
, to
.data
,
2669 to
.size
, index
== nullptr ? &i
: index
);
2670 return OUString(s
, SAL_NO_ACQUIRE
);
2675 Returns a new string resulting from replacing all occurrences of a given
2676 substring with another substring.
2678 Replacing subsequent occurrences picks up only after a given replacement.
2679 That is, replacing from "xa" to "xx" in "xaa" results in "xxa", not "xxx".
2681 @param from the substring to be replaced
2683 @param to the replacing substring
2685 @param fromIndex the position in the string where we will begin searching
2687 @since LibreOffice 4.0
2689 SAL_WARN_UNUSED_RESULT OUString
replaceAll(
2690 OUString
const & from
, OUString
const & to
, sal_Int32 fromIndex
= 0) const
2692 rtl_uString
* s
= NULL
;
2693 rtl_uString_newReplaceAllFromIndex(&s
, pData
, from
.pData
, to
.pData
, fromIndex
);
2694 return OUString(s
, SAL_NO_ACQUIRE
);
2698 Returns a new string resulting from replacing all occurrences of a given
2699 substring with another substring.
2701 Replacing subsequent occurrences picks up only after a given replacement.
2702 That is, replacing from "xa" to "xx" in "xaa" results in "xxa", not "xxx".
2704 @param from ASCII string literal, the substring to be replaced
2706 @param to the replacing substring
2708 @since LibreOffice 3.6
2710 template< typename T
>
2711 SAL_WARN_UNUSED_RESULT typename
libreoffice_internal::ConstCharArrayDetector
< T
, OUString
>::Type
replaceAll( T
& from
, OUString
const & to
) const
2713 assert(libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(from
));
2714 rtl_uString
* s
= NULL
;
2715 rtl_uString_newReplaceAllAsciiL(
2717 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(from
),
2718 libreoffice_internal::ConstCharArrayDetector
<T
>::length
, to
.pData
);
2719 return OUString(s
, SAL_NO_ACQUIRE
);
2723 Returns a new string resulting from replacing all occurrences of a given
2724 substring with another substring.
2726 Replacing subsequent occurrences picks up only after a given replacement.
2727 That is, replacing from "xa" to "xx" in "xaa" results in "xxa", not "xxx".
2729 @param from the substring to be replaced
2731 @param to ASCII string literal, the replacing substring
2733 @since LibreOffice 5.1
2735 template< typename T
>
2736 SAL_WARN_UNUSED_RESULT typename
libreoffice_internal::ConstCharArrayDetector
< T
, OUString
>::Type
replaceAll( OUString
const & from
, T
& to
) const
2738 assert(libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(to
));
2739 rtl_uString
* s
= NULL
;
2740 rtl_uString_newReplaceAllToAsciiL(
2741 &s
, pData
, from
.pData
,
2742 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(to
),
2743 libreoffice_internal::ConstCharArrayDetector
<T
>::length
);
2744 return OUString(s
, SAL_NO_ACQUIRE
);
2748 Returns a new string resulting from replacing all occurrences of a given
2749 substring with another substring.
2751 Replacing subsequent occurrences picks up only after a given replacement.
2752 That is, replacing from "xa" to "xx" in "xaa" results in "xxa", not "xxx".
2754 @param from ASCII string literal, the substring to be replaced
2756 @param to ASCII string literal, the substring to be replaced
2758 @since LibreOffice 3.6
2760 template< typename T1
, typename T2
>
2761 SAL_WARN_UNUSED_RESULT typename
libreoffice_internal::ConstCharArrayDetector
< T1
, typename
libreoffice_internal::ConstCharArrayDetector
< T2
, OUString
>::Type
>::Type
2762 replaceAll( T1
& from
, T2
& to
) const
2764 assert(libreoffice_internal::ConstCharArrayDetector
<T1
>::isValid(from
));
2765 assert(libreoffice_internal::ConstCharArrayDetector
<T2
>::isValid(to
));
2766 rtl_uString
* s
= NULL
;
2767 rtl_uString_newReplaceAllAsciiLAsciiL(
2769 libreoffice_internal::ConstCharArrayDetector
<T1
>::toPointer(from
),
2770 libreoffice_internal::ConstCharArrayDetector
<T1
>::length
,
2771 libreoffice_internal::ConstCharArrayDetector
<T2
>::toPointer(to
),
2772 libreoffice_internal::ConstCharArrayDetector
<T2
>::length
);
2773 return OUString(s
, SAL_NO_ACQUIRE
);
2776 #if defined LIBO_INTERNAL_ONLY
2777 /** @overload @since LibreOffice 5.3 */
2778 template<typename T
> [[nodiscard
]]
2780 libreoffice_internal::ConstCharArrayDetector
<T
, OUString
>::TypeUtf16
2781 replaceAll(T
& from
, OUString
const & to
) const {
2782 rtl_uString
* s
= nullptr;
2783 rtl_uString_newReplaceAllUtf16LUtf16L(
2785 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(from
),
2786 libreoffice_internal::ConstCharArrayDetector
<T
>::length
,
2787 to
.pData
->buffer
, to
.pData
->length
);
2789 throw std::bad_alloc();
2790 // should be std::length_error if resulting would be too large
2792 return OUString(s
, SAL_NO_ACQUIRE
);
2794 /** @overload @since LibreOffice 5.3 */
2795 template<typename T
> [[nodiscard
]]
2797 libreoffice_internal::ConstCharArrayDetector
<T
, OUString
>::TypeUtf16
2798 replaceAll(OUString
const & from
, T
& to
) const {
2799 rtl_uString
* s
= nullptr;
2800 rtl_uString_newReplaceAllUtf16LUtf16L(
2801 &s
, pData
, from
.pData
->buffer
, from
.pData
->length
,
2802 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(to
),
2803 libreoffice_internal::ConstCharArrayDetector
<T
>::length
);
2805 throw std::bad_alloc();
2806 // should be std::length_error if resulting would be too large
2808 return OUString(s
, SAL_NO_ACQUIRE
);
2810 /** @overload @since LibreOffice 5.3 */
2811 template<typename T1
, typename T2
> [[nodiscard
]]
2813 libreoffice_internal::ConstCharArrayDetector
<
2815 typename
libreoffice_internal::ConstCharArrayDetector
<
2816 T2
, OUString
>::TypeUtf16
2818 replaceAll(T1
& from
, T2
& to
) const {
2819 rtl_uString
* s
= nullptr;
2820 rtl_uString_newReplaceAllUtf16LUtf16L(
2822 libreoffice_internal::ConstCharArrayDetector
<T1
>::toPointer(from
),
2823 libreoffice_internal::ConstCharArrayDetector
<T1
>::length
,
2824 libreoffice_internal::ConstCharArrayDetector
<T2
>::toPointer(to
),
2825 libreoffice_internal::ConstCharArrayDetector
<T2
>::length
);
2827 throw std::bad_alloc();
2828 // should be std::length_error if resulting would be too large
2830 return OUString(s
, SAL_NO_ACQUIRE
);
2832 /** @overload @since LibreOffice 5.3 */
2833 template<typename T1
, typename T2
> [[nodiscard
]]
2835 libreoffice_internal::ConstCharArrayDetector
<
2837 typename
libreoffice_internal::ConstCharArrayDetector
<
2840 replaceAll(T1
& from
, T2
& to
) const {
2841 rtl_uString
* s
= nullptr;
2842 rtl_uString_newReplaceAllUtf16LAsciiL(
2844 libreoffice_internal::ConstCharArrayDetector
<T1
>::toPointer(from
),
2845 libreoffice_internal::ConstCharArrayDetector
<T1
>::length
,
2846 libreoffice_internal::ConstCharArrayDetector
<T2
>::toPointer(to
),
2847 libreoffice_internal::ConstCharArrayDetector
<T2
>::length
);
2849 throw std::bad_alloc();
2850 // should be std::length_error if resulting would be too large
2852 return OUString(s
, SAL_NO_ACQUIRE
);
2854 /** @overload @since LibreOffice 5.3 */
2855 template<typename T1
, typename T2
> [[nodiscard
]]
2857 libreoffice_internal::ConstCharArrayDetector
<
2859 typename
libreoffice_internal::ConstCharArrayDetector
<
2860 T2
, OUString
>::TypeUtf16
2862 replaceAll(T1
& from
, T2
& to
) const {
2863 rtl_uString
* s
= nullptr;
2864 rtl_uString_newReplaceAllAsciiLUtf16L(
2866 libreoffice_internal::ConstCharArrayDetector
<T1
>::toPointer(from
),
2867 libreoffice_internal::ConstCharArrayDetector
<T1
>::length
,
2868 libreoffice_internal::ConstCharArrayDetector
<T2
>::toPointer(to
),
2869 libreoffice_internal::ConstCharArrayDetector
<T2
>::length
);
2871 throw std::bad_alloc();
2872 // should be std::length_error if resulting would be too large
2874 return OUString(s
, SAL_NO_ACQUIRE
);
2877 /** @overload @since LibreOffice 5.4 */
2878 [[nodiscard
]] OUString
replaceAll(
2879 OUStringLiteral
const & from
, OUString
const & to
) const
2881 rtl_uString
* s
= nullptr;
2882 rtl_uString_newReplaceAllAsciiL(
2883 &s
, pData
, from
.data
, from
.size
, to
.pData
);
2884 return OUString(s
, SAL_NO_ACQUIRE
);
2886 /** @overload @since LibreOffice 5.4 */
2887 [[nodiscard
]] OUString
replaceAll(
2888 OUString
const & from
, OUStringLiteral
const & to
) const
2890 rtl_uString
* s
= nullptr;
2891 rtl_uString_newReplaceAllToAsciiL(
2892 &s
, pData
, from
.pData
, to
.data
, to
.size
);
2893 return OUString(s
, SAL_NO_ACQUIRE
);
2895 /** @overload @since LibreOffice 5.4 */
2896 [[nodiscard
]] OUString
replaceAll(
2897 OUStringLiteral
const & from
, OUStringLiteral
const & to
) const
2899 rtl_uString
* s
= nullptr;
2900 rtl_uString_newReplaceAllAsciiLAsciiL(
2901 &s
, pData
, from
.data
, from
.size
, to
.data
, to
.size
);
2902 return OUString(s
, SAL_NO_ACQUIRE
);
2904 /** @overload @since LibreOffice 5.4 */
2905 template<typename T
> [[nodiscard
]]
2906 typename
libreoffice_internal::ConstCharArrayDetector
<T
, OUString
>::Type
2907 replaceAll(OUStringLiteral
const & from
, T
& to
) const {
2908 assert(libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(to
));
2909 rtl_uString
* s
= nullptr;
2910 rtl_uString_newReplaceAllAsciiLAsciiL(
2911 &s
, pData
, from
.data
, from
.size
,
2912 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(to
),
2913 libreoffice_internal::ConstCharArrayDetector
<T
>::length
);
2914 return OUString(s
, SAL_NO_ACQUIRE
);
2916 /** @overload @since LibreOffice 5.4 */
2917 template<typename T
> [[nodiscard
]]
2918 typename
libreoffice_internal::ConstCharArrayDetector
<T
, OUString
>::Type
2919 replaceAll(T
& from
, OUStringLiteral
const & to
) const {
2920 assert(libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(from
));
2921 rtl_uString
* s
= nullptr;
2922 rtl_uString_newReplaceAllAsciiLAsciiL(
2924 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(from
),
2925 libreoffice_internal::ConstCharArrayDetector
<T
>::length
, to
.data
,
2927 return OUString(s
, SAL_NO_ACQUIRE
);
2929 /** @overload @since LibreOffice 5.4 */
2930 template<typename T
> [[nodiscard
]]
2932 libreoffice_internal::ConstCharArrayDetector
<T
, OUString
>::TypeUtf16
2933 replaceAll(OUStringLiteral
const & from
, T
& to
) const {
2934 assert(libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(to
));
2935 rtl_uString
* s
= nullptr;
2936 rtl_uString_newReplaceAllAsciiLUtf16L(
2937 &s
, pData
, from
.data
, from
.size
,
2938 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(to
),
2939 libreoffice_internal::ConstCharArrayDetector
<T
>::length
);
2940 return OUString(s
, SAL_NO_ACQUIRE
);
2942 /** @overload @since LibreOffice 5.4 */
2943 template<typename T
> [[nodiscard
]]
2945 libreoffice_internal::ConstCharArrayDetector
<T
, OUString
>::TypeUtf16
2946 replaceAll(T
& from
, OUStringLiteral
const & to
) const {
2947 assert(libreoffice_internal::ConstCharArrayDetector
<T
>::isValid(from
));
2948 rtl_uString
* s
= nullptr;
2949 rtl_uString_newReplaceAllUtf16LAsciiL(
2951 libreoffice_internal::ConstCharArrayDetector
<T
>::toPointer(from
),
2952 libreoffice_internal::ConstCharArrayDetector
<T
>::length
, to
.data
,
2954 return OUString(s
, SAL_NO_ACQUIRE
);
2959 Converts from this string all ASCII uppercase characters (65-90)
2960 to ASCII lowercase characters (97-122).
2962 This function can't be used for language specific conversion.
2963 If the string doesn't contain characters which must be converted,
2964 then the new string is assigned with str.
2966 @return the string, converted to ASCII lowercase.
2968 SAL_WARN_UNUSED_RESULT OUString
toAsciiLowerCase() const
2970 rtl_uString
* pNew
= NULL
;
2971 rtl_uString_newToAsciiLowerCase( &pNew
, pData
);
2972 return OUString( pNew
, SAL_NO_ACQUIRE
);
2976 Converts from this string all ASCII lowercase characters (97-122)
2977 to ASCII uppercase characters (65-90).
2979 This function can't be used for language specific conversion.
2980 If the string doesn't contain characters which must be converted,
2981 then the new string is assigned with str.
2983 @return the string, converted to ASCII uppercase.
2985 SAL_WARN_UNUSED_RESULT OUString
toAsciiUpperCase() const
2987 rtl_uString
* pNew
= NULL
;
2988 rtl_uString_newToAsciiUpperCase( &pNew
, pData
);
2989 return OUString( pNew
, SAL_NO_ACQUIRE
);
2993 Returns a new string resulting from removing white space from both ends
2996 All characters that have codes less than or equal to
2997 32 (the space character), and Unicode General Punctuation area Space
2998 and some Control characters are considered to be white space (see
2999 rtl_ImplIsWhitespace).
3000 If the string doesn't contain white spaces at both ends,
3001 then the new string is assigned with str.
3003 @return the string, with white space removed from the front and end.
3005 SAL_WARN_UNUSED_RESULT OUString
trim() const
3007 rtl_uString
* pNew
= NULL
;
3008 rtl_uString_newTrim( &pNew
, pData
);
3009 return OUString( pNew
, SAL_NO_ACQUIRE
);
3013 Returns a token in the string.
3016 sal_Int32 nIndex = 0;
3020 OUString aToken = aStr.getToken( 0, ';', nIndex );
3023 while ( nIndex >= 0 );
3025 @param token the number of the token to return
3026 @param cTok the character which separate the tokens.
3027 @param index the position at which the token is searched in the
3029 The index must not be greater than the length of the
3031 This param is set to the position of the
3032 next token or to -1, if it is the last token.
3033 @return the token; if either token or index is negative, an empty token
3034 is returned (and index is set to -1)
3036 OUString
getToken( sal_Int32 token
, sal_Unicode cTok
, sal_Int32
& index
) const
3038 rtl_uString
* pNew
= NULL
;
3039 index
= rtl_uString_getToken( &pNew
, pData
, token
, cTok
, index
);
3040 return OUString( pNew
, SAL_NO_ACQUIRE
);
3044 Returns a token from the string.
3046 The same as getToken(sal_Int32, sal_Unicode, sal_Int32 &), but always
3047 passing in 0 as the start index in the third argument.
3049 @param count the number of the token to return, starting with 0
3050 @param separator the character which separates the tokens
3052 @return the given token, or an empty string
3054 @since LibreOffice 3.6
3056 OUString
getToken(sal_Int32 count
, sal_Unicode separator
) const {
3058 return getToken(count
, separator
, n
);
3062 Returns the Boolean value from this string.
3064 This function can't be used for language specific conversion.
3066 @return true, if the string is 1 or "True" in any ASCII case.
3067 false in any other case.
3069 bool toBoolean() const
3071 return rtl_ustr_toBoolean( pData
->buffer
);
3075 Returns the first character from this string.
3077 @return the first character from this string or 0, if this string
3080 sal_Unicode
toChar() const
3082 return pData
->buffer
[0];
3086 Returns the int32 value from this string.
3088 This function can't be used for language specific conversion.
3090 @param radix the radix (between 2 and 36)
3091 @return the int32 represented from this string.
3092 0 if this string represents no number or one of too large
3095 sal_Int32
toInt32( sal_Int16 radix
= 10 ) const
3097 return rtl_ustr_toInt32( pData
->buffer
, radix
);
3101 Returns the uint32 value from this string.
3103 This function can't be used for language specific conversion.
3105 @param radix the radix (between 2 and 36)
3106 @return the uint32 represented from this string.
3107 0 if this string represents no number or one of too large
3110 @since LibreOffice 4.2
3112 sal_uInt32
toUInt32( sal_Int16 radix
= 10 ) const
3114 return rtl_ustr_toUInt32( pData
->buffer
, radix
);
3118 Returns the int64 value from this string.
3120 This function can't be used for language specific conversion.
3122 @param radix the radix (between 2 and 36)
3123 @return the int64 represented from this string.
3124 0 if this string represents no number or one of too large
3127 sal_Int64
toInt64( sal_Int16 radix
= 10 ) const
3129 return rtl_ustr_toInt64( pData
->buffer
, radix
);
3133 Returns the uint64 value from this string.
3135 This function can't be used for language specific conversion.
3137 @param radix the radix (between 2 and 36)
3138 @return the uint64 represented from this string.
3139 0 if this string represents no number or one of too large
3142 @since LibreOffice 4.1
3144 sal_uInt64
toUInt64( sal_Int16 radix
= 10 ) const
3146 return rtl_ustr_toUInt64( pData
->buffer
, radix
);
3150 Returns the float value from this string.
3152 This function can't be used for language specific conversion.
3154 @return the float represented from this string.
3155 0.0 if this string represents no number.
3157 float toFloat() const
3159 return rtl_ustr_toFloat( pData
->buffer
);
3163 Returns the double value from this string.
3165 This function can't be used for language specific conversion.
3167 @return the double represented from this string.
3168 0.0 if this string represents no number.
3170 double toDouble() const
3172 return rtl_ustr_toDouble( pData
->buffer
);
3177 Return a canonical representation for a string.
3179 A pool of strings, initially empty is maintained privately
3180 by the string class. On invocation, if present in the pool
3181 the original string will be returned. Otherwise this string,
3182 or a copy thereof will be added to the pool and returned.
3185 a version of the string from the pool.
3187 @exception std::bad_alloc is thrown if an out-of-memory condition occurs
3191 OUString
intern() const
3193 rtl_uString
* pNew
= NULL
;
3194 rtl_uString_intern( &pNew
, pData
);
3196 throw std::bad_alloc();
3198 return OUString( pNew
, SAL_NO_ACQUIRE
);
3202 Return a canonical representation for a converted string.
3204 A pool of strings, initially empty is maintained privately
3205 by the string class. On invocation, if present in the pool
3206 the original string will be returned. Otherwise this string,
3207 or a copy thereof will be added to the pool and returned.
3209 @param value a 8-Bit character array.
3210 @param length the number of character which should be converted.
3211 The 8-Bit character array length must be
3212 greater than or equal to this value.
3213 @param encoding the text encoding from which the 8-Bit character
3214 sequence should be converted.
3215 @param convertFlags flags which controls the conversion.
3216 see RTL_TEXTTOUNICODE_FLAGS_...
3217 @param pInfo pointer to return conversion status or NULL.
3220 a version of the converted string from the pool.
3222 @exception std::bad_alloc is thrown if an out-of-memory condition occurs
3226 static OUString
intern( const sal_Char
* value
, sal_Int32 length
,
3227 rtl_TextEncoding encoding
,
3228 sal_uInt32 convertFlags
= OSTRING_TO_OUSTRING_CVTFLAGS
,
3229 sal_uInt32
*pInfo
= NULL
)
3231 rtl_uString
* pNew
= NULL
;
3232 rtl_uString_internConvert( &pNew
, value
, length
, encoding
,
3233 convertFlags
, pInfo
);
3235 throw std::bad_alloc();
3237 return OUString( pNew
, SAL_NO_ACQUIRE
);
3241 Converts to an OString, signalling failure.
3244 An out parameter receiving the converted OString. Must not be null; the
3245 contents are not modified if conversion fails (convertToOString returns
3249 The text encoding to convert into. Must be an octet encoding (i.e.,
3250 rtl_isOctetTextEncoding(nEncoding) must return true).
3253 A combination of RTL_UNICODETOTEXT_FLAGS that detail how to do the
3254 conversion (see rtl_convertUnicodeToText). RTL_UNICODETOTEXT_FLAGS_FLUSH
3255 need not be included, it is implicitly assumed. Typical uses are either
3256 RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR |
3257 RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR (fail if a Unicode character cannot
3258 be converted to the target nEncoding) or OUSTRING_TO_OSTRING_CVTFLAGS
3259 (make a best efforts conversion).
3262 True if the conversion succeeded, false otherwise.
3264 bool convertToString(OString
* pTarget
, rtl_TextEncoding nEncoding
,
3265 sal_uInt32 nFlags
) const
3267 return rtl_convertUStringToString(&pTarget
->pData
, pData
->buffer
,
3268 pData
->length
, nEncoding
, nFlags
);
3271 /** Iterate through this string based on code points instead of UTF-16 code
3274 See Chapter 3 of The Unicode Standard 5.0 (Addison--Wesley, 2006) for
3275 definitions of the various terms used in this description.
3277 This string is interpreted as a sequence of zero or more UTF-16 code
3278 units. For each index into this sequence (from zero to one less than
3279 the length of the sequence, inclusive), a code point represented
3280 starting at the given index is computed as follows:
3282 - If the UTF-16 code unit addressed by the index constitutes a
3283 well-formed UTF-16 code unit sequence, the computed code point is the
3284 scalar value encoded by that UTF-16 code unit sequence.
3286 - Otherwise, if the index is at least two UTF-16 code units away from
3287 the end of the sequence, and the sequence of two UTF-16 code units
3288 addressed by the index constitutes a well-formed UTF-16 code unit
3289 sequence, the computed code point is the scalar value encoded by that
3290 UTF-16 code unit sequence.
3292 - Otherwise, the computed code point is the UTF-16 code unit addressed
3293 by the index. (This last case catches unmatched surrogates as well as
3294 indices pointing into the middle of surrogate pairs.)
3297 pointer to a UTF-16 based index into this string; must not be null. On
3298 entry, the index must be in the range from zero to the length of this
3299 string (in UTF-16 code units), inclusive. Upon successful return, the
3300 index will be updated to address the UTF-16 code unit that is the given
3301 incrementCodePoints away from the initial index.
3303 @param incrementCodePoints
3304 the number of code points to move the given *indexUtf16. If
3305 non-negative, moving is done after determining the code point at the
3306 index. If negative, moving is done before determining the code point
3307 at the (then updated) index. The value must be such that the resulting
3308 UTF-16 based index is in the range from zero to the length of this
3309 string (in UTF-16 code units), inclusive.
3312 the code point (an integer in the range from 0 to 0x10FFFF, inclusive)
3313 that is represented within this string starting at the index computed as
3314 follows: If incrementCodePoints is non-negative, the index is the
3315 initial value of *indexUtf16; if incrementCodePoints is negative, the
3316 index is the updated value of *indexUtf16. In either case, the computed
3317 index must be in the range from zero to one less than the length of this
3318 string (in UTF-16 code units), inclusive.
3322 sal_uInt32
iterateCodePoints(
3323 sal_Int32
* indexUtf16
, sal_Int32 incrementCodePoints
= 1) const
3325 return rtl_uString_iterateCodePoints(
3326 pData
, indexUtf16
, incrementCodePoints
);
3330 * Convert an OString to an OUString, assuming that the OString is
3334 * an OString to convert
3336 * @since LibreOffice 4.4
3338 static OUString
fromUtf8(const OString
& rSource
)
3341 bool bSuccess
= rtl_convertStringToUString(&aTarget
.pData
,
3343 rSource
.getLength(),
3344 RTL_TEXTENCODING_UTF8
,
3345 RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR
|RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR
|RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR
);
3352 * Convert this string to an OString, assuming that the string can be
3353 * UTF-8-encoded successfully.
3355 * In other words, you must not use this method on a random sequence of
3356 * UTF-16 code units, but only at places where it is assumed that the
3357 * content is a proper string.
3359 * @since LibreOffice 4.4
3361 OString
toUtf8() const
3364 bool bSuccess
= rtl_convertUStringToString(&aTarget
.pData
,
3367 RTL_TEXTENCODING_UTF8
,
3368 RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR
|RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR
);
3374 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
3376 static OUStringNumber
< int > number( int i
, sal_Int16 radix
= 10 )
3378 return OUStringNumber
< int >( i
, radix
);
3380 static OUStringNumber
< long long > number( long long ll
, sal_Int16 radix
= 10 )
3382 return OUStringNumber
< long long >( ll
, radix
);
3384 static OUStringNumber
< unsigned long long > number( unsigned long long ll
, sal_Int16 radix
= 10 )
3386 return OUStringNumber
< unsigned long long >( ll
, radix
);
3388 static OUStringNumber
< unsigned long long > number( unsigned int i
, sal_Int16 radix
= 10 )
3390 return number( static_cast< unsigned long long >( i
), radix
);
3392 static OUStringNumber
< long long > number( long i
, sal_Int16 radix
= 10)
3394 return number( static_cast< long long >( i
), radix
);
3396 static OUStringNumber
< unsigned long long > number( unsigned long i
, sal_Int16 radix
= 10 )
3398 return number( static_cast< unsigned long long >( i
), radix
);
3400 static OUStringNumber
< float > number( float f
)
3402 return OUStringNumber
< float >( f
);
3404 static OUStringNumber
< double > number( double d
)
3406 return OUStringNumber
< double >( d
);
3410 Returns the string representation of the integer argument.
3412 This function can't be used for language specific conversion.
3414 @param i an integer value
3415 @param radix the radix (between 2 and 36)
3416 @return a string with the string representation of the argument.
3417 @since LibreOffice 4.1
3419 static OUString
number( int i
, sal_Int16 radix
= 10 )
3421 sal_Unicode aBuf
[RTL_USTR_MAX_VALUEOFINT32
];
3422 return OUString(aBuf
, rtl_ustr_valueOfInt32(aBuf
, i
, radix
));
3425 /// @since LibreOffice 4.1
3426 static OUString
number( unsigned int i
, sal_Int16 radix
= 10 )
3428 return number( static_cast< unsigned long long >( i
), radix
);
3431 /// @since LibreOffice 4.1
3432 static OUString
number( long i
, sal_Int16 radix
= 10)
3434 return number( static_cast< long long >( i
), radix
);
3437 /// @since LibreOffice 4.1
3438 static OUString
number( unsigned long i
, sal_Int16 radix
= 10 )
3440 return number( static_cast< unsigned long long >( i
), radix
);
3443 /// @since LibreOffice 4.1
3444 static OUString
number( long long ll
, sal_Int16 radix
= 10 )
3446 sal_Unicode aBuf
[RTL_USTR_MAX_VALUEOFINT64
];
3447 return OUString(aBuf
, rtl_ustr_valueOfInt64(aBuf
, ll
, radix
));
3450 /// @since LibreOffice 4.1
3451 static OUString
number( unsigned long long ll
, sal_Int16 radix
= 10 )
3453 sal_Unicode aBuf
[RTL_USTR_MAX_VALUEOFUINT64
];
3454 return OUString(aBuf
, rtl_ustr_valueOfUInt64(aBuf
, ll
, radix
));
3458 Returns the string representation of the float argument.
3460 This function can't be used for language specific conversion.
3463 @return a string with the decimal representation of the argument.
3464 @since LibreOffice 4.1
3466 static OUString
number( float f
)
3468 sal_Unicode aBuf
[RTL_USTR_MAX_VALUEOFFLOAT
];
3469 return OUString(aBuf
, rtl_ustr_valueOfFloat(aBuf
, f
));
3473 Returns the string representation of the double argument.
3475 This function can't be used for language specific conversion.
3478 @return a string with the decimal representation of the argument.
3479 @since LibreOffice 4.1
3481 static OUString
number( double d
)
3483 sal_Unicode aBuf
[RTL_USTR_MAX_VALUEOFDOUBLE
];
3484 return OUString(aBuf
, rtl_ustr_valueOfDouble(aBuf
, d
));
3489 Returns the string representation of the sal_Bool argument.
3491 If the sal_Bool is true, the string "true" is returned.
3492 If the sal_Bool is false, the string "false" is returned.
3493 This function can't be used for language specific conversion.
3495 @param b a sal_Bool.
3496 @return a string with the string representation of the argument.
3497 @deprecated use boolean()
3499 SAL_DEPRECATED("use boolean()") static OUString
valueOf( sal_Bool b
)
3505 Returns the string representation of the boolean argument.
3507 If the argument is true, the string "true" is returned.
3508 If the argument is false, the string "false" is returned.
3509 This function can't be used for language specific conversion.
3512 @return a string with the string representation of the argument.
3513 @since LibreOffice 4.1
3515 static OUString
boolean( bool b
)
3517 sal_Unicode aBuf
[RTL_USTR_MAX_VALUEOFBOOLEAN
];
3518 return OUString(aBuf
, rtl_ustr_valueOfBoolean(aBuf
, b
));
3522 Returns the string representation of the char argument.
3524 @param c a character.
3525 @return a string with the string representation of the argument.
3526 @deprecated use operator, function or constructor taking char or sal_Unicode argument
3528 SAL_DEPRECATED("convert to OUString or use directly") static OUString
valueOf( sal_Unicode c
)
3530 return OUString( &c
, 1 );
3534 Returns the string representation of the int argument.
3536 This function can't be used for language specific conversion.
3539 @param radix the radix (between 2 and 36)
3540 @return a string with the string representation of the argument.
3541 @deprecated use number()
3543 SAL_DEPRECATED("use number()") static OUString
valueOf( sal_Int32 i
, sal_Int16 radix
= 10 )
3545 return number( i
, radix
);
3549 Returns the string representation of the long argument.
3551 This function can't be used for language specific conversion.
3554 @param radix the radix (between 2 and 36)
3555 @return a string with the string representation of the argument.
3556 @deprecated use number()
3558 SAL_DEPRECATED("use number()") static OUString
valueOf( sal_Int64 ll
, sal_Int16 radix
= 10 )
3560 return number( ll
, radix
);
3564 Returns the string representation of the float argument.
3566 This function can't be used for language specific conversion.
3569 @return a string with the string representation of the argument.
3570 @deprecated use number()
3572 SAL_DEPRECATED("use number()") static OUString
valueOf( float f
)
3578 Returns the string representation of the double argument.
3580 This function can't be used for language specific conversion.
3583 @return a string with the string representation of the argument.
3584 @deprecated use number()
3586 SAL_DEPRECATED("use number()") static OUString
valueOf( double d
)
3592 Returns an OUString copied without conversion from an ASCII
3595 Since this method is optimized for performance, the ASCII character
3596 values are not converted in any way. The caller has to make sure that
3597 all ASCII characters are in the allowed range between 0 and 127.
3598 The ASCII string must be NULL-terminated.
3600 Note that for string literals it is simpler and more efficient
3601 to directly use the OUString constructor.
3603 @param value the 8-Bit ASCII character string
3604 @return a string with the string representation of the argument.
3606 static OUString
createFromAscii( const sal_Char
* value
)
3608 rtl_uString
* pNew
= NULL
;
3609 rtl_uString_newFromAscii( &pNew
, value
);
3610 return OUString( pNew
, SAL_NO_ACQUIRE
);
3613 #if defined LIBO_INTERNAL_ONLY
3614 operator std::u16string_view() const { return {getStr(), sal_uInt32(getLength())}; }
3618 OUString
& internalAppend( rtl_uString
* pOtherData
)
3620 rtl_uString
* pNewData
= NULL
;
3621 rtl_uString_newConcat( &pNewData
, pData
, pOtherData
);
3622 if (pNewData
== NULL
) {
3623 throw std::bad_alloc();
3625 rtl_uString_assign(&pData
, pNewData
);
3626 rtl_uString_release(pNewData
);
3632 #if defined LIBO_INTERNAL_ONLY
3633 // Prevent the operator ==/!= overloads with 'sal_Unicode const *' parameter from
3634 // being selected for nonsensical code like
3636 // if (ouIdAttr == nullptr)
3638 void operator ==(OUString
const &, std::nullptr_t
) = delete;
3639 void operator ==(std::nullptr_t
, OUString
const &) = delete;
3640 void operator !=(OUString
const &, std::nullptr_t
) = delete;
3641 void operator !=(std::nullptr_t
, OUString
const &) = delete;
3644 #if defined LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
3651 struct ToStringHelper
< OUString
>
3653 static std::size_t length( const OUString
& s
) { return s
.getLength(); }
3654 static sal_Unicode
* addData( sal_Unicode
* buffer
, const OUString
& s
) { return addDataHelper( buffer
, s
.getStr(), s
.getLength()); }
3655 static const bool allowOStringConcat
= false;
3656 static const bool allowOUStringConcat
= true;
3663 struct ToStringHelper
< OUStringLiteral
>
3665 static std::size_t length( const OUStringLiteral
& str
) { return str
.size
; }
3666 static sal_Unicode
* addData( sal_Unicode
* buffer
, const OUStringLiteral
& str
) { return addDataLiteral( buffer
, str
.data
, str
.size
); }
3667 static const bool allowOStringConcat
= false;
3668 static const bool allowOUStringConcat
= true;
3674 template< typename charT
, typename traits
, typename T1
, typename T2
>
3675 inline std::basic_ostream
<charT
, traits
> & operator <<(
3676 std::basic_ostream
<charT
, traits
> & stream
, OUStringConcat
< T1
, T2
>&& concat
)
3678 return stream
<< OUString( std::move(concat
) );
3684 /** A helper to use OUStrings with hash maps.
3686 Instances of this class are unary function objects that can be used as
3687 hash function arguments to std::unordered_map and similar constructs.
3691 /** Compute a hash code for a string.
3697 a hash code for the string. This hash code should not be stored
3698 persistently, as its computation may change in later revisions.
3700 size_t operator()(const OUString
& rString
) const
3701 { return static_cast<size_t>(rString
.hashCode()); }
3704 /* ======================================================================= */
3706 /** Convert an OString to an OUString, using a specific text encoding.
3708 The lengths of the two strings may differ (e.g., for double-byte
3709 encodings, UTF-7, UTF-8).
3712 an OString to convert.
3715 the text encoding to use for conversion.
3718 flags which control the conversion. Either use
3719 OSTRING_TO_OUSTRING_CVTFLAGS, or see
3720 <http://udk.openoffice.org/cpp/man/spec/textconversion.html> for more
3723 inline OUString
OStringToOUString( const OString
& rStr
,
3724 rtl_TextEncoding encoding
,
3725 sal_uInt32 convertFlags
= OSTRING_TO_OUSTRING_CVTFLAGS
)
3727 return OUString( rStr
.getStr(), rStr
.getLength(), encoding
, convertFlags
);
3730 /** Convert an OUString to an OString, using a specific text encoding.
3732 The lengths of the two strings may differ (e.g., for double-byte
3733 encodings, UTF-7, UTF-8).
3736 an OUString to convert.
3739 the text encoding to use for conversion.
3742 flags which control the conversion. Either use
3743 OUSTRING_TO_OSTRING_CVTFLAGS, or see
3744 <http://udk.openoffice.org/cpp/man/spec/textconversion.html> for more
3747 inline OString
OUStringToOString( const OUString
& rUnicode
,
3748 rtl_TextEncoding encoding
,
3749 sal_uInt32 convertFlags
= OUSTRING_TO_OSTRING_CVTFLAGS
)
3751 return OString( rUnicode
.getStr(), rUnicode
.getLength(), encoding
, convertFlags
);
3754 /* ======================================================================= */
3757 Support for rtl::OUString in std::ostream (and thus in
3758 CPPUNIT_ASSERT or SAL_INFO macros, for example).
3760 The rtl::OUString is converted to UTF-8.
3762 @since LibreOffice 3.5.
3764 template< typename charT
, typename traits
>
3765 inline std::basic_ostream
<charT
, traits
> & operator <<(
3766 std::basic_ostream
<charT
, traits
> & stream
, OUString
const & rString
)
3769 OUStringToOString(rString
, RTL_TEXTENCODING_UTF8
);
3770 // best effort; potentially loses data due to conversion failures
3771 // (stray surrogate halves) and embedded null characters
3776 #ifdef RTL_STRING_UNITTEST
3779 typedef rtlunittest::OUString OUString
;
3783 // In internal code, allow to use classes like OUString without having to
3784 // explicitly refer to the rtl namespace, which is kind of superfluous given
3785 // that OUString itself is namespaced by its OU prefix:
3786 #if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST
3787 using ::rtl::OUString
;
3788 using ::rtl::OUStringHash
;
3789 using ::rtl::OStringToOUString
;
3790 using ::rtl::OUStringToOString
;
3791 using ::rtl::OUStringLiteral
;
3792 using ::rtl::OUStringChar
;
3797 Make OUString hashable by default for use in STL containers.
3799 @since LibreOffice 6.0
3801 #if defined LIBO_INTERNAL_ONLY
3805 struct hash
<::rtl::OUString
>
3807 std::size_t operator()(::rtl::OUString
const & s
) const
3808 { return std::size_t(s
.hashCode()); }
3816 #endif /* _RTL_USTRING_HXX */
3818 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */