Skip to content

Commit

Permalink
Fix implementation of Char.isCntrl (#168)
Browse files Browse the repository at this point in the history
Fixes #162
  • Loading branch information
melsman committed Mar 4, 2024
1 parent 6624dd4 commit 6d0ae0b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
6 changes: 4 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
32 changes: 17 additions & 15 deletions basis/Char.sml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 6d0ae0b

Please sign in to comment.