Skip to content

Commit 475df06

Browse files
hhugogasche
authored andcommitted
stdlib: cleanup in Char.ml by using char range patterns (#9221)
stdlib/char.ml: [minor] use range patterns for {lowercase,uppercase} functions
1 parent 2fba4c0 commit 475df06

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

Diff for: stdlib/char.ml

+18-20
Original file line numberDiff line numberDiff line change
@@ -46,29 +46,27 @@ let escaped = function
4646
bytes_unsafe_set s 3 (unsafe_chr (48 + n mod 10));
4747
unsafe_to_string s
4848

49-
let lowercase c =
50-
if (c >= 'A' && c <= 'Z')
51-
|| (c >= '\192' && c <= '\214')
52-
|| (c >= '\216' && c <= '\222')
53-
then unsafe_chr(code c + 32)
54-
else c
49+
let lowercase = function
50+
| 'A' .. 'Z'
51+
| '\192' .. '\214'
52+
| '\216' .. '\222' as c ->
53+
unsafe_chr(code c + 32)
54+
| c -> c
5555

56-
let uppercase c =
57-
if (c >= 'a' && c <= 'z')
58-
|| (c >= '\224' && c <= '\246')
59-
|| (c >= '\248' && c <= '\254')
60-
then unsafe_chr(code c - 32)
61-
else c
56+
let uppercase = function
57+
| 'a' .. 'z'
58+
| '\224' .. '\246'
59+
| '\248' .. '\254' as c ->
60+
unsafe_chr(code c - 32)
61+
| c -> c
6262

63-
let lowercase_ascii c =
64-
if (c >= 'A' && c <= 'Z')
65-
then unsafe_chr(code c + 32)
66-
else c
63+
let lowercase_ascii = function
64+
| 'A' .. 'Z' as c -> unsafe_chr(code c + 32)
65+
| c -> c
6766

68-
let uppercase_ascii c =
69-
if (c >= 'a' && c <= 'z')
70-
then unsafe_chr(code c - 32)
71-
else c
67+
let uppercase_ascii = function
68+
| 'a' .. 'z' as c -> unsafe_chr(code c - 32)
69+
| c -> c
7270

7371
type t = char
7472

0 commit comments

Comments
 (0)