added to utf8:

bool UTF8ToWide(const char * utf8, size_t utf8_len, WTextStream & res, bool clear = true, int mode = 1);
bool UTF8ToWide(const char * utf8,                  WTextStream & res, bool clear = true, int mode = 1);
bool UTF8ToWide(const std::string & utf8,           WTextStream & res, bool clear = true, int mode = 1);
bool UTF8ToWide(std::istream & utf8,                WTextStream & res, bool clear = true, int mode = 1);

void WideToUTF8(PT::WTextStream & buffer,                       std::string & utf8,  bool clear = true, int mode = 1);
void WideToUTF8(PT::WTextStream & buffer,                       std::ostream & utf8, int mode = 1);

these functions need some testing yet




git-svn-id: svn://ttmath.org/publicrep/pikotools/trunk@1156 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2018-11-24 13:30:45 +00:00
parent 8b3ae14d9a
commit da4ed9c1f8
8 changed files with 215 additions and 74 deletions

View File

@@ -100,35 +100,6 @@ void FileLog::open_file()
}
void FileLog::PutBuffer(PT::WTextStream * buffer, std::ostream & out_stream)
{
char utf8_buffer[256];
std::size_t buffer_len = sizeof(utf8_buffer) / sizeof(char);
std::size_t utf8_sequence_max_length = 10;
std::size_t index = 0;
PT::WTextStream::const_iterator i = buffer->begin();
while( i != buffer->end() )
{
if( index + utf8_sequence_max_length > buffer_len )
{
out_stream.write(utf8_buffer, index);
index = 0;
}
index += PT::IntToUTF8(*i, utf8_buffer + index, buffer_len - index);
++i;
}
if( index > 0 )
{
out_stream.write(utf8_buffer, index);
}
}
void FileLog::save_log(PT::WTextStream * buffer)
{
if( buffer->empty() )
@@ -140,7 +111,7 @@ void FileLog::save_log(PT::WTextStream * buffer)
{
if( log_stdout )
{
PutBuffer(buffer, std::cout);
PT::WideToUTF8(*buffer, std::cout);
}
if( !log_file.empty() )
@@ -155,7 +126,7 @@ void FileLog::save_log(PT::WTextStream * buffer)
if( file )
{
PutBuffer(buffer, file);
PT::WideToUTF8(*buffer, file);
file.flush();
}
}

View File

@@ -82,7 +82,6 @@ protected:
virtual bool synchro_lock();
virtual void synchro_unlock();
virtual void PutBuffer(PT::WTextStream * buffer, std::ostream & out_stream);
virtual void open_file();
};

View File

@@ -115,7 +115,7 @@ Log & Log::operator<<(const char * s)
{
if( buffer && file_log && s && current_level <= file_log->get_log_level() )
{
(*buffer) << s;
PT::UTF8ToWide(s, *buffer, false);
}
return *this;
@@ -127,7 +127,7 @@ Log & Log::operator<<(const std::string & s)
{
if( buffer && file_log && current_level <= file_log->get_log_level() )
{
(*buffer) << s;
PT::UTF8ToWide(s, *buffer, false);
}
return *this;
@@ -139,7 +139,7 @@ Log & Log::operator<<(const std::string * s)
{
if( buffer && file_log && current_level <= file_log->get_log_level() )
{
(*buffer) << *s;
PT::UTF8ToWide(*s, *buffer, false);
}
return *this;