diff options
author | Araq <rumpf_a@web.de> | 2012-08-16 16:30:13 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2012-08-16 16:30:13 +0200 |
commit | d37fe6e0a5cc414c24dbff485ee656cc6f16eed8 (patch) | |
tree | 74e3faa868d278c4cb0ca749b939c02502b7db7b /lib/pure | |
parent | bbae747f02a67e36411b0d0168ebac4912ef7555 (diff) | |
download | Nim-d37fe6e0a5cc414c24dbff485ee656cc6f16eed8.tar.gz |
stdlib uses more of varargs
Diffstat (limited to 'lib/pure')
-rwxr-xr-x | lib/pure/strutils.nim | 2 | ||||
-rw-r--r-- | lib/pure/subexes.nim | 11 |
2 files changed, 11 insertions, 2 deletions
diff --git a/lib/pure/strutils.nim b/lib/pure/strutils.nim index a93c3d289..2509bf689 100755 --- a/lib/pure/strutils.nim +++ b/lib/pure/strutils.nim @@ -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', '_'} diff --git a/lib/pure/subexes.nim b/lib/pure/subexes.nim index 7ab5d1ad3..3e5e36b38 100644 --- a/lib/pure/subexes.nim +++ b/lib/pure/subexes.nim @@ -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: |