diff options
Diffstat (limited to 'azalea-protocol/azalea-protocol-macros/src/utils.rs')
| -rw-r--r-- | azalea-protocol/azalea-protocol-macros/src/utils.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/azalea-protocol/azalea-protocol-macros/src/utils.rs b/azalea-protocol/azalea-protocol-macros/src/utils.rs new file mode 100644 index 00000000..cdfe0412 --- /dev/null +++ b/azalea-protocol/azalea-protocol-macros/src/utils.rs @@ -0,0 +1,29 @@ +pub fn to_camel_case(snake_case: &str) -> String { + let mut camel_case = String::new(); + let mut capitalize_next = true; + for c in snake_case.chars() { + if c == '_' { + capitalize_next = true; + } else { + if capitalize_next { + camel_case.push(c.to_ascii_uppercase()); + } else { + camel_case.push(c); + } + capitalize_next = false; + } + } + camel_case +} +pub fn to_snake_case(camel_case: &str) -> String { + let mut snake_case = String::new(); + for c in camel_case.chars() { + if c.is_ascii_uppercase() { + snake_case.push('_'); + snake_case.push(c.to_ascii_lowercase()); + } else { + snake_case.push(c); + } + } + snake_case +} |
