1 /* Titlecase 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/>. */
32 #include "special-casing.h"
34 #define FUNC u8_totitle
36 #define U_WORDBREAKS u8_wordbreaks
37 #define U_MBTOUC_UNSAFE u8_mbtouc_unsafe
38 #define U_UCTOMB u8_uctomb
40 #define U_NORMALIZE u8_normalize
41 #include "u-totitle.h"
51 /* Read the contents of an input stream, and return it, terminated with a NUL
54 read_file (FILE *stream)
62 while (! feof (stream))
64 if (size + BUFSIZE > alloc)
66 alloc = alloc + alloc / 2;
67 if (alloc < size + BUFSIZE)
68 alloc = size + BUFSIZE;
69 buf = realloc (buf, alloc);
72 fprintf (stderr, "out of memory\n");
76 count = fread (buf + size, 1, BUFSIZE, stream);
88 buf = realloc (buf, size + 1);
91 fprintf (stderr, "out of memory\n");
100 main (int argc, char * argv[])
102 setlocale (LC_ALL, "");
105 /* Display the upper case of the input string. */
106 char *input = read_file (stdin);
107 int length = strlen (input);
108 size_t output_length;
110 u8_toupper ((uint8_t *) input, length, uc_locale_language (),
112 NULL, &output_length);
114 fwrite (output, 1, output_length, stdout);