fixes #2041
This commit is contained in:
parent
ee4e95fefe
commit
8f587e2eab
3 changed files with 13 additions and 8 deletions
|
|
@ -295,7 +295,7 @@ iterator interpolatedFragments*(s: string): tuple[kind: InterpolatedKind,
|
||||||
dec nesting
|
dec nesting
|
||||||
of '\0':
|
of '\0':
|
||||||
raise newException(ValueError,
|
raise newException(ValueError,
|
||||||
"Expected closing '}': " & s[i..s.len])
|
"Expected closing '}': " & substr(s, i, s.high))
|
||||||
else: discard
|
else: discard
|
||||||
inc j
|
inc j
|
||||||
inc i, 2 # skip ${
|
inc i, 2 # skip ${
|
||||||
|
|
@ -311,7 +311,7 @@ iterator interpolatedFragments*(s: string): tuple[kind: InterpolatedKind,
|
||||||
kind = ikDollar
|
kind = ikDollar
|
||||||
else:
|
else:
|
||||||
raise newException(ValueError,
|
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:
|
else:
|
||||||
while j < s.len and s[j] != '$': inc j
|
while j < s.len and s[j] != '$': inc j
|
||||||
kind = ikStr
|
kind = ikStr
|
||||||
|
|
|
||||||
|
|
@ -1042,18 +1042,20 @@ proc unescape*(s: string, prefix = "\"", suffix = "\""): string {.noSideEffect,
|
||||||
## ValueError exception will be raised.
|
## ValueError exception will be raised.
|
||||||
result = newStringOfCap(s.len)
|
result = newStringOfCap(s.len)
|
||||||
var i = 0
|
var i = 0
|
||||||
if s[0 .. prefix.len-1] != prefix:
|
if not s.startsWith(prefix):
|
||||||
raise newException(ValueError,
|
raise newException(ValueError,
|
||||||
"String does not start with a prefix of: " & prefix)
|
"String does not start with a prefix of: " & prefix)
|
||||||
i.inc()
|
inc(i)
|
||||||
while true:
|
while true:
|
||||||
if i == s.len-suffix.len: break
|
if i == s.len-suffix.len: break
|
||||||
case s[i]
|
case s[i]
|
||||||
of '\\':
|
of '\\':
|
||||||
case s[i+1]:
|
case s[i+1]:
|
||||||
of 'x':
|
of 'x':
|
||||||
let j = parseHexInt(s[i+2 .. i+3])
|
inc i
|
||||||
result.add(chr(j))
|
var c: int
|
||||||
|
i += parseutils.parseHex(s, c, i)
|
||||||
|
result.add(chr(c))
|
||||||
inc(i, 2)
|
inc(i, 2)
|
||||||
of '\\':
|
of '\\':
|
||||||
result.add('\\')
|
result.add('\\')
|
||||||
|
|
@ -1066,8 +1068,8 @@ proc unescape*(s: string, prefix = "\"", suffix = "\""): string {.noSideEffect,
|
||||||
of '\0': break
|
of '\0': break
|
||||||
else:
|
else:
|
||||||
result.add(s[i])
|
result.add(s[i])
|
||||||
i.inc()
|
inc(i)
|
||||||
if s[i .. -1] != suffix:
|
if not s.endsWith(suffix):
|
||||||
raise newException(ValueError,
|
raise newException(ValueError,
|
||||||
"String does not end with a suffix of: " & suffix)
|
"String does not end with a suffix of: " & suffix)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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.}
|
proc printf(frmt: cstring) {.varargs, header: "<stdio.h>", cdecl.}
|
||||||
|
|
||||||
var x = 0
|
var x = 0
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue