X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=include%2Fhashcomp.h;h=94c836c6f0b39585836d0f3c4ea5ac5e4704a6a0;hb=c6b11d2130c640bc4a68522aa3b6d48c49fa5d7b;hp=25c2b0dc6d7b96eff3444fd67317628f01291d25;hpb=275f58a955407eda93c451273bee48e1637e3b4a;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/include/hashcomp.h b/include/hashcomp.h index 25c2b0dc6..94c836c6f 100644 --- a/include/hashcomp.h +++ b/include/hashcomp.h @@ -2,8 +2,8 @@ * | Inspire Internet Relay Chat Daemon | * +------------------------------------+ * - * InspIRCd: (C) 2002-2008 InspIRCd Development Team - * See: http://www.inspircd.org/wiki/index.php/Credits + * InspIRCd: (C) 2002-2009 InspIRCd Development Team + * See: http://wiki.inspircd.org/Credits * * This program is free but copyrighted software; see * the file COPYING for details. @@ -60,7 +60,7 @@ unsigned const char rfc_case_insensitive_map[256] = { * This is provided as a pointer so that modules can change it to their custom mapping tables, * e.g. for national character support. */ -extern unsigned const char *national_case_insensitive_map; +CoreExport extern unsigned const char *national_case_insensitive_map; /** Case insensitive map, ASCII rules. * That is; @@ -103,6 +103,29 @@ unsigned const char rfc_case_sensitive_map[256] = { #endif +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. */ namespace irc @@ -265,15 +288,15 @@ namespace irc * @param modeletter The mode letter to insert */ void Push(char modeletter); - + /** Push a '+' symbol onto the stack. */ void PushPlus(); - + /** Push a '-' symbol onto the stack. */ void PushMinus(); - + /** Return zero or more elements which form the * mode line. This will be clamped to a max of * MAXMODES items (MAXMODES-1 mode parameters and @@ -308,7 +331,7 @@ namespace irc class CoreExport tokenstream : public classbase { private: - + /** Original string */ std::string tokens; @@ -444,43 +467,43 @@ namespace irc /** Used to split on commas */ commasepstream* sep; - + /** Current position in a range of ports */ long in_range; - + /** Starting port in a range of ports */ long range_begin; - + /** Ending port in a range of ports */ long range_end; - + /** Allow overlapped port ranges */ bool overlapped; - + /** Used to determine overlapping of ports * without O(n) algorithm being used */ std::map overlap_set; - + /** Returns true if val overlaps an existing range */ bool Overlaps(long val); public: - + /** Create a portparser and fill it with the provided data * @param source The source text to parse from * @param allow_overlapped Allow overlapped ranges */ portparser(const std::string &source, bool allow_overlapped = true); - + /** Frees the internal commasepstream object */ ~portparser(); - + /** Fetch the next token from the stream * @return The next port number is returned, or 0 if none remain */ @@ -680,4 +703,3 @@ BEGIN_HASHMAP_NAMESPACE END_HASHMAP_NAMESPACE #endif -