annotate src/utf8.cc @ 1098:614b1d02e6c3

Refactor: isolate calls to utf8 functions into a single source file.
author corvid <corvid@lavabit.com>
date Fri, 15 May 2009 22:08:10 -0400
parents
children 94b9265663f6
rev   line source
1098
614b1d02e6c3 Refactor: isolate calls to utf8 functions into a single source file.
corvid <corvid@lavabit.com>
parents:
diff changeset
1 /*
614b1d02e6c3 Refactor: isolate calls to utf8 functions into a single source file.
corvid <corvid@lavabit.com>
parents:
diff changeset
2 * File: utf8.c
614b1d02e6c3 Refactor: isolate calls to utf8 functions into a single source file.
corvid <corvid@lavabit.com>
parents:
diff changeset
3 *
614b1d02e6c3 Refactor: isolate calls to utf8 functions into a single source file.
corvid <corvid@lavabit.com>
parents:
diff changeset
4 * Copyright (C) 2009 Jorge Arellano Cid <jcid@dillo.org>
614b1d02e6c3 Refactor: isolate calls to utf8 functions into a single source file.
corvid <corvid@lavabit.com>
parents:
diff changeset
5 *
614b1d02e6c3 Refactor: isolate calls to utf8 functions into a single source file.
corvid <corvid@lavabit.com>
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
614b1d02e6c3 Refactor: isolate calls to utf8 functions into a single source file.
corvid <corvid@lavabit.com>
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
614b1d02e6c3 Refactor: isolate calls to utf8 functions into a single source file.
corvid <corvid@lavabit.com>
parents:
diff changeset
8 * the Free Software Foundation; either version 3 of the License, or
614b1d02e6c3 Refactor: isolate calls to utf8 functions into a single source file.
corvid <corvid@lavabit.com>
parents:
diff changeset
9 * (at your option) any later version.
614b1d02e6c3 Refactor: isolate calls to utf8 functions into a single source file.
corvid <corvid@lavabit.com>
parents:
diff changeset
10 */
614b1d02e6c3 Refactor: isolate calls to utf8 functions into a single source file.
corvid <corvid@lavabit.com>
parents:
diff changeset
11
614b1d02e6c3 Refactor: isolate calls to utf8 functions into a single source file.
corvid <corvid@lavabit.com>
parents:
diff changeset
12 #include <fltk/utf.h>
614b1d02e6c3 Refactor: isolate calls to utf8 functions into a single source file.
corvid <corvid@lavabit.com>
parents:
diff changeset
13
614b1d02e6c3 Refactor: isolate calls to utf8 functions into a single source file.
corvid <corvid@lavabit.com>
parents:
diff changeset
14 #include "utf8.hh"
614b1d02e6c3 Refactor: isolate calls to utf8 functions into a single source file.
corvid <corvid@lavabit.com>
parents:
diff changeset
15
614b1d02e6c3 Refactor: isolate calls to utf8 functions into a single source file.
corvid <corvid@lavabit.com>
parents:
diff changeset
16 // C++ functions with C linkage ----------------------------------------------
614b1d02e6c3 Refactor: isolate calls to utf8 functions into a single source file.
corvid <corvid@lavabit.com>
parents:
diff changeset
17
614b1d02e6c3 Refactor: isolate calls to utf8 functions into a single source file.
corvid <corvid@lavabit.com>
parents:
diff changeset
18 /*
614b1d02e6c3 Refactor: isolate calls to utf8 functions into a single source file.
corvid <corvid@lavabit.com>
parents:
diff changeset
19 * Write UTF-8 encoding of ucs into buf and return number of bytes written.
614b1d02e6c3 Refactor: isolate calls to utf8 functions into a single source file.
corvid <corvid@lavabit.com>
parents:
diff changeset
20 */
614b1d02e6c3 Refactor: isolate calls to utf8 functions into a single source file.
corvid <corvid@lavabit.com>
parents:
diff changeset
21 int a_Utf8_encode(unsigned int ucs, char *buf)
614b1d02e6c3 Refactor: isolate calls to utf8 functions into a single source file.
corvid <corvid@lavabit.com>
parents:
diff changeset
22 {
614b1d02e6c3 Refactor: isolate calls to utf8 functions into a single source file.
corvid <corvid@lavabit.com>
parents:
diff changeset
23 return utf8encode(ucs, buf);
614b1d02e6c3 Refactor: isolate calls to utf8 functions into a single source file.
corvid <corvid@lavabit.com>
parents:
diff changeset
24 }
614b1d02e6c3 Refactor: isolate calls to utf8 functions into a single source file.
corvid <corvid@lavabit.com>
parents:
diff changeset
25
614b1d02e6c3 Refactor: isolate calls to utf8 functions into a single source file.
corvid <corvid@lavabit.com>
parents:
diff changeset
26 /*
614b1d02e6c3 Refactor: isolate calls to utf8 functions into a single source file.
corvid <corvid@lavabit.com>
parents:
diff changeset
27 * Examine first srclen bytes of src.
614b1d02e6c3 Refactor: isolate calls to utf8 functions into a single source file.
corvid <corvid@lavabit.com>
parents:
diff changeset
28 * Return 0 if not legal UTF-8, 1 if all ASCII, 2 if all below 0x800,
614b1d02e6c3 Refactor: isolate calls to utf8 functions into a single source file.
corvid <corvid@lavabit.com>
parents:
diff changeset
29 * 3 if all below 0x10000, and 4 otherwise.
614b1d02e6c3 Refactor: isolate calls to utf8 functions into a single source file.
corvid <corvid@lavabit.com>
parents:
diff changeset
30 */
614b1d02e6c3 Refactor: isolate calls to utf8 functions into a single source file.
corvid <corvid@lavabit.com>
parents:
diff changeset
31 int a_Utf8_test(const char* src, unsigned int srclen)
614b1d02e6c3 Refactor: isolate calls to utf8 functions into a single source file.
corvid <corvid@lavabit.com>
parents:
diff changeset
32 {
614b1d02e6c3 Refactor: isolate calls to utf8 functions into a single source file.
corvid <corvid@lavabit.com>
parents:
diff changeset
33 return utf8test(src, srclen);
614b1d02e6c3 Refactor: isolate calls to utf8 functions into a single source file.
corvid <corvid@lavabit.com>
parents:
diff changeset
34 }