Replace usage of "match" as a variable name

This commit is contained in:
Veronica Berglyd Olsen
2024-10-14 00:14:08 +02:00
parent 57e739c3ef
commit 2447ae5cff
4 changed files with 26 additions and 26 deletions
+3 -3
View File
@@ -343,9 +343,9 @@ class DocSearch:
count = 0 count = 0
capped = False capped = False
results = [] results = []
for match in self._regEx.finditer(text): for res in self._regEx.finditer(text):
pos = match.start(0) pos = res.start(0)
num = len(match.group(0)) num = len(res.group(0))
lim = text[:pos].rfind("\n") + 1 lim = text[:pos].rfind("\n") + 1
cut = text[lim:pos].rfind(" ") + lim + 1 cut = text[lim:pos].rfind(" ") + lim + 1
context = text[cut:cut+100].partition("\n")[0] context = text[cut:cut+100].partition("\n")[0]
+12 -12
View File
@@ -1109,36 +1109,36 @@ class Tokenizer(ABC):
# Match Markdown # Match Markdown
for regEx, fmts in self._rxMarkdown: for regEx, fmts in self._rxMarkdown:
for match in regEx.finditer(text): for res in regEx.finditer(text):
temp.extend( temp.extend(
(match.start(n), match.end(n), fmt, "") (res.start(n), res.end(n), fmt, "")
for n, fmt in enumerate(fmts) if fmt > 0 for n, fmt in enumerate(fmts) if fmt > 0
) )
# Match Shortcodes # Match Shortcodes
for match in REGEX_PATTERNS.shortcodePlain.finditer(text): for res in REGEX_PATTERNS.shortcodePlain.finditer(text):
temp.append(( temp.append((
match.start(1), match.end(1), res.start(1), res.end(1),
self._shortCodeFmt.get(match.group(1).lower(), 0), self._shortCodeFmt.get(res.group(1).lower(), 0),
"", "",
)) ))
# Match Shortcode w/Values # Match Shortcode w/Values
tHandle = self._handle or "" tHandle = self._handle or ""
for match in REGEX_PATTERNS.shortcodeValue.finditer(text): for res in REGEX_PATTERNS.shortcodeValue.finditer(text):
kind = self._shortCodeVals.get(match.group(1).lower(), 0) kind = self._shortCodeVals.get(res.group(1).lower(), 0)
temp.append(( temp.append((
match.start(0), match.end(0), res.start(0), res.end(0),
self.FMT_STRIP if kind == skip else kind, self.FMT_STRIP if kind == skip else kind,
f"{tHandle}:{match.group(2)}", f"{tHandle}:{res.group(2)}",
)) ))
# Match Dialogue # Match Dialogue
if self._rxDialogue and hDialog: if self._rxDialogue and hDialog:
for regEx, fmtB, fmtE in self._rxDialogue: for regEx, fmtB, fmtE in self._rxDialogue:
for match in regEx.finditer(text): for res in regEx.finditer(text):
temp.append((match.start(0), 0, fmtB, "")) temp.append((res.start(0), 0, fmtB, ""))
temp.append((match.end(0), 0, fmtE, "")) temp.append((res.end(0), 0, fmtE, ""))
# Post-process text and format # Post-process text and format
result = text result = text
+8 -8
View File
@@ -402,10 +402,10 @@ class GuiDocHighlighter(QSyntaxHighlighter):
if hRules: if hRules:
for rX, hRule in hRules: for rX, hRule in hRules:
for match in re.finditer(rX, text[xOff:]): for res in re.finditer(rX, text[xOff:]):
for xM, hFmt in hRule.items(): for xM, hFmt in hRule.items():
xPos = match.start(xM) + xOff xPos = res.start(xM) + xOff
xEnd = match.end(xM) + xOff xEnd = res.end(xM) + xOff
for x in range(xPos, xEnd): for x in range(xPos, xEnd):
cFmt = self.format(x) cFmt = self.format(x)
if cFmt.fontStyleName() != "markup": if cFmt.fontStyleName() != "markup":
@@ -484,18 +484,18 @@ class TextBlockData(QTextBlockUserData):
if "[" in text: if "[" in text:
# Strip shortcodes # Strip shortcodes
for regEx in [RX_FMT_SC, RX_FMT_SV]: for regEx in [RX_FMT_SC, RX_FMT_SV]:
for match in regEx.finditer(text, offset): for res in regEx.finditer(text, offset):
if (s := match.start(0)) >= 0 and (e := match.end(0)) >= 0: if (s := res.start(0)) >= 0 and (e := res.end(0)) >= 0:
pad = " "*(e - s) pad = " "*(e - s)
text = f"{text[:s]}{pad}{text[e:]}" text = f"{text[:s]}{pad}{text[e:]}"
self._spellErrors = [] self._spellErrors = []
checker = SHARED.spelling checker = SHARED.spelling
for match in RX_WORDS.finditer(text.replace("_", " "), offset): for res in RX_WORDS.finditer(text.replace("_", " "), offset):
if ( if (
(word := match.group(0)) (word := res.group(0))
and not (word.isnumeric() or word.isupper() or checker.checkWord(word)) and not (word.isnumeric() or word.isupper() or checker.checkWord(word))
): ):
self._spellErrors.append((match.start(0), match.end(0))) self._spellErrors.append((res.start(0), res.end(0)))
return self._spellErrors return self._spellErrors
+3 -3
View File
@@ -32,10 +32,10 @@ from novelwriter.text.patterns import REGEX_PATTERNS
def allMatches(regEx: re.Pattern, text: str) -> list[list[str]]: def allMatches(regEx: re.Pattern, text: str) -> list[list[str]]:
"""Get all matches for a regex.""" """Get all matches for a regex."""
result = [] result = []
for match in regEx.finditer(text): for res in regEx.finditer(text):
result.append([ result.append([
(match.group(n), match.start(n), match.end(n)) (res.group(n), res.start(n), res.end(n))
for n in range((match.lastindex or 0) + 1) for n in range((res.lastindex or 0) + 1)
]) ])
return result return result