(update to the new pikotools api): use a char32_t character as a main character when converting strings
Use a char32_t instead of a wchar_t type. This is needed on systems where sizeof(wchar_t) is equal to 2. This affects classes based on the pt::Stream such as Log and HtmlTextStream.
This commit is contained in:
parent
af0d34beb9
commit
5d457f3d4b
|
@ -197,6 +197,13 @@ Log & Log::operator<<(wchar_t s)
|
|||
}
|
||||
|
||||
|
||||
Log & Log::operator<<(char32_t s)
|
||||
{
|
||||
pt::Log::operator<<(s);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Log & Log::operator<<(unsigned short s)
|
||||
{
|
||||
pt::Log::operator<<(s);
|
||||
|
|
|
@ -74,6 +74,7 @@ public:
|
|||
virtual Log & operator<<(char s);
|
||||
virtual Log & operator<<(unsigned char);
|
||||
virtual Log & operator<<(wchar_t s);
|
||||
virtual Log & operator<<(char32_t s);
|
||||
virtual Log & operator<<(bool);
|
||||
virtual Log & operator<<(short);
|
||||
virtual Log & operator<<(int s);
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-2021, Tomasz Sowa
|
||||
* Copyright (c) 2010-2024, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -33,6 +33,7 @@
|
|||
*/
|
||||
|
||||
#include "htmltextstream.h"
|
||||
#include "convert/misc.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
@ -245,6 +246,14 @@ return *this;
|
|||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::PutChar(char32_t c)
|
||||
{
|
||||
buffer.operator<<(c);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::PutChar(bool val)
|
||||
{
|
||||
buffer.operator<<(val);
|
||||
|
@ -306,6 +315,13 @@ HtmlTextStream & HtmlTextStream::operator<<(RawText<wchar_t> raw)
|
|||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(RawText<char32_t> raw)
|
||||
{
|
||||
buffer.operator<<(raw.par);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(RawText<bool> raw)
|
||||
{
|
||||
buffer.operator<<(raw.par);
|
||||
|
@ -453,13 +469,12 @@ HtmlTextStream & HtmlTextStream::EPutText(const char * str)
|
|||
bool correct;
|
||||
size_t utf8_len;
|
||||
|
||||
// CHECKME
|
||||
while( (utf8_len = pt::utf8_to_int(str, res, correct)) > 0 )
|
||||
{
|
||||
if( !correct )
|
||||
res = 0xFFFD; // U+FFFD "replacement character"
|
||||
|
||||
ETextPutChar(static_cast<wchar_t>(res));
|
||||
ETextPutChar(static_cast<char32_t>(res));
|
||||
str += utf8_len;
|
||||
}
|
||||
|
||||
|
@ -475,6 +490,11 @@ HtmlTextStream & HtmlTextStream::EPutText(const std::string & str)
|
|||
|
||||
HtmlTextStream & HtmlTextStream::EPutText(const wchar_t * str)
|
||||
{
|
||||
/*
|
||||
* we assume the sizeof(wchar) is 4 here
|
||||
* as at the moment winix works only on unixes
|
||||
* so just copy directly those characters
|
||||
*/
|
||||
for( ; *str ; ++str )
|
||||
ETextPutChar(*str);
|
||||
|
||||
|
@ -528,39 +548,22 @@ HtmlTextStream & HtmlTextStream::ETextPutChar(char c)
|
|||
|
||||
HtmlTextStream & HtmlTextStream::ETextPutChar(unsigned char c)
|
||||
{
|
||||
return ETextPutChar(static_cast<wchar_t>(c));
|
||||
return ETextPutChar(static_cast<char32_t>(c));
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::ETextPutChar(wchar_t c)
|
||||
{
|
||||
if( c == '<' )
|
||||
buffer << L"<";
|
||||
else
|
||||
if( c == '>' )
|
||||
buffer << L">";
|
||||
else
|
||||
if( c == '&' )
|
||||
buffer << L"&";
|
||||
else
|
||||
if( c == '\"' )
|
||||
buffer << L""";
|
||||
else
|
||||
if( c == '\'' )
|
||||
buffer << L"'"; // (it is "'" but IE8 has a problem with ') (' is valid in HTML5, but not HTML4)
|
||||
else
|
||||
if( c == 10 )
|
||||
buffer << L" ";
|
||||
else
|
||||
if( c == 13 )
|
||||
buffer << L" ";
|
||||
else
|
||||
if( c == 0 )
|
||||
buffer << L"�";
|
||||
else
|
||||
return ETextPutChar(static_cast<char32_t>(c));
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::ETextPutChar(char32_t c)
|
||||
{
|
||||
if( !pt::try_esc_to_html(c, buffer) )
|
||||
buffer << c;
|
||||
|
||||
return *this;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
@ -650,6 +653,17 @@ return *this;
|
|||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(char32_t v)
|
||||
{
|
||||
if( escape )
|
||||
ETextPutChar(v);
|
||||
else
|
||||
PutChar(v);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(bool v)
|
||||
{
|
||||
/*
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-2022, Tomasz Sowa
|
||||
* Copyright (c) 2010-2024, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -148,6 +148,7 @@ public:
|
|||
HtmlTextStream & PutChar(char c);
|
||||
HtmlTextStream & PutChar(unsigned char c);
|
||||
HtmlTextStream & PutChar(wchar_t c);
|
||||
HtmlTextStream & PutChar(char32_t c);
|
||||
HtmlTextStream & PutChar(bool val);
|
||||
|
||||
|
||||
|
@ -171,6 +172,7 @@ public:
|
|||
HtmlTextStream & operator<<(RawText<char> raw);
|
||||
HtmlTextStream & operator<<(RawText<unsigned char> raw);
|
||||
HtmlTextStream & operator<<(RawText<wchar_t> raw);
|
||||
HtmlTextStream & operator<<(RawText<char32_t> raw);
|
||||
HtmlTextStream & operator<<(RawText<bool> raw);
|
||||
|
||||
HtmlTextStream & operator<<(RawText<short> raw);
|
||||
|
@ -219,6 +221,7 @@ public:
|
|||
HtmlTextStream & ETextPutChar(char c);
|
||||
HtmlTextStream & ETextPutChar(unsigned char c);
|
||||
HtmlTextStream & ETextPutChar(wchar_t c);
|
||||
HtmlTextStream & ETextPutChar(char32_t c);
|
||||
|
||||
|
||||
/*
|
||||
|
@ -234,6 +237,7 @@ public:
|
|||
HtmlTextStream & operator<<(char);
|
||||
HtmlTextStream & operator<<(unsigned char);
|
||||
HtmlTextStream & operator<<(wchar_t);
|
||||
HtmlTextStream & operator<<(char32_t);
|
||||
HtmlTextStream & operator<<(bool);
|
||||
HtmlTextStream & operator<<(short);
|
||||
HtmlTextStream & operator<<(int);
|
||||
|
|
Loading…
Reference in New Issue