unrevert "(wangle) express current Core functionality with a state machine""
[folly.git] / folly / String.h
index 9a44f5459116c36784a3830e48c807ae0711508a..efbda2f1bccb5b59db65082dacdc3046bdd63b3b 100644 (file)
@@ -186,6 +186,16 @@ std::string& stringAppendf(std::string* output,
                           FOLLY_PRINTF_FORMAT const char* format, ...)
   FOLLY_PRINTF_FORMAT_ATTR(2, 3);
 
+/**
+ * Similar to stringPrintf, but accepts a va_list argument.
+ *
+ * As with vsnprintf() itself, the value of ap is undefined after the call.
+ * These functions do not call va_end() on ap.
+ */
+std::string stringVPrintf(const char* format, va_list ap);
+void stringVPrintf(std::string* out, const char* format, va_list ap);
+std::string& stringVAppendf(std::string* out, const char* format, va_list ap);
+
 /**
  * Backslashify a string, that is, replace non-printable characters
  * with C-style (but NOT C compliant) "\xHH" encoding.  If hex_style
@@ -349,7 +359,8 @@ std::string hexDump(const void* ptr, size_t size);
 fbstring errnoStr(int err);
 
 /**
- * Debug string for an exception: include type and what().
+ * Debug string for an exception: include type and what(), if
+ * defined.
  */
 inline fbstring exceptionStr(const std::exception& e) {
   return folly::to<fbstring>(demangle(typeid(e)), ": ", e.what());
@@ -365,6 +376,14 @@ inline fbstring exceptionStr(std::exception_ptr ep) {
   }
 }
 
+template<typename E>
+auto exceptionStr(const E& e)
+  -> typename std::enable_if<!std::is_base_of<std::exception, E>::value,
+                             fbstring>::type
+{
+  return folly::to<fbstring>(demangle(typeid(e)));
+}
+
 /*
  * Split a string into a list of tokens by delimiter.
  *
@@ -448,7 +467,8 @@ void splitTo(const Delim& delimiter,
 template <class T>
 using IsSplitTargetType = std::integral_constant<bool,
   std::is_arithmetic<T>::value ||
-  std::is_same<T, StringPiece>::value>;
+  std::is_same<T, StringPiece>::value ||
+  IsSomeString<T>::value>;
 
 template<bool exact = true,
          class Delim,
@@ -509,37 +529,20 @@ std::string join(const Delim& delimiter,
  */
 StringPiece skipWhitespace(StringPiece sp);
 
-} // namespace folly
-
-// Hash functions to make std::string usable with e.g. hash_map
-//
-// Handle interaction with different C++ standard libraries, which
-// expect these types to be in different namespaces.
-namespace std {
-
-template <class C>
-struct hash<std::basic_string<C> > : private hash<const C*> {
-  size_t operator()(const std::basic_string<C> & s) const {
-    return hash<const C*>::operator()(s.c_str());
-  }
-};
+/**
+ * Fast, in-place lowercasing of ASCII alphabetic characters in strings.
+ * Leaves all other characters unchanged, including those with the 0x80
+ * bit set.
+ * @param str String to convert
+ * @param len Length of str, in bytes
+ */
+void toLowerAscii(char* str, size_t length);
 
+inline void toLowerAscii(MutableStringPiece str) {
+  toLowerAscii(str.begin(), str.size());
 }
 
-#if FOLLY_HAVE_DEPRECATED_ASSOC
-#if defined(_GLIBCXX_SYMVER) && !defined(__BIONIC__)
-namespace __gnu_cxx {
-
-template <class C>
-struct hash<std::basic_string<C> > : private hash<const C*> {
-  size_t operator()(const std::basic_string<C> & s) const {
-    return hash<const C*>::operator()(s.c_str());
-  }
-};
-
-}
-#endif
-#endif
+} // namespace folly
 
 // Hook into boost's type traits
 namespace boost {