/* Conversion module for UTF-7.
- Copyright (C) 2000 Free Software Foundation, Inc.
+ Copyright (C) 2000-2019 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Bruno Haible <haible@clisp.cons.org>, 2000.
The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
+ Lesser General Public License for more details.
- You should have received a copy of the GNU Library General Public
- License along with the GNU C Library; see the file COPYING.LIB. If not,
- write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA. */
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
/* UTF-7 is a legacy encoding used for transmitting Unicode within the
ASCII character set, used primarily by mail agents. New programs
A-Z a-z 0-9 ' ( ) , - . / : ? space tab lf cr
*/
-static const unsigned char direct_tab[128/8] =
+static const unsigned char direct_tab[128 / 8] =
{
0x00, 0x26, 0x00, 0x00, 0x81, 0xf3, 0xff, 0x87,
0xfe, 0xff, 0xff, 0x07, 0xfe, 0xff, 0xff, 0x07
};
-static inline int
+static int
isdirect (uint32_t ch)
{
return (ch < 128 && ((direct_tab[ch >> 3] >> (ch & 7)) & 1));
! " # $ % & * ; < = > @ [ ] ^ _ ` { | }
*/
-static const unsigned char xdirect_tab[128/8] =
+static const unsigned char xdirect_tab[128 / 8] =
{
0x00, 0x26, 0x00, 0x00, 0xff, 0xf7, 0xff, 0xff,
0xff, 0xff, 0xff, 0xef, 0xff, 0xff, 0xff, 0x3f
};
-static inline int
+static int
isxdirect (uint32_t ch)
{
return (ch < 128 && ((xdirect_tab[ch >> 3] >> (ch & 7)) & 1));
A-Z a-z 0-9 + / -
*/
-static const unsigned char xbase64_tab[128/8] =
+static const unsigned char xbase64_tab[128 / 8] =
{
0x00, 0x00, 0x00, 0x00, 0x00, 0xa8, 0xff, 0x03,
0xfe, 0xff, 0xff, 0x07, 0xfe, 0xff, 0xff, 0x07
};
-static inline int
+static int
isxbase64 (uint32_t ch)
{
return (ch < 128 && ((xbase64_tab[ch >> 3] >> (ch & 7)) & 1));
/* Converts a value in the range 0..63 to a base64 encoded char. */
-static inline unsigned char
+static unsigned char
base64 (unsigned int i)
{
if (i < 26)
#define MAX_NEEDED_FROM 6
#define MIN_NEEDED_TO 4
#define MAX_NEEDED_TO 4
+#define ONE_DIRECTION 0
#define PREPARE_LOOP \
mbstate_t saved_state; \
mbstate_t *statep = data->__statep;
put32 (outptr, ch); \
outptr += 4; \
} \
- else if (__builtin_expect (ch == '+', 1)) \
+ else if (__glibc_likely (ch == '+')) \
{ \
- if (__builtin_expect (inptr + 2 >= inend, 0)) \
+ if (__glibc_unlikely (inptr + 2 > inend)) \
{ \
/* Not enough input available. */ \
result = __GCONV_INCOMPLETE_INPUT; \
else \
{ \
/* The input is invalid. */ \
- if (! ignore_errors_p ()) \
- { \
- result = __GCONV_ILLEGAL_INPUT; \
- break; \
- } \
- \
- ++inptr; \
- ++*irreversible; \
+ STANDARD_FROM_LOOP_ERR_HANDLER (1); \
} \
} \
else \
if (__builtin_expect (statep->__value.__wch != 0, 0) \
|| __builtin_expect ((statep->__count >> 3) <= 26, 0)) \
{ \
- if (! ignore_errors_p ()) \
- { \
- result = __GCONV_ILLEGAL_INPUT; \
- break; \
- } \
- \
- ++inptr; \
- ++*irreversible; \
- statep->__count = 0; \
- continue; \
+ STANDARD_FROM_LOOP_ERR_HANDLER ((statep->__count = 0, 1)); \
} \
\
if (ch == '-') \
\
if (! __builtin_expect (wc2 >= 0xdc00 && wc2 < 0xe000, 1)) \
{ \
- if (! ignore_errors_p ()) \
- { \
- result = __GCONV_ILLEGAL_INPUT; \
- break; \
- } \
- \
- ++inptr; \
- ++*irreversible; \
- statep->__count = 0; \
- continue; \
+ STANDARD_FROM_LOOP_ERR_HANDLER ((statep->__count = 0, 1));\
} \
} \
\
else if (ch < 0x110000) \
count = 6; \
else \
- STANDARD_ERR_HANDLER (4); \
+ STANDARD_TO_LOOP_ERR_HANDLER (4); \
\
- if (__builtin_expect (outptr + count > outend, 0)) \
+ if (__glibc_unlikely (outptr + count > outend)) \
{ \
result = __GCONV_FULL_OUTPUT; \
break; \
size_t count; \
\
count = ((statep->__count & 0x18) >= 0x10) + isxbase64 (ch) + 1; \
- if (__builtin_expect (outptr + count > outend, 0)) \
+ if (__glibc_unlikely (outptr + count > outend)) \
{ \
result = __GCONV_FULL_OUTPUT; \
break; \
else if (ch < 0x110000) \
count = ((statep->__count & 0x18) >= 0x18 ? 6 : 5); \
else \
- STANDARD_ERR_HANDLER (4); \
+ STANDARD_TO_LOOP_ERR_HANDLER (4); \
\
- if (__builtin_expect (outptr + count > outend, 0)) \
+ if (__glibc_unlikely (outptr + count > outend)) \
{ \
result = __GCONV_FULL_OUTPUT; \
break; \
/* Deactivate base64 encoding. */ \
size_t count = ((state & 0x18) >= 0x10) + 1; \
\
- if (__builtin_expect (outbuf + count > outend, 0)) \
+ if (__glibc_unlikely (outbuf + count > outend)) \
/* We don't have enough room in the output buffer. */ \
status = __GCONV_FULL_OUTPUT; \
else \