mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-02 03:02:31 +00:00
fix ropes format errors (#16106) [backport:1.0]
* fix rope index
* add testcase
* fix ropes format
(cherry picked from commit 0c6c4be0e7)
This commit is contained in:
@@ -262,7 +262,7 @@ proc `%`*(frmt: string, args: openArray[Rope]): Rope {.
|
||||
while true:
|
||||
j = j * 10 + ord(frmt[i]) - ord('0')
|
||||
inc(i)
|
||||
if frmt[i] notin {'0'..'9'}: break
|
||||
if i >= frmt.len or frmt[i] notin {'0'..'9'}: break
|
||||
add(result, args[j-1])
|
||||
of '{':
|
||||
inc(i)
|
||||
|
||||
@@ -64,3 +64,10 @@ block:
|
||||
inc i
|
||||
|
||||
doAssert r[66] == '\0'
|
||||
|
||||
block:
|
||||
let r1 = "$1 $2 $3" % [rope("Nim"), rope("is"), rope("a great language")]
|
||||
doAssert $r1 == "Nim is a great language"
|
||||
|
||||
let r2 = "$# $# $#" % [rope("Nim"), rope("is"), rope("a great language")]
|
||||
doAssert $r2 == "Nim is a great language"
|
||||
|
||||
Reference in New Issue
Block a user