Merge: Added new `is_hexdigit` service on `Char`
authorJean Privat <jean@pryen.org>
Tue, 8 Dec 2015 21:19:58 +0000 (16:19 -0500)
committerJean Privat <jean@pryen.org>
Tue, 8 Dec 2015 21:19:58 +0000 (16:19 -0500)
Simple addition to the services of `Char`, might be useful

Pull-Request: #1884
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>
Reviewed-by: Jean Privat <jean@pryen.org>

lib/core/text/abstract_text.nit

index 76823e2..cacee99 100644 (file)
@@ -1709,6 +1709,16 @@ redef class Char
                return (self >= 'a' and self <= 'z') or (self >= 'A' and self <= 'Z')
        end
 
+       # Is `self` an hexadecimal digit ?
+       #
+       #     assert 'A'.is_hexdigit
+       #     assert not 'G'.is_hexdigit
+       #     assert 'a'.is_hexdigit
+       #     assert not 'g'.is_hexdigit
+       #     assert '5'.is_hexdigit
+       fun is_hexdigit: Bool do return (self >= '0' and self <= '9') or (self >= 'A' and self <= 'F') or
+                                       (self >= 'a' and self <= 'f')
+
        # Returns true if the char is an alpha or a numeric digit
        #
        #     assert 'a'.is_alphanumeric