]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/hashcomp.cpp
Switch <stdint.h> test to use a test file too.
[user/henk/code/inspircd.git] / src / hashcomp.cpp
index c7acbb6bea57fe5bc9648300439f1de55185d3c8..e0347421b29d01fb89e7cedd13d89aacde04fb74 100644 (file)
@@ -1,16 +1,25 @@
-/*       +------------------------------------+
- *       | Inspire Internet Relay Chat Daemon |
- *       +------------------------------------+
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
  *
- *  InspIRCd: (C) 2002-2010 InspIRCd Development Team
- * See: http://wiki.inspircd.org/Credits
+ *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
+ *   Copyright (C) 2005-2009 Craig Edwards <craigedwards@brainbox.cc>
+ *   Copyright (C) 2007-2008 Robin Burchell <robin+git@viroteck.net>
+ *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
  *
- * This program is free but copyrighted software; see
- *         the file COPYING for details.
+ * This file is part of InspIRCd.  InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
  *
- * ---------------------------------------------------
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+
 /* $Core */
 
 #include "inspircd.h"
@@ -118,15 +127,12 @@ void nspace::strlower(char *n)
        }
 }
 
-#if defined(WINDOWS) && !defined(HASHMAP_DEPRECATED)
-       size_t nspace::hash_compare<std::string, std::less<std::string> >::operator()(const std::string &s) const
+#ifdef HASHMAP_DEPRECATED
+       size_t CoreExport nspace::insensitive::operator()(const std::string &s) const
 #else
-       #ifdef HASHMAP_DEPRECATED
-               size_t CoreExport nspace::insensitive::operator()(const std::string &s) const
-       #else
-               size_t nspace::hash<std::string>::operator()(const std::string &s) const
-       #endif
+       size_t nspace::hash<std::string>::operator()(const std::string &s) const
 #endif
+
 {
        /* XXX: NO DATA COPIES! :)
         * The hash function here is practically
@@ -134,20 +140,16 @@ void nspace::strlower(char *n)
         * only with *x replaced with national_case_insensitive_map[*x].
         * This avoids a copy to use hash<const char*>
         */
-       register size_t t = 0;
+       size_t t = 0;
        for (std::string::const_iterator x = s.begin(); x != s.end(); ++x) /* ++x not x++, as its faster */
                t = 5 * t + national_case_insensitive_map[(unsigned char)*x];
        return t;
 }
 
 
-#if defined(WINDOWS) && !defined(HASHMAP_DEPRECATED)
-       size_t nspace::hash_compare<irc::string, std::less<irc::string> >::operator()(const irc::string &s) const
-#else
-       size_t CoreExport nspace::hash<irc::string>::operator()(const irc::string &s) const
-#endif
+size_t CoreExport irc::hash::operator()(const irc::string &s) const
 {
-       register size_t t = 0;
+       size_t t = 0;
        for (irc::string::const_iterator x = s.begin(); x != s.end(); ++x) /* ++x not x++, as its faster */
                t = 5 * t + national_case_insensitive_map[(unsigned char)*x];
        return t;
@@ -255,7 +257,7 @@ bool irc::tokenstream::GetToken(std::string &token)
                        /* If we find a space, or end of string, this is the end of a token.
                         */
                        last_starting_position = n+1;
-                       last_pushed = true;
+                       last_pushed = *n == ' ';
 
                        std::string strip(lsp, n+1 == tokens.end() ? n+1  : n++);
                        while ((strip.length()) && (strip.find_last_of(' ') == strip.length() - 1))
@@ -324,7 +326,7 @@ bool irc::sepstream::GetToken(std::string &token)
                n++;
        }
 
-       token = "";
+       token.clear();
        return false;
 }
 
@@ -442,7 +444,7 @@ int irc::modestacker::GetStackedLine(std::vector<std::string> &result, int max_l
 irc::stringjoiner::stringjoiner(const std::string &seperator, const std::vector<std::string> &sequence, int begin, int end)
 {
        if (end < begin)
-               throw "stringjoiner logic error, this causes problems.";
+               return; // nothing to do here
 
        for (int v = begin; v < end; v++)
                joined.append(sequence[v]).append(seperator);
@@ -452,7 +454,7 @@ irc::stringjoiner::stringjoiner(const std::string &seperator, const std::vector<
 irc::stringjoiner::stringjoiner(const std::string &seperator, const std::deque<std::string> &sequence, int begin, int end)
 {
        if (end < begin)
-               throw "stringjoiner logic error, this causes problems.";
+               return; // nothing to do here
 
        for (int v = begin; v < end; v++)
                joined.append(sequence[v]).append(seperator);
@@ -462,7 +464,7 @@ irc::stringjoiner::stringjoiner(const std::string &seperator, const std::deque<s
 irc::stringjoiner::stringjoiner(const std::string &seperator, const char* const* sequence, int begin, int end)
 {
        if (end < begin)
-               throw "stringjoiner logic error, this causes problems.";
+               return; // nothing to do here
 
        for (int v = begin; v < end; v++)
                joined.append(sequence[v]).append(seperator);
@@ -474,29 +476,17 @@ std::string& irc::stringjoiner::GetJoined()
        return joined;
 }
 
-irc::portparser::portparser(const std::string &source, bool allow_overlapped) : in_range(0), range_begin(0), range_end(0), overlapped(allow_overlapped)
+irc::portparser::portparser(const std::string &source, bool allow_overlapped)
+       : sep(source), in_range(0), range_begin(0), range_end(0), overlapped(allow_overlapped)
 {
-       sep = new irc::commasepstream(source);
-       overlap_set.clear();
-}
-
-irc::portparser::~portparser()
-{
-       delete sep;
 }
 
 bool irc::portparser::Overlaps(long val)
 {
-       if (!overlapped)
+       if (overlapped)
                return false;
 
-       if (overlap_set.find(val) == overlap_set.end())
-       {
-               overlap_set[val] = true;
-               return false;
-       }
-       else
-               return true;
+       return (!overlap_set.insert(val).second);
 }
 
 long irc::portparser::GetToken()
@@ -524,14 +514,14 @@ long irc::portparser::GetToken()
        }
 
        std::string x;
-       sep->GetToken(x);
+       sep.GetToken(x);
 
        if (x.empty())
                return 0;
 
        while (Overlaps(atoi(x.c_str())))
        {
-               if (!sep->GetToken(x))
+               if (!sep.GetToken(x))
                        return 0;
        }