]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/hashcomp.cpp
Merge pull request #984 from Renegade334/modules-exempt-uline
[user/henk/code/inspircd.git] / src / hashcomp.cpp
index 06b3ce66970e8bfba9e5e99e7227f5702b90d18c..42e25f8f6a6248bfb0efc19294857cd409d34e19 100644 (file)
  */
 
 
-/* $Core */
-
 #include "inspircd.h"
-#include "hashcomp.h"
 
 /******************************************************
  *
@@ -172,6 +169,25 @@ bool irc::StrHashComp::operator()(const std::string& s1, const std::string& s2)
        return (national_case_insensitive_map[*n1] == national_case_insensitive_map[*n2]);
 }
 
+bool irc::insensitive_swo::operator()(const std::string& a, const std::string& b) const
+{
+       const unsigned char* charmap = national_case_insensitive_map;
+       std::string::size_type asize = a.size();
+       std::string::size_type bsize = b.size();
+       std::string::size_type maxsize = std::min(asize, bsize);
+
+       for (std::string::size_type i = 0; i < maxsize; i++)
+       {
+               unsigned char A = charmap[(unsigned char)a[i]];
+               unsigned char B = charmap[(unsigned char)b[i]];
+               if (A > B)
+                       return false;
+               else if (A < B)
+                       return true;
+       }
+       return (asize < bsize);
+}
+
 size_t irc::insensitive::operator()(const std::string &s) const
 {
        /* XXX: NO DATA COPIES! :)
@@ -252,7 +268,7 @@ bool irc::tokenstream::GetToken(std::string &token)
        /* This is the last parameter */
        if (token[0] == ':' && !first)
        {
-               token = token.substr(1);
+               token.erase(token.begin());
                if (!StreamEnd())
                {
                        token += ' ';
@@ -316,7 +332,7 @@ bool irc::sepstream::GetToken(std::string &token)
        if (p == std::string::npos)
                p = this->tokens.length();
 
-       token = this->tokens.substr(this->pos, p - this->pos);
+       token.assign(tokens, this->pos, p - this->pos);
        this->pos = p + 1;
 
        return true;
@@ -332,79 +348,16 @@ bool irc::sepstream::StreamEnd()
        return this->pos > this->tokens.length();
 }
 
-irc::modestacker::modestacker(bool add) : adding(add)
-{
-       sequence.clear();
-       sequence.push_back("");
-}
-
-void irc::modestacker::Push(char modeletter, const std::string &parameter)
-{
-       *(sequence.begin()) += modeletter;
-       sequence.push_back(parameter);
-}
-
-void irc::modestacker::Push(char modeletter)
-{
-       this->Push(modeletter,"");
-}
-
-void irc::modestacker::PushPlus()
-{
-       this->Push('+',"");
-}
-
-void irc::modestacker::PushMinus()
-{
-       this->Push('-',"");
-}
-
-int irc::modestacker::GetStackedLine(std::vector<std::string> &result, int max_line_size)
+std::string irc::stringjoiner(const std::vector<std::string>& sequence, char separator)
 {
+       std::string joined;
        if (sequence.empty())
-       {
-               return 0;
-       }
-
-       unsigned int n = 0;
-       int size = 1; /* Account for initial +/- char */
-       int nextsize = 0;
-       int start = result.size();
-       std::string modeline = adding ? "+" : "-";
-       result.push_back(modeline);
-
-       if (sequence.size() > 1)
-               nextsize = sequence[1].length() + 2;
-
-       while (!sequence[0].empty() && (sequence.size() > 1) && (n < ServerInstance->Config->Limits.MaxModes) && ((size + nextsize) < max_line_size))
-       {
-               modeline += *(sequence[0].begin());
-               if (!sequence[1].empty())
-               {
-                       result.push_back(sequence[1]);
-                       size += nextsize; /* Account for mode character and whitespace */
-               }
-               sequence[0].erase(sequence[0].begin());
-               sequence.erase(sequence.begin() + 1);
-
-               if (sequence.size() > 1)
-                       nextsize = sequence[1].length() + 2;
-
-               n++;
-       }
-       result[start] = modeline;
-
-       return n;
-}
-
-irc::stringjoiner::stringjoiner(const std::string& separator, const std::vector<std::string>& sequence, unsigned int begin, unsigned int end)
-{
-       if (end < begin)
-               return; // nothing to do here
+               return joined; // nothing to do here
 
-       for (unsigned int v = begin; v < end; v++)
-               joined.append(sequence[v]).append(separator);
-       joined.append(sequence[end]);
+       for (std::vector<std::string>::const_iterator i = sequence.begin(); i != sequence.end(); ++i)
+               joined.append(*i).push_back(separator);
+       joined.erase(joined.end()-1);
+       return joined;
 }
 
 irc::portparser::portparser(const std::string &source, bool allow_overlapped)
@@ -459,10 +412,9 @@ long irc::portparser::GetToken()
        std::string::size_type dash = x.rfind('-');
        if (dash != std::string::npos)
        {
-               std::string sbegin = x.substr(0, dash);
-               std::string send = x.substr(dash+1, x.length());
+               std::string sbegin(x, 0, dash);
                range_begin = atoi(sbegin.c_str());
-               range_end = atoi(send.c_str());
+               range_end = atoi(x.c_str()+dash+1);
 
                if ((range_begin > 0) && (range_end > 0) && (range_begin < 65536) && (range_end < 65536) && (range_begin < range_end))
                {