Fix accidental negative bounds

See Araq/Nim #1979 for context
This commit is contained in:
Flaviu Tamas
2015-01-19 16:16:06 -05:00
parent b5f3a662c5
commit eb2fd618fe
2 changed files with 2 additions and 1 deletions

View File

@@ -116,7 +116,7 @@ proc `[]`*(pattern: Captures, i: int): string =
# capture count, plus the entire string
pattern.matchCache = newSeq[string](pattern.pattern.captureCount + 1)
if pattern.matchCache[i + 1] == nil:
pattern.matchCache[i + 1] = pattern.str[bounds.a .. bounds.b-1]
pattern.matchCache[i + 1] = pattern.str.substr(bounds.a, bounds.b-1)
return pattern.matchCache[i + 1]
else:
return nil

View File

@@ -19,3 +19,4 @@ suite "find":
test "len 0 find":
check("".findAll(re"\ ") == newSeq[string]())
check("".findAll(re"") == @[""])
check("word word".findAll(nre.re"\b") == @["", "", "", ""])