Add encoding functionality
This commit is contained in:
parent
35dbc8e731
commit
9df067c1a2
1 changed files with 18 additions and 2 deletions
|
@ -2076,10 +2076,26 @@ defmodule ExCoder do
|
|||
|
||||
|
||||
|
||||
def encode(str) do
|
||||
str
|
||||
|
||||
def encode(str) when is_binary str do
|
||||
String.codepoints(str) |> encode
|
||||
end
|
||||
|
||||
def encode([]) do
|
||||
""
|
||||
end
|
||||
|
||||
def encode([<< codepoint :: utf8 >> | rest]) when codepoint >= 32 and codepoint <= 126 do
|
||||
<< codepoint :: utf8 >> <> encode rest
|
||||
end
|
||||
|
||||
def encode([<< codepoint :: utf8 >> | rest]) do
|
||||
"&#x" <> integer_to_binary(codepoint, 16) <> ";" <> encode rest
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
defp strip_numeric(str) do
|
||||
String.split(str, ";")
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue