Split camelcase display names for speaker clarity

merge-requests/30/head
Bob Mottram 2021-03-03 20:34:55 +00:00
parent 15c5280c95
commit 30e11be0b0
3 changed files with 27 additions and 0 deletions

View File

@ -12,6 +12,7 @@ import random
import urllib.parse
from auth import createBasicAuthHeader
from session import getJson
from utils import camelCaseSplit
from utils import getDomainFromActor
from utils import getNicknameFromActor
from utils import getGenderFromBio
@ -378,6 +379,7 @@ def updateSpeaker(baseDir: str, nickname: str, domain: str,
return
speakerName = _removeEmojiFromText(speakerName)
speakerName = speakerName.replace('_', ' ')
speakerName = camelCaseSplit(speakerName)
gender = getGenderFromBio(baseDir, postJsonObject['actor'],
personCache, translate)
if announcingActor:

View File

@ -34,6 +34,7 @@ from follow import clearFollows
from follow import clearFollowers
from follow import sendFollowRequestViaServer
from follow import sendUnfollowRequestViaServer
from utils import camelCaseSplit
from utils import decodedHost
from utils import getFullDomain
from utils import validNickname
@ -3389,9 +3390,19 @@ def testSpeakerReplaceLinks():
assert 'Web link support.torproject.org' in result
def testCamelCaseSplit():
print('testCamelCaseSplit')
testStr = 'ThisIsCamelCase'
assert camelCaseSplit(testStr) == 'This Is Camel Case'
testStr = 'Notcamelcase test'
assert camelCaseSplit(testStr) == 'Notcamelcase test'
def runAllTests():
print('Running tests...')
testFunctions()
testCamelCaseSplit()
testSpeakerReplaceLinks()
testExtractTextFieldsInPOST()
testMarkdownToHtml()

View File

@ -7,6 +7,7 @@ __email__ = "bob@freedombone.net"
__status__ = "Production"
import os
import re
import time
import shutil
import datetime
@ -2020,3 +2021,16 @@ def isRecentPost(postJsonObject: {}, maxDays=3) -> bool:
if publishedDaysSinceEpoch < recently:
return False
return True
def camelCaseSplit(text: str) -> str:
""" Splits CamelCase into "Camel Case"
"""
matches = re.finditer('.+?(?:(?<=[a-z])(?=[A-Z])|' +
'(?<=[A-Z])(?=[A-Z][a-z])|$)', text)
if not matches:
return text
resultStr = ''
for word in matches:
resultStr += word.group(0) + ' '
return resultStr.strip()