Skip to content

Commit e24b206

Browse files
committed
fix: handle uppercase in string/hex
1 parent 75b498a commit e24b206

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/core/CCString.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,6 +1152,7 @@ let of_hex_exn (s:string) : string =
11521152
let n_of_c = function
11531153
| '0' .. '9' as c -> Char.code c - Char.code '0'
11541154
| 'a' .. 'f' as c -> 10 + Char.code c - Char.code 'a'
1155+
| 'A' .. 'F' as c -> 10 + Char.code c - Char.code 'A'
11551156
| _ -> invalid_arg "string: invalid hex"
11561157
in
11571158
if (String.length s mod 2 <> 0) then invalid_arg "string: hex sequence must be of even length";
@@ -1170,6 +1171,7 @@ let of_hex s = try Some (of_hex_exn s) with Invalid_argument _ -> None
11701171
"0068656c6c6f20776f726c64" (to_hex "\000hello world")
11711172
"" (to_hex "")
11721173
"\000hello world" (of_hex_exn "0068656c6c6f20776f726c64")
1174+
"hello world" (of_hex_exn "68656C6C6F20776F726C64")
11731175
*)
11741176

11751177
(*$Q

0 commit comments

Comments
 (0)