Skip to content

Instantly share code, notes, and snippets.

@tvaisanen
Created November 10, 2018 16:58
Show Gist options
  • Save tvaisanen/92924a63d7abde6c0ec915cbb8a13e24 to your computer and use it in GitHub Desktop.
Save tvaisanen/92924a63d7abde6c0ec915cbb8a13e24 to your computer and use it in GitHub Desktop.
fn uncapitalize_first_from_string(name: &String) -> String {
let mut result = String::new();
let _name_len = name.len();
for (i, c) in name.chars().enumerate() {
match i == 0 {
true => {
let mut lower = c.to_lowercase();
result.push(lower.next().unwrap())
},
false => result.push(c)
}
}
result
}
#[test]
fn should_return_copy_of_a_component_name_with_first_letter_in_lowercase(){
let camel: String = "ComponentName".to_string();
let expected = "componentName".to_string();
let result: String = uncapitalize_first_from_string(&camel);
assert_eq!(expected, result);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment