Delegate match to main internal starts/endsWith*

This simplifies and deduplicates the code, and even where it was simple,
it has an advantage that if a change in algorithm is decided, it is done
in a single place.

Change-Id: I9ec55a29c5f2b2c972ac81bf07c20fc0a52a2a8b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171033
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Tested-by: Jenkins
This commit is contained in:
Mike Kaganski 2024-07-26 07:56:18 +02:00
parent fa10be85d2
commit a79f9a7932
2 changed files with 27 additions and 127 deletions

View file

@ -1088,7 +1088,7 @@ public:
*/
bool startsWith(std::string_view str, OString * rest) const {
assert(rest);
bool b = match(str);
bool b = startsWith(str);
if (b) {
*rest = copy(str.size());
}
@ -1109,7 +1109,7 @@ public:
*/
bool startsWith(std::string_view str, std::string_view * rest) const {
assert(rest);
bool b = match(str);
bool b = startsWith(str);
if (b) {
*rest = subView(str.size());
}
@ -1163,7 +1163,7 @@ public:
{
RTL_STRING_CONST_FUNCTION
assert(rest);
bool b = match(literal, 0);
bool b = startsWith(literal);
if (b) {
*rest = copy(
libreoffice_internal::ConstCharArrayDetector<T>::length);
@ -1180,7 +1180,7 @@ public:
{
RTL_STRING_CONST_FUNCTION
assert(rest);
bool b = match(literal, 0);
bool b = startsWith(literal);
if (b) {
*rest = subView(
libreoffice_internal::ConstCharArrayDetector<T>::length);
@ -1252,7 +1252,7 @@ public:
const
{
assert(rest);
bool b = matchIgnoreAsciiCase(str);
bool b = startsWithIgnoreAsciiCase(str);
if (b) {
*rest = copy(str.size());
}
@ -1281,7 +1281,7 @@ public:
const
{
assert(rest);
bool b = matchIgnoreAsciiCase(str);
bool b = startsWithIgnoreAsciiCase(str);
if (b) {
*rest = subView(str.size());
}
@ -1343,10 +1343,8 @@ public:
startsWithIgnoreAsciiCase(T & literal, OString * rest) const
{
RTL_STRING_CONST_FUNCTION
assert(
libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
assert(rest);
bool b = matchIgnoreAsciiCase(literal);
bool b = startsWithIgnoreAsciiCase(literal);
if (b) {
*rest = copy(
libreoffice_internal::ConstCharArrayDetector<T>::length);
@ -1358,10 +1356,8 @@ public:
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);
bool b = startsWithIgnoreAsciiCase(literal);
if (b) {
*rest = subView(
libreoffice_internal::ConstCharArrayDetector<T>::length);
@ -1421,8 +1417,7 @@ public:
*/
bool endsWith(std::string_view str, OString * rest) const {
assert(rest);
bool b = str.size() <= sal_uInt32(getLength())
&& match(str, getLength() - str.size());
bool b = endsWith(str);
if (b) {
*rest = copy(0, getLength() - str.size());
}
@ -1443,8 +1438,7 @@ public:
*/
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());
bool b = endsWith(str);
if (b) {
*rest = subView(0, getLength() - str.size());
}
@ -1508,17 +1502,8 @@ public:
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));
bool b = endsWith(literal);
if (b) {
*rest = copy(
0,
@ -1537,17 +1522,8 @@ public:
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));
bool b = endsWith(literal);
if (b) {
*rest = subView(
0,

View file

@ -1476,7 +1476,7 @@ public:
*/
bool startsWith(std::u16string_view sv, OUString * rest) const {
assert(rest);
auto const b = match(sv);
auto const b = startsWith(sv);
if (b) {
*rest = copy(sv.size());
}
@ -1497,7 +1497,7 @@ public:
*/
bool startsWith(std::u16string_view sv, std::u16string_view * rest) const {
assert(rest);
auto const b = match(sv);
auto const b = startsWith(sv);
if (b) {
*rest = subView(sv.size());
}
@ -1557,17 +1557,8 @@ public:
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);
bool b = startsWith(literal);
if (b) {
*rest = copy(
libreoffice_internal::ConstCharArrayDetector<T>::length);
@ -1582,17 +1573,8 @@ public:
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);
bool b = startsWith(literal);
if (b) {
*rest = subView(
libreoffice_internal::ConstCharArrayDetector<T>::length);
@ -1653,7 +1635,7 @@ public:
}
bool startsWithIgnoreAsciiCase(std::u16string_view sv, OUString * rest) const {
assert(rest);
auto const b = matchIgnoreAsciiCase(sv);
auto const b = startsWithIgnoreAsciiCase(sv);
if (b) {
*rest = copy(sv.size());
}
@ -1661,7 +1643,7 @@ public:
}
bool startsWithIgnoreAsciiCase(std::u16string_view sv, std::u16string_view * rest) const {
assert(rest);
auto const b = matchIgnoreAsciiCase(sv);
auto const b = startsWithIgnoreAsciiCase(sv);
if (b) {
*rest = subView(sv.size());
}
@ -1712,19 +1694,8 @@ public:
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);
bool b = startsWithIgnoreAsciiCase(literal);
if (b) {
*rest = copy(
libreoffice_internal::ConstCharArrayDetector<T>::length);
@ -1739,19 +1710,8 @@ public:
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);
bool b = startsWithIgnoreAsciiCase(literal);
if (b) {
*rest = subView(
libreoffice_internal::ConstCharArrayDetector<T>::length);
@ -1804,8 +1764,7 @@ public:
&& 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());
auto const b = endsWith(sv);
if (b && rest != nullptr) {
*rest = copy(0, (pData->length - sv.size()));
}
@ -1826,8 +1785,7 @@ public:
*/
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());
auto const b = endsWith(sv);
if (b) {
*rest = subView(0, (pData->length - sv.size()));
}
@ -1885,18 +1843,8 @@ public:
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);
bool b = endsWith(literal);
if (b) {
*rest = copy(
0,
@ -1909,18 +1857,8 @@ public:
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);
bool b = endsWith(literal);
if (b) {
*rest = subView(
0,
@ -2006,8 +1944,7 @@ public:
&& 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());
auto const b = endsWithIgnoreAsciiCase(sv);
if (b && rest != nullptr) {
*rest = copy(0, pData->length - sv.size());
}
@ -2034,8 +1971,7 @@ public:
*/
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());
auto const b = endsWithIgnoreAsciiCase(sv);
if (b) {
*rest = subView(0, pData->length - sv.size());
}
@ -2105,20 +2041,8 @@ public:
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);
bool b = endsWithIgnoreAsciiCase(literal);
if (b) {
*rest = subView(
0,