mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-29 17:34:43 +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:
|
||||
|
||||
3
todo.txt
3
todo.txt
@@ -3,6 +3,7 @@ version 0.9.0
|
||||
|
||||
- implement "closure tuple consists of a single 'ref'" optimization
|
||||
- implement for loop transformation for first class iterators
|
||||
- make templates hygienic by default: 'gensym', 'inject' pragmas
|
||||
|
||||
- implicit deref for parameter matching
|
||||
- ``final`` should be the default for objects
|
||||
@@ -41,8 +42,6 @@ version 0.9.XX
|
||||
- ``hoist`` pragma for loop hoisting
|
||||
- document destructors; don't work yet when used as expression
|
||||
- make use of ``tyIter`` to fix the implicit items/pairs issue
|
||||
- make templates hygienic by default: try to gensym() everything in the 'block'
|
||||
of a template; find a better solution for gensym instead of `*ident`
|
||||
- introduce 'callsite' magic and make macros and templates the same
|
||||
- better support for macros that rewrite procs
|
||||
- macros need access to types and symbols
|
||||
|
||||
@@ -63,6 +63,8 @@ Library Additions
|
||||
only support fixed length arrays).
|
||||
- Added ``system.compiles`` which can be used to check whether a type supports
|
||||
some operation.
|
||||
- Added ``strutils.format``, ``subexes.format`` which use the
|
||||
new ``varargs`` type.
|
||||
|
||||
|
||||
Changes affecting backwards compatibility
|
||||
|
||||
Reference in New Issue
Block a user