@@ -5,6 +5,21 @@ Copyright 2017-2018 Gandalf Software, Inc., Scott P. Jones
5
5
Licensed under MIT License, see LICENSE.md
6
6
=#
7
7
8
+ _wide_lower_l (c) = ifelse (c > (V6_COMPAT ? 0xdf : 0xde ), c != 0xf7 , c == 0xb5 )
9
+
10
+ @inline _wide_lower_ch (ch) =
11
+ ch <= 0x7f ? _islower_a (ch) : (ch > 0xff ? _islower_u (ch) : _wide_lower_l (ch))
12
+
13
+ @inline _isupper_ch (ch) =
14
+ ch <= 0x7f ? _isupper_a (ch) : (ch > 0xff ? _isupper_u (ch) : _isupper_l (ch))
15
+
16
+ _wide_lower_latin (ch) = (ch == 0xb5 ) | (ch == 0xff ) | (! V6_COMPAT && (ch == 0xdf ))
17
+
18
+ _wide_out_upper (ch) =
19
+ ifelse (ch == 0xb5 , 0x39c ,
20
+ ifelse (ch == 0xff , 0x178 , ifelse (! V6_COMPAT && ch == 0xdf , 0x1e9e , ch% UInt16)))
21
+
22
+
8
23
function uppercase_first (str:: MaybeSub{S} ) where {C<: ASCIICSE ,S<: Str{C} }
9
24
(len = ncodeunits (str)) == 0 && return str
10
25
@preserve str begin
@@ -109,12 +124,6 @@ function uppercase_first(str::MaybeSub{S}) where {C<:LatinCSE,S<:Str{C}}
109
124
end
110
125
end
111
126
112
- @static if V6_COMPAT
113
- _wide_lower_latin (ch) = (ch == 0xb5 ) | (ch == 0xff )
114
- else
115
- _wide_lower_latin (ch) = (ch == 0xb5 ) | (ch == 0xff ) | (ch == 0xdf )
116
- end
117
-
118
127
# Special handling for characters that can't map into Latin1
119
128
function uppercase_first (str:: MaybeSub{S} ) where {C<: _LatinCSE ,S<: Str{C} }
120
129
(len = ncodeunits (str)) == 0 && return str
@@ -128,7 +137,7 @@ function uppercase_first(str::MaybeSub{S}) where {C<:_LatinCSE,S<:Str{C}}
128
137
Str (C, buf)
129
138
elseif _wide_lower_latin (ch)
130
139
buf, out = _allocate (UInt16, len)
131
- set_codeunit! (out, ifelse (ch == 0xb5 , 0x39c , ifelse (ch == 0xff , 0x178 , 0x1e9e ) ))
140
+ set_codeunit! (out, _wide_out_upper (ch))
132
141
# Perform the widen operation on the rest (should be done via SIMD)
133
142
@inbounds for i = 2 : len
134
143
set_codeunit! (out += 2 , get_codeunit (pnt += 2 )% UInt16)
@@ -191,15 +200,7 @@ function _widenupper(beg::Ptr{UInt8}, off, len)
191
200
out = bytoff (out, off)
192
201
while out < fin
193
202
ch = get_codeunit (cur)
194
- if ch == 0xb5
195
- set_codeunit! (out, 0x39c )
196
- elseif ch == 0xff
197
- set_codeunit! (out, 0x178 )
198
- elseif ! V6_COMPAT && (ch == 0xdf )
199
- set_codeunit! (out, 0x1e9e )
200
- else
201
- set_codeunit! (out, _can_upper (ch) ? ch - 0x20 : ch)
202
- end
203
+ set_codeunit! (out, _can_upper (ch) ? ch - 0x20 : _wide_out_upper (ch))
203
204
cur += 1
204
205
out += 2
205
206
end
@@ -319,7 +320,7 @@ function lowercase(str::MaybeSub{S}) where {C<:Union{UCS2_CSEs,UTF32_CSEs},S<:St
319
320
pnt = beg = pointer (str)
320
321
fin = beg + sizeof (str)
321
322
while pnt < fin
322
- _can_lower_ch (get_codeunit (pnt)) && return _lower (C, beg, pnt- beg, ncodeunits (str))
323
+ _isupper_ch (get_codeunit (pnt)) && return _lower (C, beg, pnt- beg, ncodeunits (str))
323
324
pnt += sizeof (CU)
324
325
end
325
326
end
0 commit comments