]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/hashcomp.cpp
Dunno why this method was static, doesnt need to be...
[user/henk/code/inspircd.git] / src / hashcomp.cpp
index 1e6db3f6597404889459fd5c40b6b87204e6079b..3ab91531fa0b03dcbdf32e57a17c668e53bdd0b6 100644 (file)
 
 #include "inspircd.h"
 #include "hashcomp.h"
+#ifndef WIN32
 #include <ext/hash_map>
 #define nspace __gnu_cxx
+#else
+#include <hash_map>
+#define nspace stdext
+using stdext::hash_map;
+#endif
 
 /******************************************************
  *
@@ -61,7 +67,11 @@ void nspace::strlower(char *n)
        }
 }
 
+#ifndef WIN32
 size_t nspace::hash<string>::operator()(const string &s) const
+#else
+size_t nspace::hash_compare<string, std::less<string> >::operator()(const string &s) const
+#endif
 {
        /* XXX: NO DATA COPIES! :)
         * The hash function here is practically
@@ -75,7 +85,11 @@ size_t nspace::hash<string>::operator()(const string &s) const
        return t;
 }
 
+#ifndef WIN32
 size_t nspace::hash<irc::string>::operator()(const irc::string &s) const
+#else
+size_t nspace::hash_compare<irc::string, std::less<irc::string> >::operator()(const irc::string &s) const
+#endif
 {
        register size_t t = 0;
        for (irc::string::const_iterator x = s.begin(); x != s.end(); ++x) /* ++x not x++, as its faster */
@@ -124,40 +138,20 @@ int irc::irc_char_traits::compare(const char* str1, const char* str2, size_t n)
        for(unsigned int i = 0; i < n; i++)
        {
                if(lowermap[(unsigned char)*str1] > lowermap[(unsigned char)*str2])
-                               return 1;
+                       return 1;
 
                if(lowermap[(unsigned char)*str1] < lowermap[(unsigned char)*str2])
-                       return -1;
+                       return -1;
 
                if(*str1 == 0 || *str2 == 0)
-                       return 0;
+                       return 0;
 
-               str1++;
+               str1++;
                str2++;
        }
        return 0;
 }
 
-std::string operator+ (std::string& leftval, irc::string& rightval)
-{
-       return leftval + std::string(rightval.c_str());
-}
-
-irc::string operator+ (irc::string& leftval, std::string& rightval)
-{
-       return leftval + irc::string(rightval.c_str());
-}
-
-bool operator== (const std::string& leftval, const irc::string& rightval)
-{
-       return (leftval.c_str() == rightval);
-}
-
-bool operator== (const irc::string& leftval, const std::string& rightval)
-{
-       return (leftval == rightval.c_str());
-}
-
 const char* irc::irc_char_traits::find(const char* s1, int  n, char c)
 {
        while(n-- > 0 && lowermap[(unsigned char)*s1] != lowermap[(unsigned char)c])
@@ -165,20 +159,6 @@ const char* irc::irc_char_traits::find(const char* s1, int  n, char c)
        return s1;
 }
 
-/* See hashcomp.h if you care about these... */
-std::ostream& operator<<(std::ostream &os, const irc::string &str)
-{
-       return os << str.c_str();
-}
-
-std::istream& operator>>(std::istream &is, irc::string &str)
-{
-       std::string tmp;
-       is >> tmp;
-       str = tmp.c_str();
-       return is;
-}
-
 irc::tokenstream::tokenstream(const std::string &source) : tokens(source), last_pushed(false)
 {
        /* Record starting position and current position */
@@ -286,8 +266,9 @@ std::string irc::hex(const unsigned char *raw, size_t rawsz)
        /* EWW! This used to be using sprintf, which is WAY inefficient. -Special */
        
        const char *hex = "0123456789abcdef";
-       
-       char buf[rawsz*2+1];
+
+       std::string buf;
+       buf.reserve(rawsz * 2 + 1);
 
        size_t i, j;
        for (i = 0, j = 0; j < rawsz; ++j)
@@ -300,7 +281,7 @@ std::string irc::hex(const unsigned char *raw, size_t rawsz)
        return buf;
 }
 
-const char* irc::Spacify(const char* n)
+CoreExport const char* irc::Spacify(const char* n)
 {
        static char x[MAXBUF];
        strlcpy(x,n,MAXBUF);
@@ -503,7 +484,7 @@ irc::dynamicbitmask::~dynamicbitmask()
        /* Tidy up the entire used memory on delete */
        delete[] bits;
 }
-                         
+
 irc::bitfield irc::dynamicbitmask::Allocate()
 {
        /* Yeah, this isnt too efficient, however a module or the core
@@ -614,13 +595,3 @@ unsigned char irc::dynamicbitmask::GetSize()
        return bits_size;
 }
 
-std::string assign(const irc::string &other)
-{
-       return other.c_str();
-}
-
-irc::string assign(const std::string &other)
-{
-       return other.c_str();
-}
-