pub trait StringExtended {
fn split_lines(&self) -> Vec<String>;
fn split_to_vec_string(&self, pattern: &str) -> Vec<String>;
fn split_to_vec_str(&self, pattern: &str) -> Vec<&str>;
fn get_char(&self, index: usize) -> Option<char>;
fn capitalize(&self) -> String;
fn is_uppercase(&self) -> bool;
fn is_lowercase(&self) -> bool;
}
impl StringExtended for String {
fn split_lines(&self) -> Vec<String> {
self.split('\n').map(|line| line.to_string()).collect()
}
fn split_to_vec_string(&self, pattern: &str) -> Vec<String> {
self.split(pattern).map(|s| s.to_string()).collect()
}
fn split_to_vec_str(&self, pattern: &str) -> Vec<&str> {
self.split(pattern).collect()
}
fn get_char(&self, index: usize) -> Option<char> {
self.chars().nth(index)
}
fn capitalize(&self) -> String {
self[0..1].to_uppercase() + &self[1..]
}
fn is_uppercase(&self) -> bool {
self.chars().all(|c| c.is_uppercase())
}
fn is_lowercase(&self) -> bool {
self.chars().all(|c| c.is_lowercase())
}
}
impl StringExtended for &str {
fn split_lines(&self) -> Vec<String> {
self.split('\n').map(|line| line.to_string()).collect()
}
fn get_char(&self, index: usize) -> Option<char> {
self.chars().nth(index)
}
fn split_to_vec_string(&self, pattern: &str) -> Vec<String> {
self.split(pattern).map(|s| s.to_string()).collect()
}
fn split_to_vec_str(&self, pattern: &str) -> Vec<&str> {
self.split(pattern).collect()
}
fn capitalize(&self) -> String {
self[0..1].to_uppercase() + &self[1..]
}
fn is_uppercase(&self) -> bool {
self.chars().all(|c| c.is_uppercase())
}
fn is_lowercase(&self) -> bool {
self.chars().all(|c| c.is_lowercase())
}
}