-
Notifications
You must be signed in to change notification settings - Fork 383
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Proper camel case in JSON parser/printer
As per protobuf JSON spec
- Loading branch information
1 parent
c2402d5
commit fe9ca9c
Showing
6 changed files
with
97 additions
and
42 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/// Implementation must match exactly | ||
/// `ToJsonName()` function in C++ `descriptor.cc`. | ||
pub(crate) 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 | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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