summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2016-05-15 11:01:22 +0200
committerAndreas Rumpf <rumpf_a@web.de>2016-05-15 11:01:22 +0200
commitc770715b167c2bd1d57b3e2e28407c5a526bc4c0 (patch)
treeb679f70e2655ea04ed2cb78eeef2cd12c1679468
parent28a45f7ac91a397b73454c1941e06cd827583013 (diff)
parent4f9b498103e27d7f627c86938bd70f81b784aeff (diff)
downloadNim-c770715b167c2bd1d57b3e2e28407c5a526bc4c0.tar.gz
Merge pull request #4161 from moigagoo/devel
Stdlib: nre: Convenience proc ``contains`` added.
-rw-r--r--lib/impure/nre.nim10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/impure/nre.nim b/lib/impure/nre.nim
index c8f690461..381b1c3fc 100644
--- a/lib/impure/nre.nim
+++ b/lib/impure/nre.nim
@@ -566,6 +566,16 @@ proc findAll*(str: string, pattern: Regex, start = 0, endpos = int.high): seq[st
   for match in str.findIter(pattern, start, endpos):
     result.add(match.match)
 
+proc contains*(str: string, pattern: Regex, start = 0, endpos = int.high): bool =
+  ## Determine if the string contains the given pattern between the end and
+  ## start positions:
+  ## -  "abc".contains(re"bc") == true
+  ## -  "abc".contains(re"cd") == false
+  ## -  "abc".contains(re"a", start = 1) == false
+  ##
+  ## Same as ``isSome(str.find(pattern, start, endpos))``.
+  return isSome(str.find(pattern, start, endpos))
+
 proc split*(str: string, pattern: Regex, maxSplit = -1, start = 0): seq[string] =
   ## Splits the string with the given regex. This works according to the
   ## rules that Perl and Javascript use: