diff --git a/src/util.h b/src/util.h index 7f1c4714..6d92529b 100644 --- a/src/util.h +++ b/src/util.h @@ -192,12 +192,8 @@ bool starts_with(InputIterator1 first1, InputIterator1 last1, return std::equal(first2, last2, first1); } -inline bool starts_with(const std::string &a, const std::string &b) { - return starts_with(std::begin(a), std::end(a), std::begin(b), std::end(b)); -} - -inline bool starts_with(const StringRef &a, const StringRef &b) { - return starts_with(std::begin(a), std::end(a), std::begin(b), std::end(b)); +template bool starts_with(const S &a, const T &b) { + return starts_with(a.begin(), a.end(), b.begin(), b.end()); } struct CaseCmp { diff --git a/src/util_test.cc b/src/util_test.cc index f6493ce9..313e9203 100644 --- a/src/util_test.cc +++ b/src/util_test.cc @@ -379,10 +379,13 @@ void test_util_format_duration(void) { } void test_util_starts_with(void) { - CU_ASSERT(util::starts_with("foo", "foo")); - CU_ASSERT(util::starts_with("fooo", "foo")); - CU_ASSERT(util::starts_with("ofoo", "")); - CU_ASSERT(!util::starts_with("ofoo", "foo")); + CU_ASSERT(util::starts_with(StringRef::from_lit("foo"), + StringRef::from_lit("foo"))); + CU_ASSERT(util::starts_with(StringRef::from_lit("fooo"), + StringRef::from_lit("foo"))); + CU_ASSERT(util::starts_with(StringRef::from_lit("ofoo"), StringRef{})); + CU_ASSERT(!util::starts_with(StringRef::from_lit("ofoo"), + StringRef::from_lit("foo"))); CU_ASSERT(util::istarts_with(StringRef::from_lit("FOO"), StringRef::from_lit("fOO")));