Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
-#include <stdlib.h>
#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;
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;
+ }
+}