Effective STL 35 Case-insensitive string comparisons via mismatch or lexicographical_compare.
来源:互联网 发布:嵌入式linux系统移植 编辑:程序博客网 时间:2024/05/16 09:57
// case-insensitively compare chars c1 and c2int ciCharCompare(char c1, char c2) { // tolower's parameter and return value is of type int, but unless that // int is EOF, its value must be representable as an unsigned char int lc1 = tolower(stastic_cast<unsigned char>(c1)); int lc2 = tolower(stastic_cast<unsigned char>(c2)); if (lc1 < lc2) return -1; if (lc1 > lc1) return 1; return 0;}
mismatch
It returns a pair of iterators indicating the locations in the ranges where corresponding characters first fail to match.
int ciStringComparelmpl(const string& s1, const string& s2);// when we call mismatch, we have to make sure the shorter string is the// first range passed;int cisStringCompare(const sring& s1, const string& s2) { if (s1.size() <= s2.size()) return ciStringComparelmpl(s1, s2); else return -ciStringComparelmpl(s2, s1);}int ciStringComparelmp(const string& s1, const string& s2) { typedef pair<string::const_iterator, string::const_iterator> PSCI; PSCI p = mismatch(s1.begin(), s1.end(), s2.begin(), not2(ptr_func(ciCharCompare))); if(p.first == s1.end()) { if (p.second == s2.end()) return 0; else return -1; } return ciCharCompare(*p.first, *p.second);}
lexicographical_compare is a generalized version of strcmp. it works with ranges of values of any type. Based on the results of calls to ciCharLess. if ciCharLess is true, so does lexicographical.
bool ciCharLess(char c1, char c2) { return tolower(static_cast<unsigned char>(c1)) < tolower(ststic_cast<unsigned char>(c2));}bool ciStringCompare(const string& s1, const string& s2) { return lexicographical_compare(s1.begin(), s1.end(), s2.begin(), s2.end(), isCharLess);
阅读全文
0 0
- Effective STL 35 Case-insensitive string comparisons via mismatch or lexicographical_compare.
- Effective STL appendix A Locales and Case-Insensitive String Comparisons
- effective stl 第35条:通过mismatch和lexicographical_compare实现简单的忽略大小写的字符串比较
- STL比较范围(equal, lexicographical_compare, mismatch)
- Case-Insensitive
- STL_Algorithm2: equal, mismatch, lexicographical_compare
- mismatch和lexicographical_compare
- Compares two strings (case insensitive)
- find_first_of,adjacent_find,equal,mismatch,lexicographical_compare大杂烩
- Effective STL--2.Vector String
- Effective STL -- vector和string
- lexicographical_compare
- lexicographical_compare
- STL_算法_区间的比较(equal、mismatch、 lexicographical_compare)
- Filesystem Case-Sensitivity Mismatch
- STL algorithm算法lexicographical_compare(30)
- Effective STL 条款35
- effective STL - 小心string实现的多样性
- centos7安装redis
- opencv的矩阵
- 深入浅出JMS(四)--Spring和ActiveMQ整合的完整实例
- mvn命令打正式服包但打出来的还是测试服包问题
- 手机微信页面怎么查看源码
- Effective STL 35 Case-insensitive string comparisons via mismatch or lexicographical_compare.
- Handler内存泄漏分析
- JAVA内存溢出解决方法
- 如何编写合理的Javascript代码并牢记javascript的地位
- Javaweb学习路线
- spring MVC原理
- Grid数据窗口加标题的方法
- FNCOS FM1208-43COS指令集 指令标识 与错误号
- Android图片三级缓存(内存,SD)