blob: f32e565997619deb25b803683f7556e75f81c2de [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 Vlasenko28055022010-01-04 20:49:58 +01008enum {
9 UNICODE_UNKNOWN = 0,
10 UNICODE_OFF = 1,
11 UNICODE_ON = 2,
12};
13
Denys Vlasenko42a8fd02009-07-11 21:36:13 +020014#if !ENABLE_FEATURE_ASSUME_UNICODE
15
Denys Vlasenko9f93d622010-01-24 07:44:03 +010016# define unicode_strlen(string) strlen(string)
Denys Vlasenko28055022010-01-04 20:49:58 +010017# define unicode_status UNICODE_OFF
18# define init_unicode() ((void)0)
Denys Vlasenko42a8fd02009-07-11 21:36:13 +020019
20#else
21
Denys Vlasenko9f93d622010-01-24 07:44:03 +010022size_t FAST_FUNC unicode_strlen(const char *string);
Denys Vlasenkoe17764c2010-01-30 23:16:21 +010023enum {
24 UNI_FLAG_PAD = (1 << 0),
25};
26typedef struct uni_stat_t {
27 unsigned byte_count;
28 unsigned unicode_count;
29 unsigned unicode_width;
30} uni_stat_t;
31//UNUSED: unsigned FAST_FUNC unicode_padding_to_width(unsigned width, const char *src);
32//UNUSED: char* FAST_FUNC unicode_conv_to_printable2(uni_stat_t *stats, const char *src, unsigned width, int flags);
33char* FAST_FUNC unicode_conv_to_printable(uni_stat_t *stats, const char *src);
34char* FAST_FUNC unicode_conv_to_printable_maxwidth(uni_stat_t *stats, const char *src, unsigned maxwidth);
35char* FAST_FUNC unicode_conv_to_printable_fixedwidth(uni_stat_t *stats, const char *src, unsigned width);
Denys Vlasenkofda8f572009-07-11 22:26:48 +020036
Denys Vlasenko42a8fd02009-07-11 21:36:13 +020037# if ENABLE_LOCALE_SUPPORT
38
39# include <wchar.h>
40# include <wctype.h>
Denys Vlasenko28055022010-01-04 20:49:58 +010041extern uint8_t unicode_status;
42void init_unicode(void) FAST_FUNC;
Denys Vlasenko42a8fd02009-07-11 21:36:13 +020043
44# else
45
Denys Vlasenko9f93d622010-01-24 07:44:03 +010046/* Homegrown Unicode support. It knows only C and Unicode locales. */
Denys Vlasenkofda8f572009-07-11 22:26:48 +020047
Denys Vlasenko42a8fd02009-07-11 21:36:13 +020048# if !ENABLE_FEATURE_CHECK_UNICODE_IN_ENV
Denys Vlasenko28055022010-01-04 20:49:58 +010049# define unicode_status UNICODE_ON
50# define init_unicode() ((void)0)
Denys Vlasenko42a8fd02009-07-11 21:36:13 +020051# else
Denys Vlasenko28055022010-01-04 20:49:58 +010052extern uint8_t unicode_status;
53void init_unicode(void) FAST_FUNC;
Denys Vlasenko42a8fd02009-07-11 21:36:13 +020054# endif
55
56# undef MB_CUR_MAX
57# define MB_CUR_MAX 6
58
59/* Prevent name collisions */
60# define wint_t bb_wint_t
61# define mbstate_t bb_mbstate_t
62# define mbstowcs bb_mbstowcs
63# define wcstombs bb_wcstombs
64# define wcrtomb bb_wcrtomb
65# define iswspace bb_iswspace
66# define iswalnum bb_iswalnum
67# define iswpunct bb_iswpunct
Denys Vlasenko9f93d622010-01-24 07:44:03 +010068# define wcwidth bb_wcwidth
Denys Vlasenko42a8fd02009-07-11 21:36:13 +020069
70typedef int32_t wint_t;
71typedef struct {
72 char bogus;
73} mbstate_t;
74
75size_t mbstowcs(wchar_t *dest, const char *src, size_t n) FAST_FUNC;
76size_t wcstombs(char *dest, const wchar_t *src, size_t n) FAST_FUNC;
77size_t wcrtomb(char *s, wchar_t wc, mbstate_t *ps) FAST_FUNC;
78int iswspace(wint_t wc) FAST_FUNC;
79int iswalnum(wint_t wc) FAST_FUNC;
80int iswpunct(wint_t wc) FAST_FUNC;
81
Denys Vlasenko9c3b84a2010-01-18 01:55:00 +010082
Denys Vlasenkofda8f572009-07-11 22:26:48 +020083# endif /* !LOCALE_SUPPORT */
Denys Vlasenko42a8fd02009-07-11 21:36:13 +020084
Denys Vlasenkofda8f572009-07-11 22:26:48 +020085#endif /* FEATURE_ASSUME_UNICODE */
Denys Vlasenko42a8fd02009-07-11 21:36:13 +020086
87#endif