to_camel_case_word
This commit is contained in:
parent
b3b514992d
commit
5117a9afd2
|
@ -17,6 +17,14 @@ TEST_PATTERN: re.Pattern = re.compile(
|
|||
|
||||
END_SYMBOLS = '.?!'
|
||||
|
||||
IGNORABLE_WORDS_IN_NAME = frozenset({
|
||||
'',
|
||||
'a',
|
||||
'the',
|
||||
'is',
|
||||
'are'
|
||||
})
|
||||
|
||||
def format_test_prefix(name: str, description: str, annotation:
|
||||
str,visibility:str, with_javadoc: bool,
|
||||
with_display_name: bool) -> str:
|
||||
|
@ -35,15 +43,27 @@ def format_test_prefix(name: str, description: str, annotation:
|
|||
str_builder += ['void ',name,'(']
|
||||
return ''.join(str_builder)
|
||||
|
||||
def to_camel_case_word(word: str) -> str | None:
|
||||
print(word)
|
||||
if word.lower() in IGNORABLE_WORDS_IN_NAME:
|
||||
return None
|
||||
if len(word) > 1 and word.upper() == word:
|
||||
word = word[0].upper() + word[1:].lower()
|
||||
else:
|
||||
word = word[0].upper() + word[1:]
|
||||
return word
|
||||
|
||||
def to_camel_case(description: str) -> str:
|
||||
description = description.strip(' \t.').replace(',',' ')
|
||||
words = description.split(' ')
|
||||
|
||||
words[0] = words[0][0].lower() + words[0][1:]
|
||||
for i in range(1, len(words)):
|
||||
if words[i] == '':
|
||||
continue
|
||||
words[i] = words[i][0].upper() + words[i][1:]
|
||||
word = to_camel_case_word(words[i])
|
||||
if not word:
|
||||
words[i] = ''
|
||||
else:
|
||||
words[i] = word
|
||||
|
||||
return ''.join(words)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user