Commit da541af3 authored by Bi Xue's avatar Bi Xue Committed by Facebook Github Bot

add equals interface for Range class.

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
parent e49575d4
...@@ -692,6 +692,12 @@ public: ...@@ -692,6 +692,12 @@ public:
trunc.begin(), trunc.end(), other.begin(), std::forward<Comp>(eq)); 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 * Remove the items in [b, e), as long as this subrange is at the beginning
* or end of the Range. * or end of the Range.
......
...@@ -418,6 +418,13 @@ TEST(StringPiece, Suffix) { ...@@ -418,6 +418,13 @@ TEST(StringPiece, Suffix) {
} }
} }
TEST(StringPiece, Equals) {
StringPiece a("hello");
EXPECT_TRUE(a.equals("HELLO", AsciiCaseInsensitive()));
EXPECT_FALSE(a.equals("HELLOX", AsciiCaseInsensitive()));
}
TEST(StringPiece, PrefixEmpty) { TEST(StringPiece, PrefixEmpty) {
StringPiece a; StringPiece a;
EXPECT_TRUE(a.startsWith("")); EXPECT_TRUE(a.startsWith(""));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment