Skip to content

Commit 648c1cb

Browse files
committed
Add identify filter for UCS-2, UCS-2BE, and UCS-2LE encodings
1 parent 374f31e commit 648c1cb

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

ext/mbstring/libmbfl/filters/mbfilter_ucs2.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#include "mbfilter.h"
3131
#include "mbfilter_ucs2.h"
3232

33+
static int mbfl_filt_ident_ucs2(int c, mbfl_identify_filter *filter);
34+
3335
static const char *mbfl_encoding_ucs2_aliases[] = {"ISO-10646-UCS-2", "UCS2" , "UNICODE", NULL};
3436

3537
const mbfl_encoding mbfl_encoding_ucs2 = {
@@ -65,6 +67,24 @@ const mbfl_encoding mbfl_encoding_ucs2le = {
6567
&vtbl_wchar_ucs2le
6668
};
6769

70+
const struct mbfl_identify_vtbl vtbl_identify_ucs2 = {
71+
mbfl_no_encoding_ucs2,
72+
mbfl_filt_ident_common_ctor,
73+
mbfl_filt_ident_ucs2
74+
};
75+
76+
const struct mbfl_identify_vtbl vtbl_identify_ucs2be = {
77+
mbfl_no_encoding_ucs2be,
78+
mbfl_filt_ident_common_ctor,
79+
mbfl_filt_ident_ucs2
80+
};
81+
82+
const struct mbfl_identify_vtbl vtbl_identify_ucs2le = {
83+
mbfl_no_encoding_ucs2le,
84+
mbfl_filt_ident_common_ctor,
85+
mbfl_filt_ident_ucs2
86+
};
87+
6888
const struct mbfl_convert_vtbl vtbl_ucs2_wchar = {
6989
mbfl_no_encoding_ucs2,
7090
mbfl_no_encoding_wchar,
@@ -237,3 +257,10 @@ int mbfl_filt_conv_wchar_ucs2le(int c, mbfl_convert_filter *filter)
237257

238258
return c;
239259
}
260+
261+
static int mbfl_filt_ident_ucs2(int c, mbfl_identify_filter *filter)
262+
{
263+
/* Input string must be a multiple of 2 bytes */
264+
filter->status = (filter->status + 1) % 2;
265+
return c;
266+
}

ext/mbstring/libmbfl/filters/mbfilter_ucs2.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
extern const mbfl_encoding mbfl_encoding_ucs2;
3636
extern const mbfl_encoding mbfl_encoding_ucs2be;
3737
extern const mbfl_encoding mbfl_encoding_ucs2le;
38+
extern const struct mbfl_identify_vtbl vtbl_identify_ucs2;
39+
extern const struct mbfl_identify_vtbl vtbl_identify_ucs2be;
40+
extern const struct mbfl_identify_vtbl vtbl_identify_ucs2le;
3841
extern const struct mbfl_convert_vtbl vtbl_ucs2_wchar;
3942
extern const struct mbfl_convert_vtbl vtbl_wchar_ucs2;
4043
extern const struct mbfl_convert_vtbl vtbl_ucs2be_wchar;

ext/mbstring/libmbfl/mbfl/mbfl_ident.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ static const struct mbfl_identify_vtbl *mbfl_identify_filter_list[] = {
164164
&vtbl_identify_utf16le,
165165
&vtbl_identify_utf16be,
166166
&vtbl_identify_8bit,
167+
&vtbl_identify_ucs2,
168+
&vtbl_identify_ucs2be,
169+
&vtbl_identify_ucs2le,
167170
&vtbl_identify_false,
168171
NULL
169172
};

0 commit comments

Comments
 (0)