Skip to content

Commit

Permalink
Make the ScreamingSnakeCase formatter behave as the SnakeCase one
Browse files Browse the repository at this point in the history
  • Loading branch information
lu-zero authored and eqrion committed Nov 26, 2018
1 parent 5a9c8b1 commit d021772
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/bindgen/rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,22 @@ impl RenameRule {
RenameRule::ScreamingSnakeCase => {
// Same as SnakeCase code above, but uses to_uppercase
let mut result = String::new();
let mut add_separator = true;
let mut prev_uppercase = false;
for (i, c) in text.char_indices() {
if c.is_uppercase() && i != 0 {
result.push_str("_");
if c == '_' {
add_separator = false;
prev_uppercase = false;
}
if c.is_uppercase() {
if i != 0 && add_separator && !prev_uppercase {
result.push_str("_");
} else {
add_separator = true;
}
prev_uppercase = true;
} else {
prev_uppercase = false;
}
for x in c.to_uppercase() {
result.push(x);
Expand Down

0 comments on commit d021772

Please sign in to comment.