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

Number word boundary bug #22

Open
jpotterm opened this issue Jan 28, 2020 · 7 comments
Open

Number word boundary bug #22

jpotterm opened this issue Jan 28, 2020 · 7 comments

Comments

@jpotterm
Copy link

Numbers usually act as word boundaries, but not always (which I believe is a bug). Here are inconsistent test cases:

strcase.ToSnake("1A2") // 1a_2
strcase.ToSnake("A1B") // a_1_b
@nasermirzaei89
Copy link

I also have this problem in this case:

strcase.ToSnake("ID3") // returns id_3 but I think it should return id3
strcase.ToSnake("ID3v2_3") // returns id_3_v2_3 but I think it should return id3_v2_3

version commit I use: 16388991a33441046539eb716cff4d294d556c70

@iancoleman
Copy link
Owner

#24 introduces the change for @jpotterm with these tests:

strcase/snake_test.go

Lines 51 to 52 in 23e9d4e

{"1A2", "1_a_2"},
{"A1B", "a_1_b"},

@nasermirzaei89 I'm not sure what the particular rule would be to differentiate those particular cases, can you describe the intention please? It looks like maybe you mean "any numbers following the token 'ID' or 'v' should be considered part of that token and not split from it"? Is it specifically for <ID|V>+?

The current rule is that numbers act as word boundaries, so ToSnake("ID3v2_3") gives "id_3_v_2_3".

@NathanBaulch
Copy link
Contributor

I think the intention is to only introduce delimiters after numbers, not before them. This is a super easy change with my recent contributions, see here. I'd also prefer this behavior but didn't include it in #24 since the current behavior isn't necessarily wrong so it feels a little more like a breaking change.

@nasermirzaei89
Copy link

@iancoleman I think the solution of @NathanBaulch is good. You should check if it doesn't break any other cases. Thanks for the follow up 🎉

@rami-dabain
Copy link

#24 is looks merged, however it doesn't solve the numbering issue:
ID3v2_3 should become id3_v2_3 but currently it gives id_3_v_2_3 or is there a config/param that i can't find to switch between the 2 methods?

@wichert
Copy link

wichert commented Dec 21, 2021

There are some many possibilities here, that I doubt you can make this work for everyone without introducing a bunch of configuration options. In my case I am looking at Position3D being changed to position_3_d, which I would prefer to be position_3d.

@amanenk
Copy link

amanenk commented Feb 16, 2022

I have faced the same issue. I want Int8Value -> int8_value but strcase generates int_8_value. I have tried to strcase.ConfigureAcronym("Int8", "int8") but it didn't help. That would be awesome to use numbers in acronyms (the issue above can be solved via adding 3D to acronyms) and adding a config parameter to attach trailing numbers would be another convenient way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants