Update source/dyaml/stream.d to conform to the existing coding style

This commit is contained in:
ZombineDev 2016-12-10 20:07:14 +02:00
parent 21c2f11a4f
commit b01e99d8e6

View file

@ -1,6 +1,7 @@
module dyaml.stream; module dyaml.stream;
enum BOM { enum BOM
{
UTF8, /// UTF-8 UTF8, /// UTF-8
UTF16LE, /// UTF-16 Little Endian UTF16LE, /// UTF-16 Little Endian
UTF16BE, /// UTF-16 Big Endian UTF16BE, /// UTF-16 Big Endian
@ -12,34 +13,40 @@ import std.system;
private enum int NBOMS = 5; private enum int NBOMS = 5;
immutable Endian[NBOMS] BOMEndian = immutable Endian[NBOMS] BOMEndian =
[ std.system.endian, [
std.system.endian,
Endian.littleEndian, Endian.bigEndian, Endian.littleEndian, Endian.bigEndian,
Endian.littleEndian, Endian.bigEndian Endian.littleEndian, Endian.bigEndian
]; ];
immutable ubyte[][NBOMS] ByteOrderMarks = immutable ubyte[][NBOMS] ByteOrderMarks =
[ [0xEF, 0xBB, 0xBF], [
[0xEF, 0xBB, 0xBF],
[0xFF, 0xFE], [0xFF, 0xFE],
[0xFE, 0xFF], [0xFE, 0xFF],
[0xFF, 0xFE, 0x00, 0x00], [0xFF, 0xFE, 0x00, 0x00],
[0x00, 0x00, 0xFE, 0xFF] [0x00, 0x00, 0xFE, 0xFF]
]; ];
interface YStream { interface YStream
{
void writeExact(const void* buffer, size_t size); void writeExact(const void* buffer, size_t size);
size_t write(const(ubyte)[] buffer); size_t write(const(ubyte)[] buffer);
void flush(); void flush();
@property bool writeable(); @property bool writeable();
} }
class YMemoryStream : YStream { class YMemoryStream : YStream
{
ubyte[] data; ubyte[] data;
void writeExact(const void* buffer, size_t size) { void writeExact(const void* buffer, size_t size)
{
data ~= cast(ubyte[])buffer[0 .. size]; data ~= cast(ubyte[])buffer[0 .. size];
} }
size_t write(const(ubyte)[] buffer) { size_t write(const(ubyte)[] buffer)
{
data ~= buffer; data ~= buffer;
return buffer.length; return buffer.length;
} }
@ -49,31 +56,37 @@ class YMemoryStream : YStream {
@property bool writeable() { return true; } @property bool writeable() { return true; }
} }
class YFile : YStream { class YFile : YStream
{
static import std.stdio; static import std.stdio;
std.stdio.File file; std.stdio.File file;
this(string fn) { this(string fn)
{
this.file = std.stdio.File(fn, "w"); this.file = std.stdio.File(fn, "w");
} }
void writeExact(const void* buffer, size_t size) { void writeExact(const void* buffer, size_t size)
{
this.file.rawWrite(cast(const) buffer[0 .. size]); this.file.rawWrite(cast(const) buffer[0 .. size]);
} }
size_t write(const(ubyte)[] buffer) { size_t write(const(ubyte)[] buffer)
{
this.file.rawWrite(buffer); this.file.rawWrite(buffer);
return buffer.length; return buffer.length;
} }
void flush() { void flush()
{
this.file.flush(); this.file.flush();
} }
@property bool writeable() { return true; } @property bool writeable() { return true; }
} }
unittest { unittest
{
import dyaml.dumper, dyaml.loader, dyaml.node; import dyaml.dumper, dyaml.loader, dyaml.node;
import std.file : readText, remove; import std.file : readText, remove;