00001 #ifndef UTF8_H
00002 #define UTF8_H
00003
00004 #include <stdio.h>
00005 #include <stdarg.h>
00006 #include <stdint.h>
00007 #include <wchar.h>
00008 #include <wctype.h>
00009 #include <stdarg.h>
00010
00011 extern int locale_is_utf8;
00012
00013
00014 #define isutf(c) (((c)&0xC0)!=0x80)
00015
00016 #define UEOF ((uint32_t)-1)
00017
00018
00019 size_t u8_toucs(uint32_t *dest, size_t sz, const char *src, size_t srcsz);
00020
00021
00022 size_t u8_toutf8(char *dest, size_t sz, const uint32_t *src, size_t srcsz);
00023
00024
00025 size_t u8_wc_toutf8(char *dest, uint32_t ch);
00026
00027
00028 size_t u8_offset(const char *str, size_t charnum);
00029
00030
00031 size_t u8_charnum(const char *s, size_t offset);
00032
00033
00034 uint32_t u8_nextchar(const char *s, size_t *i);
00035
00036
00037 uint32_t u8_nextmemchar(const char *s, size_t *i);
00038
00039
00040 void u8_inc(const char *s, size_t *i);
00041
00042
00043 void u8_dec(const char *s, size_t *i);
00044
00045
00046 size_t u8_seqlen(const char *s);
00047
00048
00049 size_t u8_charlen(uint32_t ch);
00050
00051
00052 size_t u8_codingsize(uint32_t *wcstr, size_t n);
00053
00054 char read_escape_control_char(char c);
00055
00056
00057
00058
00059 size_t u8_read_escape_sequence(const char *src, size_t ssz, uint32_t *dest);
00060
00061
00062
00063
00064 int u8_escape_wchar(char *buf, size_t sz, uint32_t ch);
00065
00066
00067 size_t u8_unescape(char *buf, size_t sz, const char *src);
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 size_t u8_escape(char *buf, size_t sz, const char *src, size_t *pi, size_t end,
00085 int escape_quotes, int ascii);
00086
00087
00088 int octal_digit(char c);
00089 int hex_digit(char c);
00090
00091
00092
00093 char *u8_strchr(const char *s, uint32_t ch, size_t *charn);
00094
00095
00096
00097 char *u8_memchr(const char *s, uint32_t ch, size_t sz, size_t *charn);
00098
00099 char *u8_memrchr(const char *s, uint32_t ch, size_t sz);
00100
00101
00102 size_t u8_strlen(const char *s);
00103
00104
00105 size_t u8_strwidth(const char *s);
00106
00107
00108
00109
00110
00111 int u8_is_locale_utf8(const char *locale);
00112
00113
00114
00115
00116 size_t u8_vprintf(const char *fmt, va_list ap);
00117 size_t u8_printf(const char *fmt, ...);
00118
00119
00120 int u8_isvalid(const char *str, size_t length);
00121
00122
00123
00124 int u8_reverse(char *dest, char *src, size_t len);
00125
00126 #endif