Added starts_with and ends_with to basic_string

This commit is contained in:
John Wellbelove 2024-11-23 12:33:36 +00:00
parent a3b40b667a
commit d5cd9567cd
11 changed files with 999 additions and 4 deletions

View File

@ -1497,7 +1497,7 @@ namespace etl
}
//*********************************************************************
/// Checks that the string is within the string
/// Checks that the string is within this string
//*********************************************************************
bool contains(const etl::ibasic_string<T>& str) const
{
@ -1505,7 +1505,7 @@ namespace etl
}
//*********************************************************************
/// Checks that the view is within the string
/// Checks that the view is within this string
//*********************************************************************
template <typename TTraits>
bool contains(const etl::basic_string_view<T, TTraits>& view) const
@ -1514,7 +1514,7 @@ namespace etl
}
//*********************************************************************
/// Checks that text is within the string
/// Checks that text is within this string
//*********************************************************************
bool contains(const_pointer s) const
{
@ -1522,13 +1522,98 @@ namespace etl
}
//*********************************************************************
/// Checks that character is within the string
/// Checks that character is within this string
//*********************************************************************
bool contains(value_type c) const
{
return find(c) != npos;
}
//*********************************************************************
/// Checks that the string is the start of this string
//*********************************************************************
bool starts_with(const ibasic_string<T>& str) const
{
return compare(0, str.size(), str) == 0;
}
//*********************************************************************
/// Checks that the view is the start of this string
//*********************************************************************
template <typename TTraits>
bool starts_with(const basic_string_view<T, TTraits>& view) const
{
return compare(0, view.size(), view) == 0;
}
//*********************************************************************
/// Checks that the string is the start of this string
//*********************************************************************
bool starts_with(const_pointer s) const
{
size_t len = etl::strlen(s);
return compare(0, len, s, len) == 0;
}
//*********************************************************************
/// Checks that the character is the start of this string
//*********************************************************************
bool starts_with(value_type c) const
{
return !empty() && (front() == c);
}
//*********************************************************************
/// Checks that the string is the end of this string
//*********************************************************************
bool ends_with(const ibasic_string<T>& str) const
{
if (str.size() > size())
{
return false;
}
return compare(size() - str.size(), str.size(), str) == 0;
}
//*********************************************************************
/// Checks that the view is the end of this string
//*********************************************************************
template <typename TTraits>
bool ends_with(const basic_string_view<T, TTraits>& view) const
{
if (view.size() > size())
{
return false;
}
return compare(size() - view.size(), view.size(), view) == 0;
}
//*********************************************************************
/// Checks that the string is the end of this string
//*********************************************************************
bool ends_with(const_pointer s) const
{
size_t len = etl::strlen(s);
if (len > size())
{
return false;
}
return compare(size() - len, len, s, len) == 0;
}
//*********************************************************************
/// Checks that the character is the end of this string
//*********************************************************************
bool ends_with(value_type c) const
{
return !empty() && (back() == c);
}
//*********************************************************************
/// Replace 'length' characters from 'position' with 'str'.
///\param position The position to start from.

View File

