X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=blobdiff_plain;f=folly%2FString-inl.h;h=597897db3f2c26b8c8708cbc80b1ea03639c0de9;hp=dbfefa010fb6f97ac530ce280b74f086996b7ec0;hb=9cb500221e2d70d8bdba2f368e4d438c97a48a9e;hpb=fa172175980b13569ba42008202a857af6e959dd diff --git a/folly/String-inl.h b/folly/String-inl.h index dbfefa01..597897db 100644 --- a/folly/String-inl.h +++ b/folly/String-inl.h @@ -16,8 +16,10 @@ #pragma once -#include #include +#include + +#include #ifndef FOLLY_STRING_H_ #error This file may only be included from String.h @@ -31,7 +33,7 @@ namespace detail { // an octal escape sequence, or 'P' if the character is printable and // should be printed as is. extern const char cEscapeTable[]; -} // namespace detail +} // namespace detail template void cEscape(StringPiece str, String& out) { @@ -78,7 +80,7 @@ extern const char cUnescapeTable[]; // Map from the character code to the hex value, or 16 if invalid hex char. extern const unsigned char hexTable[]; -} // namespace detail +} // namespace detail template void cUnescape(StringPiece str, String& out, bool strict) { @@ -156,7 +158,7 @@ namespace detail { // 3 = space, replace with '+' in QUERY mode // 4 = percent-encode extern const unsigned char uriEscapeTable[]; -} // namespace detail +} // namespace detail template void uriEscape(StringPiece str, String& out, UriEscapeMode mode) { @@ -228,6 +230,7 @@ void uriUnescape(StringPiece str, String& out, UriEscapeMode mode) { break; } // else fallthrough + FOLLY_FALLTHROUGH; default: ++p; break; @@ -272,7 +275,7 @@ inline char delimFront(StringPiece s) { * * @param ignoreEmpty iff true, don't copy empty segments to output */ -template +template void internalSplit(DelimT delim, StringPiece sp, OutputIterator out, bool ignoreEmpty) { assert(sp.empty() || sp.start() != nullptr); @@ -314,7 +317,7 @@ void internalSplit(DelimT delim, StringPiece sp, OutputIterator out, } } -template StringPiece prepareDelim(const String& s) { +template StringPiece prepareDelim(const String& s) { return StringPiece(s); } inline char prepareDelim(char c) { return c; } @@ -352,11 +355,11 @@ bool splitFixed( return false; } -} +} // namespace detail ////////////////////////////////////////////////////////////////////// -template +template void split(const Delim& delimiter, const String& input, std::vector& out, @@ -368,7 +371,7 @@ void split(const Delim& delimiter, ignoreEmpty); } -template +template void split(const Delim& delimiter, const String& input, fbvector& out, @@ -380,8 +383,11 @@ void split(const Delim& delimiter, ignoreEmpty); } -template +template < + class OutputValueType, + class Delim, + class String, + class OutputIterator> void splitTo(const Delim& delimiter, const String& input, OutputIterator out, @@ -395,7 +401,8 @@ void splitTo(const Delim& delimiter, template typename std::enable_if< - AllConvertible::value && sizeof...(OutputTypes) >= 1, + StrictConjunction...>::value && + sizeof...(OutputTypes) >= 1, bool>::type split(const Delim& delimiter, StringPiece input, OutputTypes&... outputs) { return detail::splitFixed( @@ -471,7 +478,7 @@ internalJoin(Delim delimiter, internalJoinAppend(delimiter, begin, end, output); } -} // namespace detail +} // namespace detail template void join(const Delim& delimiter, @@ -485,8 +492,11 @@ void join(const Delim& delimiter, output); } -template -void backslashify(const String1& input, String2& output, bool hex_style) { +template +void backslashify( + folly::StringPiece input, + OutputString& output, + bool hex_style) { static const char hexValues[] = "0123456789abcdef"; output.clear(); output.reserve(3 * input.size()); @@ -498,14 +508,21 @@ void backslashify(const String1& input, String2& output, bool hex_style) { if (hex_style) { hex_append = true; } else { - if (c == '\r') output += 'r'; - else if (c == '\n') output += 'n'; - else if (c == '\t') output += 't'; - else if (c == '\a') output += 'a'; - else if (c == '\b') output += 'b'; - else if (c == '\0') output += '0'; - else if (c == '\\') output += '\\'; - else { + if (c == '\r') { + output += 'r'; + } else if (c == '\n') { + output += 'n'; + } else if (c == '\t') { + output += 't'; + } else if (c == '\a') { + output += 'a'; + } else if (c == '\b') { + output += 'b'; + } else if (c == '\0') { + output += '0'; + } else if (c == '\\') { + output += '\\'; + } else { hex_append = true; } } @@ -564,10 +581,12 @@ void humanify(const String1& input, String2& output) { } } -template +template bool hexlify(const InputString& input, OutputString& output, bool append_output) { - if (!append_output) output.clear(); + if (!append_output) { + output.clear(); + } static char hexValues[] = "0123456789abcdef"; auto j = output.size(); @@ -580,7 +599,7 @@ bool hexlify(const InputString& input, OutputString& output, return true; } -template +template bool unhexlify(const InputString& input, OutputString& output) { if (input.size() % 2 != 0) { return false; @@ -607,7 +626,7 @@ namespace detail { */ size_t hexDumpLine(const void* ptr, size_t offset, size_t size, std::string& line); -} // namespace detail +} // namespace detail template void hexDump(const void* ptr, size_t size, OutIt out) { @@ -619,4 +638,4 @@ void hexDump(const void* ptr, size_t size, OutIt out) { } } -} // namespace folly +} // namespace folly