From a0458266d7cd5d802b8c51e6a997b4bf0d9beb82 Mon Sep 17 00:00:00 2001 From: Yong He Date: Fri, 3 Nov 2017 09:38:02 -0400 Subject: in-progress work --- source/core/core.natvis | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/core') diff --git a/source/core/core.natvis b/source/core/core.natvis index 3d9ac702e..91fdbb49b 100644 --- a/source/core/core.natvis +++ b/source/core/core.natvis @@ -54,7 +54,7 @@ - + pointer empty RefPtr {*pointer} -- cgit v1.2.3 From 3d90678c8f54b9696c12185481fba27d146b0820 Mon Sep 17 00:00:00 2001 From: Yong He Date: Sat, 4 Nov 2017 15:17:08 -0400 Subject: Fix encoding detection when reading text file. Win32 API could mistakenly report UTF16 when the file is actually UTF8. --- source/core/text-io.cpp | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'source/core') diff --git a/source/core/text-io.cpp b/source/core/text-io.cpp index ec41b8d7d..3e8301fa8 100644 --- a/source/core/text-io.cpp +++ b/source/core/text-io.cpp @@ -194,6 +194,14 @@ namespace Slang this->encoding = determinedEncoding; } + bool HasNullBytes(char * str, int len) + { + for (int i = 0; i < len; i++) + if (str[len] == 0) + return true; + return false; + } + Encoding * StreamReader::DetermineEncoding() { if (buffer.Count() >= 3 && (unsigned char)(buffer[0]) == 0xEF && (unsigned char)(buffer[1]) == 0xBB && (unsigned char)(buffer[2]) == 0xBF) @@ -213,19 +221,9 @@ namespace Slang } else { -#ifdef _WIN32 - int flag = IS_TEXT_UNICODE_SIGNATURE | IS_TEXT_UNICODE_REVERSE_SIGNATURE | IS_TEXT_UNICODE_STATISTICS | IS_TEXT_UNICODE_ASCII16; - int rs = IsTextUnicode(buffer.Buffer(), (int) buffer.Count(), &flag); - if (rs) - { - if (flag & (IS_TEXT_UNICODE_SIGNATURE | IS_TEXT_UNICODE_STATISTICS)) - return Encoding::UTF16; - else if (flag & (IS_TEXT_UNICODE_SIGNATURE | IS_TEXT_UNICODE_STATISTICS)) - return Encoding::UTF16Reversed; - else if (flag & IS_TEXT_UNICODE_ASCII16) - return Encoding::UTF8; - } -#endif + // find null bytes + if (HasNullBytes(buffer.Buffer(), (int)buffer.Count())) + return Encoding::UTF16; return Encoding::UTF8; } } -- cgit v1.2.3 From 1f9686ce87573efdd4ad56040deb2d424fe51929 Mon Sep 17 00:00:00 2001 From: Yong He Date: Sat, 4 Nov 2017 17:03:00 -0400 Subject: determineEncoding bug fix --- source/core/text-io.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'source/core') diff --git a/source/core/text-io.cpp b/source/core/text-io.cpp index 3e8301fa8..d0d0a3cc6 100644 --- a/source/core/text-io.cpp +++ b/source/core/text-io.cpp @@ -196,8 +196,11 @@ namespace Slang bool HasNullBytes(char * str, int len) { - for (int i = 0; i < len; i++) - if (str[len] == 0) + bool hasSeenNull = false; + for (int i = 0; i < len - 1; i++) + if (str[i] == 0) + hasSeenNull = true; + else if (hasSeenNull) return true; return false; } @@ -223,7 +226,9 @@ namespace Slang { // find null bytes if (HasNullBytes(buffer.Buffer(), (int)buffer.Count())) + { return Encoding::UTF16; + } return Encoding::UTF8; } } @@ -231,6 +236,7 @@ namespace Slang void StreamReader::ReadBuffer() { buffer.SetSize(4096); + memset(buffer.Buffer(), 0, buffer.Count() * sizeof(buffer[0])); auto len = stream->Read(buffer.Buffer(), buffer.Count()); buffer.SetSize((int)len); ptr = 0; -- cgit v1.2.3