4
* Copyright (c) 2005, 2006
5
* libchewing Core Team. See ChangeLog for details.
7
* See the file "COPYING" for information on usage and redistribution
13
#include "chewing-utf8-util.h"
15
/* Table of UTF-8 length */
16
static char utf8len_tab[256] =
18
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
19
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
20
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
21
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
22
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /*bogus*/
23
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /*bogus*/
24
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,2,2,
25
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,
28
/* Return length of UTF-8 string */
29
int ueStrLen( char *str )
34
while ( strptr[ 0 ] != '\0' ) {
35
strptr += ueBytesFromChar( strptr[0] );
41
/* Return bytes of a UTF-8 character */
42
int ueBytesFromChar( unsigned char b )
44
return utf8len_tab[ b ];
47
/* Return how many bytes was copied */
48
int ueStrNCpy( char dest[], const char *src, size_t n, int end )
51
char *iter = (char *) src;
52
for ( i = 0; i < n; i++ ) {
53
len += ueBytesFromChar( iter[ len ] );
55
memcpy( dest, iter, len );
56
if ( end == STRNCPY_CLOSE )
61
char *ueStrSeek( char *src, size_t n )
65
for ( i = 0; i < n; i++ ) {
66
iter += ueBytesFromChar( iter[0] );