Fix newline finding
This commit is contained in:
@@ -361,10 +361,10 @@ func highlightStreamPosition2(stream: string, position: int): string =
|
|||||||
|
|
||||||
let (lineStartPosition, lineEndPosition) =
|
let (lineStartPosition, lineEndPosition) =
|
||||||
case ch:
|
case ch:
|
||||||
# of '\n':
|
of '\n':
|
||||||
# let lineStartPosition = (position - 1).max(0)
|
let lineStartPosition = (position - 1).max(0)
|
||||||
# let lineEndPosition = (position).min(stream.len - 1)
|
let lineEndPosition = (position + 1).min(stream.len - 1)
|
||||||
# (lineStartPosition, lineEndPosition)
|
(lineStartPosition, lineEndPosition)
|
||||||
else:
|
else:
|
||||||
(position, position)
|
(position, position)
|
||||||
|
|
||||||
@@ -452,16 +452,22 @@ proc `$`*(x: ParserError): string =
|
|||||||
else: "ParseError"
|
else: "ParseError"
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
let test1 = """AB
|
let test1 = """ABC
|
||||||
|
|
||||||
|
D
|
||||||
|
|
||||||
|
EFG"""
|
||||||
|
# echo test1.highlightStreamPosition2(test1.find("B"))
|
||||||
|
# echo "=============="
|
||||||
|
# echo test1.highlightStreamPosition2(test1.find("C"))
|
||||||
|
# echo "=============="
|
||||||
|
# echo test1.highlightStreamPosition2(test1.find("D"))
|
||||||
|
|
||||||
|
|
||||||
|
echo test1.highlightStreamPosition2(test1.find("\n"))
|
||||||
|
echo test1.highlightStreamPosition2(test1.find("\n", test1.find("\n") + 1))
|
||||||
|
|
||||||
C
|
|
||||||
|
|
||||||
D"""
|
|
||||||
echo test1.highlightStreamPosition2(test1.find("B"))
|
|
||||||
echo "=============="
|
|
||||||
echo test1.highlightStreamPosition2(test1.find("C"))
|
|
||||||
echo "=============="
|
|
||||||
echo test1.highlightStreamPosition2(test1.find("D"))
|
|
||||||
# echo "\n1\n".rfind('\n', 0, 2)
|
# echo "\n1\n".rfind('\n', 0, 2)
|
||||||
|
|
||||||
# block highlightStreamPosition:
|
# block highlightStreamPosition:
|
||||||
|
|||||||
Reference in New Issue
Block a user