Fixed mistake with Makefile.am for spooky tests.
[folly.git] / folly / String.h
index 47d79de39af16228374ca3bd0e0289f4b128f86d..90b761e3e1e784a8babd23d61ba96f941c5a7c60 100644 (file)
@@ -17,6 +17,7 @@
 #ifndef FOLLY_BASE_STRING_H_
 #define FOLLY_BASE_STRING_H_
 
+#include <exception>
 #include <string>
 #include <boost/type_traits.hpp>
 
@@ -206,19 +207,27 @@ bool unhexlify(const InputString& input, OutputString& output);
  *
  * Current types are:
  *   PRETTY_TIME         - s, ms, us, ns, etc.
- *   PRETTY_BYTES        - kb, MB, GB, etc (goes up by 2^10 = 1024 each time)
- *   PRETTY_BYTES_METRIC - kb, MB, GB, etc (goes up by 10^3 = 1000 each time)
+ *   PRETTY_BYTES_METRIC - kB, MB, GB, etc (goes up by 10^3 = 1000 each time)
+ *   PRETTY_BYTES        - kB, MB, GB, etc (goes up by 2^10 = 1024 each time)
+ *   PRETTY_BYTES_IEC    - KiB, MiB, GiB, etc
  *   PRETTY_UNITS_METRIC - k, M, G, etc (goes up by 10^3 = 1000 each time)
  *   PRETTY_UNITS_BINARY - k, M, G, etc (goes up by 2^10 = 1024 each time)
+ *   PRETTY_UNITS_BINARY_IEC - Ki, Mi, Gi, etc
  *
  * @author Mark Rabkin <mrabkin@fb.com>
  */
 enum PrettyType {
   PRETTY_TIME,
-  PRETTY_BYTES,
+
   PRETTY_BYTES_METRIC,
+  PRETTY_BYTES_BINARY,
+  PRETTY_BYTES = PRETTY_BYTES_BINARY,
+  PRETTY_BYTES_BINARY_IEC,
+  PRETTY_BYTES_IEC = PRETTY_BYTES_BINARY_IEC,
+
   PRETTY_UNITS_METRIC,
   PRETTY_UNITS_BINARY,
+  PRETTY_UNITS_BINARY_IEC,
 
   PRETTY_NUM_TYPES
 };
@@ -277,6 +286,16 @@ inline fbstring exceptionStr(const std::exception& e) {
   return folly::to<fbstring>(demangle(typeid(e)), ": ", e.what());
 }
 
+inline fbstring exceptionStr(std::exception_ptr ep) {
+  try {
+    std::rethrow_exception(ep);
+  } catch (const std::exception& e) {
+    return exceptionStr(e);
+  } catch (...) {
+    return "<unknown exception>";
+  }
+}
+
 /*
  * Split a string into a list of tokens by delimiter.
  *
@@ -325,6 +344,34 @@ void splitTo(const Delim& delimiter,
              OutputIterator out,
              bool ignoreEmpty = false);
 
+/*
+ * Join list of tokens.
+ *
+ * Stores a string representation of tokens in the same order with
+ * deliminer between each element.
+ */
+
+template <class Delim, class Iterator, class String>
+void join(const Delim& delimiter,
+          Iterator begin,
+          Iterator end,
+          String& output);
+
+template <class Delim, class Container, class String>
+void join(const Delim& delimiter,
+          const Container& container,
+          String& output) {
+  join(delimiter, container.begin(), container.end(), output);
+}
+
+template <class Delim, class Container>
+std::string join(const Delim& delimiter,
+                 const Container& container) {
+  std::string output;
+  join(delimiter, container.begin(), container.end(), output);
+  return output;
+}
+
 } // namespace folly
 
 // Hash functions for string and fbstring usable with e.g. hash_map