Skip to content

Commit bdde9e6

Browse files
committed
Revert "Add String.titlecase/2 (#10008)"
Unicode says "HH" is not titlecased, which means we need to downcase the rest of the string, which is the behaviour we already have in capitalize. This reverts commit 3be3afb.
1 parent 1fd1577 commit bdde9e6

File tree

2 files changed

+4
-94
lines changed

2 files changed

+4
-94
lines changed

lib/elixir/lib/string.ex

+4-59
Original file line numberDiff line numberDiff line change
@@ -838,23 +838,16 @@ defmodule String do
838838
Converts the first character in the given string to
839839
uppercase and the remainder to lowercase according to `mode`.
840840
841-
`mode` may be `:default`, `:ascii` or `:greek`. The `:default`
842-
mode considers all non-conditional transformations outlined in
843-
the Unicode standard. `:ascii` lowercases only the letters A to Z.
844-
`:greek` includes the context sensitive mappings found in Greek.
845-
846-
More precisely, it converts the first character to titlecase.
847-
If you want to convert only the first character without downcasing
848-
the rest of the string, see `titlecase/2`.
841+
`mode` may be `:default`, `:ascii` or `:greek`. The `:default` mode considers
842+
all non-conditional transformations outlined in the Unicode standard. `:ascii`
843+
lowercases only the letters A to Z. `:greek` includes the context sensitive
844+
mappings found in Greek.
849845
850846
## Examples
851847
852848
iex> String.capitalize("abcd")
853849
"Abcd"
854850
855-
iex> String.capitalize("OS")
856-
"Os"
857-
858851
iex> String.capitalize("fin")
859852
"Fin"
860853
@@ -875,54 +868,6 @@ defmodule String do
875868
char <> downcase(rest, mode)
876869
end
877870

878-
@doc """
879-
Converts only the first character in the given string to
880-
uppercase according to `mode`.
881-
882-
`mode` may be `:default`, `:ascii` or `:greek`. The `:default`
883-
mode considers all non-conditional transformations outlined in
884-
the Unicode standard. `:ascii` lowercases only the letters A to Z.
885-
`:greek` includes the context sensitive mappings found in Greek.
886-
887-
More precisely, it converts the first character to titlecase,
888-
according to the Unicode Standard. This function makes no
889-
attempt to titlecase each word, as those are often language
890-
and locale specific.
891-
892-
If you want to uppercase the first character and downcase the
893-
rest of the string, see `capitalize/2`.
894-
895-
## Examples
896-
897-
iex> String.titlecase("abcd")
898-
"Abcd"
899-
900-
iex> String.titlecase("OS")
901-
"OS"
902-
903-
iex> String.titlecase("fin")
904-
"Fin"
905-
906-
iex> String.titlecase("olá")
907-
"Olá"
908-
909-
"""
910-
@spec titlecase(t, :default | :ascii | :greek) :: t
911-
def titlecase(string, mode \\ :default)
912-
913-
def titlecase(<<char, rest::binary>>, :ascii) when char >= ?a and char <= ?z do
914-
<<char - 32, rest::binary>>
915-
end
916-
917-
def titlecase(string, :ascii) when is_binary(string) do
918-
string
919-
end
920-
921-
def titlecase(string, mode) when is_binary(string) do
922-
{char, rest} = String.Casing.titlecase_once(string, mode)
923-
char <> rest
924-
end
925-
926871
@doc false
927872
@deprecated "Use String.trim_trailing/1 instead"
928873
defdelegate rstrip(binary), to: String.Break, as: :trim_trailing

lib/elixir/test/elixir/string_test.exs

-35
Original file line numberDiff line numberDiff line change
@@ -210,41 +210,6 @@ defmodule StringTest do
210210
assert String.capitalize("aáA", :ascii) == "Aáa"
211211
end
212212

213-
test "titlecase/1" do
214-
assert String.titlecase("") == ""
215-
assert String.titlecase("abc") == "Abc"
216-
assert String.titlecase("ABC") == "ABC"
217-
assert String.titlecase("c b a") == "C b a"
218-
assert String.titlecase("1ABc") == "1ABc"
219-
assert String.titlecase("_aBc1") == "_aBc1"
220-
assert String.titlecase(" aBc1") == " aBc1"
221-
end
222-
223-
test "titlecase/1 with UTF-8" do
224-
assert String.titlecase("àáâ") == "Àáâ"
225-
assert String.titlecase("ÀÁÂ") == "ÀÁÂ"
226-
assert String.titlecase("âáàÕ") == "ÂáàÕ"
227-
assert String.titlecase("ÂÁÀõ") == "ÂÁÀõ"
228-
assert String.titlecase("òóôõö") == "Òóôõö"
229-
assert String.titlecase("ÒÓÔÕÖ") == "ÒÓÔÕÖ"
230-
assert String.titlecase("fin") == "Fin"
231-
end
232-
233-
test "titlecase/2 with ascii" do
234-
assert String.titlecase("àáâ", :ascii) == "àáâ"
235-
assert String.titlecase("aáA", :ascii) == "AáA"
236-
end
237-
238-
test "titlecase/1 with greek final sigma" do
239-
assert String.titlecase("σ") == "Σ"
240-
assert String.titlecase("μΜσΣ") == "ΜΜσΣ"
241-
end
242-
243-
test "titlecase/2 with greek final sigma" do
244-
assert String.titlecase("σ", :greek) == "Σ"
245-
assert String.titlecase("σ ςΠ", :greek) == "Σ ςΠ"
246-
end
247-
248213
test "replace_leading/3" do
249214
assert String.replace_leading("aa abc ", "a", "b") == "bb abc "
250215
assert String.replace_leading("__ abc ", "_", "b") == "bb abc "

0 commit comments

Comments
 (0)