lineedit: first shot at optional unicode bidi input support
[platform/upstream/busybox.git] / include / unicode.h
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
8 #if ENABLE_LOCALE_SUPPORT
9 # include <wchar.h>
10 # include <wctype.h>
11 #endif
12
13 PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
14
15 enum {
16         UNICODE_UNKNOWN = 0,
17         UNICODE_OFF = 1,
18         UNICODE_ON = 2,
19 };
20
21 #define unicode_isrtl(wc) 0
22
23 #if !ENABLE_FEATURE_ASSUME_UNICODE
24
25 # define unicode_strlen(string) strlen(string)
26 # define unicode_status UNICODE_OFF
27 # define init_unicode() ((void)0)
28
29 #else
30
31 # if CONFIG_LAST_SUPPORTED_WCHAR < 126 || CONFIG_LAST_SUPPORTED_WCHAR >= 0x30000
32 #  define LAST_SUPPORTED_WCHAR 0x2ffff
33 # else
34 #  define LAST_SUPPORTED_WCHAR CONFIG_LAST_SUPPORTED_WCHAR
35 # endif
36
37 # if LAST_SUPPORTED_WCHAR < 0x590
38 #  undef  ENABLE_UNICODE_BIDI_SUPPORT
39 #  define ENABLE_UNICODE_BIDI_SUPPORT 0
40 # endif
41
42 size_t FAST_FUNC unicode_strlen(const char *string);
43 enum {
44         UNI_FLAG_PAD = (1 << 0),
45 };
46 //UNUSED: unsigned FAST_FUNC unicode_padding_to_width(unsigned width, const char *src);
47 //UNUSED: char* FAST_FUNC unicode_conv_to_printable2(uni_stat_t *stats, const char *src, unsigned width, int flags);
48 char* FAST_FUNC unicode_conv_to_printable(uni_stat_t *stats, const char *src);
49 char* FAST_FUNC unicode_conv_to_printable_maxwidth(uni_stat_t *stats, const char *src, unsigned maxwidth);
50 char* FAST_FUNC unicode_conv_to_printable_fixedwidth(uni_stat_t *stats, const char *src, unsigned width);
51
52 # if ENABLE_LOCALE_SUPPORT
53
54 extern uint8_t unicode_status;
55 void init_unicode(void) FAST_FUNC;
56
57 # else
58
59 /* Homegrown Unicode support. It knows only C and Unicode locales. */
60
61 #  if !ENABLE_FEATURE_CHECK_UNICODE_IN_ENV
62 #   define unicode_status UNICODE_ON
63 #   define init_unicode() ((void)0)
64 #  else
65 extern uint8_t unicode_status;
66 void init_unicode(void) FAST_FUNC;
67 #  endif
68
69 #  undef MB_CUR_MAX
70 #  define MB_CUR_MAX 6
71
72 /* Prevent name collisions */
73 #  define wint_t    bb_wint_t
74 #  define mbstate_t bb_mbstate_t
75 #  define mbstowcs  bb_mbstowcs
76 #  define wcstombs  bb_wcstombs
77 #  define wcrtomb   bb_wcrtomb
78 #  define iswspace  bb_iswspace
79 #  define iswalnum  bb_iswalnum
80 #  define iswpunct  bb_iswpunct
81 #  define wcwidth   bb_wcwidth
82
83 typedef int32_t wint_t;
84 typedef struct {
85         char bogus;
86 } mbstate_t;
87
88 size_t mbstowcs(wchar_t *dest, const char *src, size_t n) FAST_FUNC;
89 size_t wcstombs(char *dest, const wchar_t *src, size_t n) FAST_FUNC;
90 size_t wcrtomb(char *s, wchar_t wc, mbstate_t *ps) FAST_FUNC;
91 int iswspace(wint_t wc) FAST_FUNC;
92 int iswalnum(wint_t wc) FAST_FUNC;
93 int iswpunct(wint_t wc) FAST_FUNC;
94 #  if ENABLE_UNICODE_BIDI_SUPPORT
95 #   undef unicode_isrtl
96 int unicode_isrtl(wint_t wc) FAST_FUNC;
97 #  endif
98
99
100 # endif /* !LOCALE_SUPPORT */
101
102 #endif /* FEATURE_ASSUME_UNICODE */
103
104 POP_SAVED_FUNCTION_VISIBILITY
105
106 #endif