Skip to content
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

Handling of Abbreviations and Acronyms #7

Open
Fleshgrinder opened this issue Apr 24, 2021 · 0 comments
Open

Handling of Abbreviations and Acronyms #7

Fleshgrinder opened this issue Apr 24, 2021 · 0 comments
Assignees
Labels
🐛 bug Something isn't working
Milestone

Comments

@Fleshgrinder
Copy link
Owner

Abbreviations and acronyms are dirty business with both lower and upper camel case. Currently the library is doing a perfect job at dealing with them and is too strict in the transformation logic. Here are a few examples:

transform actual expected
"HTTPException".toLowerCamelCase() httpexception httpException
"HTTPException".toUpperCamelCase() Httpexception HttpException
"HTTPException".toLowerDashCase() httpexception http-exception
"HTTPException".toUpperDashCase() HTTPEXCEPTION HTTP-EXCEPTION
"HTTPException".toLowerSnakeCase() httpexception http_exception
"HTTPException".toUpperSnakeCase() HTTPEXCEPTION HTTP_EXCEPTION

There are obviously cases where it becomes impossible to translate these things, this is exactly the reason why people should always treat any abbreviation or acronym like any normal word. This parseDBMXMLFromIPAddress is from Wikipedia and is always going to be transformed incorrectly. However, the following should work as expected.

transform actual expected
"NonlinearXWave".toLowerCamelCase() nonlinearXwave nonlinearXWave
"NonlinearXWave".toUpperCamelCase() NonlinearXwave NonlinearXWave
"NonlinearXWave".toLowerDashCase() nonlinear-xwave nonlinear-x-wave
"NonlinearXWave".toUpperDashCase() NONLINEAR-XWAVE NONLINEAR-X-WAVE
"NonlinearXWave".toLowerSnakeCase() nonlinear_xwave nonlinear_x_wave
"NonlinearXWave".toUpperSnakeCase() NONLINEAR_XWAVE NONLINEAR_X_WAVE

I think that this is doable by treating the last uppercase letter as the beginning of a new word. This is most definitely going to break some other inputs, but it should produce the desired output at least for those inputs I can think of. I am not sure yet how this can be done in any non-camel case format, simply because they usually ignore case altogether. Converting to camel first to then convert to the target seems very wasteful …

It definitely makes sense to look at some other case format libraries, not only JVM, but also other languages. Maybe someone already had a good idea on how to deal with this. Or maybe it's just a fool's errand?

@Fleshgrinder Fleshgrinder added the 🐛 bug Something isn't working label Apr 24, 2021
@Fleshgrinder Fleshgrinder added this to the 0.3.0 milestone Apr 24, 2021
@Fleshgrinder Fleshgrinder self-assigned this Apr 24, 2021
@Fleshgrinder Fleshgrinder modified the milestones: 0.3.0, 0.4.0 Apr 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant