Created
November 10, 2018 16:58
-
-
Save tvaisanen/92924a63d7abde6c0ec915cbb8a13e24 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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