summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2018-04-30 08:53:31 +0200
committerAndreas Rumpf <rumpf_a@web.de>2018-04-30 08:53:31 +0200
commit5758ebf02c28e1071036d1dc9ae9e1265c6dc28c (patch)
tree5a39618bbf194607951ab97ecdcf6eb6b439956a /lib
parent87f548c5f4027a0faf57acf0878f7c5db382222c (diff)
downloadNim-5758ebf02c28e1071036d1dc9ae9e1265c6dc28c.tar.gz
more fixes for the new string behaviour
Diffstat (limited to 'lib')
-rw-r--r--lib/pure/os.nim20
-rw-r--r--lib/pure/pegs.nim2
2 files changed, 10 insertions, 12 deletions
diff --git a/lib/pure/os.nim b/lib/pure/os.nim
index 11be8f0c1..644afee32 100644
--- a/lib/pure/os.nim
+++ b/lib/pure/os.nim
@@ -1060,18 +1060,17 @@ proc parseCmdLine*(c: string): seq[string] {.
   while true:
     setLen(a, 0)
     # eat all delimiting whitespace
-    while c[i] == ' ' or c[i] == '\t' or c[i] == '\l' or c[i] == '\r' : inc(i)
+    while i < c.len and c[i] in {' ', '\t', '\l', '\r'}: inc(i)
+    if i >= c.len: break
     when defined(windows):
       # parse a single argument according to the above rules:
-      if c[i] == '\0': break
       var inQuote = false
-      while true:
+      while i < c.len:
         case c[i]
-        of '\0': break
         of '\\':
           var j = i
-          while c[j] == '\\': inc(j)
-          if c[j] == '"':
+          while j < c.len and c[j] == '\\': inc(j)
+          if j < c.len and c[j] == '"':
             for k in 1..(j-i) div 2: a.add('\\')
             if (j-i) mod 2 == 0:
               i = j
@@ -1084,7 +1083,7 @@ proc parseCmdLine*(c: string): seq[string] {.
         of '"':
           inc(i)
           if not inQuote: inQuote = true
-          elif c[i] == '"':
+          elif i < c.len and c[i] == '"':
             a.add(c[i])
             inc(i)
           else:
@@ -1102,13 +1101,12 @@ proc parseCmdLine*(c: string): seq[string] {.
       of '\'', '\"':
         var delim = c[i]
         inc(i) # skip ' or "
-        while c[i] != '\0' and c[i] != delim:
+        while i < c.len and c[i] != delim:
           add a, c[i]
           inc(i)
-        if c[i] != '\0': inc(i)
-      of '\0': break
+        if i < c.len: inc(i)
       else:
-        while c[i] > ' ':
+        while i < c.len and c[i] > ' ':
           add(a, c[i])
           inc(i)
     add(result, a)
diff --git a/lib/pure/pegs.nim b/lib/pure/pegs.nim
index 90a460776..6d415efd0 100644
--- a/lib/pure/pegs.nim
+++ b/lib/pure/pegs.nim
@@ -606,7 +606,7 @@ proc rawMatch*(s: string, p: Peg, start: int, c: var Captures): int {.
       a, b: Rune
     result = start
     while i < len(p.term):
-      if i >= s.len:
+      if result >= s.len:
         result = -1
         break
       fastRuneAt(p.term, i, a)