Improve dollar IpAddress (#20729)
* Improve dollar * Improve dollar * Simplify, remove 1 if in for loop * ci * Update lib/pure/net.nim * Update lib/pure/net.nim Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
This commit is contained in:
parent
46eac22172
commit
f562a5c55c
2 changed files with 17 additions and 10 deletions
|
|
@ -116,6 +116,9 @@
|
||||||
- `std/uri.Uri` dollar `$` improved, precalculates the `string` result length from the `Uri`.
|
- `std/uri.Uri` dollar `$` improved, precalculates the `string` result length from the `Uri`.
|
||||||
|
|
||||||
|
|
||||||
|
- `std/net.IpAddress` dollar `$` improved, uses a fixed capacity for the `string` result based from the `IpAddressFamily`.
|
||||||
|
|
||||||
|
|
||||||
[//]: # "Additions:"
|
[//]: # "Additions:"
|
||||||
- Added ISO 8601 week date utilities in `times`:
|
- Added ISO 8601 week date utilities in `times`:
|
||||||
- Added `IsoWeekRange`, a range type for weeks in a week-based year.
|
- Added `IsoWeekRange`, a range type for weeks in a week-based year.
|
||||||
|
|
|
||||||
|
|
@ -1898,14 +1898,18 @@ proc `==`*(lhs, rhs: IpAddress): bool =
|
||||||
|
|
||||||
proc `$`*(address: IpAddress): string =
|
proc `$`*(address: IpAddress): string =
|
||||||
## Converts an IpAddress into the textual representation
|
## Converts an IpAddress into the textual representation
|
||||||
result = ""
|
|
||||||
case address.family
|
case address.family
|
||||||
of IpAddressFamily.IPv4:
|
of IpAddressFamily.IPv4:
|
||||||
for i in 0 .. 3:
|
result = newStringOfCap(16)
|
||||||
if i != 0:
|
result.addInt address.address_v4[0]
|
||||||
result.add('.')
|
result.add '.'
|
||||||
result.add($address.address_v4[i])
|
result.addInt address.address_v4[1]
|
||||||
|
result.add '.'
|
||||||
|
result.addInt address.address_v4[2]
|
||||||
|
result.add '.'
|
||||||
|
result.addInt address.address_v4[3]
|
||||||
of IpAddressFamily.IPv6:
|
of IpAddressFamily.IPv6:
|
||||||
|
result = newStringOfCap(48)
|
||||||
var
|
var
|
||||||
currentZeroStart = -1
|
currentZeroStart = -1
|
||||||
currentZeroCount = 0
|
currentZeroCount = 0
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue