diff options
Diffstat (limited to 'lib/impure/nre.nim')
-rw-r--r-- | lib/impure/nre.nim | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/impure/nre.nim b/lib/impure/nre.nim index 973f1f2ee..b739e9eff 100644 --- a/lib/impure/nre.nim +++ b/lib/impure/nre.nim @@ -1,6 +1,6 @@ # # Nim's Runtime Library -# (c) Copyright 2015 Nim Contributers +# (c) Copyright 2015 Nim Contributors # # See the file "copying.txt", included in this # distribution, for details about the copyright. @@ -10,12 +10,13 @@ from pcre import nil import nre.private.util import tables -import unsigned from strutils import toLower, `%` from math import ceil import options from unicode import runeLenAt +export options + ## What is NRE? ## ============ @@ -509,7 +510,7 @@ iterator findIter*(str: string, pattern: Regex, start = 0, endpos = int.high): R ## Variants: ## ## - ``proc findAll(...)`` returns a ``seq[string]`` - # see pcredemo for explaination + # see pcredemo for explanation let matchesCrLf = pattern.matchesCrLf() let unicode = uint32(getinfo[culong](pattern, pcre.INFO_OPTIONS) and pcre.UTF8) > 0u32 @@ -567,6 +568,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: |