Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added comparing operators with other types & added new tests #5

Merged
merged 2 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions tests/utf8_string_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,27 @@ TEST(utf8_string, operators)
ASSERT_EQ(copy_data, copy_data_first.get_c_str());
ASSERT_EQ(copy_data, copy_data_second.get_c_str());
ASSERT_EQ(copy_data_first, copy_data_second);
}

// ---------------------------------------------------------------------------------------------------------------------
TEST(utf8_string, comparison_operators)
{
utf8::ustring ustr{ "привет" };
std::string str{ ustr.get_c_str() };
std::string_view str_view { ustr.get_c_str() };
const char* c_str{ "привет" };

bool result_1{ ustr == str };
bool result_2{ ustr == str_view };
bool result_3{ ustr == c_str };
ASSERT_EQ(result_1, true);
ASSERT_EQ(result_2, true);
ASSERT_EQ(result_3, true);

bool result_4{ ustr != str };
bool result_5{ ustr != str_view };
bool result_6{ ustr != c_str };
ASSERT_EQ(result_4, false);
ASSERT_EQ(result_5, false);
ASSERT_EQ(result_6, false);
}
36 changes: 36 additions & 0 deletions utf8-string-lib/utf8_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,48 @@ namespace utf8
return (String == other.String);
}

// -----------------------------------------------------------------------------------------------------------------
bool ustring::operator==(const char* other) const
{
return (String == other);
}

// -----------------------------------------------------------------------------------------------------------------
bool ustring::operator==(const std::basic_string<char>& other) const
{
return (String == other);
}

// -----------------------------------------------------------------------------------------------------------------
bool ustring::operator==(const std::basic_string_view<char>& other) const
{
return (String == other);
}

// -----------------------------------------------------------------------------------------------------------------
bool ustring::operator!=(const ustring& other) const
{
return (String != other.String);
}

// -----------------------------------------------------------------------------------------------------------------
bool ustring::operator!=(const char* other) const
{
return (String != other);
}

// -----------------------------------------------------------------------------------------------------------------
bool ustring::operator!=(const std::basic_string<char>& other) const
{
return (String != other);
}

// -----------------------------------------------------------------------------------------------------------------
bool ustring::operator!=(const std::basic_string_view<char>& other) const
{
return (String != other);
}

// -----------------------------------------------------------------------------------------------------------------
void ustring::replace_char(std::basic_string_view<char> new_symbol, std::size_t idx)
{
Expand Down
7 changes: 7 additions & 0 deletions utf8-string-lib/utf8_string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,14 @@ namespace utf8
ustring& operator=(ustring&& other) noexcept;

bool operator==(const ustring& other) const;
bool operator==(const char* other) const;
bool operator==(const std::basic_string<char>& other) const;
bool operator==(const std::basic_string_view<char>& other) const;

bool operator!=(const ustring& other) const;
bool operator!=(const char* other) const;
bool operator!=(const std::basic_string<char>& other) const;
bool operator!=(const std::basic_string_view<char>& other) const;

// TODO: ...............................................
char& operator[](std::size_t index) = delete;
Expand Down
Loading