1 /* Casefolding mapping for UTF-8 strings (locale dependent).
2 Copyright (C) 2009 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2009.
5 This program is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Lesser General Public License as published
7 by the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 #include "unicasemap.h"
28 #include "special-casing.h"
31 #define FUNC u8_casefold
33 #define U_CASEMAP u8_casemap
34 #define U_NORMALIZE u8_normalize
35 #include "u-casefold.h"
45 /* Read the contents of an input stream, and return it, terminated with a NUL
48 read_file (FILE *stream)
56 while (! feof (stream))
58 if (size + BUFSIZE > alloc)
60 alloc = alloc + alloc / 2;
61 if (alloc < size + BUFSIZE)
62 alloc = size + BUFSIZE;
63 buf = realloc (buf, alloc);
66 fprintf (stderr, "out of memory\n");
70 count = fread (buf + size, 1, BUFSIZE, stream);
82 buf = realloc (buf, size + 1);
85 fprintf (stderr, "out of memory\n");
94 main (int argc, char * argv[])
96 setlocale (LC_ALL, "");
99 /* Display the case folded input string. */
100 char *input = read_file (stdin);
101 int length = strlen (input);
102 size_t output_length;
104 u8_casefold ((uint8_t *) input, length, uc_locale_language (),
106 NULL, &output_length);
108 fwrite (output, 1, output_length, stdout);