blob: 7ab044e17cbf998d66750dabddad33099e225c8f [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 Vlasenkobb1dcc92010-02-02 12:45:38 +01008PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
9
Denys Vlasenko28055022010-01-04 20:49:58 +010010enum {
11 UNICODE_UNKNOWN = 0,
12 UNICODE_OFF = 1,
13 UNICODE_ON = 2,
14};
15
Denys Vlasenko42a8fd02009-07-11 21:36:13 +020016#if !ENABLE_FEATURE_ASSUME_UNICODE
17
Denys Vlasenko9f93d622010-01-24 07:44:03 +010018# define unicode_strlen(string) strlen(string)
Denys Vlasenko28055022010-01-04 20:49:58 +010019# define unicode_status UNICODE_OFF
20# define init_unicode() ((void)0)
Denys Vlasenko42a8fd02009-07-11 21:36:13 +020021
22#else
23
Denys Vlasenko9f93d622010-01-24 07:44:03 +010024size_t FAST_FUNC unicode_strlen(const char *string);
Denys Vlasenkoe17764c2010-01-30 23:16:21 +010025enum {
26 UNI_FLAG_PAD = (1 << 0),
27};
Denys Vlasenkoe17764c2010-01-30 23:16:21 +010028//UNUSED: unsigned FAST_FUNC unicode_padding_to_width(unsigned width, const char *src);
29//UNUSED: char* FAST_FUNC unicode_conv_to_printable2(uni_stat_t *stats, const char *src, unsigned width, int flags);
30char* FAST_FUNC unicode_conv_to_printable(uni_stat_t *stats, const char *src);
31char* FAST_FUNC unicode_conv_to_printable_maxwidth(uni_stat_t *stats, const char *src, unsigned maxwidth);
32char* FAST_FUNC unicode_conv_to_printable_fixedwidth(uni_stat_t *stats, const char *src, unsigned width);
Denys Vlasenkofda8f572009-07-11 22:26:48 +020033
Denys Vlasenko42a8fd02009-07-11 21:36:13 +020034# if ENABLE_LOCALE_SUPPORT
35
36# include <wchar.h>
37# include <wctype.h>
Denys Vlasenko28055022010-01-04 20:49:58 +010038extern uint8_t unicode_status;
39void init_unicode(void) FAST_FUNC;
Denys Vlasenko42a8fd02009-07-11 21:36:13 +020040
41# else
42
Denys Vlasenko9f93d622010-01-24 07:44:03 +010043/* Homegrown Unicode support. It knows only C and Unicode locales. */
Denys Vlasenkofda8f572009-07-11 22:26:48 +020044
Denys Vlasenko42a8fd02009-07-11 21:36:13 +020045# if !ENABLE_FEATURE_CHECK_UNICODE_IN_ENV
Denys Vlasenko28055022010-01-04 20:49:58 +010046# define unicode_status UNICODE_ON
47# define init_unicode() ((void)0)
Denys Vlasenko42a8fd02009-07-11 21:36:13 +020048# else
Denys Vlasenko28055022010-01-04 20:49:58 +010049extern uint8_t unicode_status;
50void init_unicode(void) FAST_FUNC;
Denys Vlasenko42a8fd02009-07-11 21:36:13 +020051# endif
52
53# undef MB_CUR_MAX
54# define MB_CUR_MAX 6
55
56/* Prevent name collisions */
57# define wint_t bb_wint_t
58# define mbstate_t bb_mbstate_t
59# define mbstowcs bb_mbstowcs
60# define wcstombs bb_wcstombs
61# define wcrtomb bb_wcrtomb
62# define iswspace bb_iswspace
63# define iswalnum bb_iswalnum
64# define iswpunct bb_iswpunct
Denys Vlasenko9f93d622010-01-24 07:44:03 +010065# define wcwidth bb_wcwidth
Denys Vlasenko42a8fd02009-07-11 21:36:13 +020066
67typedef int32_t wint_t;
68typedef struct {
69 char bogus;
70} mbstate_t;
71
72size_t mbstowcs(wchar_t *dest, const char *src, size_t n) FAST_FUNC;
73size_t wcstombs(char *dest, const wchar_t *src, size_t n) FAST_FUNC;
74size_t wcrtomb(char *s, wchar_t wc, mbstate_t *ps) FAST_FUNC;
75int iswspace(wint_t wc) FAST_FUNC;
76int iswalnum(wint_t wc) FAST_FUNC;
77int iswpunct(wint_t wc) FAST_FUNC;
78
Denys Vlasenko9c3b84a2010-01-18 01:55:00 +010079
Denys Vlasenkofda8f572009-07-11 22:26:48 +020080# endif /* !LOCALE_SUPPORT */
Denys Vlasenko42a8fd02009-07-11 21:36:13 +020081
Denys Vlasenkofda8f572009-07-11 22:26:48 +020082#endif /* FEATURE_ASSUME_UNICODE */
Denys Vlasenko42a8fd02009-07-11 21:36:13 +020083
Denys Vlasenkobb1dcc92010-02-02 12:45:38 +010084POP_SAVED_FUNCTION_VISIBILITY
85
Denys Vlasenko42a8fd02009-07-11 21:36:13 +020086#endif