fix loading of text files w/o BOM

This commit is contained in:
Vadim Lopatin 2015-01-19 16:24:58 +03:00
parent ed123e2fe2
commit d634aed027
2 changed files with 6 additions and 6 deletions

View File

@ -488,7 +488,7 @@ class LineStream {
uint len = cast(uint)stream.read(buf); uint len = cast(uint)stream.read(buf);
LineStream res = null; LineStream res = null;
if (buf[0] == 0xEF && buf[1] == 0xBB && buf[2] == 0xBF) { if (buf[0] == 0xEF && buf[1] == 0xBB && buf[2] == 0xBF) {
res = new Utf8LineStream(stream, filename, buf, len); res = new Utf8LineStream(stream, filename, buf, len, 3);
} else if (buf[0] == 0x00 && buf[1] == 0x00 && buf[2] == 0xFE && buf[3] == 0xFF) { } else if (buf[0] == 0x00 && buf[1] == 0x00 && buf[2] == 0xFE && buf[3] == 0xFF) {
res = new Utf32beLineStream(stream, filename, buf, len); res = new Utf32beLineStream(stream, filename, buf, len);
} else if (buf[0] == 0xFF && buf[1] == 0xFE && buf[2] == 0x00 && buf[3] == 0x00) { } else if (buf[0] == 0xFF && buf[1] == 0xFE && buf[2] == 0x00 && buf[3] == 0x00) {
@ -502,7 +502,7 @@ class LineStream {
res._bomDetected = true; res._bomDetected = true;
} else { } else {
if (autodetectUTFIfNoBOM) { if (autodetectUTFIfNoBOM) {
res = new Utf8LineStream(stream, filename, buf, len); res = new Utf8LineStream(stream, filename, buf, len, 0);
} else { } else {
res = new AsciiLineStream(stream, filename, buf, len); res = new AsciiLineStream(stream, filename, buf, len);
} }
@ -552,8 +552,8 @@ private class AsciiLineStream : LineStream {
} }
private class Utf8LineStream : LineStream { private class Utf8LineStream : LineStream {
this(InputStream stream, string filename, ubyte[] buf, uint len) { this(InputStream stream, string filename, ubyte[] buf, uint len, int skip) {
super(stream, filename, EncodingType.UTF8, buf, 3, len); super(stream, filename, EncodingType.UTF8, buf, skip, len);
} }
override uint decodeText() { override uint decodeText() {
if (invalidCharFlag) { if (invalidCharFlag) {

View File

@ -115,7 +115,7 @@ class SDLWindow : Window {
_glSupport = new GLSupport(); _glSupport = new GLSupport();
} }
_win = SDL_CreateWindow(toUTF8(_caption).toStringz, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, _win = SDL_CreateWindow(toUTF8(_caption).toStringz, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
700, 500, 800, 600,
windowFlags); windowFlags);
version(USE_OPENGL) { version(USE_OPENGL) {
if (!_win) { if (!_win) {
@ -125,7 +125,7 @@ class SDLWindow : Window {
// recreate w/o OpenGL // recreate w/o OpenGL
windowFlags &= ~SDL_WINDOW_OPENGL; windowFlags &= ~SDL_WINDOW_OPENGL;
_win = SDL_CreateWindow(toUTF8(_caption).toStringz, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, _win = SDL_CreateWindow(toUTF8(_caption).toStringz, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
700, 500, 800, 600,
windowFlags); windowFlags);
} }
} }