NetMD.SJIS (NetMD v0.1.0)

Copy Markdown View Source

Shift-JIS codec for NetMD titles.

Table-driven, generated from jconv (the codec netmd-js uses) by tools/gen_sjis_tables.ts, including its quirks: unmappable characters encode to the katakana middle dot 0x8145 and invalid byte sequences decode to .

One divergence: characters outside the Basic Multilingual Plane encode to a single where the reference produces two.

Summary

Functions

Decode Shift-JIS bytes to a UTF-8 string.

Encode a UTF-8 string to Shift-JIS bytes.

Byte length of the string once encoded to Shift-JIS.

Functions

decode(data)

@spec decode(binary()) :: String.t()

Decode Shift-JIS bytes to a UTF-8 string.

iex> NetMD.SJIS.decode(<<0x83, 0x4A, 0x83, 0x69>>)
"カナ"

encode(string)

@spec encode(String.t()) :: binary()

Encode a UTF-8 string to Shift-JIS bytes.

iex> NetMD.SJIS.encode("abc")
"abc"

iex> NetMD.SJIS.encode("カナ")
<<0x83, 0x4A, 0x83, 0x69>>

encoded_length(string)

@spec encoded_length(String.t()) :: non_neg_integer()

Byte length of the string once encoded to Shift-JIS.