mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-17 18:17:11 +00:00
Make $ on 0-length MemSlice produce Nim "" as per DMisener idea (#24015)
in https://forum.nim-lang.org/t/12463 which seems reasonable enough to me. stdlib has several dozens of places doing result.setLen now, but if `experimental:strictDefs` move sot on by default and there is no easy way to locally suppress the warning we can revisit this.
This commit is contained in:
@@ -412,7 +412,7 @@ proc `==`*(x, y: MemSlice): bool =
|
||||
proc `$`*(ms: MemSlice): string {.inline.} =
|
||||
## Return a Nim string built from a MemSlice.
|
||||
result.setLen(ms.size)
|
||||
copyMem(addr(result[0]), ms.data, ms.size)
|
||||
copyMem(result.cstring, ms.data, ms.size)
|
||||
|
||||
iterator memSlices*(mfile: MemFile, delim = '\l', eat = '\r'): MemSlice {.inline.} =
|
||||
## Iterates over \[optional `eat`] `delim`-delimited slices in MemFile `mfile`.
|
||||
|
||||
Reference in New Issue
Block a user