]> granicus.if.org Git - php/commitdiff
Add identify filter for UCS-2, UCS-2BE, and UCS-2LE encodings
authorAlex Dowad <alexinbeijing@gmail.com>
Sun, 6 Sep 2020 11:13:37 +0000 (13:13 +0200)
committerAlex Dowad <alexinbeijing@gmail.com>
Tue, 13 Oct 2020 18:26:14 +0000 (20:26 +0200)
ext/mbstring/libmbfl/filters/mbfilter_ucs2.c
ext/mbstring/libmbfl/filters/mbfilter_ucs2.h
ext/mbstring/libmbfl/mbfl/mbfl_ident.c

index 9df11cb1d029b953c3a970e0c1514f5cc69c595a..258c564aae05e2b5fed096b2828f400658a1aee5 100644 (file)
@@ -30,6 +30,8 @@
 #include "mbfilter.h"
 #include "mbfilter_ucs2.h"
 
+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};
 
 const mbfl_encoding mbfl_encoding_ucs2 = {
@@ -65,6 +67,24 @@ const mbfl_encoding mbfl_encoding_ucs2le = {
        &vtbl_wchar_ucs2le
 };
 
+const struct mbfl_identify_vtbl vtbl_identify_ucs2 = {
+       mbfl_no_encoding_ucs2,
+       mbfl_filt_ident_common_ctor,
+       mbfl_filt_ident_ucs2
+};
+
+const struct mbfl_identify_vtbl vtbl_identify_ucs2be = {
+       mbfl_no_encoding_ucs2be,
+       mbfl_filt_ident_common_ctor,
+       mbfl_filt_ident_ucs2
+};
+
+const struct mbfl_identify_vtbl vtbl_identify_ucs2le = {
+       mbfl_no_encoding_ucs2le,
+       mbfl_filt_ident_common_ctor,
+       mbfl_filt_ident_ucs2
+};
+
 const struct mbfl_convert_vtbl vtbl_ucs2_wchar = {
        mbfl_no_encoding_ucs2,
        mbfl_no_encoding_wchar,
@@ -237,3 +257,10 @@ int mbfl_filt_conv_wchar_ucs2le(int c, mbfl_convert_filter *filter)
 
        return c;
 }
+
+static int mbfl_filt_ident_ucs2(int c, mbfl_identify_filter *filter)
+{
+       /* Input string must be a multiple of 2 bytes */
+       filter->status = (filter->status + 1) % 2;
+       return c;
+}
index bbf567a49339b294e1621b6a876b887769782bed..f6d9b8b77289c89cc295ac5d299b231d56c643c8 100644 (file)
@@ -35,6 +35,9 @@
 extern const mbfl_encoding mbfl_encoding_ucs2;
 extern const mbfl_encoding mbfl_encoding_ucs2be;
 extern const mbfl_encoding mbfl_encoding_ucs2le;
+extern const struct mbfl_identify_vtbl vtbl_identify_ucs2;
+extern const struct mbfl_identify_vtbl vtbl_identify_ucs2be;
+extern const struct mbfl_identify_vtbl vtbl_identify_ucs2le;
 extern const struct mbfl_convert_vtbl vtbl_ucs2_wchar;
 extern const struct mbfl_convert_vtbl vtbl_wchar_ucs2;
 extern const struct mbfl_convert_vtbl vtbl_ucs2be_wchar;
index e6163d538ca45af390bdf159994e059dc77b7f8f..a92d55daa3eda427a048482a4869e8cb99139a5f 100644 (file)
@@ -164,6 +164,9 @@ static const struct mbfl_identify_vtbl *mbfl_identify_filter_list[] = {
        &vtbl_identify_utf16le,
        &vtbl_identify_utf16be,
        &vtbl_identify_8bit,
+       &vtbl_identify_ucs2,
+       &vtbl_identify_ucs2be,
+       &vtbl_identify_ucs2le,
        &vtbl_identify_false,
        NULL
 };