Skip to content

Commit

Permalink
Avoid trailing/leading spaces with PGN annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasf committed Aug 3, 2020
1 parent c881607 commit 8822ca5
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions chess/pgn.py
Expand Up @@ -416,7 +416,7 @@ def set_eval(self, score: Optional[chess.engine.PovScore]) -> None:
self.comment, found = EVAL_REGEX.subn(eval, self.comment, count=1)

if not found and eval:
if not self.comment.endswith(" "):
if self.comment and not self.comment.endswith(" "):
self.comment += " "
self.comment += eval

Expand Down Expand Up @@ -484,7 +484,7 @@ def set_arrows(self, arrows: Iterable[Union[chess.svg.Arrow, Tuple[chess.Square,
prefix += f"[%cal {','.join(cal)}]"

if prefix:
self.comment = prefix + " " + self.comment
self.comment = prefix + " " + self.comment if self.comment else prefix

def clock(self) -> Optional[float]:
"""
Expand Down Expand Up @@ -514,7 +514,7 @@ def set_clock(self, seconds: Optional[float]) -> None:
self.comment, found = CLOCK_REGEX.subn(clk, self.comment, count=1)

if not found and clk:
if not self.comment.endswith(" "):
if self.comment and not self.comment.endswith(" "):
self.comment += " "
self.comment += clk

Expand Down

0 comments on commit 8822ca5

Please sign in to comment.