Commit ff17894b authored by Andre Pinto's avatar Andre Pinto Committed by Facebook Github Bot

Add an overload to use backlashify with StringPiece

Summary: Allows calling backlashify on a StringPiece.

Reviewed By: yfeldblum

Differential Revision: D5930015

fbshipit-source-id: ca14c78d9a90c45781da7229eb5d2f437792b2d1
parent a95a6976
......@@ -491,8 +491,11 @@ void join(const Delim& delimiter,
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());
......
......@@ -211,12 +211,15 @@ std::string& stringVAppendf(std::string* out, const char* format, va_list ap);
* 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;
}
......
......@@ -1047,6 +1047,10 @@ TEST(String, backslashify) {
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) {
......
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