/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
/* * This file is part of LibreOffice published API.
*/
// The unittest uses slightly different code to help check that the proper // calls are made. The class is put into a different namespace to make // sure the compiler generates a different (if generating also non-inline) // copy of the function and does not merge them together. The class // is "brought" into the proper rtl namespace by a typedef below. #ifdef RTL_STRING_UNITTEST #define rtl rtlunittest #endif
/** A wrapper dressing a string literal as a static-refcount rtl_uString.
This class is not part of public API and is meant to be used only in LibreOffice code. @since LibreOffice 4.0
*/ template<std::size_t N> class SAL_WARN_UNUSED OUStringLiteral {
static_assert(N != 0);
static_assert(N - 1 <= std::numeric_limits<sal_Int32>::max(), "literal too long");
private: static constexpr void assertLayout() { // These static_asserts verifying the layout compatibility with rtl_uString cannot be class // member declarations, as offsetof requires a complete type, so defer them to here:
static_assert(std::is_standard_layout_v<OUStringLiteral>);
static_assert(offsetof(OUStringLiteral, str.refCount) == offsetof(OUStringLiteral, more.refCount));
static_assert(offsetof(OUStringLiteral, str.length) == offsetof(OUStringLiteral, more.length));
static_assert(offsetof(OUStringLiteral, str.buffer) == offsetof(OUStringLiteral, more.buffer));
}
public: // (Data members must be public so that OUStringLiteral is a structural type that can be used as // a non-type template parameter type for operator ""_ustr:) union {
rtl_uString str;
Data more = {};
};
};
/** This String class provides base functionality for C++ like Unicode character array handling. The advantage of this class is that it handles all the memory management for you - and it does it more efficiently. If you assign a string to another string, the data of both strings are shared (without any copy operation or memory allocation) as long as you do not change the string. This class also stores the length of the string, so that many operations are faster than the C-str-functions.
This class provides only readonly string handling. So you could create a string and you could only query the content from this string. It provides also functionality to change the string, but this results in every case in a new string instance (in the most cases with a memory allocation). You don't have functionality to change the content of the string. If you want to change the string content, then you should use the OStringBuffer class, which provides these functionalities and avoids too much memory allocation.
The design of this class is similar to the string classes in Java so less people should have understanding problems when they use this class.
*/
/** New string containing no characters.
*/
OUString()
{
pData = NULL;
rtl_uString_new( &pData );
}
/** New string from OUString.
@param str an OUString.
*/ #ifdefined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
constexpr #endif
OUString( const OUString & str )
{
pData = str.pData; #ifdefined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED) if (std::is_constant_evaluated()) { //TODO: We would want to // // assert(SAL_STRING_IS_STATIC(pData)); // // here, but that wouldn't work because read of member `str` of OUStringLiteral's // anonymous union with active member `more` is not allowed in a constant expression.
} else #endif
rtl_uString_acquire( pData );
}
@param str an OUString. @since LibreOffice 5.2
*/ #if !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
constexpr #endif
OUString( OUString && str ) noexcept
{
pData = str.pData; #if !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED) if (std::is_constant_evaluated()) { //TODO: We would want to // // assert(SAL_STRING_IS_STATIC(pData)); // // here, but that wouldn't work because read of member `str` of OUStringLiteral's // anonymous union with active member `more` is not allowed in a constant expression. return;
} #endif
str.pData = nullptr;
rtl_uString_new( &str.pData );
} #endif #endif
/** New string from a Unicode character buffer array.
@param value a NULL-terminated Unicode character array.
*/
OUString( const sal_Unicode * value )
{
pData = NULL;
rtl_uString_newFromStr( &pData, value );
}
#endif
/** New string from a Unicode character buffer array.
@param value a Unicode character array. @param length the number of character which should be copied. The character array length must be greater than or equal to this value.
*/
OUString( const sal_Unicode * value, sal_Int32 length )
{
pData = NULL;
rtl_uString_newFromStr_WithLength( &pData, value, length );
}
/** New string from an 8-Bit string literal that is expected to contain only characters in the ASCII set (i.e. first 128 characters). This constructor allows an efficient and convenient way to create OUString instances from ASCII literals. When creating strings from data that is not pure ASCII, it needs to be converted to OUString by explicitly providing the encoding to use for the conversion.
If there are any embedded \0's in the string literal, the result is undefined. Use the overload that explicitly accepts length.
#ifdefined LIBO_INTERNAL_ONLY // Rather use a u""_ustr literal (but don't remove this entirely, to avoid implicit support for // it via std::u16string_view from kicking in): template<typename T> OUString(
T &, typename libreoffice_internal::ConstCharArrayDetector<
T, libreoffice_internal::Dummy>::TypeUtf16
= libreoffice_internal::Dummy()) = delete;
/** New string from an 8-Bit character buffer array.
@param value An 8-Bit character array. @param length The number of character which should be converted. The 8-Bit character array length must be greater than or equal to this value. @param encoding The text encoding from which the 8-Bit character sequence should be converted. @param convertFlags Flags which control the conversion. see RTL_TEXTTOUNICODE_FLAGS_...
/** Create a new string from an array of Unicode code points.
@param codePoints an array of at least codePointCount code points, which each must be in the range from 0 to 0x10FFFF, inclusive. May be null if codePointCount is zero.
@param codePointCount the non-negative number of code points.
@exception std::bad_alloc is thrown if either an out-of-memory condition occurs or the resulting number of UTF-16 code units would have been larger than SAL_MAX_INT32.
/** Release the string data.
*/ #ifdefined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
constexpr #endif
~OUString()
{ #ifdefined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED) if (std::is_constant_evaluated()) { //TODO: We would want to // // assert(SAL_STRING_IS_STATIC(pData)); // // here, but that wouldn't work because read of member `str` of OUStringLiteral's // anonymous union with active member `more` is not allowed in a constant expression.
} else #endif
rtl_uString_release( pData );
}
/** Provides an OUString const & passing a storage pointer of an rtl_uString * handle. It is more convenient to use C++ OUString member functions when dealing with rtl_uString * handles. Using this function avoids unnecessary acquire()/release() calls for a temporary OUString object.
@param ppHandle pointer to storage @return OUString const & based on given storage
*/ static OUString const & unacquired( rtl_uString * const * ppHandle )
{ return * reinterpret_cast< OUString const * >( ppHandle ); }
#ifdefined LIBO_INTERNAL_ONLY /** Provides an OUString const & passing an OUStringBuffer const reference. It is more convenient to use C++ OUString member functions when checking current buffer content. Use this function instead of toString (that allocates a new OUString from buffer data) when the result is used in comparisons.
@param str an OUStringBuffer @return OUString const & based on given storage @since LibreOffice 7.4
*/ static OUString const& unacquired(const OUStringBuffer& str); #endif
/** Assign a new string from an 8-Bit string literal that is expected to contain only characters in the ASCII set (i.e. first 128 characters). This operator allows an efficient and convenient way to assign OUString instances from ASCII literals. When assigning strings from data that is not pure ASCII, it needs to be converted to OUString by explicitly providing the encoding to use for the conversion.
#ifdefined LIBO_INTERNAL_ONLY // Rather assign from a u""_ustr literal (but don't remove this entirely, to avoid implicit // support for it via std::u16string_view from kicking in): template<typename T> typename
libreoffice_internal::ConstCharArrayDetector<T, OUString &>::TypeUtf16 operator =(T &) = delete;
template <std::size_t N>
OUString & operator =(OUStringNumber<N> && n) { // n.length should never be zero, so no need to add an optimization for that case
rtl_uString_newFromStr_WithLength(&pData, n.buf, n.length); return *this;
}
/** Returns a pointer to the Unicode character buffer for this string.
It isn't necessarily NULL terminated.
@return a pointer to the Unicode characters buffer for this object.
*/ const sal_Unicode * getStr() const SAL_RETURNS_NONNULL { return pData->buffer; }
/** Access to individual characters.
@param index must be non-negative and less than length.
The comparison is based on the numeric value of each character in the strings and return a value indicating their relationship. This function can't be used for language specific sorting.
@param str the object to be compared. @return 0 - if both strings are equal < 0 - if this string is less than the string argument > 0 - if this string is greater than the string argument
*/ #ifdefined LIBO_INTERNAL_ONLY
sal_Int32 compareTo( std::u16string_view str ) const
{ return rtl_ustr_compare_WithLength( pData->buffer, pData->length,
str.data(), str.length() );
} #else
sal_Int32 compareTo( const OUString & str ) const
{ return rtl_ustr_compare_WithLength( pData->buffer, pData->length,
str.pData->buffer, str.pData->length );
} #endif
/** Compares two strings with a maximum count of characters.
The comparison is based on the numeric value of each character in the strings and return a value indicating their relationship. This function can't be used for language specific sorting.
@param str the object to be compared. @param maxLength the maximum count of characters to be compared. @return 0 - if both strings are equal < 0 - if this string is less than the string argument > 0 - if this string is greater than the string argument
The comparison is based on the numeric value of each character in the strings and return a value indicating their relationship. This function can't be used for language specific sorting.
@param str the object to be compared. @return 0 - if both strings are equal < 0 - if this string is less than the string argument > 0 - if this string is greater than the string argument
*/ #ifdefined LIBO_INTERNAL_ONLY
sal_Int32 reverseCompareTo(std::u16string_view sv) const { return rtl_ustr_reverseCompare_WithLength(
pData->buffer, pData->length, sv.data(), sv.size());
} #else
sal_Int32 reverseCompareTo( const OUString & str ) const
{ return rtl_ustr_reverseCompare_WithLength( pData->buffer, pData->length,
str.pData->buffer, str.pData->length );
} #endif
/** @overload This function accepts an ASCII string literal as its argument. @since LibreOffice 4.1
*/ template< typename T > typename libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type reverseCompareTo( T& literal ) const
{
assert(
libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal)); return rtl_ustr_asciil_reverseCompare_WithLength(
pData->buffer, pData->length,
libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
libreoffice_internal::ConstCharArrayDetector<T>::length);
}
/** Perform a comparison of two strings.
The result is true if and only if second string represents the same sequence of characters as the first string. This function can't be used for language specific comparison.
@param str the object to be compared. @return true if the strings are equal; false, otherwise.
*/ bool equals( const OUString & str ) const
{ if ( pData->length != str.pData->length ) returnfalse; if ( pData == str.pData ) returntrue; return rtl_ustr_reverseCompare_WithLength( pData->buffer, pData->length,
str.pData->buffer, str.pData->length ) == 0;
}
/** Perform an ASCII lowercase comparison of two strings.
The result is true if and only if second string represents the same sequence of characters as the first string, ignoring the case. Character values between 65 and 90 (ASCII A-Z) are interpreted as values between 97 and 122 (ASCII a-z). This function can't be used for language specific comparison.
@param str the object to be compared. @return true if the strings are equal; false, otherwise.
*/ #ifdefined LIBO_INTERNAL_ONLY bool equalsIgnoreAsciiCase(std::u16string_view sv) const { if ( sal_uInt32(pData->length) != sv.size() ) returnfalse; if ( pData->buffer == sv.data() ) returntrue; return
rtl_ustr_compareIgnoreAsciiCase_WithLength(
pData->buffer, pData->length, sv.data(), sv.size())
== 0;
} #else bool equalsIgnoreAsciiCase( const OUString & str ) const
{ if ( pData->length != str.pData->length ) returnfalse; if ( pData == str.pData ) returntrue; return rtl_ustr_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
str.pData->buffer, str.pData->length ) == 0;
} #endif
/** Perform an ASCII lowercase comparison of two strings.
Compare the two strings with uppercase ASCII character values between 65 and 90 (ASCII A-Z) interpreted as values between 97 and 122 (ASCII a-z). This function can't be used for language specific comparison.
@param str the object to be compared. @return 0 - if both strings are equal < 0 - if this string is less than the string argument > 0 - if this string is greater than the string argument
/** @overload This function accepts an ASCII string literal as its argument. @since LibreOffice 3.6
*/ template< typename T > typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type equalsIgnoreAsciiCase( T& literal ) const
{
assert(
libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal)); return
(pData->length
== libreoffice_internal::ConstCharArrayDetector<T>::length)
&& (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength(
pData->buffer, pData->length,
libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
literal))
== 0);
}
/** Match against a substring appearing in this string.
The result is true if and only if the second string appears as a substring of this string, at the given position. This function can't be used for language specific comparison.
@param str the object (substring) to be compared. @param fromIndex the index to start the comparison from. The index must be greater than or equal to 0 and less or equal as the string length. @return true if str match with the characters in the string at the given position; false, otherwise.
*/ #ifdefined LIBO_INTERNAL_ONLY bool match(std::u16string_view sv, sal_Int32 fromIndex = 0) const {
assert(fromIndex >= 0); return
rtl_ustr_shortenedCompare_WithLength(
pData->buffer + fromIndex, pData->length - fromIndex, sv.data(), sv.size(),
sv.size())
== 0;
} #else bool match( const OUString & str, sal_Int32 fromIndex = 0 ) const
{
assert(fromIndex >= 0); return rtl_ustr_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
str.pData->buffer, str.pData->length, str.pData->length ) == 0;
} #endif
/** @overload This function accepts an ASCII string literal as its argument. @since LibreOffice 3.6
*/ template< typename T > typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type match( T& literal, sal_Int32 fromIndex = 0 ) const
{
assert(
libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
assert(fromIndex >= 0); return
rtl_ustr_ascii_shortenedCompare_WithLength(
pData->buffer+fromIndex, pData->length-fromIndex,
libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
literal),
libreoffice_internal::ConstCharArrayDetector<T>::length)
== 0;
}
/** Match against a substring appearing in this string, ignoring the case of ASCII letters.
The result is true if and only if the second string appears as a substring of this string, at the given position. Character values between 65 and 90 (ASCII A-Z) are interpreted as values between 97 and 122 (ASCII a-z). This function can't be used for language specific comparison.
@param str the object (substring) to be compared. @param fromIndex the index to start the comparison from. The index must be greater than or equal to 0 and less than or equal to the string length. @return true if str match with the characters in the string at the given position; false, otherwise.
*/ #ifdefined LIBO_INTERNAL_ONLY bool matchIgnoreAsciiCase(std::u16string_view sv, sal_Int32 fromIndex = 0) const {
assert(fromIndex >= 0); return
rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength(
pData->buffer + fromIndex, pData->length - fromIndex, sv.data(), sv.size(),
sv.size())
== 0;
} #else bool matchIgnoreAsciiCase( const OUString & str, sal_Int32 fromIndex = 0 ) const
{
assert(fromIndex >= 0); return rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
str.pData->buffer, str.pData->length,
str.pData->length ) == 0;
} #endif
/** @overload This function accepts an ASCII string literal as its argument. @since LibreOffice 3.6
*/ template< typename T > typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type matchIgnoreAsciiCase( T& literal, sal_Int32 fromIndex = 0 ) const
{
assert(
libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal)); return matchIgnoreAsciiCaseAsciiL(
libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
libreoffice_internal::ConstCharArrayDetector<T>::length, fromIndex);
}
/** Compares two strings.
The comparison is based on the numeric value of each character in the strings and return a value indicating their relationship. Since this method is optimized for performance, the ASCII character values are not converted in any way. The caller has to make sure that all ASCII characters are in the allowed range between 0 and 127. The ASCII string must be NULL-terminated. This function can't be used for language specific sorting.
@param asciiStr the 8-Bit ASCII character string to be compared. @return 0 - if both strings are equal < 0 - if this string is less than the string argument > 0 - if this string is greater than the string argument
*/
sal_Int32 compareToAscii( constchar* asciiStr ) const
{ return rtl_ustr_ascii_compare_WithLength( pData->buffer, pData->length, asciiStr );
}
/** Compares two strings with a maximum count of characters.
The comparison is based on the numeric value of each character in the strings and return a value indicating their relationship. Since this method is optimized for performance, the ASCII character values are not converted in any way. The caller has to make sure that all ASCII characters are in the allowed range between 0 and 127. The ASCII string must be NULL-terminated. This function can't be used for language specific sorting.
@deprecated This is a confusing overload with unexpectedly different semantics from the one-parameter form, so it is marked as deprecated. Practically all uses compare the return value against zero and can thus be replaced with uses of startsWith.
@param asciiStr the 8-Bit ASCII character string to be compared. @param maxLength the maximum count of characters to be compared. @return 0 - if both strings are equal < 0 - if this string is less than the string argument > 0 - if this string is greater than the string argument
*/
SAL_DEPRECATED( "replace s1.compareToAscii(s2, strlen(s2)) == 0 with s1.startsWith(s2)")
sal_Int32 compareToAscii( constchar * asciiStr, sal_Int32 maxLength ) const
{ return rtl_ustr_ascii_shortenedCompare_WithLength( pData->buffer, pData->length,
asciiStr, maxLength );
}
/** Compares two strings in reverse order.
This could be useful, if normally both strings start with the same content. The comparison is based on the numeric value of each character in the strings and return a value indicating their relationship. Since this method is optimized for performance, the ASCII character values are not converted in any way. The caller has to make sure that all ASCII characters are in the allowed range between 0 and 127. The ASCII string must be greater than or equal to asciiStrLength. This function can't be used for language specific sorting.
@param asciiStr the 8-Bit ASCII character string to be compared. @param asciiStrLength the length of the ascii string @return 0 - if both strings are equal < 0 - if this string is less than the string argument > 0 - if this string is greater than the string argument
*/
sal_Int32 reverseCompareToAsciiL( constchar * asciiStr, sal_Int32 asciiStrLength ) const
{ return rtl_ustr_asciil_reverseCompare_WithLength( pData->buffer, pData->length,
asciiStr, asciiStrLength );
}
/** Perform a comparison of two strings.
The result is true if and only if second string represents the same sequence of characters as the first string. Since this method is optimized for performance, the ASCII character values are not converted in any way. The caller has to make sure that all ASCII characters are in the allowed range between 0 and 127. The ASCII string must be NULL-terminated. This function can't be used for language specific comparison.
@param asciiStr the 8-Bit ASCII character string to be compared. @return true if the strings are equal; false, otherwise.
*/ bool equalsAscii( constchar* asciiStr ) const
{ return rtl_ustr_ascii_compare_WithLength( pData->buffer, pData->length,
asciiStr ) == 0;
}
/** Perform a comparison of two strings.
The result is true if and only if second string represents the same sequence of characters as the first string. Since this method is optimized for performance, the ASCII character values are not converted in any way. The caller has to make sure that all ASCII characters are in the allowed range between 0 and 127. The ASCII string must be greater than or equal to asciiStrLength. This function can't be used for language specific comparison.
@param asciiStr the 8-Bit ASCII character string to be compared. @param asciiStrLength the length of the ascii string @return true if the strings are equal; false, otherwise.
*/ bool equalsAsciiL( constchar* asciiStr, sal_Int32 asciiStrLength ) const
{ if ( pData->length != asciiStrLength ) returnfalse;
/** Perform an ASCII lowercase comparison of two strings.
The result is true if and only if second string represents the same sequence of characters as the first string, ignoring the case. Character values between 65 and 90 (ASCII A-Z) are interpreted as values between 97 and 122 (ASCII a-z). Since this method is optimized for performance, the ASCII character values are not converted in any way. The caller has to make sure that all ASCII characters are in the allowed range between 0 and 127. The ASCII string must be NULL-terminated. This function can't be used for language specific comparison.
@param asciiStr the 8-Bit ASCII character string to be compared. @return true if the strings are equal; false, otherwise.
*/ bool equalsIgnoreAsciiCaseAscii( constchar * asciiStr ) const
{ return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, asciiStr ) == 0;
}
The comparison is based on the numeric value of each character in the strings and return a value indicating their relationship. Since this method is optimized for performance, the ASCII character values are not converted in any way. The caller has to make sure that all ASCII characters are in the allowed range between 0 and 127. The ASCII string must be NULL-terminated. This function can't be used for language specific sorting.
@param asciiStr the 8-Bit ASCII character string to be compared. @return 0 - if both strings are equal < 0 - if this string is less than the string argument > 0 - if this string is greater than the string argument
/** Perform an ASCII lowercase comparison of two strings.
The result is true if and only if second string represents the same sequence of characters as the first string, ignoring the case. Character values between 65 and 90 (ASCII A-Z) are interpreted as values between 97 and 122 (ASCII a-z). Since this method is optimized for performance, the ASCII character values are not converted in any way. The caller has to make sure that all ASCII characters are in the allowed range between 0 and 127. The ASCII string must be greater than or equal to asciiStrLength. This function can't be used for language specific comparison.
@param asciiStr the 8-Bit ASCII character string to be compared. @param asciiStrLength the length of the ascii string @return true if the strings are equal; false, otherwise.
*/ bool equalsIgnoreAsciiCaseAsciiL( constchar * asciiStr, sal_Int32 asciiStrLength ) const
{ if ( pData->length != asciiStrLength ) returnfalse;
/** Match against a substring appearing in this string.
The result is true if and only if the second string appears as a substring of this string, at the given position. Since this method is optimized for performance, the ASCII character values are not converted in any way. The caller has to make sure that all ASCII characters are in the allowed range between 0 and 127. The ASCII string must be greater than or equal to asciiStrLength. This function can't be used for language specific comparison.
@param asciiStr the object (substring) to be compared. @param asciiStrLength the length of asciiStr. @param fromIndex the index to start the comparison from. The index must be greater than or equal to 0 and less than or equal to the string length. @return true if str match with the characters in the string at the given position; false, otherwise.
*/ bool matchAsciiL( constchar* asciiStr, sal_Int32 asciiStrLength, sal_Int32 fromIndex = 0 ) const
{
assert(fromIndex >= 0); return rtl_ustr_ascii_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
asciiStr, asciiStrLength ) == 0;
}
// This overload is left undefined, to detect calls of matchAsciiL that // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit // platforms): #if SAL_TYPES_SIZEOFLONG == 8 void matchAsciiL(charconst *, sal_Int32, rtl_TextEncoding) const; #endif
/** Match against a substring appearing in this string, ignoring the case of ASCII letters.
The result is true if and only if the second string appears as a substring of this string, at the given position. Character values between 65 and 90 (ASCII A-Z) are interpreted as values between 97 and 122 (ASCII a-z). Since this method is optimized for performance, the ASCII character values are not converted in any way. The caller has to make sure that all ASCII characters are in the allowed range between 0 and 127. The ASCII string must be greater than or equal to asciiStrLength. This function can't be used for language specific comparison.
@param asciiStr the 8-Bit ASCII character string to be compared. @param asciiStrLength the length of the ascii string @param fromIndex the index to start the comparison from. The index must be greater than or equal to 0 and less than or equal to the string length. @return true if str match with the characters in the string at the given position; false, otherwise.
*/ bool matchIgnoreAsciiCaseAsciiL( constchar* asciiStr, sal_Int32 asciiStrLength, sal_Int32 fromIndex = 0 ) const
{
assert(fromIndex >= 0); return rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
asciiStr, asciiStrLength ) == 0;
}
// This overload is left undefined, to detect calls of // matchIgnoreAsciiCaseAsciiL that erroneously use // RTL_CONSTASCII_USTRINGPARAM instead of RTL_CONSTASCII_STRINGPARAM (but // would lead to ambiguities on 32 bit platforms): #if SAL_TYPES_SIZEOFLONG == 8 void matchIgnoreAsciiCaseAsciiL(charconst *, sal_Int32, rtl_TextEncoding) const; #endif
#ifdefined LIBO_INTERNAL_ONLY /** Check whether this string starts with a given substring.
@param str the substring to be compared
@return true if and only if the given str appears as a substring at the start of this string
@since LibreOffice 4.0
*/ bool startsWith(std::u16string_view sv) const { return match(sv);
} /** Check whether this string starts with a given substring.
@param str the substring to be compared
@param rest if this function returns true, then assign a copy of the remainder of this string to *rest. Available since LibreOffice 4.2
@return true if and only if the given str appears as a substring at the start of this string
@since LibreOffice 4.0
*/ bool startsWith(std::u16string_view sv, OUString * rest) const {
assert(rest); autoconst b = startsWith(sv); if (b) {
*rest = copy(sv.size());
} return b;
} /** Check whether this string starts with a given substring.
@param str the substring to be compared
@param rest if this function returns true, then assign a copy of the remainder of this string to *rest.
@return true if and only if the given str appears as a substring at the start of this string
@since LibreOffice 25.2
*/ bool startsWith(std::u16string_view sv, std::u16string_view * rest) const {
assert(rest); autoconst b = startsWith(sv); if (b) {
*rest = subView(sv.size());
} return b;
} #else /** Check whether this string starts with a given substring.
@param str the substring to be compared
@param rest if non-null, and this function returns true, then assign a copy of the remainder of this string to *rest. Available since LibreOffice 4.2
@return true if and only if the given str appears as a substring at the start of this string
#ifdefined LIBO_INTERNAL_ONLY /** This function accepts an ASCII string literal as its argument. @since LibreOffice 25.2
*/ template< typename T > typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type startsWith(
T & literal) const
{
assert(
libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal)); bool b
= (libreoffice_internal::ConstCharArrayDetector<T>::length
<= sal_uInt32(pData->length))
&& rtl_ustr_asciil_reverseEquals_WithLength(
pData->buffer,
libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
literal),
libreoffice_internal::ConstCharArrayDetector<T>::length); return b;
} /** @overload This function accepts an ASCII string literal as its argument. @since LibreOffice 4.0
*/ template< typename T > typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type startsWith(
T & literal, OUString * rest) const
{
assert(rest); bool b = startsWith(literal); if (b) {
*rest = copy(
libreoffice_internal::ConstCharArrayDetector<T>::length);
} return b;
} /** This function accepts an ASCII string literal as its argument. @since LibreOffice 25.2
*/ template< typename T > typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type startsWith(
T & literal, std::u16string_view * rest) const
{
assert(rest); bool b = startsWith(literal); if (b) {
*rest = subView(
libreoffice_internal::ConstCharArrayDetector<T>::length);
} return b;
} #else /** @overload This function accepts an ASCII string literal as its argument. @since LibreOffice 4.0
*/ template< typename T > typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type startsWith(
T & literal, OUString * rest = NULL) const
{
assert(
libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal)); bool b
= (libreoffice_internal::ConstCharArrayDetector<T>::length
<= sal_uInt32(pData->length))
&& rtl_ustr_asciil_reverseEquals_WithLength(
pData->buffer,
libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
literal),
libreoffice_internal::ConstCharArrayDetector<T>::length); if (b && rest != NULL) {
*rest = copy(
libreoffice_internal::ConstCharArrayDetector<T>::length);
} return b;
} #endif
/** Check whether this string starts with a given string, ignoring the case of ASCII letters.
Character values between 65 and 90 (ASCII A-Z) are interpreted as values between 97 and 122 (ASCII a-z). This function can't be used for language specific comparison.
@param str the substring to be compared
@param rest if non-null, and this function returns true, then assign a copy of the remainder of this string to *rest. Available since LibreOffice 4.2
@return true if and only if the given str appears as a substring at the start of this string, ignoring the case of ASCII letters ("A"--"Z" and "a"--"z")
#ifdefined LIBO_INTERNAL_ONLY /** @overload This function accepts an ASCII string literal as its argument. @since LibreOffice 25.2
*/ template< typename T >
--> --------------------
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.