utf.h 897 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #ifndef UTFH
  2. #define UTFH
  3. /*
  4. * utf and utfio
  5. */
  6. typedef unsigned char byte;
  7. enum {
  8. utfbytes=4,
  9. utfeof=-1,
  10. ucbsize=512,
  11. utfbsize=utfbytes*ucbsize
  12. };
  13. extern byte utf8buff[utfbsize]; /* general purpose buffer for utf8 sequences */
  14. extern int ucbuff[ucbsize]; /* general purpose buffer for unicode sequences */
  15. int convnutf(byte *, int *, int);
  16. int convnucode(int, byte *, int);
  17. int utf8nstring(int*, byte*, unsigned int);
  18. int ucodenstring(byte *, int*, unsigned int);
  19. #define utf8(u) (utf8nstring(u,utf8buff,utfbsize),utf8buff)
  20. #define ucode(b) (ucodenstring(b,ucbuff,ucbsize),ucbuff)
  21. #define convutf(p,z) convnutf(p,z,utfbytes)
  22. #define convucode(p,z) convnucode(p,z,utfbytes)
  23. /*
  24. * escaped chars
  25. *
  26. */
  27. enum {
  28. ESC=(1 << ((8*utfbytes)-1)), /* 0x80000000 */
  29. UNESC=~ESC,
  30. };
  31. #define escape(c) ((c)|ESC)
  32. #define escaped(c) ((c)&ESC)
  33. #define unescape(c) ((c)&UNESC)
  34. #endif