add case insensitive string compare

master
Daniel Kolesa 2016-09-02 00:06:13 +01:00
parent 17365642ef
commit c4039fa56f
1 changed files with 20 additions and 0 deletions

View File

@ -8,6 +8,7 @@
#include <stdio.h>
#include <stddef.h>
#include <ctype.h>
#include "ostd/utility.hh"
#include "ostd/range.hh"
@ -184,6 +185,21 @@ diffsize:
return (s1 < s2) ? -1 : ((s1 > s2) ? 1 : 0);
}
int case_compare(CharRangeBase<T const> s) const {
ostd::Size s1 = size(), s2 = s.size();
if (!s1 || !s2) {
goto diffsize;
}
for (ostd::Size i = 0, ms = ostd::min(s1, s2); i < ms; ++i) {
int d = toupper(p_beg[i]) - toupper(s[i]);
if (d) {
return d;
}
}
diffsize:
return (s1 < s2) ? -1 : ((s1 > s2) ? 1 : 0);
}
template<typename R>
EnableIf<IsOutputRange<R>, Size> copy(R &&orange, Size n = -1) {
return orange.put_n(data(), ostd::min(n, size()));
@ -613,6 +629,10 @@ public:
return iter().compare(r);
}
int case_compare(ConstRange r) const {
return iter().case_compare(r);
}
Range iter() {
return Range(p_buf.first(), size());
}