This commit is contained in:
Araq
2015-01-31 11:49:19 +01:00
parent ee4e95fefe
commit 8f587e2eab
3 changed files with 13 additions and 8 deletions

View File

@@ -295,7 +295,7 @@ iterator interpolatedFragments*(s: string): tuple[kind: InterpolatedKind,
dec nesting
of '\0':
raise newException(ValueError,
"Expected closing '}': " & s[i..s.len])
"Expected closing '}': " & substr(s, i, s.high))
else: discard
inc j
inc i, 2 # skip ${
@@ -311,7 +311,7 @@ iterator interpolatedFragments*(s: string): tuple[kind: InterpolatedKind,
kind = ikDollar
else:
raise newException(ValueError,
"Unable to parse a varible name at " & s[i..s.len])
"Unable to parse a varible name at " & substr(s, i, s.high))
else:
while j < s.len and s[j] != '$': inc j
kind = ikStr

View File

@@ -1042,18 +1042,20 @@ proc unescape*(s: string, prefix = "\"", suffix = "\""): string {.noSideEffect,
## ValueError exception will be raised.
result = newStringOfCap(s.len)
var i = 0
if s[0 .. prefix.len-1] != prefix:
if not s.startsWith(prefix):
raise newException(ValueError,
"String does not start with a prefix of: " & prefix)
i.inc()
inc(i)
while true:
if i == s.len-suffix.len: break
case s[i]
of '\\':
case s[i+1]:
of 'x':
let j = parseHexInt(s[i+2 .. i+3])
result.add(chr(j))
inc i
var c: int
i += parseutils.parseHex(s, c, i)
result.add(chr(c))
inc(i, 2)
of '\\':
result.add('\\')
@@ -1066,8 +1068,8 @@ proc unescape*(s: string, prefix = "\"", suffix = "\""): string {.noSideEffect,
of '\0': break
else:
result.add(s[i])
i.inc()
if s[i .. -1] != suffix:
inc(i)
if not s.endsWith(suffix):
raise newException(ValueError,
"String does not end with a suffix of: " & suffix)

View File

@@ -1,4 +1,7 @@
# bug #2041: Macros need to be available for os:standalone!
import macros
proc printf(frmt: cstring) {.varargs, header: "<stdio.h>", cdecl.}
var x = 0