Skip to content

Instantly share code, notes, and snippets.

@dpk
Created October 4, 2018 11:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dpk/2beb8e3813bd6b34a6dd67b37a9b2134 to your computer and use it in GitHub Desktop.
Save dpk/2beb8e3813bd6b34a6dd67b37a9b2134 to your computer and use it in GitHub Desktop.
#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