summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2014-12-19 14:12:55 +0100
committerAndreas Rumpf <rumpf_a@web.de>2014-12-19 14:12:55 +0100
commit7d80a26b3fad2859208b3fd53f5fef61048d62c9 (patch)
treea82dd6b756e0eea4f56ccd4ef6f9a1e092cacff9 /lib
parent00a702baeb4ad5e55811ec7b0fbecafa69ef412a (diff)
parent12f97a7151920d3813f9d08ef7286e72bcd88aef (diff)
downloadNim-7d80a26b3fad2859208b3fd53f5fef61048d62c9.tar.gz
Merge pull request #1751 from dyu/rfind-char
strutils.rfind via char
Diffstat (limited to 'lib')
-rw-r--r--lib/pure/strutils.nim10
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`.