mirror of
https://github.com/nim-lang/Nim.git
synced 2026-05-23 05:09:54 +00:00
s/asSeq/toSeq
`toSeq` is a better name for it
This commit is contained in:
10
src/nre.nim
10
src/nre.nim
@@ -156,7 +156,7 @@ proc asTable*(pattern: CaptureBounds, default = None[Slice[int]]()):
|
||||
result = initTable[string, Option[Slice[int]]]()
|
||||
asTableImpl(nextVal.isNone)
|
||||
|
||||
template asSeqImpl(cond: bool): stmt {.immediate, dirty.} =
|
||||
template toSeqImpl(cond: bool): stmt {.immediate, dirty.} =
|
||||
result = @[]
|
||||
for i in 0 .. <RegexMatch(pattern).pattern.captureCount:
|
||||
let nextVal = pattern[i]
|
||||
@@ -165,11 +165,11 @@ template asSeqImpl(cond: bool): stmt {.immediate, dirty.} =
|
||||
else:
|
||||
result.add(nextVal)
|
||||
|
||||
proc asSeq*(pattern: CaptureBounds, default = None[Slice[int]]()): seq[Option[Slice[int]]] =
|
||||
asSeqImpl(nextVal.isNone)
|
||||
proc toSeq*(pattern: CaptureBounds, default = None[Slice[int]]()): seq[Option[Slice[int]]] =
|
||||
toSeqImpl(nextVal.isNone)
|
||||
|
||||
proc asSeq*(pattern: Captures, default: string = nil): seq[string] =
|
||||
asSeqImpl(nextVal == nil)
|
||||
proc toSeq*(pattern: Captures, default: string = nil): seq[string] =
|
||||
toSeqImpl(nextVal == nil)
|
||||
# }}}
|
||||
|
||||
# Creation & Destruction {{{
|
||||
|
||||
@@ -50,10 +50,10 @@ suite "captures":
|
||||
|
||||
test "capture sequence":
|
||||
let ex1 = "foo".match(initRegex("(?<foo>foo)(?<bar>bar)?"))
|
||||
check(ex1.captures.asSeq == @["foo", nil])
|
||||
check(ex1.captureBounds.asSeq == @[Some(0..3), None[Slice[int]]()])
|
||||
check(ex1.captures.asSeq("") == @["foo", ""])
|
||||
check(ex1.captures.toSeq == @["foo", nil])
|
||||
check(ex1.captureBounds.toSeq == @[Some(0..3), None[Slice[int]]()])
|
||||
check(ex1.captures.toSeq("") == @["foo", ""])
|
||||
|
||||
let ex2 = "foobar".match(initRegex("(?<foo>foo)(?<bar>bar)?"))
|
||||
check(ex2.captures.asSeq == @["foo", "bar"])
|
||||
check(ex2.captures.toSeq == @["foo", "bar"])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user