diff options
author | dyu <david.yu.ftw@gmail.com> | 2014-12-19 20:08:42 +0800 |
---|---|---|
committer | dyu <david.yu.ftw@gmail.com> | 2014-12-19 20:08:42 +0800 |
commit | 12f97a7151920d3813f9d08ef7286e72bcd88aef (patch) | |
tree | b1c4d2bfab52d76f2dec75eab5d3f47eb0b794e3 /lib | |
parent | bce10ac1d3cb94d8ebb4482057752ee938a56c18 (diff) | |
download | Nim-12f97a7151920d3813f9d08ef7286e72bcd88aef.tar.gz |
strutils.rfind via char
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pure/strutils.nim | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/pure/strutils.nim b/lib/pure/strutils.nim index 55a204b4c..4f449cb0e 100644 --- a/lib/pure/strutils.nim +++ b/lib/pure/strutils.nim @@ -803,6 +803,16 @@ proc rfind*(s, sub: string, start: int = -1): int {.noSideEffect.} = if result != -1: return return -1 +proc rfind*(s: string, sub: char, start: int = -1): int {.noSideEffect, + rtl.} = + ## Searches for `sub` in `s` in reverse starting at position `start`. + ## + ## Searching is case-sensitive. If `sub` is not in `s`, -1 is returned. + let realStart = if start == -1: s.len-1 else: start + for i in countdown(realStart, 0): + if sub == s[i]: return i + return -1 + proc count*(s: string, sub: string, overlapping: bool = false): int {.noSideEffect, rtl, extern: "nsuCountString".} = ## Count the occurences of a substring `sub` in the string `s`. |