The CharMap
structure provides fast, read-only, maps from 8-bit characters
to values.
Synopsis
signature CHAR_MAP
structure CharMap :> CHAR_MAP
Interface
type 'a char_map
val mkCharMap : {default : 'a, bindings : (string * 'a) list} -> 'a char_map
val mapChr : 'a char_map -> char -> 'a
val mapStrChr : 'a char_map -> (string * int) -> 'a
Description
type 'a char_map
-
The type of a mapping from 8-bit characters to
'a
. val mkCharMap : {default : 'a, bindings : (string * 'a) list} -> 'a char_map
-
mkCharMap {default, bindings}
creates a new character map. For each item(s, v)
in thebindings
list, the characters ins
are mapped to the valuev
. If a character is bound multiple times, then the rightmost binding is used. Characters not covered by a binding are mapped to the default value. For example, the following code creates a mapping that classifies characters into lower and upper case letter, digits, and other characters:datatype char_kind = LOWER | UPPER | DIGIT | OTHER val cmap = mkCharMap { default = OTHER, bindings = [ ("abcdefghijklmnopqrstuvwxyz", LOWER), ("ABCDEFGHIJKLMNOPQRSTUVWXYZ", UPPER), ("0123456789", DIGIT) ] }
val mapChr : 'a char_map -> char -> 'a
-
mapChr cmap c
applies the map to the character. val mapStrChr : 'a char_map -> (string * int) -> 'a
-
mapStrChr cmap (s, i)
applies the map to thei`th character in `s
. TheSubscript
exception is raised ifi
is out of bounds.