Is the behavior of `macrocase` right?
macrocase("My URL") returns MY_UR_L (note the underscore between R and L). I would expect MY_URL
Regarding the word boundaries I would expect a result similar to cobolcase, snakecase, and kebabcase.
cobolcase("My URL") returns MY-URL
>>> from caseconverter import *
>>> cases = [str, macrocase, cobolcase, kebabcase, snakecase]
>>> for case in cases:
... t = f"{case.__name__: <15}"
... for s in ["My New URL", "My NewURL", "My URL", "My IP", "My MACRO"]:
... t += f"{case(s): <15}"
... print(t)
str My New URL My NewURL My URL My IP My MACRO
macrocase MY_NEW_UR_L MY_NEW_U_R_L MY_UR_L MY_IP MY_MA_C_R_O
cobolcase MY-NEW-URL MY-NEW-URL MY-URL MY-IP MY-MACRO
kebabcase my-new-url my-new-url my-url my-ip my-macro
snakecase my_new_url my_new_url my_url my_ip my_macro
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?
Related https://github.com/chrisdoherty4/python-case-converter/issues/6
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