php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
mbfilter_8bit.c
Go to the documentation of this file.
1/*
2 * "streamable kanji code filter and converter"
3 * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved.
4 *
5 * LICENSE NOTICES
6 *
7 * This file is part of "streamable kanji code filter and converter",
8 * which is distributed under the terms of GNU Lesser General Public
9 * License (version 2) as published by the Free Software Foundation.
10 *
11 * This software 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
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with "streamable kanji code filter and converter";
18 * if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19 * Suite 330, Boston, MA 02111-1307 USA
20 *
21 * The author of this file:
22 *
23 */
24/*
25 * The source code included in this files was separated from mbfilter.c
26 * by Moriyoshi Koizumi <moriyoshi@php.net> on 20 Dec 2002. The file
27 * mbfilter.c is included in this package .
28 *
29 */
30
31#include <stddef.h>
32
33#include "mbfilter.h"
34
37static int mbfl_filt_conv_8bit_wchar(int c, mbfl_convert_filter *filter);
38static int mbfl_filt_conv_wchar_8bit(int c, mbfl_convert_filter *filter);
39static size_t mb_8bit_to_wchar(unsigned char **in, size_t *in_len, uint32_t *buf, size_t bufsize, unsigned int *state);
40static void mb_wchar_to_8bit(uint32_t *in, size_t len, mb_convert_buf *buf, bool end);
41
42static const char *mbfl_encoding_8bit_aliases[] = {"binary", NULL};
43
46 "8bit",
47 "8bit",
48 mbfl_encoding_8bit_aliases,
49 NULL,
53 mb_8bit_to_wchar,
54 mb_wchar_to_8bit,
55 NULL,
56 NULL,
57};
58
63 NULL,
64 mbfl_filt_conv_8bit_wchar,
66 NULL,
67};
68
73 NULL,
74 mbfl_filt_conv_wchar_8bit,
76 NULL,
77};
78
79#define CK(statement) do { if ((statement) < 0) return (-1); } while (0)
80
81static int mbfl_filt_conv_8bit_wchar(int c, mbfl_convert_filter *filter)
82{
83 return (*filter->output_function)(c, filter->data);
84}
85
86static int mbfl_filt_conv_wchar_8bit(int c, mbfl_convert_filter *filter)
87{
88 if (c >= 0 && c < 0x100) {
89 CK((*filter->output_function)(c, filter->data));
90 } else {
92 }
93
94 return 0;
95}
96
97static size_t mb_8bit_to_wchar(unsigned char **in, size_t *in_len, uint32_t *buf, size_t bufsize, unsigned int *state)
98{
99 unsigned char *p = *in, *e = p + *in_len;
100 uint32_t *out = buf, *limit = buf + bufsize;
101
102 while (p < e && out < limit) {
103 unsigned char c = *p++;
104 *out++ = c;
105 }
106
107 *in_len = e - p;
108 *in = p;
109 return out - buf;
110}
111
112static void mb_wchar_to_8bit(uint32_t *in, size_t len, mb_convert_buf *buf, bool end)
113{
114 unsigned char *out, *limit;
115 MB_CONVERT_BUF_LOAD(buf, out, limit);
117
118 while (len--) {
119 uint32_t w = *in++;
120 if (w <= 0xFF) {
121 out = mb_convert_buf_add(out, w);
122 } else {
123 MB_CONVERT_ERROR(buf, out, limit, w, mb_wchar_to_8bit);
125 }
126 }
127
129}
size_t len
Definition apprentice.c:174
zend_ffi_ctype_name_buf buf
Definition ffi.c:4685
#define NULL
Definition gdcache.h:45
const struct mbfl_convert_vtbl vtbl_wchar_8bit
#define CK(statement)
const struct mbfl_convert_vtbl vtbl_8bit_wchar
const mbfl_encoding mbfl_encoding_8bit
#define MBFL_ENCTYPE_SBCS
Definition mbfl_consts.h:34
int mbfl_filt_conv_common_flush(mbfl_convert_filter *filter)
int mbfl_filt_conv_illegal_output(int c, mbfl_convert_filter *filter)
void mbfl_filt_conv_common_ctor(mbfl_convert_filter *filter)
struct _mbfl_convert_filter mbfl_convert_filter
@ mbfl_no_encoding_wchar
@ mbfl_no_encoding_8bit
#define MB_CONVERT_BUF_STORE(buf, _out, _limit)
#define MB_CONVERT_BUF_ENSURE(buf, out, limit, needed)
#define MB_CONVERT_ERROR(buf, out, limit, bad_cp, conv_fn)
#define MB_CONVERT_BUF_LOAD(buf, _out, _limit)
unsigned const char * end
Definition php_ffi.h:51
p
Definition session.c:1105
output_function_t output_function
out($f, $s)