summary refs log tree commit diff stats
path: root/src/nre.nim
diff options
context:
space:
mode:
authorFlaviu Tamas <tamasflaviu@gmail.com>2015-03-03 18:42:38 -0500
committerFlaviu Tamas <tamasflaviu@gmail.com>2015-03-03 18:48:35 -0500
commit7296c6d649ada6838b3c0e93fa87721c882eab2c (patch)
tree2ffd8e9d8fab000ae4a7ccdc3faf9feb21e0c52d /src/nre.nim
parentcba3b788f19deb6310d0e063f1e081dcf4b68299 (diff)
downloadNim-7296c6d649ada6838b3c0e93fa87721c882eab2c.tar.gz
Add equality operator for RegexMatch and Regex
- Technically a breaking change, but I doubt anyone depends on a compile-time
  error for long ;)
Diffstat (limited to 'src/nre.nim')
-rw-r--r--src/nre.nim12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/nre.nim b/src/nre.nim
index b9922ad0f..421b6a282 100644
--- a/src/nre.nim
+++ b/src/nre.nim
@@ -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 {{{