adjusting character counts for utf8
I have been doing this by using unsigned char buffers and a function like this:
Code:
int utfadj (unsigned char *buffer, int pos) {
int i, count=0;
for (i=0;i<pos;i++) {
if ((buffer[i]>=0x80) && (buffer[i]<=0xBF)) continue;
else count++;
}
return count;
}
However, I am kind of realizing this may not be the best idea because some functions (eg, strcasestr as opposed to strstr) return funky pointer values if the destination pointer is actually unsigned (the value works, but is useless for pointer arithmetic) . So mostly I'm just asking for the correct values to filter for a signed char (0x80 - 0xBF don't work), but I thought I'd check with a crowd to see if there are any more surprises in store.