diff options
author | Parashurama <Rhagdamaziel@ymail.com> | 2017-02-01 12:13:01 +0100 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2017-02-01 12:13:01 +0100 |
commit | c57fcf42df4206229de10c8ed0463fe94517bd4b (patch) | |
tree | 6e0e306ed40c3d49d2a30fb6cc50873a513a2d07 /lib | |
parent | d90f3f59aca668d3000d6fd64199bfe720240911 (diff) | |
download | Nim-c57fcf42df4206229de10c8ed0463fe94517bd4b.tar.gz |
fix string slice & splice (#5311)
code fixes courtesy of @memophen
Diffstat (limited to 'lib')
-rw-r--r-- | lib/system.nim | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/lib/system.nim b/lib/system.nim index 75014ff26..09d48fd12 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -3252,19 +3252,18 @@ proc `/`*(x, y: int): float {.inline, noSideEffect.} = template spliceImpl(s, a, L, b: untyped): untyped = # make room for additional elements or cut: - var slen = s.len - var shift = b.len - L - var newLen = slen + shift + var shift = b.len - max(0,L) # ignore negative slice size + var newLen = s.len + shift if shift > 0: # enlarge: setLen(s, newLen) - for i in countdown(newLen-1, a+shift+1): shallowCopy(s[i], s[i-shift]) + for i in countdown(newLen-1, a+b.len): shallowCopy(s[i], s[i-shift]) else: - for i in countup(a+b.len, s.len-1+shift): shallowCopy(s[i], s[i-shift]) + for i in countup(a+b.len, newLen-1): shallowCopy(s[i], s[i-shift]) # cut down: setLen(s, newLen) # fill the hole: - for i in 0 .. <b.len: s[i+a] = b[i] + for i in 0 .. <b.len: s[a+i] = b[i] when hasAlloc or defined(nimscript): proc `[]`*(s: string, x: Slice[int]): string {.inline.} = |