let all utf8/wide functions can be available just by including utf8/utf8.h
while here: - remove utf8/utf8_stream.h, now we only need utf8/utf8.h to include - add some new methods for converting from a utf8 stream to wide stream/string - do some improvements in TextStream: - don't use temporary objects to convert utf8/wide - add put_stream() which takes TextStreamBase<> as its argument (uses an iterator instead of get_char() for reading) - let operator<<(const Space & space) serialize to json and not to Space
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-2021, Tomasz Sowa
|
||||
* Copyright (c) 2010-2022, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -128,6 +128,25 @@ bool surrogate_pair_to_int(int c1, int c2, int & z)
|
||||
|
||||
|
||||
|
||||
/*
|
||||
converts an int to a wide string
|
||||
*/
|
||||
void int_to_wide(int c, std::wstring & res)
|
||||
{
|
||||
if( sizeof(wchar_t)==2 && c>0xffff )
|
||||
{
|
||||
// UTF16 surrogate pairs
|
||||
c -= 0x10000;
|
||||
res += static_cast<wchar_t>(((c >> 10) & 0x3FF) + 0xD800);
|
||||
res += static_cast<wchar_t>((c & 0x3FF) + 0xDC00);
|
||||
}
|
||||
else
|
||||
{
|
||||
res += static_cast<wchar_t>(c);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
this function converts one UTF-8 character into one wide-character
|
||||
@@ -312,7 +331,7 @@ unsigned char uz;
|
||||
uz = utf8.get_char(stream_index + i);
|
||||
|
||||
if( !private_namespace::utf8_to_int_add_next_octet(uz, res) )
|
||||
return i;
|
||||
return i + 1;
|
||||
}
|
||||
|
||||
if( utf8_check_range(res, len) )
|
||||
@@ -330,26 +349,6 @@ unsigned char uz;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
*/
|
||||
static void int_to_wide(int c, std::wstring & res)
|
||||
{
|
||||
if( sizeof(wchar_t)==2 && c>0xffff )
|
||||
{
|
||||
// UTF16 surrogate pairs
|
||||
c -= 0x10000;
|
||||
res += static_cast<wchar_t>(((c >> 10) & 0x3FF) + 0xD800);
|
||||
res += static_cast<wchar_t>((c & 0x3FF) + 0xDC00);
|
||||
}
|
||||
else
|
||||
{
|
||||
res += static_cast<wchar_t>(c);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
|
Reference in New Issue
Block a user