+size_t irc::find(const std::string& haystack, const std::string& needle)
+{
+ // The haystack can't contain the needle if it is smaller than it.
+ if (needle.length() > haystack.length())
+ return std::string::npos;
+
+ // The inner loop checks the characters between haystack_last and the end of the haystack.
+ size_t haystack_last = haystack.length() - needle.length();
+ for (size_t hpos = 0; hpos <= haystack_last; ++hpos)
+ {
+ // Check for the needle at the current haystack position.
+ bool found = true;
+ for (size_t npos = 0; npos < needle.length(); ++npos)
+ {
+ if (national_case_insensitive_map[(unsigned char)needle[npos]] != national_case_insensitive_map[(unsigned char)haystack[hpos + npos]])
+ {
+ // Uh-oh, characters at the current haystack position don't match.
+ found = false;
+ break;
+ }
+ }
+
+ // The entire needle was found in the haystack!
+ if (found)
+ return hpos;
+ }
+
+ // We didn't find anything.
+ return std::string::npos;
+}
+
+