1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
use crate::core::spec_chars::SpecChars; pub struct StringCompounds { _string: String } impl StringCompounds { pub fn new(_string: String) -> StringCompounds { return StringCompounds { _string: _string }; } pub fn extract(&self) -> Vec<String> { let mut compounds = self.split_on_special_char(); if compounds.len() == 1 { compounds = self.split_on_uppercase_letters(); } return compounds; } pub fn split_on_uppercase_letters(&self) -> Vec<String> { let alphanums: String = self._string.chars() .filter(|_char|_char.is_alphanumeric()) .map(|_char| { if _char.is_lowercase() { return _char.to_string(); } else { return format!( "{}{}", SpecChars::WhiteSpace.to_string(), _char.to_lowercase() ); } }) .collect::<String>(); let compounds = self.split_on_whitespace(alphanums); return compounds; } pub fn split_on_special_char(&self) -> Vec<String> { let alphanums: String = self._string.chars() .map(|_char| { if _char.is_alphanumeric() { return _char.to_string().to_lowercase(); } else { return SpecChars::WhiteSpace.to_string(); } }) .collect::<String>(); let compounds = self.split_on_whitespace(alphanums); return compounds; } fn split_on_whitespace(&self, _string: String) -> Vec<String> { return _string.split_whitespace() .map(|s| String::from(s)) .collect::<Vec<String>>(); } }