]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/boost/utility/string_ref.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / utility / string_ref.hpp
index d234e5444a49ed00b6e6c9ddc9c9c2bf3f523f1f..999f1c3d6cc93a8d4ca4bfb052233ad78fc760dc 100644 (file)
@@ -1,5 +1,6 @@
 /*
    Copyright (c) Marshall Clow 2012-2015.
+   Copyright (c) Glen Joseph Fernandes 2019 (glenjofe@gmail.com)
 
    Distributed under the Boost Software License, Version 1.0. (See accompanying
    file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -17,6 +18,7 @@
 
 #include <boost/config.hpp>
 #include <boost/detail/workaround.hpp>
+#include <boost/utility/ostream_string.hpp>
 #include <boost/utility/string_ref_fwd.hpp>
 #include <boost/throw_exception.hpp>
 
@@ -181,6 +183,7 @@ namespace boost {
             }
 
         size_type find(basic_string_ref s) const {
+            if (s.empty()) return 0;
             const_iterator iter = std::search ( this->cbegin (), this->cend (),
                                                 s.cbegin (), s.cend (), traits::eq );
             return iter == this->cend () ? npos : std::distance ( this->cbegin (), iter );
@@ -193,6 +196,7 @@ namespace boost {
             }
 
         size_type rfind(basic_string_ref s) const {
+            if (s.empty()) return 0;
             const_reverse_iterator iter = std::search ( this->crbegin (), this->crend (),
                                                 s.crbegin (), s.crend (), traits::eq );
             return iter == this->crend () ? npos : (std::distance(iter, this->crend()) - s.size());
@@ -419,52 +423,11 @@ namespace boost {
         return basic_string_ref<charT, traits>(x) >= y;
         }
 
-    namespace detail {
-
-        template<class charT, class traits>
-        inline void sr_insert_fill_chars(std::basic_ostream<charT, traits>& os, std::size_t n) {
-            enum { chunk_size = 8 };
-            charT fill_chars[chunk_size];
-            std::fill_n(fill_chars, static_cast< std::size_t >(chunk_size), os.fill());
-            for (; n >= chunk_size && os.good(); n -= chunk_size)
-                os.write(fill_chars, static_cast< std::size_t >(chunk_size));
-            if (n > 0 && os.good())
-                os.write(fill_chars, n);
-            }
-
-        template<class charT, class traits>
-        void sr_insert_aligned(std::basic_ostream<charT, traits>& os, const basic_string_ref<charT,traits>& str) {
-            const std::size_t size = str.size();
-            const std::size_t alignment_size = static_cast< std::size_t >(os.width()) - size;
-            const bool align_left = (os.flags() & std::basic_ostream<charT, traits>::adjustfield) == std::basic_ostream<charT, traits>::left;
-            if (!align_left) {
-                detail::sr_insert_fill_chars(os, alignment_size);
-                if (os.good())
-                    os.write(str.data(), size);
-                }
-            else {
-                os.write(str.data(), size);
-                if (os.good())
-                    detail::sr_insert_fill_chars(os, alignment_size);
-                }
-            }
-
-        } // namespace detail
-
     // Inserter
     template<class charT, class traits>
     inline std::basic_ostream<charT, traits>&
     operator<<(std::basic_ostream<charT, traits>& os, const basic_string_ref<charT,traits>& str) {
-        if (os.good()) {
-            const std::size_t size = str.size();
-            const std::size_t w = static_cast< std::size_t >(os.width());
-            if (w <= size)
-                os.write(str.data(), size);
-            else
-                detail::sr_insert_aligned(os, str);
-            os.width(0);
-            }
-        return os;
+        return boost::ostream_string(os, str.data(), str.size());
         }
 
 #if 0