Skip to content

Commit

Permalink
Use more modern str.format
Browse files Browse the repository at this point in the history
  • Loading branch information
obynio committed Feb 12, 2024
1 parent c1fe7f6 commit a888782
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions reading.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ def format(self, useRubyTags: bool, previous_character: str) -> str:
return self.text

if useRubyTags:
return "<ruby>%s<rp>(</rp><rt>%s</rt><rp>)</rp></ruby>" % (self.text, self.reading)
return "<ruby>{}<rp>(</rp><rt>{}</rt><rp>)</rp></ruby>".format(self.text, self.reading)
else:
add_space = previous_character is not None and previous_character != "]"
return '%s%s[%s]' % (" " if add_space else "", self.text, self.reading)
return '{}{}[{}]'.format(" " if add_space else "", self.text, self.reading)

class RegexDefinition:
def __init__(self, text: str, regexGroupIndex: Optional[int]):
Expand Down Expand Up @@ -206,7 +206,7 @@ def kanjiToRegex(kanji: str):
definitions.append(RegexDefinition(captureGroup, numCaptureGroups))
numCaptureGroups += 1

return ("^%s$" % ''.join(regexPieces), definitions)
return ("^{}$".format(str().join(regexPieces)), definitions)

class MecabController(object):

Expand Down Expand Up @@ -277,7 +277,7 @@ def reading(self, expr, ignoreNumbers = True, useRubyTags = False):
nodes.append(ReadingNode(definition.text, groupReading))

# Combine our nodes together into a single sentece
fin = ''
fin = str()
for node in nodes:
fin += node.format(useRubyTags, fin[-1] if len(fin) > 0 else None)

Expand Down

0 comments on commit a888782

Please sign in to comment.