glib/tests/unicode-collate.c
Owen Taylor 4f96a13cba Use G_N_ELEMENTS rather than a custom macro.
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.
2001-07-02 00:49:21 +00:00

95 lines
1.9 KiB
C

#include <glib.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct {
const char *key;
const char *str;
} Line;
int
compare_collate (const void *a, const void *b)
{
const Line *line_a = a;
const Line *line_b = b;
return g_utf8_collate (line_a->str, line_b->str);
}
int
compare_key (const void *a, const void *b)
{
const Line *line_a = a;
const Line *line_b = b;
return strcmp (line_a->key, line_b->key);
}
int main (int argc, char **argv)
{
GIOChannel *in;
GError *error = NULL;
GArray *line_array = g_array_new (FALSE, FALSE, sizeof(Line));
guint i;
if (argc != 1 && argc != 2)
{
fprintf (stderr, "Usage: unicode-collate [FILE]\n");
return 1;
}
if (argc == 2)
{
in = g_io_channel_new_file (argv[1], G_IO_FILE_MODE_READ, &error);
if (!in)
{
fprintf (stderr, "Cannot open %s: %s\n", argv[1], error->message);
return 1;
}
}
else
{
in = g_io_channel_unix_new (fileno (stdin));
}
while (TRUE)
{
gsize term_pos;
gchar *str;
Line line;
if (g_io_channel_read_line (in, &str, NULL, &term_pos, &error) != G_IO_STATUS_NORMAL)
break;
str[term_pos] = '\0';
line.key = g_utf8_collate_key (str);
line.str = str;
g_array_append_val (line_array, line);
}
if (error)
{
fprintf (stderr, "Error reading test file, %s\n", error->message);
return 1;
}
printf ("== g_utf8_collate ==\n");
qsort (line_array->data, line_array->len, sizeof (Line), compare_collate);
for (i = 0; i < line_array->len; i++)
printf ("%s\n", g_array_index (line_array, Line, i).str);
printf ("== g_utf8_collate_key ==\n");
qsort (line_array->data, line_array->len, sizeof (Line), compare_key);
for (i = 0; i < line_array->len; i++)
printf ("%s\n", g_array_index (line_array, Line, i).str);
g_io_channel_close (in);
return 0;
}