Denys Vlasenko | 42a8fd0 | 2009-07-11 21:36:13 +0200 | [diff] [blame] | 1 | /* 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 Vlasenko | 2f8a460 | 2010-02-19 08:47:17 +0100 | [diff] [blame] | 8 | #if ENABLE_LOCALE_SUPPORT |
| 9 | # include <wchar.h> |
| 10 | # include <wctype.h> |
| 11 | #endif |
| 12 | |
Denys Vlasenko | bb1dcc9 | 2010-02-02 12:45:38 +0100 | [diff] [blame] | 13 | PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN |
| 14 | |
Denys Vlasenko | 2805502 | 2010-01-04 20:49:58 +0100 | [diff] [blame] | 15 | enum { |
| 16 | UNICODE_UNKNOWN = 0, |
| 17 | UNICODE_OFF = 1, |
| 18 | UNICODE_ON = 2, |
| 19 | }; |
| 20 | |
Denys Vlasenko | 42a8fd0 | 2009-07-11 21:36:13 +0200 | [diff] [blame] | 21 | #if !ENABLE_FEATURE_ASSUME_UNICODE |
| 22 | |
Denys Vlasenko | 9f93d62 | 2010-01-24 07:44:03 +0100 | [diff] [blame] | 23 | # define unicode_strlen(string) strlen(string) |
Denys Vlasenko | 2805502 | 2010-01-04 20:49:58 +0100 | [diff] [blame] | 24 | # define unicode_status UNICODE_OFF |
| 25 | # define init_unicode() ((void)0) |
Denys Vlasenko | 42a8fd0 | 2009-07-11 21:36:13 +0200 | [diff] [blame] | 26 | |
| 27 | #else |
| 28 | |
Denys Vlasenko | 9f93d62 | 2010-01-24 07:44:03 +0100 | [diff] [blame] | 29 | size_t FAST_FUNC unicode_strlen(const char *string); |
Denys Vlasenko | e17764c | 2010-01-30 23:16:21 +0100 | [diff] [blame] | 30 | enum { |
| 31 | UNI_FLAG_PAD = (1 << 0), |
| 32 | }; |
Denys Vlasenko | e17764c | 2010-01-30 23:16:21 +0100 | [diff] [blame] | 33 | //UNUSED: unsigned FAST_FUNC unicode_padding_to_width(unsigned width, const char *src); |
| 34 | //UNUSED: char* FAST_FUNC unicode_conv_to_printable2(uni_stat_t *stats, const char *src, unsigned width, int flags); |
| 35 | char* FAST_FUNC unicode_conv_to_printable(uni_stat_t *stats, const char *src); |
| 36 | char* FAST_FUNC unicode_conv_to_printable_maxwidth(uni_stat_t *stats, const char *src, unsigned maxwidth); |
| 37 | char* FAST_FUNC unicode_conv_to_printable_fixedwidth(uni_stat_t *stats, const char *src, unsigned width); |
Denys Vlasenko | fda8f57 | 2009-07-11 22:26:48 +0200 | [diff] [blame] | 38 | |
Denys Vlasenko | 42a8fd0 | 2009-07-11 21:36:13 +0200 | [diff] [blame] | 39 | # if ENABLE_LOCALE_SUPPORT |
| 40 | |
Denys Vlasenko | 2805502 | 2010-01-04 20:49:58 +0100 | [diff] [blame] | 41 | extern uint8_t unicode_status; |
| 42 | void init_unicode(void) FAST_FUNC; |
Denys Vlasenko | 42a8fd0 | 2009-07-11 21:36:13 +0200 | [diff] [blame] | 43 | |
| 44 | # else |
| 45 | |
Denys Vlasenko | 9f93d62 | 2010-01-24 07:44:03 +0100 | [diff] [blame] | 46 | /* Homegrown Unicode support. It knows only C and Unicode locales. */ |
Denys Vlasenko | fda8f57 | 2009-07-11 22:26:48 +0200 | [diff] [blame] | 47 | |
Denys Vlasenko | 42a8fd0 | 2009-07-11 21:36:13 +0200 | [diff] [blame] | 48 | # if !ENABLE_FEATURE_CHECK_UNICODE_IN_ENV |
Denys Vlasenko | 2805502 | 2010-01-04 20:49:58 +0100 | [diff] [blame] | 49 | # define unicode_status UNICODE_ON |
| 50 | # define init_unicode() ((void)0) |
Denys Vlasenko | 42a8fd0 | 2009-07-11 21:36:13 +0200 | [diff] [blame] | 51 | # else |
Denys Vlasenko | 2805502 | 2010-01-04 20:49:58 +0100 | [diff] [blame] | 52 | extern uint8_t unicode_status; |
| 53 | void init_unicode(void) FAST_FUNC; |
Denys Vlasenko | 42a8fd0 | 2009-07-11 21:36:13 +0200 | [diff] [blame] | 54 | # 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 Vlasenko | 9f93d62 | 2010-01-24 07:44:03 +0100 | [diff] [blame] | 68 | # define wcwidth bb_wcwidth |
Denys Vlasenko | 42a8fd0 | 2009-07-11 21:36:13 +0200 | [diff] [blame] | 69 | |
| 70 | typedef int32_t wint_t; |
| 71 | typedef struct { |
| 72 | char bogus; |
| 73 | } mbstate_t; |
| 74 | |
| 75 | size_t mbstowcs(wchar_t *dest, const char *src, size_t n) FAST_FUNC; |
| 76 | size_t wcstombs(char *dest, const wchar_t *src, size_t n) FAST_FUNC; |
| 77 | size_t wcrtomb(char *s, wchar_t wc, mbstate_t *ps) FAST_FUNC; |
| 78 | int iswspace(wint_t wc) FAST_FUNC; |
| 79 | int iswalnum(wint_t wc) FAST_FUNC; |
| 80 | int iswpunct(wint_t wc) FAST_FUNC; |
| 81 | |
Denys Vlasenko | 9c3b84a | 2010-01-18 01:55:00 +0100 | [diff] [blame] | 82 | |
Denys Vlasenko | fda8f57 | 2009-07-11 22:26:48 +0200 | [diff] [blame] | 83 | # endif /* !LOCALE_SUPPORT */ |
Denys Vlasenko | 42a8fd0 | 2009-07-11 21:36:13 +0200 | [diff] [blame] | 84 | |
Denys Vlasenko | fda8f57 | 2009-07-11 22:26:48 +0200 | [diff] [blame] | 85 | #endif /* FEATURE_ASSUME_UNICODE */ |
Denys Vlasenko | 42a8fd0 | 2009-07-11 21:36:13 +0200 | [diff] [blame] | 86 | |
Denys Vlasenko | bb1dcc9 | 2010-02-02 12:45:38 +0100 | [diff] [blame] | 87 | POP_SAVED_FUNCTION_VISIBILITY |
| 88 | |
Denys Vlasenko | 42a8fd0 | 2009-07-11 21:36:13 +0200 | [diff] [blame] | 89 | #endif |