From 91d76116f616572e69826382255e0d36da8023f0 Mon Sep 17 00:00:00 2001 From: "Mohammed S. Yaseen" <51242349+mohasarc@users.noreply.github.com> Date: Mon, 26 Jan 2026 20:38:48 +0000 Subject: [PATCH] use join for find and replace string construction --- src/textwatermark/template.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/textwatermark/template.py b/src/textwatermark/template.py index 89a882b..0459022 100644 --- a/src/textwatermark/template.py +++ b/src/textwatermark/template.py @@ -290,19 +290,19 @@ def _find_and_replace(self, text: str, wm_final: str, loop: bool): confusables_chars_keys = "".join(self.confusables_chars.keys()) wm_idx = 0 - wm_text = "" + wm_parts = [] for idx in range(len(text)): if not loop and wm_idx >= len(wm_final): - wm_text += text[idx:] + wm_parts.append(text[idx:]) break # 查找并替换成水印字符 if confusables_chars_keys.find(text[idx]) != -1: offset = wm_final[wm_idx % len(wm_final)] - wm_text += self.confusables_chars[text[idx]][int(offset)] + wm_parts.append(self.confusables_chars[text[idx]][int(offset)]) wm_idx += 1 else: - wm_text += text[idx] - return wm_text + wm_parts.append(text[idx]) + return "".join(wm_parts) def _decorate_each_char(self, text: str, wm_final: str, loop: bool): if not isinstance(self.confusables_chars, dict):