/* Conversion to and from TCVN5712-1.
- Copyright (C) 2001, 2002 Free Software Foundation, Inc.
+ Copyright (C) 2001-2022 Free Software Foundation, Inc.
This file is part of the GNU C Library.
- Contributed by Ulrich Drepper <drepper@redhat.com>, 2001.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, write to the Free
- Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307 USA. */
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
#include <dlfcn.h>
#include <stdint.h>
#define TO_LOOP to_tcvn5712_1
#define DEFINE_INIT 1
#define DEFINE_FINI 1
-#define MIN_NEEDED_FROM 1
-#define MAX_NEEDED_FROM 2
-#define MIN_NEEDED_TO 4
-#define MAX_NEEDED_TO 8
+#define ONE_DIRECTION 0
+#define FROM_LOOP_MIN_NEEDED_FROM 1
+#define FROM_LOOP_MAX_NEEDED_FROM 1
+#define FROM_LOOP_MIN_NEEDED_TO 4
+#define FROM_LOOP_MAX_NEEDED_TO 4
+#define TO_LOOP_MIN_NEEDED_FROM 4
+#define TO_LOOP_MAX_NEEDED_FROM 4
+#define TO_LOOP_MIN_NEEDED_TO 1
+#define TO_LOOP_MAX_NEEDED_TO 2
#define PREPARE_LOOP \
int saved_state; \
int *statep = &data->__statep->__count;
{ \
if (FROM_DIRECTION) \
{ \
- if (__builtin_expect (outbuf + 4 <= outend, 1)) \
+ if (__glibc_likely (outbuf + 4 <= outend)) \
{ \
/* Write out the last character. */ \
- *((uint32_t *) outbuf)++ = data->__statep->__count >> 3; \
+ *((uint32_t *) outbuf) = data->__statep->__count >> 3; \
+ outbuf += sizeof (uint32_t); \
data->__statep->__count = 0; \
} \
else \
{ 0x01AF, 0x1EEA },
{ 0x01B0, 0x1EEB },
#define COMP_TABLE_IDX_0301 (COMP_TABLE_IDX_0300 + COMP_TABLE_LEN_0300)
-#define COMP_TABLE_LEN_0301 51
+#define COMP_TABLE_LEN_0301 50
{ 0x0041, 0x00C1 },
{ 0x0043, 0x0106 },
{ 0x0045, 0x00C9 },
{ 0x0077, 0x1E83 },
{ 0x0079, 0x00FD },
{ 0x007A, 0x017A },
- { 0x00A5, 0x0385 },
- /*{ 0x00A8, 0x1FEE },*/
+ /*{ 0x00A8, 0x0385 },*//* prefer U+0385 over U+1FEE */
{ 0x00C2, 0x1EA4 },
/*{ 0x00C5, 0x01FA },*/
/*{ 0x00C6, 0x01FC },*/
/* First define the conversion function from TCVN5712-1 to UCS4. */
-#define MIN_NEEDED_INPUT MIN_NEEDED_FROM
-#define MAX_NEEDED_INPUT MAX_NEEDED_FROM
-#define MIN_NEEDED_OUTPUT MIN_NEEDED_TO
-#define MAX_NEEDED_OUTPUT MAX_NEEDED_TO
+#define MIN_NEEDED_INPUT FROM_LOOP_MIN_NEEDED_FROM
+#define MAX_NEEDED_INPUT FROM_LOOP_MAX_NEEDED_FROM
+#define MIN_NEEDED_OUTPUT FROM_LOOP_MIN_NEEDED_TO
+#define MAX_NEEDED_OUTPUT FROM_LOOP_MAX_NEEDED_TO
#define LOOPFCT FROM_LOOP
#define BODY \
{ \
last_ch = *statep >> 3; \
\
/* We have to buffer ch if it is a possible match in comp_table_data. */ \
- must_buffer_ch = (ch >= 0x0041 && ch <= 0x01b0); \
+ must_buffer_ch = (ch >= 0x0041 && ch <= 0x01b0); \
\
if (last_ch) \
{ \
++inptr; \
}
#define EXTRA_LOOP_DECLS , int *statep
+#define ONEBYTE_BODY \
+ { \
+ uint32_t ch; \
+ \
+ if (c < 0x18) \
+ ch = map_from_tcvn_low[c]; \
+ else if (c >= 0x80) \
+ ch = map_from_tcvn_high[c - 0x80]; \
+ else \
+ ch = c; \
+ if (ch >= 0x0041 && ch <= 0x01b0) \
+ return WEOF; \
+ return ch; \
+ }
#include <iconv/loop.c>
-/* Next, define the conversion function from UCS4 to CP1258. */
+/* Next, define the conversion function from UCS4 to TCVN5712-1. */
static const unsigned char from_ucs4[] =
{
/* Next, define the other direction. */
-#define MIN_NEEDED_INPUT MIN_NEEDED_TO
-#define MIN_NEEDED_OUTPUT MIN_NEEDED_FROM
-#define MAX_NEEDED_OUTPUT MAX_NEEDED_FROM
+#define MIN_NEEDED_INPUT TO_LOOP_MIN_NEEDED_FROM
+#define MAX_NEEDED_INPUT TO_LOOP_MAX_NEEDED_FROM
+#define MIN_NEEDED_OUTPUT TO_LOOP_MIN_NEEDED_TO
+#define MAX_NEEDED_OUTPUT TO_LOOP_MAX_NEEDED_TO
#define LOOPFCT TO_LOOP
#define BODY \
{ \
res = 0; \
} \
\
- if (__builtin_expect (res != 0, 1)) \
+ if (__glibc_likely (res != 0)) \
{ \
*outptr++ = res; \
inptr += 4; \
} \
\
/* See whether we have room for two bytes. */ \
- if (__builtin_expect (outptr + 1 >= outend, 0)) \
+ if (__glibc_unlikely (outptr + 1 >= outend)) \
{ \
result = __GCONV_FULL_OUTPUT; \
break; \
\
failed: \
/* This is an illegal character. */ \
- STANDARD_ERR_HANDLER (4); \
+ STANDARD_TO_LOOP_ERR_HANDLER (4); \
} \
} \
}