return !empty() && front() == c;
}
+ template <class Comp>
+ bool startsWith(const const_range_type& other, Comp&& eq) const {
+ if (size() < other.size()) {
+ return false;
+ }
+ auto const trunc = subpiece(0, other.size());
+ return std::equal(
+ trunc.begin(), trunc.end(), other.begin(), std::forward<Comp>(eq));
+ }
+
/**
* Does this Range end with another range?
*/
return !empty() && back() == c;
}
+ template <class Comp>
+ bool endsWith(const const_range_type& other, Comp&& eq) const {
+ if (size() < other.size()) {
+ return false;
+ }
+ auto const trunc = subpiece(size() - other.size());
+ return std::equal(
+ trunc.begin(), trunc.end(), other.begin(), std::forward<Comp>(eq));
+ }
+
/**
* Remove the items in [b, e), as long as this subrange is at the beginning
* or end of the Range.
EXPECT_FALSE(a.startsWith('x'));
EXPECT_FALSE(a.startsWith("x"));
+ EXPECT_TRUE(a.startsWith("", folly::AsciiCaseInsensitive()));
+ EXPECT_TRUE(a.startsWith("hello", folly::AsciiCaseInsensitive()));
+ EXPECT_TRUE(a.startsWith("hellO", folly::AsciiCaseInsensitive()));
+ EXPECT_TRUE(a.startsWith("HELL", folly::AsciiCaseInsensitive()));
+ EXPECT_TRUE(a.startsWith("H", folly::AsciiCaseInsensitive()));
+ EXPECT_FALSE(a.startsWith("HELLOX", folly::AsciiCaseInsensitive()));
+ EXPECT_FALSE(a.startsWith("x", folly::AsciiCaseInsensitive()));
+ EXPECT_FALSE(a.startsWith("X", folly::AsciiCaseInsensitive()));
+
{
auto b = a;
EXPECT_TRUE(b.removePrefix(""));
EXPECT_FALSE(a.endsWith("x"));
EXPECT_FALSE(a.endsWith('x'));
+ EXPECT_TRUE(a.endsWith("", folly::AsciiCaseInsensitive()));
+ EXPECT_TRUE(a.endsWith("o", folly::AsciiCaseInsensitive()));
+ EXPECT_TRUE(a.endsWith("O", folly::AsciiCaseInsensitive()));
+ EXPECT_TRUE(a.endsWith("hello", folly::AsciiCaseInsensitive()));
+ EXPECT_TRUE(a.endsWith("hellO", folly::AsciiCaseInsensitive()));
+ EXPECT_FALSE(a.endsWith("xhello", folly::AsciiCaseInsensitive()));
+ EXPECT_FALSE(a.endsWith("Xhello", folly::AsciiCaseInsensitive()));
+ EXPECT_FALSE(a.endsWith("x", folly::AsciiCaseInsensitive()));
+ EXPECT_FALSE(a.endsWith("X", folly::AsciiCaseInsensitive()));
+
{
auto b = a;
EXPECT_TRUE(b.removeSuffix(""));