defmodule Alphanumeric2cjk do @moduledoc """ Documentation for `Alphanumeric2cjk`. """ # one more digit for avoid left padding zero problem @cjk_s 0x4E00 - 1 @cjk_e 0x9FFF @codes '-0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' @doc """ Compress from alphanumceric string. ## Examples iex> Alphanumeric2cjk.from_an("abc123DEF") "伫斪犌塱" """ def from_an(str) do str |> String.to_charlist() |> Enum.map(fn x -> Enum.find_index(@codes, &(&1 == x)) end) |> Integer.undigits(length(@codes)) |> Integer.digits(@cjk_e - @cjk_s) |> Enum.map_join(fn p -> <
> end)
end
@doc """
Decompress from cjk string.
## Examples
iex> Alphanumeric2cjk.from_cjk("伫斪犌塱")
"abc123DEF"
"""
def from_cjk(str) do
for <