diff --git a/oxifmt.typ b/oxifmt.typ index 6b8d9e7..c1be2b0 100644 --- a/oxifmt.typ +++ b/oxifmt.typ @@ -609,9 +609,21 @@ parameter := argument '$' let num-replacements = replacements.pos() let named-replacements = replacements.named() let unnamed-format-index = 0 - let fmt-decimal-separator = if "fmt-decimal-separator" in named-replacements { named-replacements.at("fmt-decimal-separator") } else { auto } - let fmt-thousands-count = if "fmt-thousands-count" in named-replacements { named-replacements.at("fmt-thousands-count") } else { 3 } - let fmt-thousands-separator = if "fmt-thousands-separator" in named-replacements { named-replacements.at("fmt-thousands-separator") } else { "" } + let fmt-decimal-separator = auto + let fmt-thousands-count = 3 + let fmt-thousands-separator = "" + + for (name, value) in named-replacements { + if name == "fmt-decimal-separator" { + fmt-decimal-separator = named-replacements.remove(name) + } else if name == "fmt-thousands-count" { + fmt-thousands-count = named-replacements.remove(name) + } else if name == "fmt-thousands-separator" { + fmt-thousands-separator = named-replacements.remove(name) + } else if name.starts-with("fmt-") { + assert(false, message: "String formatter error: unknown format option '" + name + "'. Keys prefixed with 'fmt-' are reserved for future oxifmt options. Please use a different key name.") + } + } assert( type(fmt-thousands-count) == _int-type, diff --git a/tests/strfmt-tests.typ b/tests/strfmt-tests.typ index 6295c45..b02503a 100644 --- a/tests/strfmt-tests.typ +++ b/tests/strfmt-tests.typ @@ -42,9 +42,6 @@ // test custom decimal separators (II) - weird values assert.eq(strfmt("{}; {:015e}; {}; {}; {:?}", 1.532, 45000, -5.6, "a.b", "c.d", fmt-decimal-separator: (a: 5)), "1(a: 5)532; 000004(a: 5)5e4; -5(a: 5)6; a.b; \"c.d\"") - - // test custom decimal separators (III) - ensure we can fetch it from inside - assert.eq(strfmt("5{fmt-decimal-separator}6", fmt-decimal-separator: "|"), "5|6") } // Issue #6: UTF-8 #{