Merge branch 'ctype.h-locale-functions-impl' into 'master'
ctype.h: add *_l family of functions See merge request redox-os/relibc!905
This commit is contained in:
+84
-2
@@ -2,8 +2,6 @@
|
||||
//!
|
||||
//! See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/ctype.h.html>.
|
||||
|
||||
// TODO: *_l functions
|
||||
|
||||
use crate::platform::types::c_int;
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isalnum.html>.
|
||||
@@ -12,12 +10,24 @@ pub extern "C" fn isalnum(c: c_int) -> c_int {
|
||||
c_int::from(isdigit(c) != 0 || isalpha(c) != 0)
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isalnum_l.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn isalnum_l(c: c_int, _loc: locale_t) -> c_int {
|
||||
isalnum(c)
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isalpha.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn isalpha(c: c_int) -> c_int {
|
||||
c_int::from(islower(c) != 0 || isupper(c) != 0)
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isalpha_l.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn isalpha_l(c: c_int, _loc: locale_t) -> c_int {
|
||||
isalpha(c)
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9699919799/functions/isascii.html>.
|
||||
///
|
||||
/// The `isascii()` function was marked obsolescent in the Open Group Base
|
||||
@@ -34,36 +44,72 @@ pub extern "C" fn isblank(c: c_int) -> c_int {
|
||||
c_int::from(c == c_int::from(b' ') || c == c_int::from(b'\t'))
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isblank_l.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn isblank_l(c: c_int, _loc: locale_t) -> c_int {
|
||||
isblank(c)
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/iscntrl.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn iscntrl(c: c_int) -> c_int {
|
||||
c_int::from((c >= 0x00 && c <= 0x1f) || c == 0x7f)
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/iscntrl_l.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn iscntrl_l(c: c_int, _loc: locale_t) -> c_int {
|
||||
iscntrl(c)
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isdigit.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn isdigit(c: c_int) -> c_int {
|
||||
c_int::from(c >= c_int::from(b'0') && c <= c_int::from(b'9'))
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isdigit_l.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn isdigit_l(c: c_int, _loc: locale_t) -> c_int {
|
||||
isdigit(c)
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isgraph.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn isgraph(c: c_int) -> c_int {
|
||||
c_int::from(c >= 0x21 && c <= 0x7e)
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isgraph_l.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn isgraph_l(c: c_int, _loc: locale_t) -> c_int {
|
||||
isgraph(c)
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/islower.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn islower(c: c_int) -> c_int {
|
||||
c_int::from(c >= c_int::from(b'a') && c <= c_int::from(b'z'))
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/islower_l.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn islower_l(c: c_int, _loc: locale_t) -> c_int {
|
||||
islower(c)
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isprint.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn isprint(c: c_int) -> c_int {
|
||||
c_int::from(c >= 0x20 && c < 0x7f)
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isprint_l.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn isprint_l(c: c_int, _loc: locale_t) -> c_int {
|
||||
isprint(c)
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/ispunct.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn ispunct(c: c_int) -> c_int {
|
||||
@@ -75,6 +121,12 @@ pub extern "C" fn ispunct(c: c_int) -> c_int {
|
||||
)
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/ispunct_l.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn ispunct_l(c: c_int, _loc: locale_t) -> c_int {
|
||||
ispunct(c)
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isspace.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn isspace(c: c_int) -> c_int {
|
||||
@@ -88,18 +140,36 @@ pub extern "C" fn isspace(c: c_int) -> c_int {
|
||||
)
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isspace_l.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn isspace_l(c: c_int, _loc: locale_t) -> c_int {
|
||||
isspace(c)
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isupper.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn isupper(c: c_int) -> c_int {
|
||||
c_int::from(c >= c_int::from(b'A') && c <= c_int::from(b'Z'))
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isupper_l.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn isupper_l(c: c_int, _loc: locale_t) -> c_int {
|
||||
isupper(c)
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isxdigit.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn isxdigit(c: c_int) -> c_int {
|
||||
c_int::from(isdigit(c) != 0 || (c | 32 >= c_int::from(b'a') && c | 32 <= c_int::from(b'f')))
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isxdigit_l.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn isxdigit_l(c: c_int, _loc: locale_t) -> c_int {
|
||||
isxdigit(c)
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9699919799/functions/toascii.html>.
|
||||
///
|
||||
/// The `toascii()` function was marked obsolescent in the Open Group Base
|
||||
@@ -116,8 +186,20 @@ pub extern "C" fn tolower(c: c_int) -> c_int {
|
||||
if isupper(c) != 0 { c | 0x20 } else { c }
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/tolower_l.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn tolower_l(c: c_int, _loc: locale_t) -> c_int {
|
||||
tolower(c)
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/toupper.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn toupper(c: c_int) -> c_int {
|
||||
if islower(c) != 0 { c & !0x20 } else { c }
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/toupper_l.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn toupper_l(c: c_int, _loc: locale_t) -> c_int {
|
||||
toupper(c)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user