From: MORIOKA Tomohiko Date: Thu, 4 Apr 2013 01:47:22 +0000 (+0900) Subject: New files. X-Git-Url: http://git.chise.org/gitweb/?a=commitdiff_plain;h=2a9f3267270e17def505e553192d7a3f74add9d3;p=chise%2Fconcord.git New files. --- diff --git a/cos-print.h b/cos-print.h new file mode 100644 index 0000000..7eba564 --- /dev/null +++ b/cos-print.h @@ -0,0 +1,41 @@ +/* Print functions of CONCORD Object System + + Copyright (C) 2013 MORIOKA Tomohiko + This file is part of the CONCORD Library. + + The CONCORD Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The CONCORD Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the CONCORD Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#ifndef _COS_PRINT_H +#define _COS_PRINT_H + +#ifdef __cplusplus +extern "C" { +#endif +#if 0 +} +#endif + +int +cos_encode_char_as_utf8 (int cid, unsigned char *dest, size_t size); + +#if 0 +{ +#endif +#ifdef __cplusplus +} +#endif + +#endif /* !_COS_PRINT_H */ diff --git a/print.c b/print.c new file mode 100644 index 0000000..9a0e761 --- /dev/null +++ b/print.c @@ -0,0 +1,108 @@ +/* Copyright (C) 2013 MORIOKA Tomohiko + This file is part of the CONCORD Library. + + The CONCORD Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The CONCORD Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the CONCORD Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include "cos-print.h" + +int +cos_encode_char_as_utf8 (int cid, unsigned char *dest, size_t size) +{ + int i = 0; + + if (cid <= 0x7F) + { + if (size >= 2) + { + dest[i++] = cid; + dest[i] = '\0'; + return i; + } + else + return -1; + } + else if (cid <= 0x7FF) + { + if (size >= 3) + { + dest[i++] = (cid >> 6) | 0xC0; + dest[i++] = (cid & 0x3F) | 0x80; + dest[i] = '\0'; + return i; + } + else + return -1; + } + else if (cid <= 0xFFFF) + { + if (size >= 4) + { + dest[i++] = (cid >> 12) | 0xE0; + dest[i++]= ((cid >> 6) & 0x3F) | 0x80; + dest[i++]= (cid & 0x3F) | 0x80; + dest[i] = '\0'; + return i; + } + else + return -1; + } + else if (cid <= 0x1FFFFF) + { + if (size >= 5) + { + 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 + return -1; + } + else if (cid <= 0x3FFFFFF) + { + if (size >= 6) + { + 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 + return -1; + } + else + { + if (size >= 7) + { + 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; + } + else + return -1; + } +}