[mod] Schalter für Beachtung von Leerzeichen

This commit is contained in:
fenris 2025-07-17 14:15:27 +02:00
parent cad4cf931a
commit 207a2b2a89

View file

@ -1,4 +1,5 @@
import sys as _sys
import re as _re
import json as _json
import yaml as _yaml
import argparse as _argparse
@ -22,23 +23,29 @@ def string_coin(
options = (
{
"character_open": "{{",
"character_close": "}}"
"character_close": "}}",
"ignore_whitespaces": True,
}
|
(options or {})
)
result = template
for (key, value, ) in arguments.items():
result = result.replace(
(
"%s%s%s"
% (
options["character_open"],
key,
options["character_close"],
pattern = (
_re.escape(options["character_open"])
+
("\s*" if options["ignore_whitespaces"] else "")
+
_re.escape(key)
+
("\s*" if options["ignore_whitespaces"] else "")
+
_re.escape(options["character_close"])
)
),
value
result = _re.sub(
pattern,
value,
result
)
return result
@ -154,6 +161,12 @@ def main(
metavar = "<character-close>",
help = "placeholder closing character",
)
argument_parser.add_argument(
"-w",
"--heed-whitespaces",
action = "store_true",
help = "whether whitespace characters in the template string shall be heeded, i.e. not be ignored",
)
args = argument_parser.parse_args()
## exec
@ -169,6 +182,7 @@ def main(
{
"character_open": args.character_open,
"character_close": args.character_close,
"ignore_whitespaces": (not args.heed_whitespaces),
}
)
_sys.stdout.write(content_out)