return Unsplit(delimiter);
}
+template<class Output = folly::fbstring,
+ class Unsplit = detail::Unsplit<fbstring, Output>>
+Unsplit unsplit(const char* delimiter) {
+ return Unsplit(delimiter);
+}
+
/*
* Joins a sequence of tokens into a string, appending them to the output
* buffer. If the output buffer is empty, an initial delimiter will not be
return UnsplitBuffer(delimiter, outputBuffer);
}
+template<class OutputBuffer,
+ class UnsplitBuffer = detail::UnsplitBuffer<fbstring, OutputBuffer>>
+UnsplitBuffer unsplit(const char* delimiter, OutputBuffer* outputBuffer) {
+ return UnsplitBuffer(delimiter, outputBuffer);
+}
+
} // namespace gen
} // namespace folly
split(s, ',') | unsplit(',', &buffer);
auto expected = folly::to<folly::fbstring>(
"asdf", s.empty() ? "" : ",", s);
- EXPECT_EQ(buffer, expected);
+ EXPECT_EQ(expected, buffer);
};
auto emptyBuffer = [](const StringPiece& s) {
std::string buffer;
split(s, ',') | unsplit(',', &buffer);
+ EXPECT_EQ(s, buffer);
+ };
+
+ auto stringDelim = [](const StringPiece& s) {
+ EXPECT_EQ(s, split(s, ',') | unsplit(","));
+ std::string buffer;
+ split(s, ',') | unsplit(",", &buffer);
EXPECT_EQ(buffer, s);
};
runUnsplitSuite(basicFn);
runUnsplitSuite(existingBuffer);
runUnsplitSuite(emptyBuffer);
+ runUnsplitSuite(stringDelim);
+ EXPECT_EQ("1, 2, 3", seq(1, 3) | unsplit(", "));
}
TEST(FileGen, ByLine) {