cpp-demo-project/include/plog/Converters/NativeEOLConverter.h

45 lines
1.1 KiB
C
Raw Permalink Normal View History

2024-01-22 12:05:59 +01:00
#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
};
}