Merge pull request #2799 from avsej/fix-streams-peekline
Fix streams peekline
This commit is contained in:
commit
77b010bd36
1 changed files with 53 additions and 49 deletions
|
|
@ -242,7 +242,7 @@ proc peekLine*(s: Stream, line: var TaintedString): bool =
|
||||||
## otherwise. If ``false`` is returned `line` contains no new data.
|
## otherwise. If ``false`` is returned `line` contains no new data.
|
||||||
let pos = getPosition(s)
|
let pos = getPosition(s)
|
||||||
defer: setPosition(s, pos)
|
defer: setPosition(s, pos)
|
||||||
readLine(s, line)
|
result = readLine(s, line)
|
||||||
|
|
||||||
proc readLine*(s: Stream): TaintedString =
|
proc readLine*(s: Stream): TaintedString =
|
||||||
## Reads a line from a stream `s`. Note: This is not very efficient. Raises
|
## Reads a line from a stream `s`. Note: This is not very efficient. Raises
|
||||||
|
|
@ -263,7 +263,7 @@ proc peekLine*(s: Stream): TaintedString =
|
||||||
## `EIO` if an error occurred.
|
## `EIO` if an error occurred.
|
||||||
let pos = getPosition(s)
|
let pos = getPosition(s)
|
||||||
defer: setPosition(s, pos)
|
defer: setPosition(s, pos)
|
||||||
readLine(s)
|
result = readLine(s)
|
||||||
|
|
||||||
type
|
type
|
||||||
StringStream* = ref StringStreamObj ## a stream that encapsulates a string
|
StringStream* = ref StringStreamObj ## a stream that encapsulates a string
|
||||||
|
|
@ -458,3 +458,7 @@ when defined(testing):
|
||||||
assert(ss.getPosition == 5) # did move
|
assert(ss.getPosition == 5) # did move
|
||||||
assert(ss.peekLine() == "uick brown fox jumped over the lazy dog.")
|
assert(ss.peekLine() == "uick brown fox jumped over the lazy dog.")
|
||||||
assert(ss.getPosition == 5) # haven't moved
|
assert(ss.getPosition == 5) # haven't moved
|
||||||
|
var str = newString(100)
|
||||||
|
assert(ss.peekLine(str))
|
||||||
|
assert(str == "uick brown fox jumped over the lazy dog.")
|
||||||
|
assert(ss.getPosition == 5) # haven't moved
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue