blob: e9e2bd14a7dda49de36c90714fd8b84c92762c05 [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
Tomas Heinrich11bcf4b2010-06-01 08:33:18 +020026# define unicode_strlen(string) strlen(string)
27# define unicode_strwidth(string) strlen(string)
Denys Vlasenko28055022010-01-04 20:49:58 +010028# define unicode_status UNICODE_OFF
29# define init_unicode() ((void)0)
Denys Vlasenko42a8fd02009-07-11 21:36:13 +020030
31#else
32
Tomas Heinrichc5c006c2010-03-18 18:35:37 +010033# if CONFIG_LAST_SUPPORTED_WCHAR < 126 || CONFIG_LAST_SUPPORTED_WCHAR >= 0x30000
Denys Vlasenko26e2c1d2010-05-16 21:15:03 +020034# undef CONFIG_LAST_SUPPORTED_WCHAR
35# define CONFIG_LAST_SUPPORTED_WCHAR 0x2ffff
Tomas Heinrichc5c006c2010-03-18 18:35:37 +010036# endif
37
Denys Vlasenko26e2c1d2010-05-16 21:15:03 +020038# if CONFIG_LAST_SUPPORTED_WCHAR < 0x300
Tomas Heinrichb8909c52010-05-16 20:46:53 +020039# undef ENABLE_UNICODE_COMBINING_WCHARS
40# define ENABLE_UNICODE_COMBINING_WCHARS 0
41# endif
42
Denys Vlasenko26e2c1d2010-05-16 21:15:03 +020043# if CONFIG_LAST_SUPPORTED_WCHAR < 0x1100
Tomas Heinrichb8909c52010-05-16 20:46:53 +020044# undef ENABLE_UNICODE_WIDE_WCHARS
45# define ENABLE_UNICODE_WIDE_WCHARS 0
46# endif
47
Denys Vlasenko26e2c1d2010-05-16 21:15:03 +020048# if CONFIG_LAST_SUPPORTED_WCHAR < 0x590
Tomas Heinrichc5c006c2010-03-18 18:35:37 +010049# undef ENABLE_UNICODE_BIDI_SUPPORT
50# define ENABLE_UNICODE_BIDI_SUPPORT 0
51# endif
52
Tomas Heinrich11bcf4b2010-06-01 08:33:18 +020053/* Number of unicode chars. Falls back to strlen() on invalid unicode */
Denys Vlasenko9f93d622010-01-24 07:44:03 +010054size_t FAST_FUNC unicode_strlen(const char *string);
Tomas Heinrich11bcf4b2010-06-01 08:33:18 +020055/* Width on terminal */
56size_t FAST_FUNC unicode_strwidth(const char *string);
Denys Vlasenkoe17764c2010-01-30 23:16:21 +010057enum {
58 UNI_FLAG_PAD = (1 << 0),
59};
Denys Vlasenkoe17764c2010-01-30 23:16:21 +010060//UNUSED: unsigned FAST_FUNC unicode_padding_to_width(unsigned width, const char *src);
61//UNUSED: char* FAST_FUNC unicode_conv_to_printable2(uni_stat_t *stats, const char *src, unsigned width, int flags);
62char* FAST_FUNC unicode_conv_to_printable(uni_stat_t *stats, const char *src);
63char* FAST_FUNC unicode_conv_to_printable_maxwidth(uni_stat_t *stats, const char *src, unsigned maxwidth);
64char* FAST_FUNC unicode_conv_to_printable_fixedwidth(uni_stat_t *stats, const char *src, unsigned width);
Denys Vlasenkofda8f572009-07-11 22:26:48 +020065
Denys Vlasenko19158a82010-03-26 14:06:56 +010066# if ENABLE_UNICODE_USING_LOCALE
Denys Vlasenko42a8fd02009-07-11 21:36:13 +020067
Denys Vlasenko28055022010-01-04 20:49:58 +010068extern uint8_t unicode_status;
69void init_unicode(void) FAST_FUNC;
Denys Vlasenko42a8fd02009-07-11 21:36:13 +020070
71# else
72
Denys Vlasenko9f93d622010-01-24 07:44:03 +010073/* Homegrown Unicode support. It knows only C and Unicode locales. */
Denys Vlasenkofda8f572009-07-11 22:26:48 +020074
Denys Vlasenko42a8fd02009-07-11 21:36:13 +020075# if !ENABLE_FEATURE_CHECK_UNICODE_IN_ENV
Denys Vlasenko28055022010-01-04 20:49:58 +010076# define unicode_status UNICODE_ON
77# define init_unicode() ((void)0)
Denys Vlasenko42a8fd02009-07-11 21:36:13 +020078# else
Denys Vlasenko28055022010-01-04 20:49:58 +010079extern uint8_t unicode_status;
80void init_unicode(void) FAST_FUNC;
Denys Vlasenko42a8fd02009-07-11 21:36:13 +020081# endif
82
83# undef MB_CUR_MAX
84# define MB_CUR_MAX 6
85
86/* Prevent name collisions */
87# define wint_t bb_wint_t
88# define mbstate_t bb_mbstate_t
89# define mbstowcs bb_mbstowcs
90# define wcstombs bb_wcstombs
91# define wcrtomb bb_wcrtomb
92# define iswspace bb_iswspace
93# define iswalnum bb_iswalnum
94# define iswpunct bb_iswpunct
Denys Vlasenko9f93d622010-01-24 07:44:03 +010095# define wcwidth bb_wcwidth
Denys Vlasenko42a8fd02009-07-11 21:36:13 +020096
97typedef int32_t wint_t;
98typedef struct {
99 char bogus;
100} mbstate_t;
101
102size_t mbstowcs(wchar_t *dest, const char *src, size_t n) FAST_FUNC;
103size_t wcstombs(char *dest, const wchar_t *src, size_t n) FAST_FUNC;
104size_t wcrtomb(char *s, wchar_t wc, mbstate_t *ps) FAST_FUNC;
105int iswspace(wint_t wc) FAST_FUNC;
106int iswalnum(wint_t wc) FAST_FUNC;
107int iswpunct(wint_t wc) FAST_FUNC;
Tomas Heinrichb8909c52010-05-16 20:46:53 +0200108int wcwidth(unsigned ucs) FAST_FUNC;
Tomas Heinrichc5c006c2010-03-18 18:35:37 +0100109# if ENABLE_UNICODE_BIDI_SUPPORT
Tomas Heinrichaa167552010-03-26 13:13:24 +0100110# undef unicode_bidi_isrtl
111int unicode_bidi_isrtl(wint_t wc) FAST_FUNC;
112# if ENABLE_UNICODE_NEUTRAL_TABLE
113# undef unicode_bidi_is_neutral_wchar
114int unicode_bidi_is_neutral_wchar(wint_t wc) FAST_FUNC;
115# endif
Tomas Heinrichc5c006c2010-03-18 18:35:37 +0100116# endif
Denys Vlasenko42a8fd02009-07-11 21:36:13 +0200117
Denys Vlasenko9c3b84a2010-01-18 01:55:00 +0100118
Denys Vlasenko19158a82010-03-26 14:06:56 +0100119# endif /* !UNICODE_USING_LOCALE */
Denys Vlasenko42a8fd02009-07-11 21:36:13 +0200120
Denys Vlasenko19158a82010-03-26 14:06:56 +0100121#endif /* UNICODE_SUPPORT */
Denys Vlasenko42a8fd02009-07-11 21:36:13 +0200122
Denys Vlasenkobb1dcc92010-02-02 12:45:38 +0100123POP_SAVED_FUNCTION_VISIBILITY
124
Denys Vlasenko42a8fd02009-07-11 21:36:13 +0200125#endif