1 /* Generic conversion to and from 8bit charsets,
2 converting from UCS using gaps.
3 Copyright (C) 1997-2022 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <https://www.gnu.org/licenses/>. */
30 /* Now we can include the tables. */
34 # define NONNUL(c) ((c) != '\0')
38 #define FROM_LOOP from_gap
39 #define TO_LOOP to_gap
42 #define MIN_NEEDED_FROM 1
43 #define MIN_NEEDED_TO 4
44 #define ONE_DIRECTION 0
47 /* First define the conversion function from the 8bit charset to UCS4. */
48 #define MIN_NEEDED_INPUT MIN_NEEDED_FROM
49 #define MIN_NEEDED_OUTPUT MIN_NEEDED_TO
50 #define LOOPFCT FROM_LOOP
53 uint32_t ch = to_ucs4[*inptr]; \
55 if (HAS_HOLES && __builtin_expect (ch == L'\0', 0) && NONNUL (*inptr)) \
57 /* This is an illegal character. */ \
58 STANDARD_FROM_LOOP_ERR_HANDLER (1); \
68 #define LOOP_NEED_FLAGS
69 #define ONEBYTE_BODY \
71 uint32_t ch = to_ucs4[c]; \
73 if (HAS_HOLES && __builtin_expect (ch == L'\0', 0) && NONNUL (c)) \
78 #include <iconv/loop.c>
81 /* Next, define the other direction. */
82 #define MIN_NEEDED_INPUT MIN_NEEDED_TO
83 #define MIN_NEEDED_OUTPUT MIN_NEEDED_FROM
84 #define LOOPFCT TO_LOOP
87 const struct gap *rp = from_idx; \
88 uint32_t ch = get32 (inptr); \
91 if (__glibc_unlikely (ch >= 0xffff)) \
93 UNICODE_TAG_HANDLER (ch, 4); \
97 while (ch > rp->end) \
99 if (__builtin_expect (rp == NULL, 0) \
100 || __builtin_expect (ch < rp->start, 0) \
101 || (res = from_ucs4[ch + rp->idx], \
102 __builtin_expect (res, '\1') == '\0' && ch != 0)) \
104 /* This is an illegal character. */ \
105 STANDARD_TO_LOOP_ERR_HANDLER (4); \
111 #define LOOP_NEED_FLAGS
112 #include <iconv/loop.c>
115 /* Now define the toplevel functions. */
116 #include <iconv/skeleton.c>