@@ -21,7 +21,7 @@ inline std::string_view trim(std::string_view s) { | |||
++iter; | |||
} | |||
auto riter = s.rbegin(); | |||
auto rend = s.rend(); | |||
auto rend = std::make_reverse_iterator(iter); | |||
while (riter != rend && std::isspace(*riter)) { | |||
++riter; | |||
} | |||
@@ -29,6 +29,8 @@ inline std::string_view trim(std::string_view s) { | |||
return sview(iter, new_end); | |||
} | |||
inline std::string_view trim(const char* str) { return trim(std::string_view(str)); } | |||
inline std::string trim(std::string&& s) { return std::string(trim(s)); } | |||
inline bool ends_with(std::string_view s, std::string_view key) { |
@@ -33,6 +33,12 @@ void test_ends_with() { | |||
CHECK(!ends_with("foo.bar", "foo")); | |||
} | |||
void test_trim() { | |||
CHECK(trim("foo") == "foo"); | |||
CHECK(trim("foo ") == "foo"); | |||
CHECK(trim(" ").size() == 0); | |||
} | |||
void test_contains() { | |||
CHECK(contains("foo", "foo")); | |||
CHECK(contains("foo", "")); | |||
@@ -48,6 +54,7 @@ void test_split() { | |||
} | |||
void run_tests() { | |||
test_trim(); | |||
test_starts_with(); | |||
test_ends_with(); | |||
test_contains(); |
@@ -10,7 +10,11 @@ void test_simple() { | |||
auto kvs = parse_string(lm_src); | |||
CHECK(kvs.size() == 0); | |||
lm_src = "foo: bar"; | |||
CHECK(parse_string(" ").size() == 0); | |||
CHECK(parse_string("\n ").size() == 0); | |||
CHECK(parse_string("#comment\n ").size() == 0); | |||
lm_src = "foo: bar\n "; | |||
kvs = parse_string(lm_src); | |||
CHECK(kvs.size() == 1); | |||
REQUIRE(kvs.find("foo")); |