Merge pull request #7045 from GULPF/fmt-str-fallback
Add additional $ fallback to fmt
This commit is contained in:
commit
e7e37713dd
2 changed files with 16 additions and 1 deletions
|
|
@ -221,8 +221,10 @@ template callFormat(res, arg) {.dirty.} =
|
||||||
template callFormatOption(res, arg, option) {.dirty.} =
|
template callFormatOption(res, arg, option) {.dirty.} =
|
||||||
when compiles(format(arg, option, res)):
|
when compiles(format(arg, option, res)):
|
||||||
format(arg, option, res)
|
format(arg, option, res)
|
||||||
else:
|
elif compiles(format(arg, option)):
|
||||||
res.add format(arg, option)
|
res.add format(arg, option)
|
||||||
|
else:
|
||||||
|
format($arg, option, res)
|
||||||
|
|
||||||
macro fmt*(pattern: string{lit}): untyped =
|
macro fmt*(pattern: string{lit}): untyped =
|
||||||
## For a specification of the ``fmt`` macro, see the module level documentation.
|
## For a specification of the ``fmt`` macro, see the module level documentation.
|
||||||
|
|
|
||||||
13
tests/stdlib/tstrformat.nim
Normal file
13
tests/stdlib/tstrformat.nim
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
discard """
|
||||||
|
action: "run"
|
||||||
|
"""
|
||||||
|
|
||||||
|
import strformat
|
||||||
|
|
||||||
|
type Obj = object
|
||||||
|
|
||||||
|
proc `$`(o: Obj): string = "foobar"
|
||||||
|
|
||||||
|
var o: Obj
|
||||||
|
doAssert fmt"{o}" == "foobar"
|
||||||
|
doAssert fmt"{o:10}" == "foobar "
|
||||||
Loading…
Add table
Add a link
Reference in a new issue