Skip to content

Commit

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

* count sub/subs must be non-empty
  • Loading branch information
eqperes authored and krux02 committed Oct 15, 2018
1 parent 2f45c3d commit 124c48c
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/pure/strutils.nim
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 124c48c

Please sign in to comment.