1 /* Lowercase mapping for UTF-8 strings (locale dependent).
2 Copyright (C) 2009-2020 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/>. */
25 #include "unicase/unicasemap.h"
26 #include "unicase/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
,
34 unicase_empty_prefix_context
, unicase_empty_suffix_context
,
36 uc_tolower
, offsetof (struct special_casing_rule
, lower
[0]),
49 /* Read the contents of an input stream, and return it, terminated with a NUL
52 read_file (FILE *stream
)
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
);
70 fprintf (stderr
, "out of memory\n");
74 count
= fread (buf
+ size
, 1, BUFSIZE
, stream
);
86 buf
= realloc (buf
, size
+ 1);
89 fprintf (stderr
, "out of memory\n");
98 main (int argc
, char * argv
[])
100 setlocale (LC_ALL
, "");
103 /* Display the lower case of the input string. */
104 char *input
= read_file (stdin
);
105 int length
= strlen (input
);
106 size_t output_length
;
108 u8_tolower ((uint8_t *) input
, length
, uc_locale_language (),
110 NULL
, &output_length
);
112 fwrite (output
, 1, output_length
, stdout
);