mllib: Add Char.hexdigit function.

Same as the function defined in fish/fish.c.
This commit is contained in:
Richard W.M. Jones
2017-04-11 08:32:04 +01:00
parent bb846887de
commit ef261d69ed
2 changed files with 23 additions and 0 deletions

View File

@@ -70,6 +70,25 @@ module Char = struct
| 'a'..'z' -> true
| 'A'..'Z' -> true
| _ -> false
let hexdigit = function
| '0' -> 0
| '1' -> 1
| '2' -> 2
| '3' -> 3
| '4' -> 4
| '5' -> 5
| '6' -> 6
| '7' -> 7
| '8' -> 8
| '9' -> 9
| 'a' | 'A' -> 10
| 'b' | 'B' -> 11
| 'c' | 'C' -> 12
| 'd' | 'D' -> 13
| 'e' | 'E' -> 14
| 'f' | 'F' -> 15
| _ -> -1
end
module String = struct

View File

@@ -43,6 +43,10 @@ module Char : sig
(** Return true if the character is a US ASCII 7 bit alphabetic. *)
val isalnum : char -> bool
(** Return true if the character is a US ASCII 7 bit alphanumeric. *)
val hexdigit : char -> int
(** Return the value of a hex digit. If the char is not in
the set [[0-9a-fA-F]] then this returns [-1]. *)
end
(** Override the Char module from stdlib. *)