diff --git a/lib/elixir/test/elixir/string_test.exs b/lib/elixir/test/elixir/string_test.exs index bd93ff5e71..b275a7eaa8 100644 --- a/lib/elixir/test/elixir/string_test.exs +++ b/lib/elixir/test/elixir/string_test.exs @@ -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" diff --git a/lib/elixir/unicode/properties.ex b/lib/elixir/unicode/properties.ex index 0ac9fc1f6d..f4ea97c732 100644 --- a/lib/elixir/unicode/properties.ex +++ b/lib/elixir/unicode/properties.ex @@ -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 "" <> _ -> [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(<>, <>) + end + end + defp downcase(<<0x03A3::utf8, rest::bits>>, acc) do + downcase(rest, <>) + end + for {codepoint, _upper, lower, _title} <- codes, lower && lower != codepoint do defp downcase(<>, acc) do downcase(rest, acc <> unquote(lower))