1
0
Fork 0
mirror of https://github.com/KingDuckZ/kamokan.git synced 2025-06-07 00:51:41 +00:00

Replace string_ref with string_view

This commit is contained in:
King_DuckZ 2017-06-06 23:04:40 +01:00
parent df1afc7616
commit 6e19745d69
39 changed files with 168 additions and 167 deletions

@ -1 +1 @@
Subproject commit fbd39c27991a3f7335f0f606f7e047bff31fa288 Subproject commit 045675c8084fce265330686ab29dc6009b84e341

View file

@ -118,8 +118,8 @@ namespace {
//Prepare the logger //Prepare the logger
spdlog::set_pattern("[%Y-%m-%d %T %z] - %v"); spdlog::set_pattern("[%Y-%m-%d %T %z] - %v");
spdlog::set_level(spdlog::level::trace); //set to maximum possible here spdlog::set_level(spdlog::level::trace); //set to maximum possible here
boost::string_ref log_path = parSettings["log_file"]; boost::string_view log_path = parSettings["log_file"];
const bool log_to_stderr = (log_path == boost::string_ref("-")); const bool log_to_stderr = (log_path == "-");
auto statuslog = (log_to_stderr ? auto statuslog = (log_to_stderr ?
spdlog::stderr_logger_st("statuslog") : spdlog::stderr_logger_st("statuslog") :
spdlog::basic_logger_st("statuslog", std::string(log_path.begin(), log_path.end()), false) spdlog::basic_logger_st("statuslog", std::string(log_path.begin(), log_path.end()), false)
@ -141,7 +141,7 @@ int main (int parArgc, char* parArgv[], char* parEnvp[]) {
using tawashi::Response; using tawashi::Response;
using tawashi::RequestMethodType; using tawashi::RequestMethodType;
if (2 == parArgc and boost::string_ref(parArgv[1]) == "--show-paths") { if (2 == parArgc and boost::string_view(parArgv[1]) == "--show-paths") {
print_buildtime_info(); print_buildtime_info();
return 0; return 0;
} }

View file

@ -36,7 +36,7 @@
BOOST_FUSION_ADAPT_STRUCT( BOOST_FUSION_ADAPT_STRUCT(
tawashi::cgi::Env::VersionInfo, tawashi::cgi::Env::VersionInfo,
(boost::string_ref, name) (boost::string_view, name)
(uint16_t, major) (uint16_t, major)
(uint16_t, minor) (uint16_t, minor)
); );
@ -50,9 +50,9 @@ namespace cgi {
using boost::spirit::ascii::space; using boost::spirit::ascii::space;
using boost::spirit::qi::raw; using boost::spirit::qi::raw;
using boost::spirit::qi::char_; using boost::spirit::qi::char_;
using boost::string_ref; using boost::string_view;
using VerNum = boost::spirit::qi::uint_parser<uint16_t, 10, 1, 1>; using VerNum = boost::spirit::qi::uint_parser<uint16_t, 10, 1, 1>;
using RuleType = boost::spirit::qi::rule<std::string::const_iterator, string_ref(), boost::spirit::ascii::space_type>; using RuleType = boost::spirit::qi::rule<std::string::const_iterator, string_view(), boost::spirit::ascii::space_type>;
using boost::spirit::_1; using boost::spirit::_1;
using boost::spirit::qi::_val; using boost::spirit::qi::_val;
using boost::phoenix::begin; using boost::phoenix::begin;
@ -64,7 +64,7 @@ namespace cgi {
assert(not parString.empty()); assert(not parString.empty());
auto beg = parString.cbegin(); auto beg = parString.cbegin();
RuleType protocol = raw[+(char_ - '/')][_val = px::bind(&string_ref::substr, construct<string_ref>(px::ref(parString)), begin(_1) - px::ref(beg), size(_1))]; RuleType protocol = raw[+(char_ - '/')][_val = px::bind(&string_view::substr, construct<string_view>(px::ref(parString)), begin(_1) - px::ref(beg), size(_1))];
VerNum ver_num; VerNum ver_num;
auto it_curr = parString.cbegin(); auto it_curr = parString.cbegin();
@ -83,9 +83,9 @@ namespace cgi {
return optional<Env::VersionInfo>(); return optional<Env::VersionInfo>();
} }
std::size_t calculate_skip_path_length (const boost::string_ref& parPath, const boost::string_ref& parBasePath) { std::size_t calculate_skip_path_length (const boost::string_view& parPath, const boost::string_view& parBasePath) {
const std::size_t base_path_tr_slash = (not parBasePath.empty() and parBasePath[parBasePath.size() - 1] == '/' ? 1 : 0); const std::size_t base_path_tr_slash = (not parBasePath.empty() and parBasePath[parBasePath.size() - 1] == '/' ? 1 : 0);
boost::string_ref base_path = parBasePath.substr(0, parBasePath.size() - base_path_tr_slash); boost::string_view base_path = parBasePath.substr(0, parBasePath.size() - base_path_tr_slash);
SPDLOG_TRACE(spdlog::get("statuslog"), "calculating skip prefix for REQUEST_URI=\"{}\", base path=\"{}\", parBasePath=\"{}\", base path trailing slash={}", SPDLOG_TRACE(spdlog::get("statuslog"), "calculating skip prefix for REQUEST_URI=\"{}\", base path=\"{}\", parBasePath=\"{}\", base path trailing slash={}",
std::string(parPath.begin(), parPath.end()), std::string(parPath.begin(), parPath.end()),
std::string(base_path.begin(), base_path.end()), std::string(base_path.begin(), base_path.end()),
@ -110,7 +110,7 @@ namespace cgi {
} }
} //unnamed namespace } //unnamed namespace
Env::Env(const char* const* parEnvList, const boost::string_ref& parBasePath) : Env::Env(const char* const* parEnvList, const boost::string_view& parBasePath) :
m_cgi_env(cgi_environment_vars(parEnvList)), m_cgi_env(cgi_environment_vars(parEnvList)),
m_skip_path_info(calculate_skip_path_length(m_cgi_env[CGIVars::REQUEST_URI], parBasePath)), m_skip_path_info(calculate_skip_path_length(m_cgi_env[CGIVars::REQUEST_URI], parBasePath)),
m_request_method_type(RequestMethodType::_from_string(m_cgi_env[CGIVars::REQUEST_METHOD].data())) m_request_method_type(RequestMethodType::_from_string(m_cgi_env[CGIVars::REQUEST_METHOD].data()))
@ -124,7 +124,7 @@ namespace cgi {
std::string err_msg = "Parsing failed at position " + std::string err_msg = "Parsing failed at position " +
std::to_string(parsed_chars) + " for input \"" + std::to_string(parsed_chars) + " for input \"" +
content_type + "\""; content_type + "\"";
throw TawashiException(ErrorReasons::InvalidContentType, boost::string_ref(err_msg)); throw TawashiException(ErrorReasons::InvalidContentType, boost::string_view(err_msg));
} }
} }
} }
@ -244,16 +244,16 @@ namespace cgi {
return parStream; return parStream;
} }
boost::string_ref Env::request_uri_relative() const { boost::string_view Env::request_uri_relative() const {
const std::string& path = m_cgi_env[CGIVars::REQUEST_URI]; const std::string& path = m_cgi_env[CGIVars::REQUEST_URI];
assert(m_skip_path_info <= path.size()); assert(m_skip_path_info <= path.size());
return boost::string_ref(path).substr(m_skip_path_info); return boost::string_view(path).substr(m_skip_path_info);
} }
boost::string_ref Env::path_info_relative() const { boost::string_view Env::path_info_relative() const {
const std::string& path = m_cgi_env[CGIVars::PATH_INFO]; const std::string& path = m_cgi_env[CGIVars::PATH_INFO];
assert(m_skip_path_info <= path.size()); assert(m_skip_path_info <= path.size());
return boost::string_ref(path).substr(m_skip_path_info); return boost::string_view(path).substr(m_skip_path_info);
} }
} //namespace cgi } //namespace cgi
} //namespace tawashi } //namespace tawashi

