Avoid build errors due to wrong references between modules.
[gnulib.git] / lib / unicase / u8-toupper.c
blob99d6ef2939e53922075ec4a1276757e816cdb14e
1 /* Uppercase mapping for UTF-8 strings (locale dependent).
2 Copyright (C) 2009-2019 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 <https://www.gnu.org/licenses/>. */
18 #include <config.h>
20 /* Specification. */
21 #include "unicase.h"
23 #include <stddef.h>
25 #include "unicase/unicasemap.h"
26 #include "unicase/special-casing.h"
28 uint8_t *
29 u8_toupper (const uint8_t *s, size_t n, const char *iso639_language,
30 uninorm_t nf,
31 uint8_t *resultbuf, size_t *lengthp)
33 return u8_casemap (s, n,
34 unicase_empty_prefix_context, unicase_empty_suffix_context,
35 iso639_language,
36 uc_toupper, offsetof (struct special_casing_rule, upper[0]),
37 nf,
38 resultbuf, lengthp);
42 #ifdef TEST
44 #include <locale.h>
45 #include <stdio.h>
46 #include <stdlib.h>
47 #include <string.h>
49 /* Read the contents of an input stream, and return it, terminated with a NUL
50 byte. */
51 char *
52 read_file (FILE *stream)
54 #define BUFSIZE 4096
55 char *buf = NULL;
56 int alloc = 0;
57 int size = 0;
58 int count;
60 while (! feof (stream))
62 if (size + BUFSIZE > alloc)
64 alloc = alloc + alloc / 2;
65 if (alloc < size + BUFSIZE)
66 alloc = size + BUFSIZE;
67 buf = realloc (buf, alloc);
68 if (buf == NULL)
70 fprintf (stderr, "out of memory\n");
71 exit (1);
74 count = fread (buf + size, 1, BUFSIZE, stream);
75 if (count == 0)
77 if (ferror (stream))
79 perror ("fread");
80 exit (1);
83 else
84 size += count;
86 buf = realloc (buf, size + 1);
87 if (buf == NULL)
89 fprintf (stderr, "out of memory\n");
90 exit (1);
92 buf[size] = '\0';
93 return buf;
94 #undef BUFSIZE
97 int
98 main (int argc, char * argv[])
100 setlocale (LC_ALL, "");
101 if (argc == 1)
103 /* Display the upper case of the input string. */
104 char *input = read_file (stdin);
105 int length = strlen (input);
106 size_t output_length;
107 uint8_t *output =
108 u8_toupper ((uint8_t *) input, length, uc_locale_language (),
109 NULL,
110 NULL, &output_length);
112 fwrite (output, 1, output_length, stdout);
114 return 0;
116 else
117 return 1;
120 #endif /* TEST */