Do not emit BOM for UTF-8 (Solve #88) (#89)

Do not emit BOM for UTF-8 (Solve #88)
merged-on-behalf-of: BBasile <BBasile@users.noreply.github.com>
This commit is contained in:
majiang 2018-02-24 19:45:36 +09:00 committed by The Dlang Bot
parent d514e9f67c
commit e7ea38652b
2 changed files with 16 additions and 2 deletions

View file

@ -1177,11 +1177,10 @@ struct Emitter
void writeStreamStart() @system void writeStreamStart() @system
{ {
immutable(ubyte)[] bom; immutable(ubyte)[] bom;
//Write BOM (always, even for UTF-8) //Write BOM (except for UTF-8)
final switch(encoding_) final switch(encoding_)
{ {
case Encoding.UTF_8: case Encoding.UTF_8:
bom = ByteOrderMarks[BOM.UTF8];
break; break;
case Encoding.UTF_16: case Encoding.UTF_16:
bom = std.system.endian == Endian.littleEndian bom = std.system.endian == Endian.littleEndian

View file

@ -134,3 +134,18 @@ unittest
// Clean up. // Clean up.
remove("output.yaml"); remove("output.yaml");
} }
unittest // #88, #89
{
import dyaml.dumper, dyaml.loader;
import std.file : remove, read;
enum fn = "output.yaml";
scope (exit) fn.remove;
auto dumper = Dumper(fn);
dumper.YAMLVersion = null; // supress directive
dumper.dump(Loader.fromString("Hello world".dup).load);
assert (cast (char[]) fn.read()[0..3] == "Hel");
}