• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*=============================================================================
2     Copyright (c) 2017 Daniel James
3     http://spirit.sourceforge.net/
4 
5     Use, modification and distribution is subject to the Boost Software
6     License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7     http://www.boost.org/LICENSE_1_0.txt)
8 =============================================================================*/
9 #if !defined(BOOST_SPIRIT_QUICKBOOK_STRING_VIEW_HPP)
10 #define BOOST_SPIRIT_QUICKBOOK_STRING_VIEW_HPP
11 
12 #include <boost/functional/hash/hash_fwd.hpp>
13 #include <boost/utility/string_view.hpp>
14 
15 namespace quickbook
16 {
17     // boost::string_view now can't be constructed from an rvalue std::string,
18     // which is something that quickbook does in several places, so this wraps
19     // it to allow that.
20 
21     struct string_view : boost::string_view
22     {
23         typedef boost::string_view base;
24 
string_viewquickbook::string_view25         string_view() : base() {}
string_viewquickbook::string_view26         string_view(string_view const& x) : base(x) {}
string_viewquickbook::string_view27         string_view(std::string const& x) : base(x) {}
string_viewquickbook::string_view28         string_view(const char* x) : base(x) {}
string_viewquickbook::string_view29         string_view(const char* x, base::size_type len) : base(x, len) {}
30 
to_squickbook::string_view31         std::string to_s() const { return std::string(begin(), end()); }
32     };
33 
34     typedef quickbook::string_view::const_iterator string_iterator;
35 
hash_value(string_view const & x)36     inline std::size_t hash_value(string_view const& x)
37     {
38         return boost::hash_range(x.begin(), x.end());
39     }
40 
operator +=(std::string & x,string_view const & y)41     inline std::string& operator+=(std::string& x, string_view const& y)
42     {
43         return x.append(y.begin(), y.end());
44     }
45 }
46 
47 #endif
48