View file

@ -25,7 +25,7 @@
#include "mime_split.hpp" #include "mime_split.hpp"
#include <vector> #include <vector>
#include <string> #include <string>
#include <boost/utility/string_ref.hpp> #include <boost/utility/string_view.hpp>
#include <cstdint> #include <cstdint>
#include <iostream> #include <iostream>
#include <boost/optional.hpp> #include <boost/optional.hpp>
@ -36,14 +36,14 @@ namespace tawashi {
class Env : public Kakoune::SafeCountable { class Env : public Kakoune::SafeCountable {
public: public:
struct VersionInfo { struct VersionInfo {
boost::string_ref name; boost::string_view name;
uint16_t major; uint16_t major;
uint16_t minor; uint16_t minor;
}; };
typedef boost::container::flat_map<std::string, std::string> GetMapType; typedef boost::container::flat_map<std::string, std::string> GetMapType;
Env (const char* const* parEnvList, const boost::string_ref& parBasePath); Env (const char* const* parEnvList, const boost::string_view& parBasePath);
~Env() noexcept; ~Env() noexcept;
const std::string& auth_type() const; const std::string& auth_type() const;
@ -70,8 +70,8 @@ namespace tawashi {
GetMapType query_string_split() const a_pure; GetMapType query_string_split() const a_pure;
const SplitMime& content_type_split() const a_pure; const SplitMime& content_type_split() const a_pure;
boost::string_ref request_uri_relative() const; boost::string_view request_uri_relative() const;
boost::string_ref path_info_relative() const; boost::string_view path_info_relative() const;
std::ostream& print_all (std::ostream& parStream, const char* parNewline) const; std::ostream& print_all (std::ostream& parStream, const char* parNewline) const;

View file

@ -20,7 +20,7 @@
#include "string_lengths.hpp" #include "string_lengths.hpp"
#include <utility> #include <utility>
#include <unordered_map> #include <unordered_map>
#include <boost/utility/string_ref.hpp> #include <boost/utility/string_view.hpp>
#include <cassert> #include <cassert>
#include <cstring> #include <cstring>
#include <boost/functional/hash.hpp> #include <boost/functional/hash.hpp>
@ -31,8 +31,8 @@
namespace std { namespace std {
template<> template<>
struct hash<boost::string_ref> { struct hash<boost::string_view> {
std::size_t operator() (const boost::string_ref& parStr) const { std::size_t operator() (const boost::string_view& parStr) const {
return boost::hash_range(parStr.begin(), parStr.end()); return boost::hash_range(parStr.begin(), parStr.end());
} }
}; };
@ -40,8 +40,8 @@ namespace std {
namespace tawashi { namespace tawashi {
namespace { namespace {
std::unordered_map<boost::string_ref, boost::string_ref> get_unrefined_env_vars (const char* const* parEnvList) { std::unordered_map<boost::string_view, boost::string_view> get_unrefined_env_vars (const char* const* parEnvList) {
using boost::string_ref; using boost::string_view;
assert(parEnvList); assert(parEnvList);
std::size_t count = 0; std::size_t count = 0;
@ -49,7 +49,7 @@ namespace tawashi {
++count; ++count;
} }
std::unordered_map<string_ref, string_ref> retval; std::unordered_map<string_view, string_view> retval;
retval.reserve(count); retval.reserve(count);
for (std::size_t z = 0; z < count; ++z) { for (std::size_t z = 0; z < count; ++z) {
const char* const equal_sign = std::strchr(parEnvList[z], '='); const char* const equal_sign = std::strchr(parEnvList[z], '=');
@ -59,14 +59,14 @@ namespace tawashi {
const std::size_t whole_length = std::strlen(parEnvList[z] + key_length) + key_length; const std::size_t whole_length = std::strlen(parEnvList[z] + key_length) + key_length;
assert(std::strlen(parEnvList[z]) == whole_length); assert(std::strlen(parEnvList[z]) == whole_length);
assert(whole_length >= key_length + 1); assert(whole_length >= key_length + 1);
retval[string_ref(parEnvList[z], key_length)] = string_ref(parEnvList[z] + key_length + 1, whole_length - key_length - 1); retval[string_view(parEnvList[z], key_length)] = string_view(parEnvList[z] + key_length + 1, whole_length - key_length - 1);
} }
return retval; return retval;
} }
} //unnamed namespace } //unnamed namespace
std::vector<std::string> cgi_environment_vars (const char* const* parEnvList) { std::vector<std::string> cgi_environment_vars (const char* const* parEnvList) {
using boost::string_ref; using boost::string_view;
std::vector<std::string> retlist; std::vector<std::string> retlist;
retlist.reserve(CGIVars::_size()); retlist.reserve(CGIVars::_size());
@ -79,7 +79,7 @@ namespace tawashi {
#if !defined(NDEBUG) #if !defined(NDEBUG)
assert(std::strlen(var._to_string()) == enum_str_lengths[z]); assert(std::strlen(var._to_string()) == enum_str_lengths[z]);
#endif #endif
auto it_found = unrefined_env_vars.find(boost::string_ref(var._to_string(), enum_str_lengths[z])); auto it_found = unrefined_env_vars.find(string_view(var._to_string(), enum_str_lengths[z]));
if (unrefined_env_vars.cend() != it_found) if (unrefined_env_vars.cend() != it_found)
retlist.push_back(sanitized_utf8(it_found->second)); retlist.push_back(sanitized_utf8(it_found->second));
else else

View file

@ -28,7 +28,7 @@
#include <ciso646> #include <ciso646>
namespace tawashi { namespace tawashi {
UnsupportedContentTypeException::UnsupportedContentTypeException (const boost::string_ref& parMessage) : UnsupportedContentTypeException::UnsupportedContentTypeException (const boost::string_view& parMessage) :
TawashiException(ErrorReasons::UnsupportedContentType, parMessage) TawashiException(ErrorReasons::UnsupportedContentType, parMessage)
{ {
} }

View file

@ -26,7 +26,7 @@
namespace tawashi { namespace tawashi {
class UnsupportedContentTypeException : public TawashiException { class UnsupportedContentTypeException : public TawashiException {
public: public:
explicit UnsupportedContentTypeException (const boost::string_ref& parMessage); explicit UnsupportedContentTypeException (const boost::string_view& parMessage);
}; };
namespace cgi { namespace cgi {

View file

@ -18,7 +18,7 @@
#pragma once #pragma once
#include "response.hpp" #include "response.hpp"
#include <boost/utility/string_ref.hpp> #include <boost/utility/string_view.hpp>
namespace tawashi { namespace tawashi {
class ErrorResponse : public Response { class ErrorResponse : public Response {
@ -30,7 +30,7 @@ namespace tawashi {
); );
protected: protected:
virtual boost::string_ref page_basename() const override { return boost::string_ref("error"); } virtual boost::string_view page_basename() const override { return boost::string_view("error"); }
private: private:
virtual void on_mustache_prepare (mstch::map& parContext) override; virtual void on_mustache_prepare (mstch::map& parContext) override;

View file

@ -35,7 +35,7 @@ namespace tawashi {
static_cast<gh_buf*>(m_gh_buf)->~gh_buf(); static_cast<gh_buf*>(m_gh_buf)->~gh_buf();
} }
std::string Escapist::unescape_url (const boost::string_ref& parURL) const { std::string Escapist::unescape_url (const boost::string_view& parURL) const {
if (parURL.empty()) if (parURL.empty())
return std::string(); return std::string();
@ -53,7 +53,7 @@ namespace tawashi {
return std::string(buf->ptr, buf->size); return std::string(buf->ptr, buf->size);
} }
std::string Escapist::escape_url (const boost::string_ref& parURL) const { std::string Escapist::escape_url (const boost::string_view& parURL) const {
if (parURL.empty()) if (parURL.empty())
return std::string(); return std::string();
@ -71,7 +71,7 @@ namespace tawashi {
return std::string(buf->ptr, buf->size); return std::string(buf->ptr, buf->size);
} }
std::string Escapist::escape_html (const boost::string_ref& parHtml) const { std::string Escapist::escape_html (const boost::string_view& parHtml) const {
if (parHtml.empty()) if (parHtml.empty())
return std::string(); return std::string();

View file

@ -17,7 +17,7 @@
#pragma once #pragma once
#include <boost/utility/string_ref.hpp> #include <boost/utility/string_view.hpp>
#include <string> #include <string>
#include <memory> #include <memory>
@ -36,9 +36,9 @@ namespace tawashi {
Escapist(); Escapist();
~Escapist() noexcept; ~Escapist() noexcept;
std::string unescape_url (const boost::string_ref& parURL) const; std::string unescape_url (const boost::string_view& parURL) const;
std::string escape_url (const boost::string_ref& parURL) const; std::string escape_url (const boost::string_view& parURL) const;
std::string escape_html (const boost::string_ref& parHtml) const; std::string escape_html (const boost::string_view& parHtml) const;
private: private:
std::aligned_storage<sizeof(implem::DummyGHBuf), alignof(implem::DummyGHBuf)>::type m_gh_buf_mem; std::aligned_storage<sizeof(implem::DummyGHBuf), alignof(implem::DummyGHBuf)>::type m_gh_buf_mem;

View file

@ -18,7 +18,7 @@
#pragma once #pragma once
#include "response.hpp" #include "response.hpp"
#include <boost/utility/string_ref.hpp> #include <boost/utility/string_view.hpp>
namespace tawashi { namespace tawashi {
class IndexResponse : public Response { class IndexResponse : public Response {
@ -30,7 +30,7 @@ namespace tawashi {
); );
protected: protected:
virtual boost::string_ref page_basename() const override { return boost::string_ref("index"); } virtual boost::string_view page_basename() const override { return boost::string_view("index"); }
private: private:
}; };

View file

@ -43,7 +43,7 @@
namespace tawashi { namespace tawashi {
namespace { namespace {
typedef boost::string_ref string_type; typedef boost::string_view string_type;
template <typename Iterator, typename Skipper> template <typename Iterator, typename Skipper>
struct IniGrammar : boost::spirit::qi::grammar<Iterator, IniFile::IniMapType(), Skipper> { struct IniGrammar : boost::spirit::qi::grammar<Iterator, IniFile::IniMapType(), Skipper> {
@ -69,7 +69,7 @@ namespace tawashi {
using boost::spirit::_1; using boost::spirit::_1;
using boost::spirit::qi::eol; using boost::spirit::qi::eol;
using boost::spirit::qi::raw; using boost::spirit::qi::raw;
using boost::string_ref; using boost::string_view;
using boost::spirit::qi::hold; using boost::spirit::qi::hold;
using boost::spirit::qi::graph; using boost::spirit::qi::graph;
using boost::spirit::qi::blank; using boost::spirit::qi::blank;
@ -77,19 +77,19 @@ namespace tawashi {
section = '[' >> raw[+(graph - ']') >> *(hold[+blank >> +(graph - ']')])] section = '[' >> raw[+(graph - ']') >> *(hold[+blank >> +(graph - ']')])]
[_val = px::bind( [_val = px::bind(
&string_ref::substr, &string_view::substr,
px::construct<string_ref>(px::ref(*m_master_string)), px::construct<string_view>(px::ref(*m_master_string)),
px::begin(_1) - px::ref(m_begin), px::size(_1) px::begin(_1) - px::ref(m_begin), px::size(_1)
)] >> ']'; )] >> ']';
key = raw[(graph - '[' - '=') >> *(graph - '=') >> *(hold[+blank >> +(graph - '=')])][_val = px::bind( key = raw[(graph - '[' - '=') >> *(graph - '=') >> *(hold[+blank >> +(graph - '=')])][_val = px::bind(
&string_ref::substr, &string_view::substr,
px::construct<string_ref>(px::ref(*m_master_string)), px::construct<string_view>(px::ref(*m_master_string)),
px::begin(_1) - px::ref(m_begin), px::size(_1) px::begin(_1) - px::ref(m_begin), px::size(_1)
)]; )];
key_value = key[px::bind(&refpair::first, _val) = _1] >> '=' >> key_value = key[px::bind(&refpair::first, _val) = _1] >> '=' >>
raw[*(graph - eol) >> *(hold[+blank >> +(graph - eol)])][px::bind(&refpair::second, _val) = px::bind( raw[*(graph - eol) >> *(hold[+blank >> +(graph - eol)])][px::bind(&refpair::second, _val) = px::bind(
&string_ref::substr, &string_view::substr,
px::construct<string_ref>(px::ref(*m_master_string)), px::construct<string_view>(px::ref(*m_master_string)),
px::begin(_1) - px::ref(m_begin), px::size(_1) px::begin(_1) - px::ref(m_begin), px::size(_1)
)]; )];
key_values = -(key_value % (+eol)); key_values = -(key_value % (+eol));

View file

@ -20,15 +20,15 @@
#include "kakoune/safe_ptr.hh" #include "kakoune/safe_ptr.hh"
#include <boost/container/flat_map.hpp> #include <boost/container/flat_map.hpp>
#include <iterator> #include <iterator>
#include <boost/utility/string_ref.hpp> #include <boost/utility/string_view.hpp>
#include <string> #include <string>
#include <cassert> #include <cassert>
namespace tawashi { namespace tawashi {
class IniFile : public Kakoune::SafeCountable { class IniFile : public Kakoune::SafeCountable {
public: public:
typedef boost::container::flat_map<boost::string_ref, boost::string_ref> KeyValueMapType; typedef boost::container::flat_map<boost::string_view, boost::string_view> KeyValueMapType;
typedef boost::container::flat_map<boost::string_ref, KeyValueMapType> IniMapType; typedef boost::container::flat_map<boost::string_view, KeyValueMapType> IniMapType;
IniFile (std::istream_iterator<char> parInputFrom, std::istream_iterator<char> parInputEnd); IniFile (std::istream_iterator<char> parInputFrom, std::istream_iterator<char> parInputEnd);
explicit IniFile (std::string&& parIniData); explicit IniFile (std::string&& parIniData);

View file

@ -81,8 +81,8 @@
BOOST_FUSION_ADAPT_STRUCT( BOOST_FUSION_ADAPT_STRUCT(
tawashi::SplitMime, tawashi::SplitMime,
(boost::string_ref, type) (boost::string_view, type)
(boost::string_ref, subtype) (boost::string_view, subtype)
(tawashi::MimeParametersMapType, parameters) (tawashi::MimeParametersMapType, parameters)
); );
@ -94,13 +94,13 @@ namespace tawashi {
boost::spirit::qi::rule<Iterator, SplitMime(), Skipper> content_type; boost::spirit::qi::rule<Iterator, SplitMime(), Skipper> content_type;
boost::spirit::qi::rule<Iterator, SplitMime(), Skipper> media_type; boost::spirit::qi::rule<Iterator, SplitMime(), Skipper> media_type;
boost::spirit::qi::rule<Iterator, boost::string_ref(), Skipper> type; boost::spirit::qi::rule<Iterator, boost::string_view(), Skipper> type;
boost::spirit::qi::rule<Iterator, boost::string_ref(), Skipper> subtype; boost::spirit::qi::rule<Iterator, boost::string_view(), Skipper> subtype;
boost::spirit::qi::rule<Iterator, MimeParametersMapType::value_type(), Skipper> parameter; boost::spirit::qi::rule<Iterator, MimeParametersMapType::value_type(), Skipper> parameter;
boost::spirit::qi::rule<Iterator, boost::string_ref(), Skipper> attribute; boost::spirit::qi::rule<Iterator, boost::string_view(), Skipper> attribute;
boost::spirit::qi::rule<Iterator, boost::string_ref(), Skipper> value; boost::spirit::qi::rule<Iterator, boost::string_view(), Skipper> value;
boost::spirit::qi::rule<Iterator, boost::string_ref(), Skipper> quoted_string; boost::spirit::qi::rule<Iterator, boost::string_view(), Skipper> quoted_string;
boost::spirit::qi::rule<Iterator, boost::string_ref(), Skipper> token; boost::spirit::qi::rule<Iterator, boost::string_view(), Skipper> token;
const std::string* m_master_string; const std::string* m_master_string;
Iterator m_begin; Iterator m_begin;
}; };
@ -119,7 +119,7 @@ namespace tawashi {
using boost::spirit::qi::raw; using boost::spirit::qi::raw;
using boost::spirit::qi::_val; using boost::spirit::qi::_val;
using boost::spirit::qi::lexeme; using boost::spirit::qi::lexeme;
using boost::string_ref; using boost::string_view;
using boost::spirit::_1; using boost::spirit::_1;
content_type = -media_type; content_type = -media_type;
@ -132,7 +132,7 @@ namespace tawashi {
token = raw[+(alnum | char_("_.-"))][ token = raw[+(alnum | char_("_.-"))][
_val = px::bind( _val = px::bind(
&string_ref::substr, px::construct<string_ref>(px::ref(*m_master_string)), &string_view::substr, px::construct<string_view>(px::ref(*m_master_string)),
px::begin(_1) - px::ref(m_begin), px::begin(_1) - px::ref(m_begin),
px::size(_1) px::size(_1)
) )
@ -144,7 +144,7 @@ namespace tawashi {
'"' '"'
] ]
][_val = px::bind( ][_val = px::bind(
&string_ref::substr, px::construct<string_ref>(px::ref(*m_master_string)), &string_view::substr, px::construct<string_view>(px::ref(*m_master_string)),
px::begin(_1) + 1 - px::ref(m_begin), px::begin(_1) + 1 - px::ref(m_begin),
px::size(_1) - 2 px::size(_1) - 2
)]; )];
@ -188,7 +188,7 @@ namespace tawashi {
std::string mime_to_string (const SplitMime& parMime, bool& parWriteOk) { std::string mime_to_string (const SplitMime& parMime, bool& parWriteOk) {
namespace px = boost::phoenix; namespace px = boost::phoenix;
using boost::string_ref; using boost::string_view;
using boost::spirit::karma::generate; using boost::spirit::karma::generate;
using boost::spirit::karma::char_; using boost::spirit::karma::char_;
using boost::spirit::karma::string; using boost::spirit::karma::string;
@ -205,9 +205,9 @@ namespace tawashi {
px::function<simple_token_checker> is_simple_token; px::function<simple_token_checker> is_simple_token;
std::string retval; std::string retval;
std::back_insert_iterator<std::string> out_iter(retval); std::back_insert_iterator<std::string> out_iter(retval);
rule<std::back_insert_iterator<std::string>, string_ref()> token; rule<std::back_insert_iterator<std::string>, string_view()> token;
rule<std::back_insert_iterator<std::string>, string_ref()> quoted_string; rule<std::back_insert_iterator<std::string>, string_view()> quoted_string;
rule<std::back_insert_iterator<std::string>, string_ref()> param_value; rule<std::back_insert_iterator<std::string>, string_view()> param_value;
token %= eps(is_simple_token(_val)) << *(alnum | char_("._-")); token %= eps(is_simple_token(_val)) << *(alnum | char_("._-"));
quoted_string %= '"' << string << '"'; quoted_string %= '"' << string << '"';

View file

@ -17,16 +17,16 @@
#pragma once #pragma once
#include <boost/utility/string_ref.hpp> #include <boost/utility/string_view.hpp>
#include <boost/container/flat_map.hpp> #include <boost/container/flat_map.hpp>
#include <string> #include <string>
namespace tawashi { namespace tawashi {
typedef boost::container::flat_map<boost::string_ref, boost::string_ref> MimeParametersMapType; typedef boost::container::flat_map<boost::string_view, boost::string_view> MimeParametersMapType;
struct SplitMime { struct SplitMime {
boost::string_ref type; boost::string_view type;
boost::string_ref subtype; boost::string_view subtype;
MimeParametersMapType parameters; MimeParametersMapType parameters;
}; };

View file

@ -22,7 +22,7 @@
namespace tawashi { namespace tawashi {
template <typename T> template <typename T>
inline bool seems_valid_number (const boost::string_ref& parValue) { inline bool seems_valid_number (const boost::string_view& parValue) {
const std::size_t skip_sign = (sprout::is_signed<T>::value and not parValue.empty() and parValue[0] == '-' ? 1 : 0); const std::size_t skip_sign = (sprout::is_signed<T>::value and not parValue.empty() and parValue[0] == '-' ? 1 : 0);
for (std::size_t z = skip_sign; z < parValue.size(); ++z) { for (std::size_t z = skip_sign; z < parValue.size(); ++z) {
const char c = parValue[z]; const char c = parValue[z];

View file

@ -33,6 +33,7 @@ namespace tawashi {
//TODO: make sure the file exists or throw or do something //TODO: make sure the file exists or throw or do something
return parSettings.as<std::string>("highlight_css"); return parSettings.as<std::string>("highlight_css");
} }
} //unnamed namespace } //unnamed namespace
PastieResponse::PastieResponse ( PastieResponse::PastieResponse (
@ -75,7 +76,7 @@ namespace tawashi {
} }
void PastieResponse::on_mustache_prepare (mstch::map& parContext) { void PastieResponse::on_mustache_prepare (mstch::map& parContext) {
boost::string_ref token = cgi_env().path_info_relative(); boost::string_view token = cgi_env().path_info_relative();
boost::optional<std::string> pastie = this->storage().retrieve_pastie(token); boost::optional<std::string> pastie = this->storage().retrieve_pastie(token);
if (not pastie) { if (not pastie) {

View file

@ -19,7 +19,7 @@
#include "response.hpp" #include "response.hpp"
#include <string> #include <string>
#include <boost/utility/string_ref.hpp> #include <boost/utility/string_view.hpp>
namespace tawashi { namespace tawashi {
class PastieResponse : public Response { class PastieResponse : public Response {
@ -31,7 +31,7 @@ namespace tawashi {
); );
protected: protected:
virtual boost::string_ref page_basename() const override { return boost::string_ref("pastie"); } virtual boost::string_view page_basename() const override { return boost::string_view("pastie"); }
private: private:
virtual HttpHeader on_process() override; virtual HttpHeader on_process() override;

View file

@ -55,7 +55,7 @@ namespace mchlib {
return reserve; return reserve;
} }
std::size_t count_grouped (boost::string_ref parIn, char parDelim) { std::size_t count_grouped (boost::string_view parIn, char parDelim) {
std::size_t retval = 0; std::size_t retval = 0;
char prev = '\0'; char prev = '\0';
for (auto c : parIn) { for (auto c : parIn) {
@ -65,9 +65,9 @@ namespace mchlib {
return retval; return retval;
} }
void split_path (std::vector<boost::string_ref>* parOut, boost::string_ref parPath) { void split_path (std::vector<boost::string_view>* parOut, boost::string_view parPath) {
auto from = parPath.begin(); auto from = parPath.begin();
boost::string_ref::const_iterator next; boost::string_view::const_iterator next;
const auto end = parPath.end(); const auto end = parPath.end();
const auto beg = parPath.begin(); const auto beg = parPath.begin();
while (end != (next = std::find(from, end, '/'))) { while (end != (next = std::find(from, end, '/'))) {
@ -111,7 +111,7 @@ namespace mchlib {
} }
} //unnamed namespace } //unnamed namespace
PathName::PathName (boost::string_ref parPath) { PathName::PathName (boost::string_view parPath) {
if (not parPath.empty()) { if (not parPath.empty()) {
m_absolute = ('/' == parPath.front()); m_absolute = ('/' == parPath.front());
std::string path(parPath.begin(), parPath.end()); std::string path(parPath.begin(), parPath.end());
@ -120,7 +120,7 @@ namespace mchlib {
const std::size_t trailing = (path.back() == '/' ? 1 : 0); const std::size_t trailing = (path.back() == '/' ? 1 : 0);
const std::size_t absolute = (m_absolute ? 1 : 0); const std::size_t absolute = (m_absolute ? 1 : 0);
const auto res = count + 1 - trailing - absolute; const auto res = count + 1 - trailing - absolute;
std::vector<boost::string_ref> atoms; std::vector<boost::string_view> atoms;
atoms.reserve(res); atoms.reserve(res);
split_path(&atoms, path); split_path(&atoms, path);
m_pool.insert(atoms, &path); m_pool.insert(atoms, &path);
@ -139,7 +139,7 @@ namespace mchlib {
m_pool.update(parOther.m_pool); m_pool.update(parOther.m_pool);
} }
const boost::string_ref PathName::operator[] (std::size_t parIndex) const { const boost::string_view PathName::operator[] (std::size_t parIndex) const {
return *(m_pool.begin() + parIndex); return *(m_pool.begin() + parIndex);
} }
@ -149,11 +149,11 @@ namespace mchlib {
void PathName::join (const char* parOther) { void PathName::join (const char* parOther) {
const std::string src(parOther); const std::string src(parOther);
const boost::string_ref ref(src); const boost::string_view ref(src);
m_pool.insert(ref, &src); m_pool.insert(ref, &src);
} }
void PathName::join (boost::string_ref parOther, const std::string* parSource) { void PathName::join (boost::string_view parOther, const std::string* parSource) {
m_pool.insert(parOther, parSource); m_pool.insert(parOther, parSource);
} }
@ -204,11 +204,11 @@ namespace mchlib {
return parStream; return parStream;
} }
const boost::string_ref basename (const PathName& parPath) { const boost::string_view basename (const PathName& parPath) {
static const char* const empty = ""; static const char* const empty = "";
const auto sz = parPath.atom_count(); const auto sz = parPath.atom_count();
if (not sz) { if (not sz) {
return boost::string_ref(empty); return boost::string_view(empty);
} }
assert(sz > 0); assert(sz > 0);

View file

@ -22,7 +22,7 @@
#include "kakoune/safe_ptr.hh" #include "kakoune/safe_ptr.hh"
#include <vector> #include <vector>
#include <string> #include <string>
#include <boost/utility/string_ref.hpp> #include <boost/utility/string_view.hpp>
#include <map> #include <map>
#include <iostream> #include <iostream>
@ -31,7 +31,7 @@ namespace mchlib {
public: public:
PathName ( PathName&& ) = default; PathName ( PathName&& ) = default;
PathName ( const PathName& ) = default; PathName ( const PathName& ) = default;
explicit PathName ( boost::string_ref parPath ); explicit PathName ( boost::string_view parPath );
~PathName ( void ) noexcept = default; ~PathName ( void ) noexcept = default;
PathName& operator= ( PathName&& ) = default; PathName& operator= ( PathName&& ) = default;
@ -41,10 +41,10 @@ namespace mchlib {
std::size_t str_path_size ( void ) const; std::size_t str_path_size ( void ) const;
const std::string& original_path ( void ) const { return (m_original_path ? *m_original_path : m_empty_str); } const std::string& original_path ( void ) const { return (m_original_path ? *m_original_path : m_empty_str); }
std::size_t atom_count ( void ) const; std::size_t atom_count ( void ) const;
const boost::string_ref operator[] ( std::size_t parIndex ) const; const boost::string_view operator[] ( std::size_t parIndex ) const;
void join ( const PathName& parOther ); void join ( const PathName& parOther );
void join ( const char* parOther ); void join ( const char* parOther );
void join ( boost::string_ref parOther, const std::string* parSource ); void join ( boost::string_view parOther, const std::string* parSource );
const std::string* get_stringref_source ( std::size_t parIndex ) const; const std::string* get_stringref_source ( std::size_t parIndex ) const;
std::string dirname ( void ) const; std::string dirname ( void ) const;
PathName& pop_right ( void ); PathName& pop_right ( void );
@ -61,7 +61,7 @@ namespace mchlib {
PathName make_relative_path ( const PathName& parBasePath, const PathName& parOtherPath ); PathName make_relative_path ( const PathName& parBasePath, const PathName& parOtherPath );
std::ostream& operator<< ( std::ostream& parStream, const PathName& parPath ); std::ostream& operator<< ( std::ostream& parStream, const PathName& parPath );
const boost::string_ref basename ( const PathName& parPath ); const boost::string_view basename ( const PathName& parPath );
} //namespace mchlib } //namespace mchlib
#endif #endif

View file

@ -19,7 +19,7 @@
#define id9CF5E6FA7E334DF09559C2968C494CB9 #define id9CF5E6FA7E334DF09559C2968C494CB9
#include <string> #include <string>
#include <boost/utility/string_ref.hpp> #include <boost/utility/string_view.hpp>
#include <vector> #include <vector>
#include <utility> #include <utility>
#include <ciso646> #include <ciso646>
@ -29,7 +29,7 @@
#include <boost/iterator/transform_iterator.hpp> #include <boost/iterator/transform_iterator.hpp>
namespace mchlib { namespace mchlib {
template <typename C, typename Str=std::basic_string<C>, typename StrRef=boost::basic_string_ref<C>> template <typename C, typename Str=std::basic_string<C>, typename StrRef=boost::basic_string_view<C>>
class StringPool { class StringPool {
typedef std::pair<StrRef, const Str*> StringListPair; typedef std::pair<StrRef, const Str*> StringListPair;
typedef std::vector<std::pair<Str, std::size_t>> PoolType; typedef std::vector<std::pair<Str, std::size_t>> PoolType;

View file

@ -19,7 +19,7 @@
#include "submit_paste_response.hpp" #include "submit_paste_response.hpp"
#include <boost/optional.hpp> #include <boost/optional.hpp>
#include <boost/utility/string_ref.hpp> #include <boost/utility/string_view.hpp>
#include <cassert> #include <cassert>
namespace tawashi { namespace tawashi {
@ -32,7 +32,7 @@ namespace tawashi {
); );
protected: protected:
virtual boost::string_ref page_basename() const override { assert(false); return boost::string_ref(""); } virtual boost::string_view page_basename() const override { assert(false); return boost::string_view(""); }
virtual HttpHeader make_success_response (std::string&& parPastieParam) override; virtual HttpHeader make_success_response (std::string&& parPastieParam) override;
private: private:

View file

@ -47,7 +47,7 @@ namespace tawashi {
// return path.substr(start_index, substr_len); // return path.substr(start_index, substr_len);
//} //}
std::string to_string (const boost::string_ref& parStr) { std::string to_string (const boost::string_view& parStr) {
return std::string(parStr.data(), parStr.size()); return std::string(parStr.data(), parStr.size());
} }
@ -61,7 +61,7 @@ namespace tawashi {
} }
} }
boost::optional<std::string> load_whole_file (const std::string& parWebsiteRoot, const char* parSuffix, const boost::string_ref& parName, bool parThrow) { boost::optional<std::string> load_whole_file (const std::string& parWebsiteRoot, const char* parSuffix, const boost::string_view& parName, bool parThrow) {
std::ostringstream oss; std::ostringstream oss;
oss << parWebsiteRoot << parName << parSuffix; oss << parWebsiteRoot << parName << parSuffix;
spdlog::get("statuslog")->info("Trying to load \"{}\"", oss.str()); spdlog::get("statuslog")->info("Trying to load \"{}\"", oss.str());
@ -93,8 +93,8 @@ namespace tawashi {
return parStr; return parStr;
}; };
boost::string_ref make_host_path (const SettingsBag& parSettings) { boost::string_view make_host_path (const SettingsBag& parSettings) {
boost::string_ref host_path = parSettings.at("host_path"); boost::string_view host_path = parSettings.at("host_path");
if (not host_path.empty() and host_path[host_path.size() - 1] == '/') if (not host_path.empty() and host_path[host_path.size() - 1] == '/')
host_path = host_path.substr(0, host_path.size() - 1); host_path = host_path.substr(0, host_path.size() - 1);
return host_path; return host_path;
@ -110,7 +110,7 @@ namespace tawashi {
else else
oss << "http://"; oss << "http://";
oss << parSettings->at("host_name"); oss << parSettings->at("host_name");
boost::string_ref host_port = parSettings->at("host_port"); boost::string_view host_port = parSettings->at("host_port");
if (not host_port.empty()) { if (not host_port.empty()) {
if (host_port == "from_downstream") { if (host_port == "from_downstream") {
const uint16_t port = parCgiEnv->server_port(); const uint16_t port = parCgiEnv->server_port();

View file

@ -25,7 +25,7 @@
#include "cgi_post.hpp" #include "cgi_post.hpp"
#include <string> #include <string>
#include <iostream> #include <iostream>
#include <boost/utility/string_ref.hpp> #include <boost/utility/string_view.hpp>
#include <memory> #include <memory>
namespace tawashi { namespace tawashi {
@ -53,7 +53,7 @@ namespace tawashi {
tawashi_virtual_testing cgi::PostMapType cgi_post() const; tawashi_virtual_testing cgi::PostMapType cgi_post() const;
const std::string& base_uri() const; const std::string& base_uri() const;
virtual boost::string_ref page_basename() const = 0; virtual boost::string_view page_basename() const = 0;
tawashi_virtual_testing const Storage& storage() const; tawashi_virtual_testing const Storage& storage() const;
const SettingsBag& settings() const; const SettingsBag& settings() const;
virtual std::string load_mustache() const; virtual std::string load_mustache() const;

View file

@ -46,7 +46,7 @@ namespace tawashi {
ResponseFactory::~ResponseFactory() noexcept = default; ResponseFactory::~ResponseFactory() noexcept = default;
std::unique_ptr<Response> ResponseFactory::make_response (const boost::string_ref& parName, RequestMethodType parReqType) { std::unique_ptr<Response> ResponseFactory::make_response (const boost::string_view& parName, RequestMethodType parReqType) {
std::string name(parName.data(), parName.size()); std::string name(parName.data(), parName.size());
spdlog::get("statuslog")->info( spdlog::get("statuslog")->info(
"making response object for \"{}\" method {}", "making response object for \"{}\" method {}",

View file

@ -36,7 +36,7 @@ namespace tawashi {
explicit ResponseFactory (const Kakoune::SafePtr<SettingsBag>& parSettings, const Kakoune::SafePtr<cgi::Env>& parCgiEnv); explicit ResponseFactory (const Kakoune::SafePtr<SettingsBag>& parSettings, const Kakoune::SafePtr<cgi::Env>& parCgiEnv);
~ResponseFactory() noexcept; ~ResponseFactory() noexcept;
std::unique_ptr<Response> make_response(const boost::string_ref& parName, RequestMethodType parReqType); std::unique_ptr<Response> make_response(const boost::string_view& parName, RequestMethodType parReqType);
void register_maker (std::string&& parName, ResponseMakerFunc parMaker); void register_maker (std::string&& parName, ResponseMakerFunc parMaker);
void register_maker (std::string&& parName, RequestMethodType parReqType, ResponseMakerFunc parMaker); void register_maker (std::string&& parName, RequestMethodType parReqType, ResponseMakerFunc parMaker);
void register_jolly_maker (ResponseMakerFunc parMaker, RequestMethodType parReqType); void register_jolly_maker (ResponseMakerFunc parMaker, RequestMethodType parReqType);

View file

@ -30,7 +30,7 @@
#endif #endif
namespace tawashi { namespace tawashi {
std::string sanitized_utf8 (const boost::string_ref& parStr) { std::string sanitized_utf8 (const boost::string_view& parStr) {
std::string sanitized; std::string sanitized;
sanitized.reserve(parStr.size()); sanitized.reserve(parStr.size());
#if defined(SANITIZE_WITH_UTFCPP) #if defined(SANITIZE_WITH_UTFCPP)

View file

@ -17,9 +17,9 @@
#pragma once #pragma once
#include <boost/utility/string_ref.hpp> #include <boost/utility/string_view.hpp>
#include <string> #include <string>
namespace tawashi { namespace tawashi {
std::string sanitized_utf8 (const boost::string_ref& parStr); std::string sanitized_utf8 (const boost::string_view& parStr);
} //namespace tawashi } //namespace tawashi

View file

@ -25,7 +25,7 @@
namespace tawashi { namespace tawashi {
namespace { namespace {
const IniFile::KeyValueMapType* get_tawashi_node (const IniFile& parIni, boost::string_ref parSectionName) { const IniFile::KeyValueMapType* get_tawashi_node (const IniFile& parIni, boost::string_view parSectionName) {
auto it_found = parIni.parsed().find(parSectionName); auto it_found = parIni.parsed().find(parSectionName);
if (parIni.parsed().end() != it_found) { if (parIni.parsed().end() != it_found) {
return &it_found->second; return &it_found->second;
@ -38,7 +38,7 @@ namespace tawashi {
} }
} //unnamed namespace } //unnamed namespace
SettingsBag::SettingsBag (const Kakoune::SafePtr<IniFile>& parIni, boost::string_ref parSectionName) : SettingsBag::SettingsBag (const Kakoune::SafePtr<IniFile>& parIni, boost::string_view parSectionName) :
m_ini(parIni), m_ini(parIni),
m_values(get_tawashi_node(*parIni, parSectionName)) m_values(get_tawashi_node(*parIni, parSectionName))
{ {
@ -47,7 +47,7 @@ namespace tawashi {
SettingsBag::~SettingsBag() noexcept = default; SettingsBag::~SettingsBag() noexcept = default;
const boost::string_ref& SettingsBag::operator[] (boost::string_ref parIndex) const { const boost::string_view& SettingsBag::operator[] (boost::string_view parIndex) const {
auto it_found = m_values->find(parIndex); auto it_found = m_values->find(parIndex);
if (m_values->end() != it_found) if (m_values->end() != it_found)
return it_found->second; return it_found->second;
@ -55,19 +55,19 @@ namespace tawashi {
return m_defaults.at(parIndex); return m_defaults.at(parIndex);
} }
void SettingsBag::add_default (boost::string_ref parKey, boost::string_ref parValue) { void SettingsBag::add_default (boost::string_view parKey, boost::string_view parValue) {
assert(m_defaults.find(parKey) == m_defaults.end()); assert(m_defaults.find(parKey) == m_defaults.end());
m_defaults[parKey] = parValue; m_defaults[parKey] = parValue;
} }
template <> template <>
std::string SettingsBag::as (boost::string_ref parIndex) const { std::string SettingsBag::as (boost::string_view parIndex) const {
auto& setting = this->at(parIndex); auto& setting = this->at(parIndex);
return std::string(setting.data(), setting.size()); return std::string(setting.data(), setting.size());
} }
template <> template <>
bool SettingsBag::as (boost::string_ref parIndex) const { bool SettingsBag::as (boost::string_view parIndex) const {
auto& setting = this->at(parIndex); auto& setting = this->at(parIndex);
if (setting == "true" or setting == "yes" or setting == "1" or setting == "on") { if (setting == "true" or setting == "yes" or setting == "1" or setting == "on") {
return true; return true;
@ -83,17 +83,17 @@ namespace tawashi {
} }
template <> template <>
uint16_t SettingsBag::as (boost::string_ref parIndex) const { uint16_t SettingsBag::as (boost::string_view parIndex) const {
return dhandy::lexical_cast<uint16_t>(this->at(parIndex)); return dhandy::lexical_cast<uint16_t>(this->at(parIndex));
} }
template <> template <>
uint32_t SettingsBag::as (boost::string_ref parIndex) const { uint32_t SettingsBag::as (boost::string_view parIndex) const {
return dhandy::lexical_cast<uint32_t>(this->at(parIndex)); return dhandy::lexical_cast<uint32_t>(this->at(parIndex));
} }
template std::string SettingsBag::as<std::string> (boost::string_ref parIndex) const; template std::string SettingsBag::as<std::string> (boost::string_view parIndex) const;
template bool SettingsBag::as<bool> (boost::string_ref parIndex) const; template bool SettingsBag::as<bool> (boost::string_view parIndex) const;
template uint16_t SettingsBag::as<uint16_t> (boost::string_ref parIndex) const; template uint16_t SettingsBag::as<uint16_t> (boost::string_view parIndex) const;
template uint32_t SettingsBag::as<uint32_t> (boost::string_ref parIndex) const; template uint32_t SettingsBag::as<uint32_t> (boost::string_view parIndex) const;
} //namespace tawashi } //namespace tawashi

View file

@ -20,7 +20,7 @@
#include "ini_file.hpp" #include "ini_file.hpp"
#include "kakoune/safe_ptr.hh" #include "kakoune/safe_ptr.hh"
#include <map> #include <map>
#include <boost/utility/string_ref.hpp> #include <boost/utility/string_view.hpp>
#include <functional> #include <functional>
#include <string> #include <string>
#if defined(SPDLOG_DEBUG_ON) #if defined(SPDLOG_DEBUG_ON)
@ -29,15 +29,15 @@
namespace tawashi { namespace tawashi {
class SettingsBag : public Kakoune::SafeCountable { class SettingsBag : public Kakoune::SafeCountable {
typedef std::map<boost::string_ref, boost::string_ref> MapType; typedef std::map<boost::string_view, boost::string_view> MapType;
public: public:
SettingsBag (const Kakoune::SafePtr<IniFile>& parIni, boost::string_ref parSectionName); SettingsBag (const Kakoune::SafePtr<IniFile>& parIni, boost::string_view parSectionName);
~SettingsBag() noexcept; ~SettingsBag() noexcept;
const boost::string_ref& operator[] (boost::string_ref parIndex) const; const boost::string_view& operator[] (boost::string_view parIndex) const;
const boost::string_ref& at (boost::string_ref parIndex) const; const boost::string_view& at (boost::string_view parIndex) const;
template <typename T> T as (boost::string_ref parIndex) const; template <typename T> T as (boost::string_view parIndex) const;
void add_default (boost::string_ref parKey, boost::string_ref parValue); void add_default (boost::string_view parKey, boost::string_view parValue);
private: private:
MapType m_defaults; MapType m_defaults;
@ -46,11 +46,11 @@ namespace tawashi {
}; };
template <> template <>
inline boost::string_ref SettingsBag::as (boost::string_ref parIndex) const { inline boost::string_view SettingsBag::as (boost::string_view parIndex) const {
return (*this)[parIndex]; return (*this)[parIndex];
} }
inline const boost::string_ref& SettingsBag::at (boost::string_ref parIndex) const { inline const boost::string_view& SettingsBag::at (boost::string_view parIndex) const {
#if defined(SPDLOG_DEBUG_ON) #if defined(SPDLOG_DEBUG_ON)
SPDLOG_DEBUG(spdlog::get("statuslog"), "Retrieving setting \"{}\"", std::string(parIndex.data(), parIndex.size())); SPDLOG_DEBUG(spdlog::get("statuslog"), "Retrieving setting \"{}\"", std::string(parIndex.data(), parIndex.size()));
#endif #endif

View file

@ -18,11 +18,11 @@
#pragma once #pragma once
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>
#include <boost/utility/string_ref.hpp> #include <boost/utility/string_view.hpp>
namespace spdlog { namespace spdlog {
template <typename OStream> template <typename OStream>
inline OStream& operator<< (OStream& parOS, const boost::string_ref& parStr) { inline OStream& operator<< (OStream& parOS, const boost::string_view& parStr) {
return parOS << parStr; return parOS << parStr;
} }
} //namespace spdlog } //namespace spdlog

View file

@ -17,7 +17,7 @@
#include "split_get_vars.hpp" #include "split_get_vars.hpp"
#include <boost/algorithm/string/finder.hpp> #include <boost/algorithm/string/finder.hpp>
#include <boost/utility/string_ref.hpp> #include <boost/utility/string_view.hpp>
#include <boost/range/adaptor/transformed.hpp> #include <boost/range/adaptor/transformed.hpp>
#include <boost/range/adaptor/filtered.hpp> #include <boost/range/adaptor/filtered.hpp>
#include <ciso646> #include <ciso646>
@ -31,7 +31,7 @@ namespace tawashi {
using boost::token_finder; using boost::token_finder;
using boost::adaptors::transformed; using boost::adaptors::transformed;
using boost::adaptors::filtered; using boost::adaptors::filtered;
using boost::string_ref; using boost::string_view;
using boost::split_iterator; using boost::split_iterator;
using boost::make_iterator_range; using boost::make_iterator_range;
using boost::range::find; using boost::range::find;
@ -49,11 +49,11 @@ namespace tawashi {
transformed([](const MatchRange& r){ transformed([](const MatchRange& r){
auto eq = find(r, '='); auto eq = find(r, '=');
if (r.empty()) if (r.empty())
return std::pair<string_ref, string_ref>(); return std::pair<string_view, string_view>();
if (r.end() == eq) if (r.end() == eq)
return std::make_pair(string_ref(&*r.begin(), r.size()), string_ref()); return std::make_pair(string_view(&*r.begin(), r.size()), string_view());
else else
return std::make_pair(string_ref(&*r.begin(), eq - r.begin()), string_ref(&*(eq + 1), r.size() - (eq - r.begin() + 1))); return std::make_pair(string_view(&*r.begin(), eq - r.begin()), string_view(&*(eq + 1), r.size() - (eq - r.begin() + 1)));
}) })
); );
} }

View file

@ -18,12 +18,12 @@
#pragma once #pragma once
#include "duckhandy/compatibility.h" #include "duckhandy/compatibility.h"
#include <boost/utility/string_ref.hpp> #include <boost/utility/string_view.hpp>
#include <vector> #include <vector>
#include <utility> #include <utility>
namespace tawashi { namespace tawashi {
typedef std::vector<std::pair<boost::string_ref, boost::string_ref>> RawKeyValueList; typedef std::vector<std::pair<boost::string_view, boost::string_view>> RawKeyValueList;
RawKeyValueList split_env_vars ( const std::string& parCommaSeparatedList ) a_pure; RawKeyValueList split_env_vars ( const std::string& parCommaSeparatedList ) a_pure;
} //namespace tawashi } //namespace tawashi

View file

@ -89,9 +89,9 @@ namespace tawashi {
} }
Storage::SubmissionResult Storage::submit_pastie ( Storage::SubmissionResult Storage::submit_pastie (
const boost::string_ref& parText, const boost::string_view& parText,
uint32_t parExpiry, uint32_t parExpiry,
const boost::string_ref& parLang, const boost::string_view& parLang,
const std::string& parRemoteIP const std::string& parRemoteIP
) const { ) const {
if (not is_connected()) if (not is_connected())
@ -121,7 +121,7 @@ namespace tawashi {
return make_submission_result(ErrorReasons::PastieNotSaved); return make_submission_result(ErrorReasons::PastieNotSaved);
} }
boost::optional<std::string> Storage::retrieve_pastie (const boost::string_ref& parToken) const { boost::optional<std::string> Storage::retrieve_pastie (const boost::string_view& parToken) const {
using opt_string = redis::IncRedis::opt_string; using opt_string = redis::IncRedis::opt_string;
using opt_string_list = redis::IncRedis::opt_string_list; using opt_string_list = redis::IncRedis::opt_string_list;

View file

@ -21,7 +21,7 @@
#include "error_reasons.hpp" #include "error_reasons.hpp"
#include <memory> #include <memory>
#include <cstdint> #include <cstdint>
#include <boost/utility/string_ref.hpp> #include <boost/utility/string_view.hpp>
#include <boost/optional.hpp> #include <boost/optional.hpp>
#include <string> #include <string>
@ -46,13 +46,13 @@ namespace tawashi {
tawashi_virtual_testing bool is_connected() const; tawashi_virtual_testing bool is_connected() const;
tawashi_virtual_testing void finalize_connection(); tawashi_virtual_testing void finalize_connection();
tawashi_virtual_testing SubmissionResult submit_pastie ( tawashi_virtual_testing SubmissionResult submit_pastie (
const boost::string_ref& parText, const boost::string_view& parText,
uint32_t parExpiry, uint32_t parExpiry,
const boost::string_ref& parLang, const boost::string_view& parLang,
const std::string& parRemoteIP const std::string& parRemoteIP
) const; ) const;
tawashi_virtual_testing boost::optional<std::string> retrieve_pastie (const boost::string_ref& parToken) const; tawashi_virtual_testing boost::optional<std::string> retrieve_pastie (const boost::string_view& parToken) const;
#if defined(TAWASHI_WITH_TESTING) #if defined(TAWASHI_WITH_TESTING)
const SettingsBag& settings() const; const SettingsBag& settings() const;

View file

@ -37,7 +37,7 @@ namespace tawashi {
class MissingPostVarError : public TawashiException { class MissingPostVarError : public TawashiException {
public: public:
explicit MissingPostVarError(const boost::string_ref& parKey) : explicit MissingPostVarError(const boost::string_view& parKey) :
TawashiException( TawashiException(
ErrorReasons::MissingPostVariable, ErrorReasons::MissingPostVariable,
"Error retrieving POST variable \"" + std::string(parKey.begin(), parKey.end()) + "\"" "Error retrieving POST variable \"" + std::string(parKey.begin(), parKey.end()) + "\""
@ -46,15 +46,15 @@ namespace tawashi {
}; };
template <std::size_t N> template <std::size_t N>
inline boost::string_ref make_string_ref (const char (&parStr)[N]) a_always_inline; inline boost::string_view make_string_view (const char (&parStr)[N]) a_always_inline;
template <std::size_t N> template <std::size_t N>
boost::string_ref make_string_ref (const char (&parStr)[N]) { boost::string_view make_string_view (const char (&parStr)[N]) {
static_assert(N > 0, "wat?"); static_assert(N > 0, "wat?");
return boost::string_ref(parStr, N - 1); return boost::string_view(parStr, N - 1);
} }
boost::string_ref get_value_from_post (const cgi::PostMapType& parPost, boost::string_ref parKey) { boost::string_view get_value_from_post (const cgi::PostMapType& parPost, boost::string_view parKey) {
std::string key(parKey.data(), parKey.size()); std::string key(parKey.data(), parKey.size());
auto post_data_it = parPost.find(key); auto post_data_it = parPost.find(key);
if (parPost.end() == post_data_it) if (parPost.end() == post_data_it)
@ -62,13 +62,13 @@ namespace tawashi {
return post_data_it->second; return post_data_it->second;
} }
boost::string_ref get_value_from_post_log_failure (const cgi::PostMapType& parPost, boost::string_ref parKey) { boost::string_view get_value_from_post_log_failure (const cgi::PostMapType& parPost, boost::string_view parKey) {
try { try {
return get_value_from_post(parPost, parKey); return get_value_from_post(parPost, parKey);
} }
catch (const MissingPostVarError& e) { catch (const MissingPostVarError& e) {
spdlog::get("statuslog")->info(e.what()); spdlog::get("statuslog")->info(e.what());
return boost::string_ref(); return boost::string_view();
} }
} }
} //unnamed namespace } //unnamed namespace
@ -95,9 +95,9 @@ namespace tawashi {
} }
HttpHeader SubmitPasteResponse::on_process() { HttpHeader SubmitPasteResponse::on_process() {
boost::string_ref pastie; boost::string_view pastie;
boost::string_ref lang; boost::string_view lang;
boost::string_ref duration; boost::string_view duration;
auto statuslog = spdlog::get("statuslog"); auto statuslog = spdlog::get("statuslog");
assert(statuslog); assert(statuslog);
@ -105,9 +105,9 @@ namespace tawashi {
const SettingsBag& settings = this->settings(); const SettingsBag& settings = this->settings();
try { try {
auto post = this->cgi_post(); auto post = this->cgi_post();
pastie = get_value_from_post(post, make_string_ref(g_post_key)); pastie = get_value_from_post(post, make_string_view(g_post_key));
lang = get_value_from_post_log_failure(post, make_string_ref(g_language_key)); lang = get_value_from_post_log_failure(post, make_string_view(g_language_key));
duration = get_value_from_post_log_failure(post, make_string_ref(g_duration_key)); duration = get_value_from_post_log_failure(post, make_string_view(g_duration_key));
} }
catch (const UnsupportedContentTypeException& err) { catch (const UnsupportedContentTypeException& err) {
statuslog->info( statuslog->info(
@ -158,9 +158,9 @@ namespace tawashi {
} }
auto SubmitPasteResponse::submit_to_storage ( auto SubmitPasteResponse::submit_to_storage (
const boost::string_ref& parText, const boost::string_view& parText,
uint32_t parExpiry, uint32_t parExpiry,
const boost::string_ref& parLang const boost::string_view& parLang
) -> StringOrHeader { ) -> StringOrHeader {
auto& storage = this->storage(); auto& storage = this->storage();
std::string remote_ip = guess_real_remote_ip(cgi_env()); std::string remote_ip = guess_real_remote_ip(cgi_env());

View file

@ -20,7 +20,7 @@
#include "response.hpp" #include "response.hpp"
#include <string> #include <string>
#include <boost/optional.hpp> #include <boost/optional.hpp>
#include <boost/utility/string_ref.hpp> #include <boost/utility/string_view.hpp>
#include <cassert> #include <cassert>
#include <utility> #include <utility>
@ -43,13 +43,13 @@ namespace tawashi {
); );
protected: protected:
virtual boost::string_ref page_basename() const override { assert(false); return boost::string_ref(""); } virtual boost::string_view page_basename() const override { assert(false); return boost::string_view(""); }
virtual HttpHeader make_success_response (std::string&& parPastieParam); virtual HttpHeader make_success_response (std::string&& parPastieParam);
private: private:
typedef std::pair<boost::optional<std::string>, HttpHeader> StringOrHeader; typedef std::pair<boost::optional<std::string>, HttpHeader> StringOrHeader;
virtual HttpHeader on_process() override; virtual HttpHeader on_process() override;
StringOrHeader submit_to_storage (const boost::string_ref& parText, uint32_t parExpiry, const boost::string_ref& parLang); StringOrHeader submit_to_storage (const boost::string_view& parText, uint32_t parExpiry, const boost::string_view& parLang);
}; };
} //namespace tawashi } //namespace tawashi

View file

@ -20,14 +20,14 @@
namespace tawashi { namespace tawashi {
namespace { namespace {
std::string compose_err_message (ErrorReasons parReason, const boost::string_ref& parMessage) { std::string compose_err_message (ErrorReasons parReason, const boost::string_view& parMessage) {
std::ostringstream oss; std::ostringstream oss;
oss << "Exception with reason " << parReason << ": " << parMessage; oss << "Exception with reason " << parReason << ": " << parMessage;
return oss.str(); return oss.str();
} }
} //unnamed namespace } //unnamed namespace
TawashiException::TawashiException (ErrorReasons parReason, const boost::string_ref& parMessage) : TawashiException::TawashiException (ErrorReasons parReason, const boost::string_view& parMessage) :
std::runtime_error(compose_err_message(parReason, parMessage)), std::runtime_error(compose_err_message(parReason, parMessage)),
m_reason(parReason) m_reason(parReason)
{ {

View file

@ -19,12 +19,12 @@
#include "error_reasons.hpp" #include "error_reasons.hpp"
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>
#include <boost/utility/string_ref.hpp> #include <boost/utility/string_view.hpp>
namespace tawashi { namespace tawashi {
class TawashiException : public std::runtime_error { class TawashiException : public std::runtime_error {
public: public:
TawashiException (ErrorReasons parReason, const boost::string_ref& parMessage); TawashiException (ErrorReasons parReason, const boost::string_view& parMessage);
~TawashiException() noexcept; ~TawashiException() noexcept;
ErrorReasons reason() const { return m_reason; } ErrorReasons reason() const { return m_reason; }