From dad61d032e5cacc6ced68bee88854c6f04bf68ba Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Fri, 25 Mar 2016 22:51:20 +0900 Subject: [PATCH] src: Don't allow const char * in 2nd argument of strieq_l(S[N], T) --- src/util.h | 11 +++-------- src/util_test.cc | 10 +++++----- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/util.h b/src/util.h index dd4fb59e..b8b04127 100644 --- a/src/util.h +++ b/src/util.h @@ -296,14 +296,9 @@ bool strieq_l(const CharT(&a)[N], InputIt b, size_t blen) { return strieq(a, a + (N - 1), b, b + blen); } -template -bool strieq_l(const CharT(&a)[N], const std::string &b) { - return strieq(a, a + (N - 1), std::begin(b), std::end(b)); -} - -template -bool strieq_l(const CharT(&a)[N], const StringRef &b) { - return strieq(a, a + (N - 1), std::begin(b), std::end(b)); +template +bool strieq_l(const CharT(&a)[N], const T &b) { + return strieq(a, a + (N - 1), b.begin(), b.end()); } template diff --git a/src/util_test.cc b/src/util_test.cc index 25259658..ae5a88bb 100644 --- a/src/util_test.cc +++ b/src/util_test.cc @@ -91,11 +91,11 @@ void test_util_strieq(void) { CU_ASSERT(!util::strieq_l("alpha", "AlPhA ", 6)); CU_ASSERT(!util::strieq_l("", "AlPhA ", 6)); - CU_ASSERT(util::strieq_l("alpha", "alpha")); - CU_ASSERT(util::strieq_l("alpha", "AlPhA")); - CU_ASSERT(util::strieq_l("", "")); - CU_ASSERT(!util::strieq_l("alpha", "AlPhA ")); - CU_ASSERT(!util::strieq_l("", "AlPhA ")); + CU_ASSERT(util::strieq_l("alpha", StringRef::from_lit("alpha"))); + CU_ASSERT(util::strieq_l("alpha", StringRef::from_lit("AlPhA"))); + CU_ASSERT(util::strieq_l("", StringRef{})); + CU_ASSERT(!util::strieq_l("alpha", StringRef::from_lit("AlPhA "))); + CU_ASSERT(!util::strieq_l("", StringRef::from_lit("AlPhA "))); } void test_util_inp_strlower(void) {