Skip to content

Commit

Permalink
ditch the ccs flag; set locale instead
Browse files Browse the repository at this point in the history
  • Loading branch information
aG0aep6G committed Sep 21, 2020
1 parent b394e32 commit 4b416af
Showing 1 changed file with 35 additions and 9 deletions.
44 changes: 35 additions & 9 deletions std/stdio.d
Original file line number Diff line number Diff line change
Expand Up @@ -3669,20 +3669,46 @@ void main()
}
@safe unittest // char/wchar -> wchar_t
{
import core.stdc.locale : LC_CTYPE, setlocale;
import core.stdc.wchar_ : fwide;
import std.algorithm.searching : any, endsWith;
import std.conv : text;
import std.meta : AliasSeq;
import std.string : fromStringz, stripLeft;
static import std.file;

auto deleteme = testFilename();
scope(exit) std.file.remove(deleteme);
const char* oldCt = () @trusted {
return setlocale(LC_CTYPE, null);
}();
const utf8 = ["en_US.UTF-8", "C.UTF-8", ".65001"].any!((loc) @trusted {
return setlocale(LC_CTYPE, loc.ptr).fromStringz.endsWith(loc);
});
scope(exit) () @trusted { setlocale(LC_CTYPE, oldCt); } ();
version (DIGITAL_MARS_STDIO) // DM can't handle Unicode above U+07FF.
{
auto writer = File(deleteme, "w,ccs=UTF-16LE").lockingTextWriter();
// char -> wchar_t
writer.put("ä");
writer.put("\U0001F607");
// wchar -> wchar_t
writer.put("ö"w);
writer.put("\U0001F608"w);
alias strs = AliasSeq!("\u07FE", "\u07FF"w);
}
else
{
alias strs = AliasSeq!("\U0001F607", "\U0001F608"w);
}
{
auto f = File(deleteme, "w");
version (MICROSOFT_STDIO)
{
() @trusted { setmode(fileno(f.getFP()), _O_U8TEXT); } ();
}
else
{
assert(fwide(f.getFP(), 1) == 1);
}
auto writer = f.lockingTextWriter();
assert(writer.orientation_ == 1);
static foreach (s; strs) writer.put(s);
}
assert(std.file.readText!wstring(deleteme) == "ä\U0001F607ö\U0001F608"w);
assert(std.file.readText!string(deleteme).stripLeft("\uFEFF") ==
text(strs));
}

@safe unittest
Expand Down

0 comments on commit 4b416af

Please sign in to comment.