* Proposed solution for issue #8919 * count sub/subs must be non-empty
This commit is contained in:
parent
97738a4f28
commit
14925ee8b6
1 changed files with 2 additions and 0 deletions
|
|
@ -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`.
|
## Count the occurrences of a substring `sub` in the string `s`.
|
||||||
## Overlapping occurrences of `sub` only count when `overlapping`
|
## Overlapping occurrences of `sub` only count when `overlapping`
|
||||||
## is set to true.
|
## is set to true.
|
||||||
|
doAssert sub.len > 0
|
||||||
var i = 0
|
var i = 0
|
||||||
while true:
|
while true:
|
||||||
i = s.find(sub, i)
|
i = s.find(sub, i)
|
||||||
|
|
@ -1488,6 +1489,7 @@ proc count*(s: string, sub: char): int {.noSideEffect,
|
||||||
proc count*(s: string, subs: set[char]): int {.noSideEffect,
|
proc count*(s: string, subs: set[char]): int {.noSideEffect,
|
||||||
rtl, extern: "nsuCountCharSet".} =
|
rtl, extern: "nsuCountCharSet".} =
|
||||||
## Count the occurrences of the group of character `subs` in the string `s`.
|
## Count the occurrences of the group of character `subs` in the string `s`.
|
||||||
|
doAssert card(subs) > 0
|
||||||
for c in s:
|
for c in s:
|
||||||
if c in subs: inc result
|
if c in subs: inc result
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue