diff options
-rw-r--r-- | include/hashcomp.h | 2 | ||||
-rw-r--r-- | src/hashcomp.cpp | 25 | ||||
-rw-r--r-- | src/helperfuncs.cpp | 3 | ||||
-rw-r--r-- | src/modules/extra/m_sqlauth.cpp | 12 | ||||
-rw-r--r-- | src/modules/m_alias.cpp | 11 | ||||
-rwxr-xr-x | src/modules/m_nationalchars.cpp | 14 |
6 files changed, 30 insertions, 37 deletions
diff --git a/include/hashcomp.h b/include/hashcomp.h index 1c81c689d..b5db9e329 100644 --- a/include/hashcomp.h +++ b/include/hashcomp.h @@ -103,6 +103,8 @@ 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); + /** The irc namespace contains a number of helper classes. */ namespace irc 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; +} + diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp index 10659ae5f..f38b3e6b5 100644 --- a/src/helperfuncs.cpp +++ b/src/helperfuncs.cpp @@ -452,3 +452,6 @@ void InspIRCd::AddExtBanChar(char c) else tok.insert(ebpos + 9, 1, c); } + + + diff --git a/src/modules/extra/m_sqlauth.cpp b/src/modules/extra/m_sqlauth.cpp index 0cd1ced24..f03ec08db 100644 --- a/src/modules/extra/m_sqlauth.cpp +++ b/src/modules/extra/m_sqlauth.cpp @@ -85,18 +85,6 @@ public: return 0; } - void SearchAndReplace(std::string& newline, const std::string &find, const std::string &replace) - { - std::string::size_type x = newline.find(find); - while (x != std::string::npos) - { - newline.erase(x, find.length()); - if (!replace.empty()) - newline.insert(x, replace); - x = newline.find(find); - } - } - bool CheckCredentials(User* user) { std::string thisquery = freeformquery; diff --git a/src/modules/m_alias.cpp b/src/modules/m_alias.cpp index c914aad66..76aceffc9 100644 --- a/src/modules/m_alias.cpp +++ b/src/modules/m_alias.cpp @@ -132,17 +132,6 @@ class ModuleAlias : public Module return word; } - void SearchAndReplace(std::string& newline, const std::string &find, const std::string &replace) - { - std::string::size_type x = newline.find(find); - while (x != std::string::npos) - { - newline.erase(x, find.length()); - newline.insert(x, replace); - x = newline.find(find); - } - } - virtual int OnPreCommand(std::string &command, std::vector<std::string> ¶meters, User *user, bool validated, const std::string &original_line) { std::multimap<std::string, Alias>::iterator i, upperbound; diff --git a/src/modules/m_nationalchars.cpp b/src/modules/m_nationalchars.cpp index cd88a02b0..6d6822d74 100755 --- a/src/modules/m_nationalchars.cpp +++ b/src/modules/m_nationalchars.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. * * --------------------------------------------------- */ @@ -26,18 +26,6 @@ DEFINE_HANDLER2(lwbNickHandler, bool, const char*, size_t); /*,m_reverse_additionalUp[256];*/ static unsigned char m_reverse_additional[256],m_additionalMB[256],m_additionalUtf8[256],m_additionalUtf8range[256]; -void SearchAndReplace(std::string& newline, const std::string &find, const std::string &replace) -{ - std::string::size_type x = newline.find(find); - while (x != std::string::npos) - { - newline.erase(x, find.length()); - newline.insert(x, replace); - x = newline.find(find); - } -} - - char utf8checkrest(unsigned char * mb, unsigned char cnt) { for (unsigned char * tmp=mb; tmp<mb+cnt; tmp++) |