mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-08 21:04:20 +00:00
fix gbk encodings on windows (#17843)
This commit is contained in:
@@ -72,6 +72,7 @@ when defined(windows):
|
||||
(875, "cp875"), # IBM EBCDIC Greek Modern
|
||||
(932, "shift_jis"), # ANSI/OEM Japanese; Japanese (Shift-JIS)
|
||||
(936, "gb2312"), # ANSI/OEM Simplified Chinese (PRC, Singapore); Chinese Simplified (GB2312)
|
||||
(936, "gbk"), # Alias for GB2312 encoding
|
||||
(949, "ks_c_5601-1987"), # ANSI/OEM Korean (Unified Hangul Code)
|
||||
(950, "big5"), # ANSI/OEM Traditional Chinese (Taiwan; Hong Kong SAR, PRC); Chinese Traditional (Big5)
|
||||
(1026, "IBM1026"), # IBM EBCDIC Turkish (Latin 5)
|
||||
|
||||
25
tests/stdlib/tencodings.nim
Normal file
25
tests/stdlib/tencodings.nim
Normal file
@@ -0,0 +1,25 @@
|
||||
import std/encodings
|
||||
|
||||
var fromGBK = open("utf-8", "gbk")
|
||||
var toGBK = open("gbk", "utf-8")
|
||||
|
||||
var fromGB2312 = open("utf-8", "gb2312")
|
||||
var toGB2312 = open("gb2312", "utf-8")
|
||||
|
||||
|
||||
block:
|
||||
let data = "\215\237\186\243\178\187\214\170\204\236\212\218\203\174\163\172\194\250\180\178\208\199\195\206\209\185\208\199\186\211"
|
||||
doAssert fromGBK.convert(data) == "醉后不知天在水,满床星梦压星河"
|
||||
|
||||
block:
|
||||
let data = "万两黄金容易得,知心一个也难求"
|
||||
doAssert toGBK.convert(data) == "\205\242\193\189\187\198\189\240\200\221\210\215\181\195\163\172\214\170\208\196\210\187\184\246\210\178\196\209\199\243"
|
||||
|
||||
|
||||
block:
|
||||
let data = "\215\212\208\197\200\203\201\250\182\254\176\217\196\234\163\172\187\225\181\177\203\174\187\247\200\253\199\167\192\239"
|
||||
doAssert fromGB2312.convert(data) == "自信人生二百年,会当水击三千里"
|
||||
|
||||
block:
|
||||
let data = "谁怕?一蓑烟雨任平生"
|
||||
doAssert toGB2312.convert(data) == "\203\173\197\194\163\191\210\187\203\242\209\204\211\234\200\206\198\189\201\250"
|
||||
Reference in New Issue
Block a user