changed things to include plog
This commit is contained in:
parent
b018a44f10
commit
68a1618743
34 changed files with 2702 additions and 27 deletions
44
include/plog/Converters/NativeEOLConverter.h
Normal file
44
include/plog/Converters/NativeEOLConverter.h
Normal file
|
@ -0,0 +1,44 @@
|
|||
#pragma once
|
||||
#include <plog/Converters/UTF8Converter.h>
|
||||
#include <plog/Util.h>
|
||||
|
||||
namespace plog
|
||||
{
|
||||
template<class NextConverter = UTF8Converter>
|
||||
class NativeEOLConverter : public NextConverter
|
||||
{
|
||||
#ifdef _WIN32
|
||||
public:
|
||||
static std::string header(const util::nstring& str)
|
||||
{
|
||||
return NextConverter::header(fixLineEndings(str));
|
||||
}
|
||||
|
||||
static std::string convert(const util::nstring& str)
|
||||
{
|
||||
return NextConverter::convert(fixLineEndings(str));
|
||||
}
|
||||
|
||||
private:
|
||||
static util::nstring fixLineEndings(const util::nstring& str)
|
||||
{
|
||||
util::nstring output;
|
||||
output.reserve(str.length() * 2); // the worst case requires 2x chars
|
||||
|
||||
for (size_t i = 0; i < str.size(); ++i)
|
||||
{
|
||||
util::nchar ch = str[i];
|
||||
|
||||
if (ch == PLOG_NSTR('\n'))
|
||||
{
|
||||
output.push_back(PLOG_NSTR('\r'));
|
||||
}
|
||||
|
||||
output.push_back(ch);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
#endif
|
||||
};
|
||||
}
|
28
include/plog/Converters/UTF8Converter.h
Normal file
28
include/plog/Converters/UTF8Converter.h
Normal file
|
@ -0,0 +1,28 @@
|
|||
#pragma once
|
||||
#include <plog/Util.h>
|
||||
|
||||
namespace plog
|
||||
{
|
||||
class UTF8Converter
|
||||
{
|
||||
public:
|
||||
static std::string header(const util::nstring& str)
|
||||
{
|
||||
const char kBOM[] = "\xEF\xBB\xBF";
|
||||
|
||||
return std::string(kBOM) + convert(str);
|
||||
}
|
||||
|
||||
#if PLOG_CHAR_IS_UTF8
|
||||
static const std::string& convert(const util::nstring& str)
|
||||
{
|
||||
return str;
|
||||
}
|
||||
#else
|
||||
static std::string convert(const util::nstring& str)
|
||||
{
|
||||
return util::toNarrow(str, codePage::kUTF8);
|
||||
}
|
||||
#endif
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue