Skip to content
Snippets Groups Projects
Commit 509555db authored by Eduardo Trujillo's avatar Eduardo Trujillo
Browse files

feat(str): Add some string manipulation utilities

parent 518a8a2d
No related branches found
No related tags found
1 merge request!2Figment Backend
const SEPARATORS: &[char] = &[' ', '_', '-'];
pub fn to_train_case<S: AsRef<str>>(input: S) -> String {
let items: Vec<String> = String::from(input.as_ref())
.split(SEPARATORS)
.map(ToString::to_string)
.collect();
items.join("_").to_uppercase()
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_to_train_case() -> () {
assert_eq!(to_train_case("omg-OMG_omg123 omg"), "OMG_OMG_OMG123_OMG")
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment