diff options
Diffstat (limited to 'include/rtl/string.hxx')
-rw-r--r-- | include/rtl/string.hxx | 382 |
1 files changed, 368 insertions, 14 deletions
diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx index d9a5bf3c3bac..a62a33e2f590 100644 --- a/include/rtl/string.hxx +++ b/include/rtl/string.hxx @@ -1059,29 +1059,77 @@ public: == 0; } +#if defined LIBO_INTERNAL_ONLY /** 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 + + @since LibreOffice 4.0 + */ + bool startsWith(std::string_view str) const { + return match(str); + } + /** + 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 4.0 */ -#if defined LIBO_INTERNAL_ONLY - bool startsWith(std::string_view str, OString * rest = NULL) const { + bool startsWith(std::string_view str, OString * rest) const { + assert(rest); bool b = match(str); - if (b && rest != NULL) { + if (b) { *rest = copy(str.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 24.2 + */ + bool startsWith(std::string_view str, std::string_view * rest) const { + assert(rest); + bool b = match(str); + if (b) { + *rest = subView(str.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 + + @since LibreOffice 4.0 + */ bool startsWith(OString const & str, OString * rest = NULL) const { bool b = match(str); if (b && rest != NULL) { @@ -1091,6 +1139,55 @@ public: } #endif +#if defined LIBO_INTERNAL_ONLY + /** + @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) const + { + RTL_STRING_CONST_FUNCTION + return match(literal, 0); + } + /** + @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, OString * rest) const + { + RTL_STRING_CONST_FUNCTION + assert(rest); + bool b = match(literal, 0); + 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::string_view * rest) const + { + RTL_STRING_CONST_FUNCTION + assert(rest); + bool b = match(literal, 0); + if (b) { + *rest = subView( + libreoffice_internal::ConstCharArrayDetector<T>::length); + } + return b; + } +#else /** @overload This function accepts an ASCII string literal as its argument. @@ -1108,7 +1205,9 @@ public: } return b; } +#endif +#if defined LIBO_INTERNAL_ONLY /** Check whether this string starts with a given string, ignoring the case of ASCII letters. @@ -1119,7 +1218,28 @@ public: @param str the substring to be compared - @param rest if non-null, and this function returns true, then assign a + @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") + + @since LibreOffice 5.1 + */ + bool startsWithIgnoreAsciiCase(std::string_view str) + const + { + return matchIgnoreAsciiCase(str); + } + /** + 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 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 @@ -1128,17 +1248,65 @@ public: @since LibreOffice 5.1 */ -#if defined LIBO_INTERNAL_ONLY - bool startsWithIgnoreAsciiCase(std::string_view str, OString * rest = NULL) + bool startsWithIgnoreAsciiCase(std::string_view str, OString * rest) const { + assert(rest); bool b = matchIgnoreAsciiCase(str); - if (b && rest != NULL) { + if (b) { *rest = copy(str.size()); } return b; } + /** + 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 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, ignoring the case of ASCII letters ("A"--"Z" and + "a"--"z") + + @since LibreOffice 24.2 + */ + bool startsWithIgnoreAsciiCase(std::string_view str, std::string_view * rest) + const + { + assert(rest); + bool b = matchIgnoreAsciiCase(str); + if (b) { + *rest = subView(str.size()); + } + return b; + } #else + /** + 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. + + @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") + + @since LibreOffice 5.1 + */ bool startsWithIgnoreAsciiCase(OString const & str, OString * rest = NULL) const { @@ -1150,6 +1318,57 @@ public: } #endif +#if defined LIBO_INTERNAL_ONLY + /** + @overload + This function accepts an ASCII string literal as its argument. + @since LibreOffice 5.1 + */ + template< typename T > + typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type + startsWithIgnoreAsciiCase(T & literal) const + { + RTL_STRING_CONST_FUNCTION + assert( + libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal)); + return matchIgnoreAsciiCase(literal); + } + /** + @overload + This function accepts an ASCII string literal as its argument. + @since LibreOffice 5.1 + */ + template< typename T > + typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type + startsWithIgnoreAsciiCase(T & literal, OString * rest) const + { + RTL_STRING_CONST_FUNCTION + assert( + libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal)); + assert(rest); + bool b = matchIgnoreAsciiCase(literal); + if (b) { + *rest = copy( + libreoffice_internal::ConstCharArrayDetector<T>::length); + } + return b; + } + template< typename T > + typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type + startsWithIgnoreAsciiCase(T & literal, std::string_view * rest) const + { + RTL_STRING_CONST_FUNCTION + assert( + libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal)); + assert(rest); + bool b = matchIgnoreAsciiCase(literal); + if (b) { + *rest = subView( + libreoffice_internal::ConstCharArrayDetector<T>::length); + } + return b; + } +#else /** @overload This function accepts an ASCII string literal as its argument. @@ -1169,13 +1388,29 @@ public: } return b; } +#endif +#if defined LIBO_INTERNAL_ONLY /** Check whether this string ends with a given substring. @param str the substring to be compared - @param rest if non-null, and this function returns true, then assign a + @return true if and only if the given str appears as a substring at the + end of this string + + @since LibreOffice 3.6 + */ + bool endsWith(std::string_view str) const { + return str.size() <= sal_uInt32(getLength()) + && match(str, getLength() - str.size()); + } + /** + Check whether this string ends 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 @@ -1184,16 +1419,52 @@ public: @since LibreOffice 3.6 */ -#if defined LIBO_INTERNAL_ONLY - bool endsWith(std::string_view str, OString * rest = NULL) const { + bool endsWith(std::string_view str, OString * rest) const { + assert(rest); bool b = str.size() <= sal_uInt32(getLength()) && match(str, getLength() - str.size()); - if (b && rest != NULL) { + if (b) { *rest = copy(0, getLength() - str.size()); } return b; } + /** + Check whether this string ends 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 + end of this string + + @since LibreOffice 24.2 + */ + bool endsWith(std::string_view str, std::string_view * rest) const { + assert(rest); + bool b = str.size() <= sal_uInt32(getLength()) + && match(str, getLength() - str.size()); + if (b) { + *rest = subView(0, getLength() - str.size()); + } + return b; + } #else + /** + Check whether this string ends 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 + end of this string + + @since LibreOffice 3.6 + */ bool endsWith(OString const & str, OString * rest = NULL) const { bool b = str.getLength() <= getLength() && match(str, getLength() - str.getLength()); @@ -1204,6 +1475,88 @@ public: } #endif +#if defined LIBO_INTERNAL_ONLY + /** + @overload + This function accepts an ASCII string literal as its argument. + @since LibreOffice 25.2 + */ + template< typename T > + typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type endsWith( + T & literal) const + { + RTL_STRING_CONST_FUNCTION + assert( + libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal)); + bool b + = (libreoffice_internal::ConstCharArrayDetector<T>::length + <= sal_uInt32(getLength())) + && match( + libreoffice_internal::ConstCharArrayDetector<T>::toPointer( + literal), + (getLength() + - libreoffice_internal::ConstCharArrayDetector<T>::length)); + return b; + } + /** + @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 endsWith( + T & literal, OString * rest) const + { + RTL_STRING_CONST_FUNCTION + assert( + libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal)); + assert(rest); + bool b + = (libreoffice_internal::ConstCharArrayDetector<T>::length + <= sal_uInt32(getLength())) + && match( + libreoffice_internal::ConstCharArrayDetector<T>::toPointer( + literal), + (getLength() + - libreoffice_internal::ConstCharArrayDetector<T>::length)); + if (b) { + *rest = copy( + 0, + (getLength() + - libreoffice_internal::ConstCharArrayDetector<T>::length)); + } + return b; + } + /** + @overload + This function accepts an ASCII string literal as its argument. + @since LibreOffice 25.2 + */ + template< typename T > + typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type endsWith( + T & literal, std::string_view * rest) const + { + RTL_STRING_CONST_FUNCTION + assert( + libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal)); + assert(rest); + bool b + = (libreoffice_internal::ConstCharArrayDetector<T>::length + <= sal_uInt32(getLength())) + && match( + libreoffice_internal::ConstCharArrayDetector<T>::toPointer( + literal), + (getLength() + - libreoffice_internal::ConstCharArrayDetector<T>::length)); + if (b) { + *rest = subView( + 0, + (getLength() + - libreoffice_internal::ConstCharArrayDetector<T>::length)); + } + return b; + } +#else /** @overload This function accepts an ASCII string literal as its argument. @@ -1232,6 +1585,7 @@ public: } return b; } +#endif /** Check whether this string ends with a given substring. |