这是indexloc提供的服务,不要输入任何密码
Skip to content

Reserve fmt- prefix for options #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions oxifmt.typ
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 0 additions & 3 deletions tests/strfmt-tests.typ
Original file line number Diff line number Diff line change
Expand Up @@ -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
#{
Expand Down