Overview
The Unicode properties and case mappings of a character, R6RS section 11.11.
(char-alphabetic? #\ä) ; #t
(char-upcase #\ä) ; #\Ä
(char-ci=? #\ſ #\S) ; #t: the long s folds to s
(char-general-category #\€) ; 'Sc
(digit-value #\٣) ; (Some 3)
(std prelude) re-exports this module, so a program has its names
without an import.
Tables. The properties are from the Unicode Character
Database, generated by tools/unicode/chars.bjo. They do not use
.NET or ICU, so every platform gives the same answers, and they are of the same
Unicode version as (std unicode normalize), casefold and
grapheme. The version is chars-unicode-version.
One character to one character. The case mappings here are
the simple ones of UnicodeData.txt and CaseFolding.txt. A
mapping that gives more than one character is not one of them: ß
upcases to itself, not to SS. To fold whole strings, use
string-foldcase of (std unicode casefold).
Culture. No function depends on a culture. I downcases
to i in Turkish text too.
Cost. Every function is two reads into the tables and one into
the kind of the character, about a nanosecond. The tables are compiled
into the assembly with include-bytes, so the first call in a
process only loads the module, about 0.4 ms.
See also: char-alphabetic?, char-upcase, char-foldcase, char-general-category, chars-unicode-version
Reference
Functions
char-upcase
function ↑ Functions
(: char-upcase (-> char char))
(char-upcase c)
The uppercase form of a character.
c- The character.
- returns
- Its simple uppercase mapping, or c itself when it has none.
(char-upcase #\a) ; #\A
(char-upcase #\dž) ; #\DŽ
(char-upcase #\ß) ; #\ß
The Simple_Uppercase_Mapping of UnicodeData.txt. A mapping to more
than one character is not a simple mapping, so ß maps to itself.
See also: char-downcase, char-titlecase, char-upper-case?
char-downcase
function ↑ Functions
(: char-downcase (-> char char))
(char-downcase c)
The lowercase form of a character.
c- The character.
- returns
- Its simple lowercase mapping, or c itself when it has none.
The Simple_Lowercase_Mapping of UnicodeData.txt. To compare
without case, use char-foldcase: the fold also maps ς and
ſ, which are lowercase already.
See also: char-upcase, char-foldcase, char-lower-case?
char-titlecase
function ↑ Functions
(: char-titlecase (-> char char))
(char-titlecase c)
The titlecase form of a character.
c- The character.
- returns
- Its simple titlecase mapping, or c itself when it has none.
(char-titlecase #\dž) ; #\Dž
(char-titlecase #\a) ; #\A
The Simple_Titlecase_Mapping of UnicodeData.txt, which is the
uppercase mapping for every character but the few with a titlecase form
of their own, such as the Latin digraphs: dž and DŽ both
map to Dž.
See also: char-upcase, char-title-case?
char-foldcase
function ↑ Functions
(: char-foldcase (-> char char))
(char-foldcase c)
A character with its case folded, for comparing without case.
c- The character.
- returns
- Its simple case fold, or c itself when it has none.
(char-foldcase #\A) ; #\a
(char-foldcase #\ς) ; #\σ
(char-foldcase #\ſ) ; #\s
(char-foldcase #\ß) ; #\ß
The simple case folding of CaseFolding.txt: the mappings of
status C and S, as R6RS specifies. Most characters fold to their
lowercase form. ς, ſ and the micro sign fold to
σ, s and μ, so the three Greek sigmas compare
equal without case. ß folds to itself: its full fold, ss,
is two characters, and is string-foldcase’s.
Every char-ci comparison folds both sides with it.
See also: char-ci=?, char-downcase
char-alphabetic?
function ↑ Functions
(: char-alphabetic? (-> char bool))
(char-alphabetic? c)
Whether a character is alphabetic.
c- The character.
- returns
- #t when c has the Unicode property Alphabetic.
(char-alphabetic? #\a) ; #t
(char-alphabetic? #\Ⅷ) ; #t: a letter number
(char-alphabetic? #\1) ; #f
Alphabetic is the letters, Lu, Ll, Lt, Lm and Lo, and also the letter numbers (Nl), such as the Roman numerals, and the marks and other characters that are Other_Alphabetic, such as the vowel signs of many scripts.
See also: char-numeric?, char-general-category
char-numeric?
function ↑ Functions
(: char-numeric? (-> char bool))
(char-numeric? c)
Whether a character is a number of any kind.
c- The character.
- returns
- #t when c is in category Nd, Nl or No.
Wider than decimal digits: ½ and Ⅶ are numeric.
digit-value returns a value only for decimal digits.
See also: digit-value, char-alphabetic?
char-whitespace?
function ↑ Functions
(: char-whitespace? (-> char bool))
(char-whitespace? c)
Whether a character is white space.
c- The character.
- returns
- #t when c has the Unicode property White_Space.
The separators (Zs, Zl and Zp), and tab, line feed, vertical tab, form feed, carriage return and U+0085 NEXT LINE.
See also: char-general-category
char-upper-case?
function ↑ Functions
(: char-upper-case? (-> char bool))
(char-upper-case? c)
Whether a character is uppercase.
c- The character.
- returns
- #t when c has the Unicode property Uppercase.
Uppercase is category Lu and the characters that are Other_Uppercase,
such as the circled letters Ⓐ to Ⓩ. A titlecase letter
such as Dž is neither uppercase nor lowercase.
See also: char-lower-case?, char-title-case?, char-upcase
char-lower-case?
function ↑ Functions
(: char-lower-case? (-> char bool))
(char-lower-case? c)
Whether a character is lowercase.
c- The character.
- returns
- #t when c has the Unicode property Lowercase.
Lowercase is category Ll and the characters that are Other_Lowercase,
such as ª, º and the modifier letters ʰ and
ˢ.
See also: char-upper-case?, char-downcase
char-title-case?
function ↑ Functions
(: char-title-case? (-> char bool))
(char-title-case? c)
Whether a character is a titlecase letter.
c- The character.
- returns
- #t when c is in category Lt, such as Dž.
See also: char-titlecase, char-upper-case?
digit-value
function ↑ Functions
(: digit-value (-> char (Option int)))
(digit-value c)
The value of a decimal digit.
c- The character.
- returns
- (Some n), n from 0 to 9, when c is a decimal digit (category Nd); None otherwise.
(digit-value #\7) ; (Some 7)
(digit-value #\٣) ; (Some 3), ARABIC-INDIC DIGIT THREE
(digit-value #\½) ; None
Narrower than char-numeric?: ½ is numeric and has no
digit value. Any decimal digit counts, not only 0 to 9 of ASCII.
See also: char-numeric?
char-general-category
function ↑ Functions
(: char-general-category (-> char Symbol))
(char-general-category c)
The Unicode general category of a character.
c- The character.
- returns
- The two-letter category as a symbol: 'Lu, 'Ll, 'Nd, 'Zs and the rest.
(char-general-category #\a) ; 'Ll
(char-general-category #\space) ; 'Zs
One of the thirty categories R6RS names: Lu Ll Lt Lm Lo, Mn Mc Me,
Nd Nl No, Pc Pd Ps Pe Pi Pf Po, Sm Sc Sk So, Zs Zl Zp, Cc Cf Cs Co
and Cn. An unassigned code point returns 'Cn. A symbol, so it
is compared with = or eq? at the cost of a reference
comparison.
See also: char-alphabetic?, char-numeric?, char-whitespace?
char-ci=?
function ↑ Functions
(: char-ci=? (-> char char bool))
(char-ci=? a b)
Whether two characters are the same, ignoring case.
a- The first character.
b- The second.
- returns
- #t when a and b are the same after char-foldcase.
(char-ci=? #\a #\A) ; #t
(char-ci=? #\ς #\Σ) ; #t
Both sides go through char-foldcase and are then compared by
code point, as every char-ci comparison does. Binary, where
R6RS’s is n-ary.
See also: char=?, char-foldcase
char-ci<?
function ↑ Functions
(: char-ci<? (-> char char bool))
(char-ci<? a b)
Whether one character comes before another, ignoring case.
a- The first character.
b- The second.
- returns
- #t when a's folded code point is less than b's.
See also: char<?, char-foldcase
char-ci>?
function ↑ Functions
(: char-ci>? (-> char char bool))
(char-ci>? a b)
Whether one character comes after another, ignoring case.
a- The first character.
b- The second.
- returns
- #t when a's folded code point is greater than b's.
See also: char>?, char-foldcase
char-ci<=?
function ↑ Functions
(: char-ci<=? (-> char char bool))
(char-ci<=? a b)
Whether one character comes before another or is the same, ignoring case.
a- The first character.
b- The second.
- returns
- #t when a's folded code point is not greater than b's.
See also: char<=?, char-foldcase
char-ci>=?
function ↑ Functions
(: char-ci>=? (-> char char bool))
(char-ci>=? a b)
Whether one character comes after another or is the same, ignoring case.
a- The first character.
b- The second.
- returns
- #t when a's folded code point is not less than b's.
See also: char>=?, char-foldcase
Values
chars-unicode-version
value ↑ Values
(: chars-unicode-version string)
The version of the Unicode Character Database the tables are from.
See also: char-general-category