Correctly convert SCREAMING_SNAKE_CASE
#1884
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The problem of normalizing casings is a very interesting one.
I've decided to reimplement the function, partly to make it more readable as well.
It's trivial to implement a function that converts consistent input to consistent output, the issue lies with converting nonsensical input (weird casings and case exceptions) to sensible output, especially while acting purely locally.
These are the test cases that would be different for the original implementation:
SCREAMING
SCREAMING
Screaming
Still_Not___Screaming
StillNotScreaming
Still_Not___Screaming
Still_Not___screaming
StillNot_screaming
Still_Not___screaming
still_not___screaming
StillNotScreaming
StillNot___screaming
_D_
D_
_D_
_d_
D
_d_
MyCool2d_string
MyCool2d_string
MyCool2dString
MyCool2_d_String
MyCool2_dString
MyCool2D_String
MyC_de_cool
MyC_de_cool
MyC_deCool
m_d_d_d
MDDD
M_dD_d
m_d_d_d
(LowerCamelCase
)mDDD
mD_dD
__m_d_d_d
MDDD
__mD_dD
The questions of design are:
MDDD
test case. I recognize that the previous handling of this case was superior, however, this case is highly synthetic (in general the test cases are not solely intended to represent real world scenarios, but to capture design decisions made).In conclusion I believe the new implementation is generally more stable, consistent and sensible in realistic edge cases.