unicode.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. #else
  25. # if CONFIG_LAST_SUPPORTED_WCHAR < 126 || CONFIG_LAST_SUPPORTED_WCHAR >= 0x30000
  26. # undef CONFIG_LAST_SUPPORTED_WCHAR
  27. # define CONFIG_LAST_SUPPORTED_WCHAR 0x2ffff
  28. # endif
  29. # if CONFIG_LAST_SUPPORTED_WCHAR < 0x300
  30. # undef ENABLE_UNICODE_COMBINING_WCHARS
  31. # define ENABLE_UNICODE_COMBINING_WCHARS 0
  32. # endif
  33. # if CONFIG_LAST_SUPPORTED_WCHAR < 0x1100
  34. # undef ENABLE_UNICODE_WIDE_WCHARS
  35. # define ENABLE_UNICODE_WIDE_WCHARS 0
  36. # endif
  37. # if CONFIG_LAST_SUPPORTED_WCHAR < 0x590
  38. # undef ENABLE_UNICODE_BIDI_SUPPORT
  39. # define ENABLE_UNICODE_BIDI_SUPPORT 0
  40. # endif
  41. /* Number of unicode chars. Falls back to strlen() on invalid unicode */
  42. size_t FAST_FUNC unicode_strlen(const char *string);
  43. /* Width on terminal */
  44. size_t FAST_FUNC unicode_strwidth(const char *string);
  45. enum {
  46. UNI_FLAG_PAD = (1 << 0),
  47. };
  48. //UNUSED: unsigned FAST_FUNC unicode_padding_to_width(unsigned width, const char *src);
  49. //UNUSED: char* FAST_FUNC unicode_conv_to_printable2(uni_stat_t *stats, const char *src, unsigned width, int flags);
  50. char* FAST_FUNC unicode_conv_to_printable(uni_stat_t *stats, const char *src);
  51. char* FAST_FUNC unicode_conv_to_printable_maxwidth(uni_stat_t *stats, const char *src, unsigned maxwidth);
  52. char* FAST_FUNC unicode_conv_to_printable_fixedwidth(uni_stat_t *stats, const char *src, unsigned width);
  53. # if ENABLE_UNICODE_USING_LOCALE
  54. extern uint8_t unicode_status;
  55. void init_unicode(void) FAST_FUNC;
  56. # else
  57. /* Homegrown Unicode support. It knows only C and Unicode locales. */
  58. # if !ENABLE_FEATURE_CHECK_UNICODE_IN_ENV
  59. # define unicode_status UNICODE_ON
  60. # define init_unicode() ((void)0)
  61. # else
  62. extern uint8_t unicode_status;
  63. void init_unicode(void) FAST_FUNC;
  64. # endif
  65. # undef MB_CUR_MAX
  66. # define MB_CUR_MAX 6
  67. /* Prevent name collisions */
  68. # define wint_t bb_wint_t
  69. # define mbstate_t bb_mbstate_t
  70. # define mbstowcs bb_mbstowcs
  71. # define wcstombs bb_wcstombs
  72. # define wcrtomb bb_wcrtomb
  73. # define iswspace bb_iswspace
  74. # define iswalnum bb_iswalnum
  75. # define iswpunct bb_iswpunct
  76. # define wcwidth bb_wcwidth
  77. typedef int32_t wint_t;
  78. typedef struct {
  79. char bogus;
  80. } mbstate_t;
  81. size_t mbstowcs(wchar_t *dest, const char *src, size_t n) FAST_FUNC;
  82. size_t wcstombs(char *dest, const wchar_t *src, size_t n) FAST_FUNC;
  83. size_t wcrtomb(char *s, wchar_t wc, mbstate_t *ps) FAST_FUNC;
  84. int iswspace(wint_t wc) FAST_FUNC;
  85. int iswalnum(wint_t wc) FAST_FUNC;
  86. int iswpunct(wint_t wc) FAST_FUNC;
  87. int wcwidth(unsigned ucs) FAST_FUNC;
  88. # if ENABLE_UNICODE_BIDI_SUPPORT
  89. # undef unicode_bidi_isrtl
  90. int unicode_bidi_isrtl(wint_t wc) FAST_FUNC;
  91. # if ENABLE_UNICODE_NEUTRAL_TABLE
  92. # undef unicode_bidi_is_neutral_wchar
  93. int unicode_bidi_is_neutral_wchar(wint_t wc) FAST_FUNC;
  94. # endif
  95. # endif
  96. # endif /* !UNICODE_USING_LOCALE */
  97. #endif /* UNICODE_SUPPORT */
  98. POP_SAVED_FUNCTION_VISIBILITY
  99. #endif