1 /* Lowercase 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/>. */
25 #include "unicasemap.h"
26 #include "special-casing.h"
29 u8_tolower (const uint8_t *s, size_t n, const char *iso639_language,
31 uint8_t *resultbuf, size_t *lengthp)
33 return u8_casemap (s, n, iso639_language,
34 uc_tolower, offsetof (struct special_casing_rule, lower[0]),
47 /* Read the contents of an input stream, and return it, terminated with a NUL
50 read_file (FILE *stream)
58 while (! feof (stream))
60 if (size + BUFSIZE > alloc)
62 alloc = alloc + alloc / 2;
63 if (alloc < size + BUFSIZE)
64 alloc = size + BUFSIZE;
65 buf = realloc (buf, alloc);
68 fprintf (stderr, "out of memory\n");
72 count = fread (buf + size, 1, BUFSIZE, stream);
84 buf = realloc (buf, size + 1);
87 fprintf (stderr, "out of memory\n");
96 main (int argc, char * argv[])
98 setlocale (LC_ALL, "");
101 /* Display the lower case of the input string. */
102 char *input = read_file (stdin);
103 int length = strlen (input);
104 size_t output_length;
106 u8_tolower ((uint8_t *) input, length, uc_locale_language (),
108 NULL, &output_length);
110 fwrite (output, 1, output_length, stdout);