From: tomo Date: Sat, 9 Aug 2003 08:08:52 +0000 (+0000) Subject: (chise_char_id_parse_c_string): New function. X-Git-Tag: r0_1_1-pre1~9 X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0638ce2087ab421f9da1827aab65b3520cf1ca0e;p=chise%2Flibchise.git (chise_char_id_parse_c_string): New function. (chise_dt_get_char): Use `chise_char_id_parse_c_string'. (chise_ft_iterate): New function. --- diff --git a/chise.c b/chise.c index 3397991..63c104b 100644 --- a/chise.c +++ b/chise.c @@ -22,6 +22,75 @@ strnlen (register const char *s, register int maxlen) #define xzero(lvalue) ((void) memset (&(lvalue), '\0', sizeof (lvalue))) +CHISE_Char_ID +chise_char_id_parse_c_string (unsigned char *str, int len) +{ + int i = 0; + + if ( (len >= 2) && (str[i++] == '?') ) + { + unsigned char c = str[i++]; + int counter; + CHISE_Char_ID cid; + + if (c == '\\') + { + if (len < 3) + return -1; + c = str[i++]; + if (c == '^') + { + if (len < 4) + return -1; + c = str[i++]; + if (c == '?') + return 0x7F; + else + return c & (0x80 | 0x1F); + } + } + if ( c < 0xC0 ) + { + cid = c; + counter = 0; + } + else if ( c < 0xE0 ) + { + cid = c & 0x1f; + counter = 1; + } + else if ( c < 0xF0 ) + { + cid = c & 0x0f; + counter = 2; + } + else if ( c < 0xF8 ) + { + cid = c & 0x07; + counter = 3; + } + else if ( c < 0xFC ) + { + cid = c & 0x03; + counter = 4; + } + else + { + cid = c & 0x01; + counter = 5; + } + + if (counter + 2 <= len) + { + int j; + + for (j = 0; j < counter; j++) + cid = (cid << 6) | (str[j + i] & 0x3F); + return cid; + } + } + return -1; +} int chise_open_data_source (CHISE_DS *ds, CHISE_DS_Type type, char *location) @@ -74,70 +143,8 @@ chise_dt_get_char (CHISE_Decoding_Table *db, int code_point) unsigned char *str = (unsigned char *)chise_value_data (&valdatum); int len = strnlen (str, chise_value_size (&valdatum)); - int i = 0; - if ( (len >= 2) && (str[i++] == '?') ) - { - unsigned char c = str[i++]; - int counter; - CHISE_Char_ID cid; - - if (c == '\\') - { - if (len < 3) - return -1; - c = str[i++]; - if (c == '^') - { - if (len < 4) - return -1; - c = str[i++]; - if (c == '?') - return 0x7F; - else - return c & (0x80 | 0x1F); - } - } - if ( c < 0xC0 ) - { - cid = c; - counter = 0; - } - else if ( c < 0xE0 ) - { - cid = c & 0x1f; - counter = 1; - } - else if ( c < 0xF0 ) - { - cid = c & 0x0f; - counter = 2; - } - else if ( c < 0xF8 ) - { - cid = c & 0x07; - counter = 3; - } - else if ( c < 0xFC ) - { - cid = c & 0x03; - counter = 4; - } - else - { - cid = c & 0x01; - counter = 5; - } - - if (counter + 2 <= len) - { - int j; - - for (j = 0; j < counter; j++) - cid = (cid << 6) | (str[j + i] & 0x3F); - return cid; - } - } + return chise_char_id_parse_c_string (str, len); } return -1; } @@ -280,6 +287,33 @@ int chise_ft_get_value (CHISE_Feature_Table *db, chise_get_attribute_table (db, key_buf, valdatum); } +void +chise_ft_iterate (CHISE_Feature_Table *dbp, + int (*func) (CHISE_Feature_Table *db, + CHISE_Char_ID cid, CHISE_Value *valdatum)) +{ + DBT keydatum, valdatum; + DBC *dbcp; + int status; + + xzero (keydatum); + xzero (valdatum); + + status = dbp->cursor (dbp, NULL, &dbcp, 0); + for (status = dbcp->c_get (dbcp, &keydatum, &valdatum, DB_FIRST); + status == 0; + status = dbcp->c_get (dbcp, &keydatum, &valdatum, DB_NEXT)) + { + unsigned char *key_str = (unsigned char *)keydatum.data; + int key_len = strnlen (key_str, keydatum.size); + CHISE_Char_ID key = chise_char_id_parse_c_string (key_str, key_len); + int ret; + + if (ret = func (dbp, key, &valdatum)) + break; + } + dbcp->c_close (dbcp); +} int chise_open_attribute_table (CHISE_Attribute_Table **db,