From 0638ce2087ab421f9da1827aab65b3520cf1ca0e Mon Sep 17 00:00:00 2001 From: tomo Date: Sat, 9 Aug 2003 08:08:52 +0000 Subject: [PATCH] (chise_char_id_parse_c_string): New function. (chise_dt_get_char): Use `chise_char_id_parse_c_string'. (chise_ft_iterate): New function. --- chise.c | 160 ++++++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 97 insertions(+), 63 deletions(-) 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, -- 1.7.10.4