Mercurial > gnulib
annotate lib/unicase/u8-toupper.c @ 40163:b89f4c441767
Avoid build errors due to wrong references between modules.
* lib/uninorm/canonical-decomposition.c: Include
"uninorm/decomposition-table.h", not "decomposition-table.h".
* lib/uninorm/decomposition.c: Likewise.
* lib/uninorm/u8-normalize.c: Include "uninorm/decompose-internal.h",
not "decompose-internal.h".
* lib/uninorm/u16-normalize.c: Likewise.
* lib/uninorm/u32-normalize.c: Likewise.
* lib/uninorm/uninorm-filter.c: Likewise.
* lib/uninorm/nfkc.c: Likewise.
* lib/uninorm/nfkd.c: Likewise.
* lib/unicase/u8-casemap.c: Include "unicase/caseprop.h", not
"caseprop.h".
* lib/unicase/u8-ct-totitle.c: Likewise.
* lib/unicase/u8-prefix-context.c: Likewise.
* lib/unicase/u8-suffix-context.c: Likewise.
* lib/unicase/u16-casemap.c: Likewise.
* lib/unicase/u16-ct-totitle.c: Likewise.
* lib/unicase/u16-prefix-context.c: Likewise.
* lib/unicase/u16-suffix-context.c: Likewise.
* lib/unicase/u32-casemap.c: Likewise.
* lib/unicase/u32-ct-totitle.c: Likewise.
* lib/unicase/u32-prefix-context.c: Likewise.
* lib/unicase/u32-suffix-context.c: Likewise.
* lib/unicase/u8-tolower.c: Include "unicase/unicasemap.h", not
"unicasemap.h".
* lib/unicase/u8-toupper.c: Likewise.
* lib/unicase/u8-ct-tolower.c: Likewise.
* lib/unicase/u8-ct-toupper.c: Likewise.
* lib/unicase/u16-tolower.c: Likewise.
* lib/unicase/u16-toupper.c: Likewise.
* lib/unicase/u16-ct-tolower.c: Likewise.
* lib/unicase/u16-ct-toupper.c: Likewise.
* lib/unicase/u32-tolower.c: Likewise.
* lib/unicase/u32-toupper.c: Likewise.
* lib/unicase/u32-ct-tolower.c: Likewise.
* lib/unicase/u32-ct-toupper.c: Likewise.
* lib/unicase/u8-ct-casefold.c: Include "unicase/unicasemap.h", not
"unicasemap.h", and "unicase/casefold.h", not "casefold.h".
* lib/unicase/u16-ct-casefold.c: Likewise.
* lib/unicase/u32-ct-casefold.c: Likewise.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Mon, 28 Jan 2019 01:20:11 +0100 |
parents | b06060465f09 |
children |
rev | line source |
---|---|
11310
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
1 /* Uppercase mapping for UTF-8 strings (locale dependent). |
40057
b06060465f09
maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents:
19484
diff
changeset
|
2 Copyright (C) 2009-2019 Free Software Foundation, Inc. |
11310
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3 Written by Bruno Haible <bruno@clisp.org>, 2009. |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
4 |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
5 This program is free software: you can redistribute it and/or modify it |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
6 under the terms of the GNU Lesser General Public License as published |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
7 by the Free Software Foundation; either version 3 of the License, or |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
8 (at your option) any later version. |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
9 |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
10 This program is distributed in the hope that it will be useful, |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
13 Lesser General Public License for more details. |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
14 |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public License |
19190 | 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
11310
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
17 |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
18 #include <config.h> |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
19 |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
20 /* Specification. */ |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
21 #include "unicase.h" |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
22 |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
23 #include <stddef.h> |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
24 |
40163
b89f4c441767
Avoid build errors due to wrong references between modules.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
25 #include "unicase/unicasemap.h" |
18921
03d88e24ab56
unicase/special-casing: Fix incompatibility with gperf-3.0.4.
Bruno Haible <bruno@clisp.org>
parents:
18626
diff
changeset
|
26 #include "unicase/special-casing.h" |
11310
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
27 |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
28 uint8_t * |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
29 u8_toupper (const uint8_t *s, size_t n, const char *iso639_language, |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11686
diff
changeset
|
30 uninorm_t nf, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11686
diff
changeset
|
31 uint8_t *resultbuf, size_t *lengthp) |
11310
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
32 { |
11686
909f4826147c
Update u8_casemap invocation.
Bruno Haible <bruno@clisp.org>
parents:
11310
diff
changeset
|
33 return u8_casemap (s, n, |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11686
diff
changeset
|
34 unicase_empty_prefix_context, unicase_empty_suffix_context, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11686
diff
changeset
|
35 iso639_language, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11686
diff
changeset
|
36 uc_toupper, offsetof (struct special_casing_rule, upper[0]), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11686
diff
changeset
|
37 nf, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11686
diff
changeset
|
38 resultbuf, lengthp); |
11310
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
39 } |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
40 |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
41 |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
42 #ifdef TEST |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
43 |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
44 #include <locale.h> |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
45 #include <stdio.h> |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
46 #include <stdlib.h> |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
47 #include <string.h> |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
48 |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
49 /* Read the contents of an input stream, and return it, terminated with a NUL |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
50 byte. */ |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
51 char * |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
52 read_file (FILE *stream) |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
53 { |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
54 #define BUFSIZE 4096 |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
55 char *buf = NULL; |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
56 int alloc = 0; |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
57 int size = 0; |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
58 int count; |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
59 |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
60 while (! feof (stream)) |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
61 { |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
62 if (size + BUFSIZE > alloc) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11686
diff
changeset
|
63 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11686
diff
changeset
|
64 alloc = alloc + alloc / 2; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11686
diff
changeset
|
65 if (alloc < size + BUFSIZE) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11686
diff
changeset
|
66 alloc = size + BUFSIZE; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11686
diff
changeset
|
67 buf = realloc (buf, alloc); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11686
diff
changeset
|
68 if (buf == NULL) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11686
diff
changeset
|
69 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11686
diff
changeset
|
70 fprintf (stderr, "out of memory\n"); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11686
diff
changeset
|
71 exit (1); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11686
diff
changeset
|
72 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11686
diff
changeset
|
73 } |
11310
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
74 count = fread (buf + size, 1, BUFSIZE, stream); |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
75 if (count == 0) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11686
diff
changeset
|
76 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11686
diff
changeset
|
77 if (ferror (stream)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11686
diff
changeset
|
78 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11686
diff
changeset
|
79 perror ("fread"); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11686
diff
changeset
|
80 exit (1); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11686
diff
changeset
|
81 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11686
diff
changeset
|
82 } |
11310
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
83 else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11686
diff
changeset
|
84 size += count; |
11310
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
85 } |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
86 buf = realloc (buf, size + 1); |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
87 if (buf == NULL) |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
88 { |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
89 fprintf (stderr, "out of memory\n"); |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
90 exit (1); |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
91 } |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
92 buf[size] = '\0'; |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
93 return buf; |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
94 #undef BUFSIZE |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
95 } |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
96 |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
97 int |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
98 main (int argc, char * argv[]) |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
99 { |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
100 setlocale (LC_ALL, ""); |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
101 if (argc == 1) |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
102 { |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
103 /* Display the upper case of the input string. */ |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
104 char *input = read_file (stdin); |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
105 int length = strlen (input); |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
106 size_t output_length; |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
107 uint8_t *output = |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11686
diff
changeset
|
108 u8_toupper ((uint8_t *) input, length, uc_locale_language (), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11686
diff
changeset
|
109 NULL, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11686
diff
changeset
|
110 NULL, &output_length); |
11310
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
111 |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
112 fwrite (output, 1, output_length, stdout); |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
113 |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
114 return 0; |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
115 } |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
116 else |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
117 return 1; |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
118 } |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
119 |
9b39c3c27fde
New module 'unicase/u8-toupper'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
120 #endif /* TEST */ |