1 /* Charset name normalization.
2 Copyright (C) 2001-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library 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
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
25 #include "gconv_int.h"
28 /* An iconv encoding is in the form of a triplet, with parts separated by
29 a '/' character. The first part is the standard name, the second part is
30 the character set, and the third part is the error handler. If the first
31 part is sufficient to identify both the standard and the character set
32 then the second part can be empty e.g. UTF-8//. If the first part is not
33 sufficient to identify both the standard and the character set then the
34 second part is required e.g. ISO-10646/UTF8/. If neither the first or
35 second parts are provided e.g. //, then the current locale is used.
36 The actual values used in the first and second parts are not entirely
37 relevant to the implementation. The values themselves are used in a hash
38 table to lookup modules and so the naming convention of the first two parts
39 is somewhat arbitrary and only helps locate the entries in the cache.
40 The third part is the error handler and is comprised of a ',' or '/'
41 separated list of suffixes. Currently, we support "TRANSLIT" for
42 transliteration and "IGNORE" for ignoring conversion errors due to
43 unrecognized input characters. */
44 #define GCONV_TRIPLE_SEPARATOR "/"
45 #define GCONV_SUFFIX_SEPARATOR ","
46 #define GCONV_TRANSLIT_SUFFIX "TRANSLIT"
47 #define GCONV_IGNORE_ERRORS_SUFFIX "IGNORE"
50 /* This function copies in-order, characters from the source 's' that are
51 either alpha-numeric or one in one of these: "_-.,:/" - into the destination
52 'wp' while dropping all other characters. In the process, it converts all
53 alphabetical characters to upper case. It then appends up to two '/'
54 characters so that the total number of '/'es in the destination is 2. */
55 static inline void __attribute__ ((unused
, always_inline
))
56 strip (char *wp
, const char *s
)
62 if (__isalnum_l (*s
, _nl_C_locobj_ptr
)
63 || *s
== '_' || *s
== '-' || *s
== '.' || *s
== ',' || *s
== ':')
64 *wp
++ = __toupper_l (*s
, _nl_C_locobj_ptr
);
67 if (++slash_count
== 3)
74 while (slash_count
++ < 2)
81 static inline char * __attribute__ ((unused
, always_inline
))
82 upstr (char *dst
, const char *str
)
85 while ((*cp
++ = __toupper_l (*str
++, _nl_C_locobj_ptr
)) != '\0')