-
Notifications
You must be signed in to change notification settings - Fork 512
Expand file tree
/
Copy path_text_util.py
More file actions
62 lines (56 loc) · 2.32 KB
/
_text_util.py
File metadata and controls
62 lines (56 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see
# https://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
"""
Copyright (C) 2010-2011 Lucas De Marchi <lucas.de.marchi@gmail.com>
Copyright (C) 2011 ProFUSION embedded systems
"""
def is_camel_case_word(input_word: str) -> bool:
return (
(input_word != input_word.lower())
and (input_word != input_word.upper())
and ("_" not in input_word)
and ("-" not in input_word)
and (" " not in input_word)
)
def is_camel_case_string(input_string: str) -> bool:
return any(is_camel_case_word(word) for word in input_string.split(","))
def fix_case(word: str, fixword: str) -> str:
if fixword == fixword.upper():
# abbreviation, acronym: fixword is in all upper case.
# Use fixword as per dictionary.
# Eg. asscii->ASCII
return fixword
if word == word.capitalize() and fixword == fixword.lower():
# word is capitalized and fixword(s) in lower.
# Capitalize/Title fixword(s).
# Eg. Weather, Whether,
return fixword.title()
if word == word.capitalize() and not is_camel_case_string(fixword):
# word is capitalized and fixword(s) contain mixed with no camelCase.
# Capitalize/Title fixword(s).
# Eg. skipt->skip, Skype, skipped,
return fixword.title()
if word == word.upper():
# word is in all upper case, change fixword to upper.
# Eg. MONDAY
return fixword.upper()
if word.lower() == fixword.lower():
# Special feature only meant for private custom dictionary.
# word is valid but fixword required in CamelCase.
# Use fixword as per dictionary.
# Eg. mysql->MySQL
return fixword
# word is in lower, capitalize, CamelCase or whatever.
# Use fixword as per dictionary.
return fixword