Skip to content

Instantly share code, notes, and snippets.

@dpk dpk/utf8strlen.c
Created Oct 4, 2018

Embed
What would you like to do?
#include <stdlib.h>
unsigned long utf8_strlen(unsigned char *s) {
unsigned long len = 0;
s--;
while (*++s) {
len += !(*s >> 7) || (*s >> 6);
}
return len;
}
int main() {
for (int i = 0; i < 10000000; i++) {
utf8_strlen("hello world");
utf8_strlen("héllo world");
utf8_strlen("héłlo world");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.