output);
}
-template <class String1, class String2>
-void backslashify(const String1& input, String2& output, bool hex_style) {
+template <class OutputString>
+void backslashify(
+ folly::StringPiece input,
+ OutputString& output,
+ bool hex_style) {
static const char hexValues[] = "0123456789abcdef";
output.clear();
output.reserve(3 * input.size());
* C++, use cEscape instead. This function is for display purposes
* only.
*/
-template <class String1, class String2>
-void backslashify(const String1& input, String2& output, bool hex_style=false);
+template <class OutputString>
+void backslashify(
+ folly::StringPiece input,
+ OutputString& output,
+ bool hex_style = false);
-template <class String>
-String backslashify(const String& input, bool hex_style=false) {
- String output;
+template <class OutputString = std::string>
+OutputString backslashify(StringPiece input, bool hex_style = false) {
+ OutputString output;
backslashify(input, output, hex_style);
return output;
}
EXPECT_EQ("abc\\r", backslashify(string("abc\r")));
EXPECT_EQ("abc\\x0d", backslashify(string("abc\r"), true));
EXPECT_EQ("\\0\\0", backslashify(string(2, '\0')));
+
+ StringPiece input1 = "abc\r";
+ std::string output1 = backslashify(input1);
+ EXPECT_EQ("abc\\r", output1);
}
TEST(String, humanify) {