From 0b44d28a3143c7f6925a5d3956d9e982974a46de Mon Sep 17 00:00:00 2001 From: brain Date: Fri, 23 Jan 2009 13:40:24 +0000 Subject: Templateise this git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@10991 e03df62e-2008-0410-955e-edbf42e46eb7 --- include/hashcomp.h | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'include/hashcomp.h') diff --git a/include/hashcomp.h b/include/hashcomp.h index b5db9e329..e650cbbe1 100644 --- a/include/hashcomp.h +++ b/include/hashcomp.h @@ -103,7 +103,28 @@ unsigned const char rfc_case_sensitive_map[256] = { #endif -CoreExport const std::string& SearchAndReplace(std::string& text, const std::string& pattern, const std::string& replace); +template const T& SearchAndReplace(T& text, const T& pattern, const T& replace) +{ + T replacement; + if ((!pattern.empty()) && (!text.empty())) + { + for (std::string::size_type n = 0; n != text.length(); ++n) + { + if (text.length() >= pattern.length() && text.substr(n, pattern.length()) == pattern) + { + /* Found the pattern in the text, replace it, and advance */ + replacement.append(replace); + n = n + pattern.length() - 1; + } + else + { + replacement += text[n]; + } + } + } + text = replacement; + return text; +} /** The irc namespace contains a number of helper classes. */ -- cgit v1.2.3