summaryrefslogtreecommitdiff
path: root/ext/mbstring/libmbfl/mbfl
diff options
context:
space:
mode:
Diffstat (limited to 'ext/mbstring/libmbfl/mbfl')
-rw-r--r--ext/mbstring/libmbfl/mbfl/Makefile.am2
-rw-r--r--ext/mbstring/libmbfl/mbfl/Makefile.bcc3218
-rw-r--r--ext/mbstring/libmbfl/mbfl/eaw_table.h4
-rw-r--r--ext/mbstring/libmbfl/mbfl/mbfilter.c757
-rw-r--r--ext/mbstring/libmbfl/mbfl/mbfilter.h4
-rw-r--r--ext/mbstring/libmbfl/mbfl/mbfilter_8bit.h2
-rw-r--r--ext/mbstring/libmbfl/mbfl/mbfilter_pass.h4
-rw-r--r--ext/mbstring/libmbfl/mbfl/mbfilter_wchar.h2
-rw-r--r--ext/mbstring/libmbfl/mbfl/mbfl_convert.c176
-rw-r--r--ext/mbstring/libmbfl/mbfl/mbfl_convert.h7
-rw-r--r--ext/mbstring/libmbfl/mbfl/mbfl_encoding.c14
-rw-r--r--ext/mbstring/libmbfl/mbfl/mbfl_encoding.h9
-rw-r--r--ext/mbstring/libmbfl/mbfl/mbfl_filter_output.c12
-rw-r--r--ext/mbstring/libmbfl/mbfl/mbfl_filter_output.h1
-rw-r--r--ext/mbstring/libmbfl/mbfl/mbfl_ident.c9
15 files changed, 480 insertions, 541 deletions
diff --git a/ext/mbstring/libmbfl/mbfl/Makefile.am b/ext/mbstring/libmbfl/mbfl/Makefile.am
index 6e662d14e..6774d8879 100644
--- a/ext/mbstring/libmbfl/mbfl/Makefile.am
+++ b/ext/mbstring/libmbfl/mbfl/Makefile.am
@@ -1,4 +1,4 @@
-EXTRA_DIST=Makefile.bcc32 mk_eaw_tbl.awk
+EXTRA_DIST=mk_eaw_tbl.awk
lib_LTLIBRARIES=libmbfl.la
libmbfl_la_SOURCES=mbfilter.c \
mbfl_string.c \
diff --git a/ext/mbstring/libmbfl/mbfl/Makefile.bcc32 b/ext/mbstring/libmbfl/mbfl/Makefile.bcc32
deleted file mode 100644
index 1b43a49ef..000000000
--- a/ext/mbstring/libmbfl/mbfl/Makefile.bcc32
+++ /dev/null
@@ -1,18 +0,0 @@
-!include ..\rules.mak.bcc32
-OBJS=mbfilter.obj \
- mbfilter_8bit.obj \
- mbfilter_pass.obj \
- mbfilter_wchar.obj \
- mbfl_allocators.obj \
- mbfl_convert.obj \
- mbfl_encoding.obj \
- mbfl_filter_output.obj \
- mbfl_ident.obj \
- mbfl_language.obj \
- mbfl_memory_device.obj \
- mbfl_string.obj
-
-all: $(OBJS)
-
-clean:
- @for %i in ($(OBJS)) do @if exist %i del %i
diff --git a/ext/mbstring/libmbfl/mbfl/eaw_table.h b/ext/mbstring/libmbfl/mbfl/eaw_table.h
index 95c895df1..a4f1e4fdf 100644
--- a/ext/mbstring/libmbfl/mbfl/eaw_table.h
+++ b/ext/mbstring/libmbfl/mbfl/eaw_table.h
@@ -2,7 +2,7 @@ static const struct {
int begin;
int end;
} mbfl_eaw_table[] = {
- { 0x1100, 0x1159 },
+ { 0x1100, 0x1159 },
{ 0x115f, 0x115f },
{ 0x2329, 0x232a },
{ 0x2e80, 0x2e99 },
@@ -32,5 +32,5 @@ static const struct {
{ 0xff01, 0xff60 },
{ 0xffe0, 0xffe6 },
{ 0x20000, 0x2fffd },
- { 0x30000, 0x3fffd }
+ { 0x30000, 0x3fffd }
};
diff --git a/ext/mbstring/libmbfl/mbfl/mbfilter.c b/ext/mbstring/libmbfl/mbfl/mbfilter.c
index 4997c5a88..d11cebe44 100644
--- a/ext/mbstring/libmbfl/mbfl/mbfilter.c
+++ b/ext/mbstring/libmbfl/mbfl/mbfilter.c
@@ -102,6 +102,7 @@
#include "mbfilter.h"
#include "mbfl_filter_output.h"
#include "mbfilter_pass.h"
+#include "filters/mbfilter_tl_jisx0201_jisx0208.h"
#include "eaw_table.h"
@@ -149,11 +150,15 @@ mbfl_buffer_converter_new(
convd->filter1 = NULL;
convd->filter2 = NULL;
if (mbfl_convert_filter_get_vtbl(convd->from->no_encoding, convd->to->no_encoding) != NULL) {
- convd->filter1 = mbfl_convert_filter_new(convd->from->no_encoding, convd->to->no_encoding, mbfl_memory_device_output, 0, &convd->device);
+ convd->filter1 = mbfl_convert_filter_new(convd->from->no_encoding, convd->to->no_encoding, mbfl_memory_device_output, NULL, &convd->device);
} else {
- convd->filter2 = mbfl_convert_filter_new(mbfl_no_encoding_wchar, convd->to->no_encoding, mbfl_memory_device_output, 0, &convd->device);
+ convd->filter2 = mbfl_convert_filter_new(mbfl_no_encoding_wchar, convd->to->no_encoding, mbfl_memory_device_output, NULL, &convd->device);
if (convd->filter2 != NULL) {
- convd->filter1 = mbfl_convert_filter_new(convd->from->no_encoding, mbfl_no_encoding_wchar, (int (*)(int, void*))convd->filter2->filter_function, NULL, convd->filter2);
+ convd->filter1 = mbfl_convert_filter_new(convd->from->no_encoding,
+ mbfl_no_encoding_wchar,
+ (int (*)(int, void*))convd->filter2->filter_function,
+ (int (*)(void*))convd->filter2->filter_flush,
+ convd->filter2);
if (convd->filter1 == NULL) {
mbfl_convert_filter_delete(convd->filter2);
}
@@ -468,7 +473,8 @@ enum mbfl_no_encoding mbfl_encoding_detector_judge(mbfl_encoding_detector *ident
}
n--;
}
-
+
+ /* fallback judge */
if (encoding == mbfl_no_encoding_invalid) {
n = identd->filter_list_size - 1;
while (n >= 0) {
@@ -477,7 +483,7 @@ enum mbfl_no_encoding mbfl_encoding_detector_judge(mbfl_encoding_detector *ident
encoding = filter->encoding->no_encoding;
}
n--;
- }
+ }
}
}
@@ -611,8 +617,8 @@ mbfl_identify_encoding(mbfl_string *string, enum mbfl_no_encoding *elist, int el
filter = &flist[i];
if (!filter->flag) {
if (strict && filter->status) {
- continue;
- }
+ continue;
+ }
encoding = filter->encoding;
break;
}
@@ -628,7 +634,7 @@ mbfl_identify_encoding(mbfl_string *string, enum mbfl_no_encoding *elist, int el
}
}
}
-
+
/* cleanup */
/* dtors should be called in reverse order */
i = num; while (--i >= 0) {
@@ -1326,7 +1332,6 @@ mbfl_substr(
return result;
}
-
/*
* strcut
*/
@@ -1338,183 +1343,280 @@ mbfl_strcut(
int length)
{
const mbfl_encoding *encoding;
- int n, m, k, len, start, end;
- unsigned char *p, *w;
- const unsigned char *mbtab;
mbfl_memory_device device;
- mbfl_convert_filter *encoder, *encoder_tmp, *decoder, *decoder_tmp;
+
+ /* validate the parameters */
+ if (string == NULL || string->val == NULL || result == NULL) {
+ return NULL;
+ }
+
+ if (from < 0 || length < 0) {
+ return NULL;
+ }
+
+ if (from >= string->len) {
+ from = string->len;
+ }
encoding = mbfl_no2encoding(string->no_encoding);
- if (encoding == NULL || string == NULL || result == NULL) {
+ if (encoding == NULL) {
return NULL;
}
+
mbfl_string_init(result);
result->no_language = string->no_language;
result->no_encoding = string->no_encoding;
- if ((encoding->flag & (MBFL_ENCTYPE_SBCS | MBFL_ENCTYPE_WCS2BE | MBFL_ENCTYPE_WCS2LE | MBFL_ENCTYPE_WCS4BE | MBFL_ENCTYPE_WCS4LE)) ||
- encoding->mblen_table != NULL) {
- len = string->len;
- start = from;
- end = from + length;
+ if ((encoding->flag & (MBFL_ENCTYPE_SBCS
+ | MBFL_ENCTYPE_WCS2BE
+ | MBFL_ENCTYPE_WCS2LE
+ | MBFL_ENCTYPE_WCS4BE
+ | MBFL_ENCTYPE_WCS4LE))
+ || encoding->mblen_table != NULL) {
+ const unsigned char *start = NULL;
+ const unsigned char *end = NULL;
+ unsigned char *w;
+ unsigned int sz;
+
if (encoding->flag & (MBFL_ENCTYPE_WCS2BE | MBFL_ENCTYPE_WCS2LE)) {
- start /= 2;
- start *= 2;
- end = length/2;
- end *= 2;
- end += start;
+ from &= -2;
+
+ if (from + length >= string->len) {
+ length = string->len - from;
+ }
+
+ start = string->val + from;
+ end = start + (length & -2);
} else if (encoding->flag & (MBFL_ENCTYPE_WCS4BE | MBFL_ENCTYPE_WCS4LE)) {
- start /= 4;
- start *= 4;
- end = length/4;
- end *= 4;
- end += start;
+ from &= -4;
+
+ if (from + length >= string->len) {
+ length = string->len - from;
+ }
+
+ start = string->val + from;
+ end = start + (length & -4);
+ } else if ((encoding->flag & MBFL_ENCTYPE_SBCS)) {
+ start = string->val + from;
+ end = start + length;
} else if (encoding->mblen_table != NULL) {
- mbtab = encoding->mblen_table;
- start = 0;
- end = 0;
- n = 0;
- p = string->val;
- if (p != NULL) {
- /* search start position */
- for (;;) {
- m = mbtab[*p];
- n += m;
- p += m;
- if (n > from) {
- break;
- }
- start = n;
- }
- /* search end position */
- k = start + length;
- if (k >= (int)string->len) {
- end = string->len;
- } else {
- end = start;
- while (n <= k) {
- end = n;
- m = mbtab[*p];
- n += m;
- p += m;
- }
+ const unsigned char *mbtab = encoding->mblen_table;
+ const unsigned char *p, *q;
+ int m;
+
+ /* search start position */
+ for (m = 0, p = string->val, q = p + from;
+ p < q; p += (m = mbtab[*p]));
+
+ if (p > q) {
+ p -= m;
+ }
+
+ start = p;
+
+ /* search end position */
+ if ((start - string->val) + length >= (int)string->len) {
+ end = string->val + string->len;
+ } else {
+ for (q = p + length; p < q; p += (m = mbtab[*p]));
+
+ if (p > q) {
+ p -= m;
}
+ end = p;
}
+ } else {
+ /* never reached */
+ return NULL;
}
- if (start > len) {
- start = len;
- }
- if (start < 0) {
- start = 0;
- }
- if (end > len) {
- end = len;
- }
- if (end < 0) {
- end = 0;
- }
- if (start > end) {
- start = end;
- }
/* allocate memory and copy string */
- n = end - start;
- result->len = 0;
- result->val = w = (unsigned char*)mbfl_malloc((n + 8)*sizeof(unsigned char));
- if (w != NULL) {
- result->len = n;
- p = &(string->val[start]);
- while (n > 0) {
- *w++ = *p++;
- n--;
- }
- *w++ = '\0';
- *w++ = '\0';
- *w++ = '\0';
- *w = '\0';
- } else {
- result = NULL;
+ sz = end - start;
+ if ((w = (unsigned char*)mbfl_calloc(sz + 8,
+ sizeof(unsigned char))) == NULL) {
+ return NULL;
}
+
+ memcpy(w, start, sz);
+ w[sz] = '\0';
+ w[sz + 1] = '\0';
+ w[sz + 2] = '\0';
+ w[sz + 3] = '\0';
+
+ result->val = w;
+ result->len = sz;
} else {
- /* wchar filter */
- encoder = mbfl_convert_filter_new(
- string->no_encoding,
- mbfl_no_encoding_wchar,
- mbfl_filter_output_null, 0, 0);
- encoder_tmp = mbfl_convert_filter_new(
- string->no_encoding,
- mbfl_no_encoding_wchar,
- mbfl_filter_output_null, 0, 0);
+ mbfl_convert_filter *encoder = NULL;
+ mbfl_convert_filter *decoder = NULL;
+ const unsigned char *p, *q, *r;
+ struct {
+ mbfl_convert_filter encoder;
+ mbfl_convert_filter decoder;
+ const unsigned char *p;
+ int pos;
+ } bk, _bk;
+
/* output code filter */
- decoder = mbfl_convert_filter_new(
- mbfl_no_encoding_wchar,
- string->no_encoding,
- mbfl_memory_device_output, 0, &device);
- decoder_tmp = mbfl_convert_filter_new(
- mbfl_no_encoding_wchar,
- string->no_encoding,
- mbfl_memory_device_output, 0, &device);
- if (encoder == NULL || encoder_tmp == NULL || decoder == NULL || decoder_tmp == NULL) {
- mbfl_convert_filter_delete(encoder);
- mbfl_convert_filter_delete(encoder_tmp);
+ if (!(decoder = mbfl_convert_filter_new(
+ mbfl_no_encoding_wchar,
+ string->no_encoding,
+ mbfl_memory_device_output, 0, &device))) {
+ return NULL;
+ }
+
+ /* wchar filter */
+ if (!(encoder = mbfl_convert_filter_new(
+ string->no_encoding,
+ mbfl_no_encoding_wchar,
+ mbfl_filter_output_null,
+ NULL, NULL))) {
mbfl_convert_filter_delete(decoder);
- mbfl_convert_filter_delete(decoder_tmp);
return NULL;
}
+
mbfl_memory_device_init(&device, length + 8, 0);
- k = 0;
- n = 0;
+
p = string->val;
- if (p != NULL) {
- /* seartch start position */
- while (n < from) {
- (*encoder->filter_function)(*p++, encoder);
- n++;
- }
+
+ /* search start position */
+ for (q = string->val + from; p < q; p++) {
+ (*encoder->filter_function)(*p, encoder);
+ }
+
+ /* switch the drain direction */
+ encoder->output_function = (int(*)(int,void *))decoder->filter_function;
+ encoder->flush_function = (int(*)(void *))decoder->filter_flush;
+ encoder->data = decoder;
+
+ q = string->val + string->len;
+
+ /* save the encoder, decoder state and the pointer */
+ mbfl_convert_filter_copy(decoder, &_bk.decoder);
+ mbfl_convert_filter_copy(encoder, &_bk.encoder);
+ _bk.p = p;
+ _bk.pos = device.pos;
+
+ if (length > q - p) {
+ length = q - p;
+ }
+
+ if (length >= 20) {
/* output a little shorter than "length" */
- encoder->output_function = mbfl_filter_output_pipe;
- encoder->data = decoder;
- k = length - 20;
- len = string->len;
- while (n < len && device.pos < k) {
- (*encoder->filter_function)(*p++, encoder);
- n++;
- }
- /* detect end position */
- for (;;) {
- /* backup current state */
- k = device.pos;
- mbfl_convert_filter_copy(encoder, encoder_tmp);
- mbfl_convert_filter_copy(decoder, decoder_tmp);
- if (n >= len) {
- break;
- }
- /* feed 1byte and flush */
+ /* XXX: the constant "20" was determined purely on the heuristics. */
+ for (r = p + length - 20; p < r; p++) {
(*encoder->filter_function)(*p, encoder);
+ }
+
+ /* if the offset of the resulting string exceeds the length,
+ * then restore the state */
+ if (device.pos > length) {
+ p = _bk.p;
+ device.pos = _bk.pos;
+ decoder->filter_dtor(decoder);
+ encoder->filter_dtor(encoder);
+ mbfl_convert_filter_copy(&_bk.decoder, decoder);
+ mbfl_convert_filter_copy(&_bk.encoder, encoder);
+ bk = _bk;
+ } else {
+ /* save the encoder, decoder state and the pointer */
+ mbfl_convert_filter_copy(decoder, &bk.decoder);
+ mbfl_convert_filter_copy(encoder, &bk.encoder);
+ bk.p = p;
+ bk.pos = device.pos;
+
+ /* flush the stream */
(*encoder->filter_flush)(encoder);
- (*decoder->filter_flush)(decoder);
+
+ /* if the offset of the resulting string exceeds the length,
+ * then restore the state */
if (device.pos > length) {
- break;
+ bk.decoder.filter_dtor(&bk.decoder);
+ bk.encoder.filter_dtor(&bk.encoder);
+
+ p = _bk.p;
+ device.pos = _bk.pos;
+ decoder->filter_dtor(decoder);
+ encoder->filter_dtor(encoder);
+ mbfl_convert_filter_copy(&_bk.decoder, decoder);
+ mbfl_convert_filter_copy(&_bk.encoder, encoder);
+ bk = _bk;
+ } else {
+ _bk.decoder.filter_dtor(&_bk.decoder);
+ _bk.encoder.filter_dtor(&_bk.encoder);
+
+ p = bk.p;
+ device.pos = bk.pos;
+ decoder->filter_dtor(decoder);
+ encoder->filter_dtor(encoder);
+ mbfl_convert_filter_copy(&bk.decoder, decoder);
+ mbfl_convert_filter_copy(&bk.encoder, encoder);
}
- /* restore filter and re-feed data */
- device.pos = k;
- mbfl_convert_filter_copy(encoder_tmp, encoder);
- mbfl_convert_filter_copy(decoder_tmp, decoder);
- (*encoder->filter_function)(*p, encoder);
- p++;
- n++;
}
- device.pos = k;
- mbfl_convert_filter_copy(encoder_tmp, encoder);
- mbfl_convert_filter_copy(decoder_tmp, decoder);
- mbfl_convert_filter_flush(encoder);
- mbfl_convert_filter_flush(decoder);
+ } else {
+ bk = _bk;
+ }
+
+ /* detect end position */
+ while (p < q) {
+ (*encoder->filter_function)(*p, encoder);
+
+ if (device.pos > length) {
+ /* restore filter */
+ p = bk.p;
+ device.pos = bk.pos;
+ decoder->filter_dtor(decoder);
+ encoder->filter_dtor(encoder);
+ mbfl_convert_filter_copy(&bk.decoder, decoder);
+ mbfl_convert_filter_copy(&bk.encoder, encoder);
+ break;
+ }
+
+ p++;
+
+ /* backup current state */
+ mbfl_convert_filter_copy(decoder, &_bk.decoder);
+ mbfl_convert_filter_copy(encoder, &_bk.encoder);
+ _bk.pos = device.pos;
+ _bk.p = p;
+
+ (*encoder->filter_flush)(encoder);
+
+ if (device.pos > length) {
+ _bk.decoder.filter_dtor(&_bk.decoder);
+ _bk.encoder.filter_dtor(&_bk.encoder);
+
+ /* restore filter */
+ p = bk.p;
+ device.pos = bk.pos;
+ decoder->filter_dtor(decoder);
+ encoder->filter_dtor(encoder);
+ mbfl_convert_filter_copy(&bk.decoder, decoder);
+ mbfl_convert_filter_copy(&bk.encoder, encoder);
+ break;
+ }
+
+ bk.decoder.filter_dtor(&bk.decoder);
+ bk.encoder.filter_dtor(&bk.encoder);
+
+ p = _bk.p;
+ device.pos = _bk.pos;
+ decoder->filter_dtor(decoder);
+ encoder->filter_dtor(encoder);
+ mbfl_convert_filter_copy(&_bk.decoder, decoder);
+ mbfl_convert_filter_copy(&_bk.encoder, encoder);
+
+ bk = _bk;
}
+
+ (*encoder->filter_flush)(encoder);
+
+ bk.decoder.filter_dtor(&bk.decoder);
+ bk.encoder.filter_dtor(&bk.encoder);
+
result = mbfl_memory_device_result(&device, result);
+
mbfl_convert_filter_delete(encoder);
- mbfl_convert_filter_delete(encoder_tmp);
mbfl_convert_filter_delete(decoder);
- mbfl_convert_filter_delete(decoder_tmp);
}
return result;
@@ -1731,276 +1833,6 @@ mbfl_strimwidth(
return result;
}
-
-
-/*
- * convert Hankaku and Zenkaku
- */
-struct collector_hantozen_data {
- mbfl_convert_filter *next_filter;
- int mode;
- int status;
- int cache;
-};
-
-static const unsigned char hankana2zenkata_table[64] = {
- 0x00,0x02,0x0C,0x0D,0x01,0xFB,0xF2,0xA1,0xA3,0xA5,
- 0xA7,0xA9,0xE3,0xE5,0xE7,0xC3,0xFC,0xA2,0xA4,0xA6,
- 0xA8,0xAA,0xAB,0xAD,0xAF,0xB1,0xB3,0xB5,0xB7,0xB9,
- 0xBB,0xBD,0xBF,0xC1,0xC4,0xC6,0xC8,0xCA,0xCB,0xCC,
- 0xCD,0xCE,0xCF,0xD2,0xD5,0xD8,0xDB,0xDE,0xDF,0xE0,
- 0xE1,0xE2,0xE4,0xE6,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,
- 0xEF,0xF3,0x9B,0x9C
-};
-static const unsigned char hankana2zenhira_table[64] = {
- 0x00,0x02,0x0C,0x0D,0x01,0xFB,0x92,0x41,0x43,0x45,
- 0x47,0x49,0x83,0x85,0x87,0x63,0xFC,0x42,0x44,0x46,
- 0x48,0x4A,0x4B,0x4D,0x4F,0x51,0x53,0x55,0x57,0x59,
- 0x5B,0x5D,0x5F,0x61,0x64,0x66,0x68,0x6A,0x6B,0x6C,
- 0x6D,0x6E,0x6F,0x72,0x75,0x78,0x7B,0x7E,0x7F,0x80,
- 0x81,0x82,0x84,0x86,0x88,0x89,0x8A,0x8B,0x8C,0x8D,
- 0x8F,0x93,0x9B,0x9C
-};
-static const unsigned char zenkana2hankana_table[84][2] = {
- {0x67,0x00},{0x71,0x00},{0x68,0x00},{0x72,0x00},{0x69,0x00},
- {0x73,0x00},{0x6A,0x00},{0x74,0x00},{0x6B,0x00},{0x75,0x00},
- {0x76,0x00},{0x76,0x9E},{0x77,0x00},{0x77,0x9E},{0x78,0x00},
- {0x78,0x9E},{0x79,0x00},{0x79,0x9E},{0x7A,0x00},{0x7A,0x9E},
- {0x7B,0x00},{0x7B,0x9E},{0x7C,0x00},{0x7C,0x9E},{0x7D,0x00},
- {0x7D,0x9E},{0x7E,0x00},{0x7E,0x9E},{0x7F,0x00},{0x7F,0x9E},
- {0x80,0x00},{0x80,0x9E},{0x81,0x00},{0x81,0x9E},{0x6F,0x00},
- {0x82,0x00},{0x82,0x9E},{0x83,0x00},{0x83,0x9E},{0x84,0x00},
- {0x84,0x9E},{0x85,0x00},{0x86,0x00},{0x87,0x00},{0x88,0x00},
- {0x89,0x00},{0x8A,0x00},{0x8A,0x9E},{0x8A,0x9F},{0x8B,0x00},
- {0x8B,0x9E},{0x8B,0x9F},{0x8C,0x00},{0x8C,0x9E},{0x8C,0x9F},
- {0x8D,0x00},{0x8D,0x9E},{0x8D,0x9F},{0x8E,0x00},{0x8E,0x9E},
- {0x8E,0x9F},{0x8F,0x00},{0x90,0x00},{0x91,0x00},{0x92,0x00},
- {0x93,0x00},{0x6C,0x00},{0x94,0x00},{0x6D,0x00},{0x95,0x00},
- {0x6E,0x00},{0x96,0x00},{0x97,0x00},{0x98,0x00},{0x99,0x00},
- {0x9A,0x00},{0x9B,0x00},{0x9C,0x00},{0x9C,0x00},{0x72,0x00},
- {0x74,0x00},{0x66,0x00},{0x9D,0x00},{0x73,0x9E}
-};
-
-static int
-collector_hantozen(int c, void* data)
-{
- int s, mode, n;
- struct collector_hantozen_data *pc = (struct collector_hantozen_data*)data;
-
- s = c;
- mode = pc->mode;
-
- if (mode & 0xf) { /* hankaku to zenkaku */
- if ((mode & 0x1) && c >= 0x21 && c <= 0x7d && c != 0x22 && c != 0x27 && c != 0x5c) { /* all except <"> <'> <\> <~> */
- s = c + 0xfee0;
- } else if ((mode & 0x2) && ((c >= 0x41 && c <= 0x5a) || (c >= 0x61 && c <= 0x7a))) { /* alpha */
- s = c + 0xfee0;
- } else if ((mode & 0x4) && c >= 0x30 && c <= 0x39) { /* num */
- s = c + 0xfee0;
- } else if ((mode & 0x8) && c == 0x20) { /* spase */
- s = 0x3000;
- }
- }
-
- if (mode & 0xf0) { /* zenkaku to hankaku */
- if ((mode & 0x10) && c >= 0xff01 && c <= 0xff5d && c != 0xff02 && c != 0xff07 && c!= 0xff3c) { /* all except <"> <'> <\> <~> */
- s = c - 0xfee0;
- } else if ((mode & 0x20) && ((c >= 0xff21 && c <= 0xff3a) || (c >= 0xff41 && c <= 0xff5a))) { /* alpha */
- s = c - 0xfee0;
- } else if ((mode & 0x40) && (c >= 0xff10 && c <= 0xff19)) { /* num */
- s = c - 0xfee0;
- } else if ((mode & 0x80) && (c == 0x3000)) { /* spase */
- s = 0x20;
- } else if ((mode & 0x10) && (c == 0x2212)) { /* MINUS SIGN */
- s = 0x2d;
- }
- }
-
- if (mode & 0x300) { /* hankaku kana to zenkaku kana */
- if ((mode & 0x100) && (mode & 0x800)) { /* hankaku kana to zenkaku katakana and glue voiced sound mark */
- if (c >= 0xff61 && c <= 0xff9f) {
- if (pc->status) {
- n = (pc->cache - 0xff60) & 0x3f;
- if (c == 0xff9e && ((n >= 22 && n <= 36) || (n >= 42 && n <= 46))) {
- pc->status = 0;
- s = 0x3001 + hankana2zenkata_table[n];
- } else if (c == 0xff9e && n == 19) {
- pc->status = 0;
- s = 0x30f4;
- } else if (c == 0xff9f && (n >= 42 && n <= 46)) {
- pc->status = 0;
- s = 0x3002 + hankana2zenkata_table[n];
- } else {
- pc->status = 1;
- pc->cache = c;
- s = 0x3000 + hankana2zenkata_table[n];
- }
- } else {
- pc->status = 1;
- pc->cache = c;
- return c;
- }
- } else {
- if (pc->status) {
- n = (pc->cache - 0xff60) & 0x3f;
- pc->status = 0;
- (*pc->next_filter->filter_function)(0x3000 + hankana2zenkata_table[n], pc->next_filter);
- }
- }
- } else if ((mode & 0x200) && (mode & 0x800)) { /* hankaku kana to zenkaku hirangana and glue voiced sound mark */
- if (c >= 0xff61 && c <= 0xff9f) {
- if (pc->status) {
- n = (pc->cache - 0xff60) & 0x3f;
- if (c == 0xff9e && ((n >= 22 && n <= 36) || (n >= 42 && n <= 46))) {
- pc->status = 0;
- s = 0x3001 + hankana2zenhira_table[n];
- } else if (c == 0xff9f && (n >= 42 && n <= 46)) {
- pc->status = 0;
- s = 0x3002 + hankana2zenhira_table[n];
- } else {
- pc->status = 1;
- pc->cache = c;
- s = 0x3000 + hankana2zenhira_table[n];
- }
- } else {
- pc->status = 1;
- pc->cache = c;
- return c;
- }
- } else {
- if (pc->status) {
- n = (pc->cache - 0xff60) & 0x3f;
- pc->status = 0;
- (*pc->next_filter->filter_function)(0x3000 + hankana2zenhira_table[n], pc->next_filter);
- }
- }
- } else if ((mode & 0x100) && c >= 0xff61 && c <= 0xff9f) { /* hankaku kana to zenkaku katakana */
- s = 0x3000 + hankana2zenkata_table[c - 0xff60];
- } else if ((mode & 0x200) && c >= 0xff61 && c <= 0xff9f) { /* hankaku kana to zenkaku hirangana */
- s = 0x3000 + hankana2zenhira_table[c - 0xff60];
- }
- }
-
- if (mode & 0x3000) { /* Zenkaku kana to hankaku kana */
- if ((mode & 0x1000) && c >= 0x30a1 && c <= 0x30f4) { /* Zenkaku katakana to hankaku kana */
- n = c - 0x30a1;
- if (zenkana2hankana_table[n][1] != 0) {
- (*pc->next_filter->filter_function)(0xff00 + zenkana2hankana_table[n][0], pc->next_filter);
- s = 0xff00 + zenkana2hankana_table[n][1];
- } else {
- s = 0xff00 + zenkana2hankana_table[n][0];
- }
- } else if ((mode & 0x2000) && c >= 0x3041 && c <= 0x3093) { /* Zenkaku hirangana to hankaku kana */
- n = c - 0x3041;
- if (zenkana2hankana_table[n][1] != 0) {
- (*pc->next_filter->filter_function)(0xff00 + zenkana2hankana_table[n][0], pc->next_filter);
- s = 0xff00 + zenkana2hankana_table[n][1];
- } else {
- s = 0xff00 + zenkana2hankana_table[n][0];
- }
- } else if (c == 0x3001) {
- s = 0xff64; /* HALFWIDTH IDEOGRAPHIC COMMA */
- } else if (c == 0x3002) {
- s = 0xff61; /* HALFWIDTH IDEOGRAPHIC FULL STOP */
- } else if (c == 0x300c) {
- s = 0xff62; /* HALFWIDTH LEFT CORNER BRACKET */
- } else if (c == 0x300d) {
- s = 0xff63; /* HALFWIDTH RIGHT CORNER BRACKET */
- } else if (c == 0x309b) {
- s = 0xff9e; /* HALFWIDTH KATAKANA VOICED SOUND MARK */
- } else if (c == 0x309c) {
- s = 0xff9f; /* HALFWIDTH KATAKANA SEMI-VOICED SOUND MARK */
- } else if (c == 0x30fc) {
- s = 0xff70; /* HALFWIDTH KATAKANA-HIRAGANA PROLONGED SOUND MARK */
- } else if (c == 0x30fb) {
- s = 0xff65; /* HALFWIDTH KATAKANA MIDDLE DOT */
- }
- } else if (mode & 0x30000) {
- if ((mode & 0x10000) && c >= 0x3041 && c <= 0x3093) { /* Zenkaku hirangana to Zenkaku katakana */
- s = c + 0x60;
- } else if ((mode & 0x20000) && c >= 0x30a1 && c <= 0x30f3) { /* Zenkaku katakana to Zenkaku hirangana */
- s = c - 0x60;
- }
- }
-
- if (mode & 0x100000) { /* special ascii to symbol */
- if (c == 0x5c) {
- s = 0xffe5; /* FULLWIDTH YEN SIGN */
- } else if (c == 0xa5) { /* YEN SIGN */
- s = 0xffe5; /* FULLWIDTH YEN SIGN */
- } else if (c == 0x7e) {
- s = 0xffe3; /* FULLWIDTH MACRON */
- } else if (c == 0x203e) { /* OVERLINE */
- s = 0xffe3; /* FULLWIDTH MACRON */
- } else if (c == 0x27) {
- s = 0x2019; /* RIGHT SINGLE QUOTATION MARK */
- } else if (c == 0x22) {
- s = 0x201d; /* RIGHT DOUBLE QUOTATION MARK */
- }
- } else if (mode & 0x200000) { /* special symbol to ascii */
- if (c == 0xffe5) { /* FULLWIDTH YEN SIGN */
- s = 0x5c;
- } else if (c == 0xff3c) { /* FULLWIDTH REVERSE SOLIDUS */
- s = 0x5c;
- } else if (c == 0xffe3) { /* FULLWIDTH MACRON */
- s = 0x7e;
- } else if (c == 0x203e) { /* OVERLINE */
- s = 0x7e;
- } else if (c == 0x2018) { /* LEFT SINGLE QUOTATION MARK*/
- s = 0x27;
- } else if (c == 0x2019) { /* RIGHT SINGLE QUOTATION MARK */
- s = 0x27;
- } else if (c == 0x201c) { /* LEFT DOUBLE QUOTATION MARK */
- s = 0x22;
- } else if (c == 0x201d) { /* RIGHT DOUBLE QUOTATION MARK */
- s = 0x22;
- }
- }
-
- if (mode & 0x400000) { /* special ascii to symbol */
- if (c == 0x5c) {
- s = 0xff3c; /* FULLWIDTH REVERSE SOLIDUS */
- } else if (c == 0x7e) {
- s = 0xff5e; /* FULLWIDTH TILDE */
- } else if (c == 0x27) {
- s = 0xff07; /* FULLWIDTH APOSTROPHE */
- } else if (c == 0x22) {
- s = 0xff02; /* FULLWIDTH QUOTATION MARK */
- }
- } else if (mode & 0x800000) { /* special symbol to ascii */
- if (c == 0xff3c) { /* FULLWIDTH REVERSE SOLIDUS */
- s = 0x5c;
- } else if (c == 0xff5e) { /* FULLWIDTH TILDE */
- s = 0x7e;
- } else if (c == 0xff07) { /* FULLWIDTH APOSTROPHE */
- s = 0x27;
- } else if (c == 0xff02) { /* FULLWIDTH QUOTATION MARK */
- s = 0x22;
- }
- }
-
- return (*pc->next_filter->filter_function)(s, pc->next_filter);
-}
-
-static int
-collector_hantozen_flush(struct collector_hantozen_data *pc)
-{
- int ret, n;
-
- ret = 0;
- if (pc->status) {
- n = (pc->cache - 0xff60) & 0x3f;
- if (pc->mode & 0x100) { /* hankaku kana to zenkaku katakana */
- ret = (*pc->next_filter->filter_function)(0x3000 + hankana2zenkata_table[n], pc->next_filter);
- } else if (pc->mode & 0x200) { /* hankaku kana to zenkaku hirangana */
- ret = (*pc->next_filter->filter_function)(0x3000 + hankana2zenhira_table[n], pc->next_filter);
- }
- pc->status = 0;
- }
-
- return ret;
-}
-
mbfl_string *
mbfl_ja_jp_hantozen(
mbfl_string *string,
@@ -2011,39 +1843,67 @@ mbfl_ja_jp_hantozen(
unsigned char *p;
const mbfl_encoding *encoding;
mbfl_memory_device device;
- struct collector_hantozen_data pc;
- mbfl_convert_filter *decoder;
- mbfl_convert_filter *encoder;
+ mbfl_convert_filter *decoder = NULL;
+ mbfl_convert_filter *encoder = NULL;
+ mbfl_convert_filter *tl_filter = NULL;
+ mbfl_convert_filter *next_filter = NULL;
+ mbfl_filt_tl_jisx0201_jisx0208_param *param = NULL;
- /* initialize */
+ /* validate parameters */
if (string == NULL || result == NULL) {
return NULL;
}
+
encoding = mbfl_no2encoding(string->no_encoding);
if (encoding == NULL) {
return NULL;
}
+
mbfl_memory_device_init(&device, string->len, 0);
mbfl_string_init(result);
+
result->no_language = string->no_language;
result->no_encoding = string->no_encoding;
+
decoder = mbfl_convert_filter_new(
- mbfl_no_encoding_wchar,
- string->no_encoding,
- mbfl_memory_device_output, 0, &device);
+ mbfl_no_encoding_wchar,
+ string->no_encoding,
+ mbfl_memory_device_output, 0, &device);
+ if (decoder == NULL) {
+ goto out;
+ }
+ next_filter = decoder;
+
+ param =
+ (mbfl_filt_tl_jisx0201_jisx0208_param *)mbfl_malloc(sizeof(mbfl_filt_tl_jisx0201_jisx0208_param));
+ if (param == NULL) {
+ goto out;
+ }
+
+ param->mode = mode;
+
+ tl_filter = mbfl_convert_filter_new2(
+ &vtbl_tl_jisx0201_jisx0208,
+ (int(*)(int, void*))next_filter->filter_function,
+ (int(*)(void*))next_filter->filter_flush,
+ next_filter);
+ if (tl_filter == NULL) {
+ mbfl_free(param);
+ goto out;
+ }
+
+ tl_filter->opaque = param;
+ next_filter = tl_filter;
+
encoder = mbfl_convert_filter_new(
- string->no_encoding,
- mbfl_no_encoding_wchar,
- collector_hantozen, 0, &pc);
- if (decoder == NULL || encoder == NULL) {
- mbfl_convert_filter_delete(encoder);
- mbfl_convert_filter_delete(decoder);
- return NULL;
+ string->no_encoding,
+ mbfl_no_encoding_wchar,
+ (int(*)(int, void*))next_filter->filter_function,
+ (int(*)(void*))next_filter->filter_flush,
+ next_filter);
+ if (encoder == NULL) {
+ goto out;
}
- pc.next_filter = decoder;
- pc.mode = mode;
- pc.status = 0;
- pc.cache = 0;
/* feed data */
p = string->val;
@@ -2058,11 +1918,22 @@ mbfl_ja_jp_hantozen(
}
mbfl_convert_filter_flush(encoder);
- collector_hantozen_flush(&pc);
- mbfl_convert_filter_flush(decoder);
result = mbfl_memory_device_result(&device, result);
- mbfl_convert_filter_delete(encoder);
- mbfl_convert_filter_delete(decoder);
+out:
+ if (tl_filter != NULL) {
+ if (tl_filter->opaque != NULL) {
+ mbfl_free(tl_filter->opaque);
+ }
+ mbfl_convert_filter_delete(tl_filter);
+ }
+
+ if (decoder != NULL) {
+ mbfl_convert_filter_delete(decoder);
+ }
+
+ if (encoder != NULL) {
+ mbfl_convert_filter_delete(encoder);
+ }
return result;
}
diff --git a/ext/mbstring/libmbfl/mbfl/mbfilter.h b/ext/mbstring/libmbfl/mbfl/mbfilter.h
index a00c51b5f..4565fc698 100644
--- a/ext/mbstring/libmbfl/mbfl/mbfilter.h
+++ b/ext/mbstring/libmbfl/mbfl/mbfilter.h
@@ -102,8 +102,8 @@
* version information
*/
#define MBFL_VERSION_MAJOR 1
-#define MBFL_VERSION_MINOR 0
-#define MBFL_VERSION_TEENY 2
+#define MBFL_VERSION_MINOR 1
+#define MBFL_VERSION_TEENY 0
/*
* convert filter
diff --git a/ext/mbstring/libmbfl/mbfl/mbfilter_8bit.h b/ext/mbstring/libmbfl/mbfl/mbfilter_8bit.h
index 4fc892260..a87c56461 100644
--- a/ext/mbstring/libmbfl/mbfl/mbfilter_8bit.h
+++ b/ext/mbstring/libmbfl/mbfl/mbfilter_8bit.h
@@ -34,6 +34,6 @@
#include "mbfl_defs.h"
#include "mbfilter.h"
-extern const mbfl_encoding mbfl_encoding_8bit;
+MBFLAPI extern const mbfl_encoding mbfl_encoding_8bit;
#endif /* MBFL_MBFILTER_8BIT_H */
diff --git a/ext/mbstring/libmbfl/mbfl/mbfilter_pass.h b/ext/mbstring/libmbfl/mbfl/mbfilter_pass.h
index 087aa2c3b..49d169c66 100644
--- a/ext/mbstring/libmbfl/mbfl/mbfilter_pass.h
+++ b/ext/mbstring/libmbfl/mbfl/mbfilter_pass.h
@@ -33,8 +33,8 @@
#include "mbfl_defs.h"
#include "mbfilter.h"
-extern const mbfl_encoding mbfl_encoding_pass;
-extern const struct mbfl_convert_vtbl vtbl_pass;
+MBFLAPI extern const mbfl_encoding mbfl_encoding_pass;
+MBFLAPI extern const struct mbfl_convert_vtbl vtbl_pass;
MBFLAPI extern int mbfl_filt_conv_pass(int c, mbfl_convert_filter *filter);
diff --git a/ext/mbstring/libmbfl/mbfl/mbfilter_wchar.h b/ext/mbstring/libmbfl/mbfl/mbfilter_wchar.h
index 24bf7473c..9e9396a77 100644
--- a/ext/mbstring/libmbfl/mbfl/mbfilter_wchar.h
+++ b/ext/mbstring/libmbfl/mbfl/mbfilter_wchar.h
@@ -34,6 +34,6 @@
#include "mbfl_defs.h"
#include "mbfilter.h"
-extern const mbfl_encoding mbfl_encoding_wchar;
+MBFLAPI extern const mbfl_encoding mbfl_encoding_wchar;
#endif /* MBFL_MBFILTER_WCHAR_H */
diff --git a/ext/mbstring/libmbfl/mbfl/mbfl_convert.c b/ext/mbstring/libmbfl/mbfl/mbfl_convert.c
index 725a674b3..d81b533dd 100644
--- a/ext/mbstring/libmbfl/mbfl/mbfl_convert.c
+++ b/ext/mbstring/libmbfl/mbfl/mbfl_convert.c
@@ -51,6 +51,7 @@
#include "filters/mbfilter_euc_kr.h"
#include "filters/mbfilter_iso2022_kr.h"
#include "filters/mbfilter_sjis.h"
+#include "filters/mbfilter_sjis_open.h"
#include "filters/mbfilter_cp51932.h"
#include "filters/mbfilter_jis.h"
#include "filters/mbfilter_iso2022_jp_ms.h"
@@ -65,6 +66,7 @@
#include "filters/mbfilter_cp1251.h"
#include "filters/mbfilter_cp1252.h"
#include "filters/mbfilter_cp1254.h"
+#include "filters/mbfilter_cp5022x.h"
#include "filters/mbfilter_iso8859_1.h"
#include "filters/mbfilter_iso8859_2.h"
#include "filters/mbfilter_iso8859_3.h"
@@ -95,8 +97,6 @@
#include "filters/mbfilter_armscii8.h"
#include "filters/mbfilter_cp850.h"
-static void mbfl_convert_filter_reset_vtbl(mbfl_convert_filter *filter);
-
/* hex character table "0123456789ABCDEF" */
static char mbfl_hexchar_table[] = {
0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x41,0x42,0x43,0x44,0x45,0x46
@@ -109,18 +109,22 @@ const struct mbfl_convert_vtbl *mbfl_convert_filter_list[] = {
&vtbl_wchar_eucjp,
&vtbl_sjis_wchar,
&vtbl_wchar_sjis,
+ &vtbl_sjis_open_wchar,
+ &vtbl_wchar_sjis_open,
&vtbl_cp51932_wchar,
&vtbl_wchar_cp51932,
&vtbl_jis_wchar,
&vtbl_wchar_jis,
+ &vtbl_jis_ms_wchar,
+ &vtbl_wchar_jis_ms,
&vtbl_2022jp_wchar,
&vtbl_wchar_2022jp,
&vtbl_2022jpms_wchar,
&vtbl_wchar_2022jpms,
&vtbl_eucjpwin_wchar,
&vtbl_wchar_eucjpwin,
- &vtbl_sjiswin_wchar,
- &vtbl_wchar_sjiswin,
+ &vtbl_cp932_wchar,
+ &vtbl_wchar_cp932,
&vtbl_euccn_wchar,
&vtbl_wchar_euccn,
&vtbl_cp936_wchar,
@@ -149,6 +153,14 @@ const struct mbfl_convert_vtbl *mbfl_convert_filter_list[] = {
&vtbl_wchar_cp1252,
&vtbl_cp1254_wchar,
&vtbl_wchar_cp1254,
+ &vtbl_cp50220_wchar,
+ &vtbl_wchar_cp50220,
+ &vtbl_cp50220raw_wchar,
+ &vtbl_wchar_cp50220raw,
+ &vtbl_cp50221_wchar,
+ &vtbl_wchar_cp50221,
+ &vtbl_cp50222_wchar,
+ &vtbl_wchar_cp50222,
&vtbl_ascii_wchar,
&vtbl_wchar_ascii,
&vtbl_8859_1_wchar,
@@ -230,6 +242,48 @@ const struct mbfl_convert_vtbl *mbfl_convert_filter_list[] = {
NULL
};
+static int
+mbfl_convert_filter_common_init(
+ mbfl_convert_filter *filter,
+ enum mbfl_no_encoding from,
+ enum mbfl_no_encoding to,
+ const struct mbfl_convert_vtbl *vtbl,
+ int (*output_function)(int, void* ),
+ int (*flush_function)(void*),
+ void* data)
+{
+ /* encoding structure */
+ if ((filter->from = mbfl_no2encoding(from)) == NULL) {
+ return 1;
+ }
+
+ if ((filter->to = mbfl_no2encoding(to)) == NULL) {
+ return 1;
+ }
+
+ if (output_function != NULL) {
+ filter->output_function = output_function;
+ } else {
+ filter->output_function = mbfl_filter_output_null;
+ }
+
+ filter->flush_function = flush_function;
+ filter->data = data;
+ filter->illegal_mode = MBFL_OUTPUTFILTER_ILLEGAL_MODE_CHAR;
+ filter->illegal_substchar = 0x3f; /* '?' */
+ filter->num_illegalchar = 0;
+ filter->filter_ctor = vtbl->filter_ctor;
+ filter->filter_dtor = vtbl->filter_dtor;
+ filter->filter_function = vtbl->filter_function;
+ filter->filter_flush = vtbl->filter_flush;
+ filter->filter_copy = vtbl->filter_copy;
+
+ (*filter->filter_ctor)(filter);
+
+ return 0;
+}
+
+
mbfl_convert_filter *
mbfl_convert_filter_new(
enum mbfl_no_encoding from,
@@ -239,6 +293,13 @@ mbfl_convert_filter_new(
void* data)
{
mbfl_convert_filter * filter;
+ const struct mbfl_convert_vtbl *vtbl;
+
+ vtbl = mbfl_convert_filter_get_vtbl(from, to);
+
+ if (vtbl == NULL) {
+ vtbl = &vtbl_pass;
+ }
/* allocate */
filter = (mbfl_convert_filter *)mbfl_malloc(sizeof(mbfl_convert_filter));
@@ -246,32 +307,39 @@ mbfl_convert_filter_new(
return NULL;
}
- /* encoding structure */
- filter->from = mbfl_no2encoding(from);
- filter->to = mbfl_no2encoding(to);
- if (filter->from == NULL) {
- filter->from = &mbfl_encoding_pass;
- }
- if (filter->to == NULL) {
- filter->to = &mbfl_encoding_pass;
+ if (mbfl_convert_filter_common_init(filter, from, to, vtbl,
+ output_function, flush_function, data)) {
+ mbfl_free(filter);
+ return NULL;
}
- if (output_function != NULL) {
- filter->output_function = output_function;
- } else {
- filter->output_function = mbfl_filter_output_null;
+ return filter;
+}
+
+mbfl_convert_filter *
+mbfl_convert_filter_new2(
+ const struct mbfl_convert_vtbl *vtbl,
+ int (*output_function)(int, void* ),
+ int (*flush_function)(void*),
+ void* data)
+{
+ mbfl_convert_filter * filter;
+
+ if (vtbl == NULL) {
+ vtbl = &vtbl_pass;
}
- filter->flush_function = flush_function;
- filter->data = data;
- filter->illegal_mode = MBFL_OUTPUTFILTER_ILLEGAL_MODE_CHAR;
- filter->illegal_substchar = 0x3f; /* '?' */
- filter->num_illegalchar = 0;
- /* setup the function table */
- mbfl_convert_filter_reset_vtbl(filter);
+ /* allocate */
+ filter = (mbfl_convert_filter *)mbfl_malloc(sizeof(mbfl_convert_filter));
+ if (filter == NULL) {
+ return NULL;
+ }
- /* constructor */
- (*filter->filter_ctor)(filter);
+ if (mbfl_convert_filter_common_init(filter, vtbl->from, vtbl->to, vtbl,
+ output_function, flush_function, data)) {
+ mbfl_free(filter);
+ return NULL;
+ }
return filter;
}
@@ -301,39 +369,32 @@ mbfl_convert_filter_flush(mbfl_convert_filter *filter)
void mbfl_convert_filter_reset(mbfl_convert_filter *filter,
enum mbfl_no_encoding from, enum mbfl_no_encoding to)
{
+ const struct mbfl_convert_vtbl *vtbl;
+
/* destruct old filter */
(*filter->filter_dtor)(filter);
- /* resset filter member */
- filter->from = mbfl_no2encoding(from);
- filter->to = mbfl_no2encoding(to);
+ vtbl = mbfl_convert_filter_get_vtbl(from, to);
- /* set the vtbl */
- mbfl_convert_filter_reset_vtbl(filter);
+ if (vtbl == NULL) {
+ vtbl = &vtbl_pass;
+ }
- /* construct new filter */
- (*filter->filter_ctor)(filter);
+ mbfl_convert_filter_common_init(filter, from, to, vtbl,
+ filter->output_function, filter->flush_function, filter->data);
}
void
mbfl_convert_filter_copy(
mbfl_convert_filter *src,
- mbfl_convert_filter *dist)
+ mbfl_convert_filter *dest)
{
- dist->filter_ctor = src->filter_ctor;
- dist->filter_dtor = src->filter_dtor;
- dist->filter_function = src->filter_function;
- dist->filter_flush = src->filter_flush;
- dist->output_function = src->output_function;
- dist->flush_function = src->flush_function;
- dist->data = src->data;
- dist->status = src->status;
- dist->cache = src->cache;
- dist->from = src->from;
- dist->to = src->to;
- dist->illegal_mode = src->illegal_mode;
- dist->illegal_substchar = src->illegal_substchar;
- dist->num_illegalchar = src->num_illegalchar;
+ if (src->filter_copy != NULL) {
+ src->filter_copy(src, dest);
+ return;
+ }
+
+ *dest = *src;
}
int mbfl_convert_filter_devcat(mbfl_convert_filter *filter, mbfl_memory_device *src)
@@ -466,6 +527,7 @@ mbfl_filt_conv_illegal_output(int c, mbfl_convert_filter *filter)
}
filter->illegal_mode = mode_backup;
filter->num_illegalchar++;
+
return ret;
}
@@ -494,22 +556,6 @@ const struct mbfl_convert_vtbl * mbfl_convert_filter_get_vtbl(enum mbfl_no_encod
return NULL;
}
-
-static void mbfl_convert_filter_reset_vtbl(mbfl_convert_filter *filter)
-{
- const struct mbfl_convert_vtbl *vtbl;
-
- vtbl = mbfl_convert_filter_get_vtbl(filter->from->no_encoding, filter->to->no_encoding);
- if (vtbl == NULL) {
- vtbl = &vtbl_pass;
- }
-
- filter->filter_ctor = vtbl->filter_ctor;
- filter->filter_dtor = vtbl->filter_dtor;
- filter->filter_function = vtbl->filter_function;
- filter->filter_flush = vtbl->filter_flush;
-}
-
/*
* commonly used constructor and destructor
*/
@@ -523,6 +569,10 @@ int mbfl_filt_conv_common_flush(mbfl_convert_filter *filter)
{
filter->status = 0;
filter->cache = 0;
+
+ if (filter->flush_function != NULL) {
+ (*filter->flush_function)(filter->data);
+ }
return 0;
}
diff --git a/ext/mbstring/libmbfl/mbfl/mbfl_convert.h b/ext/mbstring/libmbfl/mbfl/mbfl_convert.h
index bf8b3bd63..8b5ba5bc1 100644
--- a/ext/mbstring/libmbfl/mbfl/mbfl_convert.h
+++ b/ext/mbstring/libmbfl/mbfl/mbfl_convert.h
@@ -40,6 +40,7 @@ typedef struct _mbfl_convert_filter mbfl_convert_filter;
struct _mbfl_convert_filter {
void (*filter_ctor)(mbfl_convert_filter *filter);
void (*filter_dtor)(mbfl_convert_filter *filter);
+ void (*filter_copy)(mbfl_convert_filter *src, mbfl_convert_filter *dest);
int (*filter_function)(int c, mbfl_convert_filter *filter);
int (*filter_flush)(mbfl_convert_filter *filter);
int (*output_function)(int c, void *data);
@@ -62,6 +63,7 @@ struct mbfl_convert_vtbl {
void (*filter_dtor)(mbfl_convert_filter *filter);
int (*filter_function)(int c, mbfl_convert_filter *filter);
int (*filter_flush)(mbfl_convert_filter *filter);
+ void (*filter_copy)(mbfl_convert_filter *src, mbfl_convert_filter *dest);
};
MBFLAPI extern const struct mbfl_convert_vtbl *mbfl_convert_filter_list[];
@@ -72,6 +74,11 @@ MBFLAPI extern mbfl_convert_filter *mbfl_convert_filter_new(
int (*output_function)(int, void *),
int (*flush_function)(void *),
void *data );
+MBFLAPI extern mbfl_convert_filter *mbfl_convert_filter_new2(
+ const struct mbfl_convert_vtbl *vtbl,
+ int (*output_function)(int, void *),
+ int (*flush_function)(void *),
+ void *data );
MBFLAPI extern void mbfl_convert_filter_delete(mbfl_convert_filter *filter);
MBFLAPI extern int mbfl_convert_filter_feed(int c, mbfl_convert_filter *filter);
MBFLAPI extern int mbfl_convert_filter_flush(mbfl_convert_filter *filter);
diff --git a/ext/mbstring/libmbfl/mbfl/mbfl_encoding.c b/ext/mbstring/libmbfl/mbfl/mbfl_encoding.c
index 76956f053..17955b2c9 100644
--- a/ext/mbstring/libmbfl/mbfl/mbfl_encoding.c
+++ b/ext/mbstring/libmbfl/mbfl/mbfl_encoding.c
@@ -57,6 +57,7 @@
#include "filters/mbfilter_euc_kr.h"
#include "filters/mbfilter_iso2022_kr.h"
#include "filters/mbfilter_sjis.h"
+#include "filters/mbfilter_sjis_open.h"
#include "filters/mbfilter_cp51932.h"
#include "filters/mbfilter_jis.h"
#include "filters/mbfilter_iso2022_jp_ms.h"
@@ -71,6 +72,7 @@
#include "filters/mbfilter_cp1251.h"
#include "filters/mbfilter_cp1252.h"
#include "filters/mbfilter_cp1254.h"
+#include "filters/mbfilter_cp5022x.h"
#include "filters/mbfilter_iso8859_1.h"
#include "filters/mbfilter_iso8859_2.h"
#include "filters/mbfilter_iso8859_3.h"
@@ -153,7 +155,8 @@ static const mbfl_encoding *mbfl_encoding_ptr_list[] = {
&mbfl_encoding_euc_jp,
&mbfl_encoding_sjis,
&mbfl_encoding_eucjp_win,
- &mbfl_encoding_sjis_win,
+ &mbfl_encoding_sjis_open,
+ &mbfl_encoding_cp932,
&mbfl_encoding_cp51932,
&mbfl_encoding_jis,
&mbfl_encoding_2022jp,
@@ -188,6 +191,11 @@ static const mbfl_encoding *mbfl_encoding_ptr_list[] = {
&mbfl_encoding_koi8u,
&mbfl_encoding_armscii8,
&mbfl_encoding_cp850,
+ &mbfl_encoding_jis_ms,
+ &mbfl_encoding_cp50220,
+ &mbfl_encoding_cp50220raw,
+ &mbfl_encoding_cp50221,
+ &mbfl_encoding_cp50222,
NULL
};
@@ -209,7 +217,7 @@ mbfl_name2encoding(const char *name)
}
}
- /* search MIME charset name */
+ /* serch MIME charset name */
i = 0;
while ((encoding = mbfl_encoding_ptr_list[i++]) != NULL) {
if (encoding->mime_name != NULL) {
@@ -219,7 +227,7 @@ mbfl_name2encoding(const char *name)
}
}
- /* search aliases */
+ /* serch aliases */
i = 0;
while ((encoding = mbfl_encoding_ptr_list[i++]) != NULL) {
if (encoding->aliases != NULL) {
diff --git a/ext/mbstring/libmbfl/mbfl/mbfl_encoding.h b/ext/mbstring/libmbfl/mbfl/mbfl_encoding.h
index 2599e1107..fd3a66df6 100644
--- a/ext/mbstring/libmbfl/mbfl/mbfl_encoding.h
+++ b/ext/mbstring/libmbfl/mbfl/mbfl_encoding.h
@@ -68,8 +68,8 @@ enum mbfl_no_encoding {
mbfl_no_encoding_euc_jp,
mbfl_no_encoding_sjis,
mbfl_no_encoding_eucjp_win,
- mbfl_no_encoding_sjis_win,
- mbfl_no_encoding_sjis_mac,
+ mbfl_no_encoding_sjis_open,
+ mbfl_no_encoding_cp932,
mbfl_no_encoding_cp51932,
mbfl_no_encoding_jis,
mbfl_no_encoding_2022jp,
@@ -104,6 +104,11 @@ enum mbfl_no_encoding {
mbfl_no_encoding_8859_16,
mbfl_no_encoding_armscii8,
mbfl_no_encoding_cp850,
+ mbfl_no_encoding_jis_ms,
+ mbfl_no_encoding_cp50220,
+ mbfl_no_encoding_cp50220raw,
+ mbfl_no_encoding_cp50221,
+ mbfl_no_encoding_cp50222,
mbfl_no_encoding_charset_max
};
diff --git a/ext/mbstring/libmbfl/mbfl/mbfl_filter_output.c b/ext/mbstring/libmbfl/mbfl/mbfl_filter_output.c
index 2b6347821..341047d5b 100644
--- a/ext/mbstring/libmbfl/mbfl/mbfl_filter_output.c
+++ b/ext/mbstring/libmbfl/mbfl/mbfl_filter_output.c
@@ -41,9 +41,17 @@ int mbfl_filter_output_pipe(int c, void* data)
return (*filter->filter_function)(c, filter);
}
+int mbfl_filter_output_pipe_flush(void *data)
+{
+ mbfl_convert_filter *filter = (mbfl_convert_filter*)data;
+ if (filter->filter_flush != NULL) {
+ return (*filter->filter_flush)(filter);
+ }
+
+ return 0;
+}
+
int mbfl_filter_output_null(int c, void* data)
{
return c;
}
-
-
diff --git a/ext/mbstring/libmbfl/mbfl/mbfl_filter_output.h b/ext/mbstring/libmbfl/mbfl/mbfl_filter_output.h
index ce5192935..d477653d3 100644
--- a/ext/mbstring/libmbfl/mbfl/mbfl_filter_output.h
+++ b/ext/mbstring/libmbfl/mbfl/mbfl_filter_output.h
@@ -32,6 +32,7 @@
#define MBFL_FILTER_OUTPUT_H
MBFLAPI extern int mbfl_filter_output_pipe(int c, void* data);
+MBFLAPI extern int mbfl_filter_output_pipe_flush(void* data);
MBFLAPI extern int mbfl_filter_output_null(int c, void* data);
#endif /* MBFL_FILTER_OUTPUT_H */
diff --git a/ext/mbstring/libmbfl/mbfl/mbfl_ident.c b/ext/mbstring/libmbfl/mbfl/mbfl_ident.c
index 4f3bd5c58..9a8980705 100644
--- a/ext/mbstring/libmbfl/mbfl/mbfl_ident.c
+++ b/ext/mbstring/libmbfl/mbfl/mbfl_ident.c
@@ -50,6 +50,7 @@
#include "filters/mbfilter_euc_kr.h"
#include "filters/mbfilter_iso2022_kr.h"
#include "filters/mbfilter_sjis.h"
+#include "filters/mbfilter_sjis_open.h"
#include "filters/mbfilter_jis.h"
#include "filters/mbfilter_iso2022_jp_ms.h"
#include "filters/mbfilter_euc_jp.h"
@@ -64,6 +65,7 @@
#include "filters/mbfilter_cp1252.h"
#include "filters/mbfilter_cp1254.h"
#include "filters/mbfilter_cp51932.h"
+#include "filters/mbfilter_cp5022x.h"
#include "filters/mbfilter_iso8859_1.h"
#include "filters/mbfilter_iso8859_2.h"
#include "filters/mbfilter_iso8859_3.h"
@@ -107,8 +109,9 @@ static const struct mbfl_identify_vtbl *mbfl_identify_filter_list[] = {
&vtbl_identify_ascii,
&vtbl_identify_eucjp,
&vtbl_identify_sjis,
+ &vtbl_identify_sjis_open,
&vtbl_identify_eucjpwin,
- &vtbl_identify_sjiswin,
+ &vtbl_identify_cp932,
&vtbl_identify_jis,
&vtbl_identify_2022jp,
&vtbl_identify_2022jpms,
@@ -142,6 +145,10 @@ static const struct mbfl_identify_vtbl *mbfl_identify_filter_list[] = {
&vtbl_identify_8859_15,
&vtbl_identify_armscii8,
&vtbl_identify_cp850,
+ &vtbl_identify_jis_ms,
+ &vtbl_identify_cp50220,
+ &vtbl_identify_cp50221,
+ &vtbl_identify_cp50222,
&vtbl_identify_false,
NULL
};