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
pub fn to_pascal(s: &str) -> String {
    let mut result = String::with_capacity(s.len());
    let mut capital = true;

    for c in s.chars() {
        if c == '_' {
            capital = true;
            continue;
        }

        if capital {
            c.to_uppercase()
                .into_iter()
                .for_each(|x| result.push(x));
        } else {
            result.push(c);
        }

        capital = false;
    }

    result
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_to_pascal() {
        assert_eq!(to_pascal(&"to_pascal"), String::from("ToPascal"));
        assert_eq!(to_pascal(&"__to_pascal"), String::from("ToPascal"));
        assert_eq!(to_pascal(&"Very_Long_string"), String::from("VeryLongString"));
    }
}