unicode.h 910 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Unicode utilities
  2. //
  3. // Platform: ISO C++ 98/11
  4. // $Id$
  5. //
  6. // (c) __vic 2017
  7. #ifndef __VIC_UNICODE_H
  8. #define __VIC_UNICODE_H
  9. #include<__vic/defs.h>
  10. #if !__cpp_unicode_characters
  11. #include<__vic/stdint.h>
  12. #endif
  13. namespace __vic {
  14. // Unicode code point type
  15. #if __cpp_unicode_characters
  16. typedef char32_t unicode_t;
  17. #else
  18. typedef uint_least32_t unicode_t;
  19. #endif
  20. __VIC_INLINE_CONSTEXPR_VAR unicode_t unicode_max = 0x10FFFF;
  21. __VIC_INLINE_CONSTEXPR_VAR unicode_t unicode_bom = 0xFEFF;
  22. __VIC_INLINE_CONSTEXPR_VAR unicode_t unicode_replacement_char = 0xFFFD;
  23. //----------------------------------------------------------------------------
  24. template<class UTFReader, class UTFWriter>
  25. inline void utf_transcode(UTFReader r, UTFWriter w)
  26. {
  27. unicode_t cp;
  28. while(r.read(cp)) w.write(cp);
  29. }
  30. //----------------------------------------------------------------------------
  31. } // namespace
  32. #endif // header guard