diff options
author | Flaviu Tamas <tamasflaviu@gmail.com> | 2018-11-18 20:25:59 -0500 |
---|---|---|
committer | Flaviu Tamas <tamasflaviu@gmail.com> | 2018-12-11 22:15:02 +0000 |
commit | 22b3e9df27fc65ec49b8ba8ea8de492917988e3d (patch) | |
tree | 96e6a2ccb032be0945687f3927dd5eb98380f54a /lib/impure | |
parent | c682671feae3ae6c90416152f84b274cb5aa4a21 (diff) | |
download | Nim-22b3e9df27fc65ec49b8ba8ea8de492917988e3d.tar.gz |
Revert 7f49364fd0 for nre
Diffstat (limited to 'lib/impure')
-rw-r--r-- | lib/impure/nre.nim | 12 | ||||
-rw-r--r-- | lib/impure/nre/private/util.nim | 6 |
2 files changed, 11 insertions, 7 deletions
diff --git a/lib/impure/nre.nim b/lib/impure/nre.nim index 58594f054..4ceab2cca 100644 --- a/lib/impure/nre.nim +++ b/lib/impure/nre.nim @@ -289,7 +289,7 @@ proc `[]`*(pattern: Captures, i: int): string = let bounds = bounds.get return pattern.str.substr(bounds.a, bounds.b) else: - return "" + return nil proc match*(pattern: RegexMatch): string = return pattern.captures[-1] @@ -313,9 +313,9 @@ template toTableImpl(cond: untyped) {.dirty.} = else: result[key] = nextVal -proc toTable*(pattern: Captures, default: string = ""): Table[string, string] = +proc toTable*(pattern: Captures, default: string = nil): Table[string, string] = result = initTable[string, string]() - toTableImpl(nextVal.len == 0) + toTableImpl(nextVal == nil) proc toTable*(pattern: CaptureBounds, default = none(HSlice[int, int])): Table[string, Option[HSlice[int, int]]] = @@ -334,13 +334,13 @@ template itemsImpl(cond: untyped) {.dirty.} = iterator items*(pattern: CaptureBounds, default = none(HSlice[int, int])): Option[HSlice[int, int]] = itemsImpl(nextVal.isNone) -iterator items*(pattern: Captures, default: string = ""): string = - itemsImpl(nextVal.len == 0) +iterator items*(pattern: Captures, default: string = nil): string = + itemsImpl(nextVal == nil) proc toSeq*(pattern: CaptureBounds, default = none(HSlice[int, int])): seq[Option[HSlice[int, int]]] = accumulateResult(pattern.items(default)) -proc toSeq*(pattern: Captures, default: string = ""): seq[string] = +proc toSeq*(pattern: Captures, default: string = nil): seq[string] = accumulateResult(pattern.items(default)) proc `$`*(pattern: RegexMatch): string = diff --git a/lib/impure/nre/private/util.nim b/lib/impure/nre/private/util.nim index a3ae84007..12d2506ea 100644 --- a/lib/impure/nre/private/util.nim +++ b/lib/impure/nre/private/util.nim @@ -10,7 +10,11 @@ proc fget*[K, V](self: Table[K, V], key: K): V = const Ident = {'a'..'z', 'A'..'Z', '0'..'9', '_', '\128'..'\255'} const StartIdent = Ident - {'0'..'9'} -template checkNil(arg: string): string = arg +proc checkNil(arg: string): string = + if arg == nil: + raise newException(ValueError, "Cannot use nil capture") + else: + return arg template formatStr*(howExpr, namegetter, idgetter): untyped = let how = howExpr |