Summary:
Add `equals` interface to StringPiece (Range class). To support following case insensitive compare case:
```
folly::StringPiece a("hello");
if (a.equals("HELLO", folly::AsciiCaseInsensitive())) {
// Do something.
}
```
Reviewed By: ot
Differential Revision:
D5150495
fbshipit-source-id:
26816820f93959678f550768396f55293b5588cb
trunc.begin(), trunc.end(), other.begin(), std::forward<Comp>(eq));
}
+ template <class Comp>
+ bool equals(const const_range_type& other, Comp&& eq) const {
+ return size() == other.size() &&
+ std::equal(begin(), 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.
}
}
+TEST(StringPiece, Equals) {
+ StringPiece a("hello");
+
+ EXPECT_TRUE(a.equals("HELLO", AsciiCaseInsensitive()));
+ EXPECT_FALSE(a.equals("HELLOX", AsciiCaseInsensitive()));
+}
+
TEST(StringPiece, PrefixEmpty) {
StringPiece a;
EXPECT_TRUE(a.startsWith(""));