5 // Created by James McIlree on 4/16/13.
6 // Copyright (c) 2013 Apple. All rights reserved.
9 #ifndef CPPUtil_UtilString_hpp
10 #define CPPUtil_UtilString_hpp
12 struct ConstCharHash {
14 // Okay, by design std::hash<char*> hashes on the pointer,
15 // not the contents of that pointer.
17 // The C++11 std::hash<std::string> hash works, but must
18 // construct a copy of the passed in string to hash.
20 // That's 3x slower than this, minimum.
22 // This is just the __gnu_cxx hash code inlined.
24 std::size_t operator()(const char* __s) const {
25 unsigned long __h = 0;
33 struct ConstCharEqualTo {
34 bool operator() (const char* s1, const char* s2) const {
35 return strcmp(s1, s2) == 0;
39 bool ends_with(std::string& str, std::string postfix);