From c09ee513b6e31ca01c9693388978460dc316d3bf Mon Sep 17 00:00:00 2001 From: Martin Elsman Date: Mon, 4 Mar 2024 20:40:32 +0100 Subject: [PATCH] Fix implementation of Char.isCntrl --- NEWS.md | 6 ++++-- basis/Char.sml | 32 +++++++++++++++++--------------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/NEWS.md b/NEWS.md index 4701af6fb..ee16e5e43 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,7 +1,9 @@ ## MLKit NEWS -* mael 2024-03-04: Various cleanup and fixes. Infinite reals and NaNs - may now be parsed as specified in the basis library manual. +* mael 2024-03-04: Fix issue with Char.isCntrl (issue #162). + +* mael 2024-03-04: Cleanup and fixes. Infinite reals and NaNs may now + be parsed as specified in the Basis Bibrary manual (issue #163). ### MLKit version 4.7.8 is released diff --git a/basis/Char.sml b/basis/Char.sml index a95b2309a..65e4eb9b0 100644 --- a/basis/Char.sml +++ b/basis/Char.sml @@ -47,25 +47,27 @@ struct (* depends on StrBase *) fun notContains s c = not(contains s c) - fun isLower c = #"a" <= c andalso c <= #"z" + fun isAscii c = c <= #"\127" + fun isUpper c = #"A" <= c andalso c <= #"Z" + fun isLower c = #"a" <= c andalso c <= #"z" fun isDigit c = #"0" <= c andalso c <= #"9" - fun isAlpha c = isLower c orelse isUpper c - fun isHexDigit c = #"0" <= c andalso c <= #"9" - orelse #"a" <= c andalso c <= #"f" - orelse #"A" <= c andalso c <= #"F" + fun isAlpha c = isUpper c orelse isLower c fun isAlphaNum c = isAlpha c orelse isDigit c - fun isPrint c = c >= #" " andalso c < #"\127" - fun isSpace c = c = #" " orelse #"\009" <= c andalso c <= #"\013" - fun isGraph c = isPrint c andalso not (isSpace c) + fun isHexDigit c = isDigit c + orelse #"a" <= c andalso c <= #"f" + orelse #"A" <= c andalso c <= #"F" + fun isGraph c = #"!" <= c andalso c <= #"~" + fun isPrint c = isGraph c orelse c = #" " fun isPunct c = isGraph c andalso not (isAlphaNum c) - fun isAscii c = c <= #"\127" - fun isCntrl c = c < #" " orelse c >= #"\127" - - fun toLower c = if #"A" <= c andalso c <= #"Z" then unsafe_chr(ord c + 32) - else c - fun toUpper c = if #"a" <= c andalso c <= #"z" then unsafe_chr(ord c - 32) - else c + fun isCntrl c = isAscii c andalso not (isPrint c) + fun isSpace c = #"\t" <= c andalso c <= #"\r" + orelse c = #" " + + fun toLower c = if isUpper c then unsafe_chr(ord c + 32) + else c + fun toUpper c = if isLower c then unsafe_chr(ord c - 32) + else c fun toString c = StrBase.toMLescape c