https://git.reactos.org/?p=reactos.git;a=commitdiff;h=142d16c8a0fd7c02a0cb1…
commit 142d16c8a0fd7c02a0cb195ae6929eadae522fb4
Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
AuthorDate: Fri Nov 1 04:41:48 2019 +0900
Commit: GitHub <noreply(a)github.com>
CommitDate: Fri Nov 1 04:41:48 2019 +0900
[NOTEPAD] Prioritize ASCII over UTF-8 (#2006)
CORE-16467
---
base/applications/notepad/text.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/base/applications/notepad/text.c b/base/applications/notepad/text.c
index d22cf4817ee..0afdde89b6c 100644
--- a/base/applications/notepad/text.c
+++ b/base/applications/notepad/text.c
@@ -48,6 +48,19 @@ static BOOL Append(LPWSTR *ppszText, DWORD *pdwTextLen, LPCWSTR
pszAppendText, D
return TRUE;
}
+BOOL IsTextNonZeroASCII(const void *pText, DWORD dwSize)
+{
+ const signed char *pBytes = pText;
+ while (dwSize-- > 0)
+ {
+ if (*pBytes <= 0)
+ return FALSE;
+
+ ++pBytes;
+ }
+ return TRUE;
+}
+
ENCODING AnalyzeEncoding(const char *pBytes, DWORD dwSize)
{
INT flags = IS_TEXT_UNICODE_STATISTICS;
@@ -55,6 +68,11 @@ ENCODING AnalyzeEncoding(const char *pBytes, DWORD dwSize)
if (dwSize <= 1)
return ENCODING_ANSI;
+ if (IsTextNonZeroASCII(pBytes, dwSize))
+ {
+ return ENCODING_ANSI;
+ }
+
if (IsTextUnicode(pBytes, dwSize, &flags))
{
return ENCODING_UTF16LE;