summaryrefslogtreecommitdiff
path: root/ext/mbstring/libmbfl/filters
diff options
context:
space:
mode:
authorAlex Dowad <alexinbeijing@gmail.com>2020-11-04 19:54:02 +0200
committerAlex Dowad <alexinbeijing@gmail.com>2020-11-09 13:45:16 +0200
commitcc03c54c369a1a7dfc71b58f4a59edc46c3f9171 (patch)
tree85600fc79b9ae4f1be31a56bbb91c648d3327000 /ext/mbstring/libmbfl/filters
parent3eb8828d1a1027219969007f030e68a5936c2ea9 (diff)
downloadphp-git-cc03c54c369a1a7dfc71b58f4a59edc46c3f9171.tar.gz
Remove useless byte{2,4}{be,le} encodings from mbstring
There is no meaningful difference between these and UCS-{2,4}. They are just a little bit more lax about passing errors silently. They also have no known use. Alias to UCS-{2,4} in case someone, somewhere is using them.
Diffstat (limited to 'ext/mbstring/libmbfl/filters')
-rw-r--r--ext/mbstring/libmbfl/filters/mbfilter_byte2.c142
-rw-r--r--ext/mbstring/libmbfl/filters/mbfilter_byte2.h48
-rw-r--r--ext/mbstring/libmbfl/filters/mbfilter_byte4.c162
-rw-r--r--ext/mbstring/libmbfl/filters/mbfilter_byte4.h46
-rw-r--r--ext/mbstring/libmbfl/filters/mbfilter_ucs2.c11
-rw-r--r--ext/mbstring/libmbfl/filters/mbfilter_ucs4.c10
6 files changed, 17 insertions, 402 deletions
diff --git a/ext/mbstring/libmbfl/filters/mbfilter_byte2.c b/ext/mbstring/libmbfl/filters/mbfilter_byte2.c
deleted file mode 100644
index 72b5b2b7b2..0000000000
--- a/ext/mbstring/libmbfl/filters/mbfilter_byte2.c
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * "streamable kanji code filter and converter"
- * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved.
- *
- * LICENSE NOTICES
- *
- * This file is part of "streamable kanji code filter and converter",
- * which is distributed under the terms of GNU Lesser General Public
- * License (version 2) as published by the Free Software Foundation.
- *
- * This software 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 Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with "streamable kanji code filter and converter";
- * if not, write to the Free Software Foundation, Inc., 59 Temple Place,
- * Suite 330, Boston, MA 02111-1307 USA
- *
- * The author of this file:
- *
- */
-/*
- * The source code included in this files was separated from mbfilter.c
- * by Moriyoshi Koizumi <moriyoshi@php.net> on 4 Dec 2002. The file
- * mbfilter.c is included in this package .
- *
- */
-
-#include "mbfilter.h"
-#include "mbfilter_byte2.h"
-
-const mbfl_encoding mbfl_encoding_byte2be = {
- mbfl_no_encoding_byte2be,
- "byte2be",
- NULL,
- NULL,
- NULL,
- MBFL_ENCTYPE_SBCS,
- &vtbl_byte2be_wchar,
- &vtbl_wchar_byte2be
-};
-
-const mbfl_encoding mbfl_encoding_byte2le = {
- mbfl_no_encoding_byte2le,
- "byte2le",
- NULL,
- NULL,
- NULL,
- MBFL_ENCTYPE_SBCS,
- &vtbl_byte2le_wchar,
- &vtbl_wchar_byte2le
-};
-
-const struct mbfl_convert_vtbl vtbl_byte2be_wchar = {
- mbfl_no_encoding_byte2be,
- mbfl_no_encoding_wchar,
- mbfl_filt_conv_common_ctor,
- NULL,
- mbfl_filt_conv_byte2be_wchar,
- mbfl_filt_conv_common_flush,
- NULL,
-};
-
-const struct mbfl_convert_vtbl vtbl_wchar_byte2be = {
- mbfl_no_encoding_wchar,
- mbfl_no_encoding_byte2be,
- mbfl_filt_conv_common_ctor,
- NULL,
- mbfl_filt_conv_wchar_byte2be,
- mbfl_filt_conv_common_flush,
- NULL,
-};
-
-const struct mbfl_convert_vtbl vtbl_byte2le_wchar = {
- mbfl_no_encoding_byte2le,
- mbfl_no_encoding_wchar,
- mbfl_filt_conv_common_ctor,
- NULL,
- mbfl_filt_conv_byte2le_wchar,
- mbfl_filt_conv_common_flush,
- NULL,
-};
-
-const struct mbfl_convert_vtbl vtbl_wchar_byte2le = {
- mbfl_no_encoding_wchar,
- mbfl_no_encoding_byte2le,
- mbfl_filt_conv_common_ctor,
- NULL,
- mbfl_filt_conv_wchar_byte2le,
- mbfl_filt_conv_common_flush,
- NULL,
-};
-
-#define CK(statement) do { if ((statement) < 0) return (-1); } while (0)
-
-int mbfl_filt_conv_byte2be_wchar(int c, mbfl_convert_filter *filter)
-{
- int n;
-
- if (filter->status == 0) {
- filter->status = 1;
- n = (c & 0xff) << 8;
- filter->cache = n;
- } else {
- filter->status = 0;
- n = (c & 0xff) | filter->cache;
- CK((*filter->output_function)(n, filter->data));
- }
- return c;
-}
-
-int mbfl_filt_conv_wchar_byte2be(int c, mbfl_convert_filter *filter)
-{
- CK((*filter->output_function)((c >> 8) & 0xff, filter->data));
- CK((*filter->output_function)(c & 0xff, filter->data));
- return c;
-}
-
-int mbfl_filt_conv_byte2le_wchar(int c, mbfl_convert_filter *filter)
-{
- int n;
-
- if (filter->status == 0) {
- filter->status = 1;
- n = c & 0xff;
- filter->cache = n;
- } else {
- filter->status = 0;
- n = ((c & 0xff) << 8) | filter->cache;
- CK((*filter->output_function)(n, filter->data));
- }
- return c;
-}
-
-int mbfl_filt_conv_wchar_byte2le(int c, mbfl_convert_filter *filter)
-{
- CK((*filter->output_function)(c & 0xff, filter->data));
- CK((*filter->output_function)((c >> 8) & 0xff, filter->data));
- return c;
-}
diff --git a/ext/mbstring/libmbfl/filters/mbfilter_byte2.h b/ext/mbstring/libmbfl/filters/mbfilter_byte2.h
deleted file mode 100644
index 8b1d991810..0000000000
--- a/ext/mbstring/libmbfl/filters/mbfilter_byte2.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * "streamable kanji code filter and converter"
- * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved.
- *
- * LICENSE NOTICES
- *
- * This file is part of "streamable kanji code filter and converter",
- * which is distributed under the terms of GNU Lesser General Public
- * License (version 2) as published by the Free Software Foundation.
- *
- * This software 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 Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with "streamable kanji code filter and converter";
- * if not, write to the Free Software Foundation, Inc., 59 Temple Place,
- * Suite 330, Boston, MA 02111-1307 USA
- *
- * The author of this file:
- *
- */
-/*
- * The source code included in this files was separated from mbfilter.c
- * by Moriyoshi Koizumi <moriyoshi@php.net> on 4 Dec 2002. The file
- * mbfilter.c is included in this package .
- *
- */
-
-#ifndef MBFL_MBFILTER_BYTE2_H
-#define MBFL_MBFILTER_BYTE2_H
-
-#include "mbfilter.h"
-
-extern const mbfl_encoding mbfl_encoding_byte2be;
-extern const mbfl_encoding mbfl_encoding_byte2le;
-extern const struct mbfl_convert_vtbl vtbl_byte2be_wchar;
-extern const struct mbfl_convert_vtbl vtbl_wchar_byte2be;
-extern const struct mbfl_convert_vtbl vtbl_byte2le_wchar;
-extern const struct mbfl_convert_vtbl vtbl_wchar_byte2le;
-
-int mbfl_filt_conv_wchar_byte2be(int c, mbfl_convert_filter *filter);
-int mbfl_filt_conv_byte2be_wchar(int c, mbfl_convert_filter *filter);
-int mbfl_filt_conv_wchar_byte2le(int c, mbfl_convert_filter *filter);
-int mbfl_filt_conv_byte2le_wchar(int c, mbfl_convert_filter *filter);
-
-#endif /* MBFL_MBFILTER_BYTE2_H */
diff --git a/ext/mbstring/libmbfl/filters/mbfilter_byte4.c b/ext/mbstring/libmbfl/filters/mbfilter_byte4.c
deleted file mode 100644
index b566e54772..0000000000
--- a/ext/mbstring/libmbfl/filters/mbfilter_byte4.c
+++ /dev/null
@@ -1,162 +0,0 @@
-/*
- * "streamable kanji code filter and converter"
- * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved.
- *
- * LICENSE NOTICES
- *
- * This file is part of "streamable kanji code filter and converter",
- * which is distributed under the terms of GNU Lesser General Public
- * License (version 2) as published by the Free Software Foundation.
- *
- * This software 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 Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with "streamable kanji code filter and converter";
- * if not, write to the Free Software Foundation, Inc., 59 Temple Place,
- * Suite 330, Boston, MA 02111-1307 USA
- *
- * The author of this file:
- *
- */
-/*
- * The source code included in this files was separated from mbfilter.c
- * by Moriyoshi Koizumi <moriyoshi@php.net> on 4 Dec 2002. The file
- * mbfilter.c is included in this package .
- *
- */
-
-#include "mbfilter.h"
-#include "mbfilter_byte4.h"
-
-const mbfl_encoding mbfl_encoding_byte4be = {
- mbfl_no_encoding_byte4be,
- "byte4be",
- NULL,
- NULL,
- NULL,
- MBFL_ENCTYPE_SBCS,
- &vtbl_byte4be_wchar,
- &vtbl_wchar_byte4be
-};
-
-const mbfl_encoding mbfl_encoding_byte4le = {
- mbfl_no_encoding_byte4le,
- "byte4le",
- NULL,
- NULL,
- NULL,
- MBFL_ENCTYPE_SBCS,
- &vtbl_byte4le_wchar,
- &vtbl_wchar_byte4le
-};
-
-const struct mbfl_convert_vtbl vtbl_byte4be_wchar = {
- mbfl_no_encoding_byte4be,
- mbfl_no_encoding_wchar,
- mbfl_filt_conv_common_ctor,
- NULL,
- mbfl_filt_conv_byte4be_wchar,
- mbfl_filt_conv_common_flush,
- NULL,
-};
-
-const struct mbfl_convert_vtbl vtbl_wchar_byte4be = {
- mbfl_no_encoding_wchar,
- mbfl_no_encoding_byte4be,
- mbfl_filt_conv_common_ctor,
- NULL,
- mbfl_filt_conv_wchar_byte4be,
- mbfl_filt_conv_common_flush,
- NULL,
-};
-
-const struct mbfl_convert_vtbl vtbl_byte4le_wchar = {
- mbfl_no_encoding_byte4le,
- mbfl_no_encoding_wchar,
- mbfl_filt_conv_common_ctor,
- NULL,
- mbfl_filt_conv_byte4le_wchar,
- mbfl_filt_conv_common_flush,
- NULL,
-};
-
-const struct mbfl_convert_vtbl vtbl_wchar_byte4le = {
- mbfl_no_encoding_wchar,
- mbfl_no_encoding_byte4le,
- mbfl_filt_conv_common_ctor,
- NULL,
- mbfl_filt_conv_wchar_byte4le,
- mbfl_filt_conv_common_flush,
- NULL,
-};
-
-#define CK(statement) do { if ((statement) < 0) return (-1); } while (0)
-
-int mbfl_filt_conv_byte4be_wchar(int c, mbfl_convert_filter *filter)
-{
- int n;
-
- if (filter->status == 0) {
- filter->status = 1;
- n = (c & 0xff) << 24;
- filter->cache = n;
- } else if (filter->status == 1) {
- filter->status = 2;
- n = (c & 0xff) << 16;
- filter->cache |= n;
- } else if (filter->status == 2) {
- filter->status = 3;
- n = (c & 0xff) << 8;
- filter->cache |= n;
- } else {
- filter->status = 0;
- n = (c & 0xff) | filter->cache;
- CK((*filter->output_function)(n, filter->data));
- }
- return c;
-}
-
-int mbfl_filt_conv_wchar_byte4be(int c, mbfl_convert_filter *filter)
-{
- CK((*filter->output_function)((c >> 24) & 0xff, filter->data));
- CK((*filter->output_function)((c >> 16) & 0xff, filter->data));
- CK((*filter->output_function)((c >> 8) & 0xff, filter->data));
- CK((*filter->output_function)(c & 0xff, filter->data));
- return c;
-}
-
-int mbfl_filt_conv_byte4le_wchar(int c, mbfl_convert_filter *filter)
-{
- int n;
-
- if (filter->status == 0) {
- filter->status = 1;
- n = (c & 0xff);
- filter->cache = n;
- } else if (filter->status == 1) {
- filter->status = 2;
- n = (c & 0xff) << 8;
- filter->cache |= n;
- } else if (filter->status == 2) {
- filter->status = 3;
- n = (c & 0xff) << 16;
- filter->cache |= n;
- } else {
- filter->status = 0;
- n = ((c & 0xff) << 24) | filter->cache;
- CK((*filter->output_function)(n, filter->data));
- }
- return c;
-}
-
-int mbfl_filt_conv_wchar_byte4le(int c, mbfl_convert_filter *filter)
-{
- CK((*filter->output_function)(c & 0xff, filter->data));
- CK((*filter->output_function)((c >> 8) & 0xff, filter->data));
- CK((*filter->output_function)((c >> 16) & 0xff, filter->data));
- CK((*filter->output_function)((c >> 24) & 0xff, filter->data));
- return c;
-}
diff --git a/ext/mbstring/libmbfl/filters/mbfilter_byte4.h b/ext/mbstring/libmbfl/filters/mbfilter_byte4.h
deleted file mode 100644
index 572a2cf477..0000000000
--- a/ext/mbstring/libmbfl/filters/mbfilter_byte4.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * "streamable kanji code filter and converter"
- * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved.
- *
- * LICENSE NOTICES
- *
- * This file is part of "streamable kanji code filter and converter",
- * which is distributed under the terms of GNU Lesser General Public
- * License (version 2) as published by the Free Software Foundation.
- *
- * This software 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 Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with "streamable kanji code filter and converter";
- * if not, write to the Free Software Foundation, Inc., 59 Temple Place,
- * Suite 330, Boston, MA 02111-1307 USA
- *
- * The author of this file:
- *
- */
-/*
- * The source code included in this files was separated from mbfilter.c
- * by Moriyoshi Koizumi <moriyoshi@php.net> on 4 Dec 2002. The file
- * mbfilter.c is included in this package .
- *
- */
-
-#ifndef MBFL_MBFILTER_BYTE4_H
-#define MBFL_MBFILTER_BYTE4_H
-
-extern const mbfl_encoding mbfl_encoding_byte4be;
-extern const mbfl_encoding mbfl_encoding_byte4le;
-extern const struct mbfl_convert_vtbl vtbl_byte4be_wchar;
-extern const struct mbfl_convert_vtbl vtbl_wchar_byte4be;
-extern const struct mbfl_convert_vtbl vtbl_byte4le_wchar;
-extern const struct mbfl_convert_vtbl vtbl_wchar_byte4le;
-
-int mbfl_filt_conv_wchar_byte4be(int c, mbfl_convert_filter *filter);
-int mbfl_filt_conv_byte4be_wchar(int c, mbfl_convert_filter *filter);
-int mbfl_filt_conv_wchar_byte4le(int c, mbfl_convert_filter *filter);
-int mbfl_filt_conv_byte4le_wchar(int c, mbfl_convert_filter *filter);
-
-#endif /* MBFL_MBFILTER_BYTE4_H */
diff --git a/ext/mbstring/libmbfl/filters/mbfilter_ucs2.c b/ext/mbstring/libmbfl/filters/mbfilter_ucs2.c
index 258c564aae..84d94fcd26 100644
--- a/ext/mbstring/libmbfl/filters/mbfilter_ucs2.c
+++ b/ext/mbstring/libmbfl/filters/mbfilter_ucs2.c
@@ -34,6 +34,13 @@ static int mbfl_filt_ident_ucs2(int c, mbfl_identify_filter *filter);
static const char *mbfl_encoding_ucs2_aliases[] = {"ISO-10646-UCS-2", "UCS2" , "UNICODE", NULL};
+/* This library historically had encodings called 'byte2be' and 'byte2le'
+ * which were almost identical to UCS-2, except that they would truncate
+ * Unicode codepoints higher than 0xFFFF quietly
+ * Maintain minimal support by aliasing to UCS-2 */
+static const char *mbfl_encoding_ucs2be_aliases[] = {"byte2be", NULL};
+static const char *mbfl_encoding_ucs2le_aliases[] = {"byte2le", NULL};
+
const mbfl_encoding mbfl_encoding_ucs2 = {
mbfl_no_encoding_ucs2,
"UCS-2",
@@ -49,7 +56,7 @@ const mbfl_encoding mbfl_encoding_ucs2be = {
mbfl_no_encoding_ucs2be,
"UCS-2BE",
"UCS-2BE",
- NULL,
+ mbfl_encoding_ucs2be_aliases,
NULL,
MBFL_ENCTYPE_WCS2BE,
&vtbl_ucs2be_wchar,
@@ -60,7 +67,7 @@ const mbfl_encoding mbfl_encoding_ucs2le = {
mbfl_no_encoding_ucs2le,
"UCS-2LE",
"UCS-2LE",
- NULL,
+ mbfl_encoding_ucs2le_aliases,
NULL,
MBFL_ENCTYPE_WCS2LE,
&vtbl_ucs2le_wchar,
diff --git a/ext/mbstring/libmbfl/filters/mbfilter_ucs4.c b/ext/mbstring/libmbfl/filters/mbfilter_ucs4.c
index 396bae91c5..96ef6fbf6d 100644
--- a/ext/mbstring/libmbfl/filters/mbfilter_ucs4.c
+++ b/ext/mbstring/libmbfl/filters/mbfilter_ucs4.c
@@ -32,6 +32,12 @@
static const char *mbfl_encoding_ucs4_aliases[] = {"ISO-10646-UCS-4", "UCS4", NULL};
+/* This library historically had encodings called 'byte4be' and 'byte4le'
+ * which were almost identical to UCS-4
+ * Maintain minimal support by aliasing to UCS-2 */
+static const char *mbfl_encoding_ucs4be_aliases[] = {"byte4be", NULL};
+static const char *mbfl_encoding_ucs4le_aliases[] = {"byte4le", NULL};
+
const mbfl_encoding mbfl_encoding_ucs4 = {
mbfl_no_encoding_ucs4,
"UCS-4",
@@ -47,7 +53,7 @@ const mbfl_encoding mbfl_encoding_ucs4be = {
mbfl_no_encoding_ucs4be,
"UCS-4BE",
"UCS-4BE",
- NULL,
+ mbfl_encoding_ucs4be_aliases,
NULL,
MBFL_ENCTYPE_WCS4BE,
&vtbl_ucs4be_wchar,
@@ -58,7 +64,7 @@ const mbfl_encoding mbfl_encoding_ucs4le = {
mbfl_no_encoding_ucs4le,
"UCS-4LE",
"UCS-4LE",
- NULL,
+ mbfl_encoding_ucs4le_aliases,
NULL,
MBFL_ENCTYPE_WCS4LE,
&vtbl_ucs4le_wchar,