2 * Copyright (C) 2003 Robert Kooima
4 * NEVERBALL is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published
6 * by the Free Software Foundation; either version 2 of the License,
7 * or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
18 /*---------------------------------------------------------------------------*/
20 int text_add_char(Uint32 unicode, char *string, int maxbytes)
22 size_t pos = strlen(string);
25 if (unicode < 0x80) l = 1;
26 else if (unicode < 0x0800) l = 2;
27 else if (unicode < 0x10000) l = 3;
30 if (pos + l >= maxbytes)
34 string[pos++] = (char) unicode;
35 else if (unicode < 0x0800)
37 string[pos++] = (char) ((unicode >> 6) | 0xC0);
38 string[pos++] = (char) ((unicode & 0x3F) | 0x80);
40 else if (unicode < 0x10000)
42 string[pos++] = (char) ((unicode >> 12) | 0xE0);
43 string[pos++] = (char) (((unicode >> 6) & 0x3F) | 0x80);
44 string[pos++] = (char) ((unicode & 0x3F) | 0x80);
48 string[pos++] = (char) ((unicode >> 18) | 0xF0);
49 string[pos++] = (char) (((unicode >> 12) & 0x3F) | 0x80);
50 string[pos++] = (char) (((unicode >> 6) & 0x3F) | 0x80);
51 string[pos++] = (char) ((unicode & 0x3F) | 0x80);
59 int text_del_char(char *string)
61 int pos = (int) strlen(string) - 1;
63 while (pos >= 0 && ((string[pos] & 0xC0) == 0x80))
75 int text_length(const char *string)
79 while (*string != '\0')
80 if ((*string++ & 0xC0) != 0x80)
86 /*---------------------------------------------------------------------------*/