mirror of
https://github.com/ARM-software/devlib.git
synced 2025-01-31 02:00:45 +00:00
utils/misc: Check if identifier starts with a number
Now ensures that the given text does not start with a digit and if so prefix an underscore to ensure a valid python identifier.
This commit is contained in:
parent
d1b08f6df6
commit
bfda5c4271
@ -523,7 +523,9 @@ TRANS_TABLE = string.maketrans(BAD_CHARS, '_' * len(BAD_CHARS))
|
||||
|
||||
def to_identifier(text):
|
||||
"""Converts text to a valid Python identifier by replacing all
|
||||
whitespace and punctuation."""
|
||||
whitespace and punctuation and adding a prefix if starting with a digit"""
|
||||
if text[:1].isdigit():
|
||||
text = '_' + text
|
||||
return re.sub('_+', '_', text.translate(TRANS_TABLE))
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user