From acde293c2e9ee778546cf238a467aa20bd5f58b1 Mon Sep 17 00:00:00 2001 From: wh002 Date: Fri, 3 Feb 2023 11:59:39 +0800 Subject: [PATCH] cr1 --- src/utils/strings.cpp | 4 ++-- src/utils/test/utils.cpp | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/utils/strings.cpp b/src/utils/strings.cpp index 2702e3fffd..0d06e40465 100644 --- a/src/utils/strings.cpp +++ b/src/utils/strings.cpp @@ -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); } diff --git a/src/utils/test/utils.cpp b/src/utils/test/utils.cpp index 6604ff03ea..2f6ccab778 100644 --- a/src/utils/test/utils.cpp +++ b/src/utils/test/utils.cpp @@ -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); } }