Permalink
Browse files

Directly use encodings instead of no_encoding in libmbfl

In particular strings now store encoding rather than the
no_encoding.

I've also pruned out libmbfl APIs that existed in two forms, one
using no_encoding and the other using encoding. We were not actually
using any of the former.
  • Loading branch information...
nikic committed Jul 20, 2017
1 parent 2e75f84 commit b3c1d9d1118438a3dae3544447db2b39ca5cfa25

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -126,8 +126,7 @@ struct _mbfl_buffer_converter {
const mbfl_encoding *to;
};
MBFLAPI extern mbfl_buffer_converter * mbfl_buffer_converter_new(enum mbfl_no_encoding from, enum mbfl_no_encoding to, size_t buf_initsz);
MBFLAPI extern mbfl_buffer_converter * mbfl_buffer_converter_new2(const mbfl_encoding *from, const mbfl_encoding *to, size_t buf_initsz);
MBFLAPI extern mbfl_buffer_converter * mbfl_buffer_converter_new(const mbfl_encoding *from, const mbfl_encoding *to, size_t buf_initsz);
MBFLAPI extern void mbfl_buffer_converter_delete(mbfl_buffer_converter *convd);
MBFLAPI extern void mbfl_buffer_converter_reset(mbfl_buffer_converter *convd);
MBFLAPI extern int mbfl_buffer_converter_illegal_mode(mbfl_buffer_converter *convd, int mode);
@@ -152,29 +151,24 @@ struct _mbfl_encoding_detector {
int strict;
};
MBFLAPI extern mbfl_encoding_detector * mbfl_encoding_detector_new(enum mbfl_no_encoding *elist, int elistsz, int strict);
MBFLAPI extern mbfl_encoding_detector * mbfl_encoding_detector_new2(const mbfl_encoding **elist, int elistsz, int strict);
MBFLAPI extern mbfl_encoding_detector * mbfl_encoding_detector_new(const mbfl_encoding **elist, int elistsz, int strict);
MBFLAPI extern void mbfl_encoding_detector_delete(mbfl_encoding_detector *identd);
MBFLAPI extern int mbfl_encoding_detector_feed(mbfl_encoding_detector *identd, mbfl_string *string);
MBFLAPI extern enum mbfl_no_encoding mbfl_encoding_detector_judge(mbfl_encoding_detector *identd);
MBFLAPI extern const mbfl_encoding *mbfl_encoding_detector_judge2(mbfl_encoding_detector *identd);
MBFLAPI extern const mbfl_encoding *mbfl_encoding_detector_judge(mbfl_encoding_detector *identd);
/*
* encoding converter
*/
MBFLAPI extern mbfl_string *
mbfl_convert_encoding(mbfl_string *string, mbfl_string *result, enum mbfl_no_encoding toenc);
mbfl_convert_encoding(mbfl_string *string, mbfl_string *result, const mbfl_encoding *toenc);
/*
* identify encoding
*/
MBFLAPI extern const mbfl_encoding *
mbfl_identify_encoding(mbfl_string *string, enum mbfl_no_encoding *elist, int elistsz, int strict);
MBFLAPI extern const mbfl_encoding *
mbfl_identify_encoding2(mbfl_string *string, const mbfl_encoding **elist, int elistsz, int strict);
mbfl_identify_encoding(mbfl_string *string, const mbfl_encoding **elist, int elistsz, int strict);
/* Lengths -1 through -16 are reserved for error return values */
static inline int mbfl_is_error(size_t len) {
@@ -237,9 +231,9 @@ struct mime_header_encoder_data; /* forward declaration */
MBFLAPI extern struct mime_header_encoder_data *
mime_header_encoder_new(
enum mbfl_no_encoding incode,
enum mbfl_no_encoding outcode,
enum mbfl_no_encoding encoding);
const mbfl_encoding *incode,
const mbfl_encoding *outcode,
const mbfl_encoding *encoding);
MBFLAPI extern void
mime_header_encoder_delete(struct mime_header_encoder_data *pe);
@@ -253,8 +247,8 @@ mime_header_encoder_result(struct mime_header_encoder_data *pe, mbfl_string *res
MBFLAPI extern mbfl_string *
mbfl_mime_header_encode(
mbfl_string *string, mbfl_string *result,
enum mbfl_no_encoding outcode,
enum mbfl_no_encoding encoding,
const mbfl_encoding *outcode,
const mbfl_encoding *encoding,
const char *linefeed,
int indent);
@@ -264,7 +258,7 @@ mbfl_mime_header_encode(
struct mime_header_decoder_data; /* forward declaration */
MBFLAPI extern struct mime_header_decoder_data *
mime_header_decoder_new(enum mbfl_no_encoding outcode);
mime_header_decoder_new(const mbfl_encoding *outcode);
MBFLAPI extern void
mime_header_decoder_delete(struct mime_header_decoder_data *pd);
@@ -279,7 +273,7 @@ MBFLAPI extern mbfl_string *
mbfl_mime_header_decode(
mbfl_string *string,
mbfl_string *result,
enum mbfl_no_encoding outcode);
const mbfl_encoding *outcode);
/*
* convert HTML numeric entity
@@ -281,21 +281,16 @@ const struct mbfl_convert_vtbl *mbfl_convert_filter_list[] = {
static int
mbfl_convert_filter_common_init(
mbfl_convert_filter *filter,
enum mbfl_no_encoding from,
enum mbfl_no_encoding to,
const mbfl_encoding *from,
const mbfl_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;
}
filter->from = from;
filter->to = to;
if (output_function != NULL) {
filter->output_function = output_function;
@@ -322,16 +317,16 @@ mbfl_convert_filter_common_init(
mbfl_convert_filter *
mbfl_convert_filter_new(
enum mbfl_no_encoding from,
enum mbfl_no_encoding to,
const mbfl_encoding *from,
const mbfl_encoding *to,
int (*output_function)(int, void* ),
int (*flush_function)(void*),
void* data)
{
mbfl_convert_filter * filter;
const struct mbfl_convert_vtbl *vtbl;
vtbl = mbfl_convert_filter_get_vtbl(from, to);
vtbl = mbfl_convert_filter_get_vtbl(from->no_encoding, to->no_encoding);
if (vtbl == NULL) {
vtbl = &vtbl_pass;
@@ -360,18 +355,22 @@ mbfl_convert_filter_new2(
void* data)
{
mbfl_convert_filter * filter;
const mbfl_encoding *from_encoding, *to_encoding;
if (vtbl == NULL) {
vtbl = &vtbl_pass;
}
from_encoding = mbfl_no2encoding(vtbl->from);
to_encoding = mbfl_no2encoding(vtbl->to);
/* allocate */
filter = (mbfl_convert_filter *)mbfl_malloc(sizeof(mbfl_convert_filter));
if (filter == NULL) {
return NULL;
}
if (mbfl_convert_filter_common_init(filter, vtbl->from, vtbl->to, vtbl,
if (mbfl_convert_filter_common_init(filter, from_encoding, to_encoding, vtbl,
output_function, flush_function, data)) {
mbfl_free(filter);
return NULL;
@@ -403,14 +402,14 @@ 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 mbfl_encoding *from, const mbfl_encoding *to)
{
const struct mbfl_convert_vtbl *vtbl;
/* destruct old filter */
(*filter->filter_dtor)(filter);
vtbl = mbfl_convert_filter_get_vtbl(from, to);
vtbl = mbfl_convert_filter_get_vtbl(from->no_encoding, to->no_encoding);
if (vtbl == NULL) {
vtbl = &vtbl_pass;
@@ -69,8 +69,8 @@ struct mbfl_convert_vtbl {
MBFLAPI extern const struct mbfl_convert_vtbl *mbfl_convert_filter_list[];
MBFLAPI extern mbfl_convert_filter *mbfl_convert_filter_new(
enum mbfl_no_encoding from,
enum mbfl_no_encoding to,
const mbfl_encoding *from,
const mbfl_encoding *to,
int (*output_function)(int, void *),
int (*flush_function)(void *),
void *data );
@@ -82,7 +82,7 @@ MBFLAPI extern mbfl_convert_filter *mbfl_convert_filter_new2(
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);
MBFLAPI extern void mbfl_convert_filter_reset(mbfl_convert_filter *filter, enum mbfl_no_encoding from, enum mbfl_no_encoding to);
MBFLAPI extern void mbfl_convert_filter_reset(mbfl_convert_filter *filter, const mbfl_encoding *from, const mbfl_encoding *to);
MBFLAPI extern void mbfl_convert_filter_copy(mbfl_convert_filter *src, mbfl_convert_filter *dist);
MBFLAPI extern int mbfl_filt_conv_illegal_output(int c, mbfl_convert_filter *filter);
MBFLAPI extern const struct mbfl_convert_vtbl * mbfl_convert_filter_get_vtbl(enum mbfl_no_encoding from, enum mbfl_no_encoding to);
@@ -38,6 +38,7 @@
#include "mbfl_allocators.h"
#include "mbfl_string.h"
#include "mbfilter_pass.h"
/*
* string object
@@ -47,18 +48,18 @@ mbfl_string_init(mbfl_string *string)
{
if (string) {
string->no_language = mbfl_no_language_uni;
string->no_encoding = mbfl_no_encoding_pass;
string->encoding = &mbfl_encoding_pass;
string->val = (unsigned char*)NULL;
string->len = 0;
}
}
void
mbfl_string_init_set(mbfl_string *string, mbfl_language_id no_language, mbfl_encoding_id no_encoding)
mbfl_string_init_set(mbfl_string *string, mbfl_language_id no_language, const mbfl_encoding *encoding)
{
if (string) {
string->no_language = no_language;
string->no_encoding = no_encoding;
string->encoding = encoding;
string->val = (unsigned char*)NULL;
string->len = 0;
}
@@ -41,13 +41,13 @@
*/
typedef struct _mbfl_string {
enum mbfl_no_language no_language;
enum mbfl_no_encoding no_encoding;
const mbfl_encoding *encoding;
unsigned char *val;
size_t len;
} mbfl_string;
MBFLAPI extern void mbfl_string_init(mbfl_string *string);
MBFLAPI extern void mbfl_string_init_set(mbfl_string *string, mbfl_language_id no_language, mbfl_encoding_id no_encoding);
MBFLAPI extern void mbfl_string_init_set(mbfl_string *string, mbfl_language_id no_language, const mbfl_encoding *encoding);
MBFLAPI extern void mbfl_string_clear(mbfl_string *string);
#ifndef NULL
View
@@ -203,9 +203,9 @@ const mbfl_encoding *_php_mb_encoding_handler_ex(const php_mb_encoding_handler_i
mbfl_encoding_detector *identd = NULL;
mbfl_buffer_converter *convd = NULL;
mbfl_string_init_set(&string, info->to_language, info->to_encoding->no_encoding);
mbfl_string_init_set(&resvar, info->to_language, info->to_encoding->no_encoding);
mbfl_string_init_set(&resval, info->to_language, info->to_encoding->no_encoding);
mbfl_string_init_set(&string, info->to_language, info->to_encoding);
mbfl_string_init_set(&resvar, info->to_language, info->to_encoding);
mbfl_string_init_set(&resval, info->to_language, info->to_encoding);
if (!res || *res == '\0') {
goto out;
@@ -268,7 +268,7 @@ const mbfl_encoding *_php_mb_encoding_handler_ex(const php_mb_encoding_handler_i
} else {
/* auto detect */
from_encoding = NULL;
identd = mbfl_encoding_detector_new2(info->from_encodings, info->num_from_encodings, MBSTRG(strict_detection));
identd = mbfl_encoding_detector_new(info->from_encodings, info->num_from_encodings, MBSTRG(strict_detection));
if (identd != NULL) {
n = 0;
while (n < num) {
@@ -279,7 +279,7 @@ const mbfl_encoding *_php_mb_encoding_handler_ex(const php_mb_encoding_handler_i
}
n++;
}
from_encoding = mbfl_encoding_detector_judge2(identd);
from_encoding = mbfl_encoding_detector_judge(identd);
mbfl_encoding_detector_delete(identd);
}
if (!from_encoding) {
@@ -292,7 +292,7 @@ const mbfl_encoding *_php_mb_encoding_handler_ex(const php_mb_encoding_handler_i
convd = NULL;
if (from_encoding != &mbfl_encoding_pass) {
convd = mbfl_buffer_converter_new2(from_encoding, info->to_encoding, 0);
convd = mbfl_buffer_converter_new(from_encoding, info->to_encoding, 0);
if (convd != NULL) {
mbfl_buffer_converter_illegal_mode(convd, MBSTRG(current_filter_illegal_mode));
mbfl_buffer_converter_illegal_substchar(convd, MBSTRG(current_filter_illegal_substchar));
@@ -305,7 +305,7 @@ const mbfl_encoding *_php_mb_encoding_handler_ex(const php_mb_encoding_handler_i
}
/* convert encoding */
string.no_encoding = from_encoding->no_encoding;
string.encoding = from_encoding;
n = 0;
while (n < num) {
Oops, something went wrong.

0 comments on commit b3c1d9d

Please sign in to comment.