From a5693675fb36588b12033d3768d41b4c63d31c4b Mon Sep 17 00:00:00 2001 From: Flaviu Tamas Date: Mon, 19 Jan 2015 15:22:02 -0500 Subject: [PATCH] Remove findAll, rename findAllStr to findAll --- README.asciidoc | 3 +-- src/nre.nim | 5 +---- test/find.nim | 15 +++++++-------- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/README.asciidoc b/README.asciidoc index b7f0ba66f7..841943fae7 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -50,8 +50,7 @@ Arguments are the same as link:#proc-find[`find(...)`] Variants: - - `proc findAll(...)` returns a `seq[RegexMatch]` - - `proc findAllStr(...)` returns a `seq[string]` + - `proc findAll(...)` returns a `seq[string]` [[proc-split]] ==== split(string, Regex, maxsplit = -1): seq[string] diff --git a/src/nre.nim b/src/nre.nim index ffa4a6a6ec..6c5a1ab358 100644 --- a/src/nre.nim +++ b/src/nre.nim @@ -372,10 +372,7 @@ proc find*(str: string, pattern: Regex, start = 0, endpos = -1): RegexMatch = ## if `endpos == -1`, then `endpos = str.len` return str.matchImpl(pattern, start, endpos, 0) -proc findAll*(str: string, pattern: Regex, start = 0, endpos = -1): seq[RegexMatch] = - accumulateResult(str.findIter(pattern, start, endpos)) - -proc findAllStr*(str: string, pattern: Regex, start = 0, endpos = -1): seq[string] = +proc findAll*(str: string, pattern: Regex, start = 0, endpos = -1): seq[string] = result = @[] for match in str.findIter(pattern, start, endpos): result.add(match.match) diff --git a/test/find.nim b/test/find.nim index ddbfcdfdb4..d8df958f9c 100644 --- a/test/find.nim +++ b/test/find.nim @@ -1,22 +1,21 @@ -import unittest -include nre +import unittest, sequtils, nre suite "find": test "find text": check("3213a".find(re"[a-z]").match == "a") - check("1 2 3 4 5 6 7 8 ".findAll(re" ").map( + check(toSeq(findIter("1 2 3 4 5 6 7 8 ", re" ")).map( proc (a: RegexMatch): string = a.match ) == @[" ", " ", " ", " ", " ", " ", " ", " "]) test "find bounds": - check("1 2 3 4 5 ".findAll(re" ").map( + check(toSeq(findIter("1 2 3 4 5 ", re" ")).map( proc (a: RegexMatch): Slice[int] = a.matchBounds ) == @[1..2, 3..4, 5..6, 7..8, 9..10]) test "overlapping find": - check("222".findAllStr(re"22") == @["22"]) - check("2222".findAllStr(re"22") == @["22", "22"]) + check("222".findAll(re"22") == @["22"]) + check("2222".findAll(re"22") == @["22", "22"]) test "len 0 find": - check("".findAllStr(re"\ ") == newSeq[string]()) - check("".findAllStr(re"") == @[""]) + check("".findAll(re"\ ") == newSeq[string]()) + check("".findAll(re"") == @[""])