diff options
author | John Denker <jsd@av8n.com> | 2012-11-22 16:01:04 -0800 |
---|---|---|
committer | John Denker <jsd@av8n.com> | 2012-11-22 16:01:04 -0800 |
commit | 3c9817f94592907c8c19a8b8f97af87dad3dceaf (patch) | |
tree | 5f2433dbd4d7a0c872fd3400897458b79effac67 /tools/utils.h | |
parent | bf1bf1c43a82ec167ae80f185fe11255cf3a5237 (diff) |
move case-insensitive string stuff to utils.h
Diffstat (limited to 'tools/utils.h')
-rw-r--r-- | tools/utils.h | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tools/utils.h b/tools/utils.h index 4f5418f..77cff5e 100644 --- a/tools/utils.h +++ b/tools/utils.h @@ -1,6 +1,35 @@ #include <string> #include <list> +std::string noCR(const std::string bar); +int cmp_casefold(const std::string& a, const std::string& b); + +///////////////////////////////////////////////////////// +// Case insensitive comparison of strings + +class lessthan_foldcase{ +public: + bool operator() (const std::string& a, const std::string& b) const { + size_t a_len = a.length(); + size_t b_len = b.length(); + + size_t lim = a_len < b_len ? a_len : b_len; + + for (size_t i=0; i<lim; ++i) + { + char cha = toupper(a[i]); + char chb = toupper(b[i]); + + if (cha < chb) return true; + if (cha > chb) return false; + } + // here if one is an extension of the other + if ( a_len < b_len ) return true; + return false; + } +}; + + std::string basename(const std::string path); int prefix(const std::string shorter, const std::string longer); std::string time_out(const int _ttt); |