okuna-api
okuna-api copied to clipboard
:bug: User Adjective - fix titlecasing of letters immediately after a symbol
Fixes https://github.com/OpenbookOrg/openbook-app/issues/243
(sorry, initially referenced 243 in the openbook-api repo instead of openbook-app)
We need to write some tests for this. Not confident about what it does though 🤔
I took a closer look at the methods used.
With the method capwords the letter in front of which there is no space would remain unchanged.
However, if you only want to allow the first letter after a * to be small, then you should use another method.
I don't know much about performance, but one possibility could be that you continue to use title and then add letters after a ***** to the initial value (newstring[indexOf("")+1] = startstring[indexOf("")+1])
Another maybe better solution: Using regex as the standard suggests (https://docs.python.org/3/library/stdtypes.html#str.title)
import re
def titlecase(s):
return re.sub(r"[A-Za-z]+(\*[A-Za-z]+)?",
lambda mo: mo.group(0)[0].upper() + mo.group(0)[1:].lower(),
s)
mystr = "Hel*lo world! Hell'o world\n"
print(titlecase(mystr))
I'm sorry, but I don't have the time to update the PR or write tests right now.