Current section
Files
Jump to
Current section
Files
lib/exshape/twelve_fifty_two.ex
defmodule Exshape.TwelveFiftyTwo do
def convert(bin), do: convert(bin, [])
@table %{
0x80 => 0x20ac,
0x82 => 0x201a,
0x83 => 0x0192,
0x84 => 0x201e,
0x85 => 0x2026,
0x86 => 0x2020,
0x87 => 0x2021,
0x88 => 0x02c6,
0x89 => 0x2030,
0x8a => 0x0160,
0x8b => 0x2039,
0x8c => 0x0152,
0x8e => 0x017d,
0x91 => 0x2018,
0x92 => 0x2019,
0x93 => 0x201c,
0x94 => 0x201d,
0x95 => 0x2022,
0x96 => 0x2013,
0x97 => 0x2014,
0x98 => 0x02dc,
0x99 => 0x2122,
0x9a => 0x0161,
0x9b => 0x203a,
0x9c => 0x0153,
0x9e => 0x017e,
0x9f => 0x0178
}
defp convert(<<>>, chunks) do
List.to_string(Enum.reverse(chunks))
end
defp convert(<<b, bs :: binary>>, chunks) when b < 0x80 or b > 0x9f do
convert(bs, [b | chunks])
end
Enum.each(0x80..0x9f, fn byte ->
defp convert(<<unquote(byte), bs :: binary>>, chunks) do
convert(bs, [unquote(Map.get(@table, byte, byte)) | chunks])
end
end)
end