pub fn is_blank(s: &str) -> bool {
s.chars().all(|c| (c as u32) <= 0x20)
}
pub fn is_empty(s: &str) -> bool {
s.is_empty()
}
pub fn end_of_char(s: &str, c: char) -> bool {
if is_blank(s) {
return false;
}
s.chars().next_back() == Some(c)
}
pub fn end_of_str(s0: &str, s1: &str) -> bool {
if is_blank(s0) || is_blank(s1) {
return false;
}
s0.ends_with(s1)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn blank_matches_java_trim_semantics() {
assert!(is_blank(""));
assert!(is_blank(" "));
assert!(is_blank("\t\n\r "));
assert!(!is_blank(" a "));
assert!(!is_blank("x"));
assert!(!is_blank("\u{00A0}"));
assert!(!is_blank("\u{2003}")); }
#[test]
fn end_of_helpers() {
assert!(end_of_char("abc", 'c'));
assert!(!end_of_char("abc", 'b'));
assert!(!end_of_char(" ", ' '));
assert!(end_of_str("hello", "lo"));
assert!(!end_of_str("hello", "he"));
assert!(!end_of_str("hi", "")); }
}