unicode.h 3.2 KB

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