Tsukada
ttsuk****@users*****
2002年 6月 9日 (日) 13:41:24 JST
ttsukada 02/06/09 13:41:24 Modified: ext/mbstring filter.c mbfunction.c mbstring.c mbstring.h php_mb.h php_mb_filter.h Log: added method of mbString class Revision Changes Path 1.6 +19 -0 php4/ext/mbstring/filter.c Index: filter.c =================================================================== RCS file: /cvsroot/php-i18n/php4/ext/mbstring/filter.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- filter.c 26 May 2002 06:06:36 -0000 1.5 +++ filter.c 9 Jun 2002 04:41:23 -0000 1.6 @@ -199,6 +199,25 @@ return SUCCESS; } +PHPAPI int +_php_mb_conv_filt_is_supported(php_mb_enc *from, php_mb_enc *to TSRMLS_DC) +{ + mbfl_convert_collection *convert_collection; + + if (from == NULL || to == NULL) { + PHP_MB_ERRSET(PHP_MB_ERR_NULL_POINTER); + return 0; + } + + /* get convert function table */ + convert_collection = get_convert_collection(from, to TSRMLS_CC); + PHP_MB_ERRRST(); + if (convert_collection == NULL) { + return 0; + } + return 1; +} + PHPAPI void php_mb_conv_filt_state_save(mbfl_convert_filter *filter) 1.10 +3 -0 php4/ext/mbstring/mbfunction.c Index: mbfunction.c =================================================================== RCS file: /cvsroot/php-i18n/php4/ext/mbstring/mbfunction.c,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- mbfunction.c 2 Jun 2002 16:30:37 -0000 1.9 +++ mbfunction.c 9 Jun 2002 04:41:23 -0000 1.10 @@ -43,6 +43,9 @@ case PHP_MB_ERR_ILLEGAL_ARGUMENT: result = "Illegal argument"; break; + case PHP_MB_ERR_MISSING_PROPERTY: + result = "Object is missing a property"; + break; case PHP_MB_ERR_INDEX_OUT_OF_BOUNDS: result = "Index out of bounds"; break; 1.13 +231 -35 php4/ext/mbstring/mbstring.c Index: mbstring.c =================================================================== RCS file: /cvsroot/php-i18n/php4/ext/mbstring/mbstring.c,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- mbstring.c 4 Jun 2002 21:40:20 -0000 1.12 +++ mbstring.c 9 Jun 2002 04:41:23 -0000 1.13 @@ -219,7 +219,11 @@ static function_entry php_mb_str_class_functions[] = { PHP_FALIAS(mbstring, mb_str_create, NULL) PHP_FALIAS(free, mb_str_free, NULL) + PHP_FALIAS(encoding, mb_str_encoding, NULL) PHP_FALIAS(to_string, mb_str_to_string, NULL) + PHP_FALIAS(extract, mb_str_extract, NULL) + PHP_FALIAS(length, mb_str_length, NULL) + PHP_FALIAS(byte_len, mb_str_byte_len, NULL) { NULL, NULL, NULL } }; @@ -259,6 +263,7 @@ PHP_FALIAS(free, mb_filter_free, NULL) PHP_FALIAS(flush, mb_filter_flush, NULL) PHP_FALIAS(feed, mb_filter_feed, NULL) + PHP_FALIAS(is_supported, mb_filter_is_supported, NULL) { NULL, NULL, NULL } }; @@ -3421,65 +3426,79 @@ str = zend_list_find(Z_RESVAL_PP(id), &t); \ } \ if (t != le_string) { \ - PHP_MB_ERRSET(PHP_MB_ERR_ILLEGAL_ARGUMENT); \ + PHP_MB_ERRSET(PHP_MB_ERR_MISSING_PROPERTY); \ php_mb_error(); \ RETURN_FALSE; \ } \ } -/* {{{ proto object mb_str_create([mixed object [, encoding]]) +/* {{{ proto object mb_str_create([mixed text [, encoding]]) Create mbString object */ PHP_FUNCTION(mb_str_create) { - zval **arg1, **objid, *result, *prop; + zval **arg_text, **arg_enc, **objid, *result, *prop; int type; void *ptr; - php_mb_str *string, *srcstr; - php_mb_buf *srcbuf; + php_mb_enc *encoding; + php_mb_str *string; PHP_MB_ERRRST(); + arg_text = NULL; + arg_enc = NULL; if (ZEND_NUM_ARGS() != 0 && - (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE)) { + (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg_text) == FAILURE) && + (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg_text, &arg_enc) == FAILURE)) { WRONG_PARAM_COUNT; } - objid = NULL; - type = 0; - srcstr = NULL; - srcbuf = NULL; - string = NULL; - if (ZEND_NUM_ARGS() == 1) { - switch (Z_TYPE_PP(arg1)) { + string = php_mb_str_create(); + if (string == NULL) { + php_mb_error(); + RETURN_FALSE; + } + if (arg_enc == NULL) { + encoding = MBSTRG(internal_encoding_r); + } else { + convert_to_string_ex(arg_enc); + encoding = php_mb_enc_resolve(Z_STRVAL_PP(arg_enc)); + if (encoding == NULL) { + php_mb_error(); + RETURN_FALSE; + } + } + string->encoding = encoding; + if (arg_text != NULL) { + objid = NULL; + type = 0; + switch (Z_TYPE_PP(arg_text)) { case IS_OBJECT: - if (zend_hash_index_find(Z_OBJPROP_PP(arg1), 0, (void **) &objid) == SUCCESS) { + if (zend_hash_index_find(Z_OBJPROP_PP(arg_text), 0, (void **) &objid) == SUCCESS && Z_TYPE_PP(objid) == IS_RESOURCE) { ptr = zend_list_find(Z_RESVAL_PP(objid), &type); } if (type == le_string) { - srcstr = ptr; - string= php_mb_str_create(); - if (string != NULL) { - string->encoding = srcstr->encoding; - php_mb_str_concat(string, srcstr); - } + string->encoding = ((php_mb_str *)ptr)->encoding; + php_mb_str_concat(string, (php_mb_str *)ptr); + break; + } else if (type == le_buffer) { + char *result_val; + size_t result_len; + + result_val = php_mb_convert_wchar_to_encoding((php_mb_buf *)ptr, encoding, &result_len); + string->value = result_val; + string->length = result_len; break; } /* fall through */ default: - convert_to_string_ex(arg1); - string= php_mb_str_create(); - if (string != NULL) { - php_mb_str_append_cstrn(string, Z_STRVAL_PP(arg1), Z_STRLEN_PP(arg1)); - } + convert_to_string_ex(arg_text); + php_mb_str_append_cstrn(string, Z_STRVAL_PP(arg_text), Z_STRLEN_PP(arg_text)); break; } - } else { - string= php_mb_str_create(); } - if (string == NULL) { + php_mb_str_nullpad(string); + if (PHP_MB_IS_ERROR()) { php_mb_error(); - RETURN_FALSE; } - php_mb_str_nullpad(string); result = getThis(); if (result == NULL) { @@ -3517,10 +3536,161 @@ } /* }}} */ -/* {{{ proto void mb_str_to_string(object string) +/* {{{ proto string mb_str_encoding(object string) + */ +PHP_FUNCTION(mb_str_encoding) +{ + zval **arg_obj, *object, **objid; + int type; + php_mb_str *string; + + PHP_MB_ERRRST(); + arg_obj = NULL; + if (ZEND_NUM_ARGS() != 0 && + (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg_obj) == FAILURE)) { + WRONG_PARAM_COUNT; + } + + objid = NULL; + type = 0; + string = NULL; + PHP_MB_CHECK_OBJECT(object, arg_obj); + PHP_MB_FETCH_STRING(object, objid, type, string); + RETVAL_STRING((char *)string->encoding->name, 1); +} +/* }}} */ + +/* {{{ proto string mb_str_to_string(object string) */ PHP_FUNCTION(mb_str_to_string) { + zval **arg_obj, *object, **objid; + int type; + php_mb_str *string; + + PHP_MB_ERRRST(); + arg_obj = NULL; + if (ZEND_NUM_ARGS() != 0 && + (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg_obj) == FAILURE)) { + WRONG_PARAM_COUNT; + } + + objid = NULL; + type = 0; + string = NULL; + PHP_MB_CHECK_OBJECT(object, arg_obj); + PHP_MB_FETCH_STRING(object, objid, type, string); + if (string->encoding->id == MBSTRG(internal_encoding_r)->id) { + RETVAL_STRINGL(string->value, string->length, 1); + } else { + char *result_val; + size_t result_len; + + result_val = _php_mb_convert_encoding(string->value, string->length, MBSTRG(internal_encoding_r), string->encoding, &result_len TSRMLS_CC); + if (result_val != NULL) { + RETVAL_STRINGL(result_val, result_len, 0); + } else { + php_mb_error(); + RETVAL_FALSE; + } + } +} +/* }}} */ + +/* {{{ proto string mb_str_extract(object string) + */ +PHP_FUNCTION(mb_str_extract) +{ + zval **arg_obj, *object, **objid; + int type; + char *result_val; + size_t result_len; + php_mb_str *string; + + PHP_MB_ERRRST(); + arg_obj = NULL; + if (ZEND_NUM_ARGS() != 0 && + (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg_obj) == FAILURE)) { + WRONG_PARAM_COUNT; + } + + objid = NULL; + type = 0; + string = NULL; + PHP_MB_CHECK_OBJECT(object, arg_obj); + PHP_MB_FETCH_STRING(object, objid, type, string); + result_val = NULL; + result_len = 0; + php_mb_str_nullpad(string); + php_mb_str_extract(string, &result_val, &result_len); + if (result_val != NULL) { + RETVAL_STRINGL(result_val, result_len, 0); + } else { + RETVAL_EMPTY_STRING(); + } + if (PHP_MB_IS_ERROR()) { + php_mb_error(); + } +} +/* }}} */ + +/* {{{ proto int mb_str_length(object string) + */ +PHP_FUNCTION(mb_str_length) +{ + zval **arg_obj, *object, **objid; + int type; + size_t result; + php_mb_str *string; + + PHP_MB_ERRRST(); + arg_obj = NULL; + if (ZEND_NUM_ARGS() != 0 && + (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg_obj) == FAILURE)) { + WRONG_PARAM_COUNT; + } + + objid = NULL; + type = 0; + string = NULL; + PHP_MB_CHECK_OBJECT(object, arg_obj); + PHP_MB_FETCH_STRING(object, objid, type, string); + + if (string->value == NULL || string->length == 0) { + RETVAL_LONG(0); + } else { + result = _php_mb_strlen(string->value, string->length, string->encoding TSRMLS_DC); + if (PHP_MB_IS_ERROR()) { + php_mb_error(); + RETVAL_FALSE; + } else { + RETVAL_LONG(result); + } + } +} +/* }}} */ + +/* {{{ proto int mb_str_byte_len(object string) + */ +PHP_FUNCTION(mb_str_byte_len) +{ + zval **arg_obj, *object, **objid; + int type; + php_mb_str *string; + + PHP_MB_ERRRST(); + arg_obj = NULL; + if (ZEND_NUM_ARGS() != 0 && + (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg_obj) == FAILURE)) { + WRONG_PARAM_COUNT; + } + + objid = NULL; + type = 0; + string = NULL; + PHP_MB_CHECK_OBJECT(object, arg_obj); + PHP_MB_FETCH_STRING(object, objid, type, string); + RETVAL_LONG(string->length); } /* }}} */ @@ -3536,7 +3706,7 @@ buf = zend_list_find(Z_RESVAL_PP(id), &t); \ } \ if (t != le_buffer) { \ - PHP_MB_ERRSET(PHP_MB_ERR_ILLEGAL_ARGUMENT); \ + PHP_MB_ERRSET(PHP_MB_ERR_MISSING_PROPERTY); \ php_mb_error(); \ RETURN_FALSE; \ } \ @@ -5062,7 +5232,7 @@ fil = zend_list_find(Z_RESVAL_PP(id), &t); \ } \ if (t != le_filter) { \ - PHP_MB_ERRSET(PHP_MB_ERR_ILLEGAL_ARGUMENT); \ + PHP_MB_ERRSET(PHP_MB_ERR_MISSING_PROPERTY); \ php_mb_error(); \ RETURN_FALSE; \ } \ @@ -5238,6 +5408,32 @@ } /* }}} */ +/* {{{ proto object mb_filter_is_supported(string to, string from) + */ +PHP_FUNCTION(mb_filter_is_supported) +{ + zval **arg_to, **arg_from; + php_mb_enc *to_encoding, *from_encoding; + + PHP_MB_ERRRST(); + if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg_to, &arg_from) == FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_string_ex(arg_to); + convert_to_string_ex(arg_from); + to_encoding = php_mb_enc_resolve(Z_STRVAL_PP(arg_to)); + from_encoding = php_mb_enc_resolve(Z_STRVAL_PP(arg_from)); + if (to_encoding == NULL || from_encoding == NULL) { + php_mb_error(); + RETURN_FALSE; + } + if (php_mb_conv_filt_is_supported(from_encoding, to_encoding)) { + RETVAL_TRUE; + } else { + RETVAL_FALSE; + } +} + /* @@ -5700,7 +5896,7 @@ cv = zend_list_find(Z_RESVAL_PP(id), &t); \ } \ if (t != le_bufconv) { \ - PHP_MB_ERRSET(PHP_MB_ERR_ILLEGAL_ARGUMENT); \ + PHP_MB_ERRSET(PHP_MB_ERR_MISSING_PROPERTY); \ php_mb_error(); \ RETURN_FALSE; \ } \ @@ -5987,7 +6183,7 @@ det = zend_list_find(Z_RESVAL_PP(id), &t); \ } \ if (t != le_detector) { \ - PHP_MB_ERRSET(PHP_MB_ERR_ILLEGAL_ARGUMENT); \ + PHP_MB_ERRSET(PHP_MB_ERR_MISSING_PROPERTY); \ php_mb_error(); \ RETURN_FALSE; \ } \ 1.9 +6 -0 php4/ext/mbstring/mbstring.h Index: mbstring.h =================================================================== RCS file: /cvsroot/php-i18n/php4/ext/mbstring/mbstring.h,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- mbstring.h 4 Jun 2002 21:40:20 -0000 1.8 +++ mbstring.h 9 Jun 2002 04:41:23 -0000 1.9 @@ -79,6 +79,7 @@ PHP_FUNCTION(mb_get_lookup_table); PHP_FUNCTION(mb_register_lookup_table); PHP_FUNCTION(mb_get_convert_cllection); +PHP_FUNCTION(mb_is_supported_convert); PHP_FUNCTION(mb_preferred_mime_name); PHP_FUNCTION(mb_parse_str); PHP_FUNCTION(mb_output_handler); @@ -104,7 +105,11 @@ PHP_FUNCTION(mb_str_create); PHP_FUNCTION(mb_str_free); +PHP_FUNCTION(mb_str_encoding); PHP_FUNCTION(mb_str_to_string); +PHP_FUNCTION(mb_str_extract); +PHP_FUNCTION(mb_str_length); +PHP_FUNCTION(mb_str_byte_len); PHP_FUNCTION(mb_buf_create); PHP_FUNCTION(mb_buf_free); @@ -138,6 +143,7 @@ PHP_FUNCTION(mb_filter_free); PHP_FUNCTION(mb_filter_flush); PHP_FUNCTION(mb_filter_feed); +PHP_FUNCTION(mb_filter_is_supported); PHP_FUNCTION(mb_iterator_create); PHP_FUNCTION(mb_iterator_free); 1.5 +1 -0 php4/ext/mbstring/php_mb.h Index: php_mb.h =================================================================== RCS file: /cvsroot/php-i18n/php4/ext/mbstring/php_mb.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- php_mb.h 26 May 2002 06:14:21 -0000 1.4 +++ php_mb.h 9 Jun 2002 04:41:23 -0000 1.5 @@ -171,6 +171,7 @@ PHP_MB_ERR_UNSUPPORTED_CONVERT, PHP_MB_ERR_UNSUPPORTED_IDENTIFY, PHP_MB_ERR_ILLEGAL_ARGUMENT, + PHP_MB_ERR_MISSING_PROPERTY, PHP_MB_ERR_INDEX_OUT_OF_BOUNDS, PHP_MB_ERR_ENCODING_DETECT_FAILURE, PHP_MB_ERR_NOT_FOUND 1.2 +2 -0 php4/ext/mbstring/php_mb_filter.h Index: php_mb_filter.h =================================================================== RCS file: /cvsroot/php-i18n/php4/ext/mbstring/php_mb_filter.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- php_mb_filter.h 20 May 2002 11:15:54 -0000 1.1 +++ php_mb_filter.h 9 Jun 2002 04:41:23 -0000 1.2 @@ -16,6 +16,7 @@ PHPAPI void _php_mb_conv_filt_clear(mbfl_convert_filter *filter TSRMLS_DC); PHPAPI int _php_mb_conv_filt_reset(mbfl_convert_filter *filter, php_mb_enc *from, php_mb_enc *to TSRMLS_DC); PHPAPI int _php_mb_conv_filt_flush(mbfl_convert_filter *filter TSRMLS_DC); +PHPAPI int _php_mb_conv_filt_is_supported(php_mb_enc *from, php_mb_enc *to TSRMLS_DC); PHPAPI void php_mb_conv_filt_state_save(mbfl_convert_filter *filter); PHPAPI void php_mb_conv_filt_state_restore(mbfl_convert_filter *filter); @@ -31,6 +32,7 @@ #define php_mb_conv_filt_clear(filter) _php_mb_conv_filt_clear(filter TSRMLS_CC) #define php_mb_conv_filt_reset(filter, from, to) _php_mb_conv_filt_reset(filter, from, to TSRMLS_CC) #define php_mb_conv_filt_flush(filter) _php_mb_conv_filt_flush(filter TSRMLS_CC) +#define php_mb_conv_filt_is_supported(from, to) _php_mb_conv_filt_is_supported(from, to TSRMLS_CC) #define php_mb_conv_filt_feed_char(filter, c) _php_mb_conv_filt_feed_char(filter, c TSRMLS_CC) #define php_mb_conv_filt_feed_string(filter, src) _php_mb_conv_filt_feed_string(filter, src TSRMLS_CC) #define php_mb_conv_filt_feed_buffer(filter, src) _php_mb_conv_filt_feed_buffer(filter, src TSRMLS_CC)