From 553bb7165ab4ce49ea0411804613ba9950d83aac Mon Sep 17 00:00:00 2001 From: tomo Date: Thu, 7 Aug 2003 00:41:54 +0000 Subject: [PATCH] (chise_ft_get_value): Use escape forms for some special characters. --- chise.c | 111 +++++++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 86 insertions(+), 25 deletions(-) diff --git a/chise.c b/chise.c index c24fd8e..3397991 100644 --- a/chise.c +++ b/chise.c @@ -170,49 +170,110 @@ int chise_ft_get_value (CHISE_Feature_Table *db, unsigned char key_buf[8]; key_buf[0] = '?'; - if (cid <= 0x7f) + if (cid == '\t') + { + key_buf[1] = '\\'; + key_buf[2] = 't'; + key_buf[3] = '\0'; + } + else if (cid == '\n') + { + key_buf[1] = '\\'; + key_buf[2] = 'n'; + key_buf[3] = '\0'; + } + else if (cid == '\r') + { + key_buf[1] = '\\'; + key_buf[2] = 'r'; + key_buf[3] = '\0'; + } + else if (cid == 0x1C) + { + key_buf[1] = '\\'; + key_buf[2] = '^'; + key_buf[3] = '\\'; + key_buf[4] = '\\'; + key_buf[5] = '\0'; + } + else if (cid <= 0x1F) + { + key_buf[1] = '\\'; + key_buf[2] = '^'; + key_buf[3] = '@' + cid; + key_buf[4] = '\0'; + } + else if ( (cid == ' ') || (cid == '"') || + (cid == '#') || (cid == '\'') || + (cid == '(') || (cid == ')') || + (cid == ',') || (cid == '.') || + (cid == ';') || (cid == '?') || + (cid == '[') || (cid == '\\') || + (cid == ']') || (cid == '`') ) + { + key_buf[1] = '\\'; + key_buf[2] = cid; + key_buf[3] = '\0'; + } + else if (cid <= 0x7E) { key_buf[1] = cid; key_buf[2] = '\0'; } - else if (cid <= 0x7ff) + else if (cid == 0x7F) + { + key_buf[1] = '\\'; + key_buf[2] = '^'; + key_buf[3] = '?'; + key_buf[4] = '\0'; + } + else if (cid <= 0x9F) + { + key_buf[1] = '\\'; + key_buf[2] = '^'; + key_buf[3] = ((cid + '@') >> 6) | 0xC0; + key_buf[4] = ((cid + '@') & 0x3F) | 0x80; + key_buf[5] = '\0'; + + } + else if (cid <= 0x7FF) { - key_buf[1] = (cid >> 6) | 0xc0; - key_buf[2] = (cid & 0x3f) | 0x80; + key_buf[1] = (cid >> 6) | 0xC0; + key_buf[2] = (cid & 0x3F) | 0x80; key_buf[3] = '\0'; } - else if (cid <= 0xffff) + else if (cid <= 0xFFFF) { - key_buf[1] = (cid >> 12) | 0xe0; - key_buf[2]= ((cid >> 6) & 0x3f) | 0x80; - key_buf[3]= (cid & 0x3f) | 0x80; + key_buf[1] = (cid >> 12) | 0xE0; + key_buf[2]= ((cid >> 6) & 0x3F) | 0x80; + key_buf[3]= (cid & 0x3F) | 0x80; key_buf[4] = '\0'; } - else if (cid <= 0x1fffff) + else if (cid <= 0x1FFFFF) { - key_buf[1]= (cid >> 18) | 0xf0; - key_buf[2]= ((cid >> 12) & 0x3f) | 0x80; - key_buf[3]= ((cid >> 6) & 0x3f) | 0x80; - key_buf[4]= (cid & 0x3f) | 0x80; + key_buf[1]= (cid >> 18) | 0xF0; + key_buf[2]= ((cid >> 12) & 0x3F) | 0x80; + key_buf[3]= ((cid >> 6) & 0x3F) | 0x80; + key_buf[4]= (cid & 0x3F) | 0x80; key_buf[5] = '\0'; } - else if (cid <= 0x3ffffff) + else if (cid <= 0x3FFFFFF) { - key_buf[1]= (cid >> 24) | 0xf8; - key_buf[2]= ((cid >> 18) & 0x3f) | 0x80; - key_buf[3]= ((cid >> 12) & 0x3f) | 0x80; - key_buf[4]= ((cid >> 6) & 0x3f) | 0x80; - key_buf[5]= (cid & 0x3f) | 0x80; + key_buf[1]= (cid >> 24) | 0xF8; + key_buf[2]= ((cid >> 18) & 0x3F) | 0x80; + key_buf[3]= ((cid >> 12) & 0x3F) | 0x80; + key_buf[4]= ((cid >> 6) & 0x3F) | 0x80; + key_buf[5]= (cid & 0x3F) | 0x80; key_buf[6] = '\0'; } else { - key_buf[1]= (cid >> 30) | 0xfc; - key_buf[2]= ((cid >> 24) & 0x3f) | 0x80; - key_buf[3]= ((cid >> 18) & 0x3f) | 0x80; - key_buf[4]= ((cid >> 12) & 0x3f) | 0x80; - key_buf[5]= ((cid >> 6) & 0x3f) | 0x80; - key_buf[6]= (cid & 0x3f) | 0x80; + key_buf[1]= (cid >> 30) | 0xFC; + key_buf[2]= ((cid >> 24) & 0x3F) | 0x80; + key_buf[3]= ((cid >> 18) & 0x3F) | 0x80; + key_buf[4]= ((cid >> 12) & 0x3F) | 0x80; + key_buf[5]= ((cid >> 6) & 0x3F) | 0x80; + key_buf[6]= (cid & 0x3F) | 0x80; key_buf[7] = '\0'; } return -- 1.7.10.4