From 13369e8fbfe71fc49ee63a5b6de76b4258e56963 Mon Sep 17 00:00:00 2001 From: Peter Griess Date: Fri, 20 Dec 2013 11:27:06 -0800 Subject: [PATCH] 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 --- folly/FBString.h | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) 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::value_type, typename basic_fbstring::traits_type>& os, const basic_fbstring& str) { +#if _LIBCPP_VERSION + typename std::basic_ostream< + typename basic_fbstring::value_type, + typename basic_fbstring::traits_type>::sentry __s(os); + if (__s) { + typedef std::ostreambuf_iterator< + typename basic_fbstring::value_type, + typename basic_fbstring::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; } -- 2.34.1