aboutsummaryrefslogtreecommitdiff
path: root/2.27.1/src/json/json_name.rs
diff options
context:
space:
mode:
Diffstat (limited to '2.27.1/src/json/json_name.rs')
-rw-r--r--2.27.1/src/json/json_name.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/2.27.1/src/json/json_name.rs b/2.27.1/src/json/json_name.rs
new file mode 100644
index 0000000..f5c9364
--- /dev/null
+++ b/2.27.1/src/json/json_name.rs
@@ -0,0 +1,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
+}