From bbb371c8d7b7fb18b911a2291856287ee8b40637 Mon Sep 17 00:00:00 2001 From: Scott Ehlert Date: Thu, 3 May 2007 02:22:03 +0000 Subject: [PATCH] Added find_last_of() to SourceHook::String for searching the string backwards --HG-- extra : convert_revision : svn%3Ac2935e3e-5518-0410-8daf-afa5dab7d4e3/trunk%40383 --- sourcehook/sh_string.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/sourcehook/sh_string.h b/sourcehook/sh_string.h index 28f2f4b..220b4ee 100755 --- a/sourcehook/sh_string.h +++ b/sourcehook/sh_string.h @@ -153,6 +153,30 @@ public: return npos; } + int find_last_of(const char c, int index = npos) const + { + int len = static_cast(size()); + if (len < 1) + return npos; + if (index >= len || index < npos) + return npos; + int i; + if (index == npos) + i = len - 1; + else + i = index; + + for (; i>=0; i--) + { + if (v[i] == c) + { + return i; + } + } + + return npos; + } + bool is_space(int c) const { if (c == '\f' || c == '\n' ||