Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib/unichar.h @ 4899:c98008a7e9b7 HEAD
Added unichar_t UCS-4 type and some ucs4/utf8 functions.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Wed, 13 Dec 2006 15:45:16 +0200 |
parents | |
children | 8101787cdd1c |
rev | line source |
---|---|
4899
c98008a7e9b7
Added unichar_t UCS-4 type and some ucs4/utf8 functions.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1 #ifndef __UNICHAR_H |
c98008a7e9b7
Added unichar_t UCS-4 type and some ucs4/utf8 functions.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
2 #define __UNICHAR_H |
c98008a7e9b7
Added unichar_t UCS-4 type and some ucs4/utf8 functions.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
3 |
c98008a7e9b7
Added unichar_t UCS-4 type and some ucs4/utf8 functions.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
4 typedef uint32_t unichar_t; |
c98008a7e9b7
Added unichar_t UCS-4 type and some ucs4/utf8 functions.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
5 |
c98008a7e9b7
Added unichar_t UCS-4 type and some ucs4/utf8 functions.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
6 extern const char *const uni_utf8_skip; |
c98008a7e9b7
Added unichar_t UCS-4 type and some ucs4/utf8 functions.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
7 |
c98008a7e9b7
Added unichar_t UCS-4 type and some ucs4/utf8 functions.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
8 /* Returns number of characters in a NUL-terminated unicode string */ |
c98008a7e9b7
Added unichar_t UCS-4 type and some ucs4/utf8 functions.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
9 unsigned int uni_strlen(const unichar_t *str); |
c98008a7e9b7
Added unichar_t UCS-4 type and some ucs4/utf8 functions.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
10 /* Translates UTF-8 input to UCS-4 output. Returns 0 if ok, -1 if input was |
c98008a7e9b7
Added unichar_t UCS-4 type and some ucs4/utf8 functions.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
11 invalid */ |
c98008a7e9b7
Added unichar_t UCS-4 type and some ucs4/utf8 functions.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
12 int uni_utf8_to_ucs4(const char *input, buffer_t *output); |
c98008a7e9b7
Added unichar_t UCS-4 type and some ucs4/utf8 functions.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
13 /* Translates UCS-4 input to UTF-8 output. */ |
c98008a7e9b7
Added unichar_t UCS-4 type and some ucs4/utf8 functions.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
14 void uni_ucs4_to_utf8(const unichar_t *input, size_t len, buffer_t *output); |
c98008a7e9b7
Added unichar_t UCS-4 type and some ucs4/utf8 functions.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
15 |
c98008a7e9b7
Added unichar_t UCS-4 type and some ucs4/utf8 functions.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
16 /* Returns the next UTF-8 character, or (unichar_t)-1 for invalid input and |
c98008a7e9b7
Added unichar_t UCS-4 type and some ucs4/utf8 functions.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
17 (unichar_t)-2 for incomplete trailing character. */ |
c98008a7e9b7
Added unichar_t UCS-4 type and some ucs4/utf8 functions.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
18 unichar_t uni_utf8_get_char(const char *input); |
c98008a7e9b7
Added unichar_t UCS-4 type and some ucs4/utf8 functions.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
19 unichar_t uni_utf8_get_char_len(const unsigned char *input, size_t max_len); |
c98008a7e9b7
Added unichar_t UCS-4 type and some ucs4/utf8 functions.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
20 /* Returns UTF-8 string length with maximum input size. */ |
c98008a7e9b7
Added unichar_t UCS-4 type and some ucs4/utf8 functions.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
21 unsigned int uni_utf8_strlen_n(const void *input, size_t size); |
c98008a7e9b7
Added unichar_t UCS-4 type and some ucs4/utf8 functions.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
22 |
c98008a7e9b7
Added unichar_t UCS-4 type and some ucs4/utf8 functions.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
23 #define uni_utf8_next_char(p) \ |
c98008a7e9b7
Added unichar_t UCS-4 type and some ucs4/utf8 functions.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
24 ((p) + uni_utf8_skip[*(const uint8_t *)(p)]) |
c98008a7e9b7
Added unichar_t UCS-4 type and some ucs4/utf8 functions.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
25 |
c98008a7e9b7
Added unichar_t UCS-4 type and some ucs4/utf8 functions.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
26 #endif |