From a3fb932831ca09b2a931616f1701ea39429356c2 Mon Sep 17 00:00:00 2001 From: brain Date: Fri, 23 Jan 2009 13:20:57 +0000 Subject: Fix m_nationalchars using a copy and paste of my unsafe copy and paste algorithm, that will lock up if the string to replace contains the string to search for. Finally make this function a core utility function and remove the copies from 3 modules m_alias m_nationalchars and m_sqlauth git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@10990 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/hashcomp.cpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'src/hashcomp.cpp') diff --git a/src/hashcomp.cpp b/src/hashcomp.cpp index 52a6210f9..0d036d528 100644 --- a/src/hashcomp.cpp +++ b/src/hashcomp.cpp @@ -6,7 +6,7 @@ * See: http://www.inspircd.org/wiki/index.php/Credits * * This program is free but copyrighted software; see - * the file COPYING for details. + * the file COPYING for details. * * --------------------------------------------------- */ @@ -501,3 +501,26 @@ long irc::portparser::GetToken() } } +const std::string& SearchAndReplace(std::string& text, const std::string& pattern, const std::string& replace) +{ + std::string 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; +} + -- cgit v1.3.1-10-gc9f91