diff --git a/tests/utf8_string_test.cpp b/tests/utf8_string_test.cpp index a3c6001..fb2b5f7 100644 --- a/tests/utf8_string_test.cpp +++ b/tests/utf8_string_test.cpp @@ -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); } \ No newline at end of file diff --git a/utf8-string-lib/utf8_string.cpp b/utf8-string-lib/utf8_string.cpp index 62e350d..98c8fc5 100644 --- a/utf8-string-lib/utf8_string.cpp +++ b/utf8-string-lib/utf8_string.cpp @@ -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& other) const + { + return (String == other); + } + + // ----------------------------------------------------------------------------------------------------------------- + bool ustring::operator==(const std::basic_string_view& 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& other) const + { + return (String != other); + } + + // ----------------------------------------------------------------------------------------------------------------- + bool ustring::operator!=(const std::basic_string_view& other) const + { + return (String != other); + } + // ----------------------------------------------------------------------------------------------------------------- void ustring::replace_char(std::basic_string_view new_symbol, std::size_t idx) { diff --git a/utf8-string-lib/utf8_string.hpp b/utf8-string-lib/utf8_string.hpp index 9604f1b..daf23eb 100644 --- a/utf8-string-lib/utf8_string.hpp +++ b/utf8-string-lib/utf8_string.hpp @@ -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& other) const; + bool operator==(const std::basic_string_view& other) const; + bool operator!=(const ustring& other) const; + bool operator!=(const char* other) const; + bool operator!=(const std::basic_string& other) const; + bool operator!=(const std::basic_string_view& other) const; // TODO: ............................................... char& operator[](std::size_t index) = delete;