summary refs log tree commit diff stats
path: root/src/nre.nim
diff options
context:
space:
mode:
authorOleh Prypin <blaxpirit@gmail.com>2015-04-09 23:49:26 +0300
committerOleh Prypin <blaxpirit@gmail.com>2015-04-09 23:51:17 +0300
commit2f0375c4c814ffec2dcad38bd576e288fb81c4f3 (patch)
tree23b9a4cf58a67e0be1f8354a995fa86cfd0a3afb /src/nre.nim
parent7e44c08270004a7783e130e5b43dbca5d9a10245 (diff)
downloadNim-2f0375c4c814ffec2dcad38bd576e288fb81c4f3.tar.gz
Change endpos to inclusive
Diffstat (limited to 'src/nre.nim')
-rw-r--r--src/nre.nim12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/nre.nim b/src/nre.nim
index a9bbc31d5..af5dab785 100644
--- a/src/nre.nim
+++ b/src/nre.nim
@@ -311,7 +311,7 @@ proc matchImpl(str: string, pattern: Regex, start, endpos: int, flags: int): Opt
   result.pcreMatchBounds = newSeq[Slice[cint]](ceil(vecsize / 2).int)
   result.pcreMatchBounds.setLen(vecsize div 3)
 
-  let strlen = if endpos == int.high: str.len else: endpos
+  let strlen = if endpos == int.high: str.len else: endpos+1
 
   let execRet = pcre.exec(pattern.pcreObj,
                           pattern.pcreExtra,
@@ -335,7 +335,7 @@ iterator findIter*(str: string, pattern: Regex, start = 0, endpos = int.high): R
   # see pcredemo for explaination
   let matchesCrLf = pattern.matchesCrLf()
   let unicode = (getinfo[cint](pattern, pcre.INFO_OPTIONS) and pcre.UTF8) > 0
-  let endpos = if endpos == int.high: str.len else: endpos
+  let strlen = if endpos == int.high: str.len else: endpos+1
 
   var offset = start
   var match: Option[RegexMatch]
@@ -361,13 +361,13 @@ iterator findIter*(str: string, pattern: Regex, start = 0, endpos = int.high): R
       elif unicode:
         # XXX what about invalid unicode?
         offset += str.runeLenAt(offset)
-        assert(offset <= endpos)
+        assert(offset <= strlen)
     else:
       offset = match.get.matchBounds.b + 1
 
       yield match.get
 
-    if offset >= endpos:
+    if offset >= strlen:
       # do while
       break
 
@@ -390,11 +390,11 @@ proc split*(str: string, pattern: Regex, maxSplit = -1, start = 0): seq[string]
   var bounds = 0 .. -1
 
   for match in str.findIter(pattern, start = start):
-    # upper bound is exclusive, lower is inclusive:
+    # bounds are inclusive:
     #
     # 0123456
     #  ^^^
-    # (1, 4)
+    # (1, 3)
     bounds = match.matchBounds
 
     # "12".split("") would be @["", "1", "2"], but