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:
Flaviu Tamas
2015-03-03 18:42:38 -05:00
parent cba3b788f1
commit 7296c6d649
2 changed files with 13 additions and 1 deletions

View File

@@ -1,7 +1,7 @@
[Package]
name = "nre"
author = "Flaviu Tamas"
version = "0.6.0"
version = "0.6.1"
description = "Yet another PCRE library"
license = "MIT"
srcDir = "src"

View File

@@ -172,6 +172,18 @@ proc toSeq*(pattern: Captures, default: string = nil): seq[string] =
proc `$`*(pattern: RegexMatch): string =
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 {{{