mirror of
https://github.com/ryanoasis/nerd-fonts.git
synced 2024-12-19 20:12:52 +02:00
name-parser: Simplify for CodeClimate
[why] Function get_name_token has a Cognitive Complexity of 12 (exceeds 9 allowed). Consider refactoring. [how] Remove not really needed special case. Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
This commit is contained in:
parent
07a23bda90
commit
2e9caea9cd
@ -135,7 +135,7 @@ class FontnameTools:
|
|||||||
return (weights, styles)
|
return (weights, styles)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_name_token(name, tokens, allow_regex_token = False):
|
def get_name_token(name, tokens):
|
||||||
"""Try to find any case insensitive token from tokens in the name, return tuple with found token-list and rest"""
|
"""Try to find any case insensitive token from tokens in the name, return tuple with found token-list and rest"""
|
||||||
# The default mode (allow_regex_token = False) will try to find any verbatim string in the
|
# The default mode (allow_regex_token = False) will try to find any verbatim string in the
|
||||||
# tokens list (case insensitive matching) and give that tokens list item back with
|
# tokens list (case insensitive matching) and give that tokens list item back with
|
||||||
@ -150,10 +150,9 @@ class FontnameTools:
|
|||||||
all_tokens = []
|
all_tokens = []
|
||||||
j = 1
|
j = 1
|
||||||
token_regex = '|'.join(tokens)
|
token_regex = '|'.join(tokens)
|
||||||
if not allow_regex_token:
|
# Allow a dash between CamelCase token word parts, i.e. Camel-Case
|
||||||
# Allow a dash between CamelCase token word parts, i.e. Camel-Case
|
# This allows for styles like Extra-Bold
|
||||||
# This allows for styles like Extra-Bold
|
token_regex = re.sub(r'(?<=[a-z])(?=[A-Z])', '-?', token_regex)
|
||||||
token_regex = re.sub(r'(?<=[a-z])(?=[A-Z])', '-?', token_regex)
|
|
||||||
regex = re.compile('(.*?)(' + token_regex + ')(.*)', re.IGNORECASE)
|
regex = re.compile('(.*?)(' + token_regex + ')(.*)', re.IGNORECASE)
|
||||||
while j:
|
while j:
|
||||||
j = regex.match(name)
|
j = regex.match(name)
|
||||||
@ -163,9 +162,7 @@ class FontnameTools:
|
|||||||
sys.exit('Malformed regex in FontnameTools.get_name_token()')
|
sys.exit('Malformed regex in FontnameTools.get_name_token()')
|
||||||
not_matched += ' ' + j.groups()[0] # Blanc prevents unwanted concatenation of unmatched substrings
|
not_matched += ' ' + j.groups()[0] # Blanc prevents unwanted concatenation of unmatched substrings
|
||||||
tok = j.groups()[1].lower()
|
tok = j.groups()[1].lower()
|
||||||
if not allow_regex_token:
|
tok = tok.replace('-', '') # Remove dashes between CamelCase token words
|
||||||
# Remove dashes between CamelCase token words
|
|
||||||
tok = tok.replace('-', '')
|
|
||||||
if tok in lower_tokens:
|
if tok in lower_tokens:
|
||||||
tok = tokens[lower_tokens.index(tok)]
|
tok = tokens[lower_tokens.index(tok)]
|
||||||
tok = FontnameTools.unify_style_names(tok)
|
tok = FontnameTools.unify_style_names(tok)
|
||||||
@ -354,7 +351,7 @@ class FontnameTools:
|
|||||||
|
|
||||||
( style, weight_token ) = FontnameTools.get_name_token(style, weights)
|
( style, weight_token ) = FontnameTools.get_name_token(style, weights)
|
||||||
( style, style_token ) = FontnameTools.get_name_token(style, styles)
|
( style, style_token ) = FontnameTools.get_name_token(style, styles)
|
||||||
( style, other_token ) = FontnameTools.get_name_token(style, other, True)
|
( style, other_token ) = FontnameTools.get_name_token(style, other)
|
||||||
while 'Regular' in style_token and len(style_token) > 1:
|
while 'Regular' in style_token and len(style_token) > 1:
|
||||||
# Correct situation where "Regular" and something else is given
|
# Correct situation where "Regular" and something else is given
|
||||||
style_token.remove('Regular')
|
style_token.remove('Regular')
|
||||||
|
Loading…
Reference in New Issue
Block a user