mbfl_buffer_converter_new(
enum mbfl_no_encoding from,
enum mbfl_no_encoding to,
- int buf_initsz)
+ size_t buf_initsz)
{
const mbfl_encoding *_from = mbfl_no2encoding(from);
const mbfl_encoding *_to = mbfl_no2encoding(to);
mbfl_buffer_converter_new2(
const mbfl_encoding *from,
const mbfl_encoding *to,
- int buf_initsz)
+ size_t buf_initsz)
{
mbfl_buffer_converter *convd;
/* allocate */
- convd = (mbfl_buffer_converter*)mbfl_malloc(sizeof (mbfl_buffer_converter));
+ convd = (mbfl_buffer_converter*)mbfl_malloc(sizeof(mbfl_buffer_converter));
if (convd == NULL) {
return NULL;
}
/* create convert filter */
convd->filter1 = NULL;
- convd->filter2 = 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, NULL, &convd->device);
} else {
}
int
-mbfl_buffer_converter_strncat(mbfl_buffer_converter *convd, const unsigned char *p, int n)
+mbfl_buffer_converter_strncat(mbfl_buffer_converter *convd, const unsigned char *p, size_t n)
{
mbfl_convert_filter *filter;
int (*filter_function)(int c, mbfl_convert_filter *filter);
}
int
-mbfl_buffer_converter_feed2(mbfl_buffer_converter *convd, mbfl_string *string, int *loc)
+mbfl_buffer_converter_feed2(mbfl_buffer_converter *convd, mbfl_string *string, size_t *loc)
{
- int n;
+ size_t n;
unsigned char *p;
mbfl_convert_filter *filter;
int (*filter_function)(int c, mbfl_convert_filter *filter);
return mbfl_memory_device_result(&convd->device, result);
}
-int mbfl_buffer_illegalchars(mbfl_buffer_converter *convd)
+size_t mbfl_buffer_illegalchars(mbfl_buffer_converter *convd)
{
- int num_illegalchars = 0;
+ size_t num_illegalchars = 0;
if (convd == NULL) {
return 0;
num_illegalchars += convd->filter2->num_illegalchar;
}
- return (num_illegalchars);
+ return num_illegalchars;
}
/*
int
mbfl_encoding_detector_feed(mbfl_encoding_detector *identd, mbfl_string *string)
{
- int i, n, num, bad, res;
- unsigned char *p;
- mbfl_identify_filter *filter;
-
- res = 0;
+ int res = 0;
/* feed data */
if (identd != NULL && string != NULL && string->val != NULL) {
- num = identd->filter_list_size;
- n = string->len;
- p = string->val;
- bad = 0;
+ int num = identd->filter_list_size;
+ size_t n = string->len;
+ unsigned char *p = string->val;
+ int bad = 0;
while (n > 0) {
+ int i;
for (i = 0; i < num; i++) {
- filter = identd->filter_list[i];
+ mbfl_identify_filter *filter = identd->filter_list[i];
if (!filter->flag) {
(*filter->filter_function)(*p, filter);
if (filter->flag) {
mbfl_string *result,
enum mbfl_no_encoding toenc)
{
- int n;
+ size_t n;
unsigned char *p;
const mbfl_encoding *encoding;
mbfl_memory_device device;
const mbfl_encoding *
mbfl_identify_encoding(mbfl_string *string, enum mbfl_no_encoding *elist, int elistsz, int strict)
{
- int i, n, num, bad;
+ int i, num, bad;
+ size_t n;
unsigned char *p;
mbfl_identify_filter *flist, *filter;
const mbfl_encoding *encoding;
/* cleanup */
/* dtors should be called in reverse order */
- i = num; while (--i >= 0) {
+ i = num;
+ while (--i >= 0) {
mbfl_identify_filter_cleanup(&flist[i]);
}
const mbfl_encoding *
mbfl_identify_encoding2(mbfl_string *string, const mbfl_encoding **elist, int elistsz, int strict)
{
- int i, n, num, bad;
+ int i, num, bad;
+ size_t n;
unsigned char *p;
mbfl_identify_filter *flist, *filter;
const mbfl_encoding *encoding;
/* cleanup */
/* dtors should be called in reverse order */
- i = num; while (--i >= 0) {
+ i = num;
+ while (--i >= 0) {
mbfl_identify_filter_cleanup(&flist[i]);
}
static int
filter_count_output(int c, void *data)
{
- (*(int *)data)++;
+ (*(size_t *)data)++;
return c;
}
-int
+size_t
mbfl_strlen(mbfl_string *string)
{
- int len, n, m, k;
+ size_t len, n, k;
unsigned char *p;
- const unsigned char *mbtab;
const mbfl_encoding *encoding;
encoding = mbfl_no2encoding(string->no_encoding);
if (encoding == NULL || string == NULL) {
- return -1;
+ return (size_t) -1;
}
len = 0;
} else if (encoding->flag & (MBFL_ENCTYPE_WCS4BE | MBFL_ENCTYPE_WCS4LE)) {
len = string->len/4;
} else if (encoding->mblen_table != NULL) {
- mbtab = encoding->mblen_table;
+ const unsigned char *mbtab = encoding->mblen_table;
n = 0;
p = string->val;
k = string->len;
/* count */
if (p != NULL) {
while (n < k) {
- m = mbtab[*p];
+ unsigned m = mbtab[*p];
n += m;
p += m;
len++;
- };
+ }
}
} else {
/* wchar filter */
mbfl_no_encoding_wchar,
filter_count_output, 0, &len);
if (filter == NULL) {
- return -1;
+ return (size_t) -1;
}
/* count */
n = string->len;
struct collector_strpos_data {
mbfl_convert_filter *next_filter;
mbfl_wchar_device needle;
- int needle_len;
- int start;
- int output;
- int found_pos;
- int needle_pos;
- int matched_pos;
+ size_t needle_len;
+ size_t start;
+ size_t output;
+ size_t found_pos;
+ size_t needle_pos;
+ size_t matched_pos;
};
static int
/*
* oddlen
*/
-int
+size_t
mbfl_oddlen(mbfl_string *string)
{
- int len, n, m, k;
+ size_t len, n, k;
unsigned char *p;
- const unsigned char *mbtab;
const mbfl_encoding *encoding;
if (string == NULL) {
- return -1;
+ return (size_t) -1;
}
encoding = mbfl_no2encoding(string->no_encoding);
if (encoding == NULL) {
- return -1;
+ return (size_t) -1;
}
len = 0;
} else if (encoding->flag & (MBFL_ENCTYPE_WCS4BE | MBFL_ENCTYPE_WCS4LE)) {
return len % 4;
} else if (encoding->mblen_table != NULL) {
- mbtab = encoding->mblen_table;
+ const unsigned char *mbtab = encoding->mblen_table;
n = 0;
p = string->val;
k = string->len;
/* count */
if (p != NULL) {
while (n < k) {
- m = mbtab[*p];
+ unsigned m = mbtab[*p];
n += m;
p += m;
};
/* NOT REACHED */
}
-int
+size_t
mbfl_strpos(
mbfl_string *haystack,
mbfl_string *needle,
- int offset,
+ ssize_t offset,
int reverse)
{
- int result;
+ size_t result;
mbfl_string _haystack_u8, _needle_u8;
const mbfl_string *haystack_u8, *needle_u8 = NULL;
const unsigned char *u8_tbl;
if (haystack == NULL || haystack->val == NULL || needle == NULL || needle->val == NULL) {
- return -8;
+ return (size_t) -8;
}
{
const mbfl_encoding *u8_enc;
u8_enc = mbfl_no2encoding(mbfl_no_encoding_utf8);
if (u8_enc == NULL || u8_enc->mblen_table == NULL) {
- return -8;
+ return (size_t) -8;
}
u8_tbl = u8_enc->mblen_table;
}
mbfl_string_init(&_haystack_u8);
haystack_u8 = mbfl_convert_encoding(haystack, &_haystack_u8, mbfl_no_encoding_utf8);
if (haystack_u8 == NULL) {
- result = -4;
+ result = (size_t) -4;
goto out;
}
} else {
mbfl_string_init(&_needle_u8);
needle_u8 = mbfl_convert_encoding(needle, &_needle_u8, mbfl_no_encoding_utf8);
if (needle_u8 == NULL) {
- result = -4;
+ result = (size_t) -4;
goto out;
}
} else {
}
if (needle_u8->len < 1) {
- result = -8;
+ result = (size_t) -8;
goto out;
}
- result = -1;
+ result = (size_t) -1;
if (haystack_u8->len < needle_u8->len) {
goto out;
}
if (!reverse) {
- unsigned int jtbl[1 << (sizeof(unsigned char) * 8)];
- unsigned int needle_u8_len = needle_u8->len;
- unsigned int i;
+ size_t jtbl[1 << (sizeof(unsigned char) * 8)];
+ size_t needle_u8_len = needle_u8->len;
+ size_t i;
const unsigned char *p, *q, *e;
const unsigned char *haystack_u8_val = haystack_u8->val,
*needle_u8_val = needle_u8->val;
}
e = haystack_u8_val + haystack_u8->len;
p = haystack_u8_val;
- while (--offset >= 0) {
+ while (offset-- > 0) {
if (p >= e) {
- result = -16;
+ result = (size_t) -16;
goto out;
}
p += u8_tbl[*p];
}
}
} else {
- unsigned int jtbl[1 << (sizeof(unsigned char) * 8)];
- unsigned int needle_u8_len = needle_u8->len, needle_len = 0;
- unsigned int i;
+ size_t jtbl[1 << (sizeof(unsigned char) * 8)];
+ size_t needle_u8_len = needle_u8->len, needle_len = 0;
+ size_t i;
const unsigned char *p, *e, *q, *qe;
const unsigned char *haystack_u8_val = haystack_u8->val,
*needle_u8_val = needle_u8->val;
while (offset < 0) {
unsigned char c;
if (p <= e) {
- result = -16;
+ result = (size_t) -16;
goto out;
}
c = *(--p);
}
} else {
const unsigned char *ee = haystack_u8_val + haystack_u8->len;
- while (--offset >= 0) {
+ while (offset-- > 0) {
if (e >= ee) {
- result = -16;
+ result = (size_t) -16;
goto out;
}
e += u8_tbl[*e];
* substr_count
*/
-int
+size_t
mbfl_substr_count(
mbfl_string *haystack,
mbfl_string *needle
)
{
- int n, result = 0;
+ size_t n, result = 0;
unsigned char *p;
mbfl_convert_filter *filter;
struct collector_strpos_data pc;
if (haystack == NULL || needle == NULL) {
- return -8;
+ return (size_t) -8;
}
/* needle is converted into wchar */
mbfl_wchar_device_init(&pc.needle);
mbfl_no_encoding_wchar,
mbfl_wchar_device_output, 0, &pc.needle);
if (filter == NULL) {
- return -4;
+ return (size_t) -4;
}
p = needle->val;
n = needle->len;
mbfl_convert_filter_delete(filter);
pc.needle_len = pc.needle.pos;
if (pc.needle.buffer == NULL) {
- return -4;
+ return (size_t) -4;
}
if (pc.needle_len <= 0) {
mbfl_wchar_device_clear(&pc.needle);
- return -2;
+ return (size_t) -2;
}
/* initialize filter and collector data */
filter = mbfl_convert_filter_new(
collector_strpos, 0, &pc);
if (filter == NULL) {
mbfl_wchar_device_clear(&pc.needle);
- return -4;
+ return (size_t) -4;
}
pc.start = 0;
pc.output = 0;
pc.needle_pos = 0;
pc.found_pos = 0;
- pc.matched_pos = -1;
+ pc.matched_pos = (size_t) -1;
/* feed data */
p = haystack->val;
if (p != NULL) {
while (n > 0) {
if ((*filter->filter_function)(*p++, filter) < 0) {
- pc.matched_pos = -4;
+ pc.matched_pos = (size_t) -4;
break;
}
- if (pc.matched_pos >= 0) {
+ if (pc.matched_pos != (size_t) -1) {
++result;
- pc.matched_pos = -1;
+ pc.matched_pos = (size_t) -1;
pc.needle_pos = 0;
}
n--;
*/
struct collector_substr_data {
mbfl_convert_filter *next_filter;
- int start;
- int stop;
- int output;
+ size_t start;
+ size_t stop;
+ size_t output;
};
static int
mbfl_substr(
mbfl_string *string,
mbfl_string *result,
- int from,
- int length)
+ size_t from,
+ size_t length)
{
const mbfl_encoding *encoding;
- int n, m, k, len, start, end;
+ size_t n, k, len, start, end;
+ unsigned m;
unsigned char *p, *w;
- const unsigned char *mbtab;
encoding = mbfl_no2encoding(string->no_encoding);
if (encoding == NULL || string == NULL || result == NULL) {
start *= 4;
end = start + length*4;
} else if (encoding->mblen_table != NULL) {
- mbtab = encoding->mblen_table;
+ const unsigned char *mbtab = encoding->mblen_table;
start = 0;
end = 0;
n = 0;
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;
}
mbfl_strcut(
mbfl_string *string,
mbfl_string *result,
- int from,
- int length)
+ size_t from,
+ size_t length)
{
const mbfl_encoding *encoding;
mbfl_memory_device device;
return NULL;
}
- if (from < 0 || length < 0) {
- return NULL;
- }
-
if (from >= string->len) {
from = string->len;
}
const unsigned char *start = NULL;
const unsigned char *end = NULL;
unsigned char *w;
- unsigned int sz;
+ size_t sz;
if (encoding->flag & (MBFL_ENCTYPE_WCS2BE | MBFL_ENCTYPE_WCS2LE)) {
from &= -2;
start = p;
/* search end position */
- if (length >= (int)string->len - (start - string->val)) {
+ if (length >= string->len - (start - string->val)) {
end = string->val + string->len;
} else {
for (q = p + length; p < q; p += (m = mbtab[*p]));
mbfl_convert_filter encoder;
mbfl_convert_filter decoder;
const unsigned char *p;
- int pos;
+ size_t pos;
} bk, _bk;
/* output code filter */
/*
* strwidth
*/
-static int is_fullwidth(int c)
+static size_t is_fullwidth(int c)
{
int i;
static int
filter_count_width(int c, void* data)
{
- (*(int *)data) += (is_fullwidth(c) ? 2: 1);
+ (*(size_t *)data) += (is_fullwidth(c) ? 2: 1);
return c;
}
-int
+size_t
mbfl_strwidth(mbfl_string *string)
{
- int len, n;
+ size_t len, n;
unsigned char *p;
mbfl_convert_filter *filter;
mbfl_convert_filter *decoder;
mbfl_convert_filter *decoder_backup;
mbfl_memory_device device;
- int from;
- int width;
- int outwidth;
- int outchar;
+ size_t from;
+ size_t width;
+ size_t outwidth;
+ size_t outchar;
+ size_t endpos;
int status;
- int endpos;
};
static int
mbfl_string *string,
mbfl_string *marker,
mbfl_string *result,
- int from,
- int width)
+ size_t from,
+ size_t width)
{
struct collector_strimwidth_data pc;
mbfl_convert_filter *encoder;
- int n, mkwidth;
+ size_t n, mkwidth;
unsigned char *p;
if (string == NULL || result == NULL) {
mbfl_string *result,
int mode)
{
- int n;
+ size_t n;
unsigned char *p;
const mbfl_encoding *encoding;
mbfl_memory_device device;
mbfl_memory_device tmpdev;
int status1;
int status2;
- int prevpos;
- int linehead;
- int firstindent;
+ size_t prevpos;
+ size_t linehead;
+ size_t firstindent;
int encnamelen;
int lwsplen;
char encname[128];
static int
mime_header_encoder_block_collector(int c, void *data)
{
- int n;
+ size_t n;
struct mime_header_encoder_data *pe = (struct mime_header_encoder_data *)data;
switch (pe->status2) {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 /* 0xF0 */
};
- int n;
+ size_t n;
struct mime_header_encoder_data *pe = (struct mime_header_encoder_data *)data;
switch (pe->status1) {
enum mbfl_no_encoding outcode,
enum mbfl_no_encoding transenc)
{
- int n;
+ size_t n;
const char *s;
const mbfl_encoding *outencoding;
struct mime_header_encoder_data *pe;
const char *linefeed,
int indent)
{
- int n;
+ size_t n;
unsigned char *p;
struct mime_header_encoder_data *pe;
mbfl_convert_filter *conv2_filter;
mbfl_memory_device outdev;
mbfl_memory_device tmpdev;
- int cspos;
+ size_t cspos;
int status;
enum mbfl_no_encoding encoding;
enum mbfl_no_encoding incode;
mbfl_string *result,
enum mbfl_no_encoding outcode)
{
- int n;
+ size_t n;
unsigned char *p;
struct mime_header_decoder_data *pd;
struct collector_htmlnumericentity_data pc;
mbfl_memory_device device;
mbfl_convert_filter *encoder;
- int n;
+ size_t n;
unsigned char *p;
if (string == NULL || result == NULL) {
{
mbfl_string string, result;
mbfl_buffer_converter *convd;
- int status, loc;
+ int status;
+ size_t loc;
/* new encoding */
/* initialize string */
/* initialize converter */
convd = mbfl_buffer_converter_new2((const mbfl_encoding *)encoding_from, (const mbfl_encoding *)encoding_to, string.len);
if (convd == NULL) {
- return -1;
+ return (size_t) -1;
}
mbfl_buffer_converter_illegal_mode(convd, MBSTRG(current_filter_illegal_mode));
mbfl_buffer_converter_illegal_substchar(convd, MBSTRG(current_filter_illegal_substchar));
}
/* }}} */
-static char *php_mb_rfc1867_substring_conf(const zend_encoding *encoding, char *start, int len, char quote)
+static char *php_mb_rfc1867_substring_conf(const zend_encoding *encoding, char *start, size_t len, char quote)
{
char *result = emalloc(len + 2);
char *resp = result;
- int i;
+ size_t i;
for (i = 0; i < len && start[i] != quote; ++i) {
if (start[i] == '\\' && (start[i + 1] == '\\' || (quote && start[i + 1] == quote))) {
const char *charset;
char *p;
const mbfl_encoding *encoding;
- int last_feed, len;
+ int last_feed;
+ size_t len;
unsigned char send_text_mimetype = 0;
char *s, *mimetype = NULL;
int n;
mbfl_string string;
char *enc_name = NULL;
- size_t enc_name_len, string_len;
+ size_t enc_name_len;
mbfl_string_init(&string);
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|s", (char **)&string.val, &string_len, &enc_name, &enc_name_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|s", (char **)&string.val, &string.len, &enc_name, &enc_name_len) == FAILURE) {
return;
}
- if (ZEND_SIZE_T_UINT_OVFL(string_len)) {
- php_error_docref(NULL, E_WARNING, "String overflows the max allowed length of %u", UINT_MAX);
- return;
- }
-
- string.len = (uint32_t)string_len;
-
string.no_language = MBSTRG(language);
if (enc_name == NULL) {
string.no_encoding = MBSTRG(current_internal_encoding)->no_encoding;
}
n = mbfl_strlen(&string);
- if (n >= 0) {
+ if (!mbfl_is_error(n)) {
RETVAL_LONG(n);
} else {
RETVAL_FALSE;
Find position of first occurrence of a string within another */
PHP_FUNCTION(mb_strpos)
{
- int n, reverse = 0;
+ int reverse = 0;
zend_long offset = 0, slen;
mbfl_string haystack, needle;
char *enc_name = NULL;
- size_t enc_name_len, haystack_len, needle_len;
+ size_t enc_name_len, n;
mbfl_string_init(&haystack);
mbfl_string_init(&needle);
needle.no_language = MBSTRG(language);
needle.no_encoding = MBSTRG(current_internal_encoding)->no_encoding;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|ls", (char **)&haystack.val, &haystack_len, (char **)&needle.val, &needle_len, &offset, &enc_name, &enc_name_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|ls", (char **)&haystack.val, &haystack.len, (char **)&needle.val, &needle.len, &offset, &enc_name, &enc_name_len) == FAILURE) {
return;
}
- if (ZEND_SIZE_T_UINT_OVFL(haystack_len)) {
- php_error_docref(NULL, E_WARNING, "Haystack length overflows the max allowed length of %u", UINT_MAX);
- return;
- } else if (ZEND_SIZE_T_UINT_OVFL(needle_len)) {
- php_error_docref(NULL, E_WARNING, "Needle length overflows the max allowed length of %u", UINT_MAX);
- return;
- }
-
- haystack.len = (uint32_t)haystack_len;
- needle.len = (uint32_t)needle_len;
-
if (enc_name != NULL) {
haystack.no_encoding = needle.no_encoding = mbfl_name2no_encoding(enc_name);
if (haystack.no_encoding == mbfl_no_encoding_invalid) {
}
n = mbfl_strpos(&haystack, &needle, offset, reverse);
- if (n >= 0) {
+ if (!mbfl_is_error(n)) {
RETVAL_LONG(n);
} else {
switch (-n) {
Find position of last occurrence of a string within another */
PHP_FUNCTION(mb_strrpos)
{
- int n;
mbfl_string haystack, needle;
char *enc_name = NULL;
- size_t enc_name_len, haystack_len, needle_len;
+ size_t enc_name_len;
zval *zoffset = NULL;
- long offset = 0, str_flg;
+ long offset = 0, str_flg, n;
char *enc_name2 = NULL;
int enc_name_len2;
needle.no_language = MBSTRG(language);
needle.no_encoding = MBSTRG(current_internal_encoding)->no_encoding;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|zs", (char **)&haystack.val, &haystack_len, (char **)&needle.val, &needle_len, &zoffset, &enc_name, &enc_name_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|zs", (char **)&haystack.val, &haystack.len, (char **)&needle.val, &needle.len, &zoffset, &enc_name, &enc_name_len) == FAILURE) {
return;
}
- if (ZEND_SIZE_T_UINT_OVFL(haystack_len)) {
- php_error_docref(NULL, E_WARNING, "Haystack length overflows the max allowed length of %u", UINT_MAX);
- return;
- } else if (ZEND_SIZE_T_UINT_OVFL(needle_len)) {
- php_error_docref(NULL, E_WARNING, "Needle length overflows the max allowed length of %u", UINT_MAX);
- return;
- }
-
- haystack.len = (uint32_t)haystack_len;
- needle.len = (uint32_t)needle_len;
-
if (zoffset) {
if (Z_TYPE_P(zoffset) == IS_STRING) {
enc_name2 = Z_STRVAL_P(zoffset);
}
}
- if (haystack.len <= 0) {
- RETURN_FALSE;
- }
- if (needle.len <= 0) {
- RETURN_FALSE;
- }
-
{
- int haystack_char_len = mbfl_strlen(&haystack);
+ size_t haystack_char_len = mbfl_strlen(&haystack);
if ((offset > 0 && offset > haystack_char_len) ||
(offset < 0 && -offset > haystack_char_len)) {
php_error_docref(NULL, E_WARNING, "Offset is greater than the length of haystack string");
}
n = mbfl_strpos(&haystack, &needle, offset, 1);
- if (n >= 0) {
+ if (!mbfl_is_error(n)) {
RETVAL_LONG(n);
} else {
RETVAL_FALSE;
Finds position of first occurrence of a string within another, case insensitive */
PHP_FUNCTION(mb_stripos)
{
- int n = -1;
+ size_t n = (size_t) -1;
zend_long offset = 0;
mbfl_string haystack, needle;
const char *from_encoding = MBSTRG(current_internal_encoding)->mime_name;
- size_t from_encoding_len, haystack_len, needle_len;
+ size_t from_encoding_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|ls", (char **)&haystack.val, &haystack_len, (char **)&needle.val, &needle_len, &offset, &from_encoding, &from_encoding_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|ls", (char **)&haystack.val, &haystack.len, (char **)&needle.val, &needle.len, &offset, &from_encoding, &from_encoding_len) == FAILURE) {
return;
}
- if (ZEND_SIZE_T_UINT_OVFL(haystack_len)) {
- php_error_docref(NULL, E_WARNING, "Haystack length overflows the max allowed length of %u", UINT_MAX);
- return;
- } else if (ZEND_SIZE_T_UINT_OVFL(needle_len)) {
- php_error_docref(NULL, E_WARNING, "Needle length overflows the max allowed length of %u", UINT_MAX);
- return;
- }
-
- haystack.len = (uint32_t)haystack_len;
- needle.len = (uint32_t)needle_len;
-
if (needle.len == 0) {
php_error_docref(NULL, E_WARNING, "Empty delimiter");
RETURN_FALSE;
}
+
n = php_mb_stripos(0, (char *)haystack.val, haystack.len, (char *)needle.val, needle.len, offset, from_encoding);
- if (n >= 0) {
+ if (!mbfl_is_error(n)) {
RETVAL_LONG(n);
} else {
RETVAL_FALSE;
Finds position of last occurrence of a string within another, case insensitive */
PHP_FUNCTION(mb_strripos)
{
- int n = -1;
+ size_t n = (size_t) -1;
zend_long offset = 0;
mbfl_string haystack, needle;
const char *from_encoding = MBSTRG(current_internal_encoding)->mime_name;
- size_t from_encoding_len, haystack_len, needle_len;
+ size_t from_encoding_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|ls", (char **)&haystack.val, &haystack_len, (char **)&needle.val, &needle_len, &offset, &from_encoding, &from_encoding_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|ls", (char **)&haystack.val, &haystack.len, (char **)&needle.val, &needle.len, &offset, &from_encoding, &from_encoding_len) == FAILURE) {
return;
}
- if (ZEND_SIZE_T_UINT_OVFL(haystack_len)) {
- php_error_docref(NULL, E_WARNING, "Haystack length overflows the max allowed length of %u", UINT_MAX);
- return;
- } else if (ZEND_SIZE_T_UINT_OVFL(needle_len)) {
- php_error_docref(NULL, E_WARNING, "Needle length overflows the max allowed length of %u", UINT_MAX);
- return;
- }
-
- haystack.len = (uint32_t)haystack_len;
- needle.len = (uint32_t)needle_len;
-
n = php_mb_stripos(1, (char *)haystack.val, haystack.len, (char *)needle.val, needle.len, offset, from_encoding);
- if (n >= 0) {
+ if (!mbfl_is_error(n)) {
RETVAL_LONG(n);
} else {
RETVAL_FALSE;
Finds first occurrence of a string within another */
PHP_FUNCTION(mb_strstr)
{
- int n, len, mblen;
+ size_t n;
mbfl_string haystack, needle, result, *ret = NULL;
char *enc_name = NULL;
- size_t enc_name_len, haystack_len, needle_len;
+ size_t enc_name_len;
zend_bool part = 0;
mbfl_string_init(&haystack);
needle.no_language = MBSTRG(language);
needle.no_encoding = MBSTRG(current_internal_encoding)->no_encoding;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|bs", (char **)&haystack.val, &haystack_len, (char **)&needle.val, &needle_len, &part, &enc_name, &enc_name_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|bs", (char **)&haystack.val, &haystack.len, (char **)&needle.val, &needle.len, &part, &enc_name, &enc_name_len) == FAILURE) {
return;
}
- if (ZEND_SIZE_T_UINT_OVFL(haystack_len)) {
- php_error_docref(NULL, E_WARNING, "Haystack length overflows the max allowed length of %u", UINT_MAX);
- return;
- } else if (ZEND_SIZE_T_UINT_OVFL(needle_len)) {
- php_error_docref(NULL, E_WARNING, "Needle length overflows the max allowed length of %u", UINT_MAX);
- return;
- }
-
- haystack.len = (uint32_t)haystack_len;
- needle.len = (uint32_t)needle_len;
-
if (enc_name != NULL) {
haystack.no_encoding = needle.no_encoding = mbfl_name2no_encoding(enc_name);
if (haystack.no_encoding == mbfl_no_encoding_invalid) {
}
}
- if (needle.len <= 0) {
+ if (needle.len == 0) {
php_error_docref(NULL, E_WARNING, "Empty delimiter");
RETURN_FALSE;
}
+
n = mbfl_strpos(&haystack, &needle, 0, 0);
- if (n >= 0) {
- mblen = mbfl_strlen(&haystack);
+ if (!mbfl_is_error(n)) {
+ size_t mblen = mbfl_strlen(&haystack);
if (part) {
ret = mbfl_substr(&haystack, &result, 0, n);
if (ret != NULL) {
RETVAL_FALSE;
}
} else {
- len = (mblen - n);
+ size_t len = (mblen - n);
ret = mbfl_substr(&haystack, &result, n, len);
if (ret != NULL) {
// TODO: avoid reallocation ???
Finds the last occurrence of a character in a string within another */
PHP_FUNCTION(mb_strrchr)
{
- int n, len, mblen;
+ size_t n;
mbfl_string haystack, needle, result, *ret = NULL;
char *enc_name = NULL;
- size_t enc_name_len, haystack_len, needle_len;
+ size_t enc_name_len;
zend_bool part = 0;
mbfl_string_init(&haystack);
needle.no_language = MBSTRG(language);
needle.no_encoding = MBSTRG(current_internal_encoding)->no_encoding;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|bs", (char **)&haystack.val, &haystack_len, (char **)&needle.val, &needle_len, &part, &enc_name, &enc_name_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|bs", (char **)&haystack.val, &haystack.len, (char **)&needle.val, &needle.len, &part, &enc_name, &enc_name_len) == FAILURE) {
return;
}
- if (ZEND_SIZE_T_UINT_OVFL(haystack_len)) {
- php_error_docref(NULL, E_WARNING, "Haystack length overflows the max allowed length of %u", UINT_MAX);
- return;
- } else if (ZEND_SIZE_T_UINT_OVFL(needle_len)) {
- php_error_docref(NULL, E_WARNING, "Needle length overflows the max allowed length of %u", UINT_MAX);
- return;
- }
-
- haystack.len = (uint32_t)haystack_len;
- needle.len = (uint32_t)needle_len;
-
if (enc_name != NULL) {
haystack.no_encoding = needle.no_encoding = mbfl_name2no_encoding(enc_name);
if (haystack.no_encoding == mbfl_no_encoding_invalid) {
}
}
- if (haystack.len <= 0) {
+ if (haystack.len == 0) {
RETURN_FALSE;
}
- if (needle.len <= 0) {
+ if (needle.len == 0) {
RETURN_FALSE;
}
+
n = mbfl_strpos(&haystack, &needle, 0, 1);
- if (n >= 0) {
- mblen = mbfl_strlen(&haystack);
+ if (!mbfl_is_error(n)) {
+ size_t mblen = mbfl_strlen(&haystack);
if (part) {
ret = mbfl_substr(&haystack, &result, 0, n);
if (ret != NULL) {
RETVAL_FALSE;
}
} else {
- len = (mblen - n);
+ size_t len = (mblen - n);
ret = mbfl_substr(&haystack, &result, n, len);
if (ret != NULL) {
// TODO: avoid reallocation ???
PHP_FUNCTION(mb_stristr)
{
zend_bool part = 0;
- size_t from_encoding_len, len, mblen, haystack_len, needle_len;
- int n;
+ size_t from_encoding_len, n, len, mblen;
mbfl_string haystack, needle, result, *ret = NULL;
const char *from_encoding = MBSTRG(current_internal_encoding)->mime_name;
mbfl_string_init(&haystack);
needle.no_language = MBSTRG(language);
needle.no_encoding = MBSTRG(current_internal_encoding)->no_encoding;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|bs", (char **)&haystack.val, &haystack_len, (char **)&needle.val, &needle_len, &part, &from_encoding, &from_encoding_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|bs", (char **)&haystack.val, &haystack.len, (char **)&needle.val, &needle.len, &part, &from_encoding, &from_encoding_len) == FAILURE) {
return;
}
- if (ZEND_SIZE_T_UINT_OVFL(haystack_len)) {
- php_error_docref(NULL, E_WARNING, "Haystack length overflows the max allowed length of %u", UINT_MAX);
- return;
- } else if (ZEND_SIZE_T_UINT_OVFL(needle_len)) {
- php_error_docref(NULL, E_WARNING, "Needle length overflows the max allowed length of %u", UINT_MAX);
- return;
- }
-
- haystack.len = (uint32_t)haystack_len;
- needle.len = (uint32_t)needle_len;
-
if (!needle.len) {
php_error_docref(NULL, E_WARNING, "Empty delimiter");
RETURN_FALSE;
}
n = php_mb_stripos(0, (char *)haystack.val, haystack.len, (char *)needle.val, needle.len, 0, from_encoding);
-
- if (n <0) {
+ if (mbfl_is_error(n)) {
RETURN_FALSE;
}
PHP_FUNCTION(mb_strrichr)
{
zend_bool part = 0;
- int n, len, mblen;
- size_t from_encoding_len, haystack_len, needle_len;
+ size_t n, len, mblen;
+ size_t from_encoding_len;
mbfl_string haystack, needle, result, *ret = NULL;
const char *from_encoding = MBSTRG(current_internal_encoding)->name;
mbfl_string_init(&haystack);
needle.no_encoding = MBSTRG(current_internal_encoding)->no_encoding;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|bs", (char **)&haystack.val, &haystack_len, (char **)&needle.val, &needle_len, &part, &from_encoding, &from_encoding_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|bs", (char **)&haystack.val, &haystack.len, (char **)&needle.val, &needle.len, &part, &from_encoding, &from_encoding_len) == FAILURE) {
return;
}
- if (ZEND_SIZE_T_UINT_OVFL(haystack_len)) {
- php_error_docref(NULL, E_WARNING, "Haystack length overflows the max allowed length of %u", UINT_MAX);
- return;
- } else if (ZEND_SIZE_T_UINT_OVFL(needle_len)) {
- php_error_docref(NULL, E_WARNING, "Needle length overflows the max allowed length of %u", UINT_MAX);
- return;
- }
-
- haystack.len = (uint32_t)haystack_len;
- needle.len = (uint32_t)needle_len;
-
haystack.no_encoding = needle.no_encoding = mbfl_name2no_encoding(from_encoding);
if (haystack.no_encoding == mbfl_no_encoding_invalid) {
php_error_docref(NULL, E_WARNING, "Unknown encoding \"%s\"", from_encoding);
}
n = php_mb_stripos(1, (char *)haystack.val, haystack.len, (char *)needle.val, needle.len, 0, from_encoding);
-
- if (n <0) {
+ if (mbfl_is_error(n)) {
RETURN_FALSE;
}
Count the number of substring occurrences */
PHP_FUNCTION(mb_substr_count)
{
- int n;
+ size_t n;
mbfl_string haystack, needle;
char *enc_name = NULL;
- size_t enc_name_len, haystack_len, needle_len;
+ size_t enc_name_len;
mbfl_string_init(&haystack);
mbfl_string_init(&needle);
needle.no_language = MBSTRG(language);
needle.no_encoding = MBSTRG(current_internal_encoding)->no_encoding;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|s", (char **)&haystack.val, &haystack_len, (char **)&needle.val, &needle_len, &enc_name, &enc_name_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|s", (char **)&haystack.val, &haystack.len, (char **)&needle.val, &needle.len, &enc_name, &enc_name_len) == FAILURE) {
return;
}
- if (ZEND_SIZE_T_UINT_OVFL(haystack_len)) {
- php_error_docref(NULL, E_WARNING, "Haystack length overflows the max allowed length of %u", UINT_MAX);
- return;
- } else if (ZEND_SIZE_T_UINT_OVFL(needle_len)) {
- php_error_docref(NULL, E_WARNING, "Needle length overflows the max allowed length of %u", UINT_MAX);
- return;
- }
-
- haystack.len = (uint32_t)haystack_len;
- needle.len = (uint32_t)needle_len;
-
if (enc_name != NULL) {
haystack.no_encoding = needle.no_encoding = mbfl_name2no_encoding(enc_name);
if (haystack.no_encoding == mbfl_no_encoding_invalid) {
}
}
- if (needle.len <= 0) {
+ if (needle.len == 0) {
php_error_docref(NULL, E_WARNING, "Empty substring");
RETURN_FALSE;
}
n = mbfl_substr_count(&haystack, &needle);
- if (n >= 0) {
+ if (!mbfl_is_error(n)) {
RETVAL_LONG(n);
} else {
RETVAL_FALSE;
{
char *str, *encoding = NULL;
zend_long from, len;
- int mblen;
+ size_t mblen;
size_t str_len, encoding_len;
zend_bool len_is_null = 1;
mbfl_string string, result, *ret;
{
char *encoding = NULL;
zend_long from, len;
- size_t encoding_len, string_len;
+ size_t encoding_len;
zend_bool len_is_null = 1;
mbfl_string string, result, *ret;
string.no_language = MBSTRG(language);
string.no_encoding = MBSTRG(current_internal_encoding)->no_encoding;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "sl|l!s", (char **)&string.val, &string_len, &from, &len, &len_is_null, &encoding, &encoding_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "sl|l!s", (char **)&string.val, &string.len, &from, &len, &len_is_null, &encoding, &encoding_len) == FAILURE) {
return;
}
- if (ZEND_SIZE_T_UINT_OVFL(string_len)) {
- php_error_docref(NULL, E_WARNING, "String length overflows the max allowed length of %u", UINT_MAX);
- return;
- }
-
- string.len = (uint32_t)string_len;
-
if (encoding) {
string.no_encoding = mbfl_name2no_encoding(encoding);
if (string.no_encoding == mbfl_no_encoding_invalid) {
Gets terminal width of a string */
PHP_FUNCTION(mb_strwidth)
{
- int n;
+ size_t n;
mbfl_string string;
char *enc_name = NULL;
- size_t enc_name_len, string_len;
+ size_t enc_name_len;
mbfl_string_init(&string);
string.no_language = MBSTRG(language);
string.no_encoding = MBSTRG(current_internal_encoding)->no_encoding;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|s", (char **)&string.val, &string_len, &enc_name, &enc_name_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|s", (char **)&string.val, &string.len, &enc_name, &enc_name_len) == FAILURE) {
return;
}
- if (ZEND_SIZE_T_UINT_OVFL(string_len)) {
- php_error_docref(NULL, E_WARNING, "String length overflows the max allowed length of %u", UINT_MAX);
- return;
- }
-
- string.len = (uint32_t)string_len;
-
if (enc_name != NULL) {
string.no_encoding = mbfl_name2no_encoding(enc_name);
if (string.no_encoding == mbfl_no_encoding_invalid) {
}
n = mbfl_strwidth(&string);
- if (n >= 0) {
+ if (!mbfl_is_error(n)) {
RETVAL_LONG(n);
} else {
RETVAL_FALSE;
Conversion between full-width character and half-width character (Japanese) */
PHP_FUNCTION(mb_convert_kana)
{
- int opt, i;
+ int opt;
mbfl_string string, result, *ret;
char *optstr = NULL;
size_t optstr_len;
/* option */
if (optstr != NULL) {
char *p = optstr;
- int n = optstr_len;
- i = 0;
+ size_t i = 0, n = optstr_len;
opt = 0;
while (i < n) {
i++;
/* {{{ MBSTRING_API int php_mb_stripos()
*/
-MBSTRING_API int php_mb_stripos(int mode, const char *old_haystack, unsigned int old_haystack_len, const char *old_needle, unsigned int old_needle_len, long offset, const char *from_encoding)
+MBSTRING_API size_t php_mb_stripos(int mode, const char *old_haystack, size_t old_haystack_len, const char *old_needle, size_t old_needle_len, long offset, const char *from_encoding)
{
- int n = -1;
+ size_t n = (size_t) -1;
mbfl_string haystack, needle;
const mbfl_encoding *enc;
enc = php_mb_get_encoding(from_encoding);
if (!enc) {
- return -1;
+ return (size_t) -1;
}
mbfl_string_init(&haystack);
break;
}
- if (haystack.len <= 0) {
+ if (haystack.len == 0) {
break;
}
break;
}
- if (needle.len <= 0) {
+ if (needle.len == 0) {
break;
}
{
- int haystack_char_len = mbfl_strlen(&haystack);
+ size_t haystack_char_len = mbfl_strlen(&haystack);
if (mode) {
if ((offset > 0 && offset > haystack_char_len) ||