From: MORIOKA Tomohiko Date: Fri, 12 Apr 2013 09:35:26 +0000 (+0900) Subject: - Don't include . X-Git-Url: http://git.chise.org/gitweb/?a=commitdiff_plain;h=322b55a7656acb0c455ce7fc03e98d056f1e56f8;p=chise%2Fconcord.git - Don't include . - Include "cos-i.h". (cos_utf8_encode_char): Renamed from `cos_encode_char_as_utf8'. (cos_utf8_print_char): New function. --- diff --git a/print.c b/print.c index 9a0e761..2698189 100644 --- a/print.c +++ b/print.c @@ -16,11 +16,11 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#include #include "cos-print.h" +#include "cos-i.h" int -cos_encode_char_as_utf8 (int cid, unsigned char *dest, size_t size) +cos_utf8_encode_char (int cid, unsigned char *dest, size_t size) { int i = 0; @@ -106,3 +106,131 @@ cos_encode_char_as_utf8 (int cid, unsigned char *dest, size_t size) return -1; } } + +int +cos_utf8_print_char (COS_object character, unsigned char *dest, size_t size) +{ + int cid = cos_char_id (character); + int i = 0; + + dest[i++] = '?'; + if (cid == '\t') + { + dest[i++] = '\\'; + dest[i++] = 't'; + dest[i] = '\0'; + return i; + } + else if (cid == '\n') + { + dest[i++] = '\\'; + dest[i++] = 'n'; + dest[i] = '\0'; + return i; + } + else if (cid == '\r') + { + dest[i++] = '\\'; + dest[i++] = 'r'; + dest[i] = '\0'; + return i; + } + else if (cid == 0x1C) + { + dest[i++] = '\\'; + dest[i++] = '^'; + dest[i++] = '\\'; + dest[i++] = '\\'; + dest[i] = '\0'; + return i; + } + else if (cid <= 0x1F) + { + dest[i++] = '\\'; + dest[i++] = '^'; + dest[i++] = '@' + cid; + dest[i] = '\0'; + return i; + } + else if ( (cid == ' ') || (cid == '"') || + (cid == '#') || (cid == '\'') || + (cid == '(') || (cid == ')') || + (cid == ',') || (cid == '.') || + (cid == ';') || (cid == '?') || + (cid == '[') || (cid == '\\') || + (cid == ']') || (cid == '`') ) + { + dest[i++] = '\\'; + dest[i++] = cid; + dest[i] = '\0'; + return i; + } + else if (cid <= 0x7E) + { + dest[i++] = cid; + dest[i] = '\0'; + return i; + } + else if (cid == 0x7F) + { + dest[i++] = '\\'; + dest[i++] = '^'; + dest[i++] = '?'; + dest[i] = '\0'; + return i; + } + else if (cid <= 0x9F) + { + dest[i++] = '\\'; + dest[i++] = '^'; + dest[i++] = ((cid + '@') >> 6) | 0xC0; + dest[i++] = ((cid + '@') & 0x3F) | 0x80; + dest[i] = '\0'; + return i; + } + else if (cid <= 0x7FF) + { + dest[i++] = (cid >> 6) | 0xC0; + dest[i++] = (cid & 0x3F) | 0x80; + dest[i] = '\0'; + return i; + } + else if (cid <= 0xFFFF) + { + dest[i++] = (cid >> 12) | 0xE0; + dest[i++]= ((cid >> 6) & 0x3F) | 0x80; + dest[i++]= (cid & 0x3F) | 0x80; + dest[i] = '\0'; + return i; + } + else if (cid <= 0x1FFFFF) + { + dest[i++]= (cid >> 18) | 0xF0; + dest[i++]= ((cid >> 12) & 0x3F) | 0x80; + dest[i++]= ((cid >> 6) & 0x3F) | 0x80; + dest[i++]= (cid & 0x3F) | 0x80; + dest[i] = '\0'; + return i; + } + else if (cid <= 0x3FFFFFF) + { + dest[i++]= (cid >> 24) | 0xF8; + dest[i++]= ((cid >> 18) & 0x3F) | 0x80; + dest[i++]= ((cid >> 12) & 0x3F) | 0x80; + dest[i++]= ((cid >> 6) & 0x3F) | 0x80; + dest[i++]= (cid & 0x3F) | 0x80; + dest[i] = '\0'; + return i; + } + else + { + dest[i++]= (cid >> 30) | 0xFC; + dest[i++]= ((cid >> 24) & 0x3F) | 0x80; + dest[i++]= ((cid >> 18) & 0x3F) | 0x80; + dest[i++]= ((cid >> 12) & 0x3F) | 0x80; + dest[i++]= ((cid >> 6) & 0x3F) | 0x80; + dest[i++]= (cid & 0x3F) | 0x80; + dest[i] = '\0'; + return i; + } +}