@@ -107,16 +107,19 @@ defmodule Recase.Generic do
107
107
end )
108
108
109
109
Enum . each ( ?A .. ?Z , fn char ->
110
- defp do_split ( << unquote ( char ) , rest :: binary >> , { "" , acc } ) ,
111
- do: do_split ( rest , { << unquote ( char ) :: utf8 >> , acc } )
110
+ defp do_split ( << unquote ( char ) , _ :: binary >> = input , { "" , acc } ) do
111
+ { upcase_streak , rest } = upcase_streak ( input , "" )
112
+
113
+ case byte_size ( upcase_streak ) do
114
+ 1 ->
115
+ do_split ( rest , { << unquote ( char ) :: utf8 >> , acc } )
112
116
113
- defp do_split ( << unquote ( char ) , rest :: binary >> , { curr , acc } ) do
114
- << c :: utf8 , _ :: binary >> = String . reverse ( curr )
117
+ 2 ->
118
+ << c1 :: utf8 , c2 :: utf8 >> = upcase_streak
119
+ do_split ( rest , { << c2 :: utf8 >> , [ c1 | acc ] } )
115
120
116
- if c in ?A .. ?Z do
117
- do_split ( rest , { curr <> << unquote ( char ) :: utf8 >> , acc } )
118
- else
119
- do_split ( rest , { << unquote ( char ) :: utf8 >> , [ curr | acc ] } )
121
+ _ ->
122
+ do_split ( rest , { << upcase_streak :: binary >> , acc } )
120
123
end
121
124
end
122
125
end )
@@ -145,4 +148,11 @@ defmodule Recase.Generic do
145
148
do_split ( rest , { curr <> << char :: utf8 >> , acc } )
146
149
end
147
150
end
151
+
152
+ Enum . each ( ?A .. ?Z , fn char ->
153
+ defp upcase_streak ( << unquote ( char ) , rest :: binary >> , curr ) ,
154
+ do: upcase_streak ( rest , curr <> << unquote ( char ) :: utf8 >> )
155
+ end )
156
+
157
+ defp upcase_streak ( rest , upcase_streak ) , do: { upcase_streak , rest }
148
158
end
0 commit comments