11#ifndef __UNICODEUTIL_H__
12#define __UNICODEUTIL_H__
32#define DEBUG_UTF_8_ENABLED true
34#define DEBUG_UTF_8_ENABLED false
37#define _CHECK_UTF_8(level, str, len) \
39 const char *__uni_endptr; \
40 if (DEBUG_UTF_8_ENABLED && (str) != NULL && \
41 !g_utf8_validate(str, len, &__uni_endptr)) { \
42 ws_log_utf8(str, len, __uni_endptr); \
46#define WS_UTF_8_CHECK(str, len) \
47 _CHECK_UTF_8(LOG_LEVEL_DEBUG, str, len)
49#define WS_UTF_8_DEBUG_HERE(str, len) \
50 _CHECK_UTF_8(LOG_LEVEL_ECHO, str, len)
53const int ws_utf8_seqlen[256];
64#define ws_utf8_char_len(ch) (ws_utf8_seqlen[(ch)])
78WS_DLL_PUBLIC uint8_t *
107const wchar_t * utf_8to16(
const char *utf8str);
117void utf_8to16_snprintf(TCHAR *utf16buf,
int utf16buf_len,
const char* fmt, ...)
129char * utf_16to8(const
wchar_t *utf16str);
146char **arg_list_utf_16to8(
int argc,
wchar_t *wc_argv[]);
154#define IS_LEAD_SURROGATE(uchar2) \
155 ((uchar2) >= 0xd800 && (uchar2) < 0xdc00)
156#define IS_TRAIL_SURROGATE(uchar2) \
157 ((uchar2) >= 0xdc00 && (uchar2) < 0xe000)
158#define SURROGATE_VALUE(lead, trail) \
159 (((((lead) - 0xd800) << 10) | ((trail) - 0xdc00)) + 0x10000)
Internal memory allocator interface used by the wmem subsystem.
Definition wmem_allocator.h:34
Internal structure representing a wmem-allocated string buffer.
Definition wmem_strbuf.h:38
WS_DLL_PUBLIC uint8_t * ws_utf8_make_valid(wmem_allocator_t *scope, const uint8_t *ptr, ssize_t length)
Validates and sanitizes a UTF-8 byte sequence.
Definition unicode-utils.c:222
WS_DLL_PUBLIC wmem_strbuf_t * ws_utf8_make_valid_strbuf(wmem_allocator_t *scope, const uint8_t *ptr, ssize_t length)
Validates a UTF-8 byte sequence and returns a string buffer.
Definition unicode-utils.c:193