|
|
|
|
|
by SeoxyS
4948 days ago
|
|
It's not a common use case, but I've had to do it. Luckily, it's fairly easy: int count_multibytes_encountered(char *text, unsigned long len) {
int count = 0;
for (int i = 0; i < len; i++) {
if ((*(text+i) & 0b10000000) == 0b10000000 && // check if it's a multi-char byte
(~*(text+i) & 0b01000000) == 0b01000000) { // and check that it's not a leading byte
count++;
}
}
return count;
}
|
|