add some utf8 converting methods

add new methods:
- bool int_to_stream(int c, pt::Stream & stream);
- template<typename OutputFunction>
  bool utf8_to_output_function(const Stream & stream, OutputFunction output_function, int mode = 1);
- template<typename StreamIteratorType, typename OutputFunction>
  bool utf8_to_output_function(StreamIteratorType & iterator_in, const StreamIteratorType & iterator_end, OutputFunction output_function, int mode = 1);
- template<typename StreamType, typename OutputFunction>
  bool wide_to_output_function(StreamType & buffer, OutputFunction output_function, int mode = 1);

make some methods public:
- size_t wide_to_int(const wchar_t * wide_string, size_t string_len, int & z, bool & correct)
- size_t wide_to_int(const wchar_t * wide_string, int & z, bool & correct)

rename and make some methods public:
- template<typename OutputFunction>
  utf8_to_wide_generic(const char * utf8, size_t utf8_len, OutputFunction convert_function, int mode) -> utf8_to_output_function(...)

while here:
- fix: correctly convert characters in Log::put_multiline_generic()
This commit is contained in:
2024-05-30 20:19:04 +02:00
parent 5fd17175c1
commit aacb1f43ae
11 changed files with 428 additions and 338 deletions

View File

@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2018-2022, Tomasz Sowa
* Copyright (c) 2018-2024, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -36,7 +36,6 @@
#define headerfile_pikotools_src_log_log
#include <string>
#include <fstream>
#include "textstream/textstream.h"
#include "filelog.h"
@@ -246,6 +245,7 @@ void Log::put_multiline_generic(const CharType * prefix, const CharType * msg)
{
was_new_line = true;
put_prefix = true;
msg += 1;
}
else
{
@@ -265,11 +265,32 @@ void Log::put_multiline_generic(const CharType * prefix, const CharType * msg)
put_prefix = false;
}
operator<<(*msg);
if constexpr ( sizeof(CharType) == sizeof(char) )
{
int c;
bool correct;
msg += utf8_to_int(msg, c, correct);
if( correct )
int_to_stream(c, *this);
else
int_to_stream(0xFFFD, *this); // replacement character
}
else
if constexpr ( sizeof(CharType) == sizeof(wchar_t) )
{
operator<<(*msg);
msg += 1;
}
else
{
// what is the CharType?
// at the moment do not print anything
msg += 1;
}
was_something_printed = true;
}
msg += 1;
}
if( was_something_printed )