use super::*;
use unicode_segmentation::UnicodeSegmentation;
pub struct StringPasses;
impl<'a> PassSequence<'a> for StringPasses {
type T = String;
const TY_NAME: &'static str = "string";
const PASSES: &'a [Pass<'a, Self::T>] =
pass_sequence![structure, graphemes, words, bytes, modifications];
}
pub fn structure<'a>(string: &String) -> Vec<(&'a str, Info)> {
let mut result = Vec::new();
push!(result, "empty?", string.is_empty());
push!(result, "ascii?", string.is_ascii());
result
}
pub fn graphemes<'a>(string: &String) -> Vec<(&'a str, Info)> {
let mut result = Vec::new();
let graphemes: Vec<&str> = UnicodeSegmentation::graphemes(string.as_str(), true).collect();
push!(result, "array", format!("{:?}", graphemes));
push!(result, "len", graphemes.len());
result
}
pub fn words<'a>(string: &String) -> Vec<(&'a str, Info)> {
let mut result = Vec::new();
let words: Vec<&str> = UnicodeSegmentation::unicode_words(string.as_str()).collect();
push!(result, "array", format!("{:?}", words));
push!(result, "len", words.len());
result
}
pub fn bytes<'a>(string: &String) -> Vec<(&'a str, Info)> {
let mut result = Vec::new();
let bytes = string.as_bytes();
push!(result, "array", format!("{:?}", bytes));
push!(result, "len", string.len());
result
}
pub fn modifications<'a>(string: &String) -> Vec<(&'a str, Info)> {
let mut result = Vec::new();
let upper = string.to_uppercase();
let lower = string.to_lowercase();
push!(result, "upper", upper);
push!(result, "lower", lower);
result
}