-
-
Notifications
You must be signed in to change notification settings - Fork 653
Fix renaming enum variants starting with digits #2905
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
| "__EmptyString".to_string() | ||
| } else if v.chars().next().map(char::is_numeric).unwrap_or(false) { | ||
| if v.chars().any(|c| !c.is_numeric() && !c.is_alphabetic() && c != '_' && c != '-' && c != ' ') { | ||
| "".to_string() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be moved to __EmptyString and update the warning message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review! Yeah this is a confusing case. to_upper_camel_case removes invalid chars, so a field like "/" is remapped to "". In order to preserve existing behavior for variants starting with a digit, we have to strip chars manually if they are not valid.
Empty strings are then converted to UTF-8 encoding in the next block. So, "0/" is remapped to "U0030U002F". I agree that the flow is pretty hard to follow now though.
We could replace this check with format!("_{}", v.to_upper_camel_case()). However, this would map 0A-B-C to _0aBC instead of _0ABC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, that's really confusing. Could you refactor this to make the control flow clearer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or add a comment explaining that Unicode characters will be handled below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've refactored the control flow, hopefully it's easier to follow now
Signed-off-by: Agni <a@a4n1.com>
6181288 to
a9cb7c8
Compare
Signed-off-by: Agni <a@a4n1.com>
f73d402 to
7cbf791
Compare
|
|
||
| if v | ||
| .chars() | ||
| .any(|c| !c.is_alphanumeric() && c != '_' && c != '-' && c != ' ') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use matches macro
PR Info
Bug Fixes