mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-27 14:36:16 +01:00
4f96a13cba
Sun Jul 1 20:16:25 2001 Owen Taylor <otaylor@redhat.com> * glib/guniprop.c (g_unichar_totitle): Use G_N_ELEMENTS rather than a custom macro. * glib/gen-unicode-tables.pl: Adapt to changes in table formats for Unicode 3.1 * glib/gunicode.h glib/guniprop.c glib/gunichartables.h glib/gen-unicode-tables.pl: Add case conversion functions g_utf8_casefold, g_utf8_strup, g_utf8_strdown. * tests/unicode-caseconv.c tests/gen-casefold-txt.pl tests/gen-casemap-txt.pl tests/casefold.txt tests/casemap.txt: Test cases for case conversion. * glib/gunicode.h glib/gunidecomp.[ch] glib/gunicomp.h glib/gen-unicode-tables.pl: Add function to do Unicode normalization g_utf8_normalize(). * tests/unicode-normalize.c: Test program for case conversion. * glib/gunicode.h glib/gunicollate.c: Add collation functions g_utf8_collate, g_utf8_collate_key. * test/unicode-collate.c: Test program for collation. * glib/gdate.c (g_date_fill_parse_tokens): Fix uninitialized variable. * glib/gdate.c (g_date_strftime) docs/Changes-2.0.txt: Make work with UTF-8 even if the locale isn't UTF-8 based. Still somewhat of broken, if the format string contains characters not representable in the current locale, will warn and not work. * glib/gdate.c: Use UTF-8 normalization and casefolding.
117 lines
2.4 KiB
C
117 lines
2.4 KiB
C
#include <locale.h>
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <glib.h>
|
|
#include <string.h>
|
|
|
|
int main (int argc, char **argv)
|
|
{
|
|
FILE *infile;
|
|
char buffer[1024];
|
|
char **strings;
|
|
char *srcdir = getenv ("srcdir");
|
|
char *filename;
|
|
const char *locale;
|
|
const char *test;
|
|
char *convert;
|
|
char *current_locale = setlocale (LC_CTYPE, NULL);
|
|
gint result = 0;
|
|
|
|
if (!srcdir)
|
|
srcdir = ".";
|
|
filename = g_strconcat (srcdir, G_DIR_SEPARATOR_S, "casemap.txt", NULL);
|
|
|
|
infile = fopen (filename, "r");
|
|
if (!infile)
|
|
{
|
|
fprintf (stderr, "Failed to open %s\n", filename );
|
|
exit (1);
|
|
}
|
|
|
|
while (fgets (buffer, sizeof(buffer), infile))
|
|
{
|
|
if (buffer[0] == '#')
|
|
continue;
|
|
|
|
strings = g_strsplit (buffer, "\t", -1);
|
|
|
|
locale = strings[0];
|
|
|
|
if (!locale[0])
|
|
locale = "C";
|
|
|
|
if (strcmp (locale, current_locale) != 0)
|
|
{
|
|
setlocale (LC_CTYPE, locale);
|
|
current_locale = setlocale (LC_CTYPE, NULL);
|
|
|
|
if (strncmp (current_locale, locale, 2) != 0)
|
|
{
|
|
fprintf (stderr, "Cannot set locale to %s, skipping\n", locale);
|
|
goto next;
|
|
}
|
|
}
|
|
|
|
test = strings[1];
|
|
|
|
convert = g_utf8_strup (test);
|
|
if (strcmp (convert, strings[4]) != 0)
|
|
{
|
|
fprintf (stderr, "Failure: toupper(%s) == %s, should have been %s\n",
|
|
test, convert, strings[4]);
|
|
result = 1;
|
|
}
|
|
g_free (convert);
|
|
|
|
convert = g_utf8_strdown (test);
|
|
if (strcmp (convert, strings[2]) != 0)
|
|
{
|
|
fprintf (stderr, "Failure: tolower(%s) == %s, should have been %s\n",
|
|
test, convert, strings[2]);
|
|
result = 1;
|
|
}
|
|
g_free (convert);
|
|
|
|
next:
|
|
g_strfreev (strings);
|
|
}
|
|
|
|
fclose (infile);
|
|
|
|
g_free (filename);
|
|
filename = g_strconcat (srcdir, G_DIR_SEPARATOR_S, "casefold.txt", NULL);
|
|
|
|
infile = fopen (filename, "r");
|
|
if (!infile)
|
|
{
|
|
fprintf (stderr, "Failed to open %s\n", filename );
|
|
exit (1);
|
|
}
|
|
|
|
while (fgets (buffer, sizeof(buffer), infile))
|
|
{
|
|
if (buffer[0] == '#')
|
|
continue;
|
|
|
|
buffer[strlen(buffer) - 1] = '\0';
|
|
strings = g_strsplit (buffer, "\t", -1);
|
|
|
|
test = strings[0];
|
|
|
|
convert = g_utf8_casefold (test);
|
|
if (strcmp (convert, strings[1]) != 0)
|
|
{
|
|
fprintf (stderr, "Failure: casefold(%s) == '%s', should have been '%s'\n",
|
|
test, convert, strings[1]);
|
|
result = 1;
|
|
}
|
|
g_free (convert);
|
|
|
|
g_strfreev (strings);
|
|
}
|
|
|
|
fclose (infile);
|
|
|
|
return result;
|
|
}
|