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:
parent
df1afc7616
commit
6e19745d69
39 changed files with 168 additions and 167 deletions
|
@ -1 +1 @@
|
|||
Subproject commit fbd39c27991a3f7335f0f606f7e047bff31fa288
|
||||
Subproject commit 045675c8084fce265330686ab29dc6009b84e341
|
|
@ -118,8 +118,8 @@ namespace {
|
|||
//Prepare the logger
|
||||
spdlog::set_pattern("[%Y-%m-%d %T %z] - %v");
|
||||
spdlog::set_level(spdlog::level::trace); //set to maximum possible here
|
||||
boost::string_ref log_path = parSettings["log_file"];
|
||||
const bool log_to_stderr = (log_path == boost::string_ref("-"));
|
||||
boost::string_view log_path = parSettings["log_file"];
|
||||
const bool log_to_stderr = (log_path == "-");
|
||||
auto statuslog = (log_to_stderr ?
|
||||
spdlog::stderr_logger_st("statuslog") :
|
||||
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::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();
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
|
||||
BOOST_FUSION_ADAPT_STRUCT(
|
||||
tawashi::cgi::Env::VersionInfo,
|
||||
(boost::string_ref, name)
|
||||
(boost::string_view, name)
|
||||
(uint16_t, major)
|
||||
(uint16_t, minor)
|
||||
);
|
||||
|
@ -50,9 +50,9 @@ namespace cgi {
|
|||
using boost::spirit::ascii::space;
|
||||
using boost::spirit::qi::raw;
|
||||
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 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::qi::_val;
|
||||
using boost::phoenix::begin;
|
||||
|
@ -64,7 +64,7 @@ namespace cgi {
|
|||
assert(not parString.empty());
|
||||
|
||||
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;
|
||||
|
||||
auto it_curr = parString.cbegin();
|
||||
|
@ -83,9 +83,9 @@ namespace cgi {
|
|||
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);
|
||||
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={}",
|
||||
std::string(parPath.begin(), parPath.end()),
|
||||
std::string(base_path.begin(), base_path.end()),
|
||||
|
@ -110,7 +110,7 @@ namespace cgi {
|
|||
}
|
||||
} //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_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()))
|
||||
|
@ -124,7 +124,7 @@ namespace cgi {
|
|||
std::string err_msg = "Parsing failed at position " +
|
||||
std::to_string(parsed_chars) + " for input \"" +
|
||||
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;
|
||||
}
|
||||
|
||||
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];
|
||||
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];
|
||||
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 tawashi
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
#include "mime_split.hpp"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <boost/utility/string_ref.hpp>
|
||||
#include <boost/utility/string_view.hpp>
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <boost/optional.hpp>
|
||||
|
@ -36,14 +36,14 @@ namespace tawashi {
|
|||
class Env : public Kakoune::SafeCountable {
|
||||
public:
|
||||
struct VersionInfo {
|
||||
boost::string_ref name;
|
||||
boost::string_view name;
|
||||
uint16_t major;
|
||||
uint16_t minor;
|
||||
};
|
||||
|
||||
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;
|
||||
|
||||
const std::string& auth_type() const;
|
||||
|
@ -70,8 +70,8 @@ namespace tawashi {
|
|||
|
||||
GetMapType query_string_split() const a_pure;
|
||||
const SplitMime& content_type_split() const a_pure;
|
||||
boost::string_ref request_uri_relative() const;
|
||||
boost::string_ref path_info_relative() const;
|
||||
boost::string_view request_uri_relative() const;
|
||||
boost::string_view path_info_relative() const;
|
||||
|
||||
std::ostream& print_all (std::ostream& parStream, const char* parNewline) const;
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#include "string_lengths.hpp"
|
||||
#include <utility>
|
||||
#include <unordered_map>
|
||||
#include <boost/utility/string_ref.hpp>
|
||||
#include <boost/utility/string_view.hpp>
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
#include <boost/functional/hash.hpp>
|
||||
|
@ -31,8 +31,8 @@
|
|||
|
||||
namespace std {
|
||||
template<>
|
||||
struct hash<boost::string_ref> {
|
||||
std::size_t operator() (const boost::string_ref& parStr) const {
|
||||
struct hash<boost::string_view> {
|
||||
std::size_t operator() (const boost::string_view& parStr) const {
|
||||
return boost::hash_range(parStr.begin(), parStr.end());
|
||||
}
|
||||
};
|
||||
|
@ -40,8 +40,8 @@ namespace std {
|
|||
|
||||
namespace tawashi {
|
||||
namespace {
|
||||
std::unordered_map<boost::string_ref, boost::string_ref> get_unrefined_env_vars (const char* const* parEnvList) {
|
||||
using boost::string_ref;
|
||||
std::unordered_map<boost::string_view, boost::string_view> get_unrefined_env_vars (const char* const* parEnvList) {
|
||||
using boost::string_view;
|
||||
|
||||
assert(parEnvList);
|
||||
std::size_t count = 0;
|
||||
|
@ -49,7 +49,7 @@ namespace tawashi {
|
|||
++count;
|
||||
}
|
||||
|
||||
std::unordered_map<string_ref, string_ref> retval;
|
||||
std::unordered_map<string_view, string_view> retval;
|
||||
retval.reserve(count);
|
||||
for (std::size_t z = 0; z < count; ++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;
|
||||
assert(std::strlen(parEnvList[z]) == whole_length);
|
||||
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;
|
||||
}
|
||||
} //unnamed namespace
|
||||
|
||||
std::vector<std::string> cgi_environment_vars (const char* const* parEnvList) {
|
||||
using boost::string_ref;
|
||||
using boost::string_view;
|
||||
|
||||
std::vector<std::string> retlist;
|
||||
retlist.reserve(CGIVars::_size());
|
||||
|
@ -79,7 +79,7 @@ namespace tawashi {
|
|||
#if !defined(NDEBUG)
|
||||
assert(std::strlen(var._to_string()) == enum_str_lengths[z]);
|
||||
#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)
|
||||
retlist.push_back(sanitized_utf8(it_found->second));
|
||||
else
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
#include <ciso646>
|
||||
|
||||
namespace tawashi {
|
||||
UnsupportedContentTypeException::UnsupportedContentTypeException (const boost::string_ref& parMessage) :
|
||||
UnsupportedContentTypeException::UnsupportedContentTypeException (const boost::string_view& parMessage) :
|
||||
TawashiException(ErrorReasons::UnsupportedContentType, parMessage)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
namespace tawashi {
|
||||
class UnsupportedContentTypeException : public TawashiException {
|
||||
public:
|
||||
explicit UnsupportedContentTypeException (const boost::string_ref& parMessage);
|
||||
explicit UnsupportedContentTypeException (const boost::string_view& parMessage);
|
||||
};
|
||||
|
||||
namespace cgi {
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "response.hpp"
|
||||
#include <boost/utility/string_ref.hpp>
|
||||
#include <boost/utility/string_view.hpp>
|
||||
|
||||
namespace tawashi {
|
||||
class ErrorResponse : public Response {
|
||||
|
@ -30,7 +30,7 @@ namespace tawashi {
|
|||
);
|
||||
|
||||
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:
|
||||
virtual void on_mustache_prepare (mstch::map& parContext) override;
|
||||
|
|
|
@ -35,7 +35,7 @@ namespace tawashi {
|
|||
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())
|
||||
return std::string();
|
||||
|
||||
|
@ -53,7 +53,7 @@ namespace tawashi {
|
|||
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())
|
||||
return std::string();
|
||||
|
||||
|
@ -71,7 +71,7 @@ namespace tawashi {
|
|||
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())
|
||||
return std::string();
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <boost/utility/string_ref.hpp>
|
||||
#include <boost/utility/string_view.hpp>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
|
@ -36,9 +36,9 @@ namespace tawashi {
|
|||
Escapist();
|
||||
~Escapist() noexcept;
|
||||
|
||||
std::string unescape_url (const boost::string_ref& parURL) const;
|
||||
std::string escape_url (const boost::string_ref& parURL) const;
|
||||
std::string escape_html (const boost::string_ref& parHtml) const;
|
||||
std::string unescape_url (const boost::string_view& parURL) const;
|
||||
std::string escape_url (const boost::string_view& parURL) const;
|
||||
std::string escape_html (const boost::string_view& parHtml) const;
|
||||
|
||||
private:
|
||||
std::aligned_storage<sizeof(implem::DummyGHBuf), alignof(implem::DummyGHBuf)>::type m_gh_buf_mem;
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "response.hpp"
|
||||
#include <boost/utility/string_ref.hpp>
|
||||
#include <boost/utility/string_view.hpp>
|
||||
|
||||
namespace tawashi {
|
||||
class IndexResponse : public Response {
|
||||
|
@ -30,7 +30,7 @@ namespace tawashi {
|
|||
);
|
||||
|
||||
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:
|
||||
};
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
|
||||
namespace tawashi {
|
||||
namespace {
|
||||
typedef boost::string_ref string_type;
|
||||
typedef boost::string_view string_type;
|
||||
|
||||
template <typename Iterator, typename Skipper>
|
||||
struct IniGrammar : boost::spirit::qi::grammar<Iterator, IniFile::IniMapType(), Skipper> {
|
||||
|
@ -69,7 +69,7 @@ namespace tawashi {
|
|||
using boost::spirit::_1;
|
||||
using boost::spirit::qi::eol;
|
||||
using boost::spirit::qi::raw;
|
||||
using boost::string_ref;
|
||||
using boost::string_view;
|
||||
using boost::spirit::qi::hold;
|
||||
using boost::spirit::qi::graph;
|
||||
using boost::spirit::qi::blank;
|
||||
|
@ -77,19 +77,19 @@ namespace tawashi {
|
|||
|
||||
section = '[' >> raw[+(graph - ']') >> *(hold[+blank >> +(graph - ']')])]
|
||||
[_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::size(_1)
|
||||
)] >> ']';
|
||||
key = raw[(graph - '[' - '=') >> *(graph - '=') >> *(hold[+blank >> +(graph - '=')])][_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::size(_1)
|
||||
)];
|
||||
key_value = key[px::bind(&refpair::first, _val) = _1] >> '=' >>
|
||||
raw[*(graph - eol) >> *(hold[+blank >> +(graph - eol)])][px::bind(&refpair::second, _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::size(_1)
|
||||
)];
|
||||
key_values = -(key_value % (+eol));
|
||||
|
|
|
@ -20,15 +20,15 @@
|
|||
#include "kakoune/safe_ptr.hh"
|
||||
#include <boost/container/flat_map.hpp>
|
||||
#include <iterator>
|
||||
#include <boost/utility/string_ref.hpp>
|
||||
#include <boost/utility/string_view.hpp>
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
namespace tawashi {
|
||||
class IniFile : public Kakoune::SafeCountable {
|
||||
public:
|
||||
typedef boost::container::flat_map<boost::string_ref, boost::string_ref> KeyValueMapType;
|
||||
typedef boost::container::flat_map<boost::string_ref, KeyValueMapType> IniMapType;
|
||||
typedef boost::container::flat_map<boost::string_view, boost::string_view> KeyValueMapType;
|
||||
typedef boost::container::flat_map<boost::string_view, KeyValueMapType> IniMapType;
|
||||
|
||||
IniFile (std::istream_iterator<char> parInputFrom, std::istream_iterator<char> parInputEnd);
|
||||
explicit IniFile (std::string&& parIniData);
|
||||
|
|
|
@ -81,8 +81,8 @@
|
|||
|
||||
BOOST_FUSION_ADAPT_STRUCT(
|
||||
tawashi::SplitMime,
|
||||
(boost::string_ref, type)
|
||||
(boost::string_ref, subtype)
|
||||
(boost::string_view, type)
|
||||
(boost::string_view, subtype)
|
||||
(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> media_type;
|
||||
boost::spirit::qi::rule<Iterator, boost::string_ref(), Skipper> type;
|
||||
boost::spirit::qi::rule<Iterator, boost::string_ref(), Skipper> subtype;
|
||||
boost::spirit::qi::rule<Iterator, boost::string_view(), Skipper> type;
|
||||
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, boost::string_ref(), Skipper> attribute;
|
||||
boost::spirit::qi::rule<Iterator, boost::string_ref(), Skipper> value;
|
||||
boost::spirit::qi::rule<Iterator, boost::string_ref(), Skipper> quoted_string;
|
||||
boost::spirit::qi::rule<Iterator, boost::string_ref(), Skipper> token;
|
||||
boost::spirit::qi::rule<Iterator, boost::string_view(), Skipper> attribute;
|
||||
boost::spirit::qi::rule<Iterator, boost::string_view(), Skipper> value;
|
||||
boost::spirit::qi::rule<Iterator, boost::string_view(), Skipper> quoted_string;
|
||||
boost::spirit::qi::rule<Iterator, boost::string_view(), Skipper> token;
|
||||
const std::string* m_master_string;
|
||||
Iterator m_begin;
|
||||
};
|
||||
|
@ -119,7 +119,7 @@ namespace tawashi {
|
|||
using boost::spirit::qi::raw;
|
||||
using boost::spirit::qi::_val;
|
||||
using boost::spirit::qi::lexeme;
|
||||
using boost::string_ref;
|
||||
using boost::string_view;
|
||||
using boost::spirit::_1;
|
||||
|
||||
content_type = -media_type;
|
||||
|
@ -132,7 +132,7 @@ namespace tawashi {
|
|||
|
||||
token = raw[+(alnum | char_("_.-"))][
|
||||
_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::size(_1)
|
||||
)
|
||||
|
@ -144,7 +144,7 @@ namespace tawashi {
|
|||
'"'
|
||||
]
|
||||
][_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::size(_1) - 2
|
||||
)];
|
||||
|
@ -188,7 +188,7 @@ namespace tawashi {
|
|||
|
||||
std::string mime_to_string (const SplitMime& parMime, bool& parWriteOk) {
|
||||
namespace px = boost::phoenix;
|
||||
using boost::string_ref;
|
||||
using boost::string_view;
|
||||
using boost::spirit::karma::generate;
|
||||
using boost::spirit::karma::char_;
|
||||
using boost::spirit::karma::string;
|
||||
|
@ -205,9 +205,9 @@ namespace tawashi {
|
|||
px::function<simple_token_checker> is_simple_token;
|
||||
std::string 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_ref()> quoted_string;
|
||||
rule<std::back_insert_iterator<std::string>, string_ref()> param_value;
|
||||
rule<std::back_insert_iterator<std::string>, string_view()> token;
|
||||
rule<std::back_insert_iterator<std::string>, string_view()> quoted_string;
|
||||
rule<std::back_insert_iterator<std::string>, string_view()> param_value;
|
||||
|
||||
token %= eps(is_simple_token(_val)) << *(alnum | char_("._-"));
|
||||
quoted_string %= '"' << string << '"';
|
||||
|
|
|
@ -17,16 +17,16 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <boost/utility/string_ref.hpp>
|
||||
#include <boost/utility/string_view.hpp>
|
||||
#include <boost/container/flat_map.hpp>
|
||||
#include <string>
|
||||
|
||||
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 {
|
||||
boost::string_ref type;
|
||||
boost::string_ref subtype;
|
||||
boost::string_view type;
|
||||
boost::string_view subtype;
|
||||
MimeParametersMapType parameters;
|
||||
};
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
namespace tawashi {
|
||||
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);
|
||||
for (std::size_t z = skip_sign; z < parValue.size(); ++z) {
|
||||
const char c = parValue[z];
|
||||
|
|
|
@ -33,6 +33,7 @@ namespace tawashi {
|
|||
//TODO: make sure the file exists or throw or do something
|
||||
return parSettings.as<std::string>("highlight_css");
|
||||
}
|
||||
|
||||
} //unnamed namespace
|
||||
|
||||
PastieResponse::PastieResponse (
|
||||
|
@ -75,7 +76,7 @@ namespace tawashi {
|
|||
}
|
||||
|
||||
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);
|
||||
|
||||
if (not pastie) {
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
#include "response.hpp"
|
||||
#include <string>
|
||||
#include <boost/utility/string_ref.hpp>
|
||||
#include <boost/utility/string_view.hpp>
|
||||
|
||||
namespace tawashi {
|
||||
class PastieResponse : public Response {
|
||||
|
@ -31,7 +31,7 @@ namespace tawashi {
|
|||
);
|
||||
|
||||
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:
|
||||
virtual HttpHeader on_process() override;
|
||||
|
|
|
@ -55,7 +55,7 @@ namespace mchlib {
|
|||
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;
|
||||
char prev = '\0';
|
||||
for (auto c : parIn) {
|
||||
|
@ -65,9 +65,9 @@ namespace mchlib {
|
|||
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();
|
||||
boost::string_ref::const_iterator next;
|
||||
boost::string_view::const_iterator next;
|
||||
const auto end = parPath.end();
|
||||
const auto beg = parPath.begin();
|
||||
while (end != (next = std::find(from, end, '/'))) {
|
||||
|
@ -111,7 +111,7 @@ namespace mchlib {
|
|||
}
|
||||
} //unnamed namespace
|
||||
|
||||
PathName::PathName (boost::string_ref parPath) {
|
||||
PathName::PathName (boost::string_view parPath) {
|
||||
if (not parPath.empty()) {
|
||||
m_absolute = ('/' == parPath.front());
|
||||
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 absolute = (m_absolute ? 1 : 0);
|
||||
const auto res = count + 1 - trailing - absolute;
|
||||
std::vector<boost::string_ref> atoms;
|
||||
std::vector<boost::string_view> atoms;
|
||||
atoms.reserve(res);
|
||||
split_path(&atoms, path);
|
||||
m_pool.insert(atoms, &path);
|
||||
|
@ -139,7 +139,7 @@ namespace mchlib {
|
|||
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);
|
||||
}
|
||||
|
||||
|
@ -149,11 +149,11 @@ namespace mchlib {
|
|||
|
||||
void PathName::join (const char* parOther) {
|
||||
const std::string src(parOther);
|
||||
const boost::string_ref ref(src);
|
||||
const boost::string_view 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);
|
||||
}
|
||||
|
||||
|
@ -204,11 +204,11 @@ namespace mchlib {
|
|||
return parStream;
|
||||
}
|
||||
|
||||
const boost::string_ref basename (const PathName& parPath) {
|
||||
const boost::string_view basename (const PathName& parPath) {
|
||||
static const char* const empty = "";
|
||||
const auto sz = parPath.atom_count();
|
||||
if (not sz) {
|
||||
return boost::string_ref(empty);
|
||||
return boost::string_view(empty);
|
||||
}
|
||||
|
||||
assert(sz > 0);
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
#include "kakoune/safe_ptr.hh"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <boost/utility/string_ref.hpp>
|
||||
#include <boost/utility/string_view.hpp>
|
||||
#include <map>
|
||||
#include <iostream>
|
||||
|
||||
|
@ -31,7 +31,7 @@ namespace mchlib {
|
|||
public:
|
||||
PathName ( PathName&& ) = default;
|
||||
PathName ( const PathName& ) = default;
|
||||
explicit PathName ( boost::string_ref parPath );
|
||||
explicit PathName ( boost::string_view parPath );
|
||||
~PathName ( void ) noexcept = default;
|
||||
|
||||
PathName& operator= ( PathName&& ) = default;
|
||||
|
@ -41,10 +41,10 @@ namespace mchlib {
|
|||
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); }
|
||||
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 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;
|
||||
std::string dirname ( void ) const;
|
||||
PathName& pop_right ( void );
|
||||
|
@ -61,7 +61,7 @@ namespace mchlib {
|
|||
|
||||
PathName make_relative_path ( const PathName& parBasePath, const PathName& parOtherPath );
|
||||
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
|
||||
|
||||
#endif
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#define id9CF5E6FA7E334DF09559C2968C494CB9
|
||||
|
||||
#include <string>
|
||||
#include <boost/utility/string_ref.hpp>
|
||||
#include <boost/utility/string_view.hpp>
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
#include <ciso646>
|
||||
|
@ -29,7 +29,7 @@
|
|||
#include <boost/iterator/transform_iterator.hpp>
|
||||
|
||||
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 {
|
||||
typedef std::pair<StrRef, const Str*> StringListPair;
|
||||
typedef std::vector<std::pair<Str, std::size_t>> PoolType;
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
#include "submit_paste_response.hpp"
|
||||
#include <boost/optional.hpp>
|
||||
#include <boost/utility/string_ref.hpp>
|
||||
#include <boost/utility/string_view.hpp>
|
||||
#include <cassert>
|
||||
|
||||
namespace tawashi {
|
||||
|
@ -32,7 +32,7 @@ namespace tawashi {
|
|||
);
|
||||
|
||||
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;
|
||||
|
||||
private:
|
||||
|
|
|
@ -47,7 +47,7 @@ namespace tawashi {
|
|||
// 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());
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
oss << parWebsiteRoot << parName << parSuffix;
|
||||
spdlog::get("statuslog")->info("Trying to load \"{}\"", oss.str());
|
||||
|
@ -93,8 +93,8 @@ namespace tawashi {
|
|||
return parStr;
|
||||
};
|
||||
|
||||
boost::string_ref make_host_path (const SettingsBag& parSettings) {
|
||||
boost::string_ref host_path = parSettings.at("host_path");
|
||||
boost::string_view make_host_path (const SettingsBag& parSettings) {
|
||||
boost::string_view host_path = parSettings.at("host_path");
|
||||
if (not host_path.empty() and host_path[host_path.size() - 1] == '/')
|
||||
host_path = host_path.substr(0, host_path.size() - 1);
|
||||
return host_path;
|
||||
|
@ -110,7 +110,7 @@ namespace tawashi {
|
|||
else
|
||||
oss << "http://";
|
||||
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 (host_port == "from_downstream") {
|
||||
const uint16_t port = parCgiEnv->server_port();
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
#include "cgi_post.hpp"
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <boost/utility/string_ref.hpp>
|
||||
#include <boost/utility/string_view.hpp>
|
||||
#include <memory>
|
||||
|
||||
namespace tawashi {
|
||||
|
@ -53,7 +53,7 @@ namespace tawashi {
|
|||
tawashi_virtual_testing cgi::PostMapType cgi_post() 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;
|
||||
const SettingsBag& settings() const;
|
||||
virtual std::string load_mustache() const;
|
||||
|
|
|
@ -46,7 +46,7 @@ namespace tawashi {
|
|||
|
||||
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());
|
||||
spdlog::get("statuslog")->info(
|
||||
"making response object for \"{}\" method {}",
|
||||
|
|
|
@ -36,7 +36,7 @@ namespace tawashi {
|
|||
explicit ResponseFactory (const Kakoune::SafePtr<SettingsBag>& parSettings, const Kakoune::SafePtr<cgi::Env>& parCgiEnv);
|
||||
~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, RequestMethodType parReqType, ResponseMakerFunc parMaker);
|
||||
void register_jolly_maker (ResponseMakerFunc parMaker, RequestMethodType parReqType);
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#endif
|
||||
|
||||
namespace tawashi {
|
||||
std::string sanitized_utf8 (const boost::string_ref& parStr) {
|
||||
std::string sanitized_utf8 (const boost::string_view& parStr) {
|
||||
std::string sanitized;
|
||||
sanitized.reserve(parStr.size());
|
||||
#if defined(SANITIZE_WITH_UTFCPP)
|
||||
|
|
|
@ -17,9 +17,9 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <boost/utility/string_ref.hpp>
|
||||
#include <boost/utility/string_view.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace tawashi {
|
||||
std::string sanitized_utf8 (const boost::string_ref& parStr);
|
||||
std::string sanitized_utf8 (const boost::string_view& parStr);
|
||||
} //namespace tawashi
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
namespace tawashi {
|
||||
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);
|
||||
if (parIni.parsed().end() != it_found) {
|
||||
return &it_found->second;
|
||||
|
@ -38,7 +38,7 @@ namespace tawashi {
|
|||
}
|
||||
} //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_values(get_tawashi_node(*parIni, parSectionName))
|
||||
{
|
||||
|
@ -47,7 +47,7 @@ namespace tawashi {
|
|||
|
||||
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);
|
||||
if (m_values->end() != it_found)
|
||||
return it_found->second;
|
||||
|
@ -55,19 +55,19 @@ namespace tawashi {
|
|||
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());
|
||||
m_defaults[parKey] = parValue;
|
||||
}
|
||||
|
||||
template <>
|
||||
std::string SettingsBag::as (boost::string_ref parIndex) const {
|
||||
std::string SettingsBag::as (boost::string_view parIndex) const {
|
||||
auto& setting = this->at(parIndex);
|
||||
return std::string(setting.data(), setting.size());
|
||||
}
|
||||
|
||||
template <>
|
||||
bool SettingsBag::as (boost::string_ref parIndex) const {
|
||||
bool SettingsBag::as (boost::string_view parIndex) const {
|
||||
auto& setting = this->at(parIndex);
|
||||
if (setting == "true" or setting == "yes" or setting == "1" or setting == "on") {
|
||||
return true;
|
||||
|
@ -83,17 +83,17 @@ namespace tawashi {
|
|||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
template std::string SettingsBag::as<std::string> (boost::string_ref parIndex) const;
|
||||
template bool SettingsBag::as<bool> (boost::string_ref parIndex) const;
|
||||
template uint16_t SettingsBag::as<uint16_t> (boost::string_ref parIndex) const;
|
||||
template uint32_t SettingsBag::as<uint32_t> (boost::string_ref parIndex) const;
|
||||
template std::string SettingsBag::as<std::string> (boost::string_view parIndex) const;
|
||||
template bool SettingsBag::as<bool> (boost::string_view parIndex) const;
|
||||
template uint16_t SettingsBag::as<uint16_t> (boost::string_view parIndex) const;
|
||||
template uint32_t SettingsBag::as<uint32_t> (boost::string_view parIndex) const;
|
||||
} //namespace tawashi
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#include "ini_file.hpp"
|
||||
#include "kakoune/safe_ptr.hh"
|
||||
#include <map>
|
||||
#include <boost/utility/string_ref.hpp>
|
||||
#include <boost/utility/string_view.hpp>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#if defined(SPDLOG_DEBUG_ON)
|
||||
|
@ -29,15 +29,15 @@
|
|||
|
||||
namespace tawashi {
|
||||
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:
|
||||
SettingsBag (const Kakoune::SafePtr<IniFile>& parIni, boost::string_ref parSectionName);
|
||||
SettingsBag (const Kakoune::SafePtr<IniFile>& parIni, boost::string_view parSectionName);
|
||||
~SettingsBag() noexcept;
|
||||
|
||||
const boost::string_ref& operator[] (boost::string_ref parIndex) const;
|
||||
const boost::string_ref& at (boost::string_ref parIndex) const;
|
||||
template <typename T> T as (boost::string_ref parIndex) const;
|
||||
void add_default (boost::string_ref parKey, boost::string_ref parValue);
|
||||
const boost::string_view& operator[] (boost::string_view parIndex) const;
|
||||
const boost::string_view& at (boost::string_view parIndex) const;
|
||||
template <typename T> T as (boost::string_view parIndex) const;
|
||||
void add_default (boost::string_view parKey, boost::string_view parValue);
|
||||
|
||||
private:
|
||||
MapType m_defaults;
|
||||
|
@ -46,11 +46,11 @@ namespace tawashi {
|
|||
};
|
||||
|
||||
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];
|
||||
}
|
||||
|
||||
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)
|
||||
SPDLOG_DEBUG(spdlog::get("statuslog"), "Retrieving setting \"{}\"", std::string(parIndex.data(), parIndex.size()));
|
||||
#endif
|
||||
|
|
|
@ -18,11 +18,11 @@
|
|||
#pragma once
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <boost/utility/string_ref.hpp>
|
||||
#include <boost/utility/string_view.hpp>
|
||||
|
||||
namespace spdlog {
|
||||
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;
|
||||
}
|
||||
} //namespace spdlog
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
#include "split_get_vars.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/filtered.hpp>
|
||||
#include <ciso646>
|
||||
|
@ -31,7 +31,7 @@ namespace tawashi {
|
|||
using boost::token_finder;
|
||||
using boost::adaptors::transformed;
|
||||
using boost::adaptors::filtered;
|
||||
using boost::string_ref;
|
||||
using boost::string_view;
|
||||
using boost::split_iterator;
|
||||
using boost::make_iterator_range;
|
||||
using boost::range::find;
|
||||
|
@ -49,11 +49,11 @@ namespace tawashi {
|
|||
transformed([](const MatchRange& r){
|
||||
auto eq = find(r, '=');
|
||||
if (r.empty())
|
||||
return std::pair<string_ref, string_ref>();
|
||||
return std::pair<string_view, string_view>();
|
||||
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
|
||||
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)));
|
||||
})
|
||||
);
|
||||
}
|
||||
|
|
|
@ -18,12 +18,12 @@
|
|||
#pragma once
|
||||
|
||||
#include "duckhandy/compatibility.h"
|
||||
#include <boost/utility/string_ref.hpp>
|
||||
#include <boost/utility/string_view.hpp>
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
|
||||
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;
|
||||
} //namespace tawashi
|
||||
|
|
|
@ -89,9 +89,9 @@ namespace tawashi {
|
|||
}
|
||||
|
||||
Storage::SubmissionResult Storage::submit_pastie (
|
||||
const boost::string_ref& parText,
|
||||
const boost::string_view& parText,
|
||||
uint32_t parExpiry,
|
||||
const boost::string_ref& parLang,
|
||||
const boost::string_view& parLang,
|
||||
const std::string& parRemoteIP
|
||||
) const {
|
||||
if (not is_connected())
|
||||
|
@ -121,7 +121,7 @@ namespace tawashi {
|
|||
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_list = redis::IncRedis::opt_string_list;
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#include "error_reasons.hpp"
|
||||
#include <memory>
|
||||
#include <cstdint>
|
||||
#include <boost/utility/string_ref.hpp>
|
||||
#include <boost/utility/string_view.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <string>
|
||||
|
||||
|
@ -46,13 +46,13 @@ namespace tawashi {
|
|||
tawashi_virtual_testing bool is_connected() const;
|
||||
tawashi_virtual_testing void finalize_connection();
|
||||
tawashi_virtual_testing SubmissionResult submit_pastie (
|
||||
const boost::string_ref& parText,
|
||||
const boost::string_view& parText,
|
||||
uint32_t parExpiry,
|
||||
const boost::string_ref& parLang,
|
||||
const boost::string_view& parLang,
|
||||
const std::string& parRemoteIP
|
||||
) 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)
|
||||
const SettingsBag& settings() const;
|
||||
|
|
|
@ -37,7 +37,7 @@ namespace tawashi {
|
|||
|
||||
class MissingPostVarError : public TawashiException {
|
||||
public:
|
||||
explicit MissingPostVarError(const boost::string_ref& parKey) :
|
||||
explicit MissingPostVarError(const boost::string_view& parKey) :
|
||||
TawashiException(
|
||||
ErrorReasons::MissingPostVariable,
|
||||
"Error retrieving POST variable \"" + std::string(parKey.begin(), parKey.end()) + "\""
|
||||
|
@ -46,15 +46,15 @@ namespace tawashi {
|
|||
};
|
||||
|
||||
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>
|
||||
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?");
|
||||
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());
|
||||
auto post_data_it = parPost.find(key);
|
||||
if (parPost.end() == post_data_it)
|
||||
|
@ -62,13 +62,13 @@ namespace tawashi {
|
|||
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 {
|
||||
return get_value_from_post(parPost, parKey);
|
||||
}
|
||||
catch (const MissingPostVarError& e) {
|
||||
spdlog::get("statuslog")->info(e.what());
|
||||
return boost::string_ref();
|
||||
return boost::string_view();
|
||||
}
|
||||
}
|
||||
} //unnamed namespace
|
||||
|
@ -95,9 +95,9 @@ namespace tawashi {
|
|||
}
|
||||
|
||||
HttpHeader SubmitPasteResponse::on_process() {
|
||||
boost::string_ref pastie;
|
||||
boost::string_ref lang;
|
||||
boost::string_ref duration;
|
||||
boost::string_view pastie;
|
||||
boost::string_view lang;
|
||||
boost::string_view duration;
|
||||
|
||||
auto statuslog = spdlog::get("statuslog");
|
||||
assert(statuslog);
|
||||
|
@ -105,9 +105,9 @@ namespace tawashi {
|
|||
const SettingsBag& settings = this->settings();
|
||||
try {
|
||||
auto post = this->cgi_post();
|
||||
pastie = get_value_from_post(post, make_string_ref(g_post_key));
|
||||
lang = get_value_from_post_log_failure(post, make_string_ref(g_language_key));
|
||||
duration = get_value_from_post_log_failure(post, make_string_ref(g_duration_key));
|
||||
pastie = get_value_from_post(post, make_string_view(g_post_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_view(g_duration_key));
|
||||
}
|
||||
catch (const UnsupportedContentTypeException& err) {
|
||||
statuslog->info(
|
||||
|
@ -158,9 +158,9 @@ namespace tawashi {
|
|||
}
|
||||
|
||||
auto SubmitPasteResponse::submit_to_storage (
|
||||
const boost::string_ref& parText,
|
||||
const boost::string_view& parText,
|
||||
uint32_t parExpiry,
|
||||
const boost::string_ref& parLang
|
||||
const boost::string_view& parLang
|
||||
) -> StringOrHeader {
|
||||
auto& storage = this->storage();
|
||||
std::string remote_ip = guess_real_remote_ip(cgi_env());
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#include "response.hpp"
|
||||
#include <string>
|
||||
#include <boost/optional.hpp>
|
||||
#include <boost/utility/string_ref.hpp>
|
||||
#include <boost/utility/string_view.hpp>
|
||||
#include <cassert>
|
||||
#include <utility>
|
||||
|
||||
|
@ -43,13 +43,13 @@ namespace tawashi {
|
|||
);
|
||||
|
||||
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);
|
||||
|
||||
private:
|
||||
typedef std::pair<boost::optional<std::string>, HttpHeader> StringOrHeader;
|
||||
|
||||
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
|
||||
|
|
|
@ -20,14 +20,14 @@
|
|||
|
||||
namespace tawashi {
|
||||
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;
|
||||
oss << "Exception with reason " << parReason << ": " << parMessage;
|
||||
return oss.str();
|
||||
}
|
||||
} //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)),
|
||||
m_reason(parReason)
|
||||
{
|
||||
|
|
|
@ -19,12 +19,12 @@
|
|||
#include "error_reasons.hpp"
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <boost/utility/string_ref.hpp>
|
||||
#include <boost/utility/string_view.hpp>
|
||||
|
||||
namespace tawashi {
|
||||
class TawashiException : public std::runtime_error {
|
||||
public:
|
||||
TawashiException (ErrorReasons parReason, const boost::string_ref& parMessage);
|
||||
TawashiException (ErrorReasons parReason, const boost::string_view& parMessage);
|
||||
~TawashiException() noexcept;
|
||||
|
||||
ErrorReasons reason() const { return m_reason; }
|
||||
|
|
Loading…
Add table
Reference in a new issue