utf8.cpp 638 B

12345678910111213141516171819202122232425
  1. #include "precomp_wasabi_bfc.h"
  2. #include "utf8.h"
  3. // this STILL doesn't work perfectly but at least it decodes what we write out
  4. // mostly just waiting on our wide character strategy
  5. void COMEXP UTF8_to_ASCII(const char *in, char *out) {
  6. unsigned const char *src = (unsigned const char *)in;
  7. unsigned char *dst = (unsigned char *)out;
  8. *dst = 0;
  9. for (; *src; src++) {
  10. int c = *src;
  11. if ((c & 0x80) == 0) {
  12. *dst++ = c;
  13. continue;
  14. }
  15. if ((c & 224) != 192) continue; // fuck you, we only check for single bytes
  16. int v = (c & 0x3) << 6;
  17. ++src;
  18. v |= *src & 0x3f;
  19. *dst++ = v;
  20. }
  21. *dst = 0;
  22. }