@ -3644,6 +3644,90 @@ namespace
CHECK_FALSE(haystack.contains(STR('p')));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_starts_with_string)
{
TextL haystack(STR("A haystack with a needle and nothing else"));
Text start(STR("A haystack"));
Text not_start(STR("a needle"));
Text excess(STR("Really gigantic text that's really really big"));
CHECK_TRUE(haystack.starts_with(start));
CHECK_FALSE(haystack.starts_with(not_start));
CHECK_FALSE(haystack.starts_with(excess));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_starts_with_view)
{
TextL haystack(STR("A haystack with a needle and nothing else"));
CHECK_TRUE(haystack.starts_with(View(STR("A haystack"))));
CHECK_FALSE(haystack.starts_with(View(STR("a needle"))));
CHECK_FALSE(haystack.starts_with(View(STR("Really gigantic text that's really really big"))));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_starts_with_pointer)
{
TextL haystack(STR("A haystack with a needle and nothing else"));
CHECK_TRUE(haystack.starts_with(STR("A haystack")));
CHECK_FALSE(haystack.starts_with(STR("a needle")));
CHECK_FALSE(haystack.starts_with(STR("Really gigantic text that's really really big")));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_starts_with_char)
{
TextL haystack(STR("A haystack with a needle and nothing else"));
CHECK_TRUE(haystack.starts_with(haystack[0]));
CHECK_FALSE(haystack.starts_with(haystack[1]));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_ends_with_string)
{
TextL haystack(STR("A haystack with a needle and nothing else"));
Text end(STR("else"));
Text not_end(STR("needle"));
Text excess(STR("Really gigantic text that's really really big"));
CHECK_TRUE(haystack.ends_with(end));
CHECK_FALSE(haystack.ends_with(not_end));
CHECK_FALSE(haystack.ends_with(excess));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_ends_with_view)
{
TextL haystack(STR("A haystack with a needle and nothing else"));
CHECK_TRUE(haystack.ends_with(View(STR("else"))));
CHECK_FALSE(haystack.ends_with(View(STR("needle"))));
CHECK_FALSE(haystack.ends_with(View(STR("Really gigantic text that's really really big"))));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_ends_with_pointer)
{
TextL haystack(STR("A haystack with a needle and nothing else"));
CHECK_TRUE(haystack.ends_with(STR("else")));
CHECK_FALSE(haystack.ends_with(STR("needle")));
CHECK_FALSE(haystack.ends_with(STR("Really gigantic text that's really really big")));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_ends_with_char)
{
TextL haystack(STR("A haystack with a needle and nothing else"));
CHECK_TRUE(haystack.ends_with(haystack[haystack.size() - 1]));
CHECK_FALSE(haystack.ends_with(haystack[haystack.size() - 2]));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_rfind_string)
{

View File

@ -3947,6 +3947,104 @@ namespace
CHECK_FALSE(haystack.contains(STR('p')));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_starts_with_string)
{
TextBufferL buffer1{0};
TextBuffer buffer2{0};
TextBuffer buffer3{0};
TextBuffer buffer4{0};
Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size());
Text start(STR("A haystack"), buffer2.data(), buffer2.size());
Text not_start(STR("a needle"), buffer3.data(), buffer3.size());
Text excess(STR("Really gigantic text that's really really big"), buffer4.data(), buffer4.size());
CHECK_TRUE(haystack.starts_with(start));
CHECK_FALSE(haystack.starts_with(not_start));
CHECK_FALSE(haystack.starts_with(excess));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_starts_with_view)
{
TextBufferL buffer1{0};
Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size());
CHECK_TRUE(haystack.starts_with(View(STR("A haystack"))));
CHECK_FALSE(haystack.starts_with(View(STR("a needle"))));
CHECK_FALSE(haystack.starts_with(View(STR("Really gigantic text that's really really big"))));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_starts_with_pointer)
{
TextBufferL buffer1{0};
Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size());
CHECK_TRUE(haystack.starts_with(STR("A haystack")));
CHECK_FALSE(haystack.starts_with(STR("a needle")));
CHECK_FALSE(haystack.starts_with(STR("Really gigantic text that's really really big")));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_starts_with_char)
{
TextBufferL buffer1{0};
Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size());
CHECK_TRUE(haystack.starts_with(haystack[0]));
CHECK_FALSE(haystack.starts_with(haystack[1]));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_ends_with_string)
{
TextBufferL buffer1{0};
TextBuffer buffer2{0};
TextBuffer buffer3{0};
TextBuffer buffer4{0};
Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size());
Text end(STR("else"), buffer2.data(), buffer2.size());
Text not_end(STR("needle"), buffer3.data(), buffer3.size());
Text excess(STR("Really gigantic text that's really really big"), buffer4.data(), buffer4.size());
CHECK_TRUE(haystack.ends_with(end));
CHECK_FALSE(haystack.ends_with(not_end));
CHECK_FALSE(haystack.ends_with(excess));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_ends_with_view)
{
TextBufferL buffer1{0};
Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size());
CHECK_TRUE(haystack.ends_with(View(STR("else"))));
CHECK_FALSE(haystack.ends_with(View(STR("needle"))));
CHECK_FALSE(haystack.ends_with(View(STR("Really gigantic text that's really really big"))));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_ends_with_pointer)
{
TextBufferL buffer1{0};
Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size());
CHECK_TRUE(haystack.ends_with(STR("else")));
CHECK_FALSE(haystack.ends_with(STR("needle")));
CHECK_FALSE(haystack.ends_with(STR("Really gigantic text that's really really big")));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_ends_with_char)
{
TextBufferL buffer1{0};
Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size());
CHECK_TRUE(haystack.ends_with(haystack[haystack.size() - 1]));
CHECK_FALSE(haystack.ends_with(haystack[haystack.size() - 2]));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_rfind_string)
{

View File

@ -3658,6 +3658,90 @@ namespace
CHECK_FALSE(haystack.contains(STR('p')));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_starts_with_string)
{
TextL haystack(STR("A haystack with a needle and nothing else"));
Text start(STR("A haystack"));
Text not_start(STR("a needle"));
Text excess(STR("Really gigantic text that's really really big"));
CHECK_TRUE(haystack.starts_with(start));
CHECK_FALSE(haystack.starts_with(not_start));
CHECK_FALSE(haystack.starts_with(excess));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_starts_with_view)
{
TextL haystack(STR("A haystack with a needle and nothing else"));
CHECK_TRUE(haystack.starts_with(View(STR("A haystack"))));
CHECK_FALSE(haystack.starts_with(View(STR("a needle"))));
CHECK_FALSE(haystack.starts_with(View(STR("Really gigantic text that's really really big"))));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_starts_with_pointer)
{
TextL haystack(STR("A haystack with a needle and nothing else"));
CHECK_TRUE(haystack.starts_with(STR("A haystack")));
CHECK_FALSE(haystack.starts_with(STR("a needle")));
CHECK_FALSE(haystack.starts_with(STR("Really gigantic text that's really really big")));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_starts_with_char)
{
TextL haystack(STR("A haystack with a needle and nothing else"));
CHECK_TRUE(haystack.starts_with(haystack[0]));
CHECK_FALSE(haystack.starts_with(haystack[1]));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_ends_with_string)
{
TextL haystack(STR("A haystack with a needle and nothing else"));
Text end(STR("else"));
Text not_end(STR("needle"));
Text excess(STR("Really gigantic text that's really really big"));
CHECK_TRUE(haystack.ends_with(end));
CHECK_FALSE(haystack.ends_with(not_end));
CHECK_FALSE(haystack.ends_with(excess));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_ends_with_view)
{
TextL haystack(STR("A haystack with a needle and nothing else"));
CHECK_TRUE(haystack.ends_with(View(STR("else"))));
CHECK_FALSE(haystack.ends_with(View(STR("needle"))));
CHECK_FALSE(haystack.ends_with(View(STR("Really gigantic text that's really really big"))));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_ends_with_pointer)
{
TextL haystack(STR("A haystack with a needle and nothing else"));
CHECK_TRUE(haystack.ends_with(STR("else")));
CHECK_FALSE(haystack.ends_with(STR("needle")));
CHECK_FALSE(haystack.ends_with(STR("Really gigantic text that's really really big")));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_ends_with_char)
{
TextL haystack(STR("A haystack with a needle and nothing else"));
CHECK_TRUE(haystack.ends_with(haystack[haystack.size() - 1]));
CHECK_FALSE(haystack.ends_with(haystack[haystack.size() - 2]));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_rfind_string)
{

View File

@ -3961,6 +3961,104 @@ namespace
CHECK_FALSE(haystack.contains(STR('p')));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_starts_with_string)
{
TextBufferL buffer1{0};
TextBuffer buffer2{0};
TextBuffer buffer3{0};
TextBuffer buffer4{0};
Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size());
Text start(STR("A haystack"), buffer2.data(), buffer2.size());
Text not_start(STR("a needle"), buffer3.data(), buffer3.size());
Text excess(STR("Really gigantic text that's really really big"), buffer4.data(), buffer4.size());
CHECK_TRUE(haystack.starts_with(start));
CHECK_FALSE(haystack.starts_with(not_start));
CHECK_FALSE(haystack.starts_with(excess));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_starts_with_view)
{
TextBufferL buffer1{0};
Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size());
CHECK_TRUE(haystack.starts_with(View(STR("A haystack"))));
CHECK_FALSE(haystack.starts_with(View(STR("a needle"))));
CHECK_FALSE(haystack.starts_with(View(STR("Really gigantic text that's really really big"))));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_starts_with_pointer)
{
TextBufferL buffer1{0};
Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size());
CHECK_TRUE(haystack.starts_with(STR("A haystack")));
CHECK_FALSE(haystack.starts_with(STR("a needle")));
CHECK_FALSE(haystack.starts_with(STR("Really gigantic text that's really really big")));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_starts_with_char)
{
TextBufferL buffer1{0};
Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size());
CHECK_TRUE(haystack.starts_with(haystack[0]));
CHECK_FALSE(haystack.starts_with(haystack[1]));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_ends_with_string)
{
TextBufferL buffer1{0};
TextBuffer buffer2{0};
TextBuffer buffer3{0};
TextBuffer buffer4{0};
Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size());
Text end(STR("else"), buffer2.data(), buffer2.size());
Text not_end(STR("needle"), buffer3.data(), buffer3.size());
Text excess(STR("Really gigantic text that's really really big"), buffer4.data(), buffer4.size());
CHECK_TRUE(haystack.ends_with(end));
CHECK_FALSE(haystack.ends_with(not_end));
CHECK_FALSE(haystack.ends_with(excess));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_ends_with_view)
{
TextBufferL buffer1{0};
Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size());
CHECK_TRUE(haystack.ends_with(View(STR("else"))));
CHECK_FALSE(haystack.ends_with(View(STR("needle"))));
CHECK_FALSE(haystack.ends_with(View(STR("Really gigantic text that's really really big"))));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_ends_with_pointer)
{
TextBufferL buffer1{0};
Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size());
CHECK_TRUE(haystack.ends_with(STR("else")));
CHECK_FALSE(haystack.ends_with(STR("needle")));
CHECK_FALSE(haystack.ends_with(STR("Really gigantic text that's really really big")));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_ends_with_char)
{
TextBufferL buffer1{0};
Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size());
CHECK_TRUE(haystack.ends_with(haystack[haystack.size() - 1]));
CHECK_FALSE(haystack.ends_with(haystack[haystack.size() - 2]));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_rfind_string)
{

View File

@ -3658,6 +3658,90 @@ namespace
CHECK_FALSE(haystack.contains(STR('p')));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_starts_with_string)
{
TextL haystack(STR("A haystack with a needle and nothing else"));
Text start(STR("A haystack"));
Text not_start(STR("a needle"));
Text excess(STR("Really gigantic text that's really really big"));
CHECK_TRUE(haystack.starts_with(start));
CHECK_FALSE(haystack.starts_with(not_start));
CHECK_FALSE(haystack.starts_with(excess));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_starts_with_view)
{
TextL haystack(STR("A haystack with a needle and nothing else"));
CHECK_TRUE(haystack.starts_with(View(STR("A haystack"))));
CHECK_FALSE(haystack.starts_with(View(STR("a needle"))));
CHECK_FALSE(haystack.starts_with(View(STR("Really gigantic text that's really really big"))));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_starts_with_pointer)
{
TextL haystack(STR("A haystack with a needle and nothing else"));
CHECK_TRUE(haystack.starts_with(STR("A haystack")));
CHECK_FALSE(haystack.starts_with(STR("a needle")));
CHECK_FALSE(haystack.starts_with(STR("Really gigantic text that's really really big")));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_starts_with_char)
{
TextL haystack(STR("A haystack with a needle and nothing else"));
CHECK_TRUE(haystack.starts_with(haystack[0]));
CHECK_FALSE(haystack.starts_with(haystack[1]));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_ends_with_string)
{
TextL haystack(STR("A haystack with a needle and nothing else"));
Text end(STR("else"));
Text not_end(STR("needle"));
Text excess(STR("Really gigantic text that's really really big"));
CHECK_TRUE(haystack.ends_with(end));
CHECK_FALSE(haystack.ends_with(not_end));
CHECK_FALSE(haystack.ends_with(excess));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_ends_with_view)
{
TextL haystack(STR("A haystack with a needle and nothing else"));
CHECK_TRUE(haystack.ends_with(View(STR("else"))));
CHECK_FALSE(haystack.ends_with(View(STR("needle"))));
CHECK_FALSE(haystack.ends_with(View(STR("Really gigantic text that's really really big"))));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_ends_with_pointer)
{
TextL haystack(STR("A haystack with a needle and nothing else"));
CHECK_TRUE(haystack.ends_with(STR("else")));
CHECK_FALSE(haystack.ends_with(STR("needle")));
CHECK_FALSE(haystack.ends_with(STR("Really gigantic text that's really really big")));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_ends_with_char)
{
TextL haystack(STR("A haystack with a needle and nothing else"));
CHECK_TRUE(haystack.ends_with(haystack[haystack.size() - 1]));
CHECK_FALSE(haystack.ends_with(haystack[haystack.size() - 2]));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_rfind_string)
{

View File

@ -3961,6 +3961,104 @@ namespace
CHECK_FALSE(haystack.contains(STR('p')));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_starts_with_string)
{
TextBufferL buffer1{0};
TextBuffer buffer2{0};
TextBuffer buffer3{0};
TextBuffer buffer4{0};
Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size());
Text start(STR("A haystack"), buffer2.data(), buffer2.size());
Text not_start(STR("a needle"), buffer3.data(), buffer3.size());
Text excess(STR("Really gigantic text that's really really big"), buffer4.data(), buffer4.size());
CHECK_TRUE(haystack.starts_with(start));
CHECK_FALSE(haystack.starts_with(not_start));
CHECK_FALSE(haystack.starts_with(excess));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_starts_with_view)
{
TextBufferL buffer1{0};
Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size());
CHECK_TRUE(haystack.starts_with(View(STR("A haystack"))));
CHECK_FALSE(haystack.starts_with(View(STR("a needle"))));
CHECK_FALSE(haystack.starts_with(View(STR("Really gigantic text that's really really big"))));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_starts_with_pointer)
{
TextBufferL buffer1{0};
Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size());
CHECK_TRUE(haystack.starts_with(STR("A haystack")));
CHECK_FALSE(haystack.starts_with(STR("a needle")));
CHECK_FALSE(haystack.starts_with(STR("Really gigantic text that's really really big")));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_starts_with_char)
{
TextBufferL buffer1{0};
Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size());
CHECK_TRUE(haystack.starts_with(haystack[0]));
CHECK_FALSE(haystack.starts_with(haystack[1]));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_ends_with_string)
{
TextBufferL buffer1{0};
TextBuffer buffer2{0};
TextBuffer buffer3{0};
TextBuffer buffer4{0};
Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size());
Text end(STR("else"), buffer2.data(), buffer2.size());
Text not_end(STR("needle"), buffer3.data(), buffer3.size());
Text excess(STR("Really gigantic text that's really really big"), buffer4.data(), buffer4.size());
CHECK_TRUE(haystack.ends_with(end));
CHECK_FALSE(haystack.ends_with(not_end));
CHECK_FALSE(haystack.ends_with(excess));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_ends_with_view)
{
TextBufferL buffer1{0};
Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size());
CHECK_TRUE(haystack.ends_with(View(STR("else"))));
CHECK_FALSE(haystack.ends_with(View(STR("needle"))));
CHECK_FALSE(haystack.ends_with(View(STR("Really gigantic text that's really really big"))));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_ends_with_pointer)
{
TextBufferL buffer1{0};
Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size());
CHECK_TRUE(haystack.ends_with(STR("else")));
CHECK_FALSE(haystack.ends_with(STR("needle")));
CHECK_FALSE(haystack.ends_with(STR("Really gigantic text that's really really big")));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_ends_with_char)
{
TextBufferL buffer1{0};
Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size());
CHECK_TRUE(haystack.ends_with(haystack[haystack.size() - 1]));
CHECK_FALSE(haystack.ends_with(haystack[haystack.size() - 2]));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_rfind_string)
{

View File

@ -3661,6 +3661,90 @@ namespace
CHECK_FALSE(haystack.contains(STR('p')));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_starts_with_string)
{
TextL haystack(STR("A haystack with a needle and nothing else"));
Text start(STR("A haystack"));
Text not_start(STR("a needle"));
Text excess(STR("Really gigantic text that's really really big"));
CHECK_TRUE(haystack.starts_with(start));
CHECK_FALSE(haystack.starts_with(not_start));
CHECK_FALSE(haystack.starts_with(excess));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_starts_with_view)
{
TextL haystack(STR("A haystack with a needle and nothing else"));
CHECK_TRUE(haystack.starts_with(View(STR("A haystack"))));
CHECK_FALSE(haystack.starts_with(View(STR("a needle"))));
CHECK_FALSE(haystack.starts_with(View(STR("Really gigantic text that's really really big"))));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_starts_with_pointer)
{
TextL haystack(STR("A haystack with a needle and nothing else"));
CHECK_TRUE(haystack.starts_with(STR("A haystack")));
CHECK_FALSE(haystack.starts_with(STR("a needle")));
CHECK_FALSE(haystack.starts_with(STR("Really gigantic text that's really really big")));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_starts_with_char)
{
TextL haystack(STR("A haystack with a needle and nothing else"));
CHECK_TRUE(haystack.starts_with(haystack[0]));
CHECK_FALSE(haystack.starts_with(haystack[1]));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_ends_with_string)
{
TextL haystack(STR("A haystack with a needle and nothing else"));
Text end(STR("else"));
Text not_end(STR("needle"));
Text excess(STR("Really gigantic text that's really really big"));
CHECK_TRUE(haystack.ends_with(end));
CHECK_FALSE(haystack.ends_with(not_end));
CHECK_FALSE(haystack.ends_with(excess));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_ends_with_view)
{
TextL haystack(STR("A haystack with a needle and nothing else"));
CHECK_TRUE(haystack.ends_with(View(STR("else"))));
CHECK_FALSE(haystack.ends_with(View(STR("needle"))));
CHECK_FALSE(haystack.ends_with(View(STR("Really gigantic text that's really really big"))));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_ends_with_pointer)
{
TextL haystack(STR("A haystack with a needle and nothing else"));
CHECK_TRUE(haystack.ends_with(STR("else")));
CHECK_FALSE(haystack.ends_with(STR("needle")));
CHECK_FALSE(haystack.ends_with(STR("Really gigantic text that's really really big")));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_ends_with_char)
{
TextL haystack(STR("A haystack with a needle and nothing else"));
CHECK_TRUE(haystack.ends_with(haystack[haystack.size() - 1]));
CHECK_FALSE(haystack.ends_with(haystack[haystack.size() - 2]));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_rfind_string)
{

View File

@ -3933,6 +3933,104 @@ namespace
CHECK_FALSE(haystack.contains(STR('p')));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_starts_with_string)
{
TextBufferL buffer1{0};
TextBuffer buffer2{0};
TextBuffer buffer3{0};
TextBuffer buffer4{0};
Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size());
Text start(STR("A haystack"), buffer2.data(), buffer2.size());
Text not_start(STR("a needle"), buffer3.data(), buffer3.size());
Text excess(STR("Really gigantic text that's really really big"), buffer4.data(), buffer4.size());
CHECK_TRUE(haystack.starts_with(start));
CHECK_FALSE(haystack.starts_with(not_start));
CHECK_FALSE(haystack.starts_with(excess));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_starts_with_view)
{
TextBufferL buffer1{0};
Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size());
CHECK_TRUE(haystack.starts_with(View(STR("A haystack"))));
CHECK_FALSE(haystack.starts_with(View(STR("a needle"))));
CHECK_FALSE(haystack.starts_with(View(STR("Really gigantic text that's really really big"))));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_starts_with_pointer)
{
TextBufferL buffer1{0};
Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size());
CHECK_TRUE(haystack.starts_with(STR("A haystack")));
CHECK_FALSE(haystack.starts_with(STR("a needle")));
CHECK_FALSE(haystack.starts_with(STR("Really gigantic text that's really really big")));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_starts_with_char)
{
TextBufferL buffer1{0};
Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size());
CHECK_TRUE(haystack.starts_with(haystack[0]));
CHECK_FALSE(haystack.starts_with(haystack[1]));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_ends_with_string)
{
TextBufferL buffer1{0};
TextBuffer buffer2{0};
TextBuffer buffer3{0};
TextBuffer buffer4{0};
Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size());
Text end(STR("else"), buffer2.data(), buffer2.size());
Text not_end(STR("needle"), buffer3.data(), buffer3.size());
Text excess(STR("Really gigantic text that's really really big"), buffer4.data(), buffer4.size());
CHECK_TRUE(haystack.ends_with(end));
CHECK_FALSE(haystack.ends_with(not_end));
CHECK_FALSE(haystack.ends_with(excess));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_ends_with_view)
{
TextBufferL buffer1{0};
Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size());
CHECK_TRUE(haystack.ends_with(View(STR("else"))));
CHECK_FALSE(haystack.ends_with(View(STR("needle"))));
CHECK_FALSE(haystack.ends_with(View(STR("Really gigantic text that's really really big"))));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_ends_with_pointer)
{
TextBufferL buffer1{0};
Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size());
CHECK_TRUE(haystack.ends_with(STR("else")));
CHECK_FALSE(haystack.ends_with(STR("needle")));
CHECK_FALSE(haystack.ends_with(STR("Really gigantic text that's really really big")));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_ends_with_char)
{
TextBufferL buffer1{0};
Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size());
CHECK_TRUE(haystack.ends_with(haystack[haystack.size() - 1]));
CHECK_FALSE(haystack.ends_with(haystack[haystack.size() - 2]));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_find_char_pointer_n)
{

View File

@ -3659,6 +3659,90 @@ namespace
CHECK_FALSE(haystack.contains(STR('p')));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_starts_with_string)
{
TextL haystack(STR("A haystack with a needle and nothing else"));
Text start(STR("A haystack"));
Text not_start(STR("a needle"));
Text excess(STR("Really gigantic text that's really really big"));
CHECK_TRUE(haystack.starts_with(start));
CHECK_FALSE(haystack.starts_with(not_start));
CHECK_FALSE(haystack.starts_with(excess));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_starts_with_view)
{
TextL haystack(STR("A haystack with a needle and nothing else"));
CHECK_TRUE(haystack.starts_with(View(STR("A haystack"))));
CHECK_FALSE(haystack.starts_with(View(STR("a needle"))));
CHECK_FALSE(haystack.starts_with(View(STR("Really gigantic text that's really really big"))));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_starts_with_pointer)
{
TextL haystack(STR("A haystack with a needle and nothing else"));
CHECK_TRUE(haystack.starts_with(STR("A haystack")));
CHECK_FALSE(haystack.starts_with(STR("a needle")));
CHECK_FALSE(haystack.starts_with(STR("Really gigantic text that's really really big")));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_starts_with_char)
{
TextL haystack(STR("A haystack with a needle and nothing else"));
CHECK_TRUE(haystack.starts_with(haystack[0]));
CHECK_FALSE(haystack.starts_with(haystack[1]));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_ends_with_string)
{
TextL haystack(STR("A haystack with a needle and nothing else"));
Text end(STR("else"));
Text not_end(STR("needle"));
Text excess(STR("Really gigantic text that's really really big"));
CHECK_TRUE(haystack.ends_with(end));
CHECK_FALSE(haystack.ends_with(not_end));
CHECK_FALSE(haystack.ends_with(excess));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_ends_with_view)
{
TextL haystack(STR("A haystack with a needle and nothing else"));
CHECK_TRUE(haystack.ends_with(View(STR("else"))));
CHECK_FALSE(haystack.ends_with(View(STR("needle"))));
CHECK_FALSE(haystack.ends_with(View(STR("Really gigantic text that's really really big"))));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_ends_with_pointer)
{
TextL haystack(STR("A haystack with a needle and nothing else"));
CHECK_TRUE(haystack.ends_with(STR("else")));
CHECK_FALSE(haystack.ends_with(STR("needle")));
CHECK_FALSE(haystack.ends_with(STR("Really gigantic text that's really really big")));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_ends_with_char)
{
TextL haystack(STR("A haystack with a needle and nothing else"));
CHECK_TRUE(haystack.ends_with(haystack[haystack.size() - 1]));
CHECK_FALSE(haystack.ends_with(haystack[haystack.size() - 2]));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_rfind_string)
{

View File

@ -3964,6 +3964,104 @@ namespace
CHECK_FALSE(haystack.contains(STR('p')));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_starts_with_string)
{
TextBufferL buffer1{0};
TextBuffer buffer2{0};
TextBuffer buffer3{0};
TextBuffer buffer4{0};
Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size());
Text start(STR("A haystack"), buffer2.data(), buffer2.size());
Text not_start(STR("a needle"), buffer3.data(), buffer3.size());
Text excess(STR("Really gigantic text that's really really big"), buffer4.data(), buffer4.size());
CHECK_TRUE(haystack.starts_with(start));
CHECK_FALSE(haystack.starts_with(not_start));
CHECK_FALSE(haystack.starts_with(excess));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_starts_with_view)
{
TextBufferL buffer1{0};
Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size());
CHECK_TRUE(haystack.starts_with(View(STR("A haystack"))));
CHECK_FALSE(haystack.starts_with(View(STR("a needle"))));
CHECK_FALSE(haystack.starts_with(View(STR("Really gigantic text that's really really big"))));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_starts_with_pointer)
{
TextBufferL buffer1{0};
Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size());
CHECK_TRUE(haystack.starts_with(STR("A haystack")));
CHECK_FALSE(haystack.starts_with(STR("a needle")));
CHECK_FALSE(haystack.starts_with(STR("Really gigantic text that's really really big")));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_starts_with_char)
{
TextBufferL buffer1{0};
Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size());
CHECK_TRUE(haystack.starts_with(haystack[0]));
CHECK_FALSE(haystack.starts_with(haystack[1]));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_ends_with_string)
{
TextBufferL buffer1{0};
TextBuffer buffer2{0};
TextBuffer buffer3{0};
TextBuffer buffer4{0};
Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size());
Text end(STR("else"), buffer2.data(), buffer2.size());
Text not_end(STR("needle"), buffer3.data(), buffer3.size());
Text excess(STR("Really gigantic text that's really really big"), buffer4.data(), buffer4.size());
CHECK_TRUE(haystack.ends_with(end));
CHECK_FALSE(haystack.ends_with(not_end));
CHECK_FALSE(haystack.ends_with(excess));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_ends_with_view)
{
TextBufferL buffer1{0};
Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size());
CHECK_TRUE(haystack.ends_with(View(STR("else"))));
CHECK_FALSE(haystack.ends_with(View(STR("needle"))));
CHECK_FALSE(haystack.ends_with(View(STR("Really gigantic text that's really really big"))));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_ends_with_pointer)
{
TextBufferL buffer1{0};
Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size());
CHECK_TRUE(haystack.ends_with(STR("else")));
CHECK_FALSE(haystack.ends_with(STR("needle")));
CHECK_FALSE(haystack.ends_with(STR("Really gigantic text that's really really big")));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_ends_with_char)
{
TextBufferL buffer1{0};
Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size());
CHECK_TRUE(haystack.ends_with(haystack[haystack.size() - 1]));
CHECK_FALSE(haystack.ends_with(haystack[haystack.size() - 2]));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_rfind_string)
{