use boost::locale instead of corecvt.

This commit is contained in:
Joseph Lenox 2018-11-23 20:15:20 -06:00 committed by Joseph Lenox
parent 02fd5b9de7
commit d12885d042
3 changed files with 67 additions and 9 deletions

View File

@ -62,6 +62,64 @@ SCENARIO( "_Log output with std::string methods" ) {
}
}
}
SCENARIO( "_Log output with std::wstring methods" ) {
GIVEN("A log stream and a _Log object") {
std::stringstream log;
std::unique_ptr<_Log> cut { _Log::make_log(log) };
cut->set_level(log_t::DEBUG);
cut->set_inclusive(true);
WHEN("fatal_error is called with topic \"Topic\" and text \"This\"") {
log.clear();
cut->fatal_error("Topic", L"This");
THEN("Output string is Topic FERR: This\\n") {
REQUIRE(log.str() == "Topic FERR: This\n");
}
}
WHEN("error is called with topic \"Topic\" and text \"This\"") {
log.clear();
cut->error("Topic", L"This");
THEN("Output string is Topic ERR: This\\n") {
REQUIRE(log.str() == "Topic ERR: This\n");
}
}
WHEN("info is called with topic \"Topic\" and text \"This\"") {
log.clear();
cut->info("Topic", L"This");
THEN("Output string is Topic INFO: This\\n") {
REQUIRE(log.str() == "Topic INFO: This\n");
}
}
WHEN("warn is called with topic \"Topic\" and text \"This\"") {
log.clear();
cut->warn("Topic", L"This");
THEN("Output string is Topic WARN: This\\n") {
REQUIRE(log.str() == "Topic WARN: This\n");
}
}
WHEN("info is called with topic \"Topic\" and text \"This\"") {
log.clear();
cut->info("Topic", L"This");
THEN("Output string is Topic INFO: This\\n") {
REQUIRE(log.str() == "Topic INFO: This\n");
}
}
WHEN("debug is called with topic \"Topic\" and text \"This\"") {
log.clear();
cut->debug("Topic", L"This");
THEN("Output string is Topic DEBUG: This\\n") {
REQUIRE(log.str() == "Topic DEBUG: This\n");
}
}
WHEN("msg is called with text \"This\"") {
log.clear();
cut->raw(L"This");
THEN("Output string is This\\n") {
REQUIRE(log.str() == "This\n");
}
}
}
}
SCENARIO( "_Log output with << methods" ) {
GIVEN("A log stream and a _Log object") {
std::stringstream log;

View File

@ -4,6 +4,10 @@
#include <iomanip>
#include <algorithm>
// Boost
#include <boost/locale.hpp>
#include <boost/algorithm/string/case_conv.hpp>
#include "Log.hpp"
/// Local class to suppress output
@ -39,11 +43,11 @@ bool _Log::_has_topic(const std::string& topic) {
return this->_topics.find(topic) != this->_topics.end() || this->_topics.size() == 0;
}
void _Log::fatal_error(const std::string& topic, const std::wstring& message) { this->fatal_error(topic, this->converter.to_bytes(message)); }
void _Log::error(const std::string& topic, const std::wstring& message) { this->error(topic, this->converter.to_bytes(message)); }
void _Log::warn(const std::string& topic, const std::wstring& message) { this->warn(topic, this->converter.to_bytes(message)); }
void _Log::info(const std::string& topic, const std::wstring& message) { this->info(topic, this->converter.to_bytes(message)); }
void _Log::debug(const std::string& topic, const std::wstring& message) { this->debug(topic, this->converter.to_bytes(message)); }
void _Log::fatal_error(const std::string& topic, const std::wstring& message) { this->fatal_error(topic, boost::locale::conv::utf_to_utf<char>(message)); }
void _Log::error(const std::string& topic, const std::wstring& message) { this->error(topic, boost::locale::conv::utf_to_utf<char>(message)); }
void _Log::warn(const std::string& topic, const std::wstring& message) { this->warn(topic, boost::locale::conv::utf_to_utf<char>(message)); }
void _Log::info(const std::string& topic, const std::wstring& message) { this->info(topic, boost::locale::conv::utf_to_utf<char>(message)); }
void _Log::debug(const std::string& topic, const std::wstring& message) { this->debug(topic, boost::locale::conv::utf_to_utf<char>(message)); }
void _Log::fatal_error(const std::string& topic, const std::string& message) {
this->fatal_error(topic) << message << std::endl;

View File

@ -6,9 +6,7 @@
#include <sstream>
#include <iostream>
#include <memory>
#include <locale>
#include <set>
#include <codecvt> // good until c++17
namespace Slic3r {
@ -76,8 +74,6 @@ private:
std::set<log_t> _log_level { };
std::set<std::string> _topics { };
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
bool _has_log_level(log_t lvl);
bool _has_topic(const std::string& topic);