Open me-kell opened 1 year ago
Hey @me-kell, thanks for reporting the issue. We've had a few issues around that case as it caters for camelcase to macrocase where camelcase could have whatADay
. Currently there's an additional option, delims_only
, that defaults to False
. You can set it to True
and it should work. (See https://github.com/chrisdoherty4/python-case-converter#macrocase additional options).
That said, I'm wondering if the most common use-case is a normal sentence such as What a day
converted to some case form. If that's the case then the implementation might be preferencing the wrong thing.
Do you have any thoughts?
delims_only
solves only part of the problem.
IMHO the whole issue is how we define macrocase
. AFAICS the definition of macrocase
is not analogous to the other definitions.
One possible definition could be snakecase(s).upper()
or cobolcase(s).replace('-', '_')
(see below).
macrocase
has though a different behaviour. See example with s = "My NewURL"
below:
>>> from caseconverter import *
>>>
>>> def snake_upper(s):
... return snakecase(s).upper()
...
>>> def cobol_underscore(s):
... return cobolcase(s).replace('-', '_')
...
>>> for case in [macrocase, cobolcase, kebabcase, snakecase, snake_upper, cobol_underscore]:
... t = f"{case.__name__: <20}"
... s = "My NewURL"
... if case == macrocase:
... t += f"{case(s, delims_only=True): <15}"
... else:
... t += f"{case(s): <15}"
... print(t)
...
macrocase MY_NEWURL
cobolcase MY-NEW-URL
kebabcase my-new-url
snakecase my_new_url
snake_upper MY_NEW_URL
cobol_underscore MY_NEW_URL
macrocase("My URL")
returnsMY_UR_L
(note the underscore betweenR
andL
). I would expectMY_URL
Regarding the word boundaries I would expect a result similar to
cobolcase
,snakecase
, andkebabcase
.cobolcase("My URL")
returnsMY-URL