mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-01 10:52:14 +00:00
Add items, mitems and mpairs for cstrings
This commit is contained in:
@@ -1696,6 +1696,13 @@ iterator items*(a: cstring): char {.inline.} =
|
||||
yield a[i]
|
||||
inc(i)
|
||||
|
||||
iterator mitems*(a: var cstring): var char {.inline.} =
|
||||
## iterates over each item of `a` so that you can modify the yielded value.
|
||||
var i = 0
|
||||
while a[i] != '\0':
|
||||
yield a[i]
|
||||
inc(i)
|
||||
|
||||
iterator items*(E: typedesc[enum]): E =
|
||||
## iterates over the values of the enum ``E``.
|
||||
for v in low(E)..high(E):
|
||||
@@ -1765,6 +1772,21 @@ iterator mpairs*(a: var string): tuple[key: int, val: var char] {.inline.} =
|
||||
yield (i, a[i])
|
||||
inc(i)
|
||||
|
||||
iterator pairs*(a: cstring): tuple[key: int, val: char] {.inline.} =
|
||||
## iterates over each item of `a`. Yields ``(index, a[index])`` pairs.
|
||||
var i = 0
|
||||
while a[i] != '\0':
|
||||
yield (i, a[i])
|
||||
inc(i)
|
||||
|
||||
iterator mpairs*(a: var cstring): tuple[key: int, val: var char] {.inline.} =
|
||||
## iterates over each item of `a`. Yields ``(index, a[index])`` pairs.
|
||||
## ``a[index]`` can be modified.
|
||||
var i = 0
|
||||
while a[i] != '\0':
|
||||
yield (i, a[i])
|
||||
inc(i)
|
||||
|
||||
|
||||
proc isNil*[T](x: seq[T]): bool {.noSideEffect, magic: "IsNil".}
|
||||
proc isNil*[T](x: ref T): bool {.noSideEffect, magic: "IsNil".}
|
||||
|
||||
Reference in New Issue
Block a user