~ubuntu-branches/ubuntu/lucid/libchewing/lucid

« back to all changes in this revision

Viewing changes to src/common/chewing-utf8-util.c

  • Committer: Bazaar Package Importer
  • Author(s): Kanru Chen
  • Date: 2008-12-04 15:34:03 UTC
  • mfrom: (1.1.4 upstream) (2.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20081204153403-l9cksddl1k2e71zy
Tags: 0.3.2-1
* New Upstream Version 
* [5d96bf5] Update watch address
* [351d417] Add Vcs-Git field
* [63cd26a] Add Vcs-Browser field
* [e2a59e2] Conflict with scim-chewing << 0.3.3
* [cd15be8] Change libchewing3-data from all to any since we build
  binary data now.

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
        return utf8len_tab[ b ];
45
45
}
46
46
 
 
47
/* Return byets of a UTF-8 string until n position */
 
48
int ueStrNBytes( const char *str, int n )
 
49
{
 
50
        int i = 0, len = 0;
 
51
        char *iter = (char *) str;
 
52
        for ( i = 0; i < n; i++ ) {
 
53
                len += ueBytesFromChar( iter[ len ] );
 
54
        }
 
55
        return len;
 
56
}
 
57
 
47
58
/* Return how many bytes was copied */
48
59
int ueStrNCpy( char dest[], const char *src, size_t n, int end )
49
60
{
50
 
        int i = 0, len = 0;
51
 
        char *iter = (char *) src;
52
 
        for ( i = 0; i < n; i++ ) {
53
 
                len += ueBytesFromChar( iter[ len ] );
54
 
        }
55
 
        memcpy( dest, iter, len );
 
61
        int len = 0;
 
62
        len = ueStrNBytes( src, n );
 
63
        memcpy( dest, src, len );
56
64
        if ( end == STRNCPY_CLOSE )
57
65
                dest[ len ] = '\0';
58
66
        return len;