1 /* Titlecase mapping for UTF-8 strings (locale dependent).
2 Copyright (C) 2009-2012 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/>. */
23 #define FUNC u8_totitle
25 #define U_CT_TOTITLE u8_ct_totitle
26 #include "u-totitle.h"
36 /* Read the contents of an input stream, and return it, terminated with a NUL
39 read_file (FILE *stream)
47 while (! feof (stream))
49 if (size + BUFSIZE > alloc)
51 alloc = alloc + alloc / 2;
52 if (alloc < size + BUFSIZE)
53 alloc = size + BUFSIZE;
54 buf = realloc (buf, alloc);
57 fprintf (stderr, "out of memory\n");
61 count = fread (buf + size, 1, BUFSIZE, stream);
73 buf = realloc (buf, size + 1);
76 fprintf (stderr, "out of memory\n");
85 main (int argc, char * argv[])
87 setlocale (LC_ALL, "");
90 /* Display the upper case of the input string. */
91 char *input = read_file (stdin);
92 int length = strlen (input);
95 u8_toupper ((uint8_t *) input, length, uc_locale_language (),
97 NULL, &output_length);
99 fwrite (output, 1, output_length, stdout);