From: Peter Griess <pgriess@fb.com>
Date: Fri, 20 Dec 2013 19:27:06 +0000 (-0800)
Subject: Use libc++ equivalent of std::__ostream_insert()
X-Git-Tag: v0.22.0~716
X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=13369e8fbfe71fc49ee63a5b6de76b4258e56963;p=folly.git

Use libc++ equivalent of std::__ostream_insert()

Summary:
- In libstdc++, existing code uses the internal std::__ostream_insert()
method to write a formatted string that can include '\0' characters.
This internal method doesn't exist in libc++. Instead, use the
relevant internal bits.

Test Plan:
- fbconfig -r folly && fbmake runtests
- ./configure && make check on Mac OS X

Reviewed By: njormrod@fb.com

FB internal diff: D1108540
---

diff --git a/folly/FBString.h b/folly/FBString.h
index 02e4d276..143a006c 100644
--- a/folly/FBString.h
+++ b/folly/FBString.h
@@ -1,5 +1,5 @@
 /*
- * Copyright 2013 Facebook, Inc.
+ * Copyright 2014 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -2312,7 +2312,29 @@ operator<<(
   std::basic_ostream<typename basic_fbstring<E, T, A, S>::value_type,
   typename basic_fbstring<E, T, A, S>::traits_type>& os,
     const basic_fbstring<E, T, A, S>& str) {
+#if _LIBCPP_VERSION
+  typename std::basic_ostream<
+    typename basic_fbstring<E, T, A, S>::value_type,
+    typename basic_fbstring<E, T, A, S>::traits_type>::sentry __s(os);
+  if (__s) {
+    typedef std::ostreambuf_iterator<
+      typename basic_fbstring<E, T, A, S>::value_type,
+      typename basic_fbstring<E, T, A, S>::traits_type> _Ip;
+    size_t __len = str.size();
+    bool __left =
+      (os.flags() & std::ios_base::adjustfield) == std::ios_base::left;
+    if (__pad_and_output(_Ip(os),
+                         str.data(),
+                         __left ? str.data() + __len : str.data(),
+                         str.data() + __len,
+                         os,
+                         os.fill()).failed()) {
+      os.setstate(std::ios_base::badbit | std::ios_base::failbit);
+    }
+  }
+#else
   std::__ostream_insert(os, str.data(), str.size());
+#endif
   return os;
 }