@@ -153,15 +153,12 @@ import algorithm
153153import strutils
154154import sets
155155import tables
156- import options
157156import parseutils
158157
159158import unicodedb/ properties
160159import unicodedb/ types
161160import unicodeplus except isUpper, isLower
162161
163- export Option , isSome, get
164-
165162type
166163 RegexError * = object of ValueError
167164 # # raised when the pattern
@@ -2043,7 +2040,8 @@ iterator group*(m: RegexMatch, i: int): Slice[int] =
20432040 # # let
20442041 # # expected = ["a", "b", "c"]
20452042 # # text = "abc"
2046- # # m = text.match(re"(\w)+").get()
2043+ # # var m: RegexMatch
2044+ # # doAssert text.match(re"(\w)+", m)
20472045 # # var i = 0
20482046 # # for bounds in m.group(0):
20492047 # # doAssert(expected[i] == text[bounds])
@@ -2064,7 +2062,8 @@ iterator group*(m: RegexMatch, s: string): Slice[int] =
20642062 # # let
20652063 # # expected = ["a", "b", "c"]
20662064 # # text = "abc"
2067- # # m = text.match(re"(?P<foo>\w)+").get()
2065+ # # var m: RegexMatch
2066+ # # doAssert text.match(re"(?P<foo>\w)+", m)
20682067 # # var i = 0
20692068 # # for bounds in m.group("foo"):
20702069 # # doAssert(expected[i] == text[bounds])
@@ -2082,8 +2081,14 @@ proc groupsCount*(m: RegexMatch): int =
20822081 # # return the number of capturing groups
20832082 # #
20842083 # # .. code-block:: nim
2085- # # doAssert("ab".match(re"(a)(b)").get().groupsCount == 2)
2086- # # doAssert("ab".match(re"((ab))").get().groupsCount == 2)
2084+ # # block:
2085+ # # var m: RegexMatch
2086+ # # doAssert "ab".match(re"(a)(b)", m)
2087+ # # doAssert m.groupsCount == 2
2088+ # # block:
2089+ # # var m: RegexMatch
2090+ # # doAssert "ab".match(re"((ab))", m)
2091+ # # doAssert m.groupsCount == 2
20872092 # #
20882093 m.groups.len
20892094
@@ -2177,10 +2182,7 @@ proc populateCaptures(
21772182 # then calculate slices for each match
21782183 # (a group can have multiple matches).
21792184 # Note the given `capture` is in reverse order (leaf to root)
2180- if result .groups.len == 0 : # todo : remove in Nim 0.18.1
2181- result .groups = newSeq [Slice [int ]](gc)
2182- else :
2183- result .groups.setLen (gc)
2185+ result .groups.setLen (gc)
21842186 var
21852187 curr = cIdx
21862188 ci = 0
@@ -2198,10 +2200,7 @@ proc populateCaptures(
21982200 else :
21992201 g.b = - 1 # 0 .. -1
22002202 assert ci mod 2 == 0
2201- if result .captures.len == 0 : # todo : remove in Nim 0.18.1
2202- result .captures = newSeq [Slice [int ]](ci div 2 )
2203- else :
2204- result .captures.setLen (ci div 2 )
2203+ result .captures.setLen (ci div 2 )
22052204 curr = cIdx
22062205 while curr != 0 :
22072206 let
@@ -2406,15 +2405,6 @@ proc match*(
24062405 pattern.groupsCount > 0 )
24072406 result = matchImpl (ds, s, pattern, m, start)
24082407
2409- proc match * (
2410- s: string ,
2411- pattern: Regex ,
2412- start= 0 ): Option [RegexMatch ] {.deprecated .} =
2413- # # Deprecated, use ``match(string, Regex, var RegexMatch)`` instead
2414- var m = RegexMatch ()
2415- if match (s, pattern, m, start):
2416- result = some (m)
2417-
24182408proc contains * (s: string , pattern: Regex ): bool =
24192409 # # search for the pattern anywhere
24202410 # # in the string. It returns as soon
@@ -2514,15 +2504,6 @@ proc find*(
25142504 pattern.groupsCount > 0 )
25152505 result = findImpl (ds, s, pattern, m, start)
25162506
2517- proc find * (
2518- s: string ,
2519- pattern: Regex ,
2520- start = 0 ): Option [RegexMatch ] {.deprecated .} =
2521- # # Deprecated, use ``find(string, Regex, var RegexMatch)`` instead
2522- var m = RegexMatch ()
2523- if find (s, pattern, m, start):
2524- result = some (m)
2525-
25262507template runeIncAt (s: string , n: var int ) =
25272508 # # increment ``n`` up to
25282509 # # next rune's index
@@ -2558,9 +2539,12 @@ iterator findAll*(
25582539 # #
25592540 # # .. code-block:: nim
25602541 # # var i = 0
2561- # # let expected = [1 .. 2, 4 .. 5]
2562- # # for m in findAll("abcabc", re"bc"):
2563- # # doAssert(m.boundaries == expected[i])
2542+ # # let
2543+ # # expected = [1 .. 2, 4 .. 5]
2544+ # # text = "abcabc"
2545+ # # for m in findAll(text, re"bc"):
2546+ # # doAssert text[m.boundaries] == "bc"
2547+ # # doAssert m.boundaries == expected[i]
25642548 # # inc i
25652549 # #
25662550 for m in findAllImpl (s, pattern, start):
@@ -2570,14 +2554,6 @@ proc findAll*(s: string, pattern: Regex, start = 0): seq[RegexMatch] =
25702554 # # search through the string and
25712555 # # return each match. Empty matches
25722556 # # (start > end) are included
2573- # #
2574- # # .. code-block:: nim
2575- # # let
2576- # # expected = [1 .. 2, 4 .. 5]
2577- # # ms = findAll("abcabc", re"bc")
2578- # # for i, m in ms:
2579- # # doAssert(m.boundaries == expected[i])
2580- # #
25812557 result = newSeqOfCap [RegexMatch ](s.len)
25822558 for slc in findAll (s, pattern, start):
25832559 result .add (slc)
0 commit comments