33static size_t mb_qprint_to_wchar(
unsigned char **in,
size_t *in_len, uint32_t *
buf,
size_t bufsize,
unsigned int *
state);
36static const char *mbfl_encoding_qprint_aliases[] = {
"qprint",
NULL};
42 mbfl_encoding_qprint_aliases,
74#define CK(statement) do { if ((statement) < 0) return (-1); } while (0)
84 switch (filter->
status & 0xff) {
92 n = (filter->
status & 0xff00) >> 8;
100 if (
s ==
'\n' || (
s ==
'\r' && c !=
'\n')) {
103 filter->
status &= ~0xff00;
105 }
else if (
s == 0x0d) {
113 filter->
status &= ~0xff00;
148 filter->
status &= ~0xffff;
158static int hex2code_map[] = {
159 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
160 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
161 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
162 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
163 -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
164 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
165 -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
166 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
167 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
168 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
169 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
170 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
171 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
172 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
173 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
174 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
186 if (hex2code_map[c & 0xff] >= 0) {
189 }
else if (c == 0x0d) {
191 }
else if (c == 0x0a) {
200 m = hex2code_map[c & 0xff];
206 n = hex2code_map[filter->
cache] << 4 | m;
234 cache = filter->
cache;
252static size_t mb_qprint_to_wchar(
unsigned char **in,
size_t *in_len, uint32_t *
buf,
size_t bufsize,
unsigned int *
state)
254 unsigned char *
p = *in, *e =
p + *in_len;
255 uint32_t *
out =
buf, *limit =
buf + bufsize - 2;
257 while (
p < e &&
out < limit) {
258 unsigned char c = *
p++;
260 if (c ==
'=' &&
p < e) {
261 unsigned char c2 = *
p++;
263 if (hex2code_map[c2] >= 0 &&
p < e) {
264 unsigned char c3 = *
p++;
266 if (hex2code_map[c3] >= 0) {
267 *
out++ = hex2code_map[c2] << 4 | hex2code_map[c3];
273 }
else if (c2 ==
'\r' &&
p < e) {
274 unsigned char c3 = *
p++;
279 }
else if (c2 !=
'\n') {
293static unsigned char qprint_enc_nibble(
unsigned char nibble)
298 return nibble - 10 +
'A';
304 unsigned char *
out, *limit;
308 unsigned int chars_output =
buf->state;
316 out = mb_convert_buf_add(
out,
'\0');
319 }
else if (w ==
'\n') {
321 out = mb_convert_buf_add2(
out,
'\r',
'\n');
324 }
else if (w ==
'\r') {
331 if (chars_output >= 72) {
333 out = mb_convert_buf_add3(
out,
'=',
'\r',
'\n');
337 if (w >= 0x80 || w ==
'=') {
340 out = mb_convert_buf_add3(
out,
'=', qprint_enc_nibble((w >> 4) & 0xF), qprint_enc_nibble(w & 0xF));
344 out = mb_convert_buf_add(
out, w);
349 buf->state = chars_output;
zend_ffi_ctype_name_buf buf
int mbfl_filt_conv_qprintenc(int c, mbfl_convert_filter *filter)
const struct mbfl_convert_vtbl vtbl_qprint_8bit
int mbfl_filt_conv_qprintdec_flush(mbfl_convert_filter *filter)
int mbfl_filt_conv_qprintdec(int c, mbfl_convert_filter *filter)
const mbfl_encoding mbfl_encoding_qprint
int mbfl_filt_conv_qprintenc_flush(mbfl_convert_filter *filter)
const struct mbfl_convert_vtbl vtbl_8bit_qprint
#define MBFL_ENCTYPE_GL_UNSAFE
void mbfl_filt_conv_common_ctor(mbfl_convert_filter *filter)
struct _mbfl_convert_filter mbfl_convert_filter
@ mbfl_no_encoding_qprint
#define MB_CONVERT_BUF_STORE(buf, _out, _limit)
#define MB_CONVERT_BUF_ENSURE(buf, out, limit, needed)
#define MB_CONVERT_BUF_LOAD(buf, _out, _limit)
unsigned const char * end
output_function_t output_function
int(* filter_function)(int c, mbfl_convert_filter *filter)
flush_function_t flush_function