withoutboats / heck

oh heck, a case conversion library
Apache License 2.0
493 stars 34 forks source link

[feature] Option to treat consecutive uppercase characters in PascalCase as separate words #36

Open junbl opened 2 years ago

junbl commented 2 years ago

From the docs:

That is, “HelloWorld” is segmented Hello|World whereas “XMLHttpRequest” is segmented XML|Http|Request.

I have identifiers with single character words in them. I'd love it if they were snake_cased as separate words, e.g.:

assert_eq!("ABCD".to_snake_case_from_pascal_case_strict() == "a_b_c_d")
assert_eq!("ABCcD".to_snake_case_from_pascal_case_strict() == "a_b_cc_d")

This would be the exact inverse of to_pascal_case() for snake_case text, i.e.:

assert_eq!(text.to_snake_case().to_pascal_case().to_snake_case_from_pascal_case_strict() == text.to_snake_case())

Plaground link

azaleacolburn commented 1 year ago

I suppose that option can be added, not sure how much the maintainer will care to merge it though.

jplatte commented 1 year ago

This could be supported by the API I descibed in https://github.com/withoutboats/heck/issues/18#issuecomment-752538575.