fixes #6205
This commit is contained in:
parent
34c1ca1dd0
commit
50d4224d41
2 changed files with 22 additions and 19 deletions
|
|
@ -20,6 +20,9 @@
|
||||||
containing the column of the instantiation.
|
containing the column of the instantiation.
|
||||||
|
|
||||||
- ``cookies.setCookie` no longer assumes UTC for the expiration date.
|
- ``cookies.setCookie` no longer assumes UTC for the expiration date.
|
||||||
|
- ``strutils.formatEng`` does not distinguish between ``nil`` and ``""``
|
||||||
|
strings anymore for its ``unit`` parameter. Instead the space is controlled
|
||||||
|
by a new parameter ``useUnitSpace``.
|
||||||
|
|
||||||
#### Breaking changes in the compiler
|
#### Breaking changes in the compiler
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2144,8 +2144,9 @@ proc formatEng*(f: BiggestFloat,
|
||||||
precision: range[0..32] = 10,
|
precision: range[0..32] = 10,
|
||||||
trim: bool = true,
|
trim: bool = true,
|
||||||
siPrefix: bool = false,
|
siPrefix: bool = false,
|
||||||
unit: string = nil,
|
unit: string = "",
|
||||||
decimalSep = '.'): string {.noSideEffect.} =
|
decimalSep = '.',
|
||||||
|
useUnitSpace = false): string {.noSideEffect.} =
|
||||||
## Converts a floating point value `f` to a string using engineering notation.
|
## Converts a floating point value `f` to a string using engineering notation.
|
||||||
##
|
##
|
||||||
## Numbers in of the range -1000.0<f<1000.0 will be formatted without an
|
## Numbers in of the range -1000.0<f<1000.0 will be formatted without an
|
||||||
|
|
@ -2184,7 +2185,7 @@ proc formatEng*(f: BiggestFloat,
|
||||||
## with an exponent rather than an SI prefix, regardless of whether
|
## with an exponent rather than an SI prefix, regardless of whether
|
||||||
## `siPrefix` is true.
|
## `siPrefix` is true.
|
||||||
##
|
##
|
||||||
## If `unit` is not nil, the provided unit will be appended to the string
|
## If `useUnitSpace` is true, the provided unit will be appended to the string
|
||||||
## (with a space as required by the SI standard). This behaviour is slightly
|
## (with a space as required by the SI standard). This behaviour is slightly
|
||||||
## different to appending the unit to the result as the location of the space
|
## different to appending the unit to the result as the location of the space
|
||||||
## is altered depending on whether there is an exponent.
|
## is altered depending on whether there is an exponent.
|
||||||
|
|
@ -2199,7 +2200,7 @@ proc formatEng*(f: BiggestFloat,
|
||||||
## formatEng(4100, siPrefix=true, unit="") == "4.1 k"
|
## formatEng(4100, siPrefix=true, unit="") == "4.1 k"
|
||||||
## formatEng(4100) == "4.1e3"
|
## formatEng(4100) == "4.1e3"
|
||||||
## formatEng(4100, unit="V") == "4.1e3 V"
|
## formatEng(4100, unit="V") == "4.1e3 V"
|
||||||
## formatEng(4100, unit="") == "4.1e3 " # Space with unit=""
|
## formatEng(4100, unit="", useUnitSpace=true) == "4.1e3 " # Space with useUnitSpace=true
|
||||||
##
|
##
|
||||||
## `decimalSep` is used as the decimal separator.
|
## `decimalSep` is used as the decimal separator.
|
||||||
var
|
var
|
||||||
|
|
@ -2267,9 +2268,8 @@ proc formatEng*(f: BiggestFloat,
|
||||||
if p != ' ':
|
if p != ' ':
|
||||||
suffix = " " & p
|
suffix = " " & p
|
||||||
exponent = 0 # Exponent replaced by SI prefix
|
exponent = 0 # Exponent replaced by SI prefix
|
||||||
if suffix == "" and unit != nil:
|
if suffix == "" and useUnitSpace:
|
||||||
suffix = " "
|
suffix = " "
|
||||||
if unit != nil:
|
|
||||||
suffix &= unit
|
suffix &= unit
|
||||||
if exponent != 0:
|
if exponent != 0:
|
||||||
result &= "e" & $exponent
|
result &= "e" & $exponent
|
||||||
|
|
@ -2712,18 +2712,18 @@ bar
|
||||||
doAssert formatEng(-52731234, 1, decimalSep=',') == "-52,7e6"
|
doAssert formatEng(-52731234, 1, decimalSep=',') == "-52,7e6"
|
||||||
|
|
||||||
doAssert formatEng(4100, siPrefix=true, unit="V") == "4.1 kV"
|
doAssert formatEng(4100, siPrefix=true, unit="V") == "4.1 kV"
|
||||||
doAssert formatEng(4.1, siPrefix=true, unit="V") == "4.1 V"
|
doAssert formatEng(4.1, siPrefix=true, unit="V", useUnitSpace=true) == "4.1 V"
|
||||||
doAssert formatEng(4.1, siPrefix=true) == "4.1" # Note lack of space
|
doAssert formatEng(4.1, siPrefix=true) == "4.1" # Note lack of space
|
||||||
doAssert formatEng(4100, siPrefix=true) == "4.1 k"
|
doAssert formatEng(4100, siPrefix=true) == "4.1 k"
|
||||||
doAssert formatEng(4.1, siPrefix=true, unit="") == "4.1 " # Includes space
|
doAssert formatEng(4.1, siPrefix=true, unit="", useUnitSpace=true) == "4.1 " # Includes space
|
||||||
doAssert formatEng(4100, siPrefix=true, unit="") == "4.1 k"
|
doAssert formatEng(4100, siPrefix=true, unit="") == "4.1 k"
|
||||||
doAssert formatEng(4100) == "4.1e3"
|
doAssert formatEng(4100) == "4.1e3"
|
||||||
doAssert formatEng(4100, unit="V") == "4.1e3 V"
|
doAssert formatEng(4100, unit="V", useUnitSpace=true) == "4.1e3 V"
|
||||||
doAssert formatEng(4100, unit="") == "4.1e3 " # Space with unit=""
|
doAssert formatEng(4100, unit="", useUnitSpace=true) == "4.1e3 "
|
||||||
# Don't use SI prefix as number is too big
|
# Don't use SI prefix as number is too big
|
||||||
doAssert formatEng(3.1e22, siPrefix=true, unit="a") == "31e21 a"
|
doAssert formatEng(3.1e22, siPrefix=true, unit="a", useUnitSpace=true) == "31e21 a"
|
||||||
# Don't use SI prefix as number is too small
|
# Don't use SI prefix as number is too small
|
||||||
doAssert formatEng(3.1e-25, siPrefix=true, unit="A") == "310e-27 A"
|
doAssert formatEng(3.1e-25, siPrefix=true, unit="A", useUnitSpace=true) == "310e-27 A"
|
||||||
|
|
||||||
block: # startsWith / endsWith char tests
|
block: # startsWith / endsWith char tests
|
||||||
var s = "abcdef"
|
var s = "abcdef"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue