Add equality operator for RegexMatch and Regex
- Technically a breaking change, but I doubt anyone depends on a compile-time error for long ;)
This commit is contained in:
parent
cba3b788f1
commit
7296c6d649
2 changed files with 13 additions and 1 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
[Package]
|
[Package]
|
||||||
name = "nre"
|
name = "nre"
|
||||||
author = "Flaviu Tamas"
|
author = "Flaviu Tamas"
|
||||||
version = "0.6.0"
|
version = "0.6.1"
|
||||||
description = "Yet another PCRE library"
|
description = "Yet another PCRE library"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
srcDir = "src"
|
srcDir = "src"
|
||||||
|
|
|
||||||
12
src/nre.nim
12
src/nre.nim
|
|
@ -172,6 +172,18 @@ proc toSeq*(pattern: Captures, default: string = nil): seq[string] =
|
||||||
|
|
||||||
proc `$`*(pattern: RegexMatch): string =
|
proc `$`*(pattern: RegexMatch): string =
|
||||||
return pattern.captures[-1]
|
return pattern.captures[-1]
|
||||||
|
|
||||||
|
proc `==`*(a, b: Regex): bool =
|
||||||
|
# name-to-number table is generated at init time, doesn't need to be checked
|
||||||
|
return a.pattern == b.pattern and
|
||||||
|
a.pcreObj == b.pcreObj and
|
||||||
|
a.pcreExtra == b.pcreExtra
|
||||||
|
|
||||||
|
proc `==`*(a, b: RegexMatch): bool =
|
||||||
|
# don't need to compare matchbounds, if pattern and str equal, everything
|
||||||
|
# else will equal (unless callbacks, maybe? TODO)
|
||||||
|
return a.pattern == b.pattern and
|
||||||
|
a.str == b.str
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
# Creation & Destruction {{{
|
# Creation & Destruction {{{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue