diff options
author | eqperes <eqperes@gmail.com> | 2018-10-12 17:28:21 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2018-10-12 17:28:21 +0200 |
commit | 14925ee8b6c33ae1477c729b52195d38e4d68b32 (patch) | |
tree | f09381653e379e266a4d096c8e9966e521546c85 | |
parent | 97738a4f2842c88b7b63a579565cd860a7b28c4e (diff) | |
download | Nim-14925ee8b6c33ae1477c729b52195d38e4d68b32.tar.gz |
Proposed solution for issue #8919 (#9280)
* Proposed solution for issue #8919 * count sub/subs must be non-empty
-rw-r--r-- | lib/pure/strutils.nim | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/lib/pure/strutils.nim b/lib/pure/strutils.nim index c9a577b13..0e192aec0 100644 --- a/lib/pure/strutils.nim +++ b/lib/pure/strutils.nim @@ -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) @@ -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 |