protobuf_support/
json_name.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/// Implementation must match exactly
/// `ToJsonName()` function in C++ `descriptor.cc`.
pub fn json_name(input: &str) -> String {
    let mut capitalize_next = false;
    let mut result = String::with_capacity(input.len());

    for c in input.chars() {
        if c == '_' {
            capitalize_next = true;
        } else if capitalize_next {
            result.extend(c.to_uppercase());
            capitalize_next = false;
        } else {
            result.push(c);
        }
    }

    result
}