Some more o3tl::starts/ends_with overloads

...including ones with a rest out parameter, modeled after their O(U)String
counterparts and not present in any C++ standard (so intended to stay in o3tl,
even when the C++20 wrappers are eventually removed again).  Plus test code.

These additional overloads will be used in forthcoming commits changing more
places to use std string_view.

Change-Id: Ifd05e0fdcb93e8751da22b8e4a59796ad00fe581
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122407
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
This commit is contained in:
Stephan Bergmann
2021-09-21 22:19:06 +02:00
parent 58a67e6109
commit b46894e7d0
3 changed files with 713 additions and 0 deletions

View File

@@ -15,6 +15,7 @@
#include <cstddef>
#include <string>
#include <string_view>
#include <type_traits>
#include <rtl/ustring.h>
@@ -107,6 +108,126 @@ constexpr bool ends_with(std::basic_string_view<charT, traits> sv, charT const*
return ends_with(sv, std::basic_string_view<charT, traits>(x));
#endif
}
// The following overloads prevent deduction failures that would occur with their template
// counterparts, when x is of a type that is implicitly convertible to basic_string_view (like
// OString or OUString, and we only bother to provide overloads for the char and char16_t cases, not
// also for char32_t and wchar_t, nor for C++20 char8_t):
constexpr bool starts_with(std::string_view sv, std::string_view x) noexcept
{
return starts_with<char>(sv, x);
}
constexpr bool starts_with(std::u16string_view sv, std::u16string_view x) noexcept
{
return starts_with<char16_t>(sv, x);
}
constexpr bool ends_with(std::string_view sv, std::string_view x) noexcept
{
return ends_with<char>(sv, x);
}
constexpr bool ends_with(std::u16string_view sv, std::u16string_view x) noexcept
{
return ends_with<char16_t>(sv, x);
}
// Variants of C++20 std::basic_string_view::starts_with and
// std::basic_string_view::ends_with that have a rest out parameter, similar to our OString and
// OUString startsWith and endsWith member functions:
template <typename charT, typename traits = std::char_traits<charT>>
constexpr bool starts_with(std::basic_string_view<charT, traits> sv,
std::basic_string_view<charT, traits> x,
std::basic_string_view<charT, traits>* rest) noexcept
{
assert(rest != nullptr);
auto const found = starts_with(sv, x);
if (found)
{
*rest = sv.substr(x.length());
}
return found;
}
template <typename charT, typename traits = std::char_traits<charT>>
constexpr bool starts_with(std::basic_string_view<charT, traits> sv, charT x,
std::basic_string_view<charT, traits>* rest) noexcept
{
assert(rest != nullptr);
auto const found = starts_with(sv, x);
if (found)
{
*rest = sv.substr(1);
}
return found;
}
template <typename charT, typename traits = std::char_traits<charT>>
constexpr bool starts_with(std::basic_string_view<charT, traits> sv, charT const* x,
std::basic_string_view<charT, traits>* rest)
{
assert(rest != nullptr);
auto const found = starts_with(sv, x);
if (found)
{
*rest = sv.substr(traits::length(x));
}
return found;
}
template <typename charT, typename traits = std::char_traits<charT>>
constexpr bool ends_with(std::basic_string_view<charT, traits> sv,
std::basic_string_view<charT, traits> x,
std::basic_string_view<charT, traits>* rest) noexcept
{
assert(rest != nullptr);
auto const found = ends_with(sv, x);
if (found)
{
*rest = sv.substr(0, sv.length() - x.length());
}
return found;
}
template <typename charT, typename traits = std::char_traits<charT>>
constexpr bool ends_with(std::basic_string_view<charT, traits> sv, charT x,
std::basic_string_view<charT, traits>* rest) noexcept
{
assert(rest != nullptr);
auto const found = ends_with(sv, x);
if (found)
{
*rest = sv.substr(0, sv.length() - 1);
}
return found;
}
template <typename charT, typename traits = std::char_traits<charT>>
constexpr bool ends_with(std::basic_string_view<charT, traits> sv, charT const* x,
std::basic_string_view<charT, traits>* rest)
{
assert(rest != nullptr);
auto const found = ends_with(sv, x);
if (found)
{
*rest = sv.substr(0, sv.length() - traits::length(x));
}
return found;
}
// The following overloads prevent deduction failures that would occur with their template
// counterparts, when x is of a type that is implicitly convertible to basic_string_view (like
// OString or OUString, and we only bother to provide overloads for the char and char16_t cases, not
// also for char32_t and wchar_t, nor for C++20 char8_t):
constexpr bool starts_with(std::string_view sv, std::string_view x, std::string_view* rest) noexcept
{
return starts_with<char>(sv, x, rest);
}
constexpr bool starts_with(std::u16string_view sv, std::u16string_view x,
std::u16string_view* rest) noexcept
{
return starts_with<char16_t>(sv, x, rest);
}
constexpr bool ends_with(std::string_view sv, std::string_view x, std::string_view* rest) noexcept
{
return ends_with<char>(sv, x, rest);
}
constexpr bool ends_with(std::u16string_view sv, std::u16string_view x,
std::u16string_view* rest) noexcept
{
return ends_with<char16_t>(sv, x, rest);
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */

View File

@@ -33,6 +33,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,o3tl_tests,\
o3tl/qa/test-safeint \
o3tl/qa/test-sorted_vector \
o3tl/qa/test-span \
o3tl/qa/test-string_view \
o3tl/qa/test-temporary \
o3tl/qa/test-typed_flags \
o3tl/qa/test-unit_conversion \

View File

@@ -0,0 +1,591 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* 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/.
*/
#include <sal/config.h>
#include <iostream>
#include <string_view>
#include <cppunit/TestAssert.h>
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
#include <o3tl/string_view.hxx>
#include <rtl/string.hxx>
#include <rtl/ustring.hxx>
namespace CppUnit
{
template <> struct assertion_traits<std::u16string_view>
{
static bool equal(std::u16string_view x, std::u16string_view y) { return x == y; }
static std::string toString(std::u16string_view x)
{
return OUStringToOString(x, RTL_TEXTENCODING_UTF8).getStr();
}
};
}
namespace
{
OString ostringEmpty() { return {}; } // avoid loplugin:stringview
OString ostringDoof() { return "doof"; } // avoid loplugin:stringview
OString ostringFoo() { return "foo"; } // avoid loplugin:stringview
OString ostringFoobars() { return "foobars"; } // avoid loplugin:stringview
OString ostringFood() { return "food"; } // avoid loplugin:stringview
OString ostringOof() { return "oof"; } // avoid loplugin:stringview
OString ostringSraboof() { return "sraboof"; } // avoid loplugin:stringview
OUString oustringEmpty() { return {}; } // avoid loplugin:stringview
OUString oustringDoof() { return "doof"; } // avoid loplugin:stringview
OUString oustringFoo() { return "foo"; } // avoid loplugin:stringview
OUString oustringFoobars() { return "foobars"; } // avoid loplugin:stringview
OUString oustringFood() { return "food"; } // avoid loplugin:stringview
OUString oustringOof() { return "oof"; } // avoid loplugin:stringview
OUString oustringSraboof() { return "sraboof"; } // avoid loplugin:stringview
class Test : public CppUnit::TestFixture
{
private:
CPPUNIT_TEST_SUITE(Test);
CPPUNIT_TEST(testStartsWith);
CPPUNIT_TEST(testStartsWithRest);
CPPUNIT_TEST(testEndsWith);
CPPUNIT_TEST(testEndsWithRest);
CPPUNIT_TEST_SUITE_END();
void testStartsWith()
{
using namespace std::string_view_literals;
CPPUNIT_ASSERT(o3tl::starts_with(""sv, ""sv));
CPPUNIT_ASSERT(!o3tl::starts_with(""sv, "foo"sv));
CPPUNIT_ASSERT(o3tl::starts_with("foobar"sv, ""sv));
CPPUNIT_ASSERT(o3tl::starts_with("foobar"sv, "foo"sv));
CPPUNIT_ASSERT(!o3tl::starts_with("foobar"sv, "food"sv));
CPPUNIT_ASSERT(!o3tl::starts_with("foobar"sv, "foobars"sv));
CPPUNIT_ASSERT(!o3tl::starts_with(""sv, 'f'));
CPPUNIT_ASSERT(o3tl::starts_with("foobar"sv, 'f'));
CPPUNIT_ASSERT(!o3tl::starts_with("foobar"sv, 'g'));
CPPUNIT_ASSERT(o3tl::starts_with(""sv, ""));
CPPUNIT_ASSERT(!o3tl::starts_with(""sv, "foo"));
CPPUNIT_ASSERT(o3tl::starts_with("foobar"sv, ""));
CPPUNIT_ASSERT(o3tl::starts_with("foobar"sv, "foo"));
CPPUNIT_ASSERT(!o3tl::starts_with("foobar"sv, "food"));
CPPUNIT_ASSERT(!o3tl::starts_with("foobar"sv, "foobars"));
CPPUNIT_ASSERT(o3tl::starts_with(""sv, ostringEmpty()));
CPPUNIT_ASSERT(!o3tl::starts_with(""sv, ostringFoo()));
CPPUNIT_ASSERT(o3tl::starts_with("foobar"sv, ostringEmpty()));
CPPUNIT_ASSERT(o3tl::starts_with("foobar"sv, ostringFoo()));
CPPUNIT_ASSERT(!o3tl::starts_with("foobar"sv, ostringFood()));
CPPUNIT_ASSERT(!o3tl::starts_with("foobar"sv, ostringFoobars()));
CPPUNIT_ASSERT(o3tl::starts_with(u""sv, u""sv));
CPPUNIT_ASSERT(!o3tl::starts_with(u""sv, u"foo"sv));
CPPUNIT_ASSERT(o3tl::starts_with(u"foobar"sv, u""sv));
CPPUNIT_ASSERT(o3tl::starts_with(u"foobar"sv, u"foo"sv));
CPPUNIT_ASSERT(!o3tl::starts_with(u"foobar"sv, u"food"sv));
CPPUNIT_ASSERT(!o3tl::starts_with(u"foobar"sv, u"foobars"sv));
CPPUNIT_ASSERT(!o3tl::starts_with(u""sv, u'f'));
CPPUNIT_ASSERT(o3tl::starts_with(u"foobar"sv, u'f'));
CPPUNIT_ASSERT(!o3tl::starts_with(u"foobar"sv, u'g'));
CPPUNIT_ASSERT(o3tl::starts_with(u""sv, u""));
CPPUNIT_ASSERT(!o3tl::starts_with(u""sv, u"foo"));
CPPUNIT_ASSERT(o3tl::starts_with(u"foobar"sv, u""));
CPPUNIT_ASSERT(o3tl::starts_with(u"foobar"sv, u"foo"));
CPPUNIT_ASSERT(!o3tl::starts_with(u"foobar"sv, u"food"));
CPPUNIT_ASSERT(!o3tl::starts_with(u"foobar"sv, u"foobars"));
CPPUNIT_ASSERT(o3tl::starts_with(u""sv, oustringEmpty()));
CPPUNIT_ASSERT(!o3tl::starts_with(u""sv, oustringFoo()));
CPPUNIT_ASSERT(o3tl::starts_with(u"foobar"sv, oustringEmpty()));
CPPUNIT_ASSERT(o3tl::starts_with(u"foobar"sv, oustringFoo()));
CPPUNIT_ASSERT(!o3tl::starts_with(u"foobar"sv, oustringFood()));
CPPUNIT_ASSERT(!o3tl::starts_with(u"foobar"sv, oustringFoobars()));
}
void testStartsWithRest()
{
using namespace std::string_view_literals;
{
std::string_view rest;
CPPUNIT_ASSERT(o3tl::starts_with(""sv, ""sv, &rest));
CPPUNIT_ASSERT_EQUAL(""sv, rest);
}
{
std::string_view rest;
CPPUNIT_ASSERT(!o3tl::starts_with(""sv, "foo"sv, &rest));
CPPUNIT_ASSERT_EQUAL(""sv, rest);
}
{
std::string_view rest;
CPPUNIT_ASSERT(o3tl::starts_with("foobar"sv, ""sv, &rest));
CPPUNIT_ASSERT_EQUAL("foobar"sv, rest);
}
{
std::string_view rest;
CPPUNIT_ASSERT(o3tl::starts_with("foobar"sv, "foo"sv, &rest));
CPPUNIT_ASSERT_EQUAL("bar"sv, rest);
}
{
std::string_view rest;
CPPUNIT_ASSERT(!o3tl::starts_with("foobar"sv, "food"sv, &rest));
CPPUNIT_ASSERT_EQUAL(""sv, rest);
}
{
std::string_view rest;
CPPUNIT_ASSERT(!o3tl::starts_with("foobar"sv, "foobars"sv, &rest));
CPPUNIT_ASSERT_EQUAL(""sv, rest);
}
{
std::string_view rest;
CPPUNIT_ASSERT(!o3tl::starts_with(""sv, 'f', &rest));
CPPUNIT_ASSERT_EQUAL(""sv, rest);
}
{
std::string_view rest;
CPPUNIT_ASSERT(o3tl::starts_with("foobar"sv, 'f', &rest));
CPPUNIT_ASSERT_EQUAL("oobar"sv, rest);
}
{
std::string_view rest;
CPPUNIT_ASSERT(!o3tl::starts_with("foobar"sv, 'g', &rest));
CPPUNIT_ASSERT_EQUAL(""sv, rest);
}
{
std::string_view rest;
CPPUNIT_ASSERT(o3tl::starts_with(""sv, "", &rest));
CPPUNIT_ASSERT_EQUAL(""sv, rest);
}
{
std::string_view rest;
CPPUNIT_ASSERT(!o3tl::starts_with(""sv, "foo", &rest));
CPPUNIT_ASSERT_EQUAL(""sv, rest);
}
{
std::string_view rest;
CPPUNIT_ASSERT(o3tl::starts_with("foobar"sv, "", &rest));
CPPUNIT_ASSERT_EQUAL("foobar"sv, rest);
}
{
std::string_view rest;
CPPUNIT_ASSERT(o3tl::starts_with("foobar"sv, "foo", &rest));
CPPUNIT_ASSERT_EQUAL("bar"sv, rest);
}
{
std::string_view rest;
CPPUNIT_ASSERT(!o3tl::starts_with("foobar"sv, "food", &rest));
CPPUNIT_ASSERT_EQUAL(""sv, rest);
}
{
std::string_view rest;
CPPUNIT_ASSERT(!o3tl::starts_with("foobar"sv, "foobars", &rest));
CPPUNIT_ASSERT_EQUAL(""sv, rest);
}
{
std::string_view rest;
CPPUNIT_ASSERT(o3tl::starts_with(""sv, ostringEmpty(), &rest));
CPPUNIT_ASSERT_EQUAL(""sv, rest);
}
{
std::string_view rest;
CPPUNIT_ASSERT(!o3tl::starts_with(""sv, ostringFoo(), &rest));
CPPUNIT_ASSERT_EQUAL(""sv, rest);
}
{
std::string_view rest;
CPPUNIT_ASSERT(o3tl::starts_with("foobar"sv, ostringEmpty(), &rest));
CPPUNIT_ASSERT_EQUAL("foobar"sv, rest);
}
{
std::string_view rest;
CPPUNIT_ASSERT(o3tl::starts_with("foobar"sv, ostringFoo(), &rest));
CPPUNIT_ASSERT_EQUAL("bar"sv, rest);
}
{
std::string_view rest;
CPPUNIT_ASSERT(!o3tl::starts_with("foobar"sv, ostringFood(), &rest));
CPPUNIT_ASSERT_EQUAL(""sv, rest);
}
{
std::string_view rest;
CPPUNIT_ASSERT(!o3tl::starts_with("foobar"sv, ostringFoobars(), &rest));
CPPUNIT_ASSERT_EQUAL(""sv, rest);
}
{
std::u16string_view rest;
CPPUNIT_ASSERT(o3tl::starts_with(u""sv, u""sv, &rest));
CPPUNIT_ASSERT_EQUAL(u""sv, rest);
}
{
std::u16string_view rest;
CPPUNIT_ASSERT(!o3tl::starts_with(u""sv, u"foo"sv, &rest));
CPPUNIT_ASSERT_EQUAL(u""sv, rest);
}
{
std::u16string_view rest;
CPPUNIT_ASSERT(o3tl::starts_with(u"foobar"sv, u""sv, &rest));
CPPUNIT_ASSERT_EQUAL(u"foobar"sv, rest);
}
{
std::u16string_view rest;
CPPUNIT_ASSERT(o3tl::starts_with(u"foobar"sv, u"foo"sv, &rest));
CPPUNIT_ASSERT_EQUAL(u"bar"sv, rest);
}
{
std::u16string_view rest;
CPPUNIT_ASSERT(!o3tl::starts_with(u"foobar"sv, u"food"sv, &rest));
CPPUNIT_ASSERT_EQUAL(u""sv, rest);
}
{
std::u16string_view rest;
CPPUNIT_ASSERT(!o3tl::starts_with(u"foobar"sv, u"foobars"sv, &rest));
CPPUNIT_ASSERT_EQUAL(u""sv, rest);
}
{
std::u16string_view rest;
CPPUNIT_ASSERT(!o3tl::starts_with(u""sv, u'f', &rest));
CPPUNIT_ASSERT_EQUAL(u""sv, rest);
}
{
std::u16string_view rest;
CPPUNIT_ASSERT(o3tl::starts_with(u"foobar"sv, u'f', &rest));
CPPUNIT_ASSERT_EQUAL(u"oobar"sv, rest);
}
{
std::u16string_view rest;
CPPUNIT_ASSERT(!o3tl::starts_with(u"foobar"sv, u'g', &rest));
CPPUNIT_ASSERT_EQUAL(u""sv, rest);
}
{
std::u16string_view rest;
CPPUNIT_ASSERT(o3tl::starts_with(u""sv, u"", &rest));
CPPUNIT_ASSERT_EQUAL(u""sv, rest);
}
{
std::u16string_view rest;
CPPUNIT_ASSERT(!o3tl::starts_with(u""sv, u"foo", &rest));
CPPUNIT_ASSERT_EQUAL(u""sv, rest);
}
{
std::u16string_view rest;
CPPUNIT_ASSERT(o3tl::starts_with(u"foobar"sv, u"", &rest));
CPPUNIT_ASSERT_EQUAL(u"foobar"sv, rest);
}
{
std::u16string_view rest;
CPPUNIT_ASSERT(o3tl::starts_with(u"foobar"sv, u"foo", &rest));
CPPUNIT_ASSERT_EQUAL(u"bar"sv, rest);
}
{
std::u16string_view rest;
CPPUNIT_ASSERT(!o3tl::starts_with(u"foobar"sv, u"food", &rest));
CPPUNIT_ASSERT_EQUAL(u""sv, rest);
}
{
std::u16string_view rest;
CPPUNIT_ASSERT(!o3tl::starts_with(u"foobar"sv, u"foobars", &rest));
CPPUNIT_ASSERT_EQUAL(u""sv, rest);
}
{
std::u16string_view rest;
CPPUNIT_ASSERT(o3tl::starts_with(u""sv, oustringEmpty(), &rest));
CPPUNIT_ASSERT_EQUAL(u""sv, rest);
}
{
std::u16string_view rest;
CPPUNIT_ASSERT(!o3tl::starts_with(u""sv, oustringFoo(), &rest));
CPPUNIT_ASSERT_EQUAL(u""sv, rest);
}
{
std::u16string_view rest;
CPPUNIT_ASSERT(o3tl::starts_with(u"foobar"sv, oustringEmpty(), &rest));
CPPUNIT_ASSERT_EQUAL(u"foobar"sv, rest);
}
{
std::u16string_view rest;
CPPUNIT_ASSERT(o3tl::starts_with(u"foobar"sv, oustringFoo(), &rest));
CPPUNIT_ASSERT_EQUAL(u"bar"sv, rest);
}
{
std::u16string_view rest;
CPPUNIT_ASSERT(!o3tl::starts_with(u"foobar"sv, oustringFood(), &rest));
CPPUNIT_ASSERT_EQUAL(u""sv, rest);
}
{
std::u16string_view rest;
CPPUNIT_ASSERT(!o3tl::starts_with(u"foobar"sv, oustringFoobars(), &rest));
CPPUNIT_ASSERT_EQUAL(u""sv, rest);
}
}
void testEndsWith()
{
using namespace std::string_view_literals;
CPPUNIT_ASSERT(o3tl::ends_with(""sv, ""sv));
CPPUNIT_ASSERT(!o3tl::ends_with(""sv, "oof"sv));
CPPUNIT_ASSERT(o3tl::ends_with("raboof"sv, ""sv));
CPPUNIT_ASSERT(o3tl::ends_with("raboof"sv, "oof"sv));
CPPUNIT_ASSERT(!o3tl::ends_with("raboof"sv, "doof"sv));
CPPUNIT_ASSERT(!o3tl::ends_with("raboof"sv, "sraboof"sv));
CPPUNIT_ASSERT(!o3tl::ends_with(""sv, 'f'));
CPPUNIT_ASSERT(o3tl::ends_with("raboof"sv, 'f'));
CPPUNIT_ASSERT(!o3tl::ends_with("raboof"sv, 'g'));
CPPUNIT_ASSERT(o3tl::ends_with(""sv, ""));
CPPUNIT_ASSERT(!o3tl::ends_with(""sv, "oof"));
CPPUNIT_ASSERT(o3tl::ends_with("raboof"sv, ""));
CPPUNIT_ASSERT(o3tl::ends_with("raboof"sv, "oof"));
CPPUNIT_ASSERT(!o3tl::ends_with("raboof"sv, "doof"));
CPPUNIT_ASSERT(!o3tl::ends_with("raboof"sv, "sraboof"));
CPPUNIT_ASSERT(o3tl::ends_with(""sv, ostringEmpty()));
CPPUNIT_ASSERT(!o3tl::ends_with(""sv, ostringOof()));
CPPUNIT_ASSERT(o3tl::ends_with("raboof"sv, ostringEmpty()));
CPPUNIT_ASSERT(o3tl::ends_with("raboof"sv, ostringOof()));
CPPUNIT_ASSERT(!o3tl::ends_with("raboof"sv, ostringDoof()));
CPPUNIT_ASSERT(!o3tl::ends_with("raboof"sv, ostringSraboof()));
CPPUNIT_ASSERT(o3tl::ends_with(u""sv, u""sv));
CPPUNIT_ASSERT(!o3tl::ends_with(u""sv, u"oof"sv));
CPPUNIT_ASSERT(o3tl::ends_with(u"raboof"sv, u""sv));
CPPUNIT_ASSERT(o3tl::ends_with(u"raboof"sv, u"oof"sv));
CPPUNIT_ASSERT(!o3tl::ends_with(u"raboof"sv, u"doof"sv));
CPPUNIT_ASSERT(!o3tl::ends_with(u"raboof"sv, u"sraboof"sv));
CPPUNIT_ASSERT(!o3tl::ends_with(u""sv, u'f'));
CPPUNIT_ASSERT(o3tl::ends_with(u"raboof"sv, u'f'));
CPPUNIT_ASSERT(!o3tl::ends_with(u"raboof"sv, u'g'));
CPPUNIT_ASSERT(o3tl::ends_with(u""sv, u""));
CPPUNIT_ASSERT(!o3tl::ends_with(u""sv, u"oof"));
CPPUNIT_ASSERT(o3tl::ends_with(u"raboof"sv, u""));
CPPUNIT_ASSERT(o3tl::ends_with(u"raboof"sv, u"oof"));
CPPUNIT_ASSERT(!o3tl::ends_with(u"raboof"sv, u"doof"));
CPPUNIT_ASSERT(!o3tl::ends_with(u"raboof"sv, u"sraboof"));
CPPUNIT_ASSERT(o3tl::ends_with(u""sv, oustringEmpty()));
CPPUNIT_ASSERT(!o3tl::ends_with(u""sv, oustringOof()));
CPPUNIT_ASSERT(o3tl::ends_with(u"raboof"sv, oustringEmpty()));
CPPUNIT_ASSERT(o3tl::ends_with(u"raboof"sv, oustringOof()));
CPPUNIT_ASSERT(!o3tl::ends_with(u"raboof"sv, oustringDoof()));
CPPUNIT_ASSERT(!o3tl::ends_with(u"raboof"sv, oustringSraboof()));
}
void testEndsWithRest()
{
using namespace std::string_view_literals;
{
std::string_view rest;
CPPUNIT_ASSERT(o3tl::ends_with(""sv, ""sv, &rest));
CPPUNIT_ASSERT_EQUAL(""sv, rest);
}
{
std::string_view rest;
CPPUNIT_ASSERT(!o3tl::ends_with(""sv, "oof"sv, &rest));
CPPUNIT_ASSERT_EQUAL(""sv, rest);
}
{
std::string_view rest;
CPPUNIT_ASSERT(o3tl::ends_with("raboof"sv, ""sv, &rest));
CPPUNIT_ASSERT_EQUAL("raboof"sv, rest);
}
{
std::string_view rest;
CPPUNIT_ASSERT(o3tl::ends_with("raboof"sv, "oof"sv, &rest));
CPPUNIT_ASSERT_EQUAL("rab"sv, rest);
}
{
std::string_view rest;
CPPUNIT_ASSERT(!o3tl::ends_with("raboof"sv, "doof"sv, &rest));
CPPUNIT_ASSERT_EQUAL(""sv, rest);
}
{
std::string_view rest;
CPPUNIT_ASSERT(!o3tl::ends_with("raboof"sv, "sraboof"sv, &rest));
CPPUNIT_ASSERT_EQUAL(""sv, rest);
}
{
std::string_view rest;
CPPUNIT_ASSERT(!o3tl::ends_with(""sv, 'f', &rest));
CPPUNIT_ASSERT_EQUAL(""sv, rest);
}
{
std::string_view rest;
CPPUNIT_ASSERT(o3tl::ends_with("raboof"sv, 'f', &rest));
CPPUNIT_ASSERT_EQUAL("raboo"sv, rest);
}
{
std::string_view rest;
CPPUNIT_ASSERT(!o3tl::ends_with("raboof"sv, 'g', &rest));
CPPUNIT_ASSERT_EQUAL(""sv, rest);
}
{
std::string_view rest;
CPPUNIT_ASSERT(o3tl::ends_with(""sv, "", &rest));
CPPUNIT_ASSERT_EQUAL(""sv, rest);
}
{
std::string_view rest;
CPPUNIT_ASSERT(!o3tl::ends_with(""sv, "oof", &rest));
CPPUNIT_ASSERT_EQUAL(""sv, rest);
}
{
std::string_view rest;
CPPUNIT_ASSERT(o3tl::ends_with("raboof"sv, "", &rest));
CPPUNIT_ASSERT_EQUAL("raboof"sv, rest);
}
{
std::string_view rest;
CPPUNIT_ASSERT(o3tl::ends_with("raboof"sv, "oof", &rest));
CPPUNIT_ASSERT_EQUAL("rab"sv, rest);
}
{
std::string_view rest;
CPPUNIT_ASSERT(!o3tl::ends_with("raboof"sv, "doof", &rest));
CPPUNIT_ASSERT_EQUAL(""sv, rest);
}
{
std::string_view rest;
CPPUNIT_ASSERT(!o3tl::ends_with("raboof"sv, "sraboof", &rest));
CPPUNIT_ASSERT_EQUAL(""sv, rest);
}
{
std::string_view rest;
CPPUNIT_ASSERT(o3tl::ends_with(""sv, ostringEmpty(), &rest));
CPPUNIT_ASSERT_EQUAL(""sv, rest);
}
{
std::string_view rest;
CPPUNIT_ASSERT(!o3tl::ends_with(""sv, ostringOof(), &rest));
CPPUNIT_ASSERT_EQUAL(""sv, rest);
}
{
std::string_view rest;
CPPUNIT_ASSERT(o3tl::ends_with("raboof"sv, ostringEmpty(), &rest));
CPPUNIT_ASSERT_EQUAL("raboof"sv, rest);
}
{
std::string_view rest;
CPPUNIT_ASSERT(o3tl::ends_with("raboof"sv, ostringOof(), &rest));
CPPUNIT_ASSERT_EQUAL("rab"sv, rest);
}
{
std::string_view rest;
CPPUNIT_ASSERT(!o3tl::ends_with("raboof"sv, ostringDoof(), &rest));
CPPUNIT_ASSERT_EQUAL(""sv, rest);
}
{
std::string_view rest;
CPPUNIT_ASSERT(!o3tl::ends_with("raboof"sv, ostringSraboof(), &rest));
CPPUNIT_ASSERT_EQUAL(""sv, rest);
}
{
std::u16string_view rest;
CPPUNIT_ASSERT(o3tl::ends_with(u""sv, u""sv, &rest));
CPPUNIT_ASSERT_EQUAL(u""sv, rest);
}
{
std::u16string_view rest;
CPPUNIT_ASSERT(!o3tl::ends_with(u""sv, u"oof"sv, &rest));
CPPUNIT_ASSERT_EQUAL(u""sv, rest);
}
{
std::u16string_view rest;
CPPUNIT_ASSERT(o3tl::ends_with(u"raboof"sv, u""sv, &rest));
CPPUNIT_ASSERT_EQUAL(u"raboof"sv, rest);
}
{
std::u16string_view rest;
CPPUNIT_ASSERT(o3tl::ends_with(u"raboof"sv, u"oof"sv, &rest));
CPPUNIT_ASSERT_EQUAL(u"rab"sv, rest);
}
{
std::u16string_view rest;
CPPUNIT_ASSERT(!o3tl::ends_with(u"raboof"sv, u"doof"sv, &rest));
CPPUNIT_ASSERT_EQUAL(u""sv, rest);
}
{
std::u16string_view rest;
CPPUNIT_ASSERT(!o3tl::ends_with(u"raboof"sv, u"sraboof"sv, &rest));
CPPUNIT_ASSERT_EQUAL(u""sv, rest);
}
{
std::u16string_view rest;
CPPUNIT_ASSERT(!o3tl::ends_with(u""sv, u'f', &rest));
CPPUNIT_ASSERT_EQUAL(u""sv, rest);
}
{
std::u16string_view rest;
CPPUNIT_ASSERT(o3tl::ends_with(u"raboof"sv, u'f', &rest));
CPPUNIT_ASSERT_EQUAL(u"raboo"sv, rest);
}
{
std::u16string_view rest;
CPPUNIT_ASSERT(!o3tl::ends_with(u"raboof"sv, u'g', &rest));
CPPUNIT_ASSERT_EQUAL(u""sv, rest);
}
{
std::u16string_view rest;
CPPUNIT_ASSERT(o3tl::ends_with(u""sv, u"", &rest));
CPPUNIT_ASSERT_EQUAL(u""sv, rest);
}
{
std::u16string_view rest;
CPPUNIT_ASSERT(!o3tl::ends_with(u""sv, u"oof", &rest));
CPPUNIT_ASSERT_EQUAL(u""sv, rest);
}
{
std::u16string_view rest;
CPPUNIT_ASSERT(o3tl::ends_with(u"raboof"sv, u"", &rest));
CPPUNIT_ASSERT_EQUAL(u"raboof"sv, rest);
}
{
std::u16string_view rest;
CPPUNIT_ASSERT(o3tl::ends_with(u"raboof"sv, u"oof", &rest));
CPPUNIT_ASSERT_EQUAL(u"rab"sv, rest);
}
{
std::u16string_view rest;
CPPUNIT_ASSERT(!o3tl::ends_with(u"raboof"sv, u"doof", &rest));
CPPUNIT_ASSERT_EQUAL(u""sv, rest);
}
{
std::u16string_view rest;
CPPUNIT_ASSERT(!o3tl::ends_with(u"raboof"sv, u"sraboof", &rest));
CPPUNIT_ASSERT_EQUAL(u""sv, rest);
}
{
std::u16string_view rest;
CPPUNIT_ASSERT(o3tl::ends_with(u""sv, oustringEmpty(), &rest));
CPPUNIT_ASSERT_EQUAL(u""sv, rest);
}
{
std::u16string_view rest;
CPPUNIT_ASSERT(!o3tl::ends_with(u""sv, oustringOof(), &rest));
CPPUNIT_ASSERT_EQUAL(u""sv, rest);
}
{
std::u16string_view rest;
CPPUNIT_ASSERT(o3tl::ends_with(u"raboof"sv, oustringEmpty(), &rest));
CPPUNIT_ASSERT_EQUAL(u"raboof"sv, rest);
}
{
std::u16string_view rest;
CPPUNIT_ASSERT(o3tl::ends_with(u"raboof"sv, oustringOof(), &rest));
CPPUNIT_ASSERT_EQUAL(u"rab"sv, rest);
}
{
std::u16string_view rest;
CPPUNIT_ASSERT(!o3tl::ends_with(u"raboof"sv, oustringDoof(), &rest));
CPPUNIT_ASSERT_EQUAL(u""sv, rest);
}
{
std::u16string_view rest;
CPPUNIT_ASSERT(!o3tl::ends_with(u"raboof"sv, oustringSraboof(), &rest));
CPPUNIT_ASSERT_EQUAL(u""sv, rest);
}
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(Test);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */