Stream-writer for a rope (#6603)
This commit is contained in:
parent
11f6e626d7
commit
87a46765ee
1 changed files with 7 additions and 3 deletions
|
|
@ -17,6 +17,7 @@
|
||||||
## runtime efficiency.
|
## runtime efficiency.
|
||||||
|
|
||||||
include "system/inclrtl"
|
include "system/inclrtl"
|
||||||
|
import streams
|
||||||
|
|
||||||
{.deadCodeElim: on.}
|
{.deadCodeElim: on.}
|
||||||
|
|
||||||
|
|
@ -130,7 +131,7 @@ proc insertInCache(s: string, tree: Rope): Rope =
|
||||||
result.left = t
|
result.left = t
|
||||||
t.right = nil
|
t.right = nil
|
||||||
|
|
||||||
proc rope*(s: string): Rope {.rtl, extern: "nro$1Str".} =
|
proc rope*(s: string = nil): Rope {.rtl, extern: "nro$1Str".} =
|
||||||
## Converts a string to a rope.
|
## Converts a string to a rope.
|
||||||
if s.len == 0:
|
if s.len == 0:
|
||||||
result = nil
|
result = nil
|
||||||
|
|
@ -242,10 +243,13 @@ proc write*(f: File, r: Rope) {.rtl, extern: "nro$1".} =
|
||||||
## writes a rope to a file.
|
## writes a rope to a file.
|
||||||
for s in leaves(r): write(f, s)
|
for s in leaves(r): write(f, s)
|
||||||
|
|
||||||
|
proc write*(s: Stream, r: Rope) {.rtl, extern: "nro$1".} =
|
||||||
|
## writes a rope to a stream.
|
||||||
|
for rs in leaves(r): write(s, rs)
|
||||||
|
|
||||||
proc `$`*(r: Rope): string {.rtl, extern: "nroToString".}=
|
proc `$`*(r: Rope): string {.rtl, extern: "nroToString".}=
|
||||||
## converts a rope back to a string.
|
## converts a rope back to a string.
|
||||||
result = newString(r.len)
|
result = newStringOfCap(r.len)
|
||||||
setLen(result, 0)
|
|
||||||
for s in leaves(r): add(result, s)
|
for s in leaves(r): add(result, s)
|
||||||
|
|
||||||
when false:
|
when false:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue