Skip to content

Commit

Permalink
feat: str.count
Browse files Browse the repository at this point in the history
  • Loading branch information
litlighilit committed May 6, 2024
1 parent a2cf5b7 commit aa4242d
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/pylib/pystring/strmeth.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ import ./strip
export strip
import ./errHandle

func count*(a: StringLike, sub: StringLike): int =
if sub.len == 0: return str(a).len + 1

func count*(a: StringLike, sub: StringLike, start: int): int =
let subA = substr($a, start)
if sub.len == 0: return str(subA).len + 1
count($a, sub)

func count*(a: StringLike, sub: StringLike, start=0, `end`: int): int =
count(substr($a, start, `end`-1), sub)

template casefold*(a: StringLike): string =
## Mimics Python str.casefold() -> str
unicode.toLower(a)
Expand Down

0 comments on commit aa4242d

Please sign in to comment.