[php-i18n-commits] cvs commit: php4/ext/mbstring mbstring.c

アーカイブの一覧に戻る

Moriyoshi Koizumi moriy****@users*****
2002年 10月 1日 (火) 03:31:31 JST


moriyoshi    02/10/01 03:31:31

  Modified:    ext/mbstring mbstring.c
  Log:
  reimplemented mb_parse_str() to use php_mbstr_encoding_handler_ex()
  
  Revision  Changes    Path
  1.17      +16 -177   php4/ext/mbstring/mbstring.c
  
  Index: mbstring.c
  ===================================================================
  RCS file: /cvsroot/php-i18n/php4/ext/mbstring/mbstring.c,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- mbstring.c	10 Aug 2002 03:36:47 -0000	1.16
  +++ mbstring.c	30 Sep 2002 18:31:31 -0000	1.17
  @@ -59,6 +59,7 @@
   #include "ext/standard/php_mail.h"
   #include "ext/standard/url.h"
   #include "ext/standard/info.h"
  +#include "post.h"
   
   /* #undef ZEND_MULTIBYTE temporary undef for ZE2 */
   
  @@ -1523,11 +1524,8 @@
   PHP_FUNCTION(mb_parse_str)
   {
   	zval **arg_str, **arg_array, *track_vars_array;
  -	char *var, *val, *encstr, *strtok_buf, **str_list, *separator;
  -	int n, num, val_len, *len_list, elistsz, old_rg, argc;
  -	php_mb_enc *from_encoding, *to_encoding, **elist;
  -	php_mb_detector *identd;
  -	php_mb_bufconv *convd;
  +	char *encstr = NULL, *separator = NULL;
  +	int argc;
   
   	PHP_MB_ERRRST();
   	track_vars_array = NULL;
  @@ -1547,179 +1545,22 @@
   	} else {
   		WRONG_PARAM_COUNT;
   	}
  -	separator = (char *)estrdup(PG(arg_separator).input);
  -	if (separator == NULL) {
  -		RETURN_FALSE;
  +	if ( (separator = (char *)estrdup(PG(arg_separator).input)) == NULL ) {
  +		RETVAL_FALSE;
  +		goto out;
   	}
   	convert_to_string_ex(arg_str);
  -	encstr = estrndup(Z_STRVAL_PP(arg_str), Z_STRLEN_PP(arg_str));
  -	if (encstr == NULL) {
  -		efree(separator);
  -		RETURN_FALSE;
  -	}
  -
  -	/* count the variables contained in the query */
  -	num = 1;
  -	var = encstr;
  -	n = Z_STRLEN_PP(arg_str);
  -	while (n > 0) {
  -		val = separator;
  -		while (*val != '\0') {
  -			if (*var == *val) {
  -				num++;
  -			}
  -			val++;
  -		}
  -		var++;
  -		n--;
  -	}
  -	num *= 2;
  -	str_list = (char **)ecalloc(num, sizeof(char *));
  -	if (str_list == NULL) {
  -		efree(separator);
  -		efree(encstr);
  -		RETURN_FALSE;
  -	}
  -	len_list = (int *)ecalloc(num, sizeof(int));
  -	if (len_list == NULL) {
  -		efree(separator);
  -		efree(encstr);
  -		efree(str_list);
  -		RETURN_FALSE;
  -	}
  -
  -	/* split and decode the query */
  -	n = 0;
  -	strtok_buf = NULL;
  -	var = php_strtok_r(encstr, separator, &strtok_buf);
  -	while (var && n < num) {
  -		val = strchr(var, '=');
  -		if (val) { /* have a value */
  -			*val++ = '\0';
  -			str_list[n] = var;
  -			len_list[n] = php_url_decode(var, strlen(var));
  -			n++;
  -			str_list[n] = val;
  -			len_list[n] = php_url_decode(val, strlen(val));
  -		} else {
  -			str_list[n] = var;
  -			len_list[n] = php_url_decode(var, strlen(var));
  -			n++;
  -			str_list[n] = empty_string;
  -			len_list[n] = 0;
  -		}
  -		n++;
  -		var = php_strtok_r(NULL, separator, &strtok_buf);
  -	}
  -	num = n;
  -
  -	/* initialize converter */
  -	convd = NULL;
  -	from_encoding = NULL;
  -	to_encoding = MBSTRG(internal_encoding_r);
  -	elist = NULL;
  -	elistsz = 0;
  -	php_mb_parse_encoding_list(MBSTRG(http_input), &elist, &elistsz, 0  TSRMLS_CC);
  -	if (elistsz == 1) {
  -		from_encoding = elist[0];
  -	} else if (elistsz >1) {
  -		/* auto detect */
  -		identd = php_mb_detector_create(elist, elistsz TSRMLS_CC);
  -		if (identd != NULL) {
  -			n = 0;
  -			while (n < num) {
  -				if (php_mb_detector_feed(identd, str_list[n], len_list[n]  TSRMLS_CC)) {
  -					break;
  -				}
  -				n++;
  -			}
  -			from_encoding = php_mb_detector_judge(identd TSRMLS_CC);
  -			php_mb_detector_free(identd TSRMLS_CC);
  -		}
  -		if (from_encoding == NULL) {
  -			php_error(E_WARNING, "%s() unable to detect encoding",
  -					  get_active_function_name(TSRMLS_C));
  -		}
  -	}
  -	if (from_encoding != NULL) {
  -		convd = php_mb_bufconv_create(to_encoding, from_encoding, 0 TSRMLS_CC);
  -		if (convd == NULL) {
  -			php_mb_error();
  -		}
  -	}
  -	if (elist != NULL) {
  -		efree(elist);
  -	}
  -
  -	/* convert encoding */
  -	old_rg = PG(register_globals);
  -	if(argc == 1) {
  -		PG(register_globals) = 1;
  -	} else {
  -		PG(register_globals) = 0;
  -	}
  -	if (convd != NULL) {
  -		n = 0;
  -		while (n < num) {
  -			var = NULL;
  -			val = NULL;
  -			val_len = 0;
  -			if (php_mb_bufconv_feed(convd, str_list[n], len_list[n]  TSRMLS_CC) == SUCCESS) {
  -				php_mb_bufconv_flush(convd  TSRMLS_CC);
  -				php_mb_bufconv_extract(convd, &var, NULL  TSRMLS_CC);
  -			}
  -			php_mb_bufconv_clear(convd  TSRMLS_CC);
  -			n++;
  -			if (php_mb_bufconv_feed(convd, str_list[n], len_list[n]  TSRMLS_CC) == SUCCESS) {
  -				php_mb_bufconv_flush(convd  TSRMLS_CC);
  -				php_mb_bufconv_extract(convd, &val, &val_len  TSRMLS_CC);
  -			}
  -			php_mb_bufconv_clear(convd  TSRMLS_CC);
  -			n++;
  -			/* add variable to symbol table */
  -			if (var != NULL && val != NULL) {
  -				php_register_variable_safe(var, val, val_len, track_vars_array TSRMLS_CC);
  -			}
  -			if (var != NULL){
  -				efree(var);
  -			}
  -			if (val != NULL){
  -				efree(val);
  -			}
  -		}
  -	} else {
  -		n = 0;
  -		while (n < num) {
  -			var = str_list[n];
  -			n++;
  -			val = str_list[n];
  -			val_len = len_list[n];
  -			n++;
  -			/* add variable to symbol table */
  -			php_register_variable_safe(var, val, val_len, track_vars_array TSRMLS_CC);
  -		}
  -	}
  -	PG(register_globals) = old_rg;
  -
  -	if (convd != NULL) {
  -		php_mb_bufconv_free(convd TSRMLS_CC);
  -	}
  -	efree(str_list);
  -	efree(len_list);
  -	efree(encstr);
  -	efree(separator);
  -	if (from_encoding != NULL) {
  -		MBSTRG(http_input_identify) = from_encoding;
  -	} else {
  -		MBSTRG(http_input_identify) = php_mb_enc_get(php_mb_encid_pass);
  +	if ( (encstr = estrndup(Z_STRVAL_PP(arg_str), Z_STRLEN_PP(arg_str))) == NULL ) {
  +		RETVAL_FALSE;
  +		goto out;
   	}
  -	MBSTRG(http_input_identify_string) = MBSTRG(http_input_identify);
  -	RETURN_TRUE;
  +	RETVAL_BOOL( php_mbstr_encoding_handler_ex(track_vars_array, encstr, separator, (argc == 1) ) );
  +out:
  +	if ( encstr != NULL ) efree((void *)encstr);
  +	if ( separator != NULL ) efree((void *)separator);
   }
   /* }}} */
   
  -
  -
   /* {{{ proto string mb_output_handler(string contents, int status)
      Returns string in output buffer converted to the http_output encoding */
   PHP_FUNCTION(mb_output_handler)
  @@ -2286,7 +2127,6 @@
   /* }}} */
   
   
  -
   /* {{{ proto string mb_strimwidth(string str, int start, int width [, string trimmarker [, string encoding]])
      Trim the string in terminal width */
   PHP_FUNCTION(mb_strimwidth)
  @@ -2346,7 +2186,6 @@
   /* }}} */
   
   
  -
   /* {{{ proto string mb_convert_encoding(string str, string to-encoding [, mixed from-encoding])
      Returns converted string in desired encoding */
   PHP_FUNCTION(mb_convert_encoding)
  @@ -2478,7 +2317,6 @@
   /* }}} */
   
   
  -
   /* {{{ proto string mb_encode_mimeheader(string str [, string charset [, string transfer-encoding [, string linefeed]]])
      Converts the string to MIME "encoded-word" in the format of =?charset?(B|Q)?encoded_string?= */
   PHP_FUNCTION(mb_encode_mimeheader)
  @@ -2532,7 +2370,6 @@
   /* }}} */
   
   
  -
   /* {{{ proto string mb_decode_mimeheader(string string)
      Decodes the MIME "encoded-word" in the string */
   PHP_FUNCTION(mb_decode_mimeheader)
  @@ -2558,7 +2395,6 @@
   /* }}} */
   
   
  -
   /* {{{ proto string mb_convert_kana(string str [, string option] [, string encoding])
      Conversion between full-width character and half-width character (Japanese) */
   PHP_FUNCTION(mb_convert_kana)
  @@ -2668,6 +2504,8 @@
   }
   /* }}} */
   
  +
  +
   #define PHP_MBSTR_STACK_BLOCK_SIZE 32
   
   #define PHP_MBSTR_ADJUST_STACK()								\
  @@ -6406,4 +6244,5 @@
    * tab-width: 4
    * c-basic-offset: 4
    * End:
  + * vim600: ts=4 fdm=marker
    */
  
  
  



php-i18n-commits メーリングリストの案内
アーカイブの一覧に戻る