48 lines
1.0 KiB
C
48 lines
1.0 KiB
C
#include <ctype.h>
|
|
#include <gargoyle/codex.h>
|
|
#include <gargoyle/twine.h>
|
|
|
|
uint8_t gargoyle_is_sep(char tok) {
|
|
return (tok == '_' || tok == '-');
|
|
}
|
|
|
|
uint8_t gargoyle_is_eql(char lhs, char rhs) {
|
|
return tolower(lhs) == tolower(rhs);
|
|
}
|
|
|
|
uint8_t gargoyle_cmp(const char *s1, const char *s2, uint16_t len, gargoyle_flag_type flags) {
|
|
while(*s1 && *s2 && len) {
|
|
if(flags & GARGOYLE_FLG_ICASE && isalpha(*s1) && gargoyle_is_eql(*s1, *s2)) {
|
|
s1 += 1, s2 += 1;
|
|
} else if(flags & GARGOYLE_FLG_SYMBL && gargoyle_is_sep(*s1) && gargoyle_is_sep(*s2)) {
|
|
s1 += 1, s2 += 1;
|
|
} else if(*s1 == *s2) {
|
|
s1 += 1, s2 += 1;
|
|
} else {
|
|
return 0;
|
|
}
|
|
|
|
len -= 1;
|
|
}
|
|
|
|
return !len || *s1 == *s2;
|
|
}
|
|
|
|
char *gargoyle_cpy(char *dst, const char *src, uint16_t len, gargoyle_flag_type flags) {
|
|
if(flags & GARGOYLE_FLG_FILL0) {
|
|
*(dst + len - 1) = '\0';
|
|
len -= 1;
|
|
}
|
|
|
|
for(; len; dst += 1, len -= 1) {
|
|
if(*src) {
|
|
*dst = *src;
|
|
src += 1;
|
|
} else {
|
|
*dst = '\0';
|
|
}
|
|
}
|
|
|
|
return dst;
|
|
}
|