#ifndef UNICODE_H
#define UNICODE_H 1
+#if ENABLE_UNICODE_USING_LOCALE
+# include <wchar.h>
+# include <wctype.h>
+#endif
+
+PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
+
enum {
UNICODE_UNKNOWN = 0,
UNICODE_OFF = 1,
UNICODE_ON = 2,
};
-#if !ENABLE_FEATURE_ASSUME_UNICODE
+#define unicode_bidi_isrtl(wc) 0
+#define unicode_bidi_is_neutral_wchar(wc) (wc <= 126 && !isalpha(wc))
-# define unicode_strlen(string) strlen(string)
+#if !ENABLE_UNICODE_SUPPORT
+
+# define unicode_strlen(string) strlen(string)
+# define unicode_strwidth(string) strlen(string)
# define unicode_status UNICODE_OFF
# define init_unicode() ((void)0)
#else
+# if CONFIG_LAST_SUPPORTED_WCHAR < 126 || CONFIG_LAST_SUPPORTED_WCHAR >= 0x30000
+# undef CONFIG_LAST_SUPPORTED_WCHAR
+# define CONFIG_LAST_SUPPORTED_WCHAR 0x2ffff
+# endif
+
+# if CONFIG_LAST_SUPPORTED_WCHAR < 0x300
+# undef ENABLE_UNICODE_COMBINING_WCHARS
+# define ENABLE_UNICODE_COMBINING_WCHARS 0
+# endif
+
+# if CONFIG_LAST_SUPPORTED_WCHAR < 0x1100
+# undef ENABLE_UNICODE_WIDE_WCHARS
+# define ENABLE_UNICODE_WIDE_WCHARS 0
+# endif
+
+# if CONFIG_LAST_SUPPORTED_WCHAR < 0x590
+# undef ENABLE_UNICODE_BIDI_SUPPORT
+# define ENABLE_UNICODE_BIDI_SUPPORT 0
+# endif
+
+/* Number of unicode chars. Falls back to strlen() on invalid unicode */
size_t FAST_FUNC unicode_strlen(const char *string);
+/* Width on terminal */
+size_t FAST_FUNC unicode_strwidth(const char *string);
enum {
UNI_FLAG_PAD = (1 << 0),
};
-typedef struct uni_stat_t {
- unsigned byte_count;
- unsigned unicode_count;
- unsigned unicode_width;
-} uni_stat_t;
//UNUSED: unsigned FAST_FUNC unicode_padding_to_width(unsigned width, const char *src);
//UNUSED: char* FAST_FUNC unicode_conv_to_printable2(uni_stat_t *stats, const char *src, unsigned width, int flags);
char* FAST_FUNC unicode_conv_to_printable(uni_stat_t *stats, const char *src);
char* FAST_FUNC unicode_conv_to_printable_maxwidth(uni_stat_t *stats, const char *src, unsigned maxwidth);
char* FAST_FUNC unicode_conv_to_printable_fixedwidth(uni_stat_t *stats, const char *src, unsigned width);
-# if ENABLE_LOCALE_SUPPORT
+# if ENABLE_UNICODE_USING_LOCALE
-# include <wchar.h>
-# include <wctype.h>
extern uint8_t unicode_status;
void init_unicode(void) FAST_FUNC;
int iswspace(wint_t wc) FAST_FUNC;
int iswalnum(wint_t wc) FAST_FUNC;
int iswpunct(wint_t wc) FAST_FUNC;
+int wcwidth(unsigned ucs) FAST_FUNC;
+# if ENABLE_UNICODE_BIDI_SUPPORT
+# undef unicode_bidi_isrtl
+int unicode_bidi_isrtl(wint_t wc) FAST_FUNC;
+# if ENABLE_UNICODE_NEUTRAL_TABLE
+# undef unicode_bidi_is_neutral_wchar
+int unicode_bidi_is_neutral_wchar(wint_t wc) FAST_FUNC;
+# endif
+# endif
+
+# endif /* !UNICODE_USING_LOCALE */
-# endif /* !LOCALE_SUPPORT */
+#endif /* UNICODE_SUPPORT */
-#endif /* FEATURE_ASSUME_UNICODE */
+POP_SAVED_FUNCTION_VISIBILITY
#endif