--- /dev/null
+/* 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 */
--- /dev/null
+/* 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 <stdlib.h>
+#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;
+ }
+}