unichar.c revision 2a7605bb97dc9ed8accf2537fad1073a5fc5ff48
/* Copyright (C) 2005-2007 Timo Sirainen */
#include "lib.h"
#include "buffer.h"
#include "unichar.h"
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,
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
};
{
unsigned int len = 0;
return len;
}
{
chr_r);
}
{
unsigned int i, len;
int ret;
if (*input < 0x80) {
return 1;
}
/* first byte has len highest bits set, followed by zero bit.
the rest of the bits are used as the highest bits of the value. */
switch (len) {
case 2:
chr &= 0x1f;
break;
case 3:
chr &= 0x0f;
break;
case 4:
chr &= 0x07;
break;
case 5:
chr &= 0x03;
break;
case 6:
chr &= 0x01;
break;
default:
/* only 7bit chars should have len==1 */
return -1;
}
ret = 1;
else {
/* check first if the input is invalid before returning 0 */
ret = 0;
}
/* the following bytes must all be 10xxxxxx */
for (i = 1; i < len; i++) {
chr <<= 6;
}
return ret;
}
{
while (*input != '\0') {
/* invalid input */
return -1;
}
}
return 0;
}
{
}
{
unsigned char first;
int bitpos;
if (chr < 0x80) {
return;
}
/* 110xxxxx */
bitpos = 6;
/* 1110xxxx */
/* 11110xxx */
/* 111110xx */
} else {
/* 1111110x */
}
do {
bitpos -= 6;
} while (bitpos > 0);
}
{
unsigned int len = 0;
size_t i;
i += uni_utf8_char_bytes(input[i]);
if (i > size)
break;
len++;
}
return len;
}