jlevy/repren

--preserve-case enhancement: also use underscore-less CamelCase translations

c-bb opened this issue · 1 comments

c-bb commented

Currently, when --preserve-case is used to translate a CamelCase replacements to additional lowercase and uppercase replacements, it inserts underscores in between the word segments. This is cool, but on some occasions it would be useful to additionally do the replacement without the added underscores.

For example, the current behaviour is like this:

$ repren --full --from CamelCase --to DromedaryCase --preserve-case .
Using 4 patterns:
  'CAMEL_CASE' -> 'DROMEDARY_CASE'
  'CamelCase' -> 'DromedaryCase'
  'camelCase' -> 'dromedaryCase'
  'camel_case' -> 'dromedary_case'

It would be awesome if it could be extended to do this:

$ repren --full --from CamelCase --to DromedaryCase --preserve-case .
Using 6 patterns:
  'CAMEL_CASE' -> 'DROMEDARY_CASE'
  'CAMELCASE' -> 'DROMEDARYCASE'
  'CamelCase' -> 'DromedaryCase'
  'camelCase' -> 'dromedaryCase'
  'camel_case' -> 'dromedary_case'
  'camelcase' -> 'dromedarycase'

Perhaps this could be opt-in.

jlevy commented

Agree in principle. Just still thinking what the flags should be, so that there isn't a proliferation of random flags for every type of case convention. For example, the cleanest solution may be a pregen step that takes one pattern file and "case generalizes" it to another pattern file (and handles CAPS, dromedaryCamel, BactrianCamel, under_score, dash-style, and runtogether formats) that can be inspected/edited before use.