Skip to content

Instantly share code, notes, and snippets.

@niku
Last active April 15, 2019 00:28
Show Gist options
  • Save niku/7903925 to your computer and use it in GitHub Desktop.
Save niku/7903925 to your computer and use it in GitHub Desktop.
Unicode から cp932 に変換できない文字を知る 注意: gist には CP932 の文字コードではファイルを置けなかったので ここにある convert-cp932-valid-to-cp932.txt の文字コードは誤っている(UTF-8になっている)
cp932valid =
[
"\uFF5E", # FULL WIDTH TILDE
"\u2225", # PARALLEL TO
"\uFF0D", # FULLWIDTH HYPHEN-MINUS
"\uFFE0", # FULLWIDTH CENT SIGN
"\uFFE1", # FULLWIDTH POUND SIGN
"\uFFE2" # FULLWIDTH NOT SIGN
]
cp932invalid =
[
"\u301C", # WAVE DASH
"\u2016", # DOUBLE VERTICAL LINE
"\u2212", # MINUS SIGN
"\u00A2", # CENT SIGN
"\u00A3", # POUND SIGN
"\u00AC" # NOT SIGN
]
File.write('convert-cp932-valid-to-cp932.txt' , cp932valid.map {|s| s.encode("CP932") }.join("\n"))
File.write('convert-cp932-valid-to-utf8.txt' , cp932valid.map {|s| s.encode("UTF-8") }.join("\n"))
#File.write('convert-cp932-invalid-to-cp932.txt', cp932invalid.map {|s| s.encode("CP932") }.join("\n")) # raise error
File.write('convert-cp932-invalid-to-utf8.txt' , cp932invalid.map {|s| s.encode("UTF-8") }.join("\n"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment