deprecated system.copy: use system.substr instead

This commit is contained in:
Araq 2011-05-14 01:13:44 +02:00
commit 3e9dcc8be5
31 changed files with 122 additions and 109 deletions

View file

@ -83,7 +83,7 @@ proc capitalize*(s: string): string {.noSideEffect, procvar,
rtl, extern: "nsuCapitalize".} =
## Converts the first character of `s` into upper case.
## This works only for the letters a-z.
result = toUpper(s[0]) & copy(s, 1)
result = toUpper(s[0]) & substr(s, 1)
proc normalize*(s: string): string {.noSideEffect, procvar,
rtl, extern: "nsuNormalize".} =
@ -175,14 +175,14 @@ proc addf*(s: var string, formatstr: string, a: openarray[string]) {.
of '{':
var j = i+1
while formatstr[j] notin {'\0', '}'}: inc(j)
var x = findNormalized(copy(formatstr, i+2, j-1), a)
var x = findNormalized(substr(formatstr, i+2, j-1), a)
if x >= 0 and x < high(a): add s, a[x+1]
else: raise newException(EInvalidValue, "invalid format string")
i = j+1
of 'a'..'z', 'A'..'Z', '\128'..'\255', '_':
var j = i+1
while formatstr[j] in PatternChars: inc(j)
var x = findNormalized(copy(formatstr, i+1, j-1), a)
var x = findNormalized(substr(formatstr, i+1, j-1), a)
if x >= 0 and x < high(a): add s, a[x+1]
else: raise newException(EInvalidValue, "invalid format string")
i = j
@ -253,7 +253,7 @@ proc strip*(s: string, leading = true, trailing = true): string {.noSideEffect,
while s[first] in chars: inc(first)
if trailing:
while last >= 0 and s[last] in chars: dec(last)
result = copy(s, first, last)
result = substr(s, first, last)
proc toOctal*(c: char): string {.noSideEffect, rtl, extern: "nsuToOctal".} =
## Converts a character `c` to its octal representation. The resulting
@ -293,7 +293,7 @@ iterator split*(s: string, seps: set[char] = Whitespace): string =
var first = last
while last < len(s) and s[last] not_in seps: inc(last) # BUGFIX!
if first <= last-1:
yield copy(s, first, last-1)
yield substr(s, first, last-1)
iterator split*(s: string, sep: char): string =
## Splits the string `s` into substrings.
@ -326,7 +326,7 @@ iterator split*(s: string, sep: char): string =
while last <= len(s):
var first = last
while last < len(s) and s[last] != sep: inc(last)
yield copy(s, first, last-1)
yield substr(s, first, last-1)
inc(last)
iterator splitLines*(s: string): string =
@ -354,7 +354,7 @@ iterator splitLines*(s: string): string =
var last = 0
while true:
while s[last] notin {'\0', '\c', '\l'}: inc(last)
yield copy(s, first, last-1)
yield substr(s, first, last-1)
# skip newlines:
if s[last] == '\l': inc(last)
elif s[last] == '\c':
@ -504,7 +504,7 @@ iterator tokenize*(s: string, seps: set[char] = Whitespace): tuple[
var isSep = s[j] in seps
while j < s.len and (s[j] in seps) == isSep: inc(j)
if j > i:
yield (copy(s, i, j-1), isSep)
yield (substr(s, i, j-1), isSep)
else:
break
i = j
@ -520,14 +520,14 @@ proc wordWrap*(s: string, maxLineWidth = 80,
for word, isSep in tokenize(s, seps):
if len(word) > SpaceLeft:
if splitLongWords and len(word) > maxLineWidth:
result.add(copy(word, 0, spaceLeft-1))
result.add(substr(word, 0, spaceLeft-1))
var w = spaceLeft+1
var wordLeft = len(word) - spaceLeft
while wordLeft > 0:
result.add(newLine)
var L = min(maxLineWidth, wordLeft)
SpaceLeft = maxLineWidth - L
result.add(copy(word, w, w+L-1))
result.add(substr(word, w, w+L-1))
inc(w, L)
dec(wordLeft, L)
else:
@ -705,11 +705,11 @@ proc replace*(s, sub: string, by = ""): string {.noSideEffect,
while true:
var j = findAux(s, sub, i, a)
if j < 0: break
add result, copy(s, i, j - 1)
add result, substr(s, i, j - 1)
add result, by
i = j + len(sub)
# copy the rest:
add result, copy(s, i)
add result, substr(s, i)
proc replace*(s: string, sub, by: char): string {.noSideEffect,
rtl, extern: "nsuReplaceChar".} =
@ -843,7 +843,7 @@ proc validEmailAddress*(s: string): bool {.noSideEffect,
while s[i] in {'0'..'9', 'a'..'z', '-', '.'}: inc(i)
if s[i] != '\0': return false
var x = copy(s, j+1)
var x = substr(s, j+1)
if len(x) == 2 and x[0] in Letters and x[1] in Letters: return true
case toLower(x)
of "com", "org", "net", "gov", "mil", "biz", "info", "mobi", "name",