fix rope index (#16100)

* fix rope index

* add testcase

(cherry picked from commit ab2c082cb3)
This commit is contained in:
flywind
2020-11-23 18:27:09 +08:00
committed by narimiran
parent fbb58343d9
commit 74fa24ce45
2 changed files with 67 additions and 1 deletions

View File

@@ -204,8 +204,8 @@ proc `[]`*(r: Rope, i: int): char {.rtl, extern: "nroCharAt".} =
if x.left.length > j:
x = x.left
else:
dec(j, x.left.length)
x = x.right
dec(j, x.len)
iterator leaves*(r: Rope): string =
## iterates over any leaf string in the rope `r`.