Summary: Otherwise you get errors like `error: array used as initializer ./folly/experimental/StringGen-inl.h: In constructor ‘folly::gen::detail::UnsplitBuffer<Delimiter, OutputBuffer>::UnsplitBuffer(const Delimiter&, OutputBuffer*) [with Delimiter = char [3] ...]`, since literal strings bind as reference to fixed-length character arrays. Providing an explicit overload for `const char*` fixes this.
Test Plan: Unit tests
Reviewed By: tulloch@fb.com
FB internal diff:
D737117
return Unsplit(delimiter);
}
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
/*
* 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);
}
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
} // namespace gen
} // namespace folly
split(s, ',') | unsplit(',', &buffer);
auto expected = folly::to<folly::fbstring>(
"asdf", s.empty() ? "" : ",", s);
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);
};
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);
EXPECT_EQ(buffer, s);
};
runUnsplitSuite(basicFn);
runUnsplitSuite(existingBuffer);
runUnsplitSuite(emptyBuffer);
+ runUnsplitSuite(stringDelim);
+ EXPECT_EQ("1, 2, 3", seq(1, 3) | unsplit(", "));
}
TEST(FileGen, ByLine) {
}
TEST(FileGen, ByLine) {