@@ -23,11 +23,13 @@ defmodule String.Unicode do
23
23
_class , bidi , _decomposition ,
24
24
_numeric_1 , _numeric_2 , _numeric_3 ,
25
25
_bidi_mirror , _unicode_1 , _iso ,
26
- upper , lower , _title ] = :binary . split ( line , ";" , [ :global ] )
26
+ upper , lower , title ] = :binary . split ( line , ";" , [ :global ] )
27
+
28
+ title = :binary . part ( title , 0 , size ( title ) - 1 )
27
29
28
30
cond do
29
- upper != "" or lower != "" ->
30
- { [ { to_binary . ( codepoint ) , to_binary . ( upper ) , to_binary . ( lower ) } | cacc ] , wacc }
31
+ upper != "" or lower != "" or title != "" ->
32
+ { [ { to_binary . ( codepoint ) , to_binary . ( upper ) , to_binary . ( lower ) , to_binary . ( title ) } | cacc ] , wacc }
31
33
bidi in [ "B" , "S" , "WS" ] ->
32
34
{ cacc , [ to_binary . ( codepoint ) | wacc ] }
33
35
true ->
@@ -38,9 +40,9 @@ defmodule String.Unicode do
38
40
special_path = Path . expand ( "../SpecialCasing.txt" , __FILE__ )
39
41
40
42
codes = Enum . reduce File . iterator! ( special_path ) , codes , fn ( line , acc ) ->
41
- [ codepoint , lower , _title , upper , _comment ] = :binary . split ( line , "; " , [ :global ] )
43
+ [ codepoint , lower , title , upper , _comment ] = :binary . split ( line , "; " , [ :global ] )
42
44
key = to_binary . ( codepoint )
43
- :lists . keystore ( key , 1 , acc , { key , to_binary . ( upper ) , to_binary . ( lower ) } )
45
+ :lists . keystore ( key , 1 , acc , { key , to_binary . ( upper ) , to_binary . ( lower ) , to_binary . ( title ) } )
44
46
end
45
47
46
48
seqs_path = Path . expand ( "../NamedSequences.txt" , __FILE__ )
@@ -55,7 +57,7 @@ defmodule String.Unicode do
55
57
56
58
# Downcase
57
59
58
- lc { codepoint , _upper , lower } in list codes , lower && lower != codepoint do
60
+ lc { codepoint , _upper , lower , _title } in list codes , lower && lower != codepoint do
59
61
args = quote do: [ unquote ( codepoint ) <> t ]
60
62
code = quote do: unquote ( lower ) <> downcase ( t )
61
63
def :downcase , args , [ ] , do: code
@@ -71,7 +73,7 @@ defmodule String.Unicode do
71
73
72
74
# Upcase
73
75
74
- lc { codepoint , upper , _lower } in list codes , upper && upper != codepoint do
76
+ lc { codepoint , upper , _lower , _title } in list codes , upper && upper != codepoint do
75
77
args = quote do: [ unquote ( codepoint ) <> t ]
76
78
code = quote do: unquote ( upper ) <> upcase ( t )
77
79
def :upcase , args , [ ] , do: code
@@ -85,6 +87,22 @@ defmodule String.Unicode do
85
87
<< >>
86
88
end
87
89
90
+ # Titlecase once
91
+
92
+ lc { codepoint , _upper , _lower , title } in list codes , title && title != codepoint do
93
+ args = quote do: [ unquote ( codepoint ) <> t ]
94
+ code = quote do: { unquote ( title ) , t }
95
+ def :titlecase_once , args , [ ] , do: code
96
+ end
97
+
98
+ def titlecase_once ( << h , t :: binary >> ) do
99
+ { << h >> , t }
100
+ end
101
+
102
+ def titlecase_once ( << >> ) do
103
+ { << >> , << >> }
104
+ end
105
+
88
106
# Strip
89
107
90
108
def lstrip ( "" ) , do: ""
0 commit comments