aboutsummaryrefslogtreecommitdiff
path: root/include/unicode.h
blob: dee02e7776606c64c4b75902b00833f8e8c17269 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/* vi: set sw=4 ts=4: */
/*
 * Licensed under GPLv2, see file LICENSE in this source tree.
 */
#ifndef UNICODE_H
#define UNICODE_H 1

#if ENABLE_UNICODE_USING_LOCALE
# include <wchar.h>
# include <wctype.h>
#endif

PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN

enum {
	UNICODE_UNKNOWN = 0,
	UNICODE_OFF = 1,
	UNICODE_ON = 2,
};

#define unicode_bidi_isrtl(wc) 0
#define unicode_bidi_is_neutral_wchar(wc) (wc <= 126 && !isalpha(wc))

#if !ENABLE_UNICODE_SUPPORT

# define unicode_strlen(string)   strlen(string)
# define unicode_strwidth(string) strlen(string)
# define unicode_status UNICODE_OFF
# define init_unicode() ((void)0)

#else

# if CONFIG_LAST_SUPPORTED_WCHAR < 126 || CONFIG_LAST_SUPPORTED_WCHAR >= 0x30000
#  undef CONFIG_LAST_SUPPORTED_WCHAR
#  define CONFIG_LAST_SUPPORTED_WCHAR 0x2ffff
# endif

# if CONFIG_LAST_SUPPORTED_WCHAR < 0x300
#  undef ENABLE_UNICODE_COMBINING_WCHARS
#  define ENABLE_UNICODE_COMBINING_WCHARS 0
# endif

# if CONFIG_LAST_SUPPORTED_WCHAR < 0x1100
#  undef ENABLE_UNICODE_WIDE_WCHARS
#  define ENABLE_UNICODE_WIDE_WCHARS 0
# endif

# if CONFIG_LAST_SUPPORTED_WCHAR < 0x590
#  undef  ENABLE_UNICODE_BIDI_SUPPORT
#  define ENABLE_UNICODE_BIDI_SUPPORT 0
# endif

/* Number of unicode chars. Falls back to strlen() on invalid unicode */
size_t FAST_FUNC unicode_strlen(const char *string);
/* Width on terminal */
size_t FAST_FUNC unicode_strwidth(const char *string);
enum {
	UNI_FLAG_PAD = (1 << 0),
};
//UNUSED: unsigned FAST_FUNC unicode_padding_to_width(unsigned width, const char *src);
//UNUSED: char* FAST_FUNC unicode_conv_to_printable2(uni_stat_t *stats, const char *src, unsigned width, int flags);
char* FAST_FUNC unicode_conv_to_printable(uni_stat_t *stats, const char *src);
//UNUSED: char* FAST_FUNC unicode_conv_to_printable_maxwidth(uni_stat_t *stats, const char *src, unsigned maxwidth);
char* FAST_FUNC unicode_conv_to_printable_fixedwidth(/*uni_stat_t *stats,*/ const char *src, unsigned width);

# if ENABLE_UNICODE_USING_LOCALE

extern uint8_t unicode_status;
void init_unicode(void) FAST_FUNC;

# else

/* Homegrown Unicode support. It knows only C and Unicode locales. */

#  if !ENABLE_FEATURE_CHECK_UNICODE_IN_ENV
#   define unicode_status UNICODE_ON
#   define init_unicode() ((void)0)
#  else
extern uint8_t unicode_status;
void init_unicode(void) FAST_FUNC;
#  endif

#  undef MB_CUR_MAX
#  define MB_CUR_MAX 6

/* Prevent name collisions */
#  define wint_t    bb_wint_t
#  define mbstate_t bb_mbstate_t
#  define mbstowcs  bb_mbstowcs
#  define wcstombs  bb_wcstombs
#  define wcrtomb   bb_wcrtomb
#  define iswspace  bb_iswspace
#  define iswalnum  bb_iswalnum
#  define iswpunct  bb_iswpunct
#  define wcwidth   bb_wcwidth

typedef int32_t wint_t;
typedef struct {
	char bogus;
} mbstate_t;

size_t mbstowcs(wchar_t *dest, const char *src, size_t n) FAST_FUNC;
size_t wcstombs(char *dest, const wchar_t *src, size_t n) FAST_FUNC;
size_t wcrtomb(char *s, wchar_t wc, mbstate_t *ps) FAST_FUNC;
int iswspace(wint_t wc) FAST_FUNC;
int iswalnum(wint_t wc) FAST_FUNC;
int iswpunct(wint_t wc) FAST_FUNC;
int wcwidth(unsigned ucs) FAST_FUNC;
#  if ENABLE_UNICODE_BIDI_SUPPORT
#   undef unicode_bidi_isrtl
int unicode_bidi_isrtl(wint_t wc) FAST_FUNC;
#   if ENABLE_UNICODE_NEUTRAL_TABLE
#    undef unicode_bidi_is_neutral_wchar
int unicode_bidi_is_neutral_wchar(wint_t wc) FAST_FUNC;
#   endif
#  endif


# endif /* !UNICODE_USING_LOCALE */

#endif /* UNICODE_SUPPORT */

POP_SAVED_FUNCTION_VISIBILITY

#endif