Summary:
Currently UTF8Range has a constructor that allows you construct an object of type UTF8Range using only an object of type folly::Range. Adding a constructor so that we can construct an UTF8Range object using a std::string.
Currently,
void sampleMethod(UTF8StringPiece sp) {...}
/*
...
*/
std::string str = "example";
folly::UTF8Range utf8Range(str);
folly::StringPiece sp(str);
sampleMethod(utf8Range); // works
sampleMethod(sp); // works
sampleMethod(str); // doesn't work
This diff hopes to fix this issue.
Reviewed By: ddrcoder
Differential Revision:
D3221144
fb-gh-sync-id:
dd6ec4d7790d4602dccb3b63a4861d358aed3608
fbshipit-source-id:
dd6ec4d7790d4602dccb3b63a4861d358aed3608
baseRange.begin(), baseRange.begin(), baseRange.end()),
boost::u8_to_u32_iterator<Iterator>(
baseRange.end(), baseRange.begin(), baseRange.end())) {}
+ /* implicit */ UTF8Range(const std::string& baseString)
+ : Base(folly::Range<Iterator>(baseString)) {}
};
using UTF8StringPiece = UTF8Range<const char*>;
TEST(UTF8StringPiece, invalid_mid_codepoint) {
EXPECT_THROW(UTF8StringPiece(kTestUTF8.subpiece(9, 1)), std::out_of_range);
}
+
+TEST(UTF8StringPiece, valid_implicit_conversion) {
+ std::string input = "\U0001F602\U0001F602\U0001F602";
+ auto checkImplicitCtor = [](UTF8StringPiece implicitCtor) {
+ return implicitCtor.walk_size();
+ };
+ EXPECT_EQ(3, checkImplicitCtor(input));
+}