mirror of
https://github.com/dlang/phobos.git
synced 2025-04-30 07:00:37 +03:00
fix conversion from wchar to wchar_t in LockingTextWriter.put
This fixes issue 18789.
This commit is contained in:
parent
ece1672ae8
commit
41f78fc1e1
1 changed files with 40 additions and 23 deletions
29
std/stdio.d
29
std/stdio.d
|
@ -3058,14 +3058,13 @@ is empty, throws an `Exception`. In case of an I/O error throws
|
||||||
}
|
}
|
||||||
else static if (c.sizeof == 2)
|
else static if (c.sizeof == 2)
|
||||||
{
|
{
|
||||||
import std.utf : encode, decode;
|
import std.utf : decode;
|
||||||
|
|
||||||
if (orientation_ <= 0)
|
|
||||||
{
|
|
||||||
if (c <= 0x7F)
|
if (c <= 0x7F)
|
||||||
{
|
{
|
||||||
highSurrogateShouldBeEmpty();
|
highSurrogateShouldBeEmpty();
|
||||||
trustedFPUTC(c, handle_);
|
if (orientation_ <= 0) trustedFPUTC(c, handle_);
|
||||||
|
else trustedFPUTWC(c, handle_);
|
||||||
}
|
}
|
||||||
else if (0xD800 <= c && c <= 0xDBFF) // high surrogate
|
else if (0xD800 <= c && c <= 0xDBFF) // high surrogate
|
||||||
{
|
{
|
||||||
|
@ -3082,15 +3081,21 @@ is empty, throws an `Exception`. In case of an I/O error throws
|
||||||
d = decode(rbuf[], index);
|
d = decode(rbuf[], index);
|
||||||
highSurrogate = 0;
|
highSurrogate = 0;
|
||||||
}
|
}
|
||||||
|
if (orientation_ <= 0)
|
||||||
|
{
|
||||||
char[4] wbuf;
|
char[4] wbuf;
|
||||||
immutable size = encode(wbuf, d);
|
immutable size = encode(wbuf, d);
|
||||||
foreach (i; 0 .. size)
|
foreach (i; 0 .. size)
|
||||||
trustedFPUTC(wbuf[i], handle_);
|
trustedFPUTC(wbuf[i], handle_);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
trustedFPUTWC(c, handle_);
|
wchar_t[4 / wchar_t.sizeof] wbuf;
|
||||||
|
immutable size = encode(wbuf, d);
|
||||||
|
foreach (i; 0 .. size)
|
||||||
|
trustedFPUTWC(wbuf[i], handle_);
|
||||||
|
}
|
||||||
|
rbuf8Filled = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else // 32-bit characters
|
else // 32-bit characters
|
||||||
|
@ -3674,6 +3679,18 @@ void main()
|
||||||
}
|
}
|
||||||
assert(std.file.readText!wstring(deleteme) == "ö\U0001F608"w);
|
assert(std.file.readText!wstring(deleteme) == "ö\U0001F608"w);
|
||||||
}
|
}
|
||||||
|
@safe unittest // wchar -> wchar_t
|
||||||
|
{
|
||||||
|
static import std.file;
|
||||||
|
auto deleteme = testFilename();
|
||||||
|
scope(exit) std.file.remove(deleteme);
|
||||||
|
{
|
||||||
|
auto writer = File(deleteme, "w,ccs=UTF-16LE").lockingTextWriter();
|
||||||
|
writer.put("ö"w);
|
||||||
|
writer.put("\U0001F608"w);
|
||||||
|
}
|
||||||
|
assert(std.file.readText!wstring(deleteme) == "ö\U0001F608"w);
|
||||||
|
}
|
||||||
|
|
||||||
@safe unittest
|
@safe unittest
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue