From f74d7ea1197c50380e30d11f867e41c84470f222 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Fri, 25 Mar 2016 23:20:48 +0900 Subject: [PATCH] src: Don't allow const char * in starts_with --- src/util.h | 8 ++------ src/util_test.cc | 11 +++++++---- 2 files changed, 9 insertions(+), 10 deletions(-) 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")));