| | 52 | struct CIBackwardsStringCompare: public binary_function<string, string, bool> |
| | 53 | { |
| | 54 | bool operator()(const string& a, const string& b) const |
| | 55 | { |
| | 56 | const unsigned char *p1 = (const unsigned char *) a.c_str() + a.length(); |
| | 57 | const unsigned char *p2 = (const unsigned char *) b.c_str() + b.length(); |
| | 58 | int result; |
| | 59 | |
| | 60 | if (p1 == p2) { |
| | 61 | return 0; |
| | 62 | } |
| | 63 | |
| | 64 | while ((result = dns_tolower (*p1--) - dns_tolower (*p2--)) == 0) |
| | 65 | if (p1 == (unsigned char*)a.c_str() || p2 == (unsigned char*) b.c_str()) |
| | 66 | break; |
| | 67 | |
| | 68 | if(result==0) { // one of our strings ended, the shortest one is smaller then |
| | 69 | return a.length() < b.length(); |
| | 70 | } |
| | 71 | |
| | 72 | return result < 0; |
| | 73 | } |
| | 74 | }; |
| | 75 | |
| | 76 | |