我怎样才能 encode/decode shift-jis in elixir?
How can I encode/decode shift-jis in elixir?
给定 shift-jis 编码的文本,我如何将其解码为 Elixir 的原生 UTF-8 编码,反之亦然?
Codepagex 库支持这一点。你只需要弄清楚它叫什么 SHIFT_JIS.
Codepagex 使用 unicode.org 中可用的映射。 shift-jis but it's marked as OBSOLETE, so is not available in Codepagex. However, Microsoft's CP932 is also available, which is effectively SHIFT_JIS 有一个,所以你可以使用它。
配置
默认不开启,需要在配置中开启(必要时用mix deps.compile codepagex --force
重新编译):
config :codepagex, :encodings, [
"VENDORS/MICSFT/WINDOWS/CP932"
]
Encode/Decode
iex(1)> shift_jis = "VENDORS/MICSFT/WINDOWS/CP932"
"VENDORS/MICSFT/WINDOWS/CP932"
iex(2)> test = Codepagex.from_string!("テスト", shift_jis)
<<131, 101, 131, 88, 131, 103>>
iex(3)> Codepagex.to_string!(test, shift_jis)
"テスト"
示例回购
我做了一个 example repo 你可以看到它的实际效果。
给定 shift-jis 编码的文本,我如何将其解码为 Elixir 的原生 UTF-8 编码,反之亦然?
Codepagex 库支持这一点。你只需要弄清楚它叫什么 SHIFT_JIS.
Codepagex 使用 unicode.org 中可用的映射。 shift-jis but it's marked as OBSOLETE, so is not available in Codepagex. However, Microsoft's CP932 is also available, which is effectively SHIFT_JIS 有一个,所以你可以使用它。
配置
默认不开启,需要在配置中开启(必要时用mix deps.compile codepagex --force
重新编译):
config :codepagex, :encodings, [
"VENDORS/MICSFT/WINDOWS/CP932"
]
Encode/Decode
iex(1)> shift_jis = "VENDORS/MICSFT/WINDOWS/CP932"
"VENDORS/MICSFT/WINDOWS/CP932"
iex(2)> test = Codepagex.from_string!("テスト", shift_jis)
<<131, 101, 131, 88, 131, 103>>
iex(3)> Codepagex.to_string!(test, shift_jis)
"テスト"
示例回购
我做了一个 example repo 你可以看到它的实际效果。