mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-11 22:28:12 +00:00
Bugfix: strutils.delete
This commit is contained in:
@@ -655,13 +655,13 @@ proc delete*(s: var string, first, last: int) =
|
||||
## Deletes in `s` the characters at position `first`..`last`. This modifies
|
||||
## `s` itself, it does not return a copy.
|
||||
var i = first
|
||||
# example: "abc___uvwxyz\0" (___ is to be deleted)
|
||||
# --> first == 3, last == 5
|
||||
# s[first..] = s[last+1..]
|
||||
while last+i+1 < len(s):
|
||||
s[i] = s[last+i+1]
|
||||
var j = last+1
|
||||
var newLen = len(s)-j+i
|
||||
while i < newLen:
|
||||
s[i] = s[j]
|
||||
inc(i)
|
||||
setlen(s, len(s)-(last-first+1))
|
||||
inc(j)
|
||||
setlen(s, newLen)
|
||||
|
||||
proc replaceStr(s, sub, by: string): string = return replace(s, sub, by)
|
||||
proc replaceStr(s: string, sub, by: char): string = return replace(s, sub, by)
|
||||
|
||||
@@ -258,9 +258,9 @@ proc leValueConv(a, b: PNode): bool =
|
||||
else: InternalError(a.info, "leValueConv")
|
||||
|
||||
proc magicCall(m: PSym, n: PNode): PNode =
|
||||
var s = n.sons[0].sym
|
||||
if sonsLen(n) <= 1: return
|
||||
|
||||
|
||||
var s = n.sons[0].sym
|
||||
var a = getConstExpr(m, n.sons[1])
|
||||
var b, c: PNode
|
||||
if a == nil: return
|
||||
|
||||
@@ -10,6 +10,17 @@ proc main() =
|
||||
testStrip()
|
||||
for p in split("/home/a1:xyz:/usr/bin", {':'}):
|
||||
write(stdout, p)
|
||||
|
||||
proc testDelete =
|
||||
var s = "0123456789ABCDEFGH"
|
||||
delete(s, 4, 5)
|
||||
assert s == "01236789ABCDEFGH"
|
||||
delete(s, s.len-1, s.len-1)
|
||||
assert s == "01236789ABCDEFG"
|
||||
delete(s, 0, 0)
|
||||
assert s == "1236789ABCDEFG"
|
||||
|
||||
testDelete()
|
||||
|
||||
assert(insertSep($1000_000) == "1_000_000")
|
||||
assert(insertSep($232) == "232")
|
||||
|
||||
Reference in New Issue
Block a user