Skip to content

Commit 8974315

Browse files
authored
Merge pull request #5 from b1tflyyyy/dev
added comparing operators with other types & added new tests
2 parents 858eace + 583f8a7 commit 8974315

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

tests/utf8_string_test.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,27 @@ TEST(utf8_string, operators)
165165
ASSERT_EQ(copy_data, copy_data_first.get_c_str());
166166
ASSERT_EQ(copy_data, copy_data_second.get_c_str());
167167
ASSERT_EQ(copy_data_first, copy_data_second);
168+
}
169+
170+
// ---------------------------------------------------------------------------------------------------------------------
171+
TEST(utf8_string, comparison_operators)
172+
{
173+
utf8::ustring ustr{ "привет" };
174+
std::string str{ ustr.get_c_str() };
175+
std::string_view str_view { ustr.get_c_str() };
176+
const char* c_str{ "привет" };
177+
178+
bool result_1{ ustr == str };
179+
bool result_2{ ustr == str_view };
180+
bool result_3{ ustr == c_str };
181+
ASSERT_EQ(result_1, true);
182+
ASSERT_EQ(result_2, true);
183+
ASSERT_EQ(result_3, true);
184+
185+
bool result_4{ ustr != str };
186+
bool result_5{ ustr != str_view };
187+
bool result_6{ ustr != c_str };
188+
ASSERT_EQ(result_4, false);
189+
ASSERT_EQ(result_5, false);
190+
ASSERT_EQ(result_6, false);
168191
}

utf8-string-lib/utf8_string.cpp

+36
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,48 @@ namespace utf8
114114
return (String == other.String);
115115
}
116116

117+
// -----------------------------------------------------------------------------------------------------------------
118+
bool ustring::operator==(const char* other) const
119+
{
120+
return (String == other);
121+
}
122+
123+
// -----------------------------------------------------------------------------------------------------------------
124+
bool ustring::operator==(const std::basic_string<char>& other) const
125+
{
126+
return (String == other);
127+
}
128+
129+
// -----------------------------------------------------------------------------------------------------------------
130+
bool ustring::operator==(const std::basic_string_view<char>& other) const
131+
{
132+
return (String == other);
133+
}
134+
117135
// -----------------------------------------------------------------------------------------------------------------
118136
bool ustring::operator!=(const ustring& other) const
119137
{
120138
return (String != other.String);
121139
}
122140

141+
// -----------------------------------------------------------------------------------------------------------------
142+
bool ustring::operator!=(const char* other) const
143+
{
144+
return (String != other);
145+
}
146+
147+
// -----------------------------------------------------------------------------------------------------------------
148+
bool ustring::operator!=(const std::basic_string<char>& other) const
149+
{
150+
return (String != other);
151+
}
152+
153+
// -----------------------------------------------------------------------------------------------------------------
154+
bool ustring::operator!=(const std::basic_string_view<char>& other) const
155+
{
156+
return (String != other);
157+
}
158+
123159
// -----------------------------------------------------------------------------------------------------------------
124160
void ustring::replace_char(std::basic_string_view<char> new_symbol, std::size_t idx)
125161
{

utf8-string-lib/utf8_string.hpp

+7
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,14 @@ namespace utf8
5959
ustring& operator=(ustring&& other) noexcept;
6060

6161
bool operator==(const ustring& other) const;
62+
bool operator==(const char* other) const;
63+
bool operator==(const std::basic_string<char>& other) const;
64+
bool operator==(const std::basic_string_view<char>& other) const;
65+
6266
bool operator!=(const ustring& other) const;
67+
bool operator!=(const char* other) const;
68+
bool operator!=(const std::basic_string<char>& other) const;
69+
bool operator!=(const std::basic_string_view<char>& other) const;
6370

6471
// TODO: ...............................................
6572
char& operator[](std::size_t index) = delete;

0 commit comments

Comments
 (0)