commit
102b71f42e
2 changed files with 20 additions and 2 deletions
|
|
@ -415,7 +415,7 @@ proc parseStandardFormatSpecifier*(s: string; start = 0;
|
||||||
raise newException(ValueError,
|
raise newException(ValueError,
|
||||||
"invalid format string, cannot parse: " & s[i..^1])
|
"invalid format string, cannot parse: " & s[i..^1])
|
||||||
|
|
||||||
proc formatValue*(result: var string; value: SomeInteger; specifier: string) =
|
proc formatValue*[T: SomeInteger](result: var string; value: T; specifier: string) =
|
||||||
## Standard format implementation for ``SomeInteger``. It makes little
|
## Standard format implementation for ``SomeInteger``. It makes little
|
||||||
## sense to call this directly, but it is required to exist
|
## sense to call this directly, but it is required to exist
|
||||||
## by the ``&`` macro.
|
## by the ``&`` macro.
|
||||||
|
|
@ -509,7 +509,7 @@ proc formatValue*(result: var string; value: string; specifier: string) =
|
||||||
setLen(value, runeOffset(value, spec.precision))
|
setLen(value, runeOffset(value, spec.precision))
|
||||||
result.add alignString(value, spec.minimumWidth, spec.align, spec.fill)
|
result.add alignString(value, spec.minimumWidth, spec.align, spec.fill)
|
||||||
|
|
||||||
proc formatValue[T](result: var string; value: T; specifier: string) =
|
proc formatValue[T: not SomeInteger](result: var string; value: T; specifier: string) =
|
||||||
mixin `$`
|
mixin `$`
|
||||||
formatValue(result, $value, specifier)
|
formatValue(result, $value, specifier)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -115,3 +115,21 @@ proc print_object(animalAddr: AnimalRef) =
|
||||||
echo fmt"Received {animalAddr[]}"
|
echo fmt"Received {animalAddr[]}"
|
||||||
|
|
||||||
print_object(AnimalRef(name: "Foo", species: "Bar"))
|
print_object(AnimalRef(name: "Foo", species: "Bar"))
|
||||||
|
|
||||||
|
# bug #11723
|
||||||
|
|
||||||
|
let pos: Positive = 64
|
||||||
|
doAssert fmt"{pos:3}" == " 64"
|
||||||
|
doAssert fmt"{pos:3b}" == "1000000"
|
||||||
|
doAssert fmt"{pos:3d}" == " 64"
|
||||||
|
doAssert fmt"{pos:3o}" == "100"
|
||||||
|
doAssert fmt"{pos:3x}" == " 40"
|
||||||
|
doAssert fmt"{pos:3X}" == " 40"
|
||||||
|
|
||||||
|
let nat: Natural = 64
|
||||||
|
doAssert fmt"{nat:3}" == " 64"
|
||||||
|
doAssert fmt"{nat:3b}" == "1000000"
|
||||||
|
doAssert fmt"{nat:3d}" == " 64"
|
||||||
|
doAssert fmt"{nat:3o}" == "100"
|
||||||
|
doAssert fmt"{nat:3x}" == " 40"
|
||||||
|
doAssert fmt"{nat:3X}" == " 40"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue