Avoid the use of chained replace
s
This commit is contained in:
parent
b3445bc35a
commit
e508224a46
@ -174,20 +174,30 @@ class ExternalEditor(QObject):
|
|||||||
def _sub_placeholder(self, possible_placeholder, line, column):
|
def _sub_placeholder(self, possible_placeholder, line, column):
|
||||||
"""Substitute a single placeholder.
|
"""Substitute a single placeholder.
|
||||||
|
|
||||||
The input to this function is not guaranteed to be a valid or known
|
If the `possible_placeholder` input to this function is valid it will
|
||||||
placeholder. In this case the return value is the unchanged input.
|
be substituted with the appropriate value, otherwise it will be left
|
||||||
|
unchanged.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
possible_placeholder: an argument of editor.command.
|
possible_placeholder: an argument of editor.command.
|
||||||
|
line: the previously-calculated line number for the text caret
|
||||||
|
column: the previously-calculated column number for the text caret
|
||||||
|
|
||||||
Return:
|
Return:
|
||||||
The substituted placeholder or the original argument
|
The substituted placeholder or the original argument
|
||||||
"""
|
"""
|
||||||
sub = possible_placeholder\
|
replacements = {
|
||||||
.replace('{}', self._filename)\
|
'{}': self._filename,
|
||||||
.replace('{file}', self._filename)\
|
'{file}': self._filename,
|
||||||
.replace('{line}', str(line))\
|
'{line}': str(line),
|
||||||
.replace('{line0}', str(line-1))\
|
'{line0}': str(line-1),
|
||||||
.replace('{column}', str(column))\
|
'{column}': str(column),
|
||||||
.replace('{column0}', str(column-1))
|
'{column0}': str(column-1)
|
||||||
return sub
|
}
|
||||||
|
|
||||||
|
# The for loop would create a copy anyway, this should be more legible
|
||||||
|
ph = possible_placeholder
|
||||||
|
for old, new in replacements.items():
|
||||||
|
ph = ph.replace(old, new)
|
||||||
|
|
||||||
|
return ph
|
||||||
|
Loading…
Reference in New Issue
Block a user