blob: eaf67c833faa8d7b6cfcc58e7f61dc78587c9610 [file] [log] [blame]
Denys Vlasenko42a8fd02009-07-11 21:36:13 +02001/* 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
Denys Vlasenko19158a82010-03-26 14:06:56 +01008#if ENABLE_UNICODE_USING_LOCALE
Denys Vlasenko2f8a4602010-02-19 08:47:17 +01009# include <wchar.h>
10# include <wctype.h>
11#endif
12
Denys Vlasenkobb1dcc92010-02-02 12:45:38 +010013PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
14
Denys Vlasenko28055022010-01-04 20:49:58 +010015enum {
16 UNICODE_UNKNOWN = 0,
17 UNICODE_OFF = 1,
18 UNICODE_ON = 2,
19};
20
Tomas Heinrichaa167552010-03-26 13:13:24 +010021#define unicode_bidi_isrtl(wc) 0
22#define unicode_bidi_is_neutral_wchar(wc) (wc <= 126 && !isalpha(wc))
Tomas Heinrichc5c006c2010-03-18 18:35:37 +010023
Denys Vlasenko19158a82010-03-26 14:06:56 +010024#if !ENABLE_UNICODE_SUPPORT
Denys Vlasenko42a8fd02009-07-11 21:36:13 +020025
Denys Vlasenko9f93d622010-01-24 07:44:03 +010026# define unicode_strlen(string) strlen(string)
Denys Vlasenko28055022010-01-04 20:49:58 +010027# define unicode_status UNICODE_OFF
28# define init_unicode() ((void)0)
Denys Vlasenko42a8fd02009-07-11 21:36:13 +020029
30#else
31
Tomas Heinrichc5c006c2010-03-18 18:35:37 +010032# if CONFIG_LAST_SUPPORTED_WCHAR < 126 || CONFIG_LAST_SUPPORTED_WCHAR >= 0x30000
Denys Vlasenko26e2c1d2010-05-16 21:15:03 +020033# undef CONFIG_LAST_SUPPORTED_WCHAR
34# define CONFIG_LAST_SUPPORTED_WCHAR 0x2ffff
Tomas Heinrichc5c006c2010-03-18 18:35:37 +010035# endif
36
Denys Vlasenko26e2c1d2010-05-16 21:15:03 +020037# if CONFIG_LAST_SUPPORTED_WCHAR < 0x300
Tomas Heinrichb8909c52010-05-16 20:46:53 +020038# undef ENABLE_UNICODE_COMBINING_WCHARS
39# define ENABLE_UNICODE_COMBINING_WCHARS 0
40# endif
41
Denys Vlasenko26e2c1d2010-05-16 21:15:03 +020042# if CONFIG_LAST_SUPPORTED_WCHAR < 0x1100
Tomas Heinrichb8909c52010-05-16 20:46:53 +020043# undef ENABLE_UNICODE_WIDE_WCHARS
44# define ENABLE_UNICODE_WIDE_WCHARS 0
45# endif
46
Denys Vlasenko26e2c1d2010-05-16 21:15:03 +020047# if CONFIG_LAST_SUPPORTED_WCHAR < 0x590
Tomas Heinrichc5c006c2010-03-18 18:35:37 +010048# undef ENABLE_UNICODE_BIDI_SUPPORT
49# define ENABLE_UNICODE_BIDI_SUPPORT 0
50# endif
51
Denys Vlasenko9f93d622010-01-24 07:44:03 +010052size_t FAST_FUNC unicode_strlen(const char *string);
Denys Vlasenkoe17764c2010-01-30 23:16:21 +010053enum {
54 UNI_FLAG_PAD = (1 << 0),
55};
Denys Vlasenkoe17764c2010-01-30 23:16:21 +010056//UNUSED: unsigned FAST_FUNC unicode_padding_to_width(unsigned width, const char *src);
57//UNUSED: char* FAST_FUNC unicode_conv_to_printable2(uni_stat_t *stats, const char *src, unsigned width, int flags);
58char* FAST_FUNC unicode_conv_to_printable(uni_stat_t *stats, const char *src);
59char* FAST_FUNC unicode_conv_to_printable_maxwidth(uni_stat_t *stats, const char *src, unsigned maxwidth);
60char* FAST_FUNC unicode_conv_to_printable_fixedwidth(uni_stat_t *stats, const char *src, unsigned width);
Denys Vlasenkofda8f572009-07-11 22:26:48 +020061
Denys Vlasenko19158a82010-03-26 14:06:56 +010062# if ENABLE_UNICODE_USING_LOCALE
Denys Vlasenko42a8fd02009-07-11 21:36:13 +020063
Denys Vlasenko28055022010-01-04 20:49:58 +010064extern uint8_t unicode_status;
65void init_unicode(void) FAST_FUNC;
Denys Vlasenko42a8fd02009-07-11 21:36:13 +020066
67# else
68
Denys Vlasenko9f93d622010-01-24 07:44:03 +010069/* Homegrown Unicode support. It knows only C and Unicode locales. */
Denys Vlasenkofda8f572009-07-11 22:26:48 +020070
Denys Vlasenko42a8fd02009-07-11 21:36:13 +020071# if !ENABLE_FEATURE_CHECK_UNICODE_IN_ENV
Denys Vlasenko28055022010-01-04 20:49:58 +010072# define unicode_status UNICODE_ON
73# define init_unicode() ((void)0)
Denys Vlasenko42a8fd02009-07-11 21:36:13 +020074# else
Denys Vlasenko28055022010-01-04 20:49:58 +010075extern uint8_t unicode_status;
76void init_unicode(void) FAST_FUNC;
Denys Vlasenko42a8fd02009-07-11 21:36:13 +020077# endif
78
79# undef MB_CUR_MAX
80# define MB_CUR_MAX 6
81
82/* Prevent name collisions */
83# define wint_t bb_wint_t
84# define mbstate_t bb_mbstate_t
85# define mbstowcs bb_mbstowcs
86# define wcstombs bb_wcstombs
87# define wcrtomb bb_wcrtomb
88# define iswspace bb_iswspace
89# define iswalnum bb_iswalnum
90# define iswpunct bb_iswpunct
Denys Vlasenko9f93d622010-01-24 07:44:03 +010091# define wcwidth bb_wcwidth
Denys Vlasenko42a8fd02009-07-11 21:36:13 +020092
93typedef int32_t wint_t;
94typedef struct {
95 char bogus;
96} mbstate_t;
97
98size_t mbstowcs(wchar_t *dest, const char *src, size_t n) FAST_FUNC;
99size_t wcstombs(char *dest, const wchar_t *src, size_t n) FAST_FUNC;
100size_t wcrtomb(char *s, wchar_t wc, mbstate_t *ps) FAST_FUNC;
101int iswspace(wint_t wc) FAST_FUNC;
102int iswalnum(wint_t wc) FAST_FUNC;
103int iswpunct(wint_t wc) FAST_FUNC;
Tomas Heinrichb8909c52010-05-16 20:46:53 +0200104int wcwidth(unsigned ucs) FAST_FUNC;
Tomas Heinrichc5c006c2010-03-18 18:35:37 +0100105# if ENABLE_UNICODE_BIDI_SUPPORT
Tomas Heinrichaa167552010-03-26 13:13:24 +0100106# undef unicode_bidi_isrtl
107int unicode_bidi_isrtl(wint_t wc) FAST_FUNC;
108# if ENABLE_UNICODE_NEUTRAL_TABLE
109# undef unicode_bidi_is_neutral_wchar
110int unicode_bidi_is_neutral_wchar(wint_t wc) FAST_FUNC;
111# endif
Tomas Heinrichc5c006c2010-03-18 18:35:37 +0100112# endif
Denys Vlasenko42a8fd02009-07-11 21:36:13 +0200113
Denys Vlasenko9c3b84a2010-01-18 01:55:00 +0100114
Denys Vlasenko19158a82010-03-26 14:06:56 +0100115# endif /* !UNICODE_USING_LOCALE */
Denys Vlasenko42a8fd02009-07-11 21:36:13 +0200116
Denys Vlasenko19158a82010-03-26 14:06:56 +0100117#endif /* UNICODE_SUPPORT */
Denys Vlasenko42a8fd02009-07-11 21:36:13 +0200118
Denys Vlasenkobb1dcc92010-02-02 12:45:38 +0100119POP_SAVED_FUNCTION_VISIBILITY
120
Denys Vlasenko42a8fd02009-07-11 21:36:13 +0200121#endif