src: Don't allow const char * in starts_with

This commit is contained in:
Tatsuhiro Tsujikawa 2016-03-25 23:20:48 +09:00
parent 2bca6360b6
commit f74d7ea119
2 changed files with 9 additions and 10 deletions

View File

@ -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 <typename S, typename T> bool starts_with(const S &a, const T &b) {
return starts_with(a.begin(), a.end(), b.begin(), b.end());
}
struct CaseCmp {

View File

@ -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")));