-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnmfmt.go
61 lines (54 loc) · 1.25 KB
/
nmfmt.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Package nmfmt wraps fmt.Xprintf functions providing $name style placeholders.
//
// Each nmfmt.Xprintf function has a signature like:
//
// func Printf(format string, m map[string]any) (int, error)
//
// And prints according to a format that contains $name style placeholders.
//
// # Placeholders
//
// Example: `variable1:q`
//
// Each placeholder in the format is like $name, ${name}, $name:verb or ${name:verb}.
// The names are keys of the map m. (case sensitive)
// And their values are to be embedded.
//
// # Name
//
// Must match \w.
//
// See [Named], [Struct]
//
// # Verb
//
// Verb is with `:`.
// Must match \w.
//
// Defaults to `v`.
//
// See https://pkg.go.dev/fmt.
//
// # debug notation
//
// If a placeholder starts with `$=`, the output starts with the name of the placeholder followed by `=`.
//
// `$=name` -> `name=NAME_VALUE`
package nmfmt
import (
"io"
)
var f Formatter = New()
type M map[string]any
func Printf(format string, a ...any) (int, error) {
return f.Printf(format, a...)
}
func Fprintf(w io.Writer, format string, a ...any) (int, error) {
return f.Fprintf(w, format, a...)
}
func Sprintf(format string, a ...any) string {
return f.Sprintf(format, a...)
}
func Errorf(format string, a ...any) error {
return f.Errorf(format, a...)
}