Merge pull request #3073 from apense/patch-12

Added safeAdd documentation
This commit is contained in:
Andreas Rumpf
2015-07-11 13:23:07 +02:00

View File

@@ -3286,14 +3286,19 @@ when declared(initDebugger):
when hasAlloc:
# XXX: make these the default (or implement the NilObject optimization)
proc safeAdd*[T](x: var seq[T], y: T) {.noSideEffect.} =
## Adds ``y`` to ``x`` unless ``x`` is not yet initialized; in that case,
## ``x`` becomes ``@[y]``
if x == nil: x = @[y]
else: x.add(y)
proc safeAdd*(x: var string, y: char) =
## Adds ``y`` to ``x``. If ``x`` is ``nil`` it is initialized to ``""``
if x == nil: x = ""
x.add(y)
proc safeAdd*(x: var string, y: string) =
## Adds ``y`` to ``x`` unless ``x`` is not yet initalized; in that case, ``x``
## becomes ``y``
if x == nil: x = y
else: x.add(y)