okuna-api icon indicating copy to clipboard operation
okuna-api copied to clipboard

:bug: User Adjective - fix titlecasing of letters immediately after a symbol

Open ndrwy opened this issue 6 years ago • 2 comments

Fixes https://github.com/OpenbookOrg/openbook-app/issues/243

(sorry, initially referenced 243 in the openbook-api repo instead of openbook-app)

ndrwy avatar May 03 '19 19:05 ndrwy

We need to write some tests for this. Not confident about what it does though 🤔

lifenautjoe avatar May 17 '19 11:05 lifenautjoe

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.

duichwer avatar May 21 '19 20:05 duichwer