(* Some important character-based functions for text-processing *) fun isASCII (n) = ((0 <= n) andalso (n <= 255)); fun isSp (ch) = (ch = #" "); fun isLf (ch) = (ch = #"\n"); fun isTab (ch) = (ch = #"\t"); fun isWhite (ch) = isSp (ch) orelse isLf (ch) orelse isTab(ch); fun isDigit (ch) = ((ch >= #"0") andalso (ch <= #"9")); fun isUpper (ch) = ((ch >= #"A") andalso (ch <= #"Z")); fun isLower (ch) = ((ch >= #"a") andalso (ch <= #"z")); fun isAlpha (ch) = isUpper (ch) orelse isLower (ch); fun isAlphaNum (ch) = isAlpha (ch) orelse isDigit (ch); val zero = ord (#"0"); fun digitValue (ch) = let exception BadDigit in if isDigit (ch) then ord(ch) - zero else raise BadDigit end ; fun lower2Upper (ch) = if ((#"a" <= ch) andalso (ch <= #"z")) then chr(ord(ch) - 32) else ch ; fun upper2Lower (ch) = if ((#"A" <= ch) andalso (ch <= #"Z")) then chr(ord(ch) + 32) else ch ; (* Given a function f: char -> char, the following function lifts f to a corresponding function : string -> string *) fun mapstring (f) = let fun G (s) = implode ((map f) (explode (s))) in G end ; (* Given a function f: char -> char list, the following function lifts f to a corresponding function : string -> char list list *) fun mapstr2chlstlst (f) = let fun G (s) = (map f) (explode (s)) in G end ;