Skip to content

Commit dbc6127

Browse files
author
José Valim
committed
Avoid regular expressions
Signed-off-by: José Valim <[email protected]>
1 parent 2eb77e1 commit dbc6127

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

lib/elixir/unicode/unicode.ex

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,15 @@ defmodule String.Unicode do
1414

1515
# WhiteSpace.txt is extracted from Unicode's PropList.txt (just the White_Space property)
1616
prop_path = Path.join(__DIR__, "WhiteSpace.txt")
17-
prop_range_line_regex = ~r/\A([0-9A-F]{4})(?:\.\.([0-9A-F]{4}))?/
17+
1818
whitespace = Enum.reduce File.stream!(prop_path), [], fn(line, acc) ->
19-
case Regex.run(prop_range_line_regex, line, capture: :all_but_first) do
20-
[single] ->
19+
case line |> :binary.split(";") |> hd do
20+
<<first::4-bytes, "..", last::4-bytes, _::binary>> ->
21+
first = String.to_integer(first, 16)
22+
last = String.to_integer(last, 16)
23+
Enum.map(first..last, &to_binary.(Integer.to_string(&1, 16))) ++ acc
24+
<<single::4-bytes, _::binary>> ->
2125
[to_binary.(single) | acc]
22-
[first, last] ->
23-
range = String.to_integer(first, 16)..String.to_integer(last, 16)
24-
acc ++ Enum.map(range, &to_binary.(Integer.to_string(&1, 16)))
25-
_ ->
26-
acc
2726
end
2827
end
2928

0 commit comments

Comments
 (0)