protobuf_support/json_name.rs
1/// Implementation must match exactly
2/// `ToJsonName()` function in C++ `descriptor.cc`.
3pub fn json_name(input: &str) -> String {
4 let mut capitalize_next = false;
5 let mut result = String::with_capacity(input.len());
6
7 for c in input.chars() {
8 if c == '_' {
9 capitalize_next = true;
10 } else if capitalize_next {
11 result.extend(c.to_uppercase());
12 capitalize_next = false;
13 } else {
14 result.push(c);
15 }
16 }
17
18 result
19}