Skip to content

Commit 3006ace

Browse files
author
José Valim
committed
Rely only on UnicodeData for composition/decomposition
Signed-off-by: José Valim <[email protected]>
1 parent b558b90 commit 3006ace

File tree

5 files changed

+273
-3253
lines changed

5 files changed

+273
-3253
lines changed

lib/elixir/lib/string.ex

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ defmodule String do
261261
262262
"""
263263
@spec split(t) :: [t]
264-
defdelegate split(binary), to: String.Unicode
264+
defdelegate split(binary), to: String.Break
265265

266266
@doc ~S"""
267267
Divides a string into substrings based on a pattern.
@@ -449,7 +449,7 @@ defmodule String do
449449
end
450450

451451
defp do_split_at(string, position) do
452-
{byte_size, rest} = String.Graphemes.split_at(string, position)
452+
{byte_size, rest} = String.Unicode.split_at(string, position)
453453
{binary_part(string, 0, byte_size), rest || ""}
454454
end
455455

@@ -529,7 +529,7 @@ defmodule String do
529529
530530
"""
531531
@spec upcase(t) :: t
532-
defdelegate upcase(binary), to: String.Unicode
532+
defdelegate upcase(binary), to: String.Casing
533533

534534
@doc """
535535
Converts all characters in the given string to lowercase.
@@ -547,7 +547,7 @@ defmodule String do
547547
548548
"""
549549
@spec downcase(t) :: t
550-
defdelegate downcase(binary), to: String.Unicode
550+
defdelegate downcase(binary), to: String.Casing
551551

552552
@doc """
553553
Converts the first character in the given string to
@@ -572,7 +572,7 @@ defmodule String do
572572
"""
573573
@spec capitalize(t) :: t
574574
def capitalize(string) when is_binary(string) do
575-
{char, rest} = String.Unicode.titlecase_once(string)
575+
{char, rest} = String.Casing.titlecase_once(string)
576576
char <> downcase(rest)
577577
end
578578

@@ -587,7 +587,7 @@ defmodule String do
587587
588588
"""
589589
@spec rstrip(t) :: t
590-
defdelegate rstrip(binary), to: String.Unicode
590+
defdelegate rstrip(binary), to: String.Break
591591

592592
@doc """
593593
Returns a string where all trailing `char`s have been removed.
@@ -759,7 +759,7 @@ defmodule String do
759759
"abc "
760760
761761
"""
762-
defdelegate lstrip(binary), to: String.Unicode
762+
defdelegate lstrip(binary), to: String.Break
763763

764764
@doc """
765765
Returns a string where all leading `char`s have been removed.
@@ -1184,7 +1184,7 @@ defmodule String do
11841184
11851185
"""
11861186
@spec graphemes(t) :: [grapheme]
1187-
defdelegate graphemes(string), to: String.Graphemes
1187+
defdelegate graphemes(string), to: String.Unicode
11881188

11891189
@compile {:inline, next_grapheme: 1, next_grapheme_size: 1}
11901190

@@ -1223,7 +1223,7 @@ defmodule String do
12231223
12241224
"""
12251225
@spec next_grapheme_size(t) :: {pos_integer, t} | nil
1226-
defdelegate next_grapheme_size(string), to: String.Graphemes
1226+
defdelegate next_grapheme_size(string), to: String.Unicode
12271227

12281228
@doc """
12291229
Returns the first grapheme from a utf8 string,
@@ -1283,7 +1283,7 @@ defmodule String do
12831283
12841284
"""
12851285
@spec length(t) :: non_neg_integer
1286-
defdelegate length(string), to: String.Graphemes
1286+
defdelegate length(string), to: String.Unicode
12871287

12881288
@doc """
12891289
Returns the grapheme at the `position` of the given utf8 `string`.
@@ -1322,7 +1322,7 @@ defmodule String do
13221322
end
13231323

13241324
defp do_at(string, position) do
1325-
case String.Graphemes.split_at(string, position) do
1325+
case String.Unicode.split_at(string, position) do
13261326
{_, nil} -> nil
13271327
{_, rest} -> first(rest)
13281328
end
@@ -1372,10 +1372,10 @@ defmodule String do
13721372
end
13731373

13741374
def slice(string, start, len) when start >= 0 and len >= 0 do
1375-
case String.Graphemes.split_at(string, start) do
1375+
case String.Unicode.split_at(string, start) do
13761376
{_, nil} -> ""
13771377
{start_bytes, rest} ->
1378-
{len_bytes, _} = String.Graphemes.split_at(rest, len)
1378+
{len_bytes, _} = String.Unicode.split_at(rest, len)
13791379
binary_part(string, start_bytes, len_bytes)
13801380
end
13811381
end
@@ -1443,7 +1443,7 @@ defmodule String do
14431443
def slice("", _.._), do: ""
14441444

14451445
def slice(string, first..-1) when first >= 0 do
1446-
case String.Graphemes.split_at(string, first) do
1446+
case String.Unicode.split_at(string, first) do
14471447
{_, nil} ->
14481448
""
14491449
{start_bytes, _} ->

lib/elixir/test/elixir/string_test.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ defmodule StringTest do
313313
end
314314

315315
test "normalize" do
316+
assert String.normalize("ŝ", :nfd) == "ŝ"
316317
assert String.normalize("ḇravô", :nfd) == "ḇravô"
317318
assert String.normalize("ṩierra", :nfd) == "ṩierra"
318319
assert String.normalize("뢴", :nfd) == "뢴"

0 commit comments

Comments
 (0)