unichar.c revision 576e0be735a03d1fa6e82a120aba03adabdcda66
33c6d5807b449463e9b81db5ec99fe027cc1b984Timo Sirainen/* Copyright (c) 2005-2009 Dovecot authors, see the included COPYING file */
08d6658a4e2ec8104cd1307f6baa75fdb07a24f8Mark Washenbergerstatic const uint8_t utf8_non1_bytes[256 - 192 - 2] = {
33c6d5807b449463e9b81db5ec99fe027cc1b984Timo Sirainen 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
33c6d5807b449463e9b81db5ec99fe027cc1b984Timo Sirainen 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,6,6,1,1
78ed6a99e980228a75fa59cff84327dc0ea82857Timo Sirainenconst uint8_t *const uni_utf8_non1_bytes = utf8_non1_bytes;
33c6d5807b449463e9b81db5ec99fe027cc1b984Timo Sirainen unsigned int len = 0;
73bfdbe28c2ce6d143eadf0bab8ccfbe4cab0faeTimo Sirainenint uni_utf8_get_char(const char *input, unichar_t *chr_r)
33c6d5807b449463e9b81db5ec99fe027cc1b984Timo Sirainen return uni_utf8_get_char_n((const unsigned char *)input, (size_t)-1,
33c6d5807b449463e9b81db5ec99fe027cc1b984Timo Sirainenint uni_utf8_get_char_n(const void *_input, size_t max_len, unichar_t *chr_r)
33c6d5807b449463e9b81db5ec99fe027cc1b984Timo Sirainen unsigned int i, len;
50782de8a9d5ebe11ee61496b4e695a1d3875230Timo Sirainen /* first byte has len highest bits set, followed by zero bit.
1e3a608d8d0e08cb7d549718fbfbcc148fdb236fTimo Sirainen the rest of the bits are used as the highest bits of the value. */
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen /* only 7bit chars should have len==1 */
ret = 0;
return ret;
unsigned char first;
int bitpos;
} while (bitpos > 0);
unsigned int len = 0;
size_t i;
if (i > size)
len++;
return len;
unsigned int idx;
return chr;
return chr;
unsigned int idx;
return FALSE;
return FALSE;
return TRUE;
unsigned int idx;
return FALSE;
return FALSE;
return TRUE;
unsigned int bytes;
int ret = 0;
return ret;
return len;
for (i = 0; i < size;) {
goto broken;
i += len;
return TRUE;
while (i < size) {
if (len == 0) {
i += len;
return FALSE;