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

Use stock std::string conversion.

This commit is contained in:
King_DuckZ 2017-06-07 00:19:53 +01:00
parent eaf8c0778d
commit 056e7dcde4
9 changed files with 22 additions and 41 deletions

@ -1 +1 @@
Subproject commit 4a2580231259f464674d8bd998e5fb378694c98d Subproject commit 9470bdd3ec21c1158d066e49f724ed1dfcd1e698

View file

@ -48,7 +48,7 @@ namespace tawashi {
parURL.size() parURL.size()
); );
if (0 == escaped) if (0 == escaped)
return std::string(parURL.data(), parURL.size()); return std::string(parURL);
else else
return std::string(buf->ptr, buf->size); return std::string(buf->ptr, buf->size);
} }
@ -66,7 +66,7 @@ namespace tawashi {
parURL.size() parURL.size()
); );
if (0 == escaped) if (0 == escaped)
return std::string(parURL.data(), parURL.size()); return std::string(parURL);
else else
return std::string(buf->ptr, buf->size); return std::string(buf->ptr, buf->size);
} }
@ -85,7 +85,7 @@ namespace tawashi {
1 1
); );
if (0 == escaped) if (0 == escaped)
return std::string(parHtml.data(), parHtml.size()); return std::string(parHtml);
else else
return std::string(buf->ptr, buf->size); return std::string(buf->ptr, buf->size);
} }

View file

@ -17,6 +17,7 @@
#include "settings_bag.hpp" #include "settings_bag.hpp"
#include "duckhandy/lexical_cast.hpp" #include "duckhandy/lexical_cast.hpp"
#include "spdlog.hpp"
#include <ciso646> #include <ciso646>
#include <cassert> #include <cassert>
#include <cstdint> #include <cstdint>
@ -63,7 +64,7 @@ namespace tawashi {
template <> template <>
std::string SettingsBag::as (boost::string_view 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);
} }
template <> template <>

View file

@ -19,13 +19,13 @@
#include "ini_file.hpp" #include "ini_file.hpp"
#include "kakoune/safe_ptr.hh" #include "kakoune/safe_ptr.hh"
#if defined(SPDLOG_DEBUG_ON)
# include "spdlog.hpp"
#endif
#include <map> #include <map>
#include <boost/utility/string_view.hpp> #include <boost/utility/string_view.hpp>
#include <functional> #include <functional>
#include <string> #include <string>
#if defined(SPDLOG_DEBUG_ON)
# include <spdlog/spdlog.h>
#endif
namespace tawashi { namespace tawashi {
class SettingsBag : public Kakoune::SafeCountable { class SettingsBag : public Kakoune::SafeCountable {
@ -52,7 +52,7 @@ namespace tawashi {
inline const boost::string_view& SettingsBag::at (boost::string_view 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 \"{}\"", parIndex);
#endif #endif
return (*this)[parIndex]; return (*this)[parIndex];
} }

View file

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

View file

@ -21,10 +21,10 @@
#include "num_to_token.hpp" #include "num_to_token.hpp"
#include "tawashi_config.h" #include "tawashi_config.h"
#include "duckhandy/stringize.h" #include "duckhandy/stringize.h"
#include "spdlog.hpp"
#include <cassert> #include <cassert>
#include <ciso646> #include <ciso646>
#include <string> #include <string>
#include <spdlog/spdlog.h>
#include <utility> #include <utility>
namespace tawashi { namespace tawashi {
@ -131,17 +131,10 @@ namespace tawashi {
#if defined(SPDLOG_DEBUG_ON) #if defined(SPDLOG_DEBUG_ON)
{ {
auto statuslog = spdlog::get("statuslog"); auto statuslog = spdlog::get("statuslog");
if (pastie) { if (pastie)
statuslog->debug("Retrieving pastie with token \"{}\" gave a result of size {}", statuslog->debug("Retrieving pastie with token \"{}\" gave a result of size {}", parToken, pastie->size());
std::string(parToken.data(), parToken.size()), else
pastie->size() statuslog->debug("Retrieving pastie with token \"{}\" gave no results", parToken);
);
}
else {
statuslog->debug("Retrieving pastie with token \"{}\" gave no results",
std::string(parToken.data(), parToken.size())
);
}
} }
#endif #endif
return pastie; return pastie;

View file

@ -55,7 +55,7 @@ namespace tawashi {
} }
boost::string_view get_value_from_post (const cgi::PostMapType& parPost, boost::string_view 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);
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)
throw MissingPostVarError(parKey); throw MissingPostVarError(parKey);

View file

@ -48,9 +48,9 @@ namespace tawashi {
) const { ) const {
SubmittedPastie pastie; SubmittedPastie pastie;
std::string token = num_to_token(m_submission_num++); std::string token = num_to_token(m_submission_num++);
pastie.text = std::string(parText.data(), parText.size()); pastie.text = std::string(parText);
pastie.expiry = parExpiry; pastie.expiry = parExpiry;
pastie.lang = std::string(parLang.data(), parLang.size()); pastie.lang = std::string(parLang);
pastie.remote_ip = parRemoteIP; pastie.remote_ip = parRemoteIP;
pastie.token = token; pastie.token = token;
m_submitted_pasties.push_back(std::move(pastie)); m_submitted_pasties.push_back(std::move(pastie));

View file

@ -18,12 +18,6 @@
#include "catch.hpp" #include "catch.hpp"
#include "mime_split.hpp" #include "mime_split.hpp"
namespace {
std::string to_string (const boost::string_ref& parRef) {
return std::string(parRef.data(), parRef.size());
}
} //unnamed namespace
TEST_CASE ("Test the string_to_mime parser", "[mime][parser]") { TEST_CASE ("Test the string_to_mime parser", "[mime][parser]") {
using tawashi::SplitMime; using tawashi::SplitMime;
using tawashi::string_to_mime; using tawashi::string_to_mime;
@ -42,7 +36,7 @@ TEST_CASE ("Test the string_to_mime parser", "[mime][parser]") {
REQUIRE(split.parameters.size() == 1); REQUIRE(split.parameters.size() == 1);
CHECK(split.parameters.find("charset") != split.parameters.end()); CHECK(split.parameters.find("charset") != split.parameters.end());
curr_val = to_string(split.parameters.at("charset")); curr_val = std::string(split.parameters.at("charset"));
CHECK(curr_val == "UTF-8"); CHECK(curr_val == "UTF-8");
} }
@ -58,11 +52,11 @@ TEST_CASE ("Test the string_to_mime parser", "[mime][parser]") {
REQUIRE(split.parameters.size() == 2); REQUIRE(split.parameters.size() == 2);
CHECK(split.parameters.find("filename") != split.parameters.end()); CHECK(split.parameters.find("filename") != split.parameters.end());
curr_val = to_string(split.parameters.at("filename")); curr_val = std::string(split.parameters.at("filename"));
CHECK(curr_val == "genome.jpeg"); CHECK(curr_val == "genome.jpeg");
CHECK(split.parameters.find("modification-date") != split.parameters.end()); CHECK(split.parameters.find("modification-date") != split.parameters.end());
curr_val = to_string(split.parameters.at("modification-date")); curr_val = std::string(split.parameters.at("modification-date"));
CHECK(curr_val == "Wed, 12 Feb 1997 16:29:51 -0500"); CHECK(curr_val == "Wed, 12 Feb 1997 16:29:51 -0500");
} }
} }