summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2024-05-14 14:56:47 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2024-07-25 13:29:11 +0200
commit1bbcc3fdf312971ffb681b332f47369739d95dde (patch)
tree649e44c2e46b2c16973333300103cd152b9523ac /include
parentb84ef4d67eaf9f9fd7fd700ca05339cb0cdff742 (diff)
O[U]String overloads that return view for rest parameter
Add new overloads to OUString methods that have a "OUString* rest" style parameter. Instead return a view, which does not require allocation. To avoid overload ambiguity, split the methods into different variants that do not use default parameters. Change-Id: I1aa366115750f1f7ea4fe665804195f59f7c4b69 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167632 Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk> Tested-by: Jenkins
Diffstat (limited to 'include')
-rw-r--r--include/rtl/string.hxx382
-rw-r--r--include/rtl/ustring.hxx463
2 files changed, 816 insertions, 29 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.
diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index 39567014c395..aeab698c8238 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -1446,12 +1446,26 @@ public:
const;
#endif
+#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
+ @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
@@ -1460,15 +1474,50 @@ public:
@since LibreOffice 4.0
*/
-#if defined LIBO_INTERNAL_ONLY
- bool startsWith(std::u16string_view sv, OUString * rest = nullptr) const {
+ bool startsWith(std::u16string_view sv, OUString * rest) const {
+ assert(rest);
auto const b = match(sv);
- if (b && rest != nullptr) {
+ 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 24.2
+ */
+ bool startsWith(std::u16string_view sv, std::u16string_view * rest) const {
+ assert(rest);
+ auto const b = match(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
+
+ @since LibreOffice 4.0
+ */
bool startsWith(OUString const & str, OUString * rest = NULL) const {
bool b = match(str);
if (b && rest != NULL) {
@@ -1478,6 +1527,79 @@ public:
}
#endif
+#if defined 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(
+ libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
+ assert(rest);
+ 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 = 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(
+ libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
+ assert(rest);
+ 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 = subView(
+ libreoffice_internal::ConstCharArrayDetector<T>::length);
+ }
+ return b;
+ }
+#else
/**
@overload
This function accepts an ASCII string literal as its argument.
@@ -1503,6 +1625,7 @@ public:
}
return b;
}
+#endif
/**
Check whether this string starts with a given string, ignoring the case of
@@ -1525,13 +1648,25 @@ public:
@since LibreOffice 4.0
*/
#if defined LIBO_INTERNAL_ONLY
- bool startsWithIgnoreAsciiCase(std::u16string_view sv, OUString * rest = nullptr) const {
+ bool startsWithIgnoreAsciiCase(std::u16string_view sv) const {
+ return matchIgnoreAsciiCase(sv);
+ }
+ bool startsWithIgnoreAsciiCase(std::u16string_view sv, OUString * rest) const {
+ assert(rest);
auto const b = matchIgnoreAsciiCase(sv);
- if (b && rest != nullptr) {
+ if (b) {
*rest = copy(sv.size());
}
return b;
}
+ bool startsWithIgnoreAsciiCase(std::u16string_view sv, std::u16string_view * rest) const {
+ assert(rest);
+ auto const b = matchIgnoreAsciiCase(sv);
+ if (b) {
+ *rest = subView(sv.size());
+ }
+ return b;
+ }
#else
bool startsWithIgnoreAsciiCase(OUString const & str, OUString * rest = NULL)
const
@@ -1544,6 +1679,86 @@ 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
+ startsWithIgnoreAsciiCase(T & literal) const
+ {
+ assert(
+ libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
+ bool b
+ = (libreoffice_internal::ConstCharArrayDetector<T>::length
+ <= sal_uInt32(pData->length))
+ && (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(
+ pData->buffer,
+ libreoffice_internal::ConstCharArrayDetector<T>::length,
+ libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
+ literal),
+ libreoffice_internal::ConstCharArrayDetector<T>::length)
+ == 0);
+ 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
+ startsWithIgnoreAsciiCase(T & literal, OUString * rest) const
+ {
+ assert(
+ libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
+ assert(rest);
+ bool b
+ = (libreoffice_internal::ConstCharArrayDetector<T>::length
+ <= sal_uInt32(pData->length))
+ && (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(
+ pData->buffer,
+ libreoffice_internal::ConstCharArrayDetector<T>::length,
+ libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
+ literal),
+ libreoffice_internal::ConstCharArrayDetector<T>::length)
+ == 0);
+ if (b) {
+ *rest = copy(
+ libreoffice_internal::ConstCharArrayDetector<T>::length);
+ }
+ return b;
+ }
+ /**
+ This function accepts an ASCII string literal as its argument.
+ @since LibreOffice 24.2
+ */
+ template< typename T >
+ typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
+ startsWithIgnoreAsciiCase(T & literal, std::u16string_view * rest) const
+ {
+ assert(
+ libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
+ assert(rest);
+ bool b
+ = (libreoffice_internal::ConstCharArrayDetector<T>::length
+ <= sal_uInt32(pData->length))
+ && (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(
+ pData->buffer,
+ libreoffice_internal::ConstCharArrayDetector<T>::length,
+ libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
+ literal),
+ libreoffice_internal::ConstCharArrayDetector<T>::length)
+ == 0);
+ if (b) {
+ *rest = subView(
+ libreoffice_internal::ConstCharArrayDetector<T>::length);
+ }
+ return b;
+ }
+#else
/**
@overload
This function accepts an ASCII string literal as its argument.
@@ -1571,23 +1786,24 @@ 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
- 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
*/
-#if defined LIBO_INTERNAL_ONLY
- bool endsWith(std::u16string_view sv, OUString * rest = nullptr) const {
+ bool endsWith(std::u16string_view sv) const {
+ return sv.size() <= sal_uInt32(pData->length)
+ && match(sv, pData->length - sv.size());
+ }
+ bool endsWith(std::u16string_view sv, OUString * rest) const {
auto const b = sv.size() <= sal_uInt32(pData->length)
&& match(sv, pData->length - sv.size());
if (b && rest != nullptr) {
@@ -1595,7 +1811,43 @@ public:
}
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::u16string_view sv, std::u16string_view * rest) const {
+ assert(rest);
+ auto const b = sv.size() <= sal_uInt32(pData->length)
+ && match(sv, pData->length - sv.size());
+ if (b) {
+ *rest = subView(0, (pData->length - sv.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(OUString const & str, OUString * rest = NULL) const {
bool b = str.getLength() <= getLength()
&& match(str, getLength() - str.getLength());
@@ -1606,6 +1858,78 @@ 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
+ {
+ 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 + pData->length
+ - libreoffice_internal::ConstCharArrayDetector<T>::length),
+ libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
+ literal),
+ libreoffice_internal::ConstCharArrayDetector<T>::length);
+ return b;
+ }
+ template< typename T >
+ typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
+ endsWith(T & literal, OUString * rest) const
+ {
+ assert(
+ libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
+ assert(rest);
+ bool b
+ = (libreoffice_internal::ConstCharArrayDetector<T>::length
+ <= sal_uInt32(pData->length))
+ && rtl_ustr_asciil_reverseEquals_WithLength(
+ (pData->buffer + pData->length
+ - libreoffice_internal::ConstCharArrayDetector<T>::length),
+ libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
+ literal),
+ libreoffice_internal::ConstCharArrayDetector<T>::length);
+ if (b) {
+ *rest = copy(
+ 0,
+ (getLength()
+ - libreoffice_internal::ConstCharArrayDetector<T>::length));
+ }
+ return b;
+ }
+ template< typename T >
+ typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
+ endsWith(T & literal, std::u16string_view * rest) const
+ {
+ assert(
+ libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
+ assert(rest);
+ bool b
+ = (libreoffice_internal::ConstCharArrayDetector<T>::length
+ <= sal_uInt32(pData->length))
+ && rtl_ustr_asciil_reverseEquals_WithLength(
+ (pData->buffer + pData->length
+ - libreoffice_internal::ConstCharArrayDetector<T>::length),
+ libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
+ literal),
+ 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.
@@ -1634,6 +1958,7 @@ public:
}
return b;
}
+#endif
/**
Check whether this string ends with a given ASCII string.
@@ -1655,6 +1980,7 @@ public:
asciiStrLength);
}
+#if defined LIBO_INTERNAL_ONLY
/**
Check whether this string ends with a given string, ignoring the case of
ASCII letters.
@@ -1665,7 +1991,7 @@ public:
@param str the substring to be compared
- @param rest if non-null, and this function returns true, then assign a
+ @param rest if this function returns true, then assign a
copy of the remainder of this string to *rest. Available since
LibreOffice 4.2
@@ -1675,8 +2001,11 @@ public:
@since LibreOffice 3.6
*/
-#if defined LIBO_INTERNAL_ONLY
- bool endsWithIgnoreAsciiCase(std::u16string_view sv, OUString * rest = nullptr) const {
+ bool endsWithIgnoreAsciiCase(std::u16string_view sv) const {
+ return sv.size() <= sal_uInt32(pData->length)
+ && matchIgnoreAsciiCase(sv, pData->length - sv.size());
+ }
+ bool endsWithIgnoreAsciiCase(std::u16string_view sv, OUString * rest) const {
auto const b = sv.size() <= sal_uInt32(pData->length)
&& matchIgnoreAsciiCase(sv, pData->length - sv.size());
if (b && rest != nullptr) {
@@ -1684,7 +2013,55 @@ public:
}
return b;
}
+ /**
+ Check whether this string ends 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
+ end of this string, ignoring the case of ASCII letters ("A"--"Z" and
+ "a"--"z")
+
+ @since LibreOffice 24.2
+ */
+ bool endsWithIgnoreAsciiCase(std::u16string_view sv, std::u16string_view * rest) const {
+ assert(rest);
+ auto const b = sv.size() <= sal_uInt32(pData->length)
+ && matchIgnoreAsciiCase(sv, pData->length - sv.size());
+ if (b) {
+ *rest = subView(0, pData->length - sv.size());
+ }
+ return b;
+ }
#else
+ /**
+ Check whether this string ends 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
+ end of this string, ignoring the case of ASCII letters ("A"--"Z" and
+ "a"--"z")
+
+ @since LibreOffice 3.6
+ */
bool endsWithIgnoreAsciiCase(OUString const & str, OUString * rest = NULL) const
{
bool b = str.getLength() <= getLength()
@@ -1696,6 +2073,61 @@ public:
}
#endif
+#if defined LIBO_INTERNAL_ONLY
+ /**
+ This function accepts an ASCII string literal as its argument.
+ @since LibreOffice 24.2
+ */
+ template< typename T >
+ typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
+ endsWithIgnoreAsciiCase(T & literal) const
+ {
+ assert(
+ libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
+ bool b
+ = (libreoffice_internal::ConstCharArrayDetector<T>::length
+ <= sal_uInt32(pData->length))
+ && (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(
+ (pData->buffer + pData->length
+ - libreoffice_internal::ConstCharArrayDetector<T>::length),
+ libreoffice_internal::ConstCharArrayDetector<T>::length,
+ libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
+ literal),
+ libreoffice_internal::ConstCharArrayDetector<T>::length)
+ == 0);
+ return b;
+ }
+ /**
+ This function accepts an ASCII string literal as its argument.
+ @since LibreOffice 24.2
+ */
+ template< typename T >
+ typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
+ endsWithIgnoreAsciiCase(T & literal, std::u16string_view * rest) const
+ {
+ assert(
+ libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
+ assert(rest);
+ bool b
+ = (libreoffice_internal::ConstCharArrayDetector<T>::length
+ <= sal_uInt32(pData->length))
+ && (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(
+ (pData->buffer + pData->length
+ - libreoffice_internal::ConstCharArrayDetector<T>::length),
+ libreoffice_internal::ConstCharArrayDetector<T>::length,
+ libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
+ literal),
+ libreoffice_internal::ConstCharArrayDetector<T>::length)
+ == 0);
+ 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.
@@ -1726,6 +2158,7 @@ public:
}
return b;
}
+#endif
/**
Check whether this string ends with a given ASCII string, ignoring the