use super::funejson::Value; use super::validation_email::is_email; fn is_ascii_space(ch: char) -> bool { matches!(ch, ' ' | '\t' | '\n' | '\r' | '\u{0C}' | '\u{0B}') } /// The stored form of an email address: trimmed, domain lower-cased, local /// part as typed; `None` when the trimmed text is not a plausible address. pub fn normalise_email(value: &str) -> Option { // ASCII whitespace only; str::trim also strips Unicode spaces. let trimmed = value.trim_matches(is_ascii_space); if !is_email(trimmed) { return None; } let at = trimmed.find('@').unwrap(); Some(format!("{}{}", &trimmed[..=at], trimmed[at + 1..].to_ascii_lowercase())) } pub fn fune_vector(args: &[Value]) -> Value { match normalise_email(args[0].as_str()) { Some(email) => Value::Str(email), None => Value::Null, } }