From 7296c6d649ada6838b3c0e93fa87721c882eab2c Mon Sep 17 00:00:00 2001 From: Flaviu Tamas Date: Tue, 3 Mar 2015 18:42:38 -0500 Subject: [PATCH] Add equality operator for RegexMatch and Regex - Technically a breaking change, but I doubt anyone depends on a compile-time error for long ;) --- nre.nimble | 2 +- src/nre.nim | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/nre.nimble b/nre.nimble index 232c46493c..b007ff617a 100644 --- a/nre.nimble +++ b/nre.nimble @@ -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" diff --git a/src/nre.nim b/src/nre.nim index b9922ad0f5..421b6a2828 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 {{{