Dillo v3.1.1-119-g140d9ebd
Loading...
Searching...
No Matches
unicode_test.cc
Go to the documentation of this file.
1/*
2 * File: unicode_test.cc
3 *
4 * Copyright 2012 Sebastian Geerken <sgeerken@dillo.org>
5 * Copyright 2023 Rodrigo Arias Mallo <rodarima@gmail.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include <string.h>
22#include <stdio.h>
23#include <FL/fl_utf8.h>
24#include "lout/unicode.hh"
25
26using namespace lout::unicode;
27
28int main (int argc, char *argv[])
29{
30 // 0-terminated string
31 const char *t1 = "abcäöüабв−‐";
32
33 // not 0-terminated; copy from 0-terminated
34 int t2len = strlen (t1);
35 char *t2 = new char[t2len];
36 for (int i = 0; i < t2len; i++)
37 t2[i] = t1[i];
38
39 puts ("===== misc::unicode, 0-terminated =====");
40 for (const char *s = t1; s; s = nextUtf8Char (s))
41 printf ("%3d -> U+%04x ('%s')\n", (int)(s - t1), decodeUtf8(s), s);
42
43 puts ("===== Fltk, 0-terminated =====");
44 for (const char *s = t1; *s; s = fl_utf8fwd (s + 1, t1, t1 + strlen (t1)))
45 printf ("%3d -> U+%04x ('%s')\n", (int)(s - t1), decodeUtf8(s), s);
46
47 puts ("===== misc::unicode, not 0-terminated =====");
48 for (const char *s = t2; s; s = nextUtf8Char (s, t2len - (s - t2)))
49 printf ("%3d -> U+%04x\n", (int)(s - t2),
50 decodeUtf8(s, t2len - (s - t2)));
51
52 puts ("===== Fltk, not 0-terminated =====");
53 for (const char *s = t2; s - t2 < t2len; s = fl_utf8fwd (s + 1, t2, t2 + t2len))
54 printf ("%3d -> U+%04x\n", (int)(s - t2),
55 decodeUtf8(s, t2len - (s - t2)));
56
57 delete[] t2;
58
59 return 0;
60}
int main(void)
Definition bookmarks.c:1613
Stuff dealing with Unicode characters: UTF-8, character classes etc.
Definition unicode.cc:28
int decodeUtf8(const char *s)
Definition unicode.cc:73
const char * nextUtf8Char(const char *s)
Definition unicode.cc:110