src: Don't allow const char * in iends_with and iends_with_l

This commit is contained in:
Tatsuhiro Tsujikawa 2016-03-25 23:00:34 +09:00
parent 2182a85875
commit 2ab79f4938
2 changed files with 14 additions and 20 deletions

View File

@ -260,22 +260,13 @@ bool iends_with(InputIterator1 first1, InputIterator1 last1,
return std::equal(first2, last2, last1 - (last2 - first2), CaseCmp()); return std::equal(first2, last2, last1 - (last2 - first2), CaseCmp());
} }
inline bool iends_with(const std::string &a, const std::string &b) { template <typename T, typename S> bool iends_with(const T &a, const S &b) {
return iends_with(std::begin(a), std::end(a), std::begin(b), std::end(b)); return iends_with(a.begin(), a.end(), b.begin(), b.end());
} }
inline bool iends_with(const StringRef &a, const StringRef &b) { template <typename T, typename CharT, size_t N>
return iends_with(std::begin(a), std::end(a), std::begin(b), std::end(b)); bool iends_with_l(const T &a, const CharT(&b)[N]) {
} return iends_with(a.begin(), a.end(), b, b + N - 1);
template <typename CharT, size_t N>
bool iends_with_l(const std::string &a, const CharT(&b)[N]) {
return iends_with(std::begin(a), std::end(a), b, b + N - 1);
}
template <typename CharT, size_t N>
bool iends_with_l(const StringRef &a, const CharT(&b)[N]) {
return iends_with(std::begin(a), std::end(a), b, b + N - 1);
} }
template <typename InputIt1, typename InputIt2> template <typename InputIt1, typename InputIt2>

View File

@ -399,13 +399,16 @@ void test_util_ends_with(void) {
CU_ASSERT(util::ends_with("ofoo", "foo")); CU_ASSERT(util::ends_with("ofoo", "foo"));
CU_ASSERT(!util::ends_with("ofoo", "fo")); CU_ASSERT(!util::ends_with("ofoo", "fo"));
CU_ASSERT(util::iends_with("fOo", "Foo")); CU_ASSERT(
CU_ASSERT(util::iends_with("foo", "")); util::iends_with(StringRef::from_lit("fOo"), StringRef::from_lit("Foo")));
CU_ASSERT(util::iends_with("oFoo", "fOO")); CU_ASSERT(util::iends_with(StringRef::from_lit("foo"), StringRef{}));
CU_ASSERT(!util::iends_with("ofoo", "fo")); CU_ASSERT(util::iends_with(StringRef::from_lit("oFoo"),
StringRef::from_lit("fOO")));
CU_ASSERT(!util::iends_with(StringRef::from_lit("ofoo"),
StringRef::from_lit("fo")));
CU_ASSERT(util::iends_with_l("oFoo", "fOO")); CU_ASSERT(util::iends_with_l(StringRef::from_lit("oFoo"), "fOO"));
CU_ASSERT(!util::iends_with_l("ofoo", "fo")); CU_ASSERT(!util::iends_with_l(StringRef::from_lit("ofoo"), "fo"));
} }
void test_util_parse_http_date(void) { void test_util_parse_http_date(void) {