unicode.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Licensed under GPLv2, see file LICENSE in this source tree.
  4. */
  5. #ifndef UNICODE_H
  6. #define UNICODE_H 1
  7. #if ENABLE_UNICODE_USING_LOCALE
  8. # include <wchar.h>
  9. # include <wctype.h>
  10. #endif
  11. PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
  12. enum {
  13. UNICODE_UNKNOWN = 0,
  14. UNICODE_OFF = 1,
  15. UNICODE_ON = 2,
  16. };
  17. #define unicode_bidi_isrtl(wc) 0
  18. #define unicode_bidi_is_neutral_wchar(wc) (wc <= 126 && !isalpha(wc))
  19. #if !ENABLE_UNICODE_SUPPORT
  20. # define unicode_strlen(string) strlen(string)
  21. # define unicode_strwidth(string) strlen(string)
  22. # define unicode_status UNICODE_OFF
  23. # define init_unicode() ((void)0)
  24. # define reinit_unicode(LANG) ((void)0)
  25. #else
  26. # if CONFIG_LAST_SUPPORTED_WCHAR < 126 || CONFIG_LAST_SUPPORTED_WCHAR >= 0x30000
  27. # undef CONFIG_LAST_SUPPORTED_WCHAR
  28. # define CONFIG_LAST_SUPPORTED_WCHAR 0x2ffff
  29. # endif
  30. # if CONFIG_LAST_SUPPORTED_WCHAR < 0x300
  31. # undef ENABLE_UNICODE_COMBINING_WCHARS
  32. # define ENABLE_UNICODE_COMBINING_WCHARS 0
  33. # endif
  34. # if CONFIG_LAST_SUPPORTED_WCHAR < 0x1100
  35. # undef ENABLE_UNICODE_WIDE_WCHARS
  36. # define ENABLE_UNICODE_WIDE_WCHARS 0
  37. # endif
  38. # if CONFIG_LAST_SUPPORTED_WCHAR < 0x590
  39. # undef ENABLE_UNICODE_BIDI_SUPPORT
  40. # define ENABLE_UNICODE_BIDI_SUPPORT 0
  41. # endif
  42. /* Number of unicode chars. Falls back to strlen() on invalid unicode */
  43. size_t FAST_FUNC unicode_strlen(const char *string);
  44. /* Width on terminal */
  45. size_t FAST_FUNC unicode_strwidth(const char *string);
  46. enum {
  47. UNI_FLAG_PAD = (1 << 0),
  48. };
  49. //UNUSED: unsigned FAST_FUNC unicode_padding_to_width(unsigned width, const char *src);
  50. //UNUSED: char* FAST_FUNC unicode_conv_to_printable2(uni_stat_t *stats, const char *src, unsigned width, int flags);
  51. char* FAST_FUNC unicode_conv_to_printable(uni_stat_t *stats, const char *src);
  52. //UNUSED: char* FAST_FUNC unicode_conv_to_printable_maxwidth(uni_stat_t *stats, const char *src, unsigned maxwidth);
  53. char* FAST_FUNC unicode_conv_to_printable_fixedwidth(/*uni_stat_t *stats,*/ const char *src, unsigned width);
  54. # if ENABLE_UNICODE_USING_LOCALE
  55. extern uint8_t unicode_status;
  56. void init_unicode(void) FAST_FUNC;
  57. void reinit_unicode(const char *LANG) FAST_FUNC;
  58. # else
  59. /* Homegrown Unicode support. It knows only C and Unicode locales. */
  60. # if !ENABLE_FEATURE_CHECK_UNICODE_IN_ENV
  61. # define unicode_status UNICODE_ON
  62. # define init_unicode() ((void)0)
  63. # define reinit_unicode(LANG) ((void)0)
  64. # else
  65. extern uint8_t unicode_status;
  66. void init_unicode(void) FAST_FUNC;
  67. void reinit_unicode(const char *LANG) FAST_FUNC;
  68. # endif
  69. # undef MB_CUR_MAX
  70. # define MB_CUR_MAX 6
  71. /* Prevent name collisions */
  72. # define wint_t bb_wint_t
  73. # define mbstate_t bb_mbstate_t
  74. # define mbstowcs bb_mbstowcs
  75. # define wcstombs bb_wcstombs
  76. # define wcrtomb bb_wcrtomb
  77. # define iswspace bb_iswspace
  78. # define iswalnum bb_iswalnum
  79. # define iswpunct bb_iswpunct
  80. # define wcwidth bb_wcwidth
  81. typedef int32_t wint_t;
  82. typedef struct {
  83. char bogus;
  84. } mbstate_t;
  85. size_t mbstowcs(wchar_t *dest, const char *src, size_t n) FAST_FUNC;
  86. size_t wcstombs(char *dest, const wchar_t *src, size_t n) FAST_FUNC;
  87. size_t wcrtomb(char *s, wchar_t wc, mbstate_t *ps) FAST_FUNC;
  88. int iswspace(wint_t wc) FAST_FUNC;
  89. int iswalnum(wint_t wc) FAST_FUNC;
  90. int iswpunct(wint_t wc) FAST_FUNC;
  91. int wcwidth(unsigned ucs) FAST_FUNC;
  92. # if ENABLE_UNICODE_BIDI_SUPPORT
  93. # undef unicode_bidi_isrtl
  94. int unicode_bidi_isrtl(wint_t wc) FAST_FUNC;
  95. # if ENABLE_UNICODE_NEUTRAL_TABLE
  96. # undef unicode_bidi_is_neutral_wchar
  97. int unicode_bidi_is_neutral_wchar(wint_t wc) FAST_FUNC;
  98. # endif
  99. # endif
  100. # endif /* !UNICODE_USING_LOCALE */
  101. #endif /* UNICODE_SUPPORT */
  102. POP_SAVED_FUNCTION_VISIBILITY
  103. #endif