X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2FString.h;h=0251b987be1287a8d0137cd3aa1bc8a3fb5c42ca;hb=eba5e7f2236a0950957a8a247a0e83385149d13c;hp=53b54f42f8c7f022643941431341fc5bd2c98842;hpb=adf4a5ac9d3604427c85dd92ec379e9d7a3a4a8a;p=folly.git diff --git a/folly/String.h b/folly/String.h index 53b54f42..0251b987 100644 --- a/folly/String.h +++ b/folly/String.h @@ -34,6 +34,7 @@ #include #include #include +#include // Compatibility function, to make sure toStdString(s) can be called // to convert a std::string or fbstring variable s into type std::string @@ -211,12 +212,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 -void backslashify(const String1& input, String2& output, bool hex_style=false); +template +void backslashify( + folly::StringPiece input, + OutputString& output, + bool hex_style = false); -template -String backslashify(const String& input, bool hex_style=false) { - String output; +template +OutputString backslashify(StringPiece input, bool hex_style = false) { + OutputString output; backslashify(input, output, hex_style); return output; } @@ -465,56 +469,22 @@ void splitTo(const Delim& delimiter, * Note that this will likely not work if the last field's target is of numeric * type, in which case folly::to<> will throw an exception. */ -template -struct IsSomeVector { - enum { value = false }; -}; +namespace detail { +template +struct IsConvertible : std::false_type {}; -template -struct IsSomeVector, void> { - enum { value = true }; -}; - -template -struct IsSomeVector, void> { - enum { value = true }; -}; - -template -struct IsConvertible { - enum { value = false }; -}; - -template +template struct IsConvertible< - T, - decltype(static_cast( - parseTo(std::declval(), std::declval())))> { - enum { value = true }; -}; - -template -struct AllConvertible; - -template -struct AllConvertible { - enum { value = IsConvertible::value && AllConvertible::value }; -}; - -template <> -struct AllConvertible<> { - enum { value = true }; -}; - -static_assert(AllConvertible::value, ""); -static_assert(AllConvertible::value, ""); -static_assert(AllConvertible::value, ""); -static_assert(AllConvertible::value, ""); -static_assert(!AllConvertible>::value, ""); + void_t()))>, + OutputType> : std::true_type {}; +} // namespace detail +template +struct IsConvertible : detail::IsConvertible {}; 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); @@ -618,7 +588,7 @@ std::string stripLeftMargin(std::string s); * Leaves all other characters unchanged, including those with the 0x80 * bit set. * @param str String to convert - * @param len Length of str, in bytes + * @param length Length of str, in bytes */ void toLowerAscii(char* str, size_t length); @@ -626,6 +596,11 @@ inline void toLowerAscii(MutableStringPiece str) { toLowerAscii(str.begin(), str.size()); } +inline void toLowerAscii(std::string& str) { + // str[0] is legal also if the string is empty. + toLowerAscii(&str[0], str.size()); +} + template < class Iterator = const char*, class Base = folly::Range>>