From d85cee91d93cc2ac7cd9c75d5c480813be5fb9ce Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Fri, 30 Aug 2024 20:43:25 +0200 Subject: [PATCH] bytes_to_str() Win32: sync with `EncodingList` in KSC See https://github.com/kaitai-io/kaitai_struct_compiler/blob/5832a81a48e10c3c207748486e09bd58b9aa4000/shared/src/main/scala/io/kaitai/struct/EncodingList.scala --- kaitai/kaitaistream.cpp | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/kaitai/kaitaistream.cpp b/kaitai/kaitaistream.cpp index 414e615..f49da96 100644 --- a/kaitai/kaitaistream.cpp +++ b/kaitai/kaitaistream.cpp @@ -876,22 +876,10 @@ int kaitai::kstream::encoding_to_win_codepage(const char *src_enc) { std::string enc(src_enc); if (enc == "UTF-8") { return CP_UTF8; - } else if (enc == "UTF-16LE") { - return KAITAI_CP_UTF16LE; } else if (enc == "UTF-16BE") { return KAITAI_CP_UTF16BE; - } else if (enc == "IBM437") { - return 437; - } else if (enc == "IBM850") { - return 850; - } else if (enc == "SHIFT_JIS") { - return 932; - } else if (enc == "GB2312") { - return 936; - } else if (enc == "ASCII") { - return 20127; - } else if (enc == "EUC-JP") { - return 20932; + } else if (enc == "UTF-16LE") { + return KAITAI_CP_UTF16LE; } else if (enc == "ISO-8859-1") { return 28591; } else if (enc == "ISO-8859-2") { @@ -934,6 +922,24 @@ int kaitai::kstream::encoding_to_win_codepage(const char *src_enc) { // > The Windows code page number for this encoding is 28606, but kernel32.dll // > does not support this encoding. return KAITAI_CP_UNSUPPORTED; + } else if (enc == "IBM437") { + return 437; + } else if (enc == "IBM850") { + return 850; + } else if (enc == "IBM866") { + return 866; + } else if (enc == "Shift_JIS") { + return 932; + } else if (enc == "GB2312") { + return 936; + } else if (enc == "Big5") { + return 950; + } else if (enc == "ASCII") { + return 20127; + } else if (enc == "EUC-JP") { + return 20932; + } else if (enc == "EUC-KR") { + return 51949; } return KAITAI_CP_UNSUPPORTED;