utf8proc 0.1.2

Rust bindings to the utf8proc library
Documentation
//! Functionality for Unicode [case mappings]: case conversion, case detection, and caseless matching: .
//!
//! [case mappings]: https://www.unicode.org/reports/tr21/tr21-5.html

/// Check if the codepoint is lowercase.
///
/// Should return the same result as [`char::is_lowercase`].
#[inline]
pub fn is_lower(c: char) -> bool {
    // SAFETY: This is a safe function
    unsafe { utf8proc_sys::utf8proc_islower(c as i32) != 0 }
}
/// Check if the codepoint is uppercase.
///
/// Should return the same result as [`char::is_uppercase`].
#[inline]
pub fn is_upper(c: char) -> bool {
    // SAFETY: This is a safe function
    unsafe { utf8proc_sys::utf8proc_isupper(c as i32) != 0 }
}

/// Given a codepoint `c`, return the codepoint of the corresponding
/// lower-case character, if any.
///
/// Otherwise (if there is no lower-case variant),  return `c`.
#[inline]
pub fn to_lower(c: char) -> char {
    // SAFETY: Is a safe function
    let res = unsafe { utf8proc_sys::utf8proc_tolower(c as i32).cast_unsigned() };
    // SAFETY: Library returns valid codepoints
    unsafe { char::from_u32_unchecked(res) }
}

/// Given a codepoint `c`, return the codepoint of the corresponding
/// upper-case character, if any.
///
/// Otherwise (if there is no upper-case variant),  return `c`.
#[inline]
pub fn to_upper(c: char) -> char {
    // SAFETY: Is a safe function
    let res = unsafe { utf8proc_sys::utf8proc_toupper(c as i32).cast_unsigned() };
    // SAFETY: Library returns valid codepoints
    unsafe { char::from_u32_unchecked(res) }
}

/// Given a codepoint `c`, return the codepoint of the corresponding
/// title-case character, if any.
///
/// Otherwise (if there is no title-case variant),  return `c`.
#[inline]
pub fn to_title(c: char) -> char {
    // SAFETY: Is a safe function
    let res = unsafe { utf8proc_sys::utf8proc_totitle(c as i32).cast_unsigned() };
    // SAFETY: Library returns valid codepoints
    unsafe { char::from_u32_unchecked(res) }
}