Handle final sigma unicode exception
Signed-off-by: José Valim <jose.valim@plataformatec.com.br>
This commit is contained in:
@@ -159,6 +159,11 @@ defmodule StringTest do
|
||||
assert String.downcase("áüÈß") == "áüèß"
|
||||
end
|
||||
|
||||
test "downcase/1 with greek final sigma" do
|
||||
assert String.downcase("ΣΣ") == "σς"
|
||||
assert String.downcase("ΣΣ ΣΣ") == "σς σς"
|
||||
end
|
||||
|
||||
test "capitalize/1" do
|
||||
assert String.capitalize("") == ""
|
||||
assert String.capitalize("abc") == "Abc"
|
||||
|
||||
@@ -11,12 +11,12 @@ to_binary = fn
|
||||
|> IO.iodata_to_binary()
|
||||
end
|
||||
|
||||
{codes, non_breakable, decompositions, combining_classes} =
|
||||
Enum.reduce(File.stream!(data_path), {[], [], %{}, %{}}, fn line, {cacc, wacc, dacc, kacc} ->
|
||||
{codes, letters, non_breakable, decompositions, combining_classes} =
|
||||
Enum.reduce(File.stream!(data_path), {[], [], [], %{}, %{}}, fn line, {cacc, lacc, wacc, dacc, kacc} ->
|
||||
[
|
||||
codepoint,
|
||||
_name,
|
||||
_category,
|
||||
category,
|
||||
class,
|
||||
_bidi,
|
||||
decomposition,
|
||||
@@ -40,6 +40,12 @@ end
|
||||
cacc
|
||||
end
|
||||
|
||||
lacc =
|
||||
case category do
|
||||
"L" <> _ -> [to_binary.(codepoint) | lacc]
|
||||
_ -> lacc
|
||||
end
|
||||
|
||||
wacc =
|
||||
case decomposition do
|
||||
"<noBreak>" <> _ -> [to_binary.(codepoint) | wacc]
|
||||
@@ -67,7 +73,7 @@ end
|
||||
{n, ""} -> Map.put(kacc, String.to_integer(codepoint, 16), n)
|
||||
end
|
||||
|
||||
{cacc, wacc, dacc, kacc}
|
||||
{cacc, lacc, wacc, dacc, kacc}
|
||||
end)
|
||||
|
||||
defmodule String.Casing do
|
||||
@@ -86,6 +92,15 @@ defmodule String.Casing do
|
||||
|
||||
def downcase(string) when is_binary(string), do: downcase(string, "")
|
||||
|
||||
for codepoint <- letters do
|
||||
defp downcase(<<0x03A3::utf8, unquote(codepoint), rest::bits>>, acc) do
|
||||
downcase(<<unquote(codepoint), rest::bits>>, <<acc::binary, 0x03C3::utf8>>)
|
||||
end
|
||||
end
|
||||
defp downcase(<<0x03A3::utf8, rest::bits>>, acc) do
|
||||
downcase(rest, <<acc::binary, 0x03C2::utf8>>)
|
||||
end
|
||||
|
||||
for {codepoint, _upper, lower, _title} <- codes, lower && lower != codepoint do
|
||||
defp downcase(<<unquote(codepoint), rest::bits>>, acc) do
|
||||
downcase(rest, acc <> unquote(lower))
|
||||
|
||||
Reference in New Issue
Block a user