Skip to content

Commit

Permalink
Proposed solution for issue #8919 (#9280)
Browse files Browse the repository at this point in the history
* Proposed solution for issue #8919

* count sub/subs must be non-empty
  • Loading branch information
eqperes authored and Araq committed Oct 12, 2018
1 parent 97738a4 commit 14925ee
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/pure/strutils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1471,6 +1471,7 @@ proc count*(s: string, sub: string, overlapping: bool = false): int {.
## Count the occurrences of a substring `sub` in the string `s`.
## Overlapping occurrences of `sub` only count when `overlapping`
## is set to true.
doAssert sub.len > 0
var i = 0
while true:
i = s.find(sub, i)
Expand All @@ -1488,6 +1489,7 @@ proc count*(s: string, sub: char): int {.noSideEffect,
proc count*(s: string, subs: set[char]): int {.noSideEffect,
rtl, extern: "nsuCountCharSet".} =
## Count the occurrences of the group of character `subs` in the string `s`.
doAssert card(subs) > 0
for c in s:
if c in subs: inc result

Expand Down

0 comments on commit 14925ee

Please sign in to comment.