From b5dccf7bfc3c345501551229a4e65c6726d3b78b Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Mon, 3 Aug 2020 16:07:07 -0400 Subject: Support UTF-16BE-BOM --- tools/msgenc/msgenc.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/msgenc/msgenc.cpp b/tools/msgenc/msgenc.cpp index bc5e9eab..314fbce1 100644 --- a/tools/msgenc/msgenc.cpp +++ b/tools/msgenc/msgenc.cpp @@ -49,7 +49,7 @@ u16string ReadTextFileU16LE(path filename) { ss << "read error in " << filename; throw runtime_error(ss.str()); } - if (bom != u'\uFEFF') { + if (bom != u'\uFEFF' && bom != u'\uFFFE') { stringstream ss; ss << "invalid bom in " << filename; throw runtime_error(ss.str()); @@ -63,7 +63,12 @@ u16string ReadTextFileU16LE(path filename) { ss << "read error in " << filename; throw runtime_error(ss.str()); } - buf[count] = L'\0'; + if (bom == u'\uFFFE') { + for (int i = 0; i < count; i++) { + buf[i] = (buf[i] << 8) | (buf[i] >> 8); + } + } + buf[count] = u'\0'; fclose(file); return buf; } -- cgit v1.2.3