| 198 | } |
| 199 | |
| 200 | int utf8_icmp(const std::string& a, const std::string& b, int n) |
| 201 | { |
| 202 | utf8_const_iterator a_it(a.begin()); |
| 203 | utf8_const_iterator a_end(a.end()); |
| 204 | utf8_const_iterator b_it(b.begin()); |
| 205 | utf8_const_iterator b_end(b.end()); |
| 206 | int i = 0; |
| 207 | |
| 208 | for (; (n == 0 || i < n) && a_it != a_end && b_it != b_end; ++a_it, ++b_it, ++i) { |
| 209 | int a_chr = std::tolower(*a_it); |
| 210 | int b_chr = std::tolower(*b_it); |
| 211 | |
| 212 | if (a_chr < b_chr) |
| 213 | return -1; |
| 214 | else if (a_chr > b_chr) |
| 215 | return 1; |
| 216 | } |
| 217 | |
| 218 | if (n > 0 && i == n) |
| 219 | return 0; |
| 220 | else if (a_it == a_end && b_it == b_end) |
| 221 | return 0; |
| 222 | else if (a_it == a_end) |
| 223 | return -1; |
| 224 | else |
| 225 | return 1; |
| 226 | } |
| 227 | |
| 228 | } // namespace base |