libc/runeistype: accept out of range runes

out of range runes should just return 0 for whether
they're within any of the classes.
This commit is contained in:
Ori Bernstein 2024-10-05 00:06:50 +00:00
parent 4d484968bf
commit 394e9c2235
2 changed files with 15 additions and 0 deletions

View file

@ -47,6 +47,9 @@ test types and modify cases for Unicode characters.
The names are self-explanatory.
.PP
The case-conversion routines return the character unchanged if it has no case.
.PP
If a rune contains a value that is not a valid codepoint (ie, values less than
zero, or greater than Runemax), these routines return 0.
.SH SOURCE
.B /sys/src/libc/port/mkrunetype.c
.br

View file

@ -6,35 +6,47 @@
int
isspacerune(Rune c)
{
if(c < 0 || c > Runemax)
return 0;
return (mergedlkup(c) & Lspace) == Lspace;
}
int
isalpharune(Rune c)
{
if(c < 0 || c > Runemax)
return 0;
return (mergedlkup(c) & Lalpha) == Lalpha;
}
int
isdigitrune(Rune c)
{
if(c < 0 || c > Runemax)
return 0;
return (mergedlkup(c) & Ldigit) == Ldigit;
}
int
isupperrune(Rune c)
{
if(c < 0 || c > Runemax)
return 0;
return (mergedlkup(c) & Lupper) == Lupper;
}
int
islowerrune(Rune c)
{
if(c < 0 || c > Runemax)
return 0;
return (mergedlkup(c) & Llower) == Llower;
}
int
istitlerune(Rune c)
{
if(c < 0 || c > Runemax)
return 0;
return (mergedlkup(c) & Ltitle) == Ltitle;
}