mirror of
https://github.com/nim-lang/Nim.git
synced 2026-07-29 19:57:58 +00:00
stdlib uses more of varargs
This commit is contained in:
@@ -1015,7 +1015,7 @@ proc findNormalized(x: string, inArray: openarray[string]): int =
|
||||
proc invalidFormatString() {.noinline.} =
|
||||
raise newException(EInvalidValue, "invalid format string")
|
||||
|
||||
proc addf*(s: var string, formatstr: string, a: openarray[string]) {.
|
||||
proc addf*(s: var string, formatstr: string, a: varargs[string, `$`]) {.
|
||||
noSideEffect, rtl, extern: "nsuAddf".} =
|
||||
## The same as ``add(s, formatstr % a)``, but more efficient.
|
||||
const PatternChars = {'a'..'z', 'A'..'Z', '0'..'9', '\128'..'\255', '_'}
|
||||
|
||||
@@ -297,7 +297,7 @@ proc subex*(s: string): TSubex =
|
||||
## no syntax checking but this may change in later versions.
|
||||
result = TSubex(s)
|
||||
|
||||
proc addf*(s: var string, formatstr: TSubex, a: openarray[string]) {.
|
||||
proc addf*(s: var string, formatstr: TSubex, a: varargs[string, `$`]) {.
|
||||
noSideEffect, rtl, extern: "nfrmtAddf".} =
|
||||
## The same as ``add(s, formatstr % a)``, but more efficient.
|
||||
var p: TFormatParser
|
||||
@@ -326,6 +326,15 @@ proc `%` *(formatstr: TSubex, a: string): string {.noSideEffect,
|
||||
result = newStringOfCap(formatstr.string.len + a.len)
|
||||
addf(result, formatstr, [a])
|
||||
|
||||
proc format*(formatstr: TSubex, a: varargs[string, `$`]): string {.noSideEffect,
|
||||
rtl, extern: "nfrmtFormatVarargs".} =
|
||||
## The `substitution`:idx: operator performs string substitutions in
|
||||
## `formatstr` and returns a modified `formatstr`. This is often called
|
||||
## `string interpolation`:idx:.
|
||||
##
|
||||
result = newStringOfCap(formatstr.string.len + a.len shl 4)
|
||||
addf(result, formatstr, a)
|
||||
|
||||
{.pop.}
|
||||
|
||||
when isMainModule:
|
||||
|
||||
Reference in New Issue
Block a user