Skip to content

Commit

Permalink
cr1
Browse files Browse the repository at this point in the history
  • Loading branch information
wh002 committed Feb 3, 2023
1 parent f440ee6 commit acde293
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/utils/strings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,9 +420,9 @@ std::string string_md5(const char *buffer, unsigned length)

std::string find_string_prefix(const std::string &input, char separator)
{
std::size_t current = input.find(separator);
auto current = input.find(separator);
if (current == 0 || current == std::string::npos) {
return "";
return std::string();
}
return input.substr(0, current);
}
Expand Down
8 changes: 5 additions & 3 deletions src/utils/test/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,10 +455,12 @@ TEST(core, find_string_prefix)
{"abc.def", '.', "abc"},
{"ab.cd.ef", '.', "ab"},
{"abc...def", '.', "abc"},
{".abc.def", '.', ""}};
std::string actual_output;
{".abc.def", '.', ""},
{" ", ' ', ""},
{"..", '.', ""},
{". ", ' ', "."}};
for (const auto &test : tests) {
actual_output = find_string_prefix(test.input, test.separator);
auto actual_output = find_string_prefix(test.input, test.separator);
EXPECT_EQ(actual_output, test.expected_prefix);
}
}
Expand Down

0 comments on commit acde293

Please sign in to comment.