Bugfix: strutils.delete
This commit is contained in:
parent
c5d8a5c1da
commit
7d6de1cf90
3 changed files with 19 additions and 8 deletions
|
|
@ -655,13 +655,13 @@ proc delete*(s: var string, first, last: int) =
|
||||||
## Deletes in `s` the characters at position `first`..`last`. This modifies
|
## Deletes in `s` the characters at position `first`..`last`. This modifies
|
||||||
## `s` itself, it does not return a copy.
|
## `s` itself, it does not return a copy.
|
||||||
var i = first
|
var i = first
|
||||||
# example: "abc___uvwxyz\0" (___ is to be deleted)
|
var j = last+1
|
||||||
# --> first == 3, last == 5
|
var newLen = len(s)-j+i
|
||||||
# s[first..] = s[last+1..]
|
while i < newLen:
|
||||||
while last+i+1 < len(s):
|
s[i] = s[j]
|
||||||
s[i] = s[last+i+1]
|
|
||||||
inc(i)
|
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, sub, by: string): string = return replace(s, sub, by)
|
||||||
proc replaceStr(s: string, sub, by: char): 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")
|
else: InternalError(a.info, "leValueConv")
|
||||||
|
|
||||||
proc magicCall(m: PSym, n: PNode): PNode =
|
proc magicCall(m: PSym, n: PNode): PNode =
|
||||||
var s = n.sons[0].sym
|
|
||||||
if sonsLen(n) <= 1: return
|
if sonsLen(n) <= 1: return
|
||||||
|
|
||||||
|
var s = n.sons[0].sym
|
||||||
var a = getConstExpr(m, n.sons[1])
|
var a = getConstExpr(m, n.sons[1])
|
||||||
var b, c: PNode
|
var b, c: PNode
|
||||||
if a == nil: return
|
if a == nil: return
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,17 @@ proc main() =
|
||||||
testStrip()
|
testStrip()
|
||||||
for p in split("/home/a1:xyz:/usr/bin", {':'}):
|
for p in split("/home/a1:xyz:/usr/bin", {':'}):
|
||||||
write(stdout, p)
|
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($1000_000) == "1_000_000")
|
||||||
assert(insertSep($232) == "232")
|
assert(insertSep($232) == "232")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue