Blob Blame History Raw
From 0279339ee9a7b61ebcb3f64846d94f8171872737 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Tue, 11 Apr 2017 08:32:04 +0100
Subject: [PATCH] mllib: Add Char.hexdigit function.

Same as the function defined in fish/fish.c.

(cherry picked from commit ef261d69ed199cc07474a36c890f63df461b35a7)
---
 mllib/common_utils.ml  | 19 +++++++++++++++++++
 mllib/common_utils.mli |  4 ++++
 2 files changed, 23 insertions(+)

diff --git a/mllib/common_utils.ml b/mllib/common_utils.ml
index e1d6329..4593614 100644
--- a/mllib/common_utils.ml
+++ b/mllib/common_utils.ml
@@ -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
diff --git a/mllib/common_utils.mli b/mllib/common_utils.mli
index 1cd38ba..ec41a8f 100644
--- a/mllib/common_utils.mli
+++ b/mllib/common_utils.mli
@@ -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. *)
 
-- 
2.9.4