repo
stringlengths
1
152
file
stringlengths
14
221
code
stringlengths
501
25k
file_length
int64
501
25k
avg_line_length
float64
20
99.5
max_line_length
int64
21
134
extension_type
stringclasses
2 values
php-src
php-src-master/ext/intl/msgformat/msgformat_attr.c
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Stanislav Malyshev <[email protected]> | +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php_intl.h" #include "msgformat_class.h" #include "msgformat_data.h" #include "intl_convert.h" #include <unicode/ustring.h> /* {{{ Get formatter pattern. */ PHP_FUNCTION( msgfmt_get_pattern ) { MSG_FORMAT_METHOD_INIT_VARS; /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "O", &object, MessageFormatter_ce_ptr ) == FAILURE ) { RETURN_THROWS(); } /* Fetch the object. */ MSG_FORMAT_METHOD_FETCH_OBJECT; if(mfo->mf_data.orig_format) { RETURN_STRINGL(mfo->mf_data.orig_format, mfo->mf_data.orig_format_len); } RETURN_FALSE; } /* }}} */ /* {{{ Set formatter pattern. */ PHP_FUNCTION( msgfmt_set_pattern ) { char* value = NULL; size_t value_len = 0; int32_t spattern_len = 0; UChar* spattern = NULL; UParseError spattern_error = {0}; MSG_FORMAT_METHOD_INIT_VARS; /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Os", &object, MessageFormatter_ce_ptr, &value, &value_len ) == FAILURE ) { RETURN_THROWS(); } MSG_FORMAT_METHOD_FETCH_OBJECT; /* Convert given pattern to UTF-16. */ intl_convert_utf8_to_utf16(&spattern, &spattern_len, value, value_len, &INTL_DATA_ERROR_CODE(mfo)); INTL_METHOD_CHECK_STATUS(mfo, "Error converting pattern to UTF-16" ); #ifdef MSG_FORMAT_QUOTE_APOS if(msgformat_fix_quotes(&spattern, &spattern_len, &INTL_DATA_ERROR_CODE(mfo)) != SUCCESS) { intl_error_set( NULL, U_INVALID_FORMAT_ERROR, "msgfmt_set_pattern: error converting pattern to quote-friendly format", 0 ); RETURN_FALSE; } #endif umsg_applyPattern(MSG_FORMAT_OBJECT(mfo), spattern, spattern_len, &spattern_error, &INTL_DATA_ERROR_CODE(mfo)); if (spattern) { efree(spattern); } if (U_FAILURE(INTL_DATA_ERROR_CODE(mfo))) { char *msg; spprintf(&msg, 0, "Error setting symbol value at line %d, offset %d", spattern_error.line, spattern_error.offset); intl_errors_set_custom_msg(INTL_DATA_ERROR_P(mfo), msg, 1); efree(msg); RETURN_FALSE; } if(mfo->mf_data.orig_format) { efree(mfo->mf_data.orig_format); } mfo->mf_data.orig_format = estrndup(value, value_len); mfo->mf_data.orig_format_len = value_len; /* invalidate cached format types */ if (mfo->mf_data.arg_types) { zend_hash_destroy(mfo->mf_data.arg_types); efree(mfo->mf_data.arg_types); mfo->mf_data.arg_types = NULL; } RETURN_TRUE; } /* }}} */ /* {{{ Get formatter locale. */ PHP_FUNCTION( msgfmt_get_locale ) { char *loc; MSG_FORMAT_METHOD_INIT_VARS; /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "O", &object, MessageFormatter_ce_ptr ) == FAILURE ) { RETURN_THROWS(); } /* Fetch the object. */ MSG_FORMAT_METHOD_FETCH_OBJECT; loc = (char *)umsg_getLocale(MSG_FORMAT_OBJECT(mfo)); RETURN_STRING(loc); } /* }}} */
3,691
28.070866
116
c
php-src
php-src-master/ext/intl/msgformat/msgformat_class.c
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Stanislav Malyshev <[email protected]> | +----------------------------------------------------------------------+ */ #include <unicode/unum.h> #include "msgformat_class.h" #include "php_intl.h" #include "msgformat_data.h" #include "msgformat_arginfo.h" #include <zend_exceptions.h> zend_class_entry *MessageFormatter_ce_ptr = NULL; static zend_object_handlers MessageFormatter_handlers; /* * Auxiliary functions needed by objects of 'MessageFormatter' class */ /* {{{ MessageFormatter_objects_free */ void MessageFormatter_object_free( zend_object *object ) { MessageFormatter_object* mfo = php_intl_messageformatter_fetch_object(object); zend_object_std_dtor( &mfo->zo ); msgformat_data_free( &mfo->mf_data ); } /* }}} */ /* {{{ MessageFormatter_object_create */ zend_object *MessageFormatter_object_create(zend_class_entry *ce) { MessageFormatter_object* intern; intern = zend_object_alloc(sizeof(MessageFormatter_object), ce); msgformat_data_init( &intern->mf_data ); zend_object_std_init( &intern->zo, ce ); object_properties_init(&intern->zo, ce); return &intern->zo; } /* }}} */ /* {{{ MessageFormatter_object_clone */ zend_object *MessageFormatter_object_clone(zend_object *object) { MessageFormatter_object *mfo, *new_mfo; zend_object *new_obj; mfo = php_intl_messageformatter_fetch_object(object); intl_error_reset(INTL_DATA_ERROR_P(mfo)); new_obj = MessageFormatter_ce_ptr->create_object(object->ce); new_mfo = php_intl_messageformatter_fetch_object(new_obj); /* clone standard parts */ zend_objects_clone_members(&new_mfo->zo, &mfo->zo); /* clone formatter object */ if (MSG_FORMAT_OBJECT(mfo) != NULL) { MSG_FORMAT_OBJECT(new_mfo) = umsg_clone(MSG_FORMAT_OBJECT(mfo), &INTL_DATA_ERROR_CODE(mfo)); if (U_FAILURE(INTL_DATA_ERROR_CODE(mfo))) { intl_errors_set(INTL_DATA_ERROR_P(mfo), INTL_DATA_ERROR_CODE(mfo), "Failed to clone MessageFormatter object", 0); zend_throw_exception_ex(NULL, 0, "Failed to clone MessageFormatter object"); } } else { zend_throw_exception_ex(NULL, 0, "Cannot clone unconstructed MessageFormatter"); } return new_obj; } /* }}} */ /* * 'MessageFormatter' class registration structures & functions */ /* {{{ msgformat_register_class * Initialize 'MessageFormatter' class */ void msgformat_register_class( void ) { /* Create and register 'MessageFormatter' class. */ MessageFormatter_ce_ptr = register_class_MessageFormatter(); MessageFormatter_ce_ptr->create_object = MessageFormatter_object_create; MessageFormatter_ce_ptr->default_object_handlers = &MessageFormatter_handlers; memcpy(&MessageFormatter_handlers, &std_object_handlers, sizeof MessageFormatter_handlers); MessageFormatter_handlers.offset = XtOffsetOf(MessageFormatter_object, zo); MessageFormatter_handlers.clone_obj = MessageFormatter_object_clone; MessageFormatter_handlers.free_obj = MessageFormatter_object_free; } /* }}} */
3,639
32.703704
82
c
php-src
php-src-master/ext/intl/msgformat/msgformat_class.h
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Stanislav Malyshev <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef MSG_FORMAT_CLASS_H #define MSG_FORMAT_CLASS_H #include <php.h> #include <unicode/uconfig.h> #include "../intl_common.h" #include "../intl_error.h" #include "../intl_data.h" #include "msgformat_data.h" typedef struct { msgformat_data mf_data; zend_object zo; } MessageFormatter_object; static inline MessageFormatter_object *php_intl_messageformatter_fetch_object(zend_object *obj) { return (MessageFormatter_object *)((char*)(obj) - XtOffsetOf(MessageFormatter_object, zo)); } #define Z_INTL_MESSAGEFORMATTER_P(zv) php_intl_messageformatter_fetch_object(Z_OBJ_P(zv)) void msgformat_register_class( void ); extern zend_class_entry *MessageFormatter_ce_ptr; /* Auxiliary macros */ #define MSG_FORMAT_METHOD_INIT_VARS INTL_METHOD_INIT_VARS(MessageFormatter, mfo) #define MSG_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK INTL_METHOD_FETCH_OBJECT(INTL_MESSAGEFORMATTER, mfo) #define MSG_FORMAT_METHOD_FETCH_OBJECT \ MSG_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK; \ if (MSG_FORMAT_OBJECT(mfo) == NULL) { \ zend_throw_error(NULL, "Found unconstructed MessageFormatter"); \ RETURN_THROWS(); \ } #define MSG_FORMAT_OBJECT(mfo) (mfo)->mf_data.umsgf #endif // #ifndef MSG_FORMAT_CLASS_H
2,075
36.071429
100
h
php-src
php-src-master/ext/intl/msgformat/msgformat_data.c
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Stanislav Malyshev <[email protected]> | +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <unicode/ustring.h> #include "msgformat_data.h" #include "msgformat_class.h" /* {{{ void msgformat_data_init( msgformat_data* mf_data ) * Initialize internals of msgformat_data. */ void msgformat_data_init( msgformat_data* mf_data ) { if( !mf_data ) return; mf_data->umsgf = NULL; mf_data->orig_format = NULL; mf_data->arg_types = NULL; mf_data->tz_set = 0; intl_error_reset( &mf_data->error ); } /* }}} */ /* {{{ void msgformat_data_free( msgformat_data* mf_data ) * Clean up memory allocated for msgformat_data */ void msgformat_data_free(msgformat_data* mf_data) { if (!mf_data) return; if (mf_data->umsgf) umsg_close(mf_data->umsgf); if (mf_data->orig_format) { efree(mf_data->orig_format); mf_data->orig_format = NULL; } if (mf_data->arg_types) { zend_hash_destroy(mf_data->arg_types); efree(mf_data->arg_types); mf_data->arg_types = NULL; } mf_data->umsgf = NULL; intl_error_reset(&mf_data->error); } /* }}} */ /* {{{ msgformat_data* msgformat_data_create() * Allocate memory for msgformat_data and initialize it with default values. */ msgformat_data* msgformat_data_create( void ) { msgformat_data* mf_data = ecalloc( 1, sizeof(msgformat_data) ); msgformat_data_init( mf_data ); return mf_data; } /* }}} */ #ifdef MSG_FORMAT_QUOTE_APOS int msgformat_fix_quotes(UChar **spattern, uint32_t *spattern_len, UErrorCode *ec) { if(*spattern && *spattern_len && u_strchr(*spattern, (UChar)'\'')) { UChar *npattern = safe_emalloc(sizeof(UChar)*2, *spattern_len, sizeof(UChar)); uint32_t npattern_len; npattern_len = umsg_autoQuoteApostrophe(*spattern, *spattern_len, npattern, 2*(*spattern_len)+1, ec); efree(*spattern); if( U_FAILURE(*ec) ) { return FAILURE; } npattern = erealloc(npattern, sizeof(UChar)*(npattern_len+1)); *spattern = npattern; *spattern_len = npattern_len; } return SUCCESS; } #endif
2,787
27.161616
103
c
php-src
php-src-master/ext/intl/msgformat/msgformat_data.h
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Stanislav Malyshev <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef MSG_FORMAT_DATA_H #define MSG_FORMAT_DATA_H #include <php.h> #include "../intl_error.h" #include <unicode/umsg.h> typedef struct { // error hangling intl_error error; // formatter handling UMessageFormat* umsgf; char* orig_format; zend_ulong orig_format_len; HashTable* arg_types; int tz_set; /* if we've already the time zone in sub-formats */ } msgformat_data; msgformat_data* msgformat_data_create( void ); void msgformat_data_init( msgformat_data* mf_data ); void msgformat_data_free( msgformat_data* mf_data ); #ifdef MSG_FORMAT_QUOTE_APOS int msgformat_fix_quotes(UChar **spattern, uint32_t *spattern_len, UErrorCode *ec); #endif #endif // MSG_FORMAT_DATA_H
1,544
33.333333
83
h
php-src
php-src-master/ext/intl/msgformat/msgformat_format.c
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Stanislav Malyshev <[email protected]> | +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <unicode/ustring.h> #include "php_intl.h" #include "msgformat_class.h" #include "msgformat_data.h" #include "msgformat_helpers.h" #include "intl_convert.h" #ifndef Z_ADDREF_P #define Z_ADDREF_P(z) ((z)->refcount++) #endif /* {{{ */ static void msgfmt_do_format(MessageFormatter_object *mfo, zval *args, zval *return_value) { UChar* formatted = NULL; int32_t formatted_len = 0; umsg_format_helper(mfo, Z_ARRVAL_P(args), &formatted, &formatted_len); if (U_FAILURE(INTL_DATA_ERROR_CODE(mfo))) { if (formatted) { efree(formatted); } RETURN_FALSE; } else { INTL_METHOD_RETVAL_UTF8(mfo, formatted, formatted_len, 1); } } /* }}} */ /* {{{ Format a message. */ PHP_FUNCTION( msgfmt_format ) { zval *args; MSG_FORMAT_METHOD_INIT_VARS; /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Oa", &object, MessageFormatter_ce_ptr, &args ) == FAILURE ) { RETURN_THROWS(); } /* Fetch the object. */ MSG_FORMAT_METHOD_FETCH_OBJECT; msgfmt_do_format(mfo, args, return_value); } /* }}} */ /* {{{ Format a message. */ PHP_FUNCTION( msgfmt_format_message ) { zval *args; UChar *spattern = NULL; int spattern_len = 0; char *pattern = NULL; size_t pattern_len = 0; const char *slocale = NULL; size_t slocale_len = 0; MessageFormatter_object mf; MessageFormatter_object *mfo = &mf; UParseError parse_error; /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "ssa", &slocale, &slocale_len, &pattern, &pattern_len, &args ) == FAILURE ) { RETURN_THROWS(); } INTL_CHECK_LOCALE_LEN(slocale_len); memset(mfo, 0, sizeof(*mfo)); msgformat_data_init(&mfo->mf_data); if(pattern && pattern_len) { intl_convert_utf8_to_utf16(&spattern, &spattern_len, pattern, pattern_len, &INTL_DATA_ERROR_CODE(mfo)); if( U_FAILURE(INTL_DATA_ERROR_CODE((mfo))) ) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "msgfmt_format_message: error converting pattern to UTF-16", 0 ); RETURN_FALSE; } } else { spattern_len = 0; spattern = NULL; } if(slocale_len == 0) { slocale = intl_locale_get_default(); } #ifdef MSG_FORMAT_QUOTE_APOS if(msgformat_fix_quotes(&spattern, &spattern_len, &INTL_DATA_ERROR_CODE(mfo)) != SUCCESS) { intl_error_set( NULL, U_INVALID_FORMAT_ERROR, "msgfmt_format_message: error converting pattern to quote-friendly format", 0 ); RETURN_FALSE; } #endif /* Create an ICU message formatter. */ MSG_FORMAT_OBJECT(mfo) = umsg_open(spattern, spattern_len, slocale, &parse_error, &INTL_DATA_ERROR_CODE(mfo)); if(spattern && spattern_len) { efree(spattern); } /* Cannot use INTL_METHOD_CHECK_STATUS() as we need to free the message object formatter */ if (U_FAILURE(INTL_DATA_ERROR_CODE(mfo))) { if (INTL_DATA_ERROR_CODE( mfo ) == U_PATTERN_SYNTAX_ERROR) { char *msg = NULL; smart_str parse_error_str; parse_error_str = intl_parse_error_to_string( &parse_error ); spprintf( &msg, 0, "pattern syntax error (%s)", parse_error_str.s? ZSTR_VAL(parse_error_str.s) : "unknown parser error" ); smart_str_free( &parse_error_str ); intl_error_set_code( NULL, INTL_DATA_ERROR_CODE( mfo ) ); intl_errors_set_custom_msg( INTL_DATA_ERROR_P( mfo ), msg, 1 ); efree( msg ); } else { intl_errors_set_custom_msg( INTL_DATA_ERROR_P(mfo), "Creating message formatter failed", 0 ); } /* Reset custom error message as this is a static method that has no object */ intl_errors_reset(INTL_DATA_ERROR_P(mfo)); umsg_close(MSG_FORMAT_OBJECT(mfo)); RETURN_FALSE; } msgfmt_do_format(mfo, args, return_value); /* drop the temporary formatter */ msgformat_data_free(&mfo->mf_data); } /* }}} */
4,605
28.525641
125
c
php-src
php-src-master/ext/intl/msgformat/msgformat_helpers.h
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Stanislav Malyshev <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef MSG_FORMAT_HELPERS_H #define MSG_FORMAT_HELPERS_H int32_t umsg_format_arg_count(UMessageFormat *fmt); void umsg_format_helper(MessageFormatter_object *mfo, HashTable *args, UChar **formatted, int *formatted_len); void umsg_parse_helper(UMessageFormat *fmt, int *count, zval **args, UChar *source, int source_len, UErrorCode *status); #endif // MSG_FORMAT_HELPERS_H
1,232
50.375
75
h
php-src
php-src-master/ext/intl/msgformat/msgformat_parse.c
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Stanislav Malyshev <[email protected]> | +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <unicode/ustring.h> #include "php_intl.h" #include "msgformat_class.h" #include "msgformat_data.h" #include "msgformat_helpers.h" #include "intl_convert.h" /* {{{ */ static void msgfmt_do_parse(MessageFormatter_object *mfo, char *source, size_t src_len, zval *return_value) { zval *fargs; int count = 0; int i; UChar *usource = NULL; int usrc_len = 0; intl_convert_utf8_to_utf16(&usource, &usrc_len, source, src_len, &INTL_DATA_ERROR_CODE(mfo)); INTL_METHOD_CHECK_STATUS(mfo, "Converting parse string failed"); umsg_parse_helper(MSG_FORMAT_OBJECT(mfo), &count, &fargs, usource, usrc_len, &INTL_DATA_ERROR_CODE(mfo)); if (usource) { efree(usource); } INTL_METHOD_CHECK_STATUS(mfo, "Parsing failed"); array_init(return_value); for(i=0;i<count;i++) { add_next_index_zval(return_value, &fargs[i]); } efree(fargs); } /* }}} */ /* {{{ Parse a message */ PHP_FUNCTION( msgfmt_parse ) { char *source; size_t source_len; MSG_FORMAT_METHOD_INIT_VARS; /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Os", &object, MessageFormatter_ce_ptr, &source, &source_len ) == FAILURE ) { RETURN_THROWS(); } /* Fetch the object. */ MSG_FORMAT_METHOD_FETCH_OBJECT; msgfmt_do_parse(mfo, source, source_len, return_value); } /* }}} */ /* {{{ Parse a message. */ PHP_FUNCTION( msgfmt_parse_message ) { UChar *spattern = NULL; int spattern_len = 0; char *pattern = NULL; size_t pattern_len = 0; const char *slocale = NULL; size_t slocale_len = 0; char *source = NULL; size_t src_len = 0; MessageFormatter_object mf; MessageFormatter_object *mfo = &mf; /* Parse parameters. */ if( zend_parse_parameters( ZEND_NUM_ARGS(), "sss", &slocale, &slocale_len, &pattern, &pattern_len, &source, &src_len ) == FAILURE ) { RETURN_THROWS(); } INTL_CHECK_LOCALE_LEN(slocale_len); memset(mfo, 0, sizeof(*mfo)); msgformat_data_init(&mfo->mf_data); if(pattern && pattern_len) { intl_convert_utf8_to_utf16(&spattern, &spattern_len, pattern, pattern_len, &INTL_DATA_ERROR_CODE(mfo)); if( U_FAILURE(INTL_DATA_ERROR_CODE((mfo))) ) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "msgfmt_parse_message: error converting pattern to UTF-16", 0 ); RETURN_FALSE; } } else { spattern_len = 0; spattern = NULL; } if(slocale_len == 0) { slocale = intl_locale_get_default(); } #ifdef MSG_FORMAT_QUOTE_APOS if(msgformat_fix_quotes(&spattern, &spattern_len, &INTL_DATA_ERROR_CODE(mfo)) != SUCCESS) { intl_error_set( NULL, U_INVALID_FORMAT_ERROR, "msgfmt_parse_message: error converting pattern to quote-friendly format", 0 ); RETURN_FALSE; } #endif /* Create an ICU message formatter. */ MSG_FORMAT_OBJECT(mfo) = umsg_open(spattern, spattern_len, slocale, NULL, &INTL_DATA_ERROR_CODE(mfo)); if(spattern && spattern_len) { efree(spattern); } INTL_METHOD_CHECK_STATUS(mfo, "Creating message formatter failed"); msgfmt_do_parse(mfo, source, src_len, return_value); /* drop the temporary formatter */ msgformat_data_free(&mfo->mf_data); } /* }}} */
3,991
27.927536
107
c
php-src
php-src-master/ext/intl/normalizer/normalizer.h
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Ed Batutis <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef NORMALIZER_NORMALIZER_H #define NORMALIZER_NORMALIZER_H #include <php.h> #include <unicode/utypes.h> #if U_ICU_VERSION_MAJOR_NUM < 56 #include <unicode/unorm.h> #define NORMALIZER_FORM_D UNORM_NFD #define NORMALIZER_NFD UNORM_NFD #define NORMALIZER_FORM_KD UNORM_NFKD #define NORMALIZER_NFKD UNORM_NFKD #define NORMALIZER_FORM_C UNORM_NFC #define NORMALIZER_NFC UNORM_NFC #define NORMALIZER_FORM_KC UNORM_NFKC #define NORMALIZER_NFKC UNORM_NFKC #define NORMALIZER_DEFAULT UNORM_DEFAULT #else #include <unicode/unorm2.h> #define NORMALIZER_FORM_D 0x4 #define NORMALIZER_NFD NORMALIZER_FORM_D #define NORMALIZER_FORM_KD 0x8 #define NORMALIZER_NFKD NORMALIZER_FORM_KD #define NORMALIZER_FORM_C 0x10 #define NORMALIZER_NFC NORMALIZER_FORM_C #define NORMALIZER_FORM_KC 0x20 #define NORMALIZER_NFKC NORMALIZER_FORM_KC #define NORMALIZER_FORM_KC_CF 0x30 #define NORMALIZER_NFKC_CF NORMALIZER_FORM_KC_CF #define NORMALIZER_DEFAULT NORMALIZER_FORM_C #endif #endif // NORMALIZER_NORMALIZER_H
1,838
36.530612
75
h
php-src
php-src-master/ext/intl/normalizer/normalizer_class.c
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Ed Batutis <[email protected]> | +----------------------------------------------------------------------+ */ #include "normalizer.h" #include "normalizer_class.h" #include "php_intl.h" #include "normalizer_arginfo.h" #include "intl_error.h" #include <unicode/unorm.h> zend_class_entry *Normalizer_ce_ptr = NULL; /* * 'Normalizer' class registration structures & functions */ /* {{{ normalizer_register_Normalizer_class * Initialize 'Normalizer' class */ void normalizer_register_Normalizer_class( void ) { /* Create and register 'Normalizer' class. */ Normalizer_ce_ptr = register_class_Normalizer(); Normalizer_ce_ptr->create_object = NULL; } /* }}} */
1,400
34.923077
75
c
php-src
php-src-master/ext/intl/normalizer/normalizer_class.h
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Ed Batutis <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef NORMALIZER_CLASS_H #define NORMALIZER_CLASS_H #include <php.h> #include "intl_common.h" #include "intl_error.h" #include <unicode/unorm.h> typedef struct { zend_object zo; // error value not used currently intl_error err; } Normalizer_object; #define NORMALIZER_ERROR(co) (co)->err #define NORMALIZER_ERROR_P(co) &(NORMALIZER_ERROR(co)) #define NORMALIZER_ERROR_CODE(co) INTL_ERROR_CODE(NORMALIZER_ERROR(co)) #define NORMALIZER_ERROR_CODE_P(co) &(INTL_ERROR_CODE(NORMALIZER_ERROR(co))) void normalizer_register_Normalizer_class( void ); extern zend_class_entry *Normalizer_ce_ptr; #endif // #ifndef NORMALIZER_CLASS_H
1,489
34.47619
76
h
php-src
php-src-master/ext/intl/normalizer/normalizer_normalize.c
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Ed Batutis <[email protected]> | +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php_intl.h" #if U_ICU_VERSION_MAJOR_NUM < 56 #include "unicode/unorm.h" #else #include <unicode/unorm2.h> #endif #include "normalizer.h" #include "normalizer_class.h" #include "intl_convert.h" #include <unicode/utf8.h> #if U_ICU_VERSION_MAJOR_NUM >= 56 static const UNormalizer2 *intl_get_normalizer(zend_long form, UErrorCode *err) {/*{{{*/ switch (form) { case NORMALIZER_FORM_C: return unorm2_getNFCInstance(err); break; case NORMALIZER_FORM_D: return unorm2_getNFDInstance(err); break; case NORMALIZER_FORM_KC: return unorm2_getNFKCInstance(err); break; case NORMALIZER_FORM_KD: return unorm2_getNFKDInstance(err); break; case NORMALIZER_FORM_KC_CF: return unorm2_getNFKCCasefoldInstance(err); break; } *err = U_ILLEGAL_ARGUMENT_ERROR; return NULL; }/*}}}*/ static int32_t intl_normalize(zend_long form, const UChar *src, int32_t src_len, UChar *dst, int32_t dst_len, UErrorCode *err) {/*{{{*/ const UNormalizer2 *norm = intl_get_normalizer(form, err); if (U_FAILURE(*err)) { return -1; } return unorm2_normalize(norm, src, src_len, dst, dst_len, err); }/*}}}*/ static UBool intl_is_normalized(zend_long form, const UChar *uinput, int32_t uinput_len, UErrorCode *err) {/*{{{*/ const UNormalizer2 *norm = intl_get_normalizer(form, err); if(U_FAILURE(*err)) { return false; } return unorm2_isNormalized(norm, uinput, uinput_len, err); }/*}}}*/ #endif /* {{{ Normalize a string. */ PHP_FUNCTION( normalizer_normalize ) { char* input = NULL; /* form is optional, defaults to FORM_C */ zend_long form = NORMALIZER_DEFAULT; size_t input_len = 0; UChar* uinput = NULL; int32_t uinput_len = 0; int expansion_factor = 1; UErrorCode status = U_ZERO_ERROR; UChar* uret_buf = NULL; int32_t uret_len = 0; zend_string* u8str; int32_t size_needed; intl_error_reset( NULL ); /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "s|l", &input, &input_len, &form ) == FAILURE ) { RETURN_THROWS(); } expansion_factor = 1; switch(form) { case NORMALIZER_FORM_D: expansion_factor = 3; break; case NORMALIZER_FORM_KD: expansion_factor = 3; break; case NORMALIZER_FORM_C: case NORMALIZER_FORM_KC: #if U_ICU_VERSION_MAJOR_NUM >= 56 case NORMALIZER_FORM_KC_CF: #endif break; default: zend_argument_value_error(2, "must be a a valid normalization form"); RETURN_THROWS(); } /* * Normalize string (converting it to UTF-16 first). */ /* First convert the string to UTF-16. */ intl_convert_utf8_to_utf16(&uinput, &uinput_len, input, input_len, &status ); if( U_FAILURE( status ) ) { /* Set global error code. */ intl_error_set_code( NULL, status ); /* Set error messages. */ intl_error_set_custom_msg( NULL, "Error converting input string to UTF-16", 0 ); if (uinput) { efree( uinput ); } RETURN_FALSE; } /* Allocate memory for the destination buffer for normalization */ uret_len = uinput_len * expansion_factor; uret_buf = eumalloc( uret_len + 1 ); /* normalize */ #if U_ICU_VERSION_MAJOR_NUM < 56 size_needed = unorm_normalize( uinput, uinput_len, form, (int32_t) 0 /* options */, uret_buf, uret_len, &status); #else size_needed = intl_normalize(form, uinput, uinput_len, uret_buf, uret_len, &status); #endif /* Bail out if an unexpected error occurred. * (U_BUFFER_OVERFLOW_ERROR means that *target buffer is not large enough). * (U_STRING_NOT_TERMINATED_WARNING usually means that the input string is empty). */ if( U_FAILURE(status) && status != U_BUFFER_OVERFLOW_ERROR && status != U_STRING_NOT_TERMINATED_WARNING ) { intl_error_set_custom_msg( NULL, "Error normalizing string", 0 ); efree( uret_buf ); efree( uinput ); RETURN_FALSE; } if ( size_needed > uret_len ) { /* realloc does not seem to work properly - memory is corrupted * uret_buf = eurealloc(uret_buf, size_needed + 1); */ efree( uret_buf ); uret_buf = eumalloc( size_needed + 1 ); uret_len = size_needed; status = U_ZERO_ERROR; /* try normalize again */ #if U_ICU_VERSION_MAJOR_NUM < 56 size_needed = unorm_normalize( uinput, uinput_len, form, (int32_t) 0 /* options */, uret_buf, uret_len, &status); #else size_needed = intl_normalize(form, uinput, uinput_len, uret_buf, uret_len, &status); #endif /* Bail out if an unexpected error occurred. */ if( U_FAILURE(status) ) { /* Set error messages. */ intl_error_set_custom_msg( NULL,"Error normalizing string", 0 ); efree( uret_buf ); efree( uinput ); RETURN_FALSE; } } efree( uinput ); /* the buffer we actually used */ uret_len = size_needed; /* Convert normalized string from UTF-16 to UTF-8. */ u8str = intl_convert_utf16_to_utf8(uret_buf, uret_len, &status ); efree( uret_buf ); if( !u8str ) { intl_error_set( NULL, status, "normalizer_normalize: error converting normalized text UTF-8", 0 ); RETURN_FALSE; } /* Return it. */ RETVAL_NEW_STR( u8str ); } /* }}} */ /* {{{ Test if a string is in a given normalization form. */ PHP_FUNCTION( normalizer_is_normalized ) { char* input = NULL; /* form is optional, defaults to FORM_C */ zend_long form = NORMALIZER_DEFAULT; size_t input_len = 0; UChar* uinput = NULL; int uinput_len = 0; UErrorCode status = U_ZERO_ERROR; UBool uret = false; intl_error_reset( NULL ); /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "s|l", &input, &input_len, &form) == FAILURE ) { RETURN_THROWS(); } switch(form) { case NORMALIZER_FORM_D: case NORMALIZER_FORM_KD: case NORMALIZER_FORM_C: case NORMALIZER_FORM_KC: #if U_ICU_VERSION_MAJOR_NUM >= 56 case NORMALIZER_FORM_KC_CF: #endif break; default: zend_argument_value_error(2, "must be a a valid normalization form"); RETURN_THROWS(); } /* * Test normalization of string (converting it to UTF-16 first). */ /* First convert the string to UTF-16. */ intl_convert_utf8_to_utf16(&uinput, &uinput_len, input, input_len, &status ); if( U_FAILURE( status ) ) { /* Set global error code. */ intl_error_set_code( NULL, status ); /* Set error messages. */ intl_error_set_custom_msg( NULL, "Error converting string to UTF-16.", 0 ); if (uinput) { efree( uinput ); } RETURN_FALSE; } /* test string */ #if U_ICU_VERSION_MAJOR_NUM < 56 uret = unorm_isNormalizedWithOptions( uinput, uinput_len, form, (int32_t) 0 /* options */, &status); #else uret = intl_is_normalized(form, uinput, uinput_len, &status); #endif efree( uinput ); /* Bail out if an unexpected error occurred. */ if( U_FAILURE(status) ) { /* Set error messages. */ intl_error_set_custom_msg( NULL,"Error testing if string is the given normalization form.", 0 ); RETURN_FALSE; } if ( uret ) RETURN_TRUE; RETURN_FALSE; } /* }}} */ /* {{{ Returns the Decomposition_Mapping property for the given UTF-8 encoded code point. */ #if U_ICU_VERSION_MAJOR_NUM >= 56 PHP_FUNCTION( normalizer_get_raw_decomposition ) { char* input = NULL; size_t input_length = 0; UChar32 codepoint = -1; int32_t offset = 0; UErrorCode status = U_ZERO_ERROR; const UNormalizer2 *norm; UChar decomposition[32]; int32_t decomposition_length; zend_long form = NORMALIZER_DEFAULT; intl_error_reset(NULL); if ((zend_parse_parameters(ZEND_NUM_ARGS(), "s|l", &input, &input_length, &form) == FAILURE)) { RETURN_THROWS(); } norm = intl_get_normalizer(form, &status); U8_NEXT(input, offset, input_length, codepoint); if ((size_t)offset != input_length) { intl_error_set_code(NULL, U_ILLEGAL_ARGUMENT_ERROR); intl_error_set_custom_msg(NULL, "Input string must be exactly one UTF-8 encoded code point long.", 0); return; } if ((codepoint < UCHAR_MIN_VALUE) || (codepoint > UCHAR_MAX_VALUE)) { intl_error_set_code(NULL, U_ILLEGAL_ARGUMENT_ERROR); intl_error_set_custom_msg(NULL, "Code point out of range", 0); return; } decomposition_length = unorm2_getRawDecomposition(norm, codepoint, decomposition, 32, &status); if (decomposition_length == -1) { RETURN_NULL(); } RETVAL_NEW_STR(intl_convert_utf16_to_utf8(decomposition, decomposition_length, &status)); } #endif /* }}} */
9,042
25.060519
126
c
php-src
php-src-master/ext/intl/resourcebundle/resourcebundle.c
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Hans-Peter Oeri (University of St.Gallen) <[email protected]> | +----------------------------------------------------------------------+ */ #include <unicode/ures.h> #include <zend.h> #include <zend_API.h> #include "intl_convert.h" #include "intl_data.h" #include "resourcebundle/resourcebundle_class.h" /* {{{ ResourceBundle_extract_value */ void resourcebundle_extract_value( zval *return_value, ResourceBundle_object *source ) { UResType restype; const UChar* ufield; const uint8_t* bfield; const int32_t* vfield; int32_t ilen; int i; zend_long lfield; ResourceBundle_object* newrb; restype = ures_getType( source->child ); switch (restype) { case URES_STRING: ufield = ures_getString( source->child, &ilen, &INTL_DATA_ERROR_CODE(source) ); INTL_METHOD_CHECK_STATUS(source, "Failed to retrieve string value"); INTL_METHOD_RETVAL_UTF8(source, (UChar *)ufield, ilen, 0); break; case URES_BINARY: bfield = ures_getBinary( source->child, &ilen, &INTL_DATA_ERROR_CODE(source) ); INTL_METHOD_CHECK_STATUS(source, "Failed to retrieve binary value"); ZVAL_STRINGL( return_value, (char *) bfield, ilen ); break; case URES_INT: lfield = ures_getInt( source->child, &INTL_DATA_ERROR_CODE(source) ); INTL_METHOD_CHECK_STATUS(source, "Failed to retrieve integer value"); ZVAL_LONG( return_value, lfield ); break; case URES_INT_VECTOR: vfield = ures_getIntVector( source->child, &ilen, &INTL_DATA_ERROR_CODE(source) ); INTL_METHOD_CHECK_STATUS(source, "Failed to retrieve vector value"); array_init( return_value ); for (i=0; i<ilen; i++) { add_next_index_long( return_value, vfield[i] ); } break; case URES_ARRAY: case URES_TABLE: object_init_ex( return_value, ResourceBundle_ce_ptr ); newrb = Z_INTL_RESOURCEBUNDLE_P(return_value); newrb->me = source->child; source->child = NULL; intl_errors_reset(INTL_DATA_ERROR_P(source)); break; default: intl_errors_set(INTL_DATA_ERROR_P(source), U_ILLEGAL_ARGUMENT_ERROR, "Unknown resource type", 0); RETURN_FALSE; break; } } /* }}} */
2,878
34.109756
100
c
php-src
php-src-master/ext/intl/resourcebundle/resourcebundle.h
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Hans-Peter Oeri (University of St.Gallen) <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef RESOURCEBUNDLE_H #define RESOURCEBUNDLE_H #include <unicode/ures.h> #include <zend.h> #include "resourcebundle/resourcebundle_class.h" void resourcebundle_extract_value( zval *target, ResourceBundle_object *source); #endif // #ifndef RESOURCEBUNDLE_CLASS_H
1,114
40.296296
80
h
php-src
php-src-master/ext/intl/resourcebundle/resourcebundle_class.h
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Hans-Peter Oeri (University of St.Gallen) <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef RESOURCEBUNDLE_CLASS_H #define RESOURCEBUNDLE_CLASS_H #include <unicode/ures.h> #include <zend.h> #include "php.h" #include "intl_error.h" typedef struct { intl_error error; UResourceBundle *me; UResourceBundle *child; zend_object zend; } ResourceBundle_object; static inline ResourceBundle_object *php_intl_resourcebundle_fetch_object(zend_object *obj) { return (ResourceBundle_object *)((char*)(obj) - XtOffsetOf(ResourceBundle_object, zend)); } #define Z_INTL_RESOURCEBUNDLE_P(zv) php_intl_resourcebundle_fetch_object(Z_OBJ_P(zv)) #define RESOURCEBUNDLE_METHOD_INIT_VARS INTL_METHOD_INIT_VARS(ResourceBundle, rb) #define RESOURCEBUNDLE_METHOD_FETCH_OBJECT_NO_CHECK INTL_METHOD_FETCH_OBJECT(INTL_RESOURCEBUNDLE, rb) #define RESOURCEBUNDLE_METHOD_FETCH_OBJECT \ INTL_METHOD_FETCH_OBJECT(INTL_RESOURCEBUNDLE, rb); \ if (RESOURCEBUNDLE_OBJECT(rb) == NULL) { \ zend_throw_error(NULL, "Found unconstructed ResourceBundle"); \ RETURN_THROWS(); \ } #define RESOURCEBUNDLE_OBJECT(rb) (rb)->me void resourcebundle_register_class( void ); extern zend_class_entry *ResourceBundle_ce_ptr; #endif // #ifndef RESOURCEBUNDLE_CLASS_H
2,030
37.320755
101
h
php-src
php-src-master/ext/intl/resourcebundle/resourcebundle_iterator.c
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Hans-Peter Oeri (University of St.Gallen) <[email protected]> | +----------------------------------------------------------------------+ */ #include <php.h> #include <zend.h> #include <zend_API.h> #include "resourcebundle/resourcebundle.h" #include "resourcebundle/resourcebundle_class.h" #include "resourcebundle/resourcebundle_iterator.h" /* * Although libicu offers iterator functions, they are not used here: libicu does iterate * irrespective of array indices. Those cannot be recreated afterwards. Arrays as well as tables * can however be accessed by numerical index, with table keys readable ex post. */ /* {{{ resourcebundle_iterator_read */ static void resourcebundle_iterator_read( ResourceBundle_iterator *iterator ) { UErrorCode icuerror = U_ZERO_ERROR; ResourceBundle_object *rb = iterator->subject; rb->child = ures_getByIndex( rb->me, iterator->i, rb->child, &icuerror ); if (U_SUCCESS(icuerror)) { /* ATTN: key extraction must be the first thing to do... rb->child might be reset in read! */ if (iterator->is_table) { iterator->currentkey = estrdup( ures_getKey( rb->child ) ); } resourcebundle_extract_value( &iterator->current, rb ); } else { // zend_throw_exception( spl_ce_OutOfRangeException, "Running past end of ResourceBundle", 0); ZVAL_UNDEF(&iterator->current); } } /* }}} */ /* {{{ resourcebundle_iterator_invalidate */ static void resourcebundle_iterator_invalidate( zend_object_iterator *iter ) { ResourceBundle_iterator *iterator = (ResourceBundle_iterator *) iter; if (!Z_ISUNDEF(iterator->current)) { zval_ptr_dtor( &iterator->current ); ZVAL_UNDEF(&iterator->current); } if (iterator->currentkey) { efree( iterator->currentkey ); iterator->currentkey = NULL; } } /* }}} */ /* {{{ resourcebundle_iterator_dtor */ static void resourcebundle_iterator_dtor( zend_object_iterator *iter ) { ResourceBundle_iterator *iterator = (ResourceBundle_iterator *) iter; zval *object = &iterator->intern.data; resourcebundle_iterator_invalidate( iter ); zval_ptr_dtor(object); } /* }}} */ /* {{{ resourcebundle_iterator_has_more */ static int resourcebundle_iterator_has_more( zend_object_iterator *iter ) { ResourceBundle_iterator *iterator = (ResourceBundle_iterator *) iter; return (iterator->i < iterator->length) ? SUCCESS : FAILURE; } /* }}} */ /* {{{ resourcebundle_iterator_current */ static zval *resourcebundle_iterator_current( zend_object_iterator *iter ) { ResourceBundle_iterator *iterator = (ResourceBundle_iterator *) iter; if (Z_ISUNDEF(iterator->current)) { resourcebundle_iterator_read( iterator); } return &iterator->current; } /* }}} */ /* {{{ resourcebundle_iterator_key */ static void resourcebundle_iterator_key( zend_object_iterator *iter, zval *key ) { ResourceBundle_iterator *iterator = (ResourceBundle_iterator *) iter; if (Z_ISUNDEF(iterator->current)) { resourcebundle_iterator_read( iterator); } if (iterator->is_table) { ZVAL_STRING(key, iterator->currentkey); } else { ZVAL_LONG(key, iterator->i); } } /* }}} */ /* {{{ resourcebundle_iterator_step */ static void resourcebundle_iterator_step( zend_object_iterator *iter ) { ResourceBundle_iterator *iterator = (ResourceBundle_iterator *) iter; iterator->i++; resourcebundle_iterator_invalidate( iter ); } /* }}} */ /* {{{ resourcebundle_iterator_has_reset */ static void resourcebundle_iterator_reset( zend_object_iterator *iter ) { ResourceBundle_iterator *iterator = (ResourceBundle_iterator *) iter; iterator->i = 0; resourcebundle_iterator_invalidate( iter ); } /* }}} */ /* {{{ resourcebundle_iterator_funcs */ static const zend_object_iterator_funcs resourcebundle_iterator_funcs = { resourcebundle_iterator_dtor, resourcebundle_iterator_has_more, resourcebundle_iterator_current, resourcebundle_iterator_key, resourcebundle_iterator_step, resourcebundle_iterator_reset, resourcebundle_iterator_invalidate, NULL, /* get_gc */ }; /* }}} */ /* {{{ resourcebundle_get_iterator */ zend_object_iterator *resourcebundle_get_iterator( zend_class_entry *ce, zval *object, int byref ) { ResourceBundle_object *rb = Z_INTL_RESOURCEBUNDLE_P(object ); ResourceBundle_iterator *iterator = emalloc( sizeof( ResourceBundle_iterator ) ); if (byref) { php_error( E_ERROR, "ResourceBundle does not support writable iterators" ); } zend_iterator_init(&iterator->intern); Z_ADDREF_P(object); ZVAL_OBJ(&iterator->intern.data, Z_OBJ_P(object)); iterator->intern.funcs = &resourcebundle_iterator_funcs; iterator->subject = rb; /* The iterated rb can only be either URES_TABLE or URES_ARRAY * All other types are returned as php primitives! */ iterator->is_table = (ures_getType( rb->me ) == URES_TABLE); iterator->length = ures_getSize( rb->me ); ZVAL_UNDEF(&iterator->current); iterator->currentkey = NULL; iterator->i = 0; return (zend_object_iterator *) iterator; } /* }}} */
5,619
30.573034
98
c
php-src
php-src-master/ext/intl/resourcebundle/resourcebundle_iterator.h
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Hans-Peter Oeri (University of St.Gallen) <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef RESOURCEBUNDLE_ITERATOR_H #define RESOURCEBUNDLE_ITERATOR_H #include <zend.h> #include "resourcebundle/resourcebundle_class.h" typedef struct { zend_object_iterator intern; ResourceBundle_object *subject; bool is_table; zend_long length; zval current; char *currentkey; zend_long i; } ResourceBundle_iterator; zend_object_iterator *resourcebundle_get_iterator( zend_class_entry *ce, zval *object, int byref ); #endif // #ifndef RESOURCEBUNDLE_ITERATOR_H
1,389
38.714286
99
h
php-src
php-src-master/ext/intl/spoofchecker/spoofchecker_class.c
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Scott MacVicar <[email protected]> | +----------------------------------------------------------------------+ */ #include "spoofchecker_class.h" #include "spoofchecker_arginfo.h" #include "php_intl.h" #include "intl_error.h" #include <unicode/uspoof.h> zend_class_entry *Spoofchecker_ce_ptr = NULL; static zend_object_handlers Spoofchecker_handlers; /* * Auxiliary functions needed by objects of 'Spoofchecker' class */ /* {{{ Spoofchecker_objects_free */ void Spoofchecker_objects_free(zend_object *object) { Spoofchecker_object* co = php_intl_spoofchecker_fetch_object(object); zend_object_std_dtor(&co->zo); spoofchecker_object_destroy(co); } /* }}} */ /* {{{ Spoofchecker_object_create */ zend_object *Spoofchecker_object_create(zend_class_entry *ce) { Spoofchecker_object* intern; intern = zend_object_alloc(sizeof(Spoofchecker_object), ce); intl_error_init(SPOOFCHECKER_ERROR_P(intern)); zend_object_std_init(&intern->zo, ce); object_properties_init(&intern->zo, ce); return &intern->zo; } /* }}} */ /* * 'Spoofchecker' class registration structures & functions */ /* {{{ Spoofchecker_class_functions * Every 'Spoofchecker' class method has an entry in this table */ static zend_object *spoofchecker_clone_obj(zend_object *object) /* {{{ */ { zend_object *new_obj_val; Spoofchecker_object *sfo, *new_sfo; sfo = php_intl_spoofchecker_fetch_object(object); intl_error_reset(SPOOFCHECKER_ERROR_P(sfo)); new_obj_val = Spoofchecker_ce_ptr->create_object(object->ce); new_sfo = php_intl_spoofchecker_fetch_object(new_obj_val); /* clone standard parts */ zend_objects_clone_members(&new_sfo->zo, &sfo->zo); /* clone internal object */ new_sfo->uspoof = uspoof_clone(sfo->uspoof, SPOOFCHECKER_ERROR_CODE_P(new_sfo)); if(U_FAILURE(SPOOFCHECKER_ERROR_CODE(new_sfo))) { /* set up error in case error handler is interested */ intl_error_set( NULL, SPOOFCHECKER_ERROR_CODE(new_sfo), "Failed to clone SpoofChecker object", 0 ); Spoofchecker_objects_free(&new_sfo->zo); /* free new object */ zend_error(E_ERROR, "Failed to clone SpoofChecker object"); } return new_obj_val; } /* }}} */ /* {{{ spoofchecker_register_Spoofchecker_class * Initialize 'Spoofchecker' class */ void spoofchecker_register_Spoofchecker_class(void) { /* Create and register 'Spoofchecker' class. */ Spoofchecker_ce_ptr = register_class_Spoofchecker(); Spoofchecker_ce_ptr->create_object = Spoofchecker_object_create; Spoofchecker_ce_ptr->default_object_handlers = &Spoofchecker_handlers; memcpy(&Spoofchecker_handlers, &std_object_handlers, sizeof Spoofchecker_handlers); Spoofchecker_handlers.offset = XtOffsetOf(Spoofchecker_object, zo); Spoofchecker_handlers.clone_obj = spoofchecker_clone_obj; Spoofchecker_handlers.free_obj = Spoofchecker_objects_free; } /* }}} */ /* {{{ void spoofchecker_object_init( Spoofchecker_object* co ) * Initialize internals of Spoofchecker_object. * Must be called before any other call to 'spoofchecker_object_...' functions. */ void spoofchecker_object_init(Spoofchecker_object* co) { if (!co) { return; } intl_error_init(SPOOFCHECKER_ERROR_P(co)); } /* }}} */ /* {{{ void spoofchecker_object_destroy( Spoofchecker_object* co ) * Clean up mem allocted by internals of Spoofchecker_object */ void spoofchecker_object_destroy(Spoofchecker_object* co) { if (!co) { return; } if (co->uspoof) { uspoof_close(co->uspoof); co->uspoof = NULL; } #if U_ICU_VERSION_MAJOR_NUM >= 58 if (co->uspoofres) { uspoof_closeCheckResult(co->uspoofres); co->uspoofres = NULL; } #endif intl_error_reset(SPOOFCHECKER_ERROR_P(co)); } /* }}} */
4,351
29.647887
101
c
php-src
php-src-master/ext/intl/spoofchecker/spoofchecker_class.h
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Scott MacVicar <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef SPOOFCHECKER_CLASS_H #define SPOOFCHECKER_CLASS_H #include <php.h> #include "intl_common.h" #include "intl_error.h" #include "intl_data.h" #include <unicode/uspoof.h> typedef struct { // error handling intl_error err; // ICU Spoofchecker USpoofChecker* uspoof; #if U_ICU_VERSION_MAJOR_NUM >= 58 USpoofCheckResult* uspoofres; #endif zend_object zo; } Spoofchecker_object; static inline Spoofchecker_object *php_intl_spoofchecker_fetch_object(zend_object *obj) { return (Spoofchecker_object *)((char*)(obj) - XtOffsetOf(Spoofchecker_object, zo)); } #define Z_INTL_SPOOFCHECKER_P(zv) php_intl_spoofchecker_fetch_object((Z_OBJ_P(zv))) #define SPOOFCHECKER_ERROR(co) (co)->err #define SPOOFCHECKER_ERROR_P(co) &(SPOOFCHECKER_ERROR(co)) #define SPOOFCHECKER_ERROR_CODE(co) INTL_ERROR_CODE(SPOOFCHECKER_ERROR(co)) #define SPOOFCHECKER_ERROR_CODE_P(co) &(INTL_ERROR_CODE(SPOOFCHECKER_ERROR(co))) void spoofchecker_register_Spoofchecker_class(void); void spoofchecker_object_init(Spoofchecker_object* co); void spoofchecker_object_destroy(Spoofchecker_object* co); extern zend_class_entry *Spoofchecker_ce_ptr; /* Auxiliary macros */ #define SPOOFCHECKER_METHOD_INIT_VARS \ zval* object = ZEND_THIS; \ Spoofchecker_object* co = NULL; \ intl_error_reset(NULL); \ #define SPOOFCHECKER_METHOD_FETCH_OBJECT_NO_CHECK INTL_METHOD_FETCH_OBJECT(INTL_SPOOFCHECKER, co) #define SPOOFCHECKER_METHOD_FETCH_OBJECT \ SPOOFCHECKER_METHOD_FETCH_OBJECT_NO_CHECK; \ if (co->uspoof == NULL) { \ zend_throw_error(NULL, "Found unconstructed Spoofchecker"); \ RETURN_THROWS(); \ } // Macro to check return value of a ucol_* function call. #define SPOOFCHECKER_CHECK_STATUS(co, msg) \ intl_error_set_code(NULL, SPOOFCHECKER_ERROR_CODE(co)); \ if (U_FAILURE(SPOOFCHECKER_ERROR_CODE(co))) { \ intl_errors_set_custom_msg(SPOOFCHECKER_ERROR_P(co), msg, 0); \ RETURN_FALSE; \ } \ #if U_ICU_VERSION_MAJOR_NUM >= 58 #define SPOOFCHECKER_DEFAULT_RESTRICTION_LEVEL USPOOF_HIGHLY_RESTRICTIVE #endif #endif // #ifndef SPOOFCHECKER_CLASS_H
3,203
36.694118
97
h
php-src
php-src-master/ext/intl/spoofchecker/spoofchecker_create.c
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Scott MacVicar <[email protected]> | +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php_intl.h" #include "spoofchecker_class.h" #include "intl_data.h" /* {{{ Spoofchecker object constructor. */ PHP_METHOD(Spoofchecker, __construct) { #if U_ICU_VERSION_MAJOR_NUM < 58 int checks; #endif zend_error_handling error_handling; SPOOFCHECKER_METHOD_INIT_VARS; if (zend_parse_parameters_none() == FAILURE) { RETURN_THROWS(); } zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling); SPOOFCHECKER_METHOD_FETCH_OBJECT_NO_CHECK; co->uspoof = uspoof_open(SPOOFCHECKER_ERROR_CODE_P(co)); INTL_METHOD_CHECK_STATUS(co, "spoofchecker: unable to open ICU Spoof Checker"); #if U_ICU_VERSION_MAJOR_NUM >= 58 /* TODO save it into the object for further suspiction check comparison. */ /* ICU 58 removes WSC and MSC handling. However there are restriction levels as defined in http://www.unicode.org/reports/tr39/tr39-15.html#Restriction_Level_Detection and the default is high restrictive. In further, we might want to utilize uspoof_check2 APIs when it became stable, to use extended check result APIs. Subsequent changes in the unicode security algos are to be watched.*/ uspoof_setRestrictionLevel(co->uspoof, SPOOFCHECKER_DEFAULT_RESTRICTION_LEVEL); co->uspoofres = uspoof_openCheckResult(SPOOFCHECKER_ERROR_CODE_P(co)); #else /* Single-script enforcement is on by default. This fails for languages like Japanese that legally use multiple scripts within a single word, so we turn it off. */ checks = uspoof_getChecks(co->uspoof, SPOOFCHECKER_ERROR_CODE_P(co)); uspoof_setChecks(co->uspoof, checks & ~USPOOF_SINGLE_SCRIPT, SPOOFCHECKER_ERROR_CODE_P(co)); #endif zend_restore_error_handling(&error_handling); } /* }}} */
2,584
39.390625
93
c
php-src
php-src-master/ext/intl/spoofchecker/spoofchecker_main.c
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Scott MacVicar <[email protected]> | +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php_intl.h" #include "spoofchecker_class.h" /* {{{ Checks if a given text contains any suspicious characters */ PHP_METHOD(Spoofchecker, isSuspicious) { int32_t ret, errmask; char *text; size_t text_len; zval *error_code = NULL; SPOOFCHECKER_METHOD_INIT_VARS; if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "s|z", &text, &text_len, &error_code)) { RETURN_THROWS(); } SPOOFCHECKER_METHOD_FETCH_OBJECT; #if U_ICU_VERSION_MAJOR_NUM >= 58 ret = uspoof_check2UTF8(co->uspoof, text, text_len, co->uspoofres, SPOOFCHECKER_ERROR_CODE_P(co)); #else ret = uspoof_checkUTF8(co->uspoof, text, text_len, NULL, SPOOFCHECKER_ERROR_CODE_P(co)); #endif if (U_FAILURE(SPOOFCHECKER_ERROR_CODE(co))) { php_error_docref(NULL, E_WARNING, "(%d) %s", SPOOFCHECKER_ERROR_CODE(co), u_errorName(SPOOFCHECKER_ERROR_CODE(co))); #if U_ICU_VERSION_MAJOR_NUM >= 58 errmask = uspoof_getCheckResultChecks(co->uspoofres, SPOOFCHECKER_ERROR_CODE_P(co)); if (errmask != ret) { php_error_docref(NULL, E_WARNING, "unexpected error (%d), does not relate to the flags passed to setChecks (%d)", ret, errmask); } #endif RETURN_TRUE; } if (error_code) { zval_ptr_dtor(error_code); ZVAL_LONG(Z_REFVAL_P(error_code), ret); Z_TRY_ADDREF_P(error_code); } RETVAL_BOOL(ret != 0); } /* }}} */ /* {{{ Checks if a given text contains any confusable characters */ PHP_METHOD(Spoofchecker, areConfusable) { int ret; char *s1, *s2; size_t s1_len, s2_len; zval *error_code = NULL; SPOOFCHECKER_METHOD_INIT_VARS; if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "ss|z", &s1, &s1_len, &s2, &s2_len, &error_code)) { RETURN_THROWS(); } SPOOFCHECKER_METHOD_FETCH_OBJECT; if(s1_len > INT32_MAX || s2_len > INT32_MAX) { SPOOFCHECKER_ERROR_CODE(co) = U_BUFFER_OVERFLOW_ERROR; } else { ret = uspoof_areConfusableUTF8(co->uspoof, s1, (int32_t)s1_len, s2, (int32_t)s2_len, SPOOFCHECKER_ERROR_CODE_P(co)); } if (U_FAILURE(SPOOFCHECKER_ERROR_CODE(co))) { php_error_docref(NULL, E_WARNING, "(%d) %s", SPOOFCHECKER_ERROR_CODE(co), u_errorName(SPOOFCHECKER_ERROR_CODE(co))); RETURN_TRUE; } if (error_code) { zval_ptr_dtor(error_code); ZVAL_LONG(Z_REFVAL_P(error_code), ret); Z_TRY_ADDREF_P(error_code); } RETVAL_BOOL(ret != 0); } /* }}} */ /* {{{ Locales to use when running checks */ PHP_METHOD(Spoofchecker, setAllowedLocales) { char *locales; size_t locales_len; SPOOFCHECKER_METHOD_INIT_VARS; if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "s", &locales, &locales_len)) { RETURN_THROWS(); } SPOOFCHECKER_METHOD_FETCH_OBJECT; uspoof_setAllowedLocales(co->uspoof, locales, SPOOFCHECKER_ERROR_CODE_P(co)); if (U_FAILURE(SPOOFCHECKER_ERROR_CODE(co))) { php_error_docref(NULL, E_WARNING, "(%d) %s", SPOOFCHECKER_ERROR_CODE(co), u_errorName(SPOOFCHECKER_ERROR_CODE(co))); return; } } /* }}} */ /* {{{ Set the checks to run */ PHP_METHOD(Spoofchecker, setChecks) { zend_long checks; SPOOFCHECKER_METHOD_INIT_VARS; if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "l", &checks)) { RETURN_THROWS(); } SPOOFCHECKER_METHOD_FETCH_OBJECT; uspoof_setChecks(co->uspoof, checks, SPOOFCHECKER_ERROR_CODE_P(co)); if (U_FAILURE(SPOOFCHECKER_ERROR_CODE(co))) { php_error_docref(NULL, E_WARNING, "(%d) %s", SPOOFCHECKER_ERROR_CODE(co), u_errorName(SPOOFCHECKER_ERROR_CODE(co))); } } /* }}} */ #if U_ICU_VERSION_MAJOR_NUM >= 58 /* TODO Document this method on PHP.net */ /* {{{ Set the loosest restriction level allowed for strings. */ PHP_METHOD(Spoofchecker, setRestrictionLevel) { zend_long level; SPOOFCHECKER_METHOD_INIT_VARS; if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "l", &level)) { RETURN_THROWS(); } SPOOFCHECKER_METHOD_FETCH_OBJECT; if (USPOOF_ASCII != level && USPOOF_SINGLE_SCRIPT_RESTRICTIVE != level && USPOOF_HIGHLY_RESTRICTIVE != level && USPOOF_MODERATELY_RESTRICTIVE != level && USPOOF_MINIMALLY_RESTRICTIVE != level && USPOOF_UNRESTRICTIVE != level) { zend_argument_value_error(1, "must be one of Spoofchecker::ASCII, Spoofchecker::SINGLE_SCRIPT_RESTRICTIVE, " "Spoofchecker::SINGLE_HIGHLY_RESTRICTIVE, Spoofchecker::SINGLE_MODERATELY_RESTRICTIVE, " "Spoofchecker::SINGLE_MINIMALLY_RESTRICTIVE, or Spoofchecker::UNRESTRICTIVE"); RETURN_THROWS(); } uspoof_setRestrictionLevel(co->uspoof, (URestrictionLevel)level); } /* }}} */ #endif
5,268
29.994118
131
c
php-src
php-src-master/ext/intl/timezone/timezone_class.h
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Gustavo Lopes <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef TIMEZONE_CLASS_H #define TIMEZONE_CLASS_H //redefinition of inline in PHP headers causes problems, so include this before #include <math.h> //fixes the build on windows for old versions of ICU #include <stdio.h> #include <php.h> #include "intl_error.h" #include "intl_data.h" #ifndef USE_TIMEZONE_POINTER typedef void TimeZone; #else using icu::TimeZone; #endif typedef struct { // error handling intl_error err; // ICU TimeZone const TimeZone *utimezone; //whether to delete the timezone on object free bool should_delete; zend_object zo; } TimeZone_object; static inline TimeZone_object *php_intl_timezone_fetch_object(zend_object *obj) { return (TimeZone_object *)((char*)(obj) - XtOffsetOf(TimeZone_object, zo)); } #define Z_INTL_TIMEZONE_P(zv) php_intl_timezone_fetch_object(Z_OBJ_P(zv)) #define TIMEZONE_ERROR(to) (to)->err #define TIMEZONE_ERROR_P(to) &(TIMEZONE_ERROR(to)) #define TIMEZONE_ERROR_CODE(co) INTL_ERROR_CODE(TIMEZONE_ERROR(to)) #define TIMEZONE_ERROR_CODE_P(co) &(INTL_ERROR_CODE(TIMEZONE_ERROR(to))) #define TIMEZONE_METHOD_INIT_VARS INTL_METHOD_INIT_VARS(TimeZone, to) #define TIMEZONE_METHOD_FETCH_OBJECT_NO_CHECK INTL_METHOD_FETCH_OBJECT(INTL_TIMEZONE, to) #define TIMEZONE_METHOD_FETCH_OBJECT\ TIMEZONE_METHOD_FETCH_OBJECT_NO_CHECK; \ if (to->utimezone == NULL) { \ zend_throw_error(NULL, "Found unconstructed IntlTimeZone"); \ RETURN_THROWS(); \ } zval *timezone_convert_to_datetimezone(const TimeZone *timeZone, intl_error *outside_error, const char *func, zval *ret); TimeZone *timezone_process_timezone_argument(zval *zv_timezone, intl_error *error, const char *func); void timezone_object_construct(const TimeZone *zone, zval *object, int owned); void timezone_register_IntlTimeZone_class(void); extern zend_class_entry *TimeZone_ce_ptr; extern zend_object_handlers TimeZone_handlers; #endif /* #ifndef TIMEZONE_CLASS_H */
2,761
34.410256
121
h
php-src
php-src-master/ext/intl/transliterator/transliterator.h
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Gustavo Lopes <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef TRANSLITERATOR_TRANSLITERATOR_H #define TRANSLITERATOR_TRANSLITERATOR_H #include <php.h> #include <unicode/utrans.h> #include "zend_smart_str.h" smart_str transliterator_parse_error_to_string( UParseError* pe ); #endif /* #ifndef TRANSLITERATOR_TRANSLITERATOR_H */
1,121
42.153846
75
h
php-src
php-src-master/ext/intl/transliterator/transliterator_class.c
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Gustavo Lopes <[email protected]> | +----------------------------------------------------------------------+ */ #include "transliterator_class.h" #include "php_intl.h" #include "transliterator_arginfo.h" #include "intl_error.h" #include "intl_convert.h" #include "intl_data.h" #include <unicode/utrans.h> zend_class_entry *Transliterator_ce_ptr = NULL; zend_object_handlers Transliterator_handlers; /* {{{ int transliterator_object_construct( zval *object, UTransliterator *utrans, UErrorCode *status ) * Initialize internals of Transliterator_object. */ int transliterator_object_construct( zval *object, UTransliterator *utrans, UErrorCode *status ) { const UChar *ustr_id; int32_t ustr_id_len; zend_string *u8str; zval tmp; Transliterator_object *to; TRANSLITERATOR_METHOD_FETCH_OBJECT_NO_CHECK; assert( to->utrans == NULL ); /* this assignment must happen before any return with failure because the * caller relies on it always being made (so it can just destroy the object * to close the transliterator) */ to->utrans = utrans; ustr_id = utrans_getUnicodeID( utrans, &ustr_id_len ); u8str = intl_convert_utf16_to_utf8(ustr_id, (int ) ustr_id_len, status ); if( !u8str ) { return FAILURE; } ZVAL_NEW_STR(&tmp, u8str); zend_update_property(Transliterator_ce_ptr, Z_OBJ_P(object), "id", sizeof( "id" ) - 1, &tmp ); GC_DELREF(u8str); return SUCCESS; } /* }}} */ /* * Auxiliary functions needed by objects of 'Transliterator' class */ /* {{{ void transliterator_object_init( Transliterator_object* to ) * Initialize internals of Transliterator_object. */ static void transliterator_object_init( Transliterator_object* to ) { if( !to ) return; intl_error_init( TRANSLITERATOR_ERROR_P( to ) ); } /* }}} */ /* {{{ void transliterator_object_destroy( Transliterator_object* to ) * Clean up mem allocted by internals of Transliterator_object */ static void transliterator_object_destroy( Transliterator_object* to ) { if( !to ) return; if( to->utrans ) { utrans_close( to->utrans ); to->utrans = NULL; } intl_error_reset( TRANSLITERATOR_ERROR_P( to ) ); } /* }}} */ /* {{{ Transliterator_objects_free */ static void Transliterator_objects_free( zend_object *object ) { Transliterator_object* to = php_intl_transliterator_fetch_object(object); zend_object_std_dtor( &to->zo ); transliterator_object_destroy( to ); } /* }}} */ /* {{{ Transliterator_object_create */ static zend_object *Transliterator_object_create( zend_class_entry *ce ) { Transliterator_object* intern; intern = zend_object_alloc(sizeof(Transliterator_object), ce); zend_object_std_init( &intern->zo, ce ); object_properties_init( &intern->zo, ce ); transliterator_object_init( intern ); return &intern->zo; } /* }}} */ /* * Object handlers for Transliterator class (and subclasses) */ /* {{{ clone handler for Transliterator */ static zend_object *Transliterator_clone_obj( zend_object *object ) { Transliterator_object *to_orig, *to_new; zend_object *ret_val; intl_error_reset( NULL ); to_orig = php_intl_transliterator_fetch_object( object ); intl_error_reset( INTL_DATA_ERROR_P( to_orig ) ); ret_val = Transliterator_ce_ptr->create_object( object->ce ); to_new = php_intl_transliterator_fetch_object( ret_val ); zend_objects_clone_members( &to_new->zo, &to_orig->zo ); if( to_orig->utrans != NULL ) { /* guaranteed to return NULL if it fails */ UTransliterator *utrans = utrans_clone( to_orig->utrans, TRANSLITERATOR_ERROR_CODE_P( to_orig ) ); if( U_FAILURE( TRANSLITERATOR_ERROR_CODE( to_orig ) ) ) { zend_string *err_msg; if( utrans != NULL ) transliterator_object_destroy( to_new ); /* set the error anyway, in case in the future we decide not to * throw an error. It also helps build the error message */ intl_error_set_code( NULL, INTL_DATA_ERROR_CODE( to_orig ) ); intl_errors_set_custom_msg( TRANSLITERATOR_ERROR_P( to_orig ), "Could not clone transliterator", 0 ); err_msg = intl_error_get_message( TRANSLITERATOR_ERROR_P( to_orig ) ); zend_throw_error( NULL, "%s", ZSTR_VAL(err_msg) ); zend_string_free( err_msg ); /* if it's changed into a warning */ } else { to_new->utrans = utrans; } } else { /* We shouldn't have unconstructed objects in the first place */ zend_throw_error(NULL, "Unconstructed Transliterator object cannot be cloned"); } return ret_val; } /* }}} */ /* {{{ transliterator_register_Transliterator_class * Initialize 'Transliterator' class */ void transliterator_register_Transliterator_class( void ) { /* Create and register 'Transliterator' class. */ Transliterator_ce_ptr = register_class_Transliterator(); Transliterator_ce_ptr->create_object = Transliterator_object_create; Transliterator_ce_ptr->default_object_handlers = &Transliterator_handlers; memcpy( &Transliterator_handlers, &std_object_handlers, sizeof Transliterator_handlers ); Transliterator_handlers.offset = XtOffsetOf(Transliterator_object, zo); Transliterator_handlers.free_obj = Transliterator_objects_free; Transliterator_handlers.clone_obj = Transliterator_clone_obj; } /* }}} */
5,950
29.994792
103
c
php-src
php-src-master/ext/intl/transliterator/transliterator_class.h
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Gustavo Lopes <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef TRANSLITERATOR_CLASS_H #define TRANSLITERATOR_CLASS_H #include <php.h> #include "intl_common.h" #include "intl_error.h" #include <unicode/utrans.h> typedef struct { // error handling intl_error err; // ICU transliterator UTransliterator* utrans; zend_object zo; } Transliterator_object; static inline Transliterator_object *php_intl_transliterator_fetch_object(zend_object *obj) { return (Transliterator_object *)((char*)(obj) - XtOffsetOf(Transliterator_object, zo)); } #define Z_INTL_TRANSLITERATOR_P(zv) php_intl_transliterator_fetch_object(Z_OBJ_P(zv)) #define TRANSLITERATOR_FORWARD UTRANS_FORWARD #define TRANSLITERATOR_REVERSE UTRANS_REVERSE #define TRANSLITERATOR_ERROR( co ) (co)->err #define TRANSLITERATOR_ERROR_P( co ) &(TRANSLITERATOR_ERROR( co )) #define TRANSLITERATOR_ERROR_CODE( co ) INTL_ERROR_CODE(TRANSLITERATOR_ERROR( co )) #define TRANSLITERATOR_ERROR_CODE_P( co ) &(INTL_ERROR_CODE(TRANSLITERATOR_ERROR( co ))) #define TRANSLITERATOR_METHOD_INIT_VARS INTL_METHOD_INIT_VARS( Transliterator, to ) #define TRANSLITERATOR_METHOD_FETCH_OBJECT_NO_CHECK INTL_METHOD_FETCH_OBJECT( INTL_TRANSLITERATOR, to ) #define TRANSLITERATOR_METHOD_FETCH_OBJECT\ TRANSLITERATOR_METHOD_FETCH_OBJECT_NO_CHECK; \ if( to->utrans == NULL ) \ { \ zend_throw_error(NULL, "Found unconstructed transliterator"); \ RETURN_THROWS(); \ } int transliterator_object_construct( zval *object, UTransliterator *utrans, UErrorCode *status ); void transliterator_register_Transliterator_class( void ); extern zend_class_entry *Transliterator_ce_ptr; extern zend_object_handlers Transliterator_handlers; #endif /* #ifndef TRANSLITERATOR_CLASS_H */
2,551
35.985507
104
h
php-src
php-src-master/ext/intl/transliterator/transliterator_methods.c
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Gustavo Lopes <[email protected]> | +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php_intl.h" #include "transliterator.h" #include "transliterator_class.h" #include "intl_data.h" #include "intl_convert.h" #include <zend_exceptions.h> static int create_transliterator( char *str_id, size_t str_id_len, zend_long direction, zval *object ) { Transliterator_object *to; UChar *ustr_id = NULL; int32_t ustr_id_len = 0; UTransliterator *utrans; UParseError parse_error; intl_error_reset( NULL ); if( ( direction != TRANSLITERATOR_FORWARD ) && (direction != TRANSLITERATOR_REVERSE ) ) { zend_argument_value_error(2, "must be either Transliterator::FORWARD or Transliterator::REVERSE"); return FAILURE; } object_init_ex( object, Transliterator_ce_ptr ); TRANSLITERATOR_METHOD_FETCH_OBJECT_NO_CHECK; /* fetch zend object from zval "object" into "to" */ /* Convert transliterator id to UTF-16 */ intl_convert_utf8_to_utf16( &ustr_id, &ustr_id_len, str_id, str_id_len, TRANSLITERATOR_ERROR_CODE_P( to ) ); if( U_FAILURE( TRANSLITERATOR_ERROR_CODE( to ) ) ) { intl_error_set_code( NULL, TRANSLITERATOR_ERROR_CODE( to ) ); intl_error_set_custom_msg( NULL, "String conversion of id to UTF-16 failed", 0 ); zval_ptr_dtor( object ); return FAILURE; } /* Open ICU Transliterator. */ utrans = utrans_openU( ustr_id, ustr_id_len, (UTransDirection ) direction, NULL, -1, &parse_error, TRANSLITERATOR_ERROR_CODE_P( to ) ); if (ustr_id) { efree( ustr_id ); } if( U_FAILURE( TRANSLITERATOR_ERROR_CODE( to ) ) ) { char *buf = NULL; intl_error_set_code( NULL, TRANSLITERATOR_ERROR_CODE( to ) ); spprintf( &buf, 0, "transliterator_create: unable to open ICU transliterator" " with id \"%s\"", str_id ); if( buf == NULL ) { intl_error_set_custom_msg( NULL, "transliterator_create: unable to open ICU transliterator", 0 ); } else { intl_error_set_custom_msg( NULL, buf, /* copy message */ 1 ); efree( buf ); } zval_ptr_dtor( object ); return FAILURE; } transliterator_object_construct( object, utrans, TRANSLITERATOR_ERROR_CODE_P( to ) ); /* no need to close the transliterator manually on construction error */ if( U_FAILURE( TRANSLITERATOR_ERROR_CODE( to ) ) ) { intl_error_set_code( NULL, TRANSLITERATOR_ERROR_CODE( to ) ); intl_error_set_custom_msg( NULL, "transliterator_create: internal constructor call failed", 0 ); zval_ptr_dtor( object ); return FAILURE; } return SUCCESS; } /* {{{ Opens a transliterator by id. */ PHP_FUNCTION( transliterator_create ) { char *str_id; size_t str_id_len; zend_long direction = TRANSLITERATOR_FORWARD; int res; TRANSLITERATOR_METHOD_INIT_VARS; (void) to; /* unused */ if( zend_parse_parameters( ZEND_NUM_ARGS(), "s|l", &str_id, &str_id_len, &direction ) == FAILURE ) { RETURN_THROWS(); } object = return_value; res = create_transliterator( str_id, str_id_len, direction, object ); if( res == FAILURE ) RETURN_NULL(); /* success, leave return_value as it is (set by create_transliterator) */ } /* }}} */ /* {{{ Opens a transliterator by id. */ PHP_FUNCTION( transliterator_create_from_rules ) { char *str_rules; size_t str_rules_len; UChar *ustr_rules = NULL; int32_t ustr_rules_len = 0; zend_long direction = TRANSLITERATOR_FORWARD; UParseError parse_error; UTransliterator *utrans; UChar id[] = {0x52, 0x75, 0x6C, 0x65, 0x73, 0x54, 0x72, 0x61, 0x6E, 0x73, 0x50, 0x48, 0x50, 0}; /* RulesTransPHP */ TRANSLITERATOR_METHOD_INIT_VARS; if( zend_parse_parameters( ZEND_NUM_ARGS(), "s|l", &str_rules, &str_rules_len, &direction ) == FAILURE ) { RETURN_THROWS(); } if( ( direction != TRANSLITERATOR_FORWARD ) && (direction != TRANSLITERATOR_REVERSE ) ) { zend_argument_value_error(2, "must be either Transliterator::FORWARD or Transliterator::REVERSE"); RETURN_THROWS(); } object = return_value; object_init_ex( object, Transliterator_ce_ptr ); TRANSLITERATOR_METHOD_FETCH_OBJECT_NO_CHECK; intl_convert_utf8_to_utf16( &ustr_rules, &ustr_rules_len, str_rules, str_rules_len, TRANSLITERATOR_ERROR_CODE_P( to ) ); /* (I'm not a big fan of non-obvious flow control macros ). * This one checks the error value, destroys object and returns false */ INTL_METHOD_CHECK_STATUS_OR_NULL( to, "String conversion of rules to UTF-16 failed" ); /* Open ICU Transliterator. */ utrans = utrans_openU( id, ( sizeof( id ) - 1 ) / ( sizeof( *id ) ), (UTransDirection ) direction, ustr_rules, ustr_rules_len, &parse_error, TRANSLITERATOR_ERROR_CODE_P( to ) ); if (ustr_rules) { efree( ustr_rules ); } intl_error_set_code( NULL, INTL_DATA_ERROR_CODE( to ) ); if( U_FAILURE( INTL_DATA_ERROR_CODE( to ) ) ) { char *msg = NULL; smart_str parse_error_str; parse_error_str = intl_parse_error_to_string( &parse_error ); spprintf( &msg, 0, "transliterator_create_from_rules: unable to " "create ICU transliterator from rules (%s)", parse_error_str.s? ZSTR_VAL(parse_error_str.s) : "" ); smart_str_free( &parse_error_str ); if( msg != NULL ) { intl_errors_set_custom_msg( INTL_DATA_ERROR_P( to ), msg, 1 ); efree( msg ); } zval_ptr_dtor( return_value ); RETURN_NULL(); } transliterator_object_construct( object, utrans, TRANSLITERATOR_ERROR_CODE_P( to ) ); /* no need to close the transliterator manually on construction error */ INTL_METHOD_CHECK_STATUS_OR_NULL( to, "transliterator_create_from_rules: internal constructor call failed" ); } /* }}} */ /* {{{ Opens the inverse transliterator transliterator. */ PHP_FUNCTION( transliterator_create_inverse ) { Transliterator_object *to_orig; UTransliterator *utrans; TRANSLITERATOR_METHOD_INIT_VARS; if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "O", &object, Transliterator_ce_ptr ) == FAILURE ) { RETURN_THROWS(); } TRANSLITERATOR_METHOD_FETCH_OBJECT; to_orig = to; object = return_value; object_init_ex( object, Transliterator_ce_ptr ); TRANSLITERATOR_METHOD_FETCH_OBJECT_NO_CHECK; /* change "to" into new object (from "object" ) */ utrans = utrans_openInverse( to_orig->utrans, TRANSLITERATOR_ERROR_CODE_P( to ) ); INTL_METHOD_CHECK_STATUS_OR_NULL( to, "transliterator_create_inverse: could not create " "inverse ICU transliterator" ); transliterator_object_construct( object, utrans, TRANSLITERATOR_ERROR_CODE_P( to ) ); /* no need to close the transliterator manually on construction error */ INTL_METHOD_CHECK_STATUS_OR_NULL( to, "transliterator_create: internal constructor call failed" ); } /* }}} */ /* {{{ Return an array with the registered transliterator IDs. */ PHP_FUNCTION( transliterator_list_ids ) { UEnumeration *en; const UChar *elem; int32_t elem_len; UErrorCode status = U_ZERO_ERROR; intl_error_reset( NULL ); if( zend_parse_parameters_none() == FAILURE ) { RETURN_THROWS(); } en = utrans_openIDs( &status ); INTL_CHECK_STATUS( status, "transliterator_list_ids: Failed to obtain registered transliterators" ); array_init( return_value ); while( (elem = uenum_unext( en, &elem_len, &status )) ) { zend_string *el = intl_convert_utf16_to_utf8(elem, elem_len, &status ); if( !el ) { break; } else { add_next_index_str( return_value, el); } } uenum_close( en ); intl_error_set_code( NULL, status ); if( U_FAILURE( status ) ) { zend_array_destroy( Z_ARR_P(return_value) ); RETVAL_FALSE; intl_error_set_custom_msg( NULL, "transliterator_list_ids: " "Failed to build array of registered transliterators", 0 ); } } /* }}} */ /* {{{ Transliterate a string. */ PHP_FUNCTION( transliterator_transliterate ) { char *str; UChar *ustr = NULL, *uresult = NULL; size_t str_len; int32_t ustr_len = 0, capacity, uresult_len; zend_long start = 0, limit = -1; int success = 0; zval tmp_object; TRANSLITERATOR_METHOD_INIT_VARS; object = getThis(); ZVAL_UNDEF(&tmp_object); if (object == NULL) { /* in non-OOP version, accept both a transliterator and a string */ zend_string *arg1_str; zend_object *arg1_obj; ZEND_PARSE_PARAMETERS_START(2, 4) Z_PARAM_OBJ_OF_CLASS_OR_STR(arg1_obj, Transliterator_ce_ptr, arg1_str) Z_PARAM_STRING(str, str_len) Z_PARAM_OPTIONAL Z_PARAM_LONG(start) Z_PARAM_LONG(limit) ZEND_PARSE_PARAMETERS_END(); if (arg1_str) { /* not a transliterator object as first argument */ int res; object = &tmp_object; res = create_transliterator(ZSTR_VAL(arg1_str), ZSTR_LEN(arg1_str), TRANSLITERATOR_FORWARD, object); if( res == FAILURE ) { if (!EG(exception)) { zend_string *message = intl_error_get_message( NULL ); php_error_docref(NULL, E_WARNING, "Could not create transliterator with ID \"%s\" (%s)", ZSTR_VAL(arg1_str), ZSTR_VAL(message) ); zend_string_free( message ); } ZVAL_UNDEF(&tmp_object); /* don't set U_ILLEGAL_ARGUMENT_ERROR to allow fetching of inner error */ goto cleanup; } } else { ZVAL_OBJ_COPY(&tmp_object, arg1_obj); object = &tmp_object; } } else if(zend_parse_parameters( ZEND_NUM_ARGS(), "s|ll", &str, &str_len, &start, &limit) == FAILURE) { RETURN_THROWS(); } if (limit < -1) { zend_argument_value_error(object ? 3 : 4, "must be greater than or equal to -1"); goto cleanup_object; } if (start < 0) { zend_argument_value_error(object ? 2 : 3, "must be greater than or equal to 0"); goto cleanup_object; } if (limit != -1 && start > limit) { zend_argument_value_error(object ? 2 : 3, "must be less than or equal to argument #%d ($end)", object ? 3 : 4); goto cleanup_object; } /* end argument parsing/validation */ TRANSLITERATOR_METHOD_FETCH_OBJECT; intl_convert_utf8_to_utf16(&ustr, &ustr_len, str, str_len, TRANSLITERATOR_ERROR_CODE_P(to)); INTL_METHOD_CHECK_STATUS_OR_GOTO(to, "String conversion of string to UTF-16 failed", cleanup_object); /* we've started allocating resources, goto from now on */ if( ( start > ustr_len ) || (( limit != -1 ) && (limit > ustr_len ) ) ) { char *msg; spprintf( &msg, 0, "transliterator_transliterate: Neither \"start\" nor the \"end\" " "arguments can exceed the number of UTF-16 code units " "(in this case, %d)", (int) ustr_len ); if(msg != NULL ) { intl_errors_set( TRANSLITERATOR_ERROR_P( to ), U_ILLEGAL_ARGUMENT_ERROR, msg, 1 ); efree( msg ); } goto cleanup; } uresult = safe_emalloc( ustr_len, sizeof( UChar ), 1 * sizeof( UChar ) ); capacity = ustr_len + 1; while( 1 ) { int32_t temp_limit = ( limit == -1 ? ustr_len : (int32_t) limit ); memcpy( uresult, ustr, ustr_len * sizeof( UChar ) ); uresult_len = ustr_len; utrans_transUChars( to->utrans, uresult, &uresult_len, capacity, (int32_t) start, &temp_limit, TRANSLITERATOR_ERROR_CODE_P( to ) ); if( TRANSLITERATOR_ERROR_CODE( to ) == U_BUFFER_OVERFLOW_ERROR ) { efree( uresult ); uresult = safe_emalloc( uresult_len, sizeof( UChar ), 1 * sizeof( UChar ) ); capacity = uresult_len + 1; intl_error_reset( TRANSLITERATOR_ERROR_P( to ) ); } else if(TRANSLITERATOR_ERROR_CODE( to ) == U_STRING_NOT_TERMINATED_WARNING ) { uresult = safe_erealloc( uresult, uresult_len, sizeof( UChar ), 1 * sizeof( UChar ) ); intl_error_reset( TRANSLITERATOR_ERROR_P( to ) ); break; } else if( U_FAILURE( TRANSLITERATOR_ERROR_CODE( to ) ) ) { intl_error_set_code( NULL, TRANSLITERATOR_ERROR_CODE( to ) ); intl_errors_set_custom_msg( TRANSLITERATOR_ERROR_P( to ), "transliterator_transliterate: transliteration failed", 0 ); goto cleanup; } else break; } uresult[uresult_len] = (UChar) 0; success = 1; cleanup: if( ustr ) efree( ustr ); if( success ) { /* frees uresult even on error */ INTL_METHOD_RETVAL_UTF8( to, uresult, uresult_len, 1 ); } else { if( uresult ) efree( uresult ); RETVAL_FALSE; } cleanup_object: zval_ptr_dtor( &tmp_object ); } /* }}} */ PHP_METHOD( Transliterator, __construct ) { /* this constructor shouldn't be called as it's private */ zend_throw_exception( NULL, "An object of this type cannot be created with the new operator.", 0 ); } /* {{{ Get the last error code for this transliterator. */ PHP_FUNCTION( transliterator_get_error_code ) { TRANSLITERATOR_METHOD_INIT_VARS if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "O", &object, Transliterator_ce_ptr ) == FAILURE ) { RETURN_THROWS(); } /* Fetch the object (without resetting its last error code ). */ to = Z_INTL_TRANSLITERATOR_P( object ); if (to == NULL ) RETURN_FALSE; RETURN_LONG( (zend_long) TRANSLITERATOR_ERROR_CODE( to ) ); } /* }}} */ /* {{{ Get the last error message for this transliterator. */ PHP_FUNCTION( transliterator_get_error_message ) { zend_string* message = NULL; TRANSLITERATOR_METHOD_INIT_VARS if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "O", &object, Transliterator_ce_ptr ) == FAILURE ) { RETURN_THROWS(); } /* Fetch the object (without resetting its last error code ). */ to = Z_INTL_TRANSLITERATOR_P( object ); if (to == NULL ) RETURN_FALSE; /* Return last error message. */ message = intl_error_get_message( TRANSLITERATOR_ERROR_P( to ) ); RETURN_STR( message ); } /* }}} */
14,100
28.748945
134
c
php-src
php-src-master/ext/json/json_encoder.c
/* +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Omar Kilani <[email protected]> | | Jakub Zelenka <[email protected]> | +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php.h" #include "php_ini.h" #include "ext/standard/info.h" #include "ext/standard/html.h" #include "zend_smart_str.h" #include "php_json.h" #include "php_json_encoder.h" #include <zend_exceptions.h> #include "zend_enum.h" static const char digits[] = "0123456789abcdef"; static int php_json_determine_array_type(zval *val) /* {{{ */ { zend_array *myht = Z_ARRVAL_P(val); if (myht) { return zend_array_is_list(myht) ? PHP_JSON_OUTPUT_ARRAY : PHP_JSON_OUTPUT_OBJECT; } return PHP_JSON_OUTPUT_ARRAY; } /* }}} */ /* {{{ Pretty printing support functions */ static inline void php_json_pretty_print_char(smart_str *buf, int options, char c) /* {{{ */ { if (options & PHP_JSON_PRETTY_PRINT) { smart_str_appendc(buf, c); } } /* }}} */ static inline void php_json_pretty_print_indent(smart_str *buf, int options, php_json_encoder *encoder) /* {{{ */ { int i; if (options & PHP_JSON_PRETTY_PRINT) { for (i = 0; i < encoder->depth; ++i) { smart_str_appendl(buf, " ", 4); } } } /* }}} */ /* }}} */ static #if defined(_MSC_VER) && defined(_M_ARM64) // MSVC bug: https://developercommunity.visualstudio.com/t/corrupt-optimization-on-arm64-with-Ox-/10102551 zend_never_inline #else inline #endif bool php_json_is_valid_double(double d) /* {{{ */ { return !zend_isinf(d) && !zend_isnan(d); } /* }}} */ static inline void php_json_encode_double(smart_str *buf, double d, int options) /* {{{ */ { size_t len; char num[ZEND_DOUBLE_MAX_LENGTH]; zend_gcvt(d, (int)PG(serialize_precision), '.', 'e', num); len = strlen(num); if (options & PHP_JSON_PRESERVE_ZERO_FRACTION && strchr(num, '.') == NULL && len < ZEND_DOUBLE_MAX_LENGTH - 2) { num[len++] = '.'; num[len++] = '0'; num[len] = '\0'; } smart_str_appendl(buf, num, len); } /* }}} */ #define PHP_JSON_HASH_PROTECT_RECURSION(_tmp_ht) \ do { \ if (_tmp_ht) { \ GC_TRY_PROTECT_RECURSION(_tmp_ht); \ } \ } while (0) #define PHP_JSON_HASH_UNPROTECT_RECURSION(_tmp_ht) \ do { \ if (_tmp_ht) { \ GC_TRY_UNPROTECT_RECURSION(_tmp_ht); \ } \ } while (0) static zend_result php_json_encode_array(smart_str *buf, zval *val, int options, php_json_encoder *encoder) /* {{{ */ { int i, r, need_comma = 0; HashTable *myht, *prop_ht; if (Z_TYPE_P(val) == IS_ARRAY) { myht = Z_ARRVAL_P(val); prop_ht = NULL; r = (options & PHP_JSON_FORCE_OBJECT) ? PHP_JSON_OUTPUT_OBJECT : php_json_determine_array_type(val); } else if (Z_OBJ_P(val)->properties == NULL && Z_OBJ_HT_P(val)->get_properties_for == NULL && Z_OBJ_HT_P(val)->get_properties == zend_std_get_properties) { /* Optimized version without rebuilding properties HashTable */ zend_object *obj = Z_OBJ_P(val); zend_class_entry *ce = obj->ce; zend_property_info *prop_info; zval *prop; int i; if (GC_IS_RECURSIVE(obj)) { encoder->error_code = PHP_JSON_ERROR_RECURSION; smart_str_appendl(buf, "null", 4); return FAILURE; } PHP_JSON_HASH_PROTECT_RECURSION(obj); smart_str_appendc(buf, '{'); ++encoder->depth; for (i = 0; i < ce->default_properties_count; i++) { prop_info = ce->properties_info_table[i]; if (!prop_info) { continue; } if (ZSTR_VAL(prop_info->name)[0] == '\0' && ZSTR_LEN(prop_info->name) > 0) { /* Skip protected and private members. */ continue; } prop = OBJ_PROP(obj, prop_info->offset); if (Z_TYPE_P(prop) == IS_UNDEF) { continue; } if (need_comma) { smart_str_appendc(buf, ','); } else { need_comma = 1; } php_json_pretty_print_char(buf, options, '\n'); php_json_pretty_print_indent(buf, options, encoder); if (php_json_escape_string(buf, ZSTR_VAL(prop_info->name), ZSTR_LEN(prop_info->name), options & ~PHP_JSON_NUMERIC_CHECK, encoder) == FAILURE && (options & PHP_JSON_PARTIAL_OUTPUT_ON_ERROR) && buf->s) { ZSTR_LEN(buf->s) -= 4; smart_str_appendl(buf, "\"\"", 2); } smart_str_appendc(buf, ':'); php_json_pretty_print_char(buf, options, ' '); if (php_json_encode_zval(buf, prop, options, encoder) == FAILURE && !(options & PHP_JSON_PARTIAL_OUTPUT_ON_ERROR)) { PHP_JSON_HASH_UNPROTECT_RECURSION(obj); return FAILURE; } } PHP_JSON_HASH_UNPROTECT_RECURSION(obj); if (encoder->depth > encoder->max_depth) { encoder->error_code = PHP_JSON_ERROR_DEPTH; if (!(options & PHP_JSON_PARTIAL_OUTPUT_ON_ERROR)) { return FAILURE; } } --encoder->depth; if (need_comma) { php_json_pretty_print_char(buf, options, '\n'); php_json_pretty_print_indent(buf, options, encoder); } smart_str_appendc(buf, '}'); return SUCCESS; } else { prop_ht = myht = zend_get_properties_for(val, ZEND_PROP_PURPOSE_JSON); r = PHP_JSON_OUTPUT_OBJECT; } if (myht && GC_IS_RECURSIVE(myht)) { encoder->error_code = PHP_JSON_ERROR_RECURSION; smart_str_appendl(buf, "null", 4); zend_release_properties(prop_ht); return FAILURE; } PHP_JSON_HASH_PROTECT_RECURSION(myht); if (r == PHP_JSON_OUTPUT_ARRAY) { smart_str_appendc(buf, '['); } else { smart_str_appendc(buf, '{'); } ++encoder->depth; i = myht ? zend_hash_num_elements(myht) : 0; if (i > 0) { zend_string *key; zval *data; zend_ulong index; ZEND_HASH_FOREACH_KEY_VAL_IND(myht, index, key, data) { if (r == PHP_JSON_OUTPUT_ARRAY) { if (need_comma) { smart_str_appendc(buf, ','); } else { need_comma = 1; } php_json_pretty_print_char(buf, options, '\n'); php_json_pretty_print_indent(buf, options, encoder); } else if (r == PHP_JSON_OUTPUT_OBJECT) { if (key) { if (ZSTR_VAL(key)[0] == '\0' && ZSTR_LEN(key) > 0 && Z_TYPE_P(val) == IS_OBJECT) { /* Skip protected and private members. */ continue; } if (need_comma) { smart_str_appendc(buf, ','); } else { need_comma = 1; } php_json_pretty_print_char(buf, options, '\n'); php_json_pretty_print_indent(buf, options, encoder); if (php_json_escape_string(buf, ZSTR_VAL(key), ZSTR_LEN(key), options & ~PHP_JSON_NUMERIC_CHECK, encoder) == FAILURE && (options & PHP_JSON_PARTIAL_OUTPUT_ON_ERROR) && buf->s) { ZSTR_LEN(buf->s) -= 4; smart_str_appendl(buf, "\"\"", 2); } } else { if (need_comma) { smart_str_appendc(buf, ','); } else { need_comma = 1; } php_json_pretty_print_char(buf, options, '\n'); php_json_pretty_print_indent(buf, options, encoder); smart_str_appendc(buf, '"'); smart_str_append_long(buf, (zend_long) index); smart_str_appendc(buf, '"'); } smart_str_appendc(buf, ':'); php_json_pretty_print_char(buf, options, ' '); } if (php_json_encode_zval(buf, data, options, encoder) == FAILURE && !(options & PHP_JSON_PARTIAL_OUTPUT_ON_ERROR)) { PHP_JSON_HASH_UNPROTECT_RECURSION(myht); zend_release_properties(prop_ht); return FAILURE; } } ZEND_HASH_FOREACH_END(); } PHP_JSON_HASH_UNPROTECT_RECURSION(myht); if (encoder->depth > encoder->max_depth) { encoder->error_code = PHP_JSON_ERROR_DEPTH; if (!(options & PHP_JSON_PARTIAL_OUTPUT_ON_ERROR)) { zend_release_properties(prop_ht); return FAILURE; } } --encoder->depth; /* Only keep closing bracket on same line for empty arrays/objects */ if (need_comma) { php_json_pretty_print_char(buf, options, '\n'); php_json_pretty_print_indent(buf, options, encoder); } if (r == PHP_JSON_OUTPUT_ARRAY) { smart_str_appendc(buf, ']'); } else { smart_str_appendc(buf, '}'); } zend_release_properties(prop_ht); return SUCCESS; } /* }}} */ zend_result php_json_escape_string( smart_str *buf, const char *s, size_t len, int options, php_json_encoder *encoder) /* {{{ */ { unsigned int us; size_t pos, checkpoint; char *dst; if (len == 0) { smart_str_appendl(buf, "\"\"", 2); return SUCCESS; } if (options & PHP_JSON_NUMERIC_CHECK) { double d; int type; zend_long p; if ((type = is_numeric_string(s, len, &p, &d, 0)) != 0) { if (type == IS_LONG) { smart_str_append_long(buf, p); return SUCCESS; } else if (type == IS_DOUBLE && php_json_is_valid_double(d)) { php_json_encode_double(buf, d, options); return SUCCESS; } } } checkpoint = buf->s ? ZSTR_LEN(buf->s) : 0; /* pre-allocate for string length plus 2 quotes */ smart_str_alloc(buf, len+2, 0); smart_str_appendc(buf, '"'); pos = 0; do { static const uint32_t charmap[8] = { 0xffffffff, 0x500080c4, 0x10000000, 0x00000000, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}; us = (unsigned char)s[pos]; if (EXPECTED(!ZEND_BIT_TEST(charmap, us))) { pos++; len--; if (len == 0) { smart_str_appendl(buf, s, pos); break; } } else { if (pos) { smart_str_appendl(buf, s, pos); s += pos; pos = 0; } us = (unsigned char)s[0]; if (UNEXPECTED(us >= 0x80)) { zend_result status; us = php_next_utf8_char((unsigned char *)s, len, &pos, &status); /* check whether UTF8 character is correct */ if (UNEXPECTED(status != SUCCESS)) { if (options & PHP_JSON_INVALID_UTF8_IGNORE) { /* ignore invalid UTF8 character */ } else if (options & PHP_JSON_INVALID_UTF8_SUBSTITUTE) { /* Use Unicode character 'REPLACEMENT CHARACTER' (U+FFFD) */ if (options & PHP_JSON_UNESCAPED_UNICODE) { smart_str_appendl(buf, "\xef\xbf\xbd", 3); } else { smart_str_appendl(buf, "\\ufffd", 6); } } else { ZSTR_LEN(buf->s) = checkpoint; encoder->error_code = PHP_JSON_ERROR_UTF8; if (options & PHP_JSON_PARTIAL_OUTPUT_ON_ERROR) { smart_str_appendl(buf, "null", 4); } return FAILURE; } /* Escape U+2028/U+2029 line terminators, UNLESS both JSON_UNESCAPED_UNICODE and JSON_UNESCAPED_LINE_TERMINATORS were provided */ } else if ((options & PHP_JSON_UNESCAPED_UNICODE) && ((options & PHP_JSON_UNESCAPED_LINE_TERMINATORS) || us < 0x2028 || us > 0x2029)) { smart_str_appendl(buf, s, pos); } else { /* From http://en.wikipedia.org/wiki/UTF16 */ if (us >= 0x10000) { unsigned int next_us; us -= 0x10000; next_us = (unsigned short)((us & 0x3ff) | 0xdc00); us = (unsigned short)((us >> 10) | 0xd800); dst = smart_str_extend(buf, 6); dst[0] = '\\'; dst[1] = 'u'; dst[2] = digits[(us >> 12) & 0xf]; dst[3] = digits[(us >> 8) & 0xf]; dst[4] = digits[(us >> 4) & 0xf]; dst[5] = digits[us & 0xf]; us = next_us; } dst = smart_str_extend(buf, 6); dst[0] = '\\'; dst[1] = 'u'; dst[2] = digits[(us >> 12) & 0xf]; dst[3] = digits[(us >> 8) & 0xf]; dst[4] = digits[(us >> 4) & 0xf]; dst[5] = digits[us & 0xf]; } s += pos; len -= pos; pos = 0; } else { s++; switch (us) { case '"': if (options & PHP_JSON_HEX_QUOT) { smart_str_appendl(buf, "\\u0022", 6); } else { smart_str_appendl(buf, "\\\"", 2); } break; case '\\': smart_str_appendl(buf, "\\\\", 2); break; case '/': if (options & PHP_JSON_UNESCAPED_SLASHES) { smart_str_appendc(buf, '/'); } else { smart_str_appendl(buf, "\\/", 2); } break; case '\b': smart_str_appendl(buf, "\\b", 2); break; case '\f': smart_str_appendl(buf, "\\f", 2); break; case '\n': smart_str_appendl(buf, "\\n", 2); break; case '\r': smart_str_appendl(buf, "\\r", 2); break; case '\t': smart_str_appendl(buf, "\\t", 2); break; case '<': if (options & PHP_JSON_HEX_TAG) { smart_str_appendl(buf, "\\u003C", 6); } else { smart_str_appendc(buf, '<'); } break; case '>': if (options & PHP_JSON_HEX_TAG) { smart_str_appendl(buf, "\\u003E", 6); } else { smart_str_appendc(buf, '>'); } break; case '&': if (options & PHP_JSON_HEX_AMP) { smart_str_appendl(buf, "\\u0026", 6); } else { smart_str_appendc(buf, '&'); } break; case '\'': if (options & PHP_JSON_HEX_APOS) { smart_str_appendl(buf, "\\u0027", 6); } else { smart_str_appendc(buf, '\''); } break; default: ZEND_ASSERT(us < ' '); dst = smart_str_extend(buf, 6); dst[0] = '\\'; dst[1] = 'u'; dst[2] = '0'; dst[3] = '0'; dst[4] = digits[(us >> 4) & 0xf]; dst[5] = digits[us & 0xf]; break; } len--; } } } while (len); smart_str_appendc(buf, '"'); return SUCCESS; } /* }}} */ static zend_result php_json_encode_serializable_object(smart_str *buf, zval *val, int options, php_json_encoder *encoder) /* {{{ */ { zend_class_entry *ce = Z_OBJCE_P(val); HashTable* myht = Z_OBJPROP_P(val); zval retval, fname; zend_result return_code; if (myht && GC_IS_RECURSIVE(myht)) { encoder->error_code = PHP_JSON_ERROR_RECURSION; if (options & PHP_JSON_PARTIAL_OUTPUT_ON_ERROR) { smart_str_appendl(buf, "null", 4); } return FAILURE; } PHP_JSON_HASH_PROTECT_RECURSION(myht); ZVAL_STRING(&fname, "jsonSerialize"); if (FAILURE == call_user_function(NULL, val, &fname, &retval, 0, NULL) || Z_TYPE(retval) == IS_UNDEF) { if (!EG(exception)) { zend_throw_exception_ex(NULL, 0, "Failed calling %s::jsonSerialize()", ZSTR_VAL(ce->name)); } zval_ptr_dtor(&fname); if (options & PHP_JSON_PARTIAL_OUTPUT_ON_ERROR) { smart_str_appendl(buf, "null", 4); } PHP_JSON_HASH_UNPROTECT_RECURSION(myht); return FAILURE; } if (EG(exception)) { /* Error already raised */ zval_ptr_dtor(&retval); zval_ptr_dtor(&fname); if (options & PHP_JSON_PARTIAL_OUTPUT_ON_ERROR) { smart_str_appendl(buf, "null", 4); } PHP_JSON_HASH_UNPROTECT_RECURSION(myht); return FAILURE; } if ((Z_TYPE(retval) == IS_OBJECT) && (Z_OBJ(retval) == Z_OBJ_P(val))) { /* Handle the case where jsonSerialize does: return $this; by going straight to encode array */ PHP_JSON_HASH_UNPROTECT_RECURSION(myht); return_code = php_json_encode_array(buf, &retval, options, encoder); } else { /* All other types, encode as normal */ return_code = php_json_encode_zval(buf, &retval, options, encoder); PHP_JSON_HASH_UNPROTECT_RECURSION(myht); } zval_ptr_dtor(&retval); zval_ptr_dtor(&fname); return return_code; } /* }}} */ static zend_result php_json_encode_serializable_enum(smart_str *buf, zval *val, int options, php_json_encoder *encoder) { zend_class_entry *ce = Z_OBJCE_P(val); if (ce->enum_backing_type == IS_UNDEF) { encoder->error_code = PHP_JSON_ERROR_NON_BACKED_ENUM; smart_str_appendc(buf, '0'); return FAILURE; } zval *value_zv = zend_enum_fetch_case_value(Z_OBJ_P(val)); return php_json_encode_zval(buf, value_zv, options, encoder); } zend_result php_json_encode_zval(smart_str *buf, zval *val, int options, php_json_encoder *encoder) /* {{{ */ { again: switch (Z_TYPE_P(val)) { case IS_NULL: smart_str_appendl(buf, "null", 4); break; case IS_TRUE: smart_str_appendl(buf, "true", 4); break; case IS_FALSE: smart_str_appendl(buf, "false", 5); break; case IS_LONG: smart_str_append_long(buf, Z_LVAL_P(val)); break; case IS_DOUBLE: if (php_json_is_valid_double(Z_DVAL_P(val))) { php_json_encode_double(buf, Z_DVAL_P(val), options); } else { encoder->error_code = PHP_JSON_ERROR_INF_OR_NAN; smart_str_appendc(buf, '0'); } break; case IS_STRING: return php_json_escape_string(buf, Z_STRVAL_P(val), Z_STRLEN_P(val), options, encoder); case IS_OBJECT: if (instanceof_function(Z_OBJCE_P(val), php_json_serializable_ce)) { return php_json_encode_serializable_object(buf, val, options, encoder); } if (Z_OBJCE_P(val)->ce_flags & ZEND_ACC_ENUM) { return php_json_encode_serializable_enum(buf, val, options, encoder); } /* fallthrough -- Non-serializable object */ ZEND_FALLTHROUGH; case IS_ARRAY: { /* Avoid modifications (and potential freeing) of the array through a reference when a * jsonSerialize() method is invoked. */ zval zv; int res; ZVAL_COPY(&zv, val); res = php_json_encode_array(buf, &zv, options, encoder); zval_ptr_dtor_nogc(&zv); return res; } case IS_REFERENCE: val = Z_REFVAL_P(val); goto again; default: encoder->error_code = PHP_JSON_ERROR_UNSUPPORTED_TYPE; if (options & PHP_JSON_PARTIAL_OUTPUT_ON_ERROR) { smart_str_appendl(buf, "null", 4); } return FAILURE; } return SUCCESS; } /* }}} */
17,650
25.22734
131
c
php-src
php-src-master/ext/json/php_json.h
/* +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Omar Kilani <[email protected]> | | Jakub Zelenka <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef PHP_JSON_H #define PHP_JSON_H #include "php_version.h" #include "zend_smart_str_public.h" #define PHP_JSON_VERSION PHP_VERSION extern zend_module_entry json_module_entry; #define phpext_json_ptr &json_module_entry #if defined(PHP_WIN32) && defined(JSON_EXPORTS) #define PHP_JSON_API __declspec(dllexport) #else #define PHP_JSON_API PHPAPI #endif #ifdef ZTS #include "TSRM.h" #endif extern PHP_JSON_API zend_class_entry *php_json_serializable_ce; /* error codes */ typedef enum { PHP_JSON_ERROR_NONE = 0, PHP_JSON_ERROR_DEPTH, PHP_JSON_ERROR_STATE_MISMATCH, PHP_JSON_ERROR_CTRL_CHAR, PHP_JSON_ERROR_SYNTAX, PHP_JSON_ERROR_UTF8, PHP_JSON_ERROR_RECURSION, PHP_JSON_ERROR_INF_OR_NAN, PHP_JSON_ERROR_UNSUPPORTED_TYPE, PHP_JSON_ERROR_INVALID_PROPERTY_NAME, PHP_JSON_ERROR_UTF16, PHP_JSON_ERROR_NON_BACKED_ENUM, } php_json_error_code; /* json_decode() options */ #define PHP_JSON_OBJECT_AS_ARRAY (1<<0) #define PHP_JSON_BIGINT_AS_STRING (1<<1) /* json_encode() options */ #define PHP_JSON_HEX_TAG (1<<0) #define PHP_JSON_HEX_AMP (1<<1) #define PHP_JSON_HEX_APOS (1<<2) #define PHP_JSON_HEX_QUOT (1<<3) #define PHP_JSON_FORCE_OBJECT (1<<4) #define PHP_JSON_NUMERIC_CHECK (1<<5) #define PHP_JSON_UNESCAPED_SLASHES (1<<6) #define PHP_JSON_PRETTY_PRINT (1<<7) #define PHP_JSON_UNESCAPED_UNICODE (1<<8) #define PHP_JSON_PARTIAL_OUTPUT_ON_ERROR (1<<9) #define PHP_JSON_PRESERVE_ZERO_FRACTION (1<<10) #define PHP_JSON_UNESCAPED_LINE_TERMINATORS (1<<11) /* json_validate(), json_decode() and json_encode() common options */ #define PHP_JSON_INVALID_UTF8_IGNORE (1<<20) /* json_decode() and json_encode() common options */ #define PHP_JSON_INVALID_UTF8_SUBSTITUTE (1<<21) #define PHP_JSON_THROW_ON_ERROR (1<<22) /* Internal flags */ #define PHP_JSON_OUTPUT_ARRAY 0 #define PHP_JSON_OUTPUT_OBJECT 1 /* default depth */ #define PHP_JSON_PARSER_DEFAULT_DEPTH 512 ZEND_BEGIN_MODULE_GLOBALS(json) int encoder_depth; int encode_max_depth; php_json_error_code error_code; ZEND_END_MODULE_GLOBALS(json) PHP_JSON_API ZEND_EXTERN_MODULE_GLOBALS(json) #define JSON_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(json, v) #if defined(ZTS) && defined(COMPILE_DL_JSON) ZEND_TSRMLS_CACHE_EXTERN() #endif PHP_JSON_API zend_string *php_json_encode_string(const char *s, size_t len, int options); PHP_JSON_API zend_result php_json_encode_ex(smart_str *buf, zval *val, int options, zend_long depth); PHP_JSON_API zend_result php_json_encode(smart_str *buf, zval *val, int options); PHP_JSON_API zend_result php_json_decode_ex(zval *return_value, const char *str, size_t str_len, zend_long options, zend_long depth); PHP_JSON_API bool php_json_validate_ex(const char *str, size_t str_len, zend_long options, zend_long depth); static inline zend_result php_json_decode(zval *return_value, const char *str, size_t str_len, bool assoc, zend_long depth) { return php_json_decode_ex(return_value, str, str_len, assoc ? PHP_JSON_OBJECT_AS_ARRAY : 0, depth); } #endif /* PHP_JSON_H */
4,214
35.652174
133
h
php-src
php-src-master/ext/json/php_json_encoder.h
/* +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Jakub Zelenka <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef PHP_JSON_ENCODER_H #define PHP_JSON_ENCODER_H #include "php.h" #include "zend_smart_str.h" typedef struct _php_json_encoder php_json_encoder; struct _php_json_encoder { int depth; int max_depth; php_json_error_code error_code; }; static inline void php_json_encode_init(php_json_encoder *encoder) { memset(encoder, 0, sizeof(php_json_encoder)); } zend_result php_json_encode_zval(smart_str *buf, zval *val, int options, php_json_encoder *encoder); zend_result php_json_escape_string(smart_str *buf, const char *s, size_t len, int options, php_json_encoder *encoder); #endif /* PHP_JSON_ENCODER_H */
1,600
38.04878
118
h
php-src
php-src-master/ext/json/php_json_parser.h
/* +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Jakub Zelenka <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef PHP_JSON_PARSER_H #define PHP_JSON_PARSER_H #include "php.h" #include "php_json_scanner.h" typedef struct _php_json_parser php_json_parser; typedef int (*php_json_parser_func_array_create_t)( php_json_parser *parser, zval *array); typedef int (*php_json_parser_func_array_append_t)( php_json_parser *parser, zval *array, zval *zvalue); typedef int (*php_json_parser_func_array_start_t)( php_json_parser *parser); typedef int (*php_json_parser_func_array_end_t)( php_json_parser *parser, zval *object); typedef int (*php_json_parser_func_object_create_t)( php_json_parser *parser, zval *object); typedef int (*php_json_parser_func_object_update_t)( php_json_parser *parser, zval *object, zend_string *key, zval *zvalue); typedef int (*php_json_parser_func_object_start_t)( php_json_parser *parser); typedef int (*php_json_parser_func_object_end_t)( php_json_parser *parser, zval *object); typedef struct _php_json_parser_methods { php_json_parser_func_array_create_t array_create; php_json_parser_func_array_append_t array_append; php_json_parser_func_array_start_t array_start; php_json_parser_func_array_end_t array_end; php_json_parser_func_object_create_t object_create; php_json_parser_func_object_update_t object_update; php_json_parser_func_object_start_t object_start; php_json_parser_func_object_end_t object_end; } php_json_parser_methods; struct _php_json_parser { php_json_scanner scanner; zval *return_value; int depth; int max_depth; php_json_parser_methods methods; }; PHP_JSON_API void php_json_parser_init_ex( php_json_parser *parser, zval *return_value, const char *str, size_t str_len, int options, int max_depth, const php_json_parser_methods *methods); PHP_JSON_API void php_json_parser_init( php_json_parser *parser, zval *return_value, const char *str, size_t str_len, int options, int max_depth); PHP_JSON_API php_json_error_code php_json_parser_error_code(const php_json_parser *parser); PHP_JSON_API int php_json_parse(php_json_parser *parser); int php_json_yyparse(php_json_parser *parser); const php_json_parser_methods* php_json_get_validate_methods(void); #endif /* PHP_JSON_PARSER_H */
3,173
35.482759
91
h
php-src
php-src-master/ext/json/php_json_scanner.h
/* +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Jakub Zelenka <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef PHP_JSON_SCANNER_H #define PHP_JSON_SCANNER_H #include "php.h" #include "php_json.h" typedef unsigned char php_json_ctype; typedef struct _php_json_scanner { php_json_ctype *cursor; /* cursor position */ php_json_ctype *token; /* token position */ php_json_ctype *limit; /* the last read character + 1 position */ php_json_ctype *marker; /* marker position for backtracking */ php_json_ctype *ctxmarker; /* marker position for context backtracking */ php_json_ctype *str_start; /* start position of the string */ php_json_ctype *pstr; /* string pointer for escapes conversion */ zval value; /* value */ int str_esc; /* number of extra characters for escaping */ int state; /* condition state */ int options; /* options */ php_json_error_code errcode; /* error type if there is an error */ int utf8_invalid; /* whether utf8 is invalid */ int utf8_invalid_count; /* number of extra character for invalid utf8 */ } php_json_scanner; void php_json_scanner_init(php_json_scanner *scanner, const char *str, size_t str_len, int options); int php_json_scan(php_json_scanner *s); #endif /* PHP_JSON_SCANNER_H */
2,271
47.340426
100
h
php-src
php-src-master/ext/ldap/php_ldap.h
/* +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Amitay Isaacs <[email protected]> | | Eric Warnke <[email protected]> | | Jani Taskinen <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef PHP_LDAP_H #define PHP_LDAP_H #ifndef HAVE_ORALDAP #include <lber.h> #endif #include <ldap.h> extern zend_module_entry ldap_module_entry; #define ldap_module_ptr &ldap_module_entry #include "php_version.h" #define PHP_LDAP_VERSION PHP_VERSION /* LDAP functions */ PHP_MINIT_FUNCTION(ldap); PHP_MSHUTDOWN_FUNCTION(ldap); PHP_MINFO_FUNCTION(ldap); ZEND_BEGIN_MODULE_GLOBALS(ldap) zend_long num_links; zend_long max_links; ZEND_END_MODULE_GLOBALS(ldap) #if defined(ZTS) && defined(COMPILE_DL_LDAP) ZEND_TSRMLS_CACHE_EXTERN() #endif ZEND_EXTERN_MODULE_GLOBALS(ldap) #define LDAPG(v) ZEND_MODULE_GLOBALS_ACCESSOR(ldap, v) #define phpext_ldap_ptr ldap_module_ptr /* Constants for ldap_modify_batch */ #define LDAP_MODIFY_BATCH_ADD 0x01 #define LDAP_MODIFY_BATCH_REMOVE 0x02 #define LDAP_MODIFY_BATCH_REMOVE_ALL 0x12 #define LDAP_MODIFY_BATCH_REPLACE 0x03 #define LDAP_MODIFY_BATCH_ATTRIB "attrib" #define LDAP_MODIFY_BATCH_MODTYPE "modtype" #define LDAP_MODIFY_BATCH_VALUES "values" #endif /* PHP_LDAP_H */
2,195
33.3125
75
h
php-src
php-src-master/ext/libxml/php_libxml.h
/* +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Shane Caraveo <[email protected]> | | Wez Furlong <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef PHP_LIBXML_H #define PHP_LIBXML_H #ifdef HAVE_LIBXML extern zend_module_entry libxml_module_entry; #define libxml_module_ptr &libxml_module_entry #include "php_version.h" #define PHP_LIBXML_VERSION PHP_VERSION #ifdef PHP_WIN32 # define PHP_LIBXML_API __declspec(dllexport) #elif defined(__GNUC__) && __GNUC__ >= 4 # define PHP_LIBXML_API __attribute__ ((visibility("default"))) #else # define PHP_LIBXML_API #endif #include "zend_smart_str.h" #include <libxml/tree.h> #define LIBXML_SAVE_NOEMPTYTAG 1<<2 ZEND_BEGIN_MODULE_GLOBALS(libxml) zval stream_context; smart_str error_buffer; zend_llist *error_list; zend_fcall_info_cache entity_loader_callback; bool entity_loader_disabled; ZEND_END_MODULE_GLOBALS(libxml) typedef struct _libxml_doc_props { HashTable *classmap; bool formatoutput; bool validateonparse; bool resolveexternals; bool preservewhitespace; bool substituteentities; bool stricterror; bool recover; } libxml_doc_props; typedef struct _php_libxml_ref_obj { void *ptr; int refcount; libxml_doc_props *doc_props; } php_libxml_ref_obj; typedef struct _php_libxml_node_ptr { xmlNodePtr node; int refcount; void *_private; } php_libxml_node_ptr; typedef struct { size_t modification_nr; } php_libxml_cache_tag; /* extends php_libxml_node_ptr */ typedef struct { php_libxml_node_ptr node_ptr; php_libxml_cache_tag cache_tag; } php_libxml_doc_ptr; typedef struct _php_libxml_node_object { php_libxml_node_ptr *node; php_libxml_ref_obj *document; HashTable *properties; zend_object std; } php_libxml_node_object; static inline php_libxml_node_object *php_libxml_node_fetch_object(zend_object *obj) { return (php_libxml_node_object *)((char*)(obj) - obj->handlers->offset); } static zend_always_inline void php_libxml_invalidate_node_list_cache(php_libxml_doc_ptr *doc_ptr) { #if SIZEOF_SIZE_T == 8 /* If one operation happens every nanosecond, then it would still require 584 years to overflow * the counter. So we'll just assume this never happens. */ doc_ptr->cache_tag.modification_nr++; #else size_t new_modification_nr = doc_ptr->cache_tag.modification_nr + 1; if (EXPECTED(new_modification_nr > 0)) { /* unsigned overflow; checking after addition results in one less instruction */ doc_ptr->cache_tag.modification_nr = new_modification_nr; } #endif } static zend_always_inline void php_libxml_invalidate_node_list_cache_from_doc(xmlDocPtr docp) { if (docp && docp->_private) { /* docp is NULL for detached nodes */ php_libxml_invalidate_node_list_cache(docp->_private); } } #define Z_LIBXML_NODE_P(zv) php_libxml_node_fetch_object(Z_OBJ_P((zv))) typedef void * (*php_libxml_export_node) (zval *object); PHP_LIBXML_API int php_libxml_increment_node_ptr(php_libxml_node_object *object, xmlNodePtr node, void *private_data); PHP_LIBXML_API int php_libxml_decrement_node_ptr(php_libxml_node_object *object); PHP_LIBXML_API int php_libxml_increment_doc_ref(php_libxml_node_object *object, xmlDocPtr docp); PHP_LIBXML_API int php_libxml_decrement_doc_ref(php_libxml_node_object *object); PHP_LIBXML_API xmlNodePtr php_libxml_import_node(zval *object); PHP_LIBXML_API zval *php_libxml_register_export(zend_class_entry *ce, php_libxml_export_node export_function); /* When an explicit freeing of node and children is required */ PHP_LIBXML_API void php_libxml_node_free_list(xmlNodePtr node); PHP_LIBXML_API void php_libxml_node_free_resource(xmlNodePtr node); /* When object dtor is called as node may still be referenced */ PHP_LIBXML_API void php_libxml_node_decrement_resource(php_libxml_node_object *object); PHP_LIBXML_API void php_libxml_error_handler(void *ctx, const char *msg, ...); PHP_LIBXML_API void php_libxml_ctx_warning(void *ctx, const char *msg, ...); PHP_LIBXML_API void php_libxml_ctx_error(void *ctx, const char *msg, ...); PHP_LIBXML_API int php_libxml_xmlCheckUTF8(const unsigned char *s); PHP_LIBXML_API void php_libxml_switch_context(zval *context, zval *oldcontext); PHP_LIBXML_API void php_libxml_issue_error(int level, const char *msg); PHP_LIBXML_API bool php_libxml_disable_entity_loader(bool disable); /* Init/shutdown functions*/ PHP_LIBXML_API void php_libxml_initialize(void); PHP_LIBXML_API void php_libxml_shutdown(void); #define LIBXML(v) ZEND_MODULE_GLOBALS_ACCESSOR(libxml, v) #if defined(ZTS) && defined(COMPILE_DL_LIBXML) ZEND_TSRMLS_CACHE_EXTERN() #endif #else /* HAVE_LIBXML */ #define libxml_module_ptr NULL #endif #define phpext_libxml_ptr libxml_module_ptr #endif /* PHP_LIBXML_H */
5,582
35.019355
122
h
php-src
php-src-master/ext/mbstring/mb_gpc.h
/* +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Rui Hirokawa <[email protected]> | | Moriyoshi Koizumi <[email protected]> | +----------------------------------------------------------------------+ */ /* {{{ includes */ #include "php.h" /* }}} */ /* {{{ typedefs */ typedef struct _php_mb_encoding_handler_info_t { const char *separator; const mbfl_encoding *to_encoding; const mbfl_encoding **from_encodings; size_t num_from_encodings; int data_type; bool report_errors; } php_mb_encoding_handler_info_t; /* }}}*/ /* {{{ prototypes */ SAPI_POST_HANDLER_FUNC(php_mb_post_handler); MBSTRING_API SAPI_TREAT_DATA_FUNC(mbstr_treat_data); int _php_mb_enable_encoding_translation(int flag); const mbfl_encoding *_php_mb_encoding_handler_ex(const php_mb_encoding_handler_info_t *info, zval *arg, char *res); /* }}} */
1,692
40.292683
115
h
php-src
php-src-master/ext/mbstring/mbstring_arginfo.h
/* This is a generated file, edit the .stub.php file instead. * Stub hash: 141073d610f862b525406fb7f48ac58b6691080e */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_language, 0, 0, MAY_BE_STRING|MAY_BE_BOOL) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, language, IS_STRING, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_internal_encoding, 0, 0, MAY_BE_STRING|MAY_BE_BOOL) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_STRING, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_http_input, 0, 0, MAY_BE_ARRAY|MAY_BE_STRING|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, type, IS_STRING, 1, "null") ZEND_END_ARG_INFO() #define arginfo_mb_http_output arginfo_mb_internal_encoding ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_detect_order, 0, 0, MAY_BE_ARRAY|MAY_BE_BOOL) ZEND_ARG_TYPE_MASK(0, encoding, MAY_BE_ARRAY|MAY_BE_STRING|MAY_BE_NULL, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_substitute_character, 0, 0, MAY_BE_STRING|MAY_BE_LONG|MAY_BE_BOOL) ZEND_ARG_TYPE_MASK(0, substitute_character, MAY_BE_STRING|MAY_BE_LONG|MAY_BE_NULL, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_preferred_mime_name, 0, 1, MAY_BE_STRING|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, encoding, IS_STRING, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mb_parse_str, 0, 2, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) ZEND_ARG_INFO(1, result) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mb_output_handler, 0, 2, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, status, IS_LONG, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mb_str_split, 0, 1, IS_ARRAY, 0) ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, length, IS_LONG, 0, "1") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_STRING, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mb_strlen, 0, 1, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_STRING, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_strpos, 0, 2, MAY_BE_LONG|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, haystack, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, needle, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, offset, IS_LONG, 0, "0") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_STRING, 1, "null") ZEND_END_ARG_INFO() #define arginfo_mb_strrpos arginfo_mb_strpos #define arginfo_mb_stripos arginfo_mb_strpos #define arginfo_mb_strripos arginfo_mb_strpos ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_strstr, 0, 2, MAY_BE_STRING|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, haystack, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, needle, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, before_needle, _IS_BOOL, 0, "false") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_STRING, 1, "null") ZEND_END_ARG_INFO() #define arginfo_mb_strrchr arginfo_mb_strstr #define arginfo_mb_stristr arginfo_mb_strstr #define arginfo_mb_strrichr arginfo_mb_strstr ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mb_substr_count, 0, 2, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, haystack, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, needle, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_STRING, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mb_substr, 0, 2, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, start, IS_LONG, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, length, IS_LONG, 1, "null") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_STRING, 1, "null") ZEND_END_ARG_INFO() #define arginfo_mb_strcut arginfo_mb_substr #define arginfo_mb_strwidth arginfo_mb_strlen ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mb_strimwidth, 0, 3, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, start, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, width, IS_LONG, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, trim_marker, IS_STRING, 0, "\"\"") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_STRING, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_convert_encoding, 0, 2, MAY_BE_ARRAY|MAY_BE_STRING|MAY_BE_FALSE) ZEND_ARG_TYPE_MASK(0, string, MAY_BE_ARRAY|MAY_BE_STRING, NULL) ZEND_ARG_TYPE_INFO(0, to_encoding, IS_STRING, 0) ZEND_ARG_TYPE_MASK(0, from_encoding, MAY_BE_ARRAY|MAY_BE_STRING|MAY_BE_NULL, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mb_convert_case, 0, 2, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, mode, IS_LONG, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_STRING, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mb_strtoupper, 0, 1, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_STRING, 1, "null") ZEND_END_ARG_INFO() #define arginfo_mb_strtolower arginfo_mb_strtoupper ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_detect_encoding, 0, 1, MAY_BE_STRING|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) ZEND_ARG_TYPE_MASK(0, encodings, MAY_BE_ARRAY|MAY_BE_STRING|MAY_BE_NULL, "null") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, strict, _IS_BOOL, 0, "false") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mb_list_encodings, 0, 0, IS_ARRAY, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mb_encoding_aliases, 0, 1, IS_ARRAY, 0) ZEND_ARG_TYPE_INFO(0, encoding, IS_STRING, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mb_encode_mimeheader, 0, 1, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, charset, IS_STRING, 1, "null") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, transfer_encoding, IS_STRING, 1, "null") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, newline, IS_STRING, 0, "\"\\r\\n\"") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, indent, IS_LONG, 0, "0") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mb_decode_mimeheader, 0, 1, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mb_convert_kana, 0, 1, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mode, IS_STRING, 0, "\"KV\"") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_STRING, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_convert_variables, 0, 3, MAY_BE_STRING|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, to_encoding, IS_STRING, 0) ZEND_ARG_TYPE_MASK(0, from_encoding, MAY_BE_ARRAY|MAY_BE_STRING, NULL) ZEND_ARG_TYPE_INFO(1, var, IS_MIXED, 0) ZEND_ARG_VARIADIC_TYPE_INFO(1, vars, IS_MIXED, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mb_encode_numericentity, 0, 2, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, map, IS_ARRAY, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_STRING, 1, "null") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, hex, _IS_BOOL, 0, "false") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mb_decode_numericentity, 0, 2, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, map, IS_ARRAY, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_STRING, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mb_send_mail, 0, 3, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, to, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, subject, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0) ZEND_ARG_TYPE_MASK(0, additional_headers, MAY_BE_ARRAY|MAY_BE_STRING, "[]") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, additional_params, IS_STRING, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_get_info, 0, 0, MAY_BE_ARRAY|MAY_BE_STRING|MAY_BE_LONG|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, type, IS_STRING, 0, "\"all\"") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mb_check_encoding, 0, 0, _IS_BOOL, 0) ZEND_ARG_TYPE_MASK(0, value, MAY_BE_ARRAY|MAY_BE_STRING|MAY_BE_NULL, "null") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_STRING, 1, "null") ZEND_END_ARG_INFO() #define arginfo_mb_scrub arginfo_mb_strtoupper ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_ord, 0, 1, MAY_BE_LONG|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_STRING, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_chr, 0, 1, MAY_BE_STRING|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, codepoint, IS_LONG, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_STRING, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mb_str_pad, 0, 2, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, length, IS_LONG, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, pad_string, IS_STRING, 0, "\" \"") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, pad_type, IS_LONG, 0, "STR_PAD_RIGHT") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_STRING, 1, "null") ZEND_END_ARG_INFO() #if defined(HAVE_MBREGEX) ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_regex_encoding, 0, 0, MAY_BE_STRING|MAY_BE_BOOL) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_STRING, 1, "null") ZEND_END_ARG_INFO() #endif #if defined(HAVE_MBREGEX) ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mb_ereg, 0, 2, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, pattern, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) ZEND_ARG_INFO_WITH_DEFAULT_VALUE(1, matches, "null") ZEND_END_ARG_INFO() #endif #if defined(HAVE_MBREGEX) #define arginfo_mb_eregi arginfo_mb_ereg #endif #if defined(HAVE_MBREGEX) ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_ereg_replace, 0, 3, MAY_BE_STRING|MAY_BE_FALSE|MAY_BE_NULL) ZEND_ARG_TYPE_INFO(0, pattern, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, replacement, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_STRING, 1, "null") ZEND_END_ARG_INFO() #endif #if defined(HAVE_MBREGEX) #define arginfo_mb_eregi_replace arginfo_mb_ereg_replace #endif #if defined(HAVE_MBREGEX) ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_ereg_replace_callback, 0, 3, MAY_BE_STRING|MAY_BE_FALSE|MAY_BE_NULL) ZEND_ARG_TYPE_INFO(0, pattern, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, callback, IS_CALLABLE, 0) ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_STRING, 1, "null") ZEND_END_ARG_INFO() #endif #if defined(HAVE_MBREGEX) ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_split, 0, 2, MAY_BE_ARRAY|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, pattern, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, limit, IS_LONG, 0, "-1") ZEND_END_ARG_INFO() #endif #if defined(HAVE_MBREGEX) ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mb_ereg_match, 0, 2, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, pattern, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_STRING, 1, "null") ZEND_END_ARG_INFO() #endif #if defined(HAVE_MBREGEX) ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mb_ereg_search, 0, 0, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, pattern, IS_STRING, 1, "null") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_STRING, 1, "null") ZEND_END_ARG_INFO() #endif #if defined(HAVE_MBREGEX) ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_ereg_search_pos, 0, 0, MAY_BE_ARRAY|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, pattern, IS_STRING, 1, "null") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_STRING, 1, "null") ZEND_END_ARG_INFO() #endif #if defined(HAVE_MBREGEX) #define arginfo_mb_ereg_search_regs arginfo_mb_ereg_search_pos #endif #if defined(HAVE_MBREGEX) ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mb_ereg_search_init, 0, 1, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, pattern, IS_STRING, 1, "null") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_STRING, 1, "null") ZEND_END_ARG_INFO() #endif #if defined(HAVE_MBREGEX) ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_ereg_search_getregs, 0, 0, MAY_BE_ARRAY|MAY_BE_FALSE) ZEND_END_ARG_INFO() #endif #if defined(HAVE_MBREGEX) ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mb_ereg_search_getpos, 0, 0, IS_LONG, 0) ZEND_END_ARG_INFO() #endif #if defined(HAVE_MBREGEX) ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mb_ereg_search_setpos, 0, 1, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, offset, IS_LONG, 0) ZEND_END_ARG_INFO() #endif #if defined(HAVE_MBREGEX) ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mb_regex_set_options, 0, 0, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_STRING, 1, "null") ZEND_END_ARG_INFO() #endif ZEND_FUNCTION(mb_language); ZEND_FUNCTION(mb_internal_encoding); ZEND_FUNCTION(mb_http_input); ZEND_FUNCTION(mb_http_output); ZEND_FUNCTION(mb_detect_order); ZEND_FUNCTION(mb_substitute_character); ZEND_FUNCTION(mb_preferred_mime_name); ZEND_FUNCTION(mb_parse_str); ZEND_FUNCTION(mb_output_handler); ZEND_FUNCTION(mb_str_split); ZEND_FUNCTION(mb_strlen); ZEND_FUNCTION(mb_strpos); ZEND_FUNCTION(mb_strrpos); ZEND_FUNCTION(mb_stripos); ZEND_FUNCTION(mb_strripos); ZEND_FUNCTION(mb_strstr); ZEND_FUNCTION(mb_strrchr); ZEND_FUNCTION(mb_stristr); ZEND_FUNCTION(mb_strrichr); ZEND_FUNCTION(mb_substr_count); ZEND_FUNCTION(mb_substr); ZEND_FUNCTION(mb_strcut); ZEND_FUNCTION(mb_strwidth); ZEND_FUNCTION(mb_strimwidth); ZEND_FUNCTION(mb_convert_encoding); ZEND_FUNCTION(mb_convert_case); ZEND_FUNCTION(mb_strtoupper); ZEND_FUNCTION(mb_strtolower); ZEND_FUNCTION(mb_detect_encoding); ZEND_FUNCTION(mb_list_encodings); ZEND_FUNCTION(mb_encoding_aliases); ZEND_FUNCTION(mb_encode_mimeheader); ZEND_FUNCTION(mb_decode_mimeheader); ZEND_FUNCTION(mb_convert_kana); ZEND_FUNCTION(mb_convert_variables); ZEND_FUNCTION(mb_encode_numericentity); ZEND_FUNCTION(mb_decode_numericentity); ZEND_FUNCTION(mb_send_mail); ZEND_FUNCTION(mb_get_info); ZEND_FUNCTION(mb_check_encoding); ZEND_FUNCTION(mb_scrub); ZEND_FUNCTION(mb_ord); ZEND_FUNCTION(mb_chr); ZEND_FUNCTION(mb_str_pad); #if defined(HAVE_MBREGEX) ZEND_FUNCTION(mb_regex_encoding); #endif #if defined(HAVE_MBREGEX) ZEND_FUNCTION(mb_ereg); #endif #if defined(HAVE_MBREGEX) ZEND_FUNCTION(mb_eregi); #endif #if defined(HAVE_MBREGEX) ZEND_FUNCTION(mb_ereg_replace); #endif #if defined(HAVE_MBREGEX) ZEND_FUNCTION(mb_eregi_replace); #endif #if defined(HAVE_MBREGEX) ZEND_FUNCTION(mb_ereg_replace_callback); #endif #if defined(HAVE_MBREGEX) ZEND_FUNCTION(mb_split); #endif #if defined(HAVE_MBREGEX) ZEND_FUNCTION(mb_ereg_match); #endif #if defined(HAVE_MBREGEX) ZEND_FUNCTION(mb_ereg_search); #endif #if defined(HAVE_MBREGEX) ZEND_FUNCTION(mb_ereg_search_pos); #endif #if defined(HAVE_MBREGEX) ZEND_FUNCTION(mb_ereg_search_regs); #endif #if defined(HAVE_MBREGEX) ZEND_FUNCTION(mb_ereg_search_init); #endif #if defined(HAVE_MBREGEX) ZEND_FUNCTION(mb_ereg_search_getregs); #endif #if defined(HAVE_MBREGEX) ZEND_FUNCTION(mb_ereg_search_getpos); #endif #if defined(HAVE_MBREGEX) ZEND_FUNCTION(mb_ereg_search_setpos); #endif #if defined(HAVE_MBREGEX) ZEND_FUNCTION(mb_regex_set_options); #endif static const zend_function_entry ext_functions[] = { ZEND_FE(mb_language, arginfo_mb_language) ZEND_FE(mb_internal_encoding, arginfo_mb_internal_encoding) ZEND_FE(mb_http_input, arginfo_mb_http_input) ZEND_FE(mb_http_output, arginfo_mb_http_output) ZEND_FE(mb_detect_order, arginfo_mb_detect_order) ZEND_FE(mb_substitute_character, arginfo_mb_substitute_character) ZEND_FE(mb_preferred_mime_name, arginfo_mb_preferred_mime_name) ZEND_FE(mb_parse_str, arginfo_mb_parse_str) ZEND_FE(mb_output_handler, arginfo_mb_output_handler) ZEND_FE(mb_str_split, arginfo_mb_str_split) ZEND_FE(mb_strlen, arginfo_mb_strlen) ZEND_FE(mb_strpos, arginfo_mb_strpos) ZEND_FE(mb_strrpos, arginfo_mb_strrpos) ZEND_FE(mb_stripos, arginfo_mb_stripos) ZEND_FE(mb_strripos, arginfo_mb_strripos) ZEND_FE(mb_strstr, arginfo_mb_strstr) ZEND_FE(mb_strrchr, arginfo_mb_strrchr) ZEND_FE(mb_stristr, arginfo_mb_stristr) ZEND_FE(mb_strrichr, arginfo_mb_strrichr) ZEND_FE(mb_substr_count, arginfo_mb_substr_count) ZEND_FE(mb_substr, arginfo_mb_substr) ZEND_FE(mb_strcut, arginfo_mb_strcut) ZEND_FE(mb_strwidth, arginfo_mb_strwidth) ZEND_FE(mb_strimwidth, arginfo_mb_strimwidth) ZEND_FE(mb_convert_encoding, arginfo_mb_convert_encoding) ZEND_FE(mb_convert_case, arginfo_mb_convert_case) ZEND_FE(mb_strtoupper, arginfo_mb_strtoupper) ZEND_FE(mb_strtolower, arginfo_mb_strtolower) ZEND_FE(mb_detect_encoding, arginfo_mb_detect_encoding) ZEND_FE(mb_list_encodings, arginfo_mb_list_encodings) ZEND_FE(mb_encoding_aliases, arginfo_mb_encoding_aliases) ZEND_FE(mb_encode_mimeheader, arginfo_mb_encode_mimeheader) ZEND_FE(mb_decode_mimeheader, arginfo_mb_decode_mimeheader) ZEND_FE(mb_convert_kana, arginfo_mb_convert_kana) ZEND_FE(mb_convert_variables, arginfo_mb_convert_variables) ZEND_FE(mb_encode_numericentity, arginfo_mb_encode_numericentity) ZEND_FE(mb_decode_numericentity, arginfo_mb_decode_numericentity) ZEND_FE(mb_send_mail, arginfo_mb_send_mail) ZEND_FE(mb_get_info, arginfo_mb_get_info) ZEND_FE(mb_check_encoding, arginfo_mb_check_encoding) ZEND_FE(mb_scrub, arginfo_mb_scrub) ZEND_FE(mb_ord, arginfo_mb_ord) ZEND_FE(mb_chr, arginfo_mb_chr) ZEND_FE(mb_str_pad, arginfo_mb_str_pad) #if defined(HAVE_MBREGEX) ZEND_FE(mb_regex_encoding, arginfo_mb_regex_encoding) #endif #if defined(HAVE_MBREGEX) ZEND_FE(mb_ereg, arginfo_mb_ereg) #endif #if defined(HAVE_MBREGEX) ZEND_FE(mb_eregi, arginfo_mb_eregi) #endif #if defined(HAVE_MBREGEX) ZEND_FE(mb_ereg_replace, arginfo_mb_ereg_replace) #endif #if defined(HAVE_MBREGEX) ZEND_FE(mb_eregi_replace, arginfo_mb_eregi_replace) #endif #if defined(HAVE_MBREGEX) ZEND_FE(mb_ereg_replace_callback, arginfo_mb_ereg_replace_callback) #endif #if defined(HAVE_MBREGEX) ZEND_FE(mb_split, arginfo_mb_split) #endif #if defined(HAVE_MBREGEX) ZEND_FE(mb_ereg_match, arginfo_mb_ereg_match) #endif #if defined(HAVE_MBREGEX) ZEND_FE(mb_ereg_search, arginfo_mb_ereg_search) #endif #if defined(HAVE_MBREGEX) ZEND_FE(mb_ereg_search_pos, arginfo_mb_ereg_search_pos) #endif #if defined(HAVE_MBREGEX) ZEND_FE(mb_ereg_search_regs, arginfo_mb_ereg_search_regs) #endif #if defined(HAVE_MBREGEX) ZEND_FE(mb_ereg_search_init, arginfo_mb_ereg_search_init) #endif #if defined(HAVE_MBREGEX) ZEND_FE(mb_ereg_search_getregs, arginfo_mb_ereg_search_getregs) #endif #if defined(HAVE_MBREGEX) ZEND_FE(mb_ereg_search_getpos, arginfo_mb_ereg_search_getpos) #endif #if defined(HAVE_MBREGEX) ZEND_FE(mb_ereg_search_setpos, arginfo_mb_ereg_search_setpos) #endif #if defined(HAVE_MBREGEX) ZEND_FE(mb_regex_set_options, arginfo_mb_regex_set_options) #endif ZEND_FE_END }; static void register_mbstring_symbols(int module_number) { #if defined(HAVE_MBREGEX) REGISTER_STRING_CONSTANT("MB_ONIGURUMA_VERSION", php_mb_oniguruma_version, CONST_PERSISTENT); #endif REGISTER_LONG_CONSTANT("MB_CASE_UPPER", PHP_UNICODE_CASE_UPPER, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("MB_CASE_LOWER", PHP_UNICODE_CASE_LOWER, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("MB_CASE_TITLE", PHP_UNICODE_CASE_TITLE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("MB_CASE_FOLD", PHP_UNICODE_CASE_FOLD, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("MB_CASE_UPPER_SIMPLE", PHP_UNICODE_CASE_UPPER_SIMPLE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("MB_CASE_LOWER_SIMPLE", PHP_UNICODE_CASE_LOWER_SIMPLE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("MB_CASE_TITLE_SIMPLE", PHP_UNICODE_CASE_TITLE_SIMPLE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("MB_CASE_FOLD_SIMPLE", PHP_UNICODE_CASE_FOLD_SIMPLE, CONST_PERSISTENT); }
20,131
37.864865
119
h
php-src
php-src-master/ext/mbstring/php_mbregex.h
/* +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Moriyoshi Koizumi <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef _PHP_MBREGEX_H #define _PHP_MBREGEX_H #ifdef HAVE_MBREGEX #include "php.h" #include "zend.h" #define PHP_MBREGEX_MAXCACHE 50 PHP_MINIT_FUNCTION(mb_regex); PHP_MSHUTDOWN_FUNCTION(mb_regex); PHP_RINIT_FUNCTION(mb_regex); PHP_RSHUTDOWN_FUNCTION(mb_regex); PHP_MINFO_FUNCTION(mb_regex); extern char php_mb_oniguruma_version[256]; typedef struct _zend_mb_regex_globals zend_mb_regex_globals; zend_mb_regex_globals *php_mb_regex_globals_alloc(void); void php_mb_regex_globals_free(zend_mb_regex_globals *pglobals); int php_mb_regex_set_mbctype(const char *enc); int php_mb_regex_set_default_mbctype(const char *encname); const char *php_mb_regex_get_mbctype(void); const char *php_mb_regex_get_default_mbctype(void); #endif /* HAVE_MBREGEX */ #endif /* _PHP_MBREGEX_H */
1,778
36.851064
75
h
php-src
php-src-master/ext/mbstring/php_unicode.h
/* +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Wez Furlong ([email protected]) | +----------------------------------------------------------------------+ Based on code from ucdata-2.5, which has the following Copyright: Copyright 2001 Computing Research Labs, New Mexico State University Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. */ #ifndef PHP_UNICODE_H #define PHP_UNICODE_H #define UC_MN 0 /* Mark, Non-Spacing */ #define UC_MC 1 /* Mark, Spacing Combining */ #define UC_ME 2 /* Mark, Enclosing */ #define UC_ND 3 /* Number, Decimal Digit */ #define UC_NL 4 /* Number, Letter */ #define UC_NO 5 /* Number, Other */ #define UC_ZS 6 /* Separator, Space */ #define UC_ZL 7 /* Separator, Line */ #define UC_ZP 8 /* Separator, Paragraph */ #define UC_OS 9 /* Other, Surrogate */ #define UC_CO 10 /* Other, Private Use */ #define UC_CN 11 /* Other, Not Assigned */ #define UC_LU 12 /* Letter, Uppercase */ #define UC_LL 13 /* Letter, Lowercase */ #define UC_LT 14 /* Letter, Titlecase */ #define UC_LM 15 /* Letter, Modifier */ #define UC_LO 16 /* Letter, Other */ #define UC_SM 17 /* Symbol, Math */ #define UC_SC 18 /* Symbol, Currency */ #define UC_SK 19 /* Symbol, Modifier */ #define UC_SO 20 /* Symbol, Other */ #define UC_L 21 /* Left-To-Right */ #define UC_R 22 /* Right-To-Left */ #define UC_EN 23 /* European Number */ #define UC_ES 24 /* European Number Separator */ #define UC_ET 25 /* European Number Terminator */ #define UC_AN 26 /* Arabic Number */ #define UC_CS 27 /* Common Number Separator */ #define UC_B 28 /* Block Separator */ #define UC_S 29 /* Segment Separator */ #define UC_WS 30 /* Whitespace */ #define UC_ON 31 /* Other Neutrals */ #define UC_AL 32 /* Arabic Letter */ /* Merged property categories */ #define UC_C 33 /* Control */ #define UC_P 34 /* Punctuation */ /* Derived properties from DerivedCoreProperties.txt */ #define UC_CASED 35 #define UC_CASE_IGNORABLE 36 MBSTRING_API bool php_unicode_is_prop(unsigned long code, ...); MBSTRING_API bool php_unicode_is_prop1(unsigned long code, int prop); typedef enum { PHP_UNICODE_CASE_UPPER = 0, PHP_UNICODE_CASE_LOWER, PHP_UNICODE_CASE_TITLE, PHP_UNICODE_CASE_FOLD, PHP_UNICODE_CASE_UPPER_SIMPLE, PHP_UNICODE_CASE_LOWER_SIMPLE, PHP_UNICODE_CASE_TITLE_SIMPLE, PHP_UNICODE_CASE_FOLD_SIMPLE, PHP_UNICODE_CASE_MODE_MAX } php_case_mode; MBSTRING_API zend_string *php_unicode_convert_case( php_case_mode case_mode, const char *srcstr, size_t srclen, const mbfl_encoding *src_encoding, const mbfl_encoding *dst_encoding, int illegal_mode, uint32_t illegal_substchar); /* Optimize the common ASCII case for lower/upper */ static inline int php_unicode_is_lower(unsigned long code) { if (code < 0x80) { return code >= 0x61 && code <= 0x7A; } else { return php_unicode_is_prop1(code, UC_LL); } } static inline int php_unicode_is_upper(unsigned long code) { if (code < 0x80) { return code >= 0x41 && code <= 0x5A; } else { return php_unicode_is_prop1(code, UC_LU); } } #define php_unicode_is_alpha(cc) php_unicode_is_prop(cc, UC_LU, UC_LL, UC_LM, UC_LO, UC_LT, -1) #define php_unicode_is_digit(cc) php_unicode_is_prop1(cc, UC_ND) #define php_unicode_is_alnum(cc) php_unicode_is_prop(cc, UC_LU, UC_LL, UC_LM, UC_LO, UC_LT, UC_ND, -1) #define php_unicode_is_cntrl(cc) php_unicode_is_prop1(cc, UC_C) #define php_unicode_is_blank(cc) php_unicode_is_prop1(cc, UC_ZS) #define php_unicode_is_punct(cc) php_unicode_is_prop1(cc, UC_P) #define php_unicode_is_graph(cc) php_unicode_is_prop(cc, \ UC_MN, UC_MC, UC_ME, UC_ND, UC_NL, UC_NO, \ UC_LU, UC_LL, UC_LT, UC_LM, UC_LO, UC_P, \ UC_SM, UC_SM, UC_SC, UC_SK, UC_SO, -1) #define php_unicode_is_print(cc) php_unicode_is_prop(cc, \ UC_MN, UC_MC, UC_ME, UC_ND, UC_NL, UC_NO, \ UC_LU, UC_LL, UC_LT, UC_LM, UC_LO, UC_P, \ UC_SM, UC_SM, UC_SC, UC_SK, UC_SO, UC_ZS, -1) #define php_unicode_is_title(cc) php_unicode_is_prop1(cc, UC_LT) #define php_unicode_is_symbol(cc) php_unicode_is_prop(cc, UC_SM, UC_SC, UC_SO, UC_SK, -1) #define php_unicode_is_number(cc) php_unicode_is_prop(cc, UC_ND, UC_NO, UC_NL, -1) #define php_unicode_is_nonspacing(cc) php_unicode_is_prop1(cc, UC_MN) /* * Directionality macros. */ #define php_unicode_is_rtl(cc) php_unicode_is_prop1(cc, UC_R) #define php_unicode_is_ltr(cc) php_unicode_is_prop1(cc, UC_L) #define php_unicode_is_strong(cc) php_unicode_is_prop(cc, UC_L, UC_R, -1) #define php_unicode_is_weak(cc) php_unicode_is_prop(cc, UC_EN, UC_ES, UC_ET, UC_AN, UC_CS, -1) #define php_unicode_is_neutral(cc) php_unicode_is_prop(cc, UC_B, UC_S, UC_WS, UC_ON, -1) #define php_unicode_is_separator(cc) php_unicode_is_prop(cc, UC_B, UC_S, -1) /* * Other macros inspired by John Cowan. */ #define php_unicode_is_mark(cc) php_unicode_is_prop(cc, UC_MN, UC_MC, UC_ME, -1) #define php_unicode_is_modif(cc) php_unicode_is_prop1(cc, UC_LM) #define php_unicode_is_letnum(cc) php_unicode_is_prop1(cc, UC_NL) #define php_unicode_is_math(cc) php_unicode_is_prop1(cc, UC_SM) #define php_unicode_is_currency(cc) php_unicode_is_prop1(cc, UC_SC) #define php_unicode_is_modifsymbol(cc) php_unicode_is_prop1(cc, UC_SK) #define php_unicode_is_nsmark(cc) php_unicode_is_prop1(cc, UC_MN) #define php_unicode_is_spmark(cc) php_unicode_is_prop1(cc, UC_MC) #define php_unicode_is_enclosing(cc) php_unicode_is_prop1(cc, UC_ME) #define php_unicode_is_private(cc) php_unicode_is_prop1(cc, UC_CO) #define php_unicode_is_surrogate(cc) php_unicode_is_prop1(cc, UC_OS) #define php_unicode_is_lsep(cc) php_unicode_is_prop1(cc, UC_ZL) #define php_unicode_is_psep(cc) php_unicode_is_prop1(cc, UC_ZP) /* * Other miscellaneous character property macros. */ #define php_unicode_is_han(cc) (((cc) >= 0x4e00 && (cc) <= 0x9fff) ||\ ((cc) >= 0xf900 && (cc) <= 0xfaff)) #define php_unicode_is_hangul(cc) ((cc) >= 0xac00 && (cc) <= 0xd7ff) /* * Derived core properties. */ #define php_unicode_is_cased(cc) php_unicode_is_prop1(cc, UC_CASED) #define php_unicode_is_case_ignorable(cc) php_unicode_is_prop1(cc, UC_CASE_IGNORABLE) #endif /* PHP_UNICODE_H */
7,736
42.960227
118
h
php-src
php-src-master/ext/mbstring/libmbfl/filters/cp932_table.h
/* * "streamable kanji code filter and converter" * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved. * * LICENSE NOTICES * * This file is part of "streamable kanji code filter and converter", * which is distributed under the terms of GNU Lesser General Public * License (version 2) as published by the Free Software Foundation. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with "streamable kanji code filter and converter"; * if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA * * The author of this file: * */ #ifndef CP932_TABLE_H #define CP932_TABLE_H /* * cp932 table */ static const unsigned short cp932ext3_eucjp_table[] = { /* ku 115 */ 0xF3F3,0xF3F4,0xF3F5,0xF3F6,0xF3F7,0xF3F8,0xF3F9,0xF3FA, 0xF3FB,0xF3FC,0xF3FD,0xF3FE,0xF4A1,0xF4A2,0xF4A3,0xF4A4, 0xF4A5,0xF4A6,0xF4A7,0xF4A8,0x224C,0xA2C3,0xF4A9,0xF4AA, 0xF4AB,0xF4AC,0xF4AD,0x2268,0xD4E3,0xDCDF,0xE4E9,0xE3F8, 0xD9A1,0xB1BB,0xF4AE,0xC2AD,0xC3FC,0xE4D0,0xC2BF,0xBCF4, 0xB0A9,0xB0C8,0xF4AF,0xB0D2,0xB0D4,0xB0E3,0xB0EE,0xB1A7, 0xB1A3,0xB1AC,0xB1A9,0xB1BE,0xB1DF,0xB1D8,0xB1C8,0xB1D7, 0xB1E3,0xB1F4,0xB1E1,0xB2A3,0xF4B0,0xB2BB,0xB2E6,0xB2ED, 0xB2F5,0xB2FC,0xF4B1,0xB3B5,0xB3D8,0xB3DB,0xB3E5,0xB3EE, 0xB3FB,0xF4B2,0xF4B3,0xB4C0,0xB4C7,0xB4D0,0xB4DE,0xF4B4, 0xB5AA,0xF4B5,0xB5AF,0xB5C4,0xB5E8,0xF4B6,0xB7C2,0xB7E4, 0xB7E8,0xB7E7,0xF4B7,0xF4B8,0xF4B9,0xB8CE, /* ku 116 */ 0xB8E1,0xB8F5,0xB8F7,0xB8F8,0xB8FC,0xB9AF,0xB9B7,0xBABE, 0xBADB,0xCDAA,0xBAE1,0xF4BA,0xBAEB,0xBBB3,0xBBB8,0xF4BB, 0xBBCA,0xF4BC,0xF4BD,0xBBD0,0xBBDE,0xBBF4,0xBBF5,0xBBF9, 0xBCE4,0xBCED,0xBCFE,0xF4BE,0xBDC2,0xBDE7,0xF4BF,0xBDF0, 0xBEB0,0xBEAC,0xF4C0,0xBEB3,0xBEBD,0xBECD,0xBEC9,0xBEE4, 0xBFA8,0xBFC9,0xC0C4,0xC0E4,0xC0F4,0xC1A6,0xF4C1,0xC1F5, 0xC1FC,0xF4C2,0xC1F8,0xC2AB,0xC2A1,0xC2A5,0xF4C3,0xC2B8, 0xC2BA,0xF4C4,0xC2C4,0xC2D2,0xC2D7,0xC2DB,0xC2DE,0xC2ED, 0xC2F0,0xF4C5,0xC3A1,0xC3B5,0xC3C9,0xC3B9,0xF4C6,0xC3D8, 0xC3FE,0xF4C7,0xC4CC,0xF4C8,0xC4D9,0xC4EA,0xC4FD,0xF4C9, 0xC5A7,0xC5B5,0xC5B6,0xF4CA,0xC5D5,0xC6B8,0xC6D7,0xC6E0, 0xC6EA,0xC6E3,0xC7A1,0xC7AB,0xC7C7,0xC7C3, /* ku 117 */ 0xC7CB,0xC7CF,0xC7D9,0xF4CB,0xF4CC,0xC7E6,0xC7EE,0xC7FC, 0xC7EB,0xC7F0,0xC8B1,0xC8E5,0xC8F8,0xC9A6,0xC9AB,0xC9AD, 0xF4CD,0xC9CA,0xC9D3,0xC9E9,0xC9E3,0xC9FC,0xC9F4,0xC9F5, 0xF4CE,0xCAB3,0xCABD,0xCAEF,0xCAF1,0xCBAE,0xF4CF,0xCBCA, 0xCBE6,0xCBEA,0xCBF0,0xCBF4,0xCBEE,0xCCA5,0xCBF9,0xCCAB, 0xCCAE,0xCCAD,0xCCB2,0xCCC2,0xCCD0,0xCCD9,0xF4D0,0xCDBB, 0xF4D1,0xCEBB,0xF4D2,0xCEBA,0xCEC3,0xF4D3,0xCEF2,0xB3DD, 0xCFD5,0xCFE2,0xCFE9,0xCFED,0xF4D4,0xF4D5,0xF4D6,0xF4D7, 0xD0E5,0xF4D8,0xD0E9,0xD1E8,0xF4D9,0xF4DA,0xD1EC,0xD2BB, 0xF4DB,0xD3E1,0xD3E8,0xD4A7,0xF4DC,0xF4DD,0xD4D4,0xD4F2, 0xD5AE,0xF4DE,0xD7DE,0xF4DF,0xD8A2,0xD8B7,0xD8C1,0xD8D1, 0xD8F4,0xD9C6,0xD9C8,0xD9D1,0xF4E0,0xF4E1, /* ku 118 */ 0xF4E2,0xF4E3,0xF4E4,0xDCD3,0xDDC8,0xDDD4,0xDDEA,0xDDFA, 0xDEA4,0xDEB0,0xF4E5,0xDEB5,0xDECB,0xF4E6,0xDFB9,0xF4E7, 0xDFC3,0xF4E8,0xF4E9,0xE0D9,0xF4EA,0xF4EB,0xE1E2,0xF4EC, 0xF4ED,0xF4EE,0xE2C7,0xE3A8,0xE3A6,0xE3A9,0xE3AF,0xE3B0, 0xE3AA,0xE3AB,0xE3BC,0xE3C1,0xE3BF,0xE3D5,0xE3D8,0xE3D6, 0xE3DF,0xE3E3,0xE3E1,0xE3D4,0xE3E9,0xE4A6,0xE3F1,0xE3F2, 0xE4CB,0xE4C1,0xE4C3,0xE4BE,0xF4EF,0xE4C0,0xE4C7,0xE4BF, 0xE4E0,0xE4DE,0xE4D1,0xF4F0,0xE4DC,0xE4D2,0xE4DB,0xE4D4, 0xE4FA,0xE4EF,0xE5B3,0xE5BF,0xE5C9,0xE5D0,0xE5E2,0xE5EA, 0xE5EB,0xF4F1,0xF4F2,0xF4F3,0xE6E8,0xE6EF,0xE7AC,0xF4F4, 0xE7AE,0xF4F5,0xE7B1,0xF4F6,0xE7B2,0xE8B1,0xE8B6,0xF4F7, 0xF4F8,0xE8DD,0xF4F9,0xF4FA,0xE9D1,0xF4FB, /* ku 119 */ 0xE9ED,0xEACD,0xF4FC,0xEADB,0xEAE6,0xEAEA,0xEBA5,0xEBFB, 0xEBFA,0xF4FD,0xECD6,0xF4FE }; static const int cp932ext3_eucjp_table_size = (sizeof (cp932ext3_eucjp_table) / sizeof (unsigned short)); #endif /* CP932_TABLE_H */
4,049
41.1875
105
h
php-src
php-src-master/ext/mbstring/libmbfl/filters/html_entities.c
/* * "streamable kanji code filter and converter" * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved. * * LICENSE NOTICES * * This file is part of "streamable kanji code filter and converter", * which is distributed under the terms of GNU Lesser General Public * License (version 2) as published by the Free Software Foundation. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with "streamable kanji code filter and converter"; * if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA * * The author of this part: Marcus Boerger <[email protected]> * */ /* * The source code included in this files was separated from mbfilter.c * by moriyoshi koizumi <[email protected]> on 4 dec 2002. * */ #include "mbfilter.h" #include "html_entities.h" const mbfl_html_entity_entry mbfl_html_entity_list[] = { {"quot", 34}, {"amp", 38}, {"lt", 60}, {"gt", 62}, {"nbsp", 160}, {"iexcl", 161}, {"cent", 162}, {"pound", 163}, {"curren", 164}, {"yen", 165}, {"brvbar", 166}, {"sect", 167}, {"uml", 168}, {"copy", 169}, {"ordf", 170}, {"laquo", 171}, {"not", 172}, {"shy", 173}, {"reg", 174}, {"macr", 175}, {"deg", 176}, {"plusmn", 177}, {"sup2", 178}, {"sup3", 179}, {"acute", 180}, {"micro", 181}, {"para", 182}, {"middot", 183}, {"cedil", 184}, {"sup1", 185}, {"ordm", 186}, {"raquo", 187}, {"frac14", 188}, {"frac12", 189}, {"frac34", 190}, {"iquest", 191}, {"Agrave", 192}, {"Aacute", 193}, {"Acirc", 194}, {"Atilde", 195}, {"Auml", 196}, {"Aring", 197}, {"AElig", 198}, {"Ccedil", 199}, {"Egrave", 200}, {"Eacute", 201}, {"Ecirc", 202}, {"Euml", 203}, {"Igrave", 204}, {"Iacute", 205}, {"Icirc", 206}, {"Iuml", 207}, {"ETH", 208}, {"Ntilde", 209}, {"Ograve", 210}, {"Oacute", 211}, {"Ocirc", 212}, {"Otilde", 213}, {"Ouml", 214}, {"times", 215}, {"Oslash", 216}, {"Ugrave", 217}, {"Uacute", 218}, {"Ucirc", 219}, {"Uuml", 220}, {"Yacute", 221}, {"THORN", 222}, {"szlig", 223}, {"agrave", 224}, {"aacute", 225}, {"acirc", 226}, {"atilde", 227}, {"auml", 228}, {"aring", 229}, {"aelig", 230}, {"ccedil", 231}, {"egrave", 232}, {"eacute", 233}, {"ecirc", 234}, {"euml", 235}, {"igrave", 236}, {"iacute", 237}, {"icirc", 238}, {"iuml", 239}, {"eth", 240}, {"ntilde", 241}, {"ograve", 242}, {"oacute", 243}, {"ocirc", 244}, {"otilde", 245}, {"ouml", 246}, {"divide", 247}, {"oslash", 248}, {"ugrave", 249}, {"uacute", 250}, {"ucirc", 251}, {"uuml", 252}, {"yacute", 253}, {"thorn", 254}, {"yuml", 255}, {"OElig", 338}, {"oelig", 339}, {"Scaron", 352}, {"scaron", 353}, {"Yuml", 376}, {"fnof", 402}, {"circ", 710}, {"tilde", 732}, {"Alpha", 913}, {"Beta", 914}, {"Gamma", 915}, {"Delta", 916}, {"Epsilon", 917}, {"Zeta", 918}, {"Eta", 919}, {"Theta", 920}, {"Iota", 921}, {"Kappa", 922}, {"Lambda", 923}, {"Mu", 924}, {"Nu", 925}, {"Xi", 926}, {"Omicron", 927}, {"Pi", 928}, {"Rho", 929}, {"Sigma", 931}, {"Tau", 932}, {"Upsilon", 933}, {"Phi", 934}, {"Chi", 935}, {"Psi", 936}, {"Omega", 937}, {"alpha", 945}, {"beta", 946}, {"gamma", 947}, {"delta", 948}, {"epsilon", 949}, {"zeta", 950}, {"eta", 951}, {"theta", 952}, {"iota", 953}, {"kappa", 954}, {"lambda", 955}, {"mu", 956}, {"nu", 957}, {"xi", 958}, {"omicron", 959}, {"pi", 960}, {"rho", 961}, {"sigmaf", 962}, {"sigma", 963}, {"tau", 964}, {"upsilon", 965}, {"phi", 966}, {"chi", 967}, {"psi", 968}, {"omega", 969}, {"thetasym", 977}, {"upsih", 978}, {"piv", 982}, {"ensp", 8194}, {"emsp", 8195}, {"thinsp", 8201}, {"zwnj", 8204}, {"zwj", 8205}, {"lrm", 8206}, {"rlm", 8207}, {"ndash", 8211}, {"mdash", 8212}, {"lsquo", 8216}, {"rsquo", 8217}, {"sbquo", 8218}, {"ldquo", 8220}, {"rdquo", 8221}, {"bdquo", 8222}, {"dagger", 8224}, {"Dagger", 8225}, {"bull", 8226}, {"hellip", 8230}, {"permil", 8240}, {"prime", 8242}, {"Prime", 8243}, {"lsaquo", 8249}, {"rsaquo", 8250}, {"oline", 8254}, {"frasl", 8260}, {"euro", 8364}, {"weierp", 8472}, {"image", 8465}, {"real", 8476}, {"trade", 8482}, {"alefsym", 8501}, {"larr", 8592}, {"uarr", 8593}, {"rarr", 8594}, {"darr", 8595}, {"harr", 8596}, {"crarr", 8629}, {"lArr", 8656}, {"uArr", 8657}, {"rArr", 8658}, {"dArr", 8659}, {"hArr", 8660}, {"forall", 8704}, {"part", 8706}, {"exist", 8707}, {"empty", 8709}, {"nabla", 8711}, {"isin", 8712}, {"notin", 8713}, {"ni", 8715}, {"prod", 8719}, {"sum", 8721}, {"minus", 8722}, {"lowast", 8727}, {"radic", 8730}, {"prop", 8733}, {"infin", 8734}, {"ang", 8736}, {"and", 8743}, {"or", 8744}, {"cap", 8745}, {"cup", 8746}, {"int", 8747}, {"there4", 8756}, {"sim", 8764}, {"cong", 8773}, {"asymp", 8776}, {"ne", 8800}, {"equiv", 8801}, {"le", 8804}, {"ge", 8805}, {"sub", 8834}, {"sup", 8835}, {"nsub", 8836}, {"sube", 8838}, {"supe", 8839}, {"oplus", 8853}, {"otimes", 8855}, {"perp", 8869}, {"sdot", 8901}, {"lceil", 8968}, {"rceil", 8969}, {"lfloor", 8970}, {"rfloor", 8971}, {"lang", 9001}, {"rang", 9002}, {"loz", 9674}, {"spades", 9824}, {"clubs", 9827}, {"hearts", 9829}, {"diams", 9830}, {NULL, -1} /* mark end of table */ };
6,770
22.510417
72
c
php-src
php-src-master/ext/mbstring/libmbfl/filters/html_entities.h
/* * "streamable kanji code filter and converter" * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved. * * LICENSE NOTICES * * This file is part of "streamable kanji code filter and converter", * which is distributed under the terms of GNU Lesser General Public * License (version 2) as published by the Free Software Foundation. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with "streamable kanji code filter and converter"; * if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA * * The author of this part: Marcus Boerger <[email protected]> * */ /* * The source code included in this files was separated from mbfilter.h * by moriyoshi koizumi <[email protected]> on 4 dec 2002. * */ #ifndef MBFL_HTML_ENTITIES_H #define MBFL_HTML_ENTITIES_H typedef struct _mbfl_html_entity_entry { char * name; int code; } mbfl_html_entity_entry; extern const mbfl_html_entity_entry mbfl_html_entity_list[]; #endif /* MBFL_HTML_ENTITIES_H */
1,323
31.292683
72
h
php-src
php-src-master/ext/mbstring/libmbfl/filters/mbfilter_7bit.c
/* * "streamable kanji code filter and converter" * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved. * * LICENSE NOTICES * * This file is part of "streamable kanji code filter and converter", * which is distributed under the terms of GNU Lesser General Public * License (version 2) as published by the Free Software Foundation. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with "streamable kanji code filter and converter"; * if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA * * The author of this file: * */ /* * The source code included in this files was separated from mbfilter.c * by Moriyoshi Koizumi <[email protected]> on 4 Dec 2002. The file * mbfilter.c is included in this package . * */ #include "mbfilter.h" #include "mbfilter_7bit.h" static size_t mb_7bit_to_wchar(unsigned char **in, size_t *in_len, uint32_t *buf, size_t bufsize, unsigned int *state); static void mb_wchar_to_7bit(uint32_t *in, size_t len, mb_convert_buf *buf, bool end); const struct mbfl_convert_vtbl vtbl_7bit_wchar = { mbfl_no_encoding_7bit, mbfl_no_encoding_wchar, mbfl_filt_conv_common_ctor, NULL, mbfl_filt_conv_7bit_any, mbfl_filt_conv_common_flush, NULL, }; const struct mbfl_convert_vtbl vtbl_wchar_7bit = { mbfl_no_encoding_wchar, mbfl_no_encoding_7bit, mbfl_filt_conv_common_ctor, NULL, mbfl_filt_conv_any_7bit, mbfl_filt_conv_common_flush, NULL, }; const mbfl_encoding mbfl_encoding_7bit = { mbfl_no_encoding_7bit, "7bit", "7bit", NULL, NULL, MBFL_ENCTYPE_SBCS, &vtbl_7bit_wchar, &vtbl_wchar_7bit, mb_7bit_to_wchar, mb_wchar_to_7bit, NULL }; #define CK(statement) do { if ((statement) < 0) return (-1); } while (0) int mbfl_filt_conv_7bit_any(int c, mbfl_convert_filter *filter) { return (*filter->output_function)(c < 0x80 ? c : MBFL_BAD_INPUT, filter->data); } int mbfl_filt_conv_any_7bit(int c, mbfl_convert_filter *filter) { if (c >= 0 && c < 0x80) { CK((*filter->output_function)(c, filter->data)); } else { CK(mbfl_filt_conv_illegal_output(c, filter)); } return 0; } static size_t mb_7bit_to_wchar(unsigned char **in, size_t *in_len, uint32_t *buf, size_t bufsize, unsigned int *state) { unsigned char *p = *in, *e = p + *in_len; uint32_t *out = buf, *limit = buf + bufsize; while (p < e && out < limit) { unsigned char c = *p++; *out++ = (c < 0x80) ? c : MBFL_BAD_INPUT; } *in_len = e - p; *in = p; return out - buf; } static void mb_wchar_to_7bit(uint32_t *in, size_t len, mb_convert_buf *buf, bool end) { unsigned char *out, *limit; MB_CONVERT_BUF_LOAD(buf, out, limit); MB_CONVERT_BUF_ENSURE(buf, out, limit, len); while (len--) { uint32_t w = *in++; if (w <= 0x7F) { out = mb_convert_buf_add(out, w); } else { MB_CONVERT_ERROR(buf, out, limit, w, mb_wchar_to_7bit); MB_CONVERT_BUF_ENSURE(buf, out, limit, len); } } MB_CONVERT_BUF_STORE(buf, out, limit); }
3,271
26.041322
119
c
php-src
php-src-master/ext/mbstring/libmbfl/filters/mbfilter_7bit.h
/* * "streamable kanji code filter and converter" * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved. * * LICENSE NOTICES * * This file is part of "streamable kanji code filter and converter", * which is distributed under the terms of GNU Lesser General Public * License (version 2) as published by the Free Software Foundation. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with "streamable kanji code filter and converter"; * if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA * * The author of this file: * */ /* * The source code included in this files was separated from mbfilter.c * by Moriyoshi Koizumi <[email protected]> on 4 Dec 2002. The file * mbfilter.c is included in this package . * */ #ifndef MBFL_MBFILTER_7BIT_H #define MBFL_MBFILTER_7BIT_H #include "mbfilter.h" extern const mbfl_encoding mbfl_encoding_7bit; extern const struct mbfl_convert_vtbl vtbl_8bit_7bit; extern const struct mbfl_convert_vtbl vtbl_7bit_8bit; int mbfl_filt_conv_7bit_any(int c, mbfl_convert_filter *filter); int mbfl_filt_conv_any_7bit(int c, mbfl_convert_filter *filter); #endif /* MBFL_MBFILTER_7BIT_H */
1,495
33
72
h
php-src
php-src-master/ext/mbstring/libmbfl/filters/mbfilter_base64.h
/* * "streamable kanji code filter and converter" * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved. * * LICENSE NOTICES * * This file is part of "streamable kanji code filter and converter", * which is distributed under the terms of GNU Lesser General Public * License (version 2) as published by the Free Software Foundation. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with "streamable kanji code filter and converter"; * if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA * * The author of this file: * */ /* * The source code included in this files was separated from mbfilter.c * by Moriyoshi Koizumi <[email protected]> on 4 Dec 2002. The file * mbfilter.c is included in this package . * */ #ifndef MBFL_MBFILTER_BASE64_H #define MBFL_MBFILTER_BASE64_H #include "mbfilter.h" extern const mbfl_encoding mbfl_encoding_base64; extern const struct mbfl_convert_vtbl vtbl_b64_8bit; extern const struct mbfl_convert_vtbl vtbl_8bit_b64; int mbfl_filt_conv_base64enc(int c, mbfl_convert_filter *filter); int mbfl_filt_conv_base64enc_flush(mbfl_convert_filter *filter); int mbfl_filt_conv_base64dec(int c, mbfl_convert_filter *filter); int mbfl_filt_conv_base64dec_flush(mbfl_convert_filter *filter); #endif /* MBFL_MBFILTER_BASE64_H */
1,633
34.521739
72
h
php-src
php-src-master/ext/mbstring/libmbfl/filters/mbfilter_cjk.h
#ifndef MBFL_MBFILTER_CJK_H #define MBFL_MBFILTER_CJK_H #include "mbfilter.h" extern const mbfl_encoding mbfl_encoding_jis; extern const mbfl_encoding mbfl_encoding_2022jp; extern const mbfl_encoding mbfl_encoding_2022jp_kddi; extern const mbfl_encoding mbfl_encoding_2022jpms; extern const mbfl_encoding mbfl_encoding_2022jp_2004; extern const mbfl_encoding mbfl_encoding_cp50220; extern const mbfl_encoding mbfl_encoding_cp50221; extern const mbfl_encoding mbfl_encoding_cp50222; extern const mbfl_encoding mbfl_encoding_2022kr; extern const mbfl_encoding mbfl_encoding_sjis; extern const mbfl_encoding mbfl_encoding_sjis_mac; extern const mbfl_encoding mbfl_encoding_sjis_docomo; extern const mbfl_encoding mbfl_encoding_sjis_kddi; extern const mbfl_encoding mbfl_encoding_sjis_sb; extern const mbfl_encoding mbfl_encoding_sjis2004; extern const mbfl_encoding mbfl_encoding_cp932; extern const mbfl_encoding mbfl_encoding_sjiswin; extern const mbfl_encoding mbfl_encoding_euc_jp; extern const mbfl_encoding mbfl_encoding_eucjp_win; extern const mbfl_encoding mbfl_encoding_eucjp2004; extern const mbfl_encoding mbfl_encoding_cp51932; extern const mbfl_encoding mbfl_encoding_euc_cn; extern const mbfl_encoding mbfl_encoding_euc_tw; extern const mbfl_encoding mbfl_encoding_euc_kr; extern const mbfl_encoding mbfl_encoding_uhc; extern const mbfl_encoding mbfl_encoding_gb18030; extern const mbfl_encoding mbfl_encoding_cp936; extern const mbfl_encoding mbfl_encoding_big5; extern const mbfl_encoding mbfl_encoding_cp950; extern const mbfl_encoding mbfl_encoding_hz; int mbfilter_sjis_emoji_docomo2unicode(int s, int *snd); int mbfilter_sjis_emoji_kddi2unicode(int s, int *snd); int mbfilter_sjis_emoji_sb2unicode(int s, int *snd); int mbfilter_unicode2sjis_emoji_docomo(int c, int *s1, mbfl_convert_filter *filter); int mbfilter_unicode2sjis_emoji_kddi_sjis(int c, int *s1, mbfl_convert_filter *filter); int mbfilter_unicode2sjis_emoji_sb(int c, int *s1, mbfl_convert_filter *filter); #endif /* MBFL_MBFILTER_CJK_H */
2,028
40.408163
87
h
php-src
php-src-master/ext/mbstring/libmbfl/filters/mbfilter_cp51932.h
/* * "streamable kanji code filter and converter" * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved. * * LICENSE NOTICES * * This file is part of "streamable kanji code filter and converter", * which is distributed under the terms of GNU Lesser General Public * License (version 2) as published by the Free Software Foundation. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with "streamable kanji code filter and converter"; * if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA * * The author of this file: * */ /* * The source code included in this files was separated from mbfilter_ja.h * by moriyoshi koizumi <[email protected]> on 4 dec 2002. * */ #ifndef MBFL_MBFILTER_CP51932_H #define MBFL_MBFILTER_CP51932_H #include "mbfilter.h" extern const mbfl_encoding mbfl_encoding_cp51932; extern const struct mbfl_convert_vtbl vtbl_cp51932_wchar; extern const struct mbfl_convert_vtbl vtbl_wchar_cp51932; int mbfl_filt_conv_cp51932_wchar(int c, mbfl_convert_filter *filter); int mbfl_filt_conv_wchar_cp51932(int c, mbfl_convert_filter *filter); #endif /* MBFL_MBFILTER_CP51932_H */
1,475
33.325581
74
h
php-src
php-src-master/ext/mbstring/libmbfl/filters/mbfilter_htmlent.c
/* * "streamable kanji code filter and converter" * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved. * * LICENSE NOTICES * * This file is part of "streamable kanji code filter and converter", * which is distributed under the terms of GNU Lesser General Public * License (version 2) as published by the Free Software Foundation. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with "streamable kanji code filter and converter"; * if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA * * The author of this part: Marcus Boerger <[email protected]> * */ /* * The source code included in this files was separated from mbfilter.c * by moriyoshi koizumi <[email protected]> on 4 dec 2002. * */ #include <string.h> #include "mbfilter.h" #include "mbfilter_htmlent.h" #include "html_entities.h" static size_t mb_htmlent_to_wchar(unsigned char **in, size_t *in_len, uint32_t *buf, size_t bufsize, unsigned int *state); static void mb_wchar_to_htmlent(uint32_t *in, size_t len, mb_convert_buf *buf, bool end); static const int htmlentitifieds[256] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; static const char *mbfl_encoding_html_ent_aliases[] = {"HTML", "html", NULL}; const mbfl_encoding mbfl_encoding_html_ent = { mbfl_no_encoding_html_ent, "HTML-ENTITIES", "HTML-ENTITIES", mbfl_encoding_html_ent_aliases, NULL, MBFL_ENCTYPE_GL_UNSAFE, &vtbl_html_wchar, &vtbl_wchar_html, mb_htmlent_to_wchar, mb_wchar_to_htmlent, NULL }; const struct mbfl_convert_vtbl vtbl_wchar_html = { mbfl_no_encoding_wchar, mbfl_no_encoding_html_ent, mbfl_filt_conv_common_ctor, NULL, mbfl_filt_conv_html_enc, mbfl_filt_conv_html_enc_flush, NULL, }; const struct mbfl_convert_vtbl vtbl_html_wchar = { mbfl_no_encoding_html_ent, mbfl_no_encoding_wchar, mbfl_filt_conv_html_dec_ctor, mbfl_filt_conv_html_dec_dtor, mbfl_filt_conv_html_dec, mbfl_filt_conv_html_dec_flush, mbfl_filt_conv_html_dec_copy, }; #define CK(statement) do { if ((statement) < 0) return (-1); } while (0) /* * any => HTML */ int mbfl_filt_conv_html_enc(int c, mbfl_convert_filter *filter) { int tmp[64]; int i; unsigned int uc; const mbfl_html_entity_entry *e; if (c < sizeof(htmlentitifieds) / sizeof(htmlentitifieds[0]) && htmlentitifieds[c] != 1) { CK((*filter->output_function)(c, filter->data)); } else { CK((*filter->output_function)('&', filter->data)); for (i = 0; (e = &mbfl_html_entity_list[i])->name != NULL; i++) { if (c == e->code) { char *p; for (p = e->name; *p != '\0'; p++) { CK((*filter->output_function)((int)*p, filter->data)); } goto last; } } { int *p = tmp + sizeof(tmp) / sizeof(tmp[0]); CK((*filter->output_function)('#', filter->data)); uc = (unsigned int)c; *(--p) = '\0'; do { *(--p) = "0123456789"[uc % 10]; uc /= 10; } while (uc); for (; *p != '\0'; p++) { CK((*filter->output_function)(*p, filter->data)); } } last: CK((*filter->output_function)(';', filter->data)); } return 0; } int mbfl_filt_conv_html_enc_flush(mbfl_convert_filter *filter) { filter->status = 0; filter->opaque = NULL; if (filter->flush_function != NULL) { (*filter->flush_function)(filter->data); } return 0; } /* * HTML => any */ #define html_enc_buffer_size 16 static const char html_entity_chars[] = "#0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; void mbfl_filt_conv_html_dec_ctor(mbfl_convert_filter *filter) { filter->status = 0; filter->opaque = emalloc(html_enc_buffer_size+1); } void mbfl_filt_conv_html_dec_dtor(mbfl_convert_filter *filter) { filter->status = 0; if (filter->opaque) { efree((void*)filter->opaque); } filter->opaque = NULL; } int mbfl_filt_conv_html_dec(int c, mbfl_convert_filter *filter) { int pos; unsigned int ent = 0; mbfl_html_entity_entry *entity; unsigned char *buffer = (unsigned char*)filter->opaque; if (!filter->status) { if (c == '&' ) { filter->status = 1; buffer[0] = '&'; } else { CK((*filter->output_function)(c, filter->data)); } } else { if (c == ';') { if (buffer[1]=='#') { if (filter->status > 2 && (buffer[2] == 'x' || buffer[2] == 'X')) { if (filter->status > 3) { /* numeric entity */ for (pos=3; pos<filter->status; pos++) { int v = buffer[pos]; if (v >= '0' && v <= '9') { v = v - '0'; } else if (v >= 'A' && v <= 'F') { v = v - 'A' + 10; } else if (v >= 'a' && v <= 'f') { v = v - 'a' + 10; } else { ent = -1; break; } ent = ent * 16 + v; } } else { ent = -1; } } else { /* numeric entity */ if (filter->status > 2) { for (pos=2; pos<filter->status; pos++) { if (ent > 0x19999999) { ent = -1; break; } int v = buffer[pos]; if (v >= '0' && v <= '9') { v = v - '0'; } else { ent = -1; break; } ent = ent*10 + v; } } else { ent = -1; } } if (ent < 0x110000) { CK((*filter->output_function)(ent, filter->data)); } else { for (pos = 0; pos < filter->status; pos++) { CK((*filter->output_function)(buffer[pos], filter->data)); } CK((*filter->output_function)(c, filter->data)); } filter->status = 0; } else { /* named entity */ buffer[filter->status] = 0; entity = (mbfl_html_entity_entry *)mbfl_html_entity_list; while (entity->name) { if (!strcmp((const char*)buffer+1, entity->name)) { ent = entity->code; break; } entity++; } if (ent) { /* decoded */ CK((*filter->output_function)(ent, filter->data)); filter->status = 0; } else { /* failure */ buffer[filter->status++] = ';'; buffer[filter->status] = 0; /* flush fragments */ pos = 0; while (filter->status--) { int e = (*filter->output_function)(buffer[pos++], filter->data); if (e != 0) return e; } filter->status = 0; } } } else { /* add character */ buffer[filter->status++] = c; /* add character and check */ if (!strchr(html_entity_chars, c) || filter->status+1==html_enc_buffer_size || (c=='#' && filter->status>2)) { /* illegal character or end of buffer */ if (c=='&') filter->status--; buffer[filter->status] = 0; pos = 0; while (filter->status--) { int e = (*filter->output_function)(buffer[pos++], filter->data); if (e != 0) return e; } filter->status = 0; if (c=='&') { buffer[filter->status++] = '&'; } } } } return 0; } int mbfl_filt_conv_html_dec_flush(mbfl_convert_filter *filter) { int status, pos = 0; unsigned char *buffer; int err = 0; buffer = (unsigned char*)filter->opaque; status = filter->status; filter->status = 0; /* flush fragments */ while (status--) { int e = (*filter->output_function)(buffer[pos++], filter->data); if (e != 0) err = e; } if (filter->flush_function != NULL) { (*filter->flush_function)(filter->data); } return err; } void mbfl_filt_conv_html_dec_copy(mbfl_convert_filter *src, mbfl_convert_filter *dest) { *dest = *src; dest->opaque = emalloc(html_enc_buffer_size+1); memcpy(dest->opaque, src->opaque, html_enc_buffer_size+1); } static bool is_html_entity_char(unsigned char c) { return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '#'; } static size_t mb_htmlent_to_wchar(unsigned char **in, size_t *in_len, uint32_t *buf, size_t bufsize, unsigned int *state) { unsigned char *p = *in, *e = p + *in_len; uint32_t *out = buf, *limit = buf + bufsize; while (p < e && out < limit) { unsigned char c = *p++; if (c == '&') { /* Find terminating ; for HTML entity */ unsigned char *terminator = p; while (terminator < e && is_html_entity_char(*terminator)) terminator++; if (terminator < e && *terminator == ';') { if (*p == '#' && (e - p) >= 2) { /* Numeric entity */ unsigned int value = 0; unsigned char *digits = p + 1; if (*digits == 'x' || *digits == 'X') { /* Hexadecimal */ digits++; if (digits == terminator) { goto bad_entity; } while (digits < terminator) { unsigned char digit = *digits++; if (digit >= '0' && digit <= '9') { value = (value * 16) + (digit - '0'); } else if (digit >= 'A' && digit <= 'F') { value = (value * 16) + (digit - 'A' + 10); } else if (digit >= 'a' && digit <= 'f') { value = (value * 16) + (digit - 'a' + 10); } else { goto bad_entity; } } } else { /* Decimal */ if (digits == terminator) { goto bad_entity; } while (digits < terminator) { unsigned char digit = *digits++; if (digit >= '0' && digit <= '9') { value = (value * 10) + (digit - '0'); } else { goto bad_entity; } } } if (value > 0x10FFFF) { goto bad_entity; } *out++ = value; p = terminator + 1; goto next_iteration; } else if (terminator > p && terminator < e) { /* Named entity */ mbfl_html_entity_entry *entity = (mbfl_html_entity_entry*)mbfl_html_entity_list; while (entity->name) { if (!strncmp((char*)p, entity->name, terminator - p) && strlen(entity->name) == terminator - p) { *out++ = entity->code; p = terminator + 1; goto next_iteration; } entity++; } } } /* Either we didn't find ;, or the name of the entity was not recognized */ bad_entity: *out++ = '&'; while (p < terminator && out < limit) { *out++ = *p++; } if (terminator < e && *terminator == ';' && out < limit) { *out++ = *p++; } } else { *out++ = c; } next_iteration: ; } *in_len = e - p; *in = p; return out - buf; } static void mb_wchar_to_htmlent(uint32_t *in, size_t len, mb_convert_buf *buf, bool end) { unsigned char *out, *limit; MB_CONVERT_BUF_LOAD(buf, out, limit); MB_CONVERT_BUF_ENSURE(buf, out, limit, len); while (len--) { uint32_t w = *in++; if (w < sizeof(htmlentitifieds) / sizeof(htmlentitifieds[0]) && htmlentitifieds[w] != 1) { /* Fast path for most ASCII characters */ out = mb_convert_buf_add(out, w); } else { out = mb_convert_buf_add(out, '&'); /* See if there is a matching named entity */ mbfl_html_entity_entry *entity = (mbfl_html_entity_entry*)mbfl_html_entity_list; while (entity->name) { if (w == entity->code) { MB_CONVERT_BUF_ENSURE(buf, out, limit, len + 1 + strlen(entity->name)); for (char *str = entity->name; *str; str++) { out = mb_convert_buf_add(out, *str); } out = mb_convert_buf_add(out, ';'); goto next_iteration; } entity++; } /* There is no matching named entity; emit a numeric entity instead */ MB_CONVERT_BUF_ENSURE(buf, out, limit, len + 12); out = mb_convert_buf_add(out, '#'); if (!w) { out = mb_convert_buf_add(out, '0'); } else { unsigned char buf[12]; unsigned char *converted = buf + sizeof(buf); while (w) { *(--converted) = "0123456789"[w % 10]; w /= 10; } while (converted < buf + sizeof(buf)) { out = mb_convert_buf_add(out, *converted++); } } out = mb_convert_buf_add(out, ';'); } next_iteration: ; } MB_CONVERT_BUF_STORE(buf, out, limit); }
12,571
24.815195
122
c
php-src
php-src-master/ext/mbstring/libmbfl/filters/mbfilter_htmlent.h
/* * "streamable kanji code filter and converter" * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved. * * LICENSE NOTICES * * This file is part of "streamable kanji code filter and converter", * which is distributed under the terms of GNU Lesser General Public * License (version 2) as published by the Free Software Foundation. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with "streamable kanji code filter and converter"; * if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA * * The author of this part: Marcus Boerger <[email protected]> * */ /* * The source code included in this files was separated from mbfilter.c * by moriyoshi koizumi <[email protected]> on 4 dec 2002. * */ #ifndef MBFL_MBFILTER_HTMLENT_H #define MBFL_MBFILTER_HTMLENT_H #include "mbfilter.h" extern const mbfl_encoding mbfl_encoding_html_ent; extern const struct mbfl_convert_vtbl vtbl_wchar_html; extern const struct mbfl_convert_vtbl vtbl_html_wchar; void mbfl_filt_conv_html_dec_ctor(mbfl_convert_filter *filter); void mbfl_filt_conv_html_dec_dtor(mbfl_convert_filter *filter); int mbfl_filt_conv_html_enc(int c, mbfl_convert_filter *filter); int mbfl_filt_conv_html_enc_flush(mbfl_convert_filter *filter); int mbfl_filt_conv_html_dec(int c, mbfl_convert_filter *filter); int mbfl_filt_conv_html_dec_flush(mbfl_convert_filter *filter); void mbfl_filt_conv_html_dec_copy(mbfl_convert_filter *src, mbfl_convert_filter *dest); #endif /* MBFL_MBFILTER_HTMLENT_H */
1,832
37.1875
87
h
php-src
php-src-master/ext/mbstring/libmbfl/filters/mbfilter_iso2022jp_2004.h
/* * "streamable kanji code filter and converter" * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved. * * LICENSE NOTICES * * This file is part of "streamable kanji code filter and converter", * which is distributed under the terms of GNU Lesser General Public * License (version 2) as published by the Free Software Foundation. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with "streamable kanji code filter and converter"; * if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA * * The author of this file: * */ /* * The source code included in this files was separated from mbfilter_ja.c * by moriyoshi koizumi <[email protected]> on 4 dec 2002. * */ #ifndef MBFL_MBFILTER_2022JP_2004_H #define MBFL_MBFILTER_2022JP_2004_H #include "mbfilter.h" extern const mbfl_encoding mbfl_encoding_2022jp_2004; extern const struct mbfl_convert_vtbl vtbl_2022jp_2004_wchar; extern const struct mbfl_convert_vtbl vtbl_wchar_2022jp_2004; #endif /* MBFL_MBFILTER_2022JP_2004_H */
1,358
32.975
74
h
php-src
php-src-master/ext/mbstring/libmbfl/filters/mbfilter_qprint.c
/* * "streamable kanji code filter and converter" * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved. * * LICENSE NOTICES * * This file is part of "streamable kanji code filter and converter", * which is distributed under the terms of GNU Lesser General Public * License (version 2) as published by the Free Software Foundation. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with "streamable kanji code filter and converter"; * if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA * * The author of this file: * */ /* * The source code included in this file was separated from mbfilter.c * by moriyoshi koizumi <[email protected]> on 4 dec 2002. * */ #include "mbfilter.h" #include "mbfilter_qprint.h" static size_t mb_qprint_to_wchar(unsigned char **in, size_t *in_len, uint32_t *buf, size_t bufsize, unsigned int *state); static void mb_wchar_to_qprint(uint32_t *in, size_t len, mb_convert_buf *buf, bool end); static const char *mbfl_encoding_qprint_aliases[] = {"qprint", NULL}; const mbfl_encoding mbfl_encoding_qprint = { mbfl_no_encoding_qprint, "Quoted-Printable", "Quoted-Printable", mbfl_encoding_qprint_aliases, NULL, MBFL_ENCTYPE_GL_UNSAFE, NULL, NULL, mb_qprint_to_wchar, mb_wchar_to_qprint, NULL }; const struct mbfl_convert_vtbl vtbl_8bit_qprint = { mbfl_no_encoding_8bit, mbfl_no_encoding_qprint, mbfl_filt_conv_common_ctor, NULL, mbfl_filt_conv_qprintenc, mbfl_filt_conv_qprintenc_flush, NULL, }; const struct mbfl_convert_vtbl vtbl_qprint_8bit = { mbfl_no_encoding_qprint, mbfl_no_encoding_8bit, mbfl_filt_conv_common_ctor, NULL, mbfl_filt_conv_qprintdec, mbfl_filt_conv_qprintdec_flush, NULL, }; #define CK(statement) do { if ((statement) < 0) return (-1); } while (0) /* * any => Quoted-Printable */ int mbfl_filt_conv_qprintenc(int c, mbfl_convert_filter *filter) { int s, n; switch (filter->status & 0xff) { case 0: filter->cache = c; filter->status++; break; default: s = filter->cache; filter->cache = c; n = (filter->status & 0xff00) >> 8; if (s == 0) { /* null */ CK((*filter->output_function)(s, filter->data)); filter->status &= ~0xff00; break; } if (s == '\n' || (s == '\r' && c != '\n')) { /* line feed */ CK((*filter->output_function)('\r', filter->data)); CK((*filter->output_function)('\n', filter->data)); filter->status &= ~0xff00; break; } else if (s == 0x0d) { break; } if (n >= 72) { /* soft line feed */ CK((*filter->output_function)('=', filter->data)); CK((*filter->output_function)('\r', filter->data)); CK((*filter->output_function)('\n', filter->data)); filter->status &= ~0xff00; } if (s <= 0 || s >= 0x80 || s == '=') { /* not ASCII or '=' */ /* hex-octet */ CK((*filter->output_function)('=', filter->data)); n = (s >> 4) & 0xf; if (n < 10) { n += 48; /* '0' */ } else { n += 55; /* 'A' - 10 */ } CK((*filter->output_function)(n, filter->data)); n = s & 0xf; if (n < 10) { n += 48; } else { n += 55; } CK((*filter->output_function)(n, filter->data)); filter->status += 0x300; } else { CK((*filter->output_function)(s, filter->data)); filter->status += 0x100; } break; } return 0; } int mbfl_filt_conv_qprintenc_flush(mbfl_convert_filter *filter) { /* flush filter cache */ (*filter->filter_function)('\0', filter); filter->status &= ~0xffff; filter->cache = 0; if (filter->flush_function) { (*filter->flush_function)(filter->data); } return 0; } static int hex2code_map[] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; /* * Quoted-Printable => any */ int mbfl_filt_conv_qprintdec(int c, mbfl_convert_filter *filter) { int n, m; switch (filter->status) { case 1: if (hex2code_map[c & 0xff] >= 0) { filter->cache = c; filter->status = 2; } else if (c == 0x0d) { /* soft line feed */ filter->status = 3; } else if (c == 0x0a) { /* soft line feed */ filter->status = 0; } else { CK((*filter->output_function)(0x3d, filter->data)); /* '=' */ CK((*filter->output_function)(c, filter->data)); filter->status = 0; } break; case 2: m = hex2code_map[c & 0xff]; if (m < 0) { CK((*filter->output_function)(0x3d, filter->data)); /* '=' */ CK((*filter->output_function)(filter->cache, filter->data)); n = c; } else { n = hex2code_map[filter->cache] << 4 | m; } CK((*filter->output_function)(n, filter->data)); filter->status = 0; break; case 3: if (c != 0x0a) { /* LF */ CK((*filter->output_function)(c, filter->data)); } filter->status = 0; break; default: if (c == 0x3d) { /* '=' */ filter->status = 1; } else { CK((*filter->output_function)(c, filter->data)); } break; } return 0; } int mbfl_filt_conv_qprintdec_flush(mbfl_convert_filter *filter) { int status, cache; status = filter->status; cache = filter->cache; filter->status = 0; filter->cache = 0; /* flush fragments */ if (status == 1) { CK((*filter->output_function)(0x3d, filter->data)); /* '=' */ } else if (status == 2) { CK((*filter->output_function)(0x3d, filter->data)); /* '=' */ CK((*filter->output_function)(cache, filter->data)); } if (filter->flush_function) { (*filter->flush_function)(filter->data); } return 0; } static size_t mb_qprint_to_wchar(unsigned char **in, size_t *in_len, uint32_t *buf, size_t bufsize, unsigned int *state) { unsigned char *p = *in, *e = p + *in_len; uint32_t *out = buf, *limit = buf + bufsize - 2; while (p < e && out < limit) { unsigned char c = *p++; if (c == '=' && p < e) { unsigned char c2 = *p++; if (hex2code_map[c2] >= 0 && p < e) { unsigned char c3 = *p++; if (hex2code_map[c3] >= 0) { *out++ = hex2code_map[c2] << 4 | hex2code_map[c3]; } else { *out++ = '='; *out++ = c2; *out++ = c3; } } else if (c2 == '\r' && p < e) { unsigned char c3 = *p++; if (c3 != '\n') { *out++ = c3; } } else if (c2 != '\n') { *out++ = '='; *out++ = c2; } } else { *out++ = c; } } *in_len = e - p; *in = p; return out - buf; } static unsigned char qprint_enc_nibble(unsigned char nibble) { if (nibble < 10) { return nibble + '0'; } else { return nibble - 10 + 'A'; } } static void mb_wchar_to_qprint(uint32_t *in, size_t len, mb_convert_buf *buf, bool end) { unsigned char *out, *limit; MB_CONVERT_BUF_LOAD(buf, out, limit); MB_CONVERT_BUF_ENSURE(buf, out, limit, len); unsigned int chars_output = buf->state; while (len--) { /* We assume that all the input 'codepoints' are not really Unicode codepoints at all, * but raw bytes from 0x00-0xFF */ uint32_t w = *in++; if (!w) { out = mb_convert_buf_add(out, '\0'); chars_output = 0; continue; } else if (w == '\n') { MB_CONVERT_BUF_ENSURE(buf, out, limit, len + 2); out = mb_convert_buf_add2(out, '\r', '\n'); chars_output = 0; continue; } else if (w == '\r') { /* No output */ continue; } /* QPrint actually mandates that line length should not be more than 76 characters, * but mbstring stops slightly short of that */ if (chars_output >= 72) { MB_CONVERT_BUF_ENSURE(buf, out, limit, len + 4); out = mb_convert_buf_add3(out, '=', '\r', '\n'); chars_output = 0; } if (w >= 0x80 || w == '=') { /* Not ASCII */ MB_CONVERT_BUF_ENSURE(buf, out, limit, len + 3); out = mb_convert_buf_add3(out, '=', qprint_enc_nibble((w >> 4) & 0xF), qprint_enc_nibble(w & 0xF)); chars_output += 3; } else { /* Plain ASCII */ out = mb_convert_buf_add(out, w); chars_output++; } } buf->state = chars_output; MB_CONVERT_BUF_STORE(buf, out, limit); }
9,020
24.700855
121
c
php-src
php-src-master/ext/mbstring/libmbfl/filters/mbfilter_qprint.h
/* * "streamable kanji code filter and converter" * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved. * * LICENSE NOTICES * * This file is part of "streamable kanji code filter and converter", * which is distributed under the terms of GNU Lesser General Public * License (version 2) as published by the Free Software Foundation. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with "streamable kanji code filter and converter"; * if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA * * The author of this file: * */ /* * The source code included in this files was separated from mbfilter.c * by moriyoshi koizumi <[email protected]> on 4 dec 2002. * */ #ifndef MBFL_MBFILTER_QPRINT_H #define MBFL_MBFILTER_QPRINT_H #include "mbfilter.h" extern const mbfl_encoding mbfl_encoding_qprint; extern const struct mbfl_convert_vtbl vtbl_8bit_qprint; extern const struct mbfl_convert_vtbl vtbl_qprint_8bit; int mbfl_filt_conv_qprintenc(int c, mbfl_convert_filter *filter); int mbfl_filt_conv_qprintenc_flush(mbfl_convert_filter *filter); int mbfl_filt_conv_qprintdec(int c, mbfl_convert_filter *filter); int mbfl_filt_conv_qprintdec_flush(mbfl_convert_filter *filter); #endif /* MBFL_MBFILTER_ASCII_H */
1,585
34.244444
72
h
php-src
php-src-master/ext/mbstring/libmbfl/filters/mbfilter_singlebyte.h
/* +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ */ #ifndef MBFL_SINGLEBYTE_H #define MBFL_SINGLEBYTE_H #include "mbfilter.h" extern const mbfl_encoding mbfl_encoding_ascii; extern const mbfl_encoding mbfl_encoding_8859_1; extern const mbfl_encoding mbfl_encoding_8859_2; extern const mbfl_encoding mbfl_encoding_8859_3; extern const mbfl_encoding mbfl_encoding_8859_4; extern const mbfl_encoding mbfl_encoding_8859_5; extern const mbfl_encoding mbfl_encoding_8859_6; extern const mbfl_encoding mbfl_encoding_8859_7; extern const mbfl_encoding mbfl_encoding_8859_8; extern const mbfl_encoding mbfl_encoding_8859_9; extern const mbfl_encoding mbfl_encoding_8859_10; extern const mbfl_encoding mbfl_encoding_8859_13; extern const mbfl_encoding mbfl_encoding_8859_14; extern const mbfl_encoding mbfl_encoding_8859_15; extern const mbfl_encoding mbfl_encoding_8859_16; extern const mbfl_encoding mbfl_encoding_cp1251; extern const mbfl_encoding mbfl_encoding_cp1252; extern const mbfl_encoding mbfl_encoding_cp1254; extern const mbfl_encoding mbfl_encoding_cp866; extern const mbfl_encoding mbfl_encoding_cp850; extern const mbfl_encoding mbfl_encoding_koi8r; extern const mbfl_encoding mbfl_encoding_koi8u; extern const mbfl_encoding mbfl_encoding_armscii8; #endif /* MBFL_SINGLEBYTE_H */
2,080
45.244444
75
h
php-src
php-src-master/ext/mbstring/libmbfl/filters/mbfilter_ucs2.c
/* * "streamable kanji code filter and converter" * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved. * * LICENSE NOTICES * * This file is part of "streamable kanji code filter and converter", * which is distributed under the terms of GNU Lesser General Public * License (version 2) as published by the Free Software Foundation. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with "streamable kanji code filter and converter"; * if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA * * The author of this file: * */ /* * The source code included in this files was separated from mbfilter.c * by moriyoshi koizumi <[email protected]> on 4 dec 2002. * */ #include "mbfilter.h" #include "mbfilter_ucs2.h" static int mbfl_filt_conv_ucs2_wchar_flush(mbfl_convert_filter *filter); static size_t mb_ucs2_to_wchar(unsigned char **in, size_t *in_len, uint32_t *buf, size_t bufsize, unsigned int *state); static size_t mb_ucs2be_to_wchar(unsigned char **in, size_t *in_len, uint32_t *buf, size_t bufsize, unsigned int *state); static void mb_wchar_to_ucs2be(uint32_t *in, size_t len, mb_convert_buf *buf, bool end); static size_t mb_ucs2le_to_wchar(unsigned char **in, size_t *in_len, uint32_t *buf, size_t bufsize, unsigned int *state); static void mb_wchar_to_ucs2le(uint32_t *in, size_t len, mb_convert_buf *buf, bool end); static const char *mbfl_encoding_ucs2_aliases[] = {"ISO-10646-UCS-2", "UCS2" , "UNICODE", NULL}; /* This library historically had encodings called 'byte2be' and 'byte2le' * which were almost identical to UCS-2, except that they would truncate * Unicode codepoints higher than 0xFFFF quietly * Maintain minimal support by aliasing to UCS-2 */ static const char *mbfl_encoding_ucs2be_aliases[] = {"byte2be", NULL}; static const char *mbfl_encoding_ucs2le_aliases[] = {"byte2le", NULL}; const mbfl_encoding mbfl_encoding_ucs2 = { mbfl_no_encoding_ucs2, "UCS-2", "UCS-2", mbfl_encoding_ucs2_aliases, NULL, MBFL_ENCTYPE_WCS2, &vtbl_ucs2_wchar, &vtbl_wchar_ucs2, mb_ucs2_to_wchar, mb_wchar_to_ucs2be, NULL }; const mbfl_encoding mbfl_encoding_ucs2be = { mbfl_no_encoding_ucs2be, "UCS-2BE", "UCS-2BE", mbfl_encoding_ucs2be_aliases, NULL, MBFL_ENCTYPE_WCS2, &vtbl_ucs2be_wchar, &vtbl_wchar_ucs2be, mb_ucs2be_to_wchar, mb_wchar_to_ucs2be, NULL }; const mbfl_encoding mbfl_encoding_ucs2le = { mbfl_no_encoding_ucs2le, "UCS-2LE", "UCS-2LE", mbfl_encoding_ucs2le_aliases, NULL, MBFL_ENCTYPE_WCS2, &vtbl_ucs2le_wchar, &vtbl_wchar_ucs2le, mb_ucs2le_to_wchar, mb_wchar_to_ucs2le, NULL }; const struct mbfl_convert_vtbl vtbl_ucs2_wchar = { mbfl_no_encoding_ucs2, mbfl_no_encoding_wchar, mbfl_filt_conv_common_ctor, NULL, mbfl_filt_conv_ucs2_wchar, mbfl_filt_conv_ucs2_wchar_flush, NULL, }; const struct mbfl_convert_vtbl vtbl_wchar_ucs2 = { mbfl_no_encoding_wchar, mbfl_no_encoding_ucs2, mbfl_filt_conv_common_ctor, NULL, mbfl_filt_conv_wchar_ucs2be, mbfl_filt_conv_common_flush, NULL, }; const struct mbfl_convert_vtbl vtbl_ucs2be_wchar = { mbfl_no_encoding_ucs2be, mbfl_no_encoding_wchar, mbfl_filt_conv_common_ctor, NULL, mbfl_filt_conv_ucs2be_wchar, mbfl_filt_conv_ucs2_wchar_flush, NULL, }; const struct mbfl_convert_vtbl vtbl_wchar_ucs2be = { mbfl_no_encoding_wchar, mbfl_no_encoding_ucs2be, mbfl_filt_conv_common_ctor, NULL, mbfl_filt_conv_wchar_ucs2be, mbfl_filt_conv_common_flush, NULL, }; const struct mbfl_convert_vtbl vtbl_ucs2le_wchar = { mbfl_no_encoding_ucs2le, mbfl_no_encoding_wchar, mbfl_filt_conv_common_ctor, NULL, mbfl_filt_conv_ucs2le_wchar, mbfl_filt_conv_ucs2_wchar_flush, NULL, }; const struct mbfl_convert_vtbl vtbl_wchar_ucs2le = { mbfl_no_encoding_wchar, mbfl_no_encoding_ucs2le, mbfl_filt_conv_common_ctor, NULL, mbfl_filt_conv_wchar_ucs2le, mbfl_filt_conv_common_flush, NULL, }; #define CK(statement) do { if ((statement) < 0) return (-1); } while (0) int mbfl_filt_conv_ucs2_wchar(int c, mbfl_convert_filter *filter) { if (filter->status == 0) { filter->status = 1; filter->cache = c & 0xFF; } else { filter->status = 0; int n = (filter->cache << 8) | (c & 0xFF); if (n == 0xFFFE) { /* Found little-endian byte order mark */ filter->filter_function = mbfl_filt_conv_ucs2le_wchar; } else { filter->filter_function = mbfl_filt_conv_ucs2be_wchar; if (n != 0xFEFF) { CK((*filter->output_function)(n, filter->data)); } } } return 0; } int mbfl_filt_conv_ucs2be_wchar(int c, mbfl_convert_filter *filter) { if (filter->status == 0) { filter->status = 1; filter->cache = (c & 0xFF) << 8; } else { filter->status = 0; CK((*filter->output_function)((c & 0xFF) | filter->cache, filter->data)); } return 0; } int mbfl_filt_conv_wchar_ucs2be(int c, mbfl_convert_filter *filter) { if (c >= 0 && c < MBFL_WCSPLANE_UCS2MAX) { CK((*filter->output_function)((c >> 8) & 0xFF, filter->data)); CK((*filter->output_function)(c & 0xFF, filter->data)); } else { CK(mbfl_filt_conv_illegal_output(c, filter)); } return 0; } int mbfl_filt_conv_ucs2le_wchar(int c, mbfl_convert_filter *filter) { if (filter->status == 0) { filter->status = 1; filter->cache = c & 0xFF; } else { filter->status = 0; CK((*filter->output_function)(((c & 0xFF) << 8) | filter->cache, filter->data)); } return 0; } int mbfl_filt_conv_wchar_ucs2le(int c, mbfl_convert_filter *filter) { if (c >= 0 && c < MBFL_WCSPLANE_UCS2MAX) { CK((*filter->output_function)(c & 0xFF, filter->data)); CK((*filter->output_function)((c >> 8) & 0xFF, filter->data)); } else { CK(mbfl_filt_conv_illegal_output(c, filter)); } return 0; } static int mbfl_filt_conv_ucs2_wchar_flush(mbfl_convert_filter *filter) { if (filter->status) { /* Input string was truncated */ filter->status = 0; CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } if (filter->flush_function) { (*filter->flush_function)(filter->data); } return 0; } #define DETECTED_BE 1 #define DETECTED_LE 2 static size_t mb_ucs2_to_wchar(unsigned char **in, size_t *in_len, uint32_t *buf, size_t bufsize, unsigned int *state) { if (*state == DETECTED_BE) { return mb_ucs2be_to_wchar(in, in_len, buf, bufsize, NULL); } else if (*state == DETECTED_LE) { return mb_ucs2le_to_wchar(in, in_len, buf, bufsize, NULL); } else if (*in_len >= 2) { unsigned char *p = *in; unsigned char c1 = *p++; unsigned char c2 = *p++; uint32_t w = (c1 << 8) | c2; if (w == 0xFFFE) { /* Little-endian BOM */ *in = p; *in_len -= 2; *state = DETECTED_LE; return mb_ucs2le_to_wchar(in, in_len, buf, bufsize, NULL); } else if (w == 0xFEFF) { /* Big-endian BOM; don't send it to output */ *in = p; *in_len -= 2; } } *state = DETECTED_BE; return mb_ucs2be_to_wchar(in, in_len, buf, bufsize, NULL); } static size_t mb_ucs2be_to_wchar(unsigned char **in, size_t *in_len, uint32_t *buf, size_t bufsize, unsigned int *state) { unsigned char *p = *in, *e = p + (*in_len & ~1); uint32_t *out = buf, *limit = buf + bufsize; while (p < e && out < limit) { unsigned char c1 = *p++; unsigned char c2 = *p++; uint32_t w = (c1 << 8) | c2; *out++ = w; } if (p == e && (*in_len & 0x1) && out < limit) { /* There is 1 trailing byte, which shouldn't be there */ *out++ = MBFL_BAD_INPUT; p++; } *in_len -= (p - *in); *in = p; return out - buf; } static void mb_wchar_to_ucs2be(uint32_t *in, size_t len, mb_convert_buf *buf, bool end) { unsigned char *out, *limit; MB_CONVERT_BUF_LOAD(buf, out, limit); MB_CONVERT_BUF_ENSURE(buf, out, limit, len * 2); while (len--) { uint32_t w = *in++; if (w < MBFL_WCSPLANE_UCS2MAX) { out = mb_convert_buf_add2(out, (w >> 8) & 0xFF, w & 0xFF); } else { MB_CONVERT_ERROR(buf, out, limit, w, mb_wchar_to_ucs2be); MB_CONVERT_BUF_ENSURE(buf, out, limit, len * 2); } } MB_CONVERT_BUF_STORE(buf, out, limit); } static size_t mb_ucs2le_to_wchar(unsigned char **in, size_t *in_len, uint32_t *buf, size_t bufsize, unsigned int *state) { unsigned char *p = *in, *e = p + (*in_len & ~1); uint32_t *out = buf, *limit = buf + bufsize; while (p < e && out < limit) { unsigned char c1 = *p++; unsigned char c2 = *p++; uint32_t w = (c2 << 8) | c1; *out++ = w; } if (p == e && (*in_len & 0x1) && out < limit) { /* There is 1 trailing byte, which shouldn't be there */ *out++ = MBFL_BAD_INPUT; p++; } *in_len -= (p - *in); *in = p; return out - buf; } static void mb_wchar_to_ucs2le(uint32_t *in, size_t len, mb_convert_buf *buf, bool end) { unsigned char *out, *limit; MB_CONVERT_BUF_LOAD(buf, out, limit); MB_CONVERT_BUF_ENSURE(buf, out, limit, len * 2); while (len--) { uint32_t w = *in++; if (w < MBFL_WCSPLANE_UCS2MAX) { out = mb_convert_buf_add2(out, w & 0xFF, (w >> 8) & 0xFF); } else { MB_CONVERT_ERROR(buf, out, limit, w, mb_wchar_to_ucs2le); MB_CONVERT_BUF_ENSURE(buf, out, limit, len * 2); } } MB_CONVERT_BUF_STORE(buf, out, limit); }
9,286
25.534286
121
c
php-src
php-src-master/ext/mbstring/libmbfl/filters/mbfilter_ucs2.h
/* * "streamable kanji code filter and converter" * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved. * * LICENSE NOTICES * * This file is part of "streamable kanji code filter and converter", * which is distributed under the terms of GNU Lesser General Public * License (version 2) as published by the Free Software Foundation. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with "streamable kanji code filter and converter"; * if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA * * The author of this file: * */ /* * The source code included in this files was separated from mbfilter.c * by moriyoshi koizumi <[email protected]> on 4 dec 2002. * */ #ifndef MBFL_MBFILTER_UCS2_H #define MBFL_MBFILTER_UCS2_H #include "mbfilter.h" extern const mbfl_encoding mbfl_encoding_ucs2; extern const mbfl_encoding mbfl_encoding_ucs2be; extern const mbfl_encoding mbfl_encoding_ucs2le; extern const struct mbfl_convert_vtbl vtbl_ucs2_wchar; extern const struct mbfl_convert_vtbl vtbl_wchar_ucs2; extern const struct mbfl_convert_vtbl vtbl_ucs2be_wchar; extern const struct mbfl_convert_vtbl vtbl_wchar_ucs2be; extern const struct mbfl_convert_vtbl vtbl_ucs2le_wchar; extern const struct mbfl_convert_vtbl vtbl_wchar_ucs2le; int mbfl_filt_conv_ucs2_wchar(int c, mbfl_convert_filter *filter); int mbfl_filt_conv_ucs2be_wchar(int c, mbfl_convert_filter *filter); int mbfl_filt_conv_wchar_ucs2be(int c, mbfl_convert_filter *filter); int mbfl_filt_conv_ucs2le_wchar(int c, mbfl_convert_filter *filter); int mbfl_filt_conv_wchar_ucs2le(int c, mbfl_convert_filter *filter); #endif /* MBFL_MBFILTER_UCS2_H */
1,983
37.153846
72
h
php-src
php-src-master/ext/mbstring/libmbfl/filters/mbfilter_ucs4.c
/* * "streamable kanji code filter and converter" * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved. * * LICENSE NOTICES * * This file is part of "streamable kanji code filter and converter", * which is distributed under the terms of GNU Lesser General Public * License (version 2) as published by the Free Software Foundation. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with "streamable kanji code filter and converter"; * if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA * * The author of this file: * */ /* * The source code included in this file was separated from mbfilter.c * by moriyoshi koizumi <[email protected]> on 4 dec 2002. * */ #include "mbfilter.h" #include "mbfilter_ucs4.h" static size_t mb_ucs4_to_wchar(unsigned char **in, size_t *in_len, uint32_t *buf, size_t bufsize, unsigned int *state); static size_t mb_ucs4be_to_wchar(unsigned char **in, size_t *in_len, uint32_t *buf, size_t bufsize, unsigned int *state); static void mb_wchar_to_ucs4be(uint32_t *in, size_t len, mb_convert_buf *buf, bool end); static size_t mb_ucs4le_to_wchar(unsigned char **in, size_t *in_len, uint32_t *buf, size_t bufsize, unsigned int *state); static void mb_wchar_to_ucs4le(uint32_t *in, size_t len, mb_convert_buf *buf, bool end); static const char *mbfl_encoding_ucs4_aliases[] = {"ISO-10646-UCS-4", "UCS4", NULL}; /* This library historically had encodings called 'byte4be' and 'byte4le' * which were almost identical to UCS-4 * Maintain minimal support by aliasing to UCS-4 */ static const char *mbfl_encoding_ucs4be_aliases[] = {"byte4be", NULL}; static const char *mbfl_encoding_ucs4le_aliases[] = {"byte4le", NULL}; static int mbfl_filt_conv_ucs4_wchar_flush(mbfl_convert_filter *filter); const mbfl_encoding mbfl_encoding_ucs4 = { mbfl_no_encoding_ucs4, "UCS-4", "UCS-4", mbfl_encoding_ucs4_aliases, NULL, MBFL_ENCTYPE_WCS4, &vtbl_ucs4_wchar, &vtbl_wchar_ucs4, mb_ucs4_to_wchar, mb_wchar_to_ucs4be, NULL }; const mbfl_encoding mbfl_encoding_ucs4be = { mbfl_no_encoding_ucs4be, "UCS-4BE", "UCS-4BE", mbfl_encoding_ucs4be_aliases, NULL, MBFL_ENCTYPE_WCS4, &vtbl_ucs4be_wchar, &vtbl_wchar_ucs4be, mb_ucs4be_to_wchar, mb_wchar_to_ucs4be, NULL }; const mbfl_encoding mbfl_encoding_ucs4le = { mbfl_no_encoding_ucs4le, "UCS-4LE", "UCS-4LE", mbfl_encoding_ucs4le_aliases, NULL, MBFL_ENCTYPE_WCS4, &vtbl_ucs4le_wchar, &vtbl_wchar_ucs4le, mb_ucs4le_to_wchar, mb_wchar_to_ucs4le, NULL }; const struct mbfl_convert_vtbl vtbl_ucs4_wchar = { mbfl_no_encoding_ucs4, mbfl_no_encoding_wchar, mbfl_filt_conv_common_ctor, NULL, mbfl_filt_conv_ucs4_wchar, mbfl_filt_conv_ucs4_wchar_flush, NULL, }; const struct mbfl_convert_vtbl vtbl_wchar_ucs4 = { mbfl_no_encoding_wchar, mbfl_no_encoding_ucs4, mbfl_filt_conv_common_ctor, NULL, mbfl_filt_conv_wchar_ucs4be, mbfl_filt_conv_common_flush, NULL, }; const struct mbfl_convert_vtbl vtbl_ucs4be_wchar = { mbfl_no_encoding_ucs4be, mbfl_no_encoding_wchar, mbfl_filt_conv_common_ctor, NULL, mbfl_filt_conv_ucs4be_wchar, mbfl_filt_conv_ucs4_wchar_flush, NULL, }; const struct mbfl_convert_vtbl vtbl_wchar_ucs4be = { mbfl_no_encoding_wchar, mbfl_no_encoding_ucs4be, mbfl_filt_conv_common_ctor, NULL, mbfl_filt_conv_wchar_ucs4be, mbfl_filt_conv_common_flush, NULL, }; const struct mbfl_convert_vtbl vtbl_ucs4le_wchar = { mbfl_no_encoding_ucs4le, mbfl_no_encoding_wchar, mbfl_filt_conv_common_ctor, NULL, mbfl_filt_conv_ucs4le_wchar, mbfl_filt_conv_ucs4_wchar_flush, NULL, }; const struct mbfl_convert_vtbl vtbl_wchar_ucs4le = { mbfl_no_encoding_wchar, mbfl_no_encoding_ucs4le, mbfl_filt_conv_common_ctor, NULL, mbfl_filt_conv_wchar_ucs4le, mbfl_filt_conv_common_flush, NULL, }; #define CK(statement) do { if ((statement) < 0) return (-1); } while (0) /* * UCS-4 => wchar */ int mbfl_filt_conv_ucs4_wchar(int c, mbfl_convert_filter *filter) { int n, endian; endian = filter->status & 0xff00; switch (filter->status & 0xff) { case 0: if (endian) { n = c & 0xff; } else { n = (c & 0xffu) << 24; } filter->cache = n; filter->status++; break; case 1: if (endian) { n = (c & 0xff) << 8; } else { n = (c & 0xff) << 16; } filter->cache |= n; filter->status++; break; case 2: if (endian) { n = (c & 0xff) << 16; } else { n = (c & 0xff) << 8; } filter->cache |= n; filter->status++; break; default: if (endian) { n = (c & 0xffu) << 24; } else { n = c & 0xff; } n |= filter->cache; filter->status &= ~0xff; if ((n & 0xffff) == 0 && ((n >> 16) & 0xffff) == 0xfffe) { if (endian) { filter->status = 0; /* big-endian */ } else { filter->status = 0x100; /* little-endian */ } } else if (n != 0xfeff) { CK((*filter->output_function)(n, filter->data)); } break; } return 0; } /* * UCS-4BE => wchar */ int mbfl_filt_conv_ucs4be_wchar(int c, mbfl_convert_filter *filter) { int n; if (filter->status == 0) { filter->status = 1; n = (c & 0xffu) << 24; filter->cache = n; } else if (filter->status == 1) { filter->status = 2; n = (c & 0xff) << 16; filter->cache |= n; } else if (filter->status == 2) { filter->status = 3; n = (c & 0xff) << 8; filter->cache |= n; } else { filter->status = 0; n = (c & 0xff) | filter->cache; CK((*filter->output_function)(n, filter->data)); } return 0; } /* * wchar => UCS-4BE */ int mbfl_filt_conv_wchar_ucs4be(int c, mbfl_convert_filter *filter) { if (c != MBFL_BAD_INPUT) { CK((*filter->output_function)((c >> 24) & 0xff, filter->data)); CK((*filter->output_function)((c >> 16) & 0xff, filter->data)); CK((*filter->output_function)((c >> 8) & 0xff, filter->data)); CK((*filter->output_function)(c & 0xff, filter->data)); } else { CK(mbfl_filt_conv_illegal_output(c, filter)); } return 0; } /* * UCS-4LE => wchar */ int mbfl_filt_conv_ucs4le_wchar(int c, mbfl_convert_filter *filter) { int n; if (filter->status == 0) { filter->status = 1; n = (c & 0xff); filter->cache = n; } else if (filter->status == 1) { filter->status = 2; n = (c & 0xff) << 8; filter->cache |= n; } else if (filter->status == 2) { filter->status = 3; n = (c & 0xff) << 16; filter->cache |= n; } else { filter->status = 0; n = ((c & 0xffu) << 24) | filter->cache; CK((*filter->output_function)(n, filter->data)); } return 0; } /* * wchar => UCS-4LE */ int mbfl_filt_conv_wchar_ucs4le(int c, mbfl_convert_filter *filter) { if (c != MBFL_BAD_INPUT) { CK((*filter->output_function)(c & 0xff, filter->data)); CK((*filter->output_function)((c >> 8) & 0xff, filter->data)); CK((*filter->output_function)((c >> 16) & 0xff, filter->data)); CK((*filter->output_function)((c >> 24) & 0xff, filter->data)); } else { CK(mbfl_filt_conv_illegal_output(c, filter)); } return 0; } static int mbfl_filt_conv_ucs4_wchar_flush(mbfl_convert_filter *filter) { if (filter->status & 0xF) { /* Input string was truncated */ CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } filter->status = 0; if (filter->flush_function) { (*filter->flush_function)(filter->data); } return 0; } #define DETECTED_BE 1 #define DETECTED_LE 2 static size_t mb_ucs4_to_wchar(unsigned char **in, size_t *in_len, uint32_t *buf, size_t bufsize, unsigned int *state) { if (*state == DETECTED_BE) { return mb_ucs4be_to_wchar(in, in_len, buf, bufsize, NULL); } else if (*state == DETECTED_LE) { return mb_ucs4le_to_wchar(in, in_len, buf, bufsize, NULL); } else if (*in_len >= 4) { unsigned char *p = *in; uint32_t c1 = *p++; uint32_t c2 = *p++; uint32_t c3 = *p++; uint32_t c4 = *p++; uint32_t w = (c1 << 24) | (c2 << 16) | (c3 << 8) | c4; if (w == 0xFFFE0000) { /* Little-endian BOM */ *in = p; *in_len -= 4; *state = DETECTED_LE; return mb_ucs4le_to_wchar(in, in_len, buf, bufsize, NULL); } else if (w == 0xFEFF) { /* Big-endian BOM; don't send it to output */ *in = p; *in_len -= 4; } } *state = DETECTED_BE; return mb_ucs4be_to_wchar(in, in_len, buf, bufsize, NULL); } static size_t mb_ucs4be_to_wchar(unsigned char **in, size_t *in_len, uint32_t *buf, size_t bufsize, unsigned int *state) { unsigned char *p = *in, *e = p + (*in_len & ~3); uint32_t *out = buf, *limit = buf + bufsize; while (p < e && out < limit) { uint32_t c1 = *p++; uint32_t c2 = *p++; uint32_t c3 = *p++; uint32_t c4 = *p++; uint32_t w = (c1 << 24) | (c2 << 16) | (c3 << 8) | c4; *out++ = w; } if (p == e && (*in_len & 0x3) && out < limit) { /* There are 1-3 trailing bytes, which shouldn't be there */ *out++ = MBFL_BAD_INPUT; p = *in + *in_len; } *in_len -= (p - *in); *in = p; return out - buf; } static void mb_wchar_to_ucs4be(uint32_t *in, size_t len, mb_convert_buf *buf, bool end) { unsigned char *out, *limit; MB_CONVERT_BUF_LOAD(buf, out, limit); MB_CONVERT_BUF_ENSURE(buf, out, limit, len * 4); while (len--) { uint32_t w = *in++; if (w != MBFL_BAD_INPUT) { out = mb_convert_buf_add4(out, (w >> 24) & 0xFF, (w >> 16) & 0xFF, (w >> 8) & 0xFF, w & 0xFF); } else { MB_CONVERT_ERROR(buf, out, limit, w, mb_wchar_to_ucs4be); MB_CONVERT_BUF_ENSURE(buf, out, limit, len * 4); } } MB_CONVERT_BUF_STORE(buf, out, limit); } static size_t mb_ucs4le_to_wchar(unsigned char **in, size_t *in_len, uint32_t *buf, size_t bufsize, unsigned int *state) { unsigned char *p = *in, *e = p + (*in_len & ~3); uint32_t *out = buf, *limit = buf + bufsize; while (p < e && out < limit) { uint32_t c1 = *p++; uint32_t c2 = *p++; uint32_t c3 = *p++; uint32_t c4 = *p++; uint32_t w = (c4 << 24) | (c3 << 16) | (c2 << 8) | c1; *out++ = w; } if (p == e && (*in_len & 0x3) && out < limit) { /* There are 1-3 trailing bytes, which shouldn't be there */ *out++ = MBFL_BAD_INPUT; p = *in + *in_len; } *in_len -= (p - *in); *in = p; return out - buf; } static void mb_wchar_to_ucs4le(uint32_t *in, size_t len, mb_convert_buf *buf, bool end) { unsigned char *out, *limit; MB_CONVERT_BUF_LOAD(buf, out, limit); MB_CONVERT_BUF_ENSURE(buf, out, limit, len * 4); while (len--) { uint32_t w = *in++; if (w != MBFL_BAD_INPUT) { out = mb_convert_buf_add4(out, w & 0xFF, (w >> 8) & 0xFF, (w >> 16) & 0xFF, (w >> 24) & 0xFF); } else { MB_CONVERT_ERROR(buf, out, limit, w, mb_wchar_to_ucs4le); MB_CONVERT_BUF_ENSURE(buf, out, limit, len * 4); } } MB_CONVERT_BUF_STORE(buf, out, limit); }
10,795
23.704805
121
c
php-src
php-src-master/ext/mbstring/libmbfl/filters/mbfilter_ucs4.h
/* * "streamable kanji code filter and converter" * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved. * * LICENSE NOTICES * * This file is part of "streamable kanji code filter and converter", * which is distributed under the terms of GNU Lesser General Public * License (version 2) as published by the Free Software Foundation. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with "streamable kanji code filter and converter"; * if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA * * The author of this file: * */ /* * The source code included in this files was separated from mbfilter.c * by moriyoshi koizumi <[email protected]> on 4 dec 2002. * */ #ifndef MBFL_MBFILTER_UCS4_H #define MBFL_MBFILTER_UCS4_H extern const mbfl_encoding mbfl_encoding_ucs4; extern const mbfl_encoding mbfl_encoding_ucs4le; extern const mbfl_encoding mbfl_encoding_ucs4be; extern const struct mbfl_convert_vtbl vtbl_ucs4_wchar; extern const struct mbfl_convert_vtbl vtbl_wchar_ucs4; extern const struct mbfl_convert_vtbl vtbl_ucs4be_wchar; extern const struct mbfl_convert_vtbl vtbl_wchar_ucs4be; extern const struct mbfl_convert_vtbl vtbl_ucs4le_wchar; extern const struct mbfl_convert_vtbl vtbl_wchar_ucs4le; int mbfl_filt_conv_ucs4_wchar(int c, mbfl_convert_filter *filter); int mbfl_filt_conv_ucs4be_wchar(int c, mbfl_convert_filter *filter); int mbfl_filt_conv_wchar_ucs4be(int c, mbfl_convert_filter *filter); int mbfl_filt_conv_ucs4le_wchar(int c, mbfl_convert_filter *filter); int mbfl_filt_conv_wchar_ucs4le(int c, mbfl_convert_filter *filter); #endif /* MBFL_MBFILTER_UCS4_H */
1,960
38.22
72
h
php-src
php-src-master/ext/mbstring/libmbfl/filters/mbfilter_utf16.h
/* * "streamable kanji code filter and converter" * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved. * * LICENSE NOTICES * * This file is part of "streamable kanji code filter and converter", * which is distributed under the terms of GNU Lesser General Public * License (version 2) as published by the Free Software Foundation. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with "streamable kanji code filter and converter"; * if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA * * The author of this file: * */ /* * The source code included in this files was separated from mbfilter.c * by moriyoshi koizumi <[email protected]> on 4 dec 2002. * */ #ifndef MBFL_MBFILTER_UTF16_H #define MBFL_MBFILTER_UTF16_H extern const mbfl_encoding mbfl_encoding_utf16; extern const mbfl_encoding mbfl_encoding_utf16be; extern const mbfl_encoding mbfl_encoding_utf16le; extern const struct mbfl_convert_vtbl vtbl_utf16_wchar; extern const struct mbfl_convert_vtbl vtbl_wchar_utf16; extern const struct mbfl_convert_vtbl vtbl_utf16be_wchar; extern const struct mbfl_convert_vtbl vtbl_wchar_utf16be; extern const struct mbfl_convert_vtbl vtbl_utf16le_wchar; extern const struct mbfl_convert_vtbl vtbl_wchar_utf16le; int mbfl_filt_conv_utf16_wchar(int c, mbfl_convert_filter *filter); int mbfl_filt_conv_utf16be_wchar(int c, mbfl_convert_filter *filter); int mbfl_filt_conv_wchar_utf16be(int c, mbfl_convert_filter *filter); int mbfl_filt_conv_utf16le_wchar(int c, mbfl_convert_filter *filter); int mbfl_filt_conv_wchar_utf16le(int c, mbfl_convert_filter *filter); #ifdef ZEND_INTRIN_AVX2_FUNC_PTR void init_convert_utf16(void); #endif #endif /* MBFL_MBFILTER_UTF16_H */
2,050
36.290909
72
h
php-src
php-src-master/ext/mbstring/libmbfl/filters/mbfilter_utf32.c
/* * "streamable kanji code filter and converter" * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved. * * LICENSE NOTICES * * This file is part of "streamable kanji code filter and converter", * which is distributed under the terms of GNU Lesser General Public * License (version 2) as published by the Free Software Foundation. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with "streamable kanji code filter and converter"; * if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA * * The author of this file: * */ /* * The source code included in this file was separated from mbfilter.c * by moriyoshi koizumi <[email protected]> on 20 dec 2002. * */ #include "mbfilter.h" #include "mbfilter_utf32.h" static int mbfl_filt_conv_utf32_wchar_flush(mbfl_convert_filter *filter); static size_t mb_utf32_to_wchar(unsigned char **in, size_t *in_len, uint32_t *buf, size_t bufsize, unsigned int *state); static size_t mb_utf32be_to_wchar(unsigned char **in, size_t *in_len, uint32_t *buf, size_t bufsize, unsigned int *state); static void mb_wchar_to_utf32be(uint32_t *in, size_t len, mb_convert_buf *buf, bool end); static size_t mb_utf32le_to_wchar(unsigned char **in, size_t *in_len, uint32_t *buf, size_t bufsize, unsigned int *state); static void mb_wchar_to_utf32le(uint32_t *in, size_t len, mb_convert_buf *buf, bool end); static const char *mbfl_encoding_utf32_aliases[] = {"utf32", NULL}; const mbfl_encoding mbfl_encoding_utf32 = { mbfl_no_encoding_utf32, "UTF-32", "UTF-32", mbfl_encoding_utf32_aliases, NULL, MBFL_ENCTYPE_WCS4, &vtbl_utf32_wchar, &vtbl_wchar_utf32, mb_utf32_to_wchar, mb_wchar_to_utf32be, NULL }; const mbfl_encoding mbfl_encoding_utf32be = { mbfl_no_encoding_utf32be, "UTF-32BE", "UTF-32BE", NULL, NULL, MBFL_ENCTYPE_WCS4, &vtbl_utf32be_wchar, &vtbl_wchar_utf32be, mb_utf32be_to_wchar, mb_wchar_to_utf32be, NULL }; const mbfl_encoding mbfl_encoding_utf32le = { mbfl_no_encoding_utf32le, "UTF-32LE", "UTF-32LE", NULL, NULL, MBFL_ENCTYPE_WCS4, &vtbl_utf32le_wchar, &vtbl_wchar_utf32le, mb_utf32le_to_wchar, mb_wchar_to_utf32le, NULL }; const struct mbfl_convert_vtbl vtbl_utf32_wchar = { mbfl_no_encoding_utf32, mbfl_no_encoding_wchar, mbfl_filt_conv_common_ctor, NULL, mbfl_filt_conv_utf32_wchar, mbfl_filt_conv_utf32_wchar_flush, NULL, }; const struct mbfl_convert_vtbl vtbl_wchar_utf32 = { mbfl_no_encoding_wchar, mbfl_no_encoding_utf32, mbfl_filt_conv_common_ctor, NULL, mbfl_filt_conv_wchar_utf32be, mbfl_filt_conv_common_flush, NULL, }; const struct mbfl_convert_vtbl vtbl_utf32be_wchar = { mbfl_no_encoding_utf32be, mbfl_no_encoding_wchar, mbfl_filt_conv_common_ctor, NULL, mbfl_filt_conv_utf32be_wchar, mbfl_filt_conv_utf32_wchar_flush, NULL, }; const struct mbfl_convert_vtbl vtbl_wchar_utf32be = { mbfl_no_encoding_wchar, mbfl_no_encoding_utf32be, mbfl_filt_conv_common_ctor, NULL, mbfl_filt_conv_wchar_utf32be, mbfl_filt_conv_common_flush, NULL, }; const struct mbfl_convert_vtbl vtbl_utf32le_wchar = { mbfl_no_encoding_utf32le, mbfl_no_encoding_wchar, mbfl_filt_conv_common_ctor, NULL, mbfl_filt_conv_utf32le_wchar, mbfl_filt_conv_utf32_wchar_flush, NULL, }; const struct mbfl_convert_vtbl vtbl_wchar_utf32le = { mbfl_no_encoding_wchar, mbfl_no_encoding_utf32le, mbfl_filt_conv_common_ctor, NULL, mbfl_filt_conv_wchar_utf32le, mbfl_filt_conv_common_flush, NULL, }; #define CK(statement) do { if ((statement) < 0) return (-1); } while (0) static int emit_char_if_valid(int n, mbfl_convert_filter *filter) { if (n >= 0 && n < MBFL_WCSPLANE_UTF32MAX && (n < 0xD800 || n > 0xDFFF)) { CK((*filter->output_function)(n, filter->data)); } else { CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } return 0; } int mbfl_filt_conv_utf32_wchar(int c, mbfl_convert_filter *filter) { if (filter->status < 3) { filter->cache = (filter->cache << 8) | (c & 0xFF); filter->status++; } else { int n = ((unsigned int)filter->cache << 8) | (c & 0xFF); filter->cache = filter->status = 0; if (n == 0xFFFE0000) { /* Found a little-endian byte order mark */ filter->filter_function = mbfl_filt_conv_utf32le_wchar; } else { filter->filter_function = mbfl_filt_conv_utf32be_wchar; if (n != 0xFEFF) { CK(emit_char_if_valid(n, filter)); } } } return 0; } int mbfl_filt_conv_utf32be_wchar(int c, mbfl_convert_filter *filter) { if (filter->status < 3) { filter->cache = (filter->cache << 8) | (c & 0xFF); filter->status++; } else { int n = ((unsigned int)filter->cache << 8) | (c & 0xFF); filter->cache = filter->status = 0; CK(emit_char_if_valid(n, filter)); } return 0; } int mbfl_filt_conv_wchar_utf32be(int c, mbfl_convert_filter *filter) { if (c >= 0 && c < MBFL_WCSPLANE_UTF32MAX) { CK((*filter->output_function)((c >> 24) & 0xff, filter->data)); CK((*filter->output_function)((c >> 16) & 0xff, filter->data)); CK((*filter->output_function)((c >> 8) & 0xff, filter->data)); CK((*filter->output_function)(c & 0xff, filter->data)); } else { CK(mbfl_filt_conv_illegal_output(c, filter)); } return 0; } int mbfl_filt_conv_utf32le_wchar(int c, mbfl_convert_filter *filter) { if (filter->status < 3) { filter->cache |= ((c & 0xFFU) << (8 * filter->status)); filter->status++; } else { int n = ((c & 0xFFU) << 24) | filter->cache; filter->cache = filter->status = 0; CK(emit_char_if_valid(n, filter)); } return 0; } int mbfl_filt_conv_wchar_utf32le(int c, mbfl_convert_filter *filter) { if (c >= 0 && c < MBFL_WCSPLANE_UTF32MAX) { CK((*filter->output_function)(c & 0xff, filter->data)); CK((*filter->output_function)((c >> 8) & 0xff, filter->data)); CK((*filter->output_function)((c >> 16) & 0xff, filter->data)); CK((*filter->output_function)((c >> 24) & 0xff, filter->data)); } else { CK(mbfl_filt_conv_illegal_output(c, filter)); } return 0; } static int mbfl_filt_conv_utf32_wchar_flush(mbfl_convert_filter *filter) { if (filter->status) { /* Input string was truncated */ CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } filter->cache = filter->status = 0; if (filter->flush_function) { (*filter->flush_function)(filter->data); } return 0; } #define DETECTED_BE 1 #define DETECTED_LE 2 static size_t mb_utf32_to_wchar(unsigned char **in, size_t *in_len, uint32_t *buf, size_t bufsize, unsigned int *state) { if (*state == DETECTED_BE) { return mb_utf32be_to_wchar(in, in_len, buf, bufsize, NULL); } else if (*state == DETECTED_LE) { return mb_utf32le_to_wchar(in, in_len, buf, bufsize, NULL); } else if (*in_len >= 4) { unsigned char *p = *in; uint32_t c1 = *p++; uint32_t c2 = *p++; uint32_t c3 = *p++; uint32_t c4 = *p++; uint32_t w = (c1 << 24) | (c2 << 16) | (c3 << 8) | c4; if (w == 0xFFFE0000) { /* Little-endian BOM */ *in = p; *in_len -= 4; *state = DETECTED_LE; return mb_utf32le_to_wchar(in, in_len, buf, bufsize, NULL); } else if (w == 0xFEFF) { /* Big-endian BOM; don't send it to output */ *in = p; *in_len -= 4; } } *state = DETECTED_BE; return mb_utf32be_to_wchar(in, in_len, buf, bufsize, NULL); } static size_t mb_utf32be_to_wchar(unsigned char **in, size_t *in_len, uint32_t *buf, size_t bufsize, unsigned int *state) { unsigned char *p = *in, *e = p + (*in_len & ~3); uint32_t *out = buf, *limit = buf + bufsize; while (p < e && out < limit) { uint32_t c1 = *p++; uint32_t c2 = *p++; uint32_t c3 = *p++; uint32_t c4 = *p++; uint32_t w = (c1 << 24) | (c2 << 16) | (c3 << 8) | c4; if (w < MBFL_WCSPLANE_UTF32MAX && (w < 0xD800 || w > 0xDFFF)) { *out++ = w; } else { *out++ = MBFL_BAD_INPUT; } } if (p == e && (*in_len & 0x3) && out < limit) { /* There are 1-3 trailing bytes, which shouldn't be there */ *out++ = MBFL_BAD_INPUT; p = *in + *in_len; } *in_len -= (p - *in); *in = p; return out - buf; } static void mb_wchar_to_utf32be(uint32_t *in, size_t len, mb_convert_buf *buf, bool end) { unsigned char *out, *limit; MB_CONVERT_BUF_LOAD(buf, out, limit); MB_CONVERT_BUF_ENSURE(buf, out, limit, len * 4); while (len--) { uint32_t w = *in++; if (w < MBFL_WCSPLANE_UTF32MAX) { out = mb_convert_buf_add4(out, (w >> 24) & 0xFF, (w >> 16) & 0xFF, (w >> 8) & 0xFF, w & 0xFF); } else { MB_CONVERT_ERROR(buf, out, limit, w, mb_wchar_to_utf32be); MB_CONVERT_BUF_ENSURE(buf, out, limit, len * 4); } } MB_CONVERT_BUF_STORE(buf, out, limit); } static size_t mb_utf32le_to_wchar(unsigned char **in, size_t *in_len, uint32_t *buf, size_t bufsize, unsigned int *state) { unsigned char *p = *in, *e = p + (*in_len & ~3); uint32_t *out = buf, *limit = buf + bufsize; while (p < e && out < limit) { uint32_t c1 = *p++; uint32_t c2 = *p++; uint32_t c3 = *p++; uint32_t c4 = *p++; uint32_t w = (c4 << 24) | (c3 << 16) | (c2 << 8) | c1; if (w < MBFL_WCSPLANE_UTF32MAX && (w < 0xD800 || w > 0xDFFF)) { *out++ = w; } else { *out++ = MBFL_BAD_INPUT; } } if (p == e && (*in_len & 0x3) && out < limit) { /* There are 1-3 trailing bytes, which shouldn't be there */ *out++ = MBFL_BAD_INPUT; p = *in + *in_len; } *in_len -= (p - *in); *in = p; return out - buf; } static void mb_wchar_to_utf32le(uint32_t *in, size_t len, mb_convert_buf *buf, bool end) { unsigned char *out, *limit; MB_CONVERT_BUF_LOAD(buf, out, limit); MB_CONVERT_BUF_ENSURE(buf, out, limit, len * 4); while (len--) { uint32_t w = *in++; if (w < MBFL_WCSPLANE_UTF32MAX) { out = mb_convert_buf_add4(out, w & 0xFF, (w >> 8) & 0xFF, (w >> 16) & 0xFF, (w >> 24) & 0xFF); } else { MB_CONVERT_ERROR(buf, out, limit, w, mb_wchar_to_utf32le); MB_CONVERT_BUF_ENSURE(buf, out, limit, len * 4); } } MB_CONVERT_BUF_STORE(buf, out, limit); }
10,115
25.691293
122
c
php-src
php-src-master/ext/mbstring/libmbfl/filters/mbfilter_utf32.h
/* * "streamable kanji code filter and converter" * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved. * * LICENSE NOTICES * * This file is part of "streamable kanji code filter and converter", * which is distributed under the terms of GNU Lesser General Public * License (version 2) as published by the Free Software Foundation. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with "streamable kanji code filter and converter"; * if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA * * The author of this file: * */ /* * The source code included in this files was separated from mbfilter.c * by moriyoshi koizumi <[email protected]> on 20 dec 2002. * */ #ifndef MBFL_MBFILTER_UTF32_H #define MBFL_MBFILTER_UTF32_H extern const mbfl_encoding mbfl_encoding_utf32; extern const mbfl_encoding mbfl_encoding_utf32be; extern const mbfl_encoding mbfl_encoding_utf32le; extern const struct mbfl_convert_vtbl vtbl_utf32_wchar; extern const struct mbfl_convert_vtbl vtbl_wchar_utf32; extern const struct mbfl_convert_vtbl vtbl_utf32be_wchar; extern const struct mbfl_convert_vtbl vtbl_wchar_utf32be; extern const struct mbfl_convert_vtbl vtbl_utf32le_wchar; extern const struct mbfl_convert_vtbl vtbl_wchar_utf32le; int mbfl_filt_conv_utf32_wchar(int c, mbfl_convert_filter *filter); int mbfl_filt_conv_utf32be_wchar(int c, mbfl_convert_filter *filter); int mbfl_filt_conv_wchar_utf32be(int c, mbfl_convert_filter *filter); int mbfl_filt_conv_utf32le_wchar(int c, mbfl_convert_filter *filter); int mbfl_filt_conv_wchar_utf32le(int c, mbfl_convert_filter *filter); #endif /* MBFL_MBFILTER_UTF32_H */
1,979
37.823529
72
h
php-src
php-src-master/ext/mbstring/libmbfl/filters/mbfilter_utf7.h
/* * "streamable kanji code filter and converter" * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved. * * LICENSE NOTICES * * This file is part of "streamable kanji code filter and converter", * which is distributed under the terms of GNU Lesser General Public * License (version 2) as published by the Free Software Foundation. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with "streamable kanji code filter and converter"; * if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA * * The author of this file: * */ /* * The source code included in this files was separated from mbfilter.c * by moriyoshi koizumi <[email protected]> on 4 dec 2002. * */ #ifndef MBFL_MBFILTER_UTF7_H #define MBFL_MBFILTER_UTF7_H #include "mbfilter.h" extern const mbfl_encoding mbfl_encoding_utf7; extern const struct mbfl_convert_vtbl vtbl_utf7_wchar; extern const struct mbfl_convert_vtbl vtbl_wchar_utf7; int mbfl_filt_conv_utf7_wchar(int c, mbfl_convert_filter *filter); int mbfl_filt_conv_wchar_utf7(int c, mbfl_convert_filter *filter); int mbfl_filt_conv_wchar_utf7_flush(mbfl_convert_filter *filter); #endif /* MBFL_MBFILTER_UTF7_H */
1,514
33.431818
72
h
php-src
php-src-master/ext/mbstring/libmbfl/filters/mbfilter_utf7imap.h
/* * "streamable kanji code filter and converter" * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved. * * LICENSE NOTICES * * This file is part of "streamable kanji code filter and converter", * which is distributed under the terms of GNU Lesser General Public * License (version 2) as published by the Free Software Foundation. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with "streamable kanji code filter and converter"; * if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA * * The author of this file: * */ /* * The source code included in this files was separated from mbfilter.c * by moriyoshi koizumi <[email protected]> on 4 dec 2002. * */ #ifndef MBFL_MBFILTER_UTF7IMAP_H #define MBFL_MBFILTER_UTF7IMAP_H #include "mbfilter.h" extern const mbfl_encoding mbfl_encoding_utf7imap; extern const struct mbfl_convert_vtbl vtbl_utf7imap_wchar; extern const struct mbfl_convert_vtbl vtbl_wchar_utf7imap; int mbfl_filt_conv_utf7imap_wchar(int c, mbfl_convert_filter *filter); int mbfl_filt_conv_wchar_utf7imap(int c, mbfl_convert_filter *filter); #endif /* MBFL_MBFILTER_UTF7IMAP_H */
1,480
33.44186
72
h
php-src
php-src-master/ext/mbstring/libmbfl/filters/mbfilter_utf8.c
/* * "streamable kanji code filter and converter" * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved. * * LICENSE NOTICES * * This file is part of "streamable kanji code filter and converter", * which is distributed under the terms of GNU Lesser General Public * License (version 2) as published by the Free Software Foundation. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with "streamable kanji code filter and converter"; * if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA * * The author of this file: * */ /* * The source code included in this files was separated from mbfilter.c * by moriyoshi koizumi <[email protected]> on 4 dec 2002. * */ #include "mbfilter.h" #include "mbfilter_utf8.h" const unsigned char mblen_table_utf8[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; static size_t mb_utf8_to_wchar(unsigned char **in, size_t *in_len, uint32_t *buf, size_t bufsize, unsigned int *state); static void mb_wchar_to_utf8(uint32_t *in, size_t len, mb_convert_buf *buf, bool end); static const char *mbfl_encoding_utf8_aliases[] = {"utf8", NULL}; const mbfl_encoding mbfl_encoding_utf8 = { mbfl_no_encoding_utf8, "UTF-8", "UTF-8", mbfl_encoding_utf8_aliases, mblen_table_utf8, 0, &vtbl_utf8_wchar, &vtbl_wchar_utf8, mb_utf8_to_wchar, mb_wchar_to_utf8, NULL }; const struct mbfl_convert_vtbl vtbl_utf8_wchar = { mbfl_no_encoding_utf8, mbfl_no_encoding_wchar, mbfl_filt_conv_common_ctor, NULL, mbfl_filt_conv_utf8_wchar, mbfl_filt_conv_utf8_wchar_flush, NULL, }; const struct mbfl_convert_vtbl vtbl_wchar_utf8 = { mbfl_no_encoding_wchar, mbfl_no_encoding_utf8, mbfl_filt_conv_common_ctor, NULL, mbfl_filt_conv_wchar_utf8, mbfl_filt_conv_common_flush, NULL, }; #define CK(statement) do { if ((statement) < 0) return (-1); } while (0) int mbfl_filt_put_invalid_char(mbfl_convert_filter *filter) { filter->status = filter->cache = 0; CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); return 0; } int mbfl_filt_conv_utf8_wchar(int c, mbfl_convert_filter *filter) { int s, c1; retry: switch (filter->status) { case 0x00: if (c < 0x80) { CK((*filter->output_function)(c, filter->data)); } else if (c >= 0xc2 && c <= 0xdf) { /* 2byte code first char: 0xc2-0xdf */ filter->status = 0x10; filter->cache = c & 0x1f; } else if (c >= 0xe0 && c <= 0xef) { /* 3byte code first char: 0xe0-0xef */ filter->status = 0x20; filter->cache = c & 0xf; } else if (c >= 0xf0 && c <= 0xf4) { /* 3byte code first char: 0xf0-0xf4 */ filter->status = 0x30; filter->cache = c & 0x7; } else { CK(mbfl_filt_put_invalid_char(filter)); } break; case 0x10: /* 2byte code 2nd char: 0x80-0xbf */ case 0x21: /* 3byte code 3rd char: 0x80-0xbf */ case 0x32: /* 4byte code 4th char: 0x80-0xbf */ if (c >= 0x80 && c <= 0xbf) { s = (filter->cache<<6) | (c & 0x3f); filter->status = filter->cache = 0; CK((*filter->output_function)(s, filter->data)); } else { CK(mbfl_filt_put_invalid_char(filter)); goto retry; } break; case 0x20: /* 3byte code 2nd char: 0:0xa0-0xbf,D:0x80-9F,1-C,E-F:0x80-0x9f */ s = (filter->cache<<6) | (c & 0x3f); c1 = filter->cache & 0xf; if ((c >= 0x80 && c <= 0xbf) && ((c1 == 0x0 && c >= 0xa0) || (c1 == 0xd && c < 0xa0) || (c1 > 0x0 && c1 != 0xd))) { filter->cache = s; filter->status++; } else { CK(mbfl_filt_put_invalid_char(filter)); goto retry; } break; case 0x30: /* 4byte code 2nd char: 0:0x90-0xbf,1-3:0x80-0xbf,4:0x80-0x8f */ s = (filter->cache<<6) | (c & 0x3f); c1 = filter->cache & 0x7; if ((c >= 0x80 && c <= 0xbf) && ((c1 == 0x0 && c >= 0x90) || (c1 == 0x4 && c < 0x90) || (c1 > 0x0 && c1 != 0x4))) { filter->cache = s; filter->status++; } else { CK(mbfl_filt_put_invalid_char(filter)); goto retry; } break; case 0x31: /* 4byte code 3rd char: 0x80-0xbf */ if (c >= 0x80 && c <= 0xbf) { filter->cache = (filter->cache<<6) | (c & 0x3f); filter->status++; } else { CK(mbfl_filt_put_invalid_char(filter)); goto retry; } break; EMPTY_SWITCH_DEFAULT_CASE(); } return 0; } int mbfl_filt_conv_utf8_wchar_flush(mbfl_convert_filter *filter) { if (filter->status) { (*filter->output_function)(MBFL_BAD_INPUT, filter->data); filter->status = 0; } if (filter->flush_function) { (*filter->flush_function)(filter->data); } return 0; } int mbfl_filt_conv_wchar_utf8(int c, mbfl_convert_filter *filter) { if (c >= 0 && c < 0x110000) { if (c < 0x80) { CK((*filter->output_function)(c, filter->data)); } else if (c < 0x800) { CK((*filter->output_function)(((c >> 6) & 0x1f) | 0xc0, filter->data)); CK((*filter->output_function)((c & 0x3f) | 0x80, filter->data)); } else if (c < 0x10000) { CK((*filter->output_function)(((c >> 12) & 0x0f) | 0xe0, filter->data)); CK((*filter->output_function)(((c >> 6) & 0x3f) | 0x80, filter->data)); CK((*filter->output_function)((c & 0x3f) | 0x80, filter->data)); } else { CK((*filter->output_function)(((c >> 18) & 0x07) | 0xf0, filter->data)); CK((*filter->output_function)(((c >> 12) & 0x3f) | 0x80, filter->data)); CK((*filter->output_function)(((c >> 6) & 0x3f) | 0x80, filter->data)); CK((*filter->output_function)((c & 0x3f) | 0x80, filter->data)); } } else { CK(mbfl_filt_conv_illegal_output(c, filter)); } return 0; } static size_t mb_utf8_to_wchar(unsigned char **in, size_t *in_len, uint32_t *buf, size_t bufsize, unsigned int *state) { unsigned char *p = *in, *e = p + *in_len; uint32_t *out = buf, *limit = buf + bufsize; while (p < e && out < limit) { unsigned char c = *p++; if (c < 0x80) { *out++ = c; } else if (c < 0xC2) { *out++ = MBFL_BAD_INPUT; } else if (c <= 0xDF) { /* 2 byte character */ if (p < e) { unsigned char c2 = *p++; if ((c2 & 0xC0) != 0x80) { *out++ = MBFL_BAD_INPUT; p--; } else { *out++ = ((c & 0x1F) << 6) | (c2 & 0x3F); } } else { *out++ = MBFL_BAD_INPUT; } } else if (c <= 0xEF) { /* 3 byte character */ if ((e - p) >= 2) { unsigned char c2 = *p++; unsigned char c3 = *p++; if ((c2 & 0xC0) != 0x80 || (c == 0xE0 && c2 < 0xA0) || (c == 0xED && c2 >= 0xA0)) { *out++ = MBFL_BAD_INPUT; p -= 2; } else if ((c3 & 0xC0) != 0x80) { *out++ = MBFL_BAD_INPUT; p--; } else { uint32_t decoded = ((c & 0xF) << 12) | ((c2 & 0x3F) << 6) | (c3 & 0x3F); ZEND_ASSERT(decoded >= 0x800); /* Not an overlong code unit */ ZEND_ASSERT(decoded < 0xD800 || decoded > 0xDFFF); /* U+D800-DFFF are reserved, illegal code points */ *out++ = decoded; } } else { *out++ = MBFL_BAD_INPUT; if (p < e && (c != 0xE0 || *p >= 0xA0) && (c != 0xED || *p < 0xA0) && (*p & 0xC0) == 0x80) { p++; if (p < e && (*p & 0xC0) == 0x80) { p++; } } } } else if (c <= 0xF4) { /* 4 byte character */ if ((e - p) >= 3) { unsigned char c2 = *p++; unsigned char c3 = *p++; unsigned char c4 = *p++; /* If c == 0xF0 and c2 < 0x90, then this is an over-long code unit; it could have * fit in 3 bytes only. If c == 0xF4 and c2 >= 0x90, then this codepoint is * greater than U+10FFFF, which is the highest legal codepoint */ if ((c2 & 0xC0) != 0x80 || (c == 0xF0 && c2 < 0x90) || (c == 0xF4 && c2 >= 0x90)) { *out++ = MBFL_BAD_INPUT; p -= 3; } else if ((c3 & 0xC0) != 0x80) { *out++ = MBFL_BAD_INPUT; p -= 2; } else if ((c4 & 0xC0) != 0x80) { *out++ = MBFL_BAD_INPUT; p--; } else { uint32_t decoded = ((c & 0x7) << 18) | ((c2 & 0x3F) << 12) | ((c3 & 0x3F) << 6) | (c4 & 0x3F); ZEND_ASSERT(decoded >= 0x10000); /* Not an overlong code unit */ *out++ = decoded; } } else { *out++ = MBFL_BAD_INPUT; if (p < e) { unsigned char c2 = *p; if ((c == 0xF0 && c2 >= 0x90) || (c == 0xF4 && c2 < 0x90) || (c >= 0xF1 && c <= 0xF3)) { while (p < e && (*p & 0xC0) == 0x80) { p++; } } } } } else { *out++ = MBFL_BAD_INPUT; } } *in_len = e - p; *in = p; return out - buf; } static void mb_wchar_to_utf8(uint32_t *in, size_t len, mb_convert_buf *buf, bool end) { unsigned char *out, *limit; MB_CONVERT_BUF_LOAD(buf, out, limit); MB_CONVERT_BUF_ENSURE(buf, out, limit, len); while (len--) { uint32_t w = *in++; if (w < 0x80) { out = mb_convert_buf_add(out, w & 0xFF); } else if (w < 0x800) { MB_CONVERT_BUF_ENSURE(buf, out, limit, len + 2); out = mb_convert_buf_add2(out, ((w >> 6) & 0x1F) | 0xC0, (w & 0x3F) | 0x80); } else if (w < 0x10000) { MB_CONVERT_BUF_ENSURE(buf, out, limit, len + 3); out = mb_convert_buf_add3(out, ((w >> 12) & 0xF) | 0xE0, ((w >> 6) & 0x3F) | 0x80, (w & 0x3F) | 0x80); } else if (w < 0x110000) { MB_CONVERT_BUF_ENSURE(buf, out, limit, len + 4); out = mb_convert_buf_add4(out, ((w >> 18) & 0x7) | 0xF0, ((w >> 12) & 0x3F) | 0x80, ((w >> 6) & 0x3F) | 0x80, (w & 0x3F) | 0x80); } else { MB_CONVERT_ERROR(buf, out, limit, w, mb_wchar_to_utf8); MB_CONVERT_BUF_ENSURE(buf, out, limit, len); } } MB_CONVERT_BUF_STORE(buf, out, limit); }
10,234
29.281065
132
c
php-src
php-src-master/ext/mbstring/libmbfl/filters/mbfilter_utf8.h
/* * "streamable kanji code filter and converter" * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved. * * LICENSE NOTICES * * This file is part of "streamable kanji code filter and converter", * which is distributed under the terms of GNU Lesser General Public * License (version 2) as published by the Free Software Foundation. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with "streamable kanji code filter and converter"; * if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA * * The author of this file: * */ /* * The source code included in this files was separated from mbfilter.c * by moriyoshi koizumi <[email protected]> on 4 dec 2002. * */ #ifndef MBFL_MBFILTER_UTF8_H #define MBFL_MBFILTER_UTF8_H extern const mbfl_encoding mbfl_encoding_utf8; extern const struct mbfl_convert_vtbl vtbl_utf8_wchar; extern const struct mbfl_convert_vtbl vtbl_wchar_utf8; int mbfl_filt_conv_utf8_wchar(int c, mbfl_convert_filter *filter); int mbfl_filt_conv_wchar_utf8(int c, mbfl_convert_filter *filter); int mbfl_filt_conv_utf8_wchar_flush(mbfl_convert_filter *filter); #endif /* MBFL_MBFILTER_UTF8_H */
1,491
34.52381
72
h
php-src
php-src-master/ext/mbstring/libmbfl/filters/mbfilter_utf8_mobile.h
/* * "streamable kanji code filter and converter" * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved. * * LICENSE NOTICES * * This file is part of "streamable kanji code filter and converter", * which is distributed under the terms of GNU Lesser General Public * License (version 2) as published by the Free Software Foundation. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with "streamable kanji code filter and converter"; * if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA * * The author of this file: * */ /* * The source code included in this files was separated from mbfilter.c * by rui hrokawa <[email protected]> on 8 aug 2011. * */ #ifndef MBFL_MBFILTER_UTF8_MOBILE_H #define MBFL_MBFILTER_UTF8_MOBILE_H extern const mbfl_encoding mbfl_encoding_utf8_docomo; extern const mbfl_encoding mbfl_encoding_utf8_kddi_a; extern const mbfl_encoding mbfl_encoding_utf8_kddi_b; extern const mbfl_encoding mbfl_encoding_utf8_sb; extern const struct mbfl_convert_vtbl vtbl_utf8_docomo_wchar; extern const struct mbfl_convert_vtbl vtbl_wchar_utf8_docomo; extern const struct mbfl_convert_vtbl vtbl_utf8_kddi_a_wchar; extern const struct mbfl_convert_vtbl vtbl_wchar_utf8_kddi_a; extern const struct mbfl_convert_vtbl vtbl_utf8_kddi_b_wchar; extern const struct mbfl_convert_vtbl vtbl_wchar_utf8_kddi_b; extern const struct mbfl_convert_vtbl vtbl_utf8_sb_wchar; extern const struct mbfl_convert_vtbl vtbl_wchar_utf8_sb; int mbfl_filt_conv_utf8_mobile_wchar(int c, mbfl_convert_filter *filter); int mbfl_filt_conv_wchar_utf8_mobile(int c, mbfl_convert_filter *filter); #endif /* MBFL_MBFILTER_UTF8_MOBILE_H */
1,999
36.735849
73
h
php-src
php-src-master/ext/mbstring/libmbfl/filters/mbfilter_uuencode.h
/* * "streamable kanji code filter and converter" * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved. * * LICENSE NOTICES * * This file is part of "streamable kanji code filter and converter", * which is distributed under the terms of GNU Lesser General Public * License (version 2) as published by the Free Software Foundation. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with "streamable kanji code filter and converter"; * if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA * * The author of this file: * */ /* * The source code included in this files was separated from mbfilter.c * by moriyoshi koizumi <[email protected]> on 4 dec 2002. * */ #ifndef MBFL_MBFILTER_UUENCODE_H #define MBFL_MBFILTER_UUENCODE_H extern const mbfl_encoding mbfl_encoding_uuencode; extern const struct mbfl_convert_vtbl vtbl_uuencode_8bit; int mbfl_filt_conv_uudec(int c, mbfl_convert_filter *filter); #endif /* MBFL_MBFILTER_UUENCODE_H */
1,317
32.794872
72
h
php-src
php-src-master/ext/mbstring/libmbfl/filters/sjis_mac2uni.h
static const unsigned short sjis_mac2wchar1[] = { // 0x03ac - 0x03c9 0x339c, 0x339f, 0x339d, 0x33a0, 0x33a4, 0xff4d, 0x33a1, 0x33a5, 0x339e, 0x33a2, 0x338e, 0xff47, 0x338f, 0x33c4, 0x3396, 0x3397, 0x2113, 0x3398, 0x33b3, 0x33b2, 0x33b1, 0x33b0, 0x2109, 0x33d4, 0x33cb, 0x3390, 0x3385, 0x3386, 0x3387, 0xf860, }; static const unsigned short sjis_mac2wchar2[] = { // 0x0406 - 0x0420 0x2116, 0x33cd, 0x2121, 0xf861, 0x2664, 0x2667, 0x2661, 0x2662, 0x2660, 0x2663, 0x2665, 0x2666, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x3020, 0x260e, 0x3004, }; static const unsigned short sjis_mac2wchar3[] = { // 0x0432 - 0x0441 0x261e, 0x261c, 0x261d, 0x261f, 0x21c6, 0x21c4, 0x21c5, 0xf860, 0x21e8, 0x21e6, 0x21e7, 0x21e9, 0x21e8, 0x21e6, 0x21e7, 0x21e9, }; static const unsigned short sjis_mac2wchar4[] = { // 0x0468 - 0x0480 0x3230, 0x322a, 0x322b, 0x322c, 0x322d, 0x322e, 0x322f, 0x3240, 0x3237, 0x3242, 0x3243, 0x3239, 0x323a, 0x3231, 0x323e, 0x3234, 0x3232, 0x323b, 0x3236, 0x3233, 0x3235, 0x323c, 0x323d, 0x323f, 0x3238, }; static const unsigned short sjis_mac2wchar5[] = { // 0x04b8 - 0x04e8 0x5927, 0x5c0f, 0x32a4, 0x32a5, 0x32a6, 0x32a7, 0x32a8, 0x32a9, 0x3296, 0x329d, 0x3298, 0x329e, 0x63a7, 0x3299, 0x3349, 0x3322, 0x334d, 0x3314, 0x3316, 0x3305, 0x3333, 0x334e, 0x3303, 0x3336, 0x3318, 0x3315, 0x3327, 0x3351, 0x334a, 0x3339, 0x3357, 0x330d, 0x3342, 0x3323, 0x3326, 0x333b, 0x332b, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x3300, 0x331e, 0x332a, 0x3331, 0x3347, }; static const unsigned short sjis_mac2wchar6[] = { // 0x050c - 0x0551 0x337e, 0x337d, 0x337c, 0x337b, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x337f, 0xf862, 0xf862, 0x222e, 0x221f, 0x22bf, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x301d, 0x301f, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x3094, 0x0000, 0x30f7, 0x30f8, 0x30f9, 0x30fa, }; static const unsigned short sjis_mac2wchar7[] = { // 0x1ed9 - 0x1f18 0x3001, 0x3002, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xffe3, 0xfe33, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x30fc, 0xfe31, 0x2010, 0x0000, 0x0000, 0x301c, 0x2016, 0xff5c, 0x2026, 0xfe30, 0x0000, 0x0000, 0x0000, 0x0000, 0xfe35, 0xfe36, 0xfe39, 0xfe3a, 0xff3b, 0xff3d, 0xfe37, 0xfe38, 0xfe3f, 0xfe40, 0xfe3d, 0xfe3e, 0xfe41, 0xfe42, 0xfe43, 0xfe44, 0xfe3b, 0xfe3c, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xff1d, }; static const unsigned short sjis_mac2wchar8[] = { // 0x1ff2 - 0x20a5 0x3041, 0x0000, 0x3043, 0x0000, 0x3045, 0x0000, 0x3047, 0x0000, 0x3049, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x3063, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x3083, 0x0000, 0x3085, 0x0000, 0x3087, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x308e, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x30a1, 0x0000, 0x30a3, 0x0000, 0x30a5, 0x0000, 0x30a7, 0x0000, 0x30a9, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x30c3, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x30e3, 0x0000, 0x30e5, 0x0000, 0x30e7, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x30ee, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x30f5, 0x30f6, }; static const unsigned short wchar2sjis_mac4[] = { // 0x2660 - 0x2667 0x040e, 0x040c, 0x040d, 0x040f, 0x040a, 0x0410, 0x0411, 0x040b, }; static const unsigned short wchar2sjis_mac7[] = { // 0x322a - 0x3243 0x0469, 0x046a, 0x046b, 0x046c, 0x046d, 0x046e, 0x0468, 0x0475, 0x0478, 0x047b, 0x0477, 0x047c, 0x047a, 0x0470, 0x0480, 0x0473, 0x0474, 0x0479, 0x047d, 0x047e, 0x0476, 0x047f, 0x046f, 0x0000, 0x0471, 0x0472, }; static const unsigned short wchar2sjis_mac8[] = { // 0x3296 - 0x329e 0x04c0, 0x0000, 0x04c2, 0x04c5, 0x0000, 0x0000, 0x0000, 0x04c1, 0x04c3, }; static const unsigned short wchar2sjis_mac9[] = { // 0x3300 - 0x33d4 0x04e4, 0x0000, 0x0000, 0x04ce, 0x0000, 0x04cb, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x04d7, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x04c9, 0x04d1, 0x04ca, 0x0000, 0x04d0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x04e5, 0x0000, 0x0000, 0x0000, 0x04c7, 0x04d9, 0x0000, 0x0000, 0x04da, 0x04d2, 0x0000, 0x0000, 0x04e6, 0x04dc, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x04e7, 0x0000, 0x04cc, 0x0000, 0x0000, 0x04cf, 0x0000, 0x0000, 0x04d5, 0x0000, 0x04db, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x04d8, 0x0000, 0x0000, 0x0000, 0x0000, 0x04e8, 0x0000, 0x04c6, 0x04d4, 0x0000, 0x0000, 0x04c8, 0x04cd, 0x0000, 0x0000, 0x04d3, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x04d6, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x050f, 0x050e, 0x050d, 0x050c, 0x0521, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x03c6, 0x03c7, 0x03c8, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x03b6, 0x03b8, 0x03c5, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x03ba, 0x03bb, 0x03bd, 0x0000, 0x0000, 0x0000, 0x03ac, 0x03ae, 0x03b4, 0x03ad, 0x03af, 0x03b2, 0x03b5, 0x0000, 0x03b0, 0x03b3, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x03c1, 0x03c0, 0x03bf, 0x03be, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x03b9, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x03c4, 0x0000, 0x0407, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x03c3, }; static const unsigned short wchar2sjis_mac10[] = { // 0xfe30 - 0xfe44 0x1efc, 0x1ef4, 0x0000, 0x1ee9, 0x0000, 0x1f01, 0x1f02, 0x1f07, 0x1f08, 0x1f03, 0x1f04, 0x1f11, 0x1f12, 0x1f0b, 0x1f0c, 0x1f09, 0x1f0a, 0x1f0d, 0x1f0e, 0x1f0f, 0x1f10, }; static const unsigned short code_tbl[][3] = { {0x02f0, 0x0303, 0x2460}, {0x030e, 0x0321, 0x2474}, {0x032c, 0x0334, 0x2776}, {0x0341, 0x0349, 0x2488}, {0x034e, 0x0359, 0x2160}, {0x0362, 0x036d, 0x2170}, {0x038a, 0x03a3, 0x249c}, }; static const unsigned short code_ofst_tbl[][2] = { {0x03ac, 0x03c9}, {0x0406, 0x0420}, {0x0432, 0x0441}, {0x0468, 0x0480}, {0x04b8, 0x04e8}, {0x050c, 0x0551}, {0x1ed9, 0x1f18}, {0x1ff2, 0x20a5}, }; static const unsigned short *code_map[] = { sjis_mac2wchar1, sjis_mac2wchar2, sjis_mac2wchar3, sjis_mac2wchar4, sjis_mac2wchar5, sjis_mac2wchar6, sjis_mac2wchar7, sjis_mac2wchar8}; static const unsigned short code_tbl_m[][6] = { {0x0340, 0xf860, 0x0030, 0x002e, 0x0000, 0x0000}, {0x03c9, 0xf860, 0x0054, 0x0042, 0x0000, 0x0000}, {0x035c, 0xf860, 0x0058, 0x0056, 0x0000, 0x0000}, {0x0370, 0xf860, 0x0078, 0x0076, 0x0000, 0x0000}, {0x0439, 0xf860, 0x2193, 0x2191, 0x0000, 0x0000}, {0x0409, 0xf861, 0x0046, 0x0041, 0x0058, 0x0000}, {0x035b, 0xf861, 0x0058, 0x0049, 0x0056, 0x0000}, {0x036f, 0xf861, 0x0078, 0x0069, 0x0076, 0x0000}, {0x035a, 0xf862, 0x0058, 0x0049, 0x0049, 0x0049}, {0x036e, 0xf862, 0x0078, 0x0069, 0x0069, 0x0069}, {0x0522, 0xf862, 0x6709, 0x9650, 0x4f1a, 0x793e}, {0x0523, 0xf862, 0x8ca1, 0x56e3, 0x6cd5, 0x4eba}, }; static int code_tbl_m_len = sizeof(code_tbl_m)/(sizeof(unsigned short)*6); static const unsigned short s_form_tbl[] = { 0x2010,0x2016,0x2026, 0x3001,0x3002,0x301c,0x3041,0x3043,0x3045,0x3047,0x3049, 0x3063,0x3083,0x3085,0x3087,0x308e,0x30a1,0x30a3,0x30a5, 0x30a7,0x30a9,0x30c3,0x30e3,0x30e5,0x30e7,0x30ee,0x30f5, 0x30f6,0x30fc,0xff1d,0xff3b,0xff3d,0xff5c,0xffe3, // vertical f87e (34) 0x2026,0xff47,0xff4d, // halfwidth f87f (3) 0x5927,0x5c0f,0x63a7, // enclosing circle 20dd (3) 0x21e6,0x21e7,0x21e8,0x21e9, // black arrow f87a (4) }; static int s_form_tbl_len = sizeof(s_form_tbl)/sizeof(unsigned short); static const unsigned short s_form_sjis_tbl[] = { 0xeb5d,0xeb61,0xeb63, 0xeb41,0xeb42,0xeb60,0xec9f,0xeca1,0xeca3,0xeca5,0xeca7, 0xecc1,0xece1,0xece3,0xece5,0xecec,0xed40,0xed42,0xed44, 0xed46,0xed48,0xed62,0xed83,0xed85,0xed87,0xed8e,0xed95, 0xed96,0xeb5b,0xeb81,0xeb6d,0xeb6e,0xeb62,0xeb50, // vertical 0x00ff,0x864b,0x8645, // halfwidth 0x8791,0x8792,0x879d, // enclosing circle 0x86d4,0x86d5,0x86d3,0x86d6, // black arrow }; static const unsigned short s_form_sjis_fallback_tbl[] = { 0x815d,0x8161,0x8163, 0x8141,0x8142,0x8160,0x829f,0x82a1,0x82a3,0x82a5,0x82a7, 0x82c1,0x82e1,0x82e3,0x82e5,0x82ec,0x8340,0x8342,0x8344, 0x8346,0x8348,0x8362,0x8383,0x8385,0x8387,0x838e,0x8395, 0x8396,0x815b,0x8181,0x816d,0x816e,0x8162,0x8150, // vertical 0x815d,0x8287,0x828d, // halfwidth 0x91e5,0x8fac,0x8d54, // enclosing circle 0x86d0,0x86d1,0x86cf,0x86d2, // arrow }; static const unsigned short wchar2sjis_mac_r_tbl[][3] = { {0x2160, 0x216b, 0x034e}, {0x2170, 0x217b, 0x0362}, {0x2460, 0x2473, 0x02f0}, {0x2474, 0x2487, 0x030e}, {0x2488, 0x2490, 0x0341}, {0x249c, 0x24b5, 0x038a}, {0x2776, 0x277e, 0x032c}, {0x30f7, 0x30fa, 0x054e}, {0x32a4, 0x32a9, 0x04ba}, }; static int wchar2sjis_mac_r_tbl_len = sizeof(wchar2sjis_mac_r_tbl)/(3*sizeof(unsigned short)); static const unsigned short wchar2sjis_mac_r_map[][2] = { {0x2660, 0x2667}, {0x322a, 0x3243}, {0x3296, 0x329e}, {0x3300, 0x33d4}, {0xfe30, 0xfe44}, }; static int wchar2sjis_mac_r_map_len = sizeof(wchar2sjis_mac_r_map)/(2*sizeof(unsigned short)); static const unsigned short *wchar2sjis_mac_code_map[] = { wchar2sjis_mac4, wchar2sjis_mac7, wchar2sjis_mac8, wchar2sjis_mac9, wchar2sjis_mac10}; static const unsigned short wchar2sjis_mac_wchar_tbl[][2] = { {0x2109, 0x03c2}, {0x2113, 0x03bc}, {0x2116, 0x0406}, {0x2121, 0x0408}, {0x21c4, 0x0437}, {0x21c5, 0x0438}, {0x21c6, 0x0436}, {0x21e6, 0x043b}, {0x21e7, 0x043c}, {0x21e8, 0x043a}, {0x21e9, 0x043d}, {0x221f, 0x0525}, {0x222e, 0x0524}, {0x22bf, 0x0526}, {0x260e, 0x041f}, {0x261c, 0x0433}, {0x261d, 0x0434}, {0x261e, 0x0432}, {0x261f, 0x0435}, {0x3004, 0x0420}, {0x301d, 0x0538}, {0x301f, 0x0539}, {0x3020, 0x041e}, {0x3094, 0x054c}, }; static int wchar2sjis_mac_wchar_tbl_len = sizeof(wchar2sjis_mac_wchar_tbl)/(2*sizeof(unsigned short));
11,065
30.798851
102
h
php-src
php-src-master/ext/mbstring/libmbfl/filters/translit_kana_jisx0201_jisx0208.h
/* * "streamable kanji code filter and converter" * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved. * * LICENSE NOTICES * * This file is part of "streamable kanji code filter and converter", * which is distributed under the terms of GNU Lesser General Public * License (version 2) as published by the Free Software Foundation. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with "streamable kanji code filter and converter"; * if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA * * The author of this file: Moriyoshi Koizumi <[email protected]> * */ #ifndef TRANSLIT_KANA_JISX0201_JISX0208_H #define TRANSLIT_KANA_JISX0201_JISX0208_H /* "Zen" is 全, or "full"; "Han" is 半, or "half" * This refers to "fullwidth" or "halfwidth" variants of characters used for writing Japanese */ #define MBFL_HAN2ZEN_ALL 0x00001 #define MBFL_HAN2ZEN_ALPHA 0x00002 #define MBFL_HAN2ZEN_NUMERIC 0x00004 #define MBFL_HAN2ZEN_SPACE 0x00008 #define MBFL_HAN2ZEN_KATAKANA 0x00010 #define MBFL_HAN2ZEN_HIRAGANA 0x00020 #define MBFL_HAN2ZEN_SPECIAL 0x00040 #define MBFL_ZENKAKU_HIRA2KATA 0x00080 #define MBFL_ZEN2HAN_ALL 0x00100 #define MBFL_ZEN2HAN_ALPHA 0x00200 #define MBFL_ZEN2HAN_NUMERIC 0x00400 #define MBFL_ZEN2HAN_SPACE 0x00800 #define MBFL_ZEN2HAN_KATAKANA 0x01000 #define MBFL_ZEN2HAN_HIRAGANA 0x02000 #define MBFL_ZEN2HAN_SPECIAL 0x04000 #define MBFL_ZENKAKU_KATA2HIRA 0x08000 #define MBFL_HAN2ZEN_GLUE 0x10000 #endif /* TRANSLIT_KANA_JISX0201_JISX0208_H */
1,880
35.882353
96
h
php-src
php-src-master/ext/mbstring/libmbfl/filters/unicode_table_cp1252.h
/* * "streamable kanji code filter and converter" * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved. * * LICENSE NOTICES * * This file is part of "streamable kanji code filter and converter", * which is distributed under the terms of GNU Lesser General Public * License (version 2) as published by the Free Software Foundation. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with "streamable kanji code filter and converter"; * if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA * * The authors of this file: PHP3 internationalization team * You can contact the primary author 金本 茂 <[email protected]>. * */ #ifndef UNICODE_TABLE_CP1252_H #define UNICODE_TABLE_CP1252_H /* Windows CodePage 1252 - it's the same as iso-8859-1 but * defines extra symbols in the range 0x80-0x9f. * This table differs from the rest of the unicode tables below * as it only covers this range, while the rest cover 0xa0 onwards */ static const unsigned short cp1252_ucs_table[] = { 0x20ac,0x0000,0x201a,0x0192,0x201e,0x2026,0x2020,0x2021, 0x02c6,0x2030,0x0160,0x2039,0x0152,0x0000,0x017d,0x0000, 0x0000,0x2018,0x2019,0x201c,0x201d,0x2022,0x2013,0x2014, 0x02dc,0x2122,0x0161,0x203a,0x0153,0x0000,0x017e,0x0178 }; #endif /* UNICODE_TABLE_CP1252_H */
1,623
38.609756
72
h
php-src
php-src-master/ext/mbstring/libmbfl/filters/unicode_table_cp932_ext.h
/* * "streamable kanji code filter and converter" * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved. * * LICENSE NOTICES * * This file is part of "streamable kanji code filter and converter", * which is distributed under the terms of GNU Lesser General Public * License (version 2) as published by the Free Software Foundation. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with "streamable kanji code filter and converter"; * if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA * * The author of this file: Rui Hirokawa <[email protected]> * */ #ifndef UNICODE_TABLE_CP932_EXT_H #define UNICODE_TABLE_CP932_EXT_H const unsigned short cp932ext1_ucs_table[] = { /* ku 13 */ 0x2460,0x2461,0x2462,0x2463,0x2464,0x2465,0x2466,0x2467, 0x2468,0x2469,0x246A,0x246B,0x246C,0x246D,0x246E,0x246F, 0x2470,0x2471,0x2472,0x2473,0x2160,0x2161,0x2162,0x2163, 0x2164,0x2165,0x2166,0x2167,0x2168,0x2169,0x0000,0x3349, 0x3314,0x3322,0x334D,0x3318,0x3327,0x3303,0x3336,0x3351, 0x3357,0x330D,0x3326,0x3323,0x332B,0x334A,0x333B,0x339C, 0x339D,0x339E,0x338E,0x338F,0x33C4,0x33A1,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x337B,0x301D, 0x301F,0x2116,0x33CD,0x2121,0x32A4,0x32A5,0x32A6,0x32A7, 0x32A8,0x3231,0x3232,0x3239,0x337E,0x337D,0x337C,0x2252, 0x2261,0x222B,0x222E,0x2211,0x221A,0x22A5,0x2220,0x221F, 0x22BF,0x2235,0x2229,0x222A,0x0000,0x0000 }; const int cp932ext1_ucs_table_min = (13 - 1)*94; const int cp932ext1_ucs_table_max = (13 - 1)*94 + (sizeof (cp932ext1_ucs_table) / sizeof (unsigned short)); const unsigned short cp932ext2_ucs_table[] = { /* ku 89 */ 0x7E8A,0x891C,0x9348,0x9288,0x84DC,0x4FC9,0x70BB,0x6631, 0x68C8,0x92F9,0x66FB,0x5F45,0x4E28,0x4EE1,0x4EFC,0x4F00, 0x4F03,0x4F39,0x4F56,0x4F92,0x4F8A,0x4F9A,0x4F94,0x4FCD, 0x5040,0x5022,0x4FFF,0x501E,0x5046,0x5070,0x5042,0x5094, 0x50F4,0x50D8,0x514A,0x5164,0x519D,0x51BE,0x51EC,0x5215, 0x529C,0x52A6,0x52C0,0x52DB,0x5300,0x5307,0x5324,0x5372, 0x5393,0x53B2,0x53DD,0xFA0E,0x549C,0x548A,0x54A9,0x54FF, 0x5586,0x5759,0x5765,0x57AC,0x57C8,0x57C7,0xFA0F,0xFA10, 0x589E,0x58B2,0x590B,0x5953,0x595B,0x595D,0x5963,0x59A4, 0x59BA,0x5B56,0x5BC0,0x752F,0x5BD8,0x5BEC,0x5C1E,0x5CA6, 0x5CBA,0x5CF5,0x5D27,0x5D53,0xFA11,0x5D42,0x5D6D,0x5DB8, 0x5DB9,0x5DD0,0x5F21,0x5F34,0x5F67,0x5FB7, /* ku 90 */ 0x5FDE,0x605D,0x6085,0x608A,0x60DE,0x60D5,0x6120,0x60F2, 0x6111,0x6137,0x6130,0x6198,0x6213,0x62A6,0x63F5,0x6460, 0x649D,0x64CE,0x654E,0x6600,0x6615,0x663B,0x6609,0x662E, 0x661E,0x6624,0x6665,0x6657,0x6659,0xFA12,0x6673,0x6699, 0x66A0,0x66B2,0x66BF,0x66FA,0x670E,0xF929,0x6766,0x67BB, 0x6852,0x67C0,0x6801,0x6844,0x68CF,0xFA13,0x6968,0xFA14, 0x6998,0x69E2,0x6A30,0x6A6B,0x6A46,0x6A73,0x6A7E,0x6AE2, 0x6AE4,0x6BD6,0x6C3F,0x6C5C,0x6C86,0x6C6F,0x6CDA,0x6D04, 0x6D87,0x6D6F,0x6D96,0x6DAC,0x6DCF,0x6DF8,0x6DF2,0x6DFC, 0x6E39,0x6E5C,0x6E27,0x6E3C,0x6EBF,0x6F88,0x6FB5,0x6FF5, 0x7005,0x7007,0x7028,0x7085,0x70AB,0x710F,0x7104,0x715C, 0x7146,0x7147,0xFA15,0x71C1,0x71FE,0x72B1, /* ku 91 */ 0x72BE,0x7324,0xFA16,0x7377,0x73BD,0x73C9,0x73D6,0x73E3, 0x73D2,0x7407,0x73F5,0x7426,0x742A,0x7429,0x742E,0x7462, 0x7489,0x749F,0x7501,0x756F,0x7682,0x769C,0x769E,0x769B, 0x76A6,0xFA17,0x7746,0x52AF,0x7821,0x784E,0x7864,0x787A, 0x7930,0xFA18,0xFA19,0xFA1A,0x7994,0xFA1B,0x799B,0x7AD1, 0x7AE7,0xFA1C,0x7AEB,0x7B9E,0xFA1D,0x7D48,0x7D5C,0x7DB7, 0x7DA0,0x7DD6,0x7E52,0x7F47,0x7FA1,0xFA1E,0x8301,0x8362, 0x837F,0x83C7,0x83F6,0x8448,0x84B4,0x8553,0x8559,0x856B, 0xFA1F,0x85B0,0xFA20,0xFA21,0x8807,0x88F5,0x8A12,0x8A37, 0x8A79,0x8AA7,0x8ABE,0x8ADF,0xFA22,0x8AF6,0x8B53,0x8B7F, 0x8CF0,0x8CF4,0x8D12,0x8D76,0xFA23,0x8ECF,0xFA24,0xFA25, 0x9067,0x90DE,0xFA26,0x9115,0x9127,0x91DA, /* ku 92 */ 0x91D7,0x91DE,0x91ED,0x91EE,0x91E4,0x91E5,0x9206,0x9210, 0x920A,0x923A,0x9240,0x923C,0x924E,0x9259,0x9251,0x9239, 0x9267,0x92A7,0x9277,0x9278,0x92E7,0x92D7,0x92D9,0x92D0, 0xFA27,0x92D5,0x92E0,0x92D3,0x9325,0x9321,0x92FB,0xFA28, 0x931E,0x92FF,0x931D,0x9302,0x9370,0x9357,0x93A4,0x93C6, 0x93DE,0x93F8,0x9431,0x9445,0x9448,0x9592,0xF9DC,0xFA29, 0x969D,0x96AF,0x9733,0x973B,0x9743,0x974D,0x974F,0x9751, 0x9755,0x9857,0x9865,0xFA2A,0xFA2B,0x9927,0xFA2C,0x999E, 0x9A4E,0x9AD9,0x9ADC,0x9B75,0x9B72,0x9B8F,0x9BB1,0x9BBB, 0x9C00,0x9D70,0x9D6B,0xFA2D,0x9E19,0x9ED1,0x0000,0x0000, 0x2170,0x2171,0x2172,0x2173,0x2174,0x2175,0x2176,0x2177, 0x2178,0x2179,0xFFE2,0xFFE4,0xFF07,0xFF02 }; const int cp932ext2_ucs_table_min = (89 - 1)*94; const int cp932ext2_ucs_table_max = (89 - 1)*94 + (sizeof (cp932ext2_ucs_table) / sizeof (unsigned short)); const unsigned short cp932ext3_ucs_table[] = { /* ku 115 */ 0x2170,0x2171,0x2172,0x2173,0x2174,0x2175,0x2176,0x2177, 0x2178,0x2179,0x2160,0x2161,0x2162,0x2163,0x2164,0x2165, 0x2166,0x2167,0x2168,0x2169,0xFFE2,0xFFE4,0xFF07,0xFF02, 0x3231,0x2116,0x2121,0x2235,0x7E8A,0x891C,0x9348,0x9288, 0x84DC,0x4FC9,0x70BB,0x6631,0x68C8,0x92F9,0x66FB,0x5F45, 0x4E28,0x4EE1,0x4EFC,0x4F00,0x4F03,0x4F39,0x4F56,0x4F92, 0x4F8A,0x4F9A,0x4F94,0x4FCD,0x5040,0x5022,0x4FFF,0x501E, 0x5046,0x5070,0x5042,0x5094,0x50F4,0x50D8,0x514A,0x5164, 0x519D,0x51BE,0x51EC,0x5215,0x529C,0x52A6,0x52C0,0x52DB, 0x5300,0x5307,0x5324,0x5372,0x5393,0x53B2,0x53DD,0xFA0E, 0x549C,0x548A,0x54A9,0x54FF,0x5586,0x5759,0x5765,0x57AC, 0x57C8,0x57C7,0xFA0F,0xFA10,0x589E,0x58B2, /* ku 116 */ 0x590B,0x5953,0x595B,0x595D,0x5963,0x59A4,0x59BA,0x5B56, 0x5BC0,0x752F,0x5BD8,0x5BEC,0x5C1E,0x5CA6,0x5CBA,0x5CF5, 0x5D27,0x5D53,0xFA11,0x5D42,0x5D6D,0x5DB8,0x5DB9,0x5DD0, 0x5F21,0x5F34,0x5F67,0x5FB7,0x5FDE,0x605D,0x6085,0x608A, 0x60DE,0x60D5,0x6120,0x60F2,0x6111,0x6137,0x6130,0x6198, 0x6213,0x62A6,0x63F5,0x6460,0x649D,0x64CE,0x654E,0x6600, 0x6615,0x663B,0x6609,0x662E,0x661E,0x6624,0x6665,0x6657, 0x6659,0xFA12,0x6673,0x6699,0x66A0,0x66B2,0x66BF,0x66FA, 0x670E,0xF929,0x6766,0x67BB,0x6852,0x67C0,0x6801,0x6844, 0x68CF,0xFA13,0x6968,0xFA14,0x6998,0x69E2,0x6A30,0x6A6B, 0x6A46,0x6A73,0x6A7E,0x6AE2,0x6AE4,0x6BD6,0x6C3F,0x6C5C, 0x6C86,0x6C6F,0x6CDA,0x6D04,0x6D87,0x6D6F, /* ku 117 */ 0x6D96,0x6DAC,0x6DCF,0x6DF8,0x6DF2,0x6DFC,0x6E39,0x6E5C, 0x6E27,0x6E3C,0x6EBF,0x6F88,0x6FB5,0x6FF5,0x7005,0x7007, 0x7028,0x7085,0x70AB,0x710F,0x7104,0x715C,0x7146,0x7147, 0xFA15,0x71C1,0x71FE,0x72B1,0x72BE,0x7324,0xFA16,0x7377, 0x73BD,0x73C9,0x73D6,0x73E3,0x73D2,0x7407,0x73F5,0x7426, 0x742A,0x7429,0x742E,0x7462,0x7489,0x749F,0x7501,0x756F, 0x7682,0x769C,0x769E,0x769B,0x76A6,0xFA17,0x7746,0x52AF, 0x7821,0x784E,0x7864,0x787A,0x7930,0xFA18,0xFA19,0xFA1A, 0x7994,0xFA1B,0x799B,0x7AD1,0x7AE7,0xFA1C,0x7AEB,0x7B9E, 0xFA1D,0x7D48,0x7D5C,0x7DB7,0x7DA0,0x7DD6,0x7E52,0x7F47, 0x7FA1,0xFA1E,0x8301,0x8362,0x837F,0x83C7,0x83F6,0x8448, 0x84B4,0x8553,0x8559,0x856B,0xFA1F,0x85B0, /* ku 118 */ 0xFA20,0xFA21,0x8807,0x88F5,0x8A12,0x8A37,0x8A79,0x8AA7, 0x8ABE,0x8ADF,0xFA22,0x8AF6,0x8B53,0x8B7F,0x8CF0,0x8CF4, 0x8D12,0x8D76,0xFA23,0x8ECF,0xFA24,0xFA25,0x9067,0x90DE, 0xFA26,0x9115,0x9127,0x91DA,0x91D7,0x91DE,0x91ED,0x91EE, 0x91E4,0x91E5,0x9206,0x9210,0x920A,0x923A,0x9240,0x923C, 0x924E,0x9259,0x9251,0x9239,0x9267,0x92A7,0x9277,0x9278, 0x92E7,0x92D7,0x92D9,0x92D0,0xFA27,0x92D5,0x92E0,0x92D3, 0x9325,0x9321,0x92FB,0xFA28,0x931E,0x92FF,0x931D,0x9302, 0x9370,0x9357,0x93A4,0x93C6,0x93DE,0x93F8,0x9431,0x9445, 0x9448,0x9592,0xF9DC,0xFA29,0x969D,0x96AF,0x9733,0x973B, 0x9743,0x974D,0x974F,0x9751,0x9755,0x9857,0x9865,0xFA2A, 0xFA2B,0x9927,0xFA2C,0x999E,0x9A4E,0x9AD9, /* ku 119 */ 0x9ADC,0x9B75,0x9B72,0x9B8F,0x9BB1,0x9BBB,0x9C00,0x9D70, 0x9D6B,0xFA2D,0x9E19,0x9ED1 }; const int cp932ext3_ucs_table_min = (115 - 1)*94; const int cp932ext3_ucs_table_max = (115 - 1)*94 + (sizeof (cp932ext3_ucs_table) / sizeof (unsigned short)); #endif /* UNICODE_TABLE_CP932_EXT_H */
8,029
45.959064
108
h
php-src
php-src-master/ext/mbstring/libmbfl/filters/unicode_table_gb18030.h
/* * "streamable kanji code filter and converter" * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved. * * LICENSE NOTICES * * This file is part of "streamable kanji code filter and converter", * which is distributed under the terms of GNU Lesser General Public * License (version 2) as published by the Free Software Foundation. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with "streamable kanji code filter and converter"; * if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA * * The author of this file: Rui Hirokawa <[email protected]> * */ #ifndef UNICODE_TABLE_GB18030_H #define UNICODE_TABLE_GB18030_H static const unsigned short mbfl_gb18030_c_tbl_val[] = { 0xfe50,0xfe54,0xfe57,0xfe58,0xfe5d,0xfe5e,0xfe6b,0xfe6e, 0xfe71,0xfe73,0xfe74,0xfe75,0xfe79,0xfe84,0xa98a,0xa98b, 0xa98c,0xa98d,0xa98e,0xa98f,0xa990,0xa991,0xa992,0xa993, 0xa994,0xa995,0xa989,0xfe56,0xfe55,0xfe5a,0xfe5c,0xfe5b, 0xfe60,0xfe5f,0xfe62,0xfe65,0xfe63,0xfe64,0xfe68,0xfe69, 0xfe6a,0xfe6f,0xfe70,0xfe72,0xfe78,0xfe77,0xfe7a,0xfe7b, 0xfe7d,0xfe7c,0xfe80,0xfe81,0xfe82,0xfe83,0xfe85,0xfe86, 0xfe87,0xfe88,0xfe89,0xfe8a,0xfe8b,0xfe8d,0xfe8c,0xfe8f, 0xfe8e,0xfe96,0xfe93,0xfe94,0xfe95,0xfe97,0xfe92,0xfe98, 0xfe99,0xfe9a,0xfe9b,0xfe9c,0xfe9d,0xfe9e,0xfe9f }; static const unsigned short mbfl_gb18030_c_tbl_key[] = { 0x2e81,0x2e84,0x2e88,0x2e8b,0x2e8c,0x2e97,0x2ea7,0x2eaa, 0x2eae,0x2eb3,0x2eb6,0x2eb7,0x2ebb,0x2eca,0x2ff0,0x2ff1, 0x2ff2,0x2ff3,0x2ff4,0x2ff5,0x2ff6,0x2ff7,0x2ff8,0x2ff9, 0x2ffa,0x2ffb,0x303e,0x3447,0x3473,0x359e,0x360e,0x361a, 0x3918,0x396e,0x39cf,0x39d0,0x39df,0x3a73,0x3b4e,0x3c6e, 0x3ce0,0x4056,0x415f,0x4337,0x43ac,0x43b1,0x43dd,0x44d6, 0x464c,0x4661,0x4723,0x4729,0x477c,0x478d,0x4947,0x497a, 0x497d,0x4982,0x4983,0x4985,0x4986,0x499b,0x499f,0x49b6, 0x49b7,0x4c77,0x4c9f,0x4ca0,0x4ca1,0x4ca2,0x4ca3,0x4d13, 0x4d14,0x4d15,0x4d16,0x4d17,0x4d18,0x4d19,0x4dae }; static const int mbfl_gb18030_c_tbl_max = sizeof(mbfl_gb18030_c_tbl_key) / sizeof(unsigned short); static const unsigned short mbfl_gb18030_pua_tbl[][3] = { {0xe766, 0xe76b, 0xa2ab}, {0xe76d, 0xe76d, 0xa2e4}, {0xe76e, 0xe76f, 0xa2ef}, {0xe770, 0xe771, 0xa2fd}, {0xe772, 0xe77c, 0xa4f4}, {0xe77d, 0xe784, 0xa5f7}, {0xe785, 0xe78c, 0xa6b9}, {0xe78d, 0xe793, 0xa6d9}, {0xe794, 0xe795, 0xa6ec}, {0xe796, 0xe796, 0xa6f3}, {0xe797, 0xe79f, 0xa6f6}, {0xe7a0, 0xe7ae, 0xa7c2}, {0xe7af, 0xe7bb, 0xa7f2}, {0xe7bc, 0xe7c6, 0xa896}, {0xe7c7, 0xe7c7, 0xa8bc}, {0xe7c9, 0xe7cc, 0xa8c1}, {0xe7cd, 0xe7e1, 0xa8ea}, {0xe7e2, 0xe7e2, 0xa958}, {0xe7e3, 0xe7e3, 0xa95b}, {0xe7e4, 0xe7e6, 0xa95d}, {0xe7f4, 0xe800, 0xa997}, {0xe801, 0xe80f, 0xa9f0}, {0xe810, 0xe814, 0xd7fa}, {0xe816, 0xe818, 0xfe51}, {0xe81e, 0xe81e, 0xfe59}, {0xe826, 0xe826, 0xfe61}, {0xe82b, 0xe82c, 0xfe66}, {0xe831, 0xe832, 0xfe6c}, {0xe83b, 0xe83b, 0xfe76}, {0xe843, 0xe843, 0xfe7e}, {0xe854, 0xe855, 0xfe90}, {0xe864, 0xe864, 0xfea0}, }; static const int mbfl_gb18030_pua_tbl_max = sizeof(mbfl_gb18030_pua_tbl)/(sizeof(unsigned short)*3); static const unsigned short mbfl_gb2uni_tbl[] = { 0x0000, 0x0023, 0x0024, 0x0025, 0x0026, 0x002c, 0x002d, 0x0031, 0x0032, 0x0050, 0x0051, 0x0058, 0x0059, 0x005e, 0x005f, 0x005f, 0x0060, 0x0063, 0x0064, 0x0066, 0x0067, 0x0067, 0x0068, 0x0068, 0x0069, 0x006c, 0x006d, 0x007d, 0x007e, 0x0084, 0x0085, 0x0093, 0x0094, 0x00ab, 0x00ac, 0x00ae, 0x00af, 0x00b2, 0x00b3, 0x00cf, 0x00d0, 0x0131, 0x0132, 0x0132, 0x0133, 0x0133, 0x0134, 0x0134, 0x0135, 0x0135, 0x0136, 0x0136, 0x0137, 0x0137, 0x0138, 0x0138, 0x0139, 0x0154, 0x0155, 0x01ab, 0x01ac, 0x01ba, 0x01bb, 0x021f, 0x0220, 0x0220, 0x0221, 0x022d, 0x022e, 0x02e4, 0x02e5, 0x02e5, 0x02e6, 0x02ec, 0x02ed, 0x02ed, 0x02ee, 0x0324, 0x0325, 0x0332, 0x0333, 0x0333, 0x0334, 0x1ef1, 0x1ef2, 0x1ef3, 0x1ef4, 0x1ef4, 0x1ef5, 0x1ef6, 0x1ef7, 0x1efd, 0x1efe, 0x1f06, 0x1f07, 0x1f07, 0x1f08, 0x1f08, 0x1f09, 0x1f0d, 0x1f0e, 0x1f7d, 0x1f7e, 0x1fd3, 0x1fd4, 0x1fd4, 0x1fd5, 0x1fd7, 0x1fd8, 0x1fe3, 0x1fe4, 0x1fed, 0x1fee, 0x202b, 0x202c, 0x202f, 0x2030, 0x2045, 0x2046, 0x2047, 0x2048, 0x20b5, 0x20b6, 0x20bb, 0x20bc, 0x20bc, 0x20bd, 0x20bf, 0x20c0, 0x20c3, 0x20c4, 0x20c5, 0x20c6, 0x20c7, 0x20c8, 0x20c8, 0x20c9, 0x20c9, 0x20ca, 0x20cb, 0x20cc, 0x20d0, 0x20d1, 0x20d5, 0x20d6, 0x20df, 0x20e0, 0x20e2, 0x20e3, 0x20e7, 0x20e8, 0x20f4, 0x20f5, 0x20f6, 0x20f7, 0x20fc, 0x20fd, 0x2121, 0x2122, 0x2124, 0x2125, 0x212f, 0x2130, 0x2148, 0x2149, 0x219a, 0x219b, 0x22e7, 0x22e8, 0x22f1, 0x22f2, 0x2355, 0x2356, 0x2359, 0x235a, 0x2366, 0x2367, 0x2369, 0x236a, 0x2373, 0x2374, 0x2383, 0x2384, 0x238b, 0x238c, 0x2393, 0x2394, 0x2396, 0x2397, 0x2398, 0x2399, 0x23aa, 0x23ab, 0x23c9, 0x23ca, 0x23cb, 0x23cc, 0x2401, 0x2402, 0x2402, 0x2403, 0x2c40, 0x2c41, 0x2c42, 0x2c43, 0x2c45, 0x2c46, 0x2c47, 0x2c48, 0x2c51, 0x2c52, 0x2c60, 0x2c61, 0x2c62, 0x2c63, 0x2c65, 0x2c66, 0x2c69, 0x2c6a, 0x2c6b, 0x2c6c, 0x2c6e, 0x2c6f, 0x2c7c, 0x2c7d, 0x2da1, 0x2da2, 0x2da5, 0x2da6, 0x2da6, 0x2da7, 0x2dab, 0x2dac, 0x2dad, 0x2dae, 0x2dc1, 0x2dc2, 0x2dc3, 0x2dc4, 0x2dca, 0x2dcb, 0x2dcc, 0x2dcd, 0x2dd1, 0x2dd2, 0x2dd7, 0x2dd8, 0x2ecd, 0x2ece, 0x2ed4, 0x2ed5, 0x2f45, 0x2f46, 0x302f, 0x3030, 0x303b, 0x303c, 0x303d, 0x303e, 0x305f, 0x3060, 0x3068, 0x3069, 0x306a, 0x306b, 0x306c, 0x306d, 0x30dd, 0x30de, 0x3108, 0x3109, 0x3232, 0x3233, 0x32a1, 0x32a2, 0x32ac, 0x32ad, 0x35a9, 0x35aa, 0x35fe, 0x35ff, 0x365e, 0x365f, 0x366c, 0x366d, 0x36ff, 0x3700, 0x37d9, 0x37da, 0x38f8, 0x38f9, 0x3969, 0x396a, 0x3cde, 0x3cdf, 0x3de6, 0x3de7, 0x3fbd, 0x3fbe, 0x4031, 0x4032, 0x4035, 0x4036, 0x4060, 0x4061, 0x4158, 0x4159, 0x42cd, 0x42ce, 0x42e1, 0x42e2, 0x43a2, 0x43a3, 0x43a7, 0x43a8, 0x43f9, 0x43fa, 0x4409, 0x440a, 0x45c2, 0x45c3, 0x45f4, 0x45f5, 0x45f6, 0x45f7, 0x45fa, 0x45fb, 0x45fb, 0x45fc, 0x460f, 0x4610, 0x4612, 0x4613, 0x4628, 0x4629, 0x48e7, 0x48e8, 0x490e, 0x490f, 0x497d, 0x497e, 0x4a11, 0x4a12, 0x4a62, 0x4a63, 0x82bc, 0x82bd, 0x82bd, 0x82be, 0x82be, 0x82bf, 0x82cb, 0x82cc, 0x82cc, 0x82cd, 0x82d1, 0x82d2, 0x82d8, 0x82d9, 0x82dc, 0x82dd, 0x82e0, 0x82e1, 0x82e8, 0x82e9, 0x82ef, 0x82f0, 0x82ff, 0x8300, 0x830d, 0x830e, 0x93d4, 0x93d5, 0x9420, 0x9421, 0x943b, 0x943c, 0x948c, 0x948d, 0x9495, 0x9496, 0x94af, 0x94b0, 0x94b0, 0x94b1, 0x94b1, 0x94b2, 0x94b4, 0x94b5, 0x94ba, 0x94bb, 0x94bb, 0x94bc, 0x94bd, 0x94be, 0x98c3, 0x98c4, 0x98c4, 0x98c5, 0x98c8, 0x98c9, 0x98c9, 0x98ca, 0x98ca, 0x98cb, 0x98cb, 0x98cc, 0x9960, 0x9961, 0x99e1, 0x99e2, 0x99fb, }; static const unsigned short mbfl_uni2gb_tbl[] = { 0x0080, 0x00a3, 0x00a5, 0x00a6, 0x00a9, 0x00af, 0x00b2, 0x00b6, 0x00b8, 0x00d6, 0x00d8, 0x00df, 0x00e2, 0x00e7, 0x00eb, 0x00eb, 0x00ee, 0x00f1, 0x00f4, 0x00f6, 0x00f8, 0x00f8, 0x00fb, 0x00fb, 0x00fd, 0x0100, 0x0102, 0x0112, 0x0114, 0x011a, 0x011c, 0x012a, 0x012c, 0x0143, 0x0145, 0x0147, 0x0149, 0x014c, 0x014e, 0x016a, 0x016c, 0x01cd, 0x01cf, 0x01cf, 0x01d1, 0x01d1, 0x01d3, 0x01d3, 0x01d5, 0x01d5, 0x01d7, 0x01d7, 0x01d9, 0x01d9, 0x01db, 0x01db, 0x01dd, 0x01f8, 0x01fa, 0x0250, 0x0252, 0x0260, 0x0262, 0x02c6, 0x02c8, 0x02c8, 0x02cc, 0x02d8, 0x02da, 0x0390, 0x03a2, 0x03a2, 0x03aa, 0x03b0, 0x03c2, 0x03c2, 0x03ca, 0x0400, 0x0402, 0x040f, 0x0450, 0x0450, 0x0452, 0x200f, 0x2011, 0x2012, 0x2017, 0x2017, 0x201a, 0x201b, 0x201e, 0x2024, 0x2027, 0x202f, 0x2031, 0x2031, 0x2034, 0x2034, 0x2036, 0x203a, 0x203c, 0x20ab, 0x20ad, 0x2102, 0x2104, 0x2104, 0x2106, 0x2108, 0x210a, 0x2115, 0x2117, 0x2120, 0x2122, 0x215f, 0x216c, 0x216f, 0x217a, 0x218f, 0x2194, 0x2195, 0x219a, 0x2207, 0x2209, 0x220e, 0x2210, 0x2210, 0x2212, 0x2214, 0x2216, 0x2219, 0x221b, 0x221c, 0x2221, 0x2222, 0x2224, 0x2224, 0x2226, 0x2226, 0x222c, 0x222d, 0x222f, 0x2233, 0x2238, 0x223c, 0x223e, 0x2247, 0x2249, 0x224b, 0x224d, 0x2251, 0x2253, 0x225f, 0x2262, 0x2263, 0x2268, 0x226d, 0x2270, 0x2294, 0x2296, 0x2298, 0x229a, 0x22a4, 0x22a6, 0x22be, 0x22c0, 0x2311, 0x2313, 0x245f, 0x246a, 0x2473, 0x249c, 0x24ff, 0x254c, 0x254f, 0x2574, 0x2580, 0x2590, 0x2592, 0x2596, 0x259f, 0x25a2, 0x25b1, 0x25b4, 0x25bb, 0x25be, 0x25c5, 0x25c8, 0x25ca, 0x25cc, 0x25cd, 0x25d0, 0x25e1, 0x25e6, 0x2604, 0x2607, 0x2608, 0x260a, 0x263f, 0x2641, 0x2641, 0x2643, 0x2e80, 0x2e82, 0x2e83, 0x2e85, 0x2e87, 0x2e89, 0x2e8a, 0x2e8d, 0x2e96, 0x2e98, 0x2ea6, 0x2ea8, 0x2ea9, 0x2eab, 0x2ead, 0x2eaf, 0x2eb2, 0x2eb4, 0x2eb5, 0x2eb8, 0x2eba, 0x2ebc, 0x2ec9, 0x2ecb, 0x2fef, 0x2ffc, 0x2fff, 0x3004, 0x3004, 0x3018, 0x301c, 0x301f, 0x3020, 0x302a, 0x303d, 0x303f, 0x3040, 0x3094, 0x309a, 0x309f, 0x30a0, 0x30f7, 0x30fb, 0x30ff, 0x3104, 0x312a, 0x321f, 0x322a, 0x3230, 0x3232, 0x32a2, 0x32a4, 0x338d, 0x3390, 0x339b, 0x339f, 0x33a0, 0x33a2, 0x33c3, 0x33c5, 0x33cd, 0x33cf, 0x33d0, 0x33d3, 0x33d4, 0x33d6, 0x3446, 0x3448, 0x3472, 0x3474, 0x359d, 0x359f, 0x360d, 0x360f, 0x3619, 0x361b, 0x3917, 0x3919, 0x396d, 0x396f, 0x39ce, 0x39d1, 0x39de, 0x39e0, 0x3a72, 0x3a74, 0x3b4d, 0x3b4f, 0x3c6d, 0x3c6f, 0x3cdf, 0x3ce1, 0x4055, 0x4057, 0x415e, 0x4160, 0x4336, 0x4338, 0x43ab, 0x43ad, 0x43b0, 0x43b2, 0x43dc, 0x43de, 0x44d5, 0x44d7, 0x464b, 0x464d, 0x4660, 0x4662, 0x4722, 0x4724, 0x4728, 0x472a, 0x477b, 0x477d, 0x478c, 0x478e, 0x4946, 0x4948, 0x4979, 0x497b, 0x497c, 0x497e, 0x4981, 0x4984, 0x4984, 0x4987, 0x499a, 0x499c, 0x499e, 0x49a0, 0x49b5, 0x49b8, 0x4c76, 0x4c78, 0x4c9e, 0x4ca4, 0x4d12, 0x4d1a, 0x4dad, 0x4daf, 0x4dff, 0x9fa6, 0xd7ff, 0xe76c, 0xe76c, 0xe7c8, 0xe7c8, 0xe7e7, 0xe7f3, 0xe815, 0xe815, 0xe819, 0xe81d, 0xe81f, 0xe825, 0xe827, 0xe82a, 0xe82d, 0xe830, 0xe833, 0xe83a, 0xe83c, 0xe842, 0xe844, 0xe853, 0xe856, 0xe863, 0xe865, 0xf92b, 0xf92d, 0xf978, 0xf97a, 0xf994, 0xf996, 0xf9e6, 0xf9e8, 0xf9f0, 0xf9f2, 0xfa0b, 0xfa10, 0xfa10, 0xfa12, 0xfa12, 0xfa15, 0xfa17, 0xfa19, 0xfa1e, 0xfa22, 0xfa22, 0xfa25, 0xfa26, 0xfa2a, 0xfe2f, 0xfe32, 0xfe32, 0xfe45, 0xfe48, 0xfe53, 0xfe53, 0xfe58, 0xfe58, 0xfe67, 0xfe67, 0xfe6c, 0xff00, 0xff5f, 0xffdf, 0xffe6, 0xffff, }; static const unsigned short mbfl_gb_uni_ofst[] = { 128, 129, 131, 133, 134, 135, 137, 140, 142, 144, 145, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 171, 172, 189, 196, 213, 220, 221, 285, 286, 287, 291, 293, 295, 297, 298, 300, 301, 302, 303, 304, 305, 306, 307, 308, 320, 330, 334, 338, 339, 340, 341, 342, 343, 347, 348, 349, 354, 355, 359, 360, 361, 362, 363, 365, 369, 371, 372, 373, 374, 375, 376, 386, 426, 502, 538, 553, 556, 558, 560, 562, 564, 565, 567, 571, 573, 574, 575, 576, 577, 578, 579, 581, 582, 583, 584, 585, 586, 588, 589, 590, 602, 606, 625, 627, 636, 637, 720, 724, 810, 813, 850, 860, 861, 862, 864, 867, 868, 869, 870, 872, 873, 874, 875, 876, 877, 878, 879, 880, 882, 883, 884, 885, 886, 887, 888, 889, 890, 891, 892, 893, 894, 895, 896, 897, 898, 899, 900, 901, 902, 903, 905, 907, 908, 909, 911, 912, 917, 924, 925, 21827, 25775, 25866, 25896, 25929, 25932, 25933, 25934, 25936, 25938, 25939, 25940, 25942, 25943, 25944, 25945, 25946, 25947, 25948, 25952, 25953, 25955, 25956, 25959, 25961, 25964, 25966, 25984, 25994, 25998, 26012, 26016, 26110, 26116, }; static const int mbfl_gb_uni_max = sizeof(mbfl_gb_uni_ofst)/sizeof(unsigned short); #endif /* UNICODE_TABLE_GB18030_H */
11,914
49.274262
100
h
php-src
php-src-master/ext/mbstring/libmbfl/filters/utf7_helper.h
#ifndef MBFL_UTF7_HELPER_H #define MBFL_UTF7_HELPER_H #include "mbfilter.h" /* Ways which a Base64-encoded section can end: */ #define DASH 0xFC #define DIRECT 0xFD #define ASCII 0xFE #define ILLEGAL 0xFF static inline bool is_base64_end_valid(unsigned char n, bool gap, bool is_surrogate) { return !(gap || is_surrogate || n == ASCII || n == ILLEGAL); } static inline bool has_surrogate(uint16_t cp, bool is_surrogate) { return !is_surrogate && cp >= 0xD800 && cp <= 0xDBFF; } #endif /* MBFL_UTF7_HELPER_H */
517
21.521739
84
h
php-src
php-src-master/ext/mbstring/libmbfl/mbfl/eaw_table.h
/* This file was generated by ext/mbstring/ucgendat/ucgendat.php. * * DO NOT EDIT THIS FILE! * * East Asian Width table * * Some characters in East Asian languages are intended to be displayed in a space * which is roughly square. (This contrasts with others such as the Latin alphabet, * which are taller than they are wide.) To display these East Asian characters * properly, twice the horizontal space is used. This must be taken into account * when doing things like wrapping text to a specific width. * * Each pair of numbers in the below table is a range of Unicode codepoints * which should be displayed as double-width. */ #define FIRST_DOUBLEWIDTH_CODEPOINT 0x1100 static const struct { int begin; int end; } mbfl_eaw_table[] = { { 0x1100, 0x115f }, { 0x231a, 0x231b }, { 0x2329, 0x232a }, { 0x23e9, 0x23ec }, { 0x23f0, 0x23f0 }, { 0x23f3, 0x23f3 }, { 0x25fd, 0x25fe }, { 0x2614, 0x2615 }, { 0x2648, 0x2653 }, { 0x267f, 0x267f }, { 0x2693, 0x2693 }, { 0x26a1, 0x26a1 }, { 0x26aa, 0x26ab }, { 0x26bd, 0x26be }, { 0x26c4, 0x26c5 }, { 0x26ce, 0x26ce }, { 0x26d4, 0x26d4 }, { 0x26ea, 0x26ea }, { 0x26f2, 0x26f3 }, { 0x26f5, 0x26f5 }, { 0x26fa, 0x26fa }, { 0x26fd, 0x26fd }, { 0x2705, 0x2705 }, { 0x270a, 0x270b }, { 0x2728, 0x2728 }, { 0x274c, 0x274c }, { 0x274e, 0x274e }, { 0x2753, 0x2755 }, { 0x2757, 0x2757 }, { 0x2795, 0x2797 }, { 0x27b0, 0x27b0 }, { 0x27bf, 0x27bf }, { 0x2b1b, 0x2b1c }, { 0x2b50, 0x2b50 }, { 0x2b55, 0x2b55 }, { 0x2e80, 0x2e99 }, { 0x2e9b, 0x2ef3 }, { 0x2f00, 0x2fd5 }, { 0x2ff0, 0x2ffb }, { 0x3000, 0x303e }, { 0x3041, 0x3096 }, { 0x3099, 0x30ff }, { 0x3105, 0x312f }, { 0x3131, 0x318e }, { 0x3190, 0x31e3 }, { 0x31f0, 0x321e }, { 0x3220, 0x3247 }, { 0x3250, 0x4dbf }, { 0x4e00, 0xa48c }, { 0xa490, 0xa4c6 }, { 0xa960, 0xa97c }, { 0xac00, 0xd7a3 }, { 0xf900, 0xfaff }, { 0xfe10, 0xfe19 }, { 0xfe30, 0xfe52 }, { 0xfe54, 0xfe66 }, { 0xfe68, 0xfe6b }, { 0xff01, 0xff60 }, { 0xffe0, 0xffe6 }, { 0x16fe0, 0x16fe4 }, { 0x16ff0, 0x16ff1 }, { 0x17000, 0x187f7 }, { 0x18800, 0x18cd5 }, { 0x18d00, 0x18d08 }, { 0x1aff0, 0x1aff3 }, { 0x1aff5, 0x1affb }, { 0x1affd, 0x1affe }, { 0x1b000, 0x1b122 }, { 0x1b150, 0x1b152 }, { 0x1b164, 0x1b167 }, { 0x1b170, 0x1b2fb }, { 0x1f004, 0x1f004 }, { 0x1f0cf, 0x1f0cf }, { 0x1f18e, 0x1f18e }, { 0x1f191, 0x1f19a }, { 0x1f200, 0x1f202 }, { 0x1f210, 0x1f23b }, { 0x1f240, 0x1f248 }, { 0x1f250, 0x1f251 }, { 0x1f260, 0x1f265 }, { 0x1f300, 0x1f320 }, { 0x1f32d, 0x1f335 }, { 0x1f337, 0x1f37c }, { 0x1f37e, 0x1f393 }, { 0x1f3a0, 0x1f3ca }, { 0x1f3cf, 0x1f3d3 }, { 0x1f3e0, 0x1f3f0 }, { 0x1f3f4, 0x1f3f4 }, { 0x1f3f8, 0x1f43e }, { 0x1f440, 0x1f440 }, { 0x1f442, 0x1f4fc }, { 0x1f4ff, 0x1f53d }, { 0x1f54b, 0x1f54e }, { 0x1f550, 0x1f567 }, { 0x1f57a, 0x1f57a }, { 0x1f595, 0x1f596 }, { 0x1f5a4, 0x1f5a4 }, { 0x1f5fb, 0x1f64f }, { 0x1f680, 0x1f6c5 }, { 0x1f6cc, 0x1f6cc }, { 0x1f6d0, 0x1f6d2 }, { 0x1f6d5, 0x1f6d7 }, { 0x1f6dd, 0x1f6df }, { 0x1f6eb, 0x1f6ec }, { 0x1f6f4, 0x1f6fc }, { 0x1f7e0, 0x1f7eb }, { 0x1f7f0, 0x1f7f0 }, { 0x1f90c, 0x1f93a }, { 0x1f93c, 0x1f945 }, { 0x1f947, 0x1f9ff }, { 0x1fa70, 0x1fa74 }, { 0x1fa78, 0x1fa7c }, { 0x1fa80, 0x1fa86 }, { 0x1fa90, 0x1faac }, { 0x1fab0, 0x1faba }, { 0x1fac0, 0x1fac5 }, { 0x1fad0, 0x1fad9 }, { 0x1fae0, 0x1fae7 }, { 0x1faf0, 0x1faf6 }, { 0x20000, 0x2fffd }, { 0x30000, 0x3fffd }, };
3,445
22.765517
83
h
php-src
php-src-master/ext/mbstring/libmbfl/mbfl/mbfilter.c
/* * charset=UTF-8 */ /* * "streamable kanji code filter and converter" * * Copyright (c) 1998,1999,2000,2001 HappySize, Inc. All rights reserved. * * This software is released under the GNU Lesser General Public License. * (Version 2.1, February 1999) * Please read the following detail of the licence (in japanese). * * ◆使用許諾条件◆ * * このソフトウェアは株式会社ハッピーサイズによって開発されました。株式会社ハッ * ピーサイズは、著作権法および万国著作権条約の定めにより、このソフトウェアに関 * するすべての権利を留保する権利を持ち、ここに行使します。株式会社ハッピーサイ * ズは以下に明記した条件に従って、このソフトウェアを使用する排他的ではない権利 * をお客様に許諾します。何人たりとも、以下の条件に反してこのソフトウェアを使用 * することはできません。 * * このソフトウェアを「GNU Lesser General Public License (Version 2.1, February * 1999)」に示された条件で使用することを、全ての方に許諾します。「GNU Lesser * General Public License」を満たさない使用には、株式会社ハッピーサイズから書面 * による許諾を得る必要があります。 * * 「GNU Lesser General Public License」の全文は以下のウェブページから取得でき * ます。「GNU Lesser General Public License」とは、これまでLibrary General * Public Licenseと呼ばれていたものです。 * http://www.gnu.org/ --- GNUウェブサイト * http://www.gnu.org/copyleft/lesser.html --- ライセンス文面 * このライセンスの内容がわからない方、守れない方には使用を許諾しません。 * * しかしながら、当社とGNUプロジェクトとの特定の関係を示唆または主張するもので * はありません。 * * ◆保証内容◆ * * このソフトウェアは、期待された動作・機能・性能を持つことを目標として設計され * 開発されていますが、これを保証するものではありません。このソフトウェアは「こ * のまま」の状態で提供されており、たとえばこのソフトウェアの有用性ないし特定の * 目的に合致することといった、何らかの保証内容が、明示されたり暗黙に示されてい * る場合であっても、その保証は無効です。このソフトウェアを使用した結果ないし使 * 用しなかった結果によって、直接あるいは間接に受けた身体的な傷害、財産上の損害 * 、データの損失あるいはその他の全ての損害については、その損害の可能性が使用者 * 、当社あるいは第三者によって警告されていた場合であっても、当社はその損害の賠 * 償および補填を行いません。この規定は他の全ての、書面上または書面に無い保証・ * 契約・規定に優先します。 * * ◆著作権者の連絡先および使用条件についての問い合わせ先◆ * * 〒102-0073 * 東京都千代田区九段北1-13-5日本地所第一ビル4F * 株式会社ハッピーサイズ * Phone: 03-3512-3655, Fax: 03-3512-3656 * Email: [email protected] * Web: http://happysize.com/ * * ◆著者◆ * * 金本 茂 <[email protected]> * * ◆履歴◆ * * 1998/11/10 sgk implementation in C++ * 1999/4/25 sgk Cで書きなおし。 * 1999/4/26 sgk 入力フィルタを実装。漢字コードを推定しながらフィルタを追加。 * 1999/6/?? Unicodeサポート。 * 1999/6/22 sgk ライセンスをLGPLに変更。 * */ /* * Unicode support * * Portions copyright (c) 1999,2000,2001 by the PHP3 internationalization team. * All rights reserved. * */ #include <stddef.h> #include <string.h> #include "mbfilter.h" #include "mbfl_filter_output.h" #include "mbfilter_8bit.h" #include "mbfilter_wchar.h" #include "mbstring.h" #include "php_unicode.h" #include "filters/mbfilter_base64.h" #include "filters/mbfilter_qprint.h" #include "filters/mbfilter_singlebyte.h" #include "filters/mbfilter_utf8.h" /* * strcut */ mbfl_string * mbfl_strcut( mbfl_string *string, mbfl_string *result, size_t from, size_t length) { const mbfl_encoding *encoding = string->encoding; mbfl_memory_device device; if (from >= string->len) { from = string->len; } mbfl_string_init(result); result->encoding = string->encoding; if ((encoding->flag & (MBFL_ENCTYPE_SBCS | MBFL_ENCTYPE_WCS2 | MBFL_ENCTYPE_WCS4)) || encoding->mblen_table != NULL) { const unsigned char *start = NULL; const unsigned char *end = NULL; unsigned char *w; size_t sz; if (encoding->flag & MBFL_ENCTYPE_WCS2) { from &= -2; if (length >= string->len - from) { length = string->len - from; } start = string->val + from; end = start + (length & -2); } else if (encoding->flag & MBFL_ENCTYPE_WCS4) { from &= -4; if (length >= string->len - from) { length = string->len - from; } start = string->val + from; end = start + (length & -4); } else if ((encoding->flag & MBFL_ENCTYPE_SBCS)) { if (length >= string->len - from) { length = string->len - from; } start = string->val + from; end = start + length; } else if (encoding->mblen_table != NULL) { 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 (length >= string->len - (start - string->val)) { 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; } /* allocate memory and copy string */ sz = end - start; w = ecalloc(sz + 8, sizeof(unsigned char)); 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 { 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; size_t pos; } bk, _bk; /* output code filter */ if (!(decoder = mbfl_convert_filter_new( &mbfl_encoding_wchar, string->encoding, mbfl_memory_device_output, 0, &device))) { return NULL; } /* wchar filter */ if (!(encoder = mbfl_convert_filter_new( string->encoding, &mbfl_encoding_wchar, mbfl_filter_output_null, NULL, NULL))) { mbfl_convert_filter_delete(decoder); return NULL; } mbfl_memory_device_init(&device, length + 8, 0); p = string->val; /* search start position */ for (q = string->val + from; p < q; p++) { (*encoder->filter_function)(*p, encoder); } /* switch the drain direction */ encoder->output_function = (output_function_t)decoder->filter_function; encoder->flush_function = (flush_function_t)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" */ /* 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; if (decoder->filter_dtor) decoder->filter_dtor(decoder); if (encoder->filter_dtor) 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); /* if the offset of the resulting string exceeds the length, * then restore the state */ if (device.pos > length) { if (bk.decoder.filter_dtor) bk.decoder.filter_dtor(&bk.decoder); if (bk.encoder.filter_dtor) bk.encoder.filter_dtor(&bk.encoder); p = _bk.p; device.pos = _bk.pos; if (decoder->filter_dtor) decoder->filter_dtor(decoder); if (encoder->filter_dtor) encoder->filter_dtor(encoder); mbfl_convert_filter_copy(&_bk.decoder, decoder); mbfl_convert_filter_copy(&_bk.encoder, encoder); bk = _bk; } else { if (_bk.decoder.filter_dtor) _bk.decoder.filter_dtor(&_bk.decoder); if (_bk.encoder.filter_dtor) _bk.encoder.filter_dtor(&_bk.encoder); p = bk.p; device.pos = bk.pos; if (decoder->filter_dtor) decoder->filter_dtor(decoder); if (encoder->filter_dtor) encoder->filter_dtor(encoder); mbfl_convert_filter_copy(&bk.decoder, decoder); mbfl_convert_filter_copy(&bk.encoder, encoder); } } } 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; if (decoder->filter_dtor) decoder->filter_dtor(decoder); if (encoder->filter_dtor) 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) { if (_bk.decoder.filter_dtor) _bk.decoder.filter_dtor(&_bk.decoder); if (_bk.encoder.filter_dtor) _bk.encoder.filter_dtor(&_bk.encoder); /* restore filter */ p = bk.p; device.pos = bk.pos; if (decoder->filter_dtor) decoder->filter_dtor(decoder); if (encoder->filter_dtor) encoder->filter_dtor(encoder); mbfl_convert_filter_copy(&bk.decoder, decoder); mbfl_convert_filter_copy(&bk.encoder, encoder); break; } if (bk.decoder.filter_dtor) bk.decoder.filter_dtor(&bk.decoder); if (bk.encoder.filter_dtor) bk.encoder.filter_dtor(&bk.encoder); p = _bk.p; device.pos = _bk.pos; if (decoder->filter_dtor) decoder->filter_dtor(decoder); if (encoder->filter_dtor) encoder->filter_dtor(encoder); mbfl_convert_filter_copy(&_bk.decoder, decoder); mbfl_convert_filter_copy(&_bk.encoder, encoder); bk = _bk; } decoder->illegal_mode = MBFL_OUTPUTFILTER_ILLEGAL_MODE_NONE; (*encoder->filter_flush)(encoder); if (bk.decoder.filter_dtor) bk.decoder.filter_dtor(&bk.decoder); if (bk.encoder.filter_dtor) bk.encoder.filter_dtor(&bk.encoder); result = mbfl_memory_device_result(&device, result); mbfl_convert_filter_delete(encoder); mbfl_convert_filter_delete(decoder); } return result; }
9,829
24.269923
119
c
php-src
php-src-master/ext/mbstring/libmbfl/mbfl/mbfilter_8bit.c
/* * "streamable kanji code filter and converter" * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved. * * LICENSE NOTICES * * This file is part of "streamable kanji code filter and converter", * which is distributed under the terms of GNU Lesser General Public * License (version 2) as published by the Free Software Foundation. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with "streamable kanji code filter and converter"; * if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA * * The author of this file: * */ /* * The source code included in this files was separated from mbfilter.c * by Moriyoshi Koizumi <[email protected]> on 20 Dec 2002. The file * mbfilter.c is included in this package . * */ #include <stddef.h> #include "mbfilter.h" const struct mbfl_convert_vtbl vtbl_8bit_wchar; const struct mbfl_convert_vtbl vtbl_wchar_8bit; static int mbfl_filt_conv_8bit_wchar(int c, mbfl_convert_filter *filter); static int mbfl_filt_conv_wchar_8bit(int c, mbfl_convert_filter *filter); static size_t mb_8bit_to_wchar(unsigned char **in, size_t *in_len, uint32_t *buf, size_t bufsize, unsigned int *state); static void mb_wchar_to_8bit(uint32_t *in, size_t len, mb_convert_buf *buf, bool end); static const char *mbfl_encoding_8bit_aliases[] = {"binary", NULL}; const mbfl_encoding mbfl_encoding_8bit = { mbfl_no_encoding_8bit, "8bit", "8bit", mbfl_encoding_8bit_aliases, NULL, MBFL_ENCTYPE_SBCS, &vtbl_8bit_wchar, &vtbl_wchar_8bit, mb_8bit_to_wchar, mb_wchar_to_8bit, NULL }; const struct mbfl_convert_vtbl vtbl_8bit_wchar = { mbfl_no_encoding_8bit, mbfl_no_encoding_wchar, mbfl_filt_conv_common_ctor, NULL, mbfl_filt_conv_8bit_wchar, mbfl_filt_conv_common_flush, NULL, }; const struct mbfl_convert_vtbl vtbl_wchar_8bit = { mbfl_no_encoding_wchar, mbfl_no_encoding_8bit, mbfl_filt_conv_common_ctor, NULL, mbfl_filt_conv_wchar_8bit, mbfl_filt_conv_common_flush, NULL, }; #define CK(statement) do { if ((statement) < 0) return (-1); } while (0) static int mbfl_filt_conv_8bit_wchar(int c, mbfl_convert_filter *filter) { return (*filter->output_function)(c, filter->data); } static int mbfl_filt_conv_wchar_8bit(int c, mbfl_convert_filter *filter) { if (c >= 0 && c < 0x100) { CK((*filter->output_function)(c, filter->data)); } else { CK(mbfl_filt_conv_illegal_output(c, filter)); } return 0; } static size_t mb_8bit_to_wchar(unsigned char **in, size_t *in_len, uint32_t *buf, size_t bufsize, unsigned int *state) { unsigned char *p = *in, *e = p + *in_len; uint32_t *out = buf, *limit = buf + bufsize; while (p < e && out < limit) { unsigned char c = *p++; *out++ = c; } *in_len = e - p; *in = p; return out - buf; } static void mb_wchar_to_8bit(uint32_t *in, size_t len, mb_convert_buf *buf, bool end) { unsigned char *out, *limit; MB_CONVERT_BUF_LOAD(buf, out, limit); MB_CONVERT_BUF_ENSURE(buf, out, limit, len); while (len--) { uint32_t w = *in++; if (w <= 0xFF) { out = mb_convert_buf_add(out, w); } else { MB_CONVERT_ERROR(buf, out, limit, w, mb_wchar_to_8bit); MB_CONVERT_BUF_ENSURE(buf, out, limit, len); } } MB_CONVERT_BUF_STORE(buf, out, limit); }
3,567
26.658915
119
c
php-src
php-src-master/ext/mbstring/libmbfl/mbfl/mbfilter_8bit.h
/* * "streamable kanji code filter and converter" * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved. * * LICENSE NOTICES * * This file is part of "streamable kanji code filter and converter", * which is distributed under the terms of GNU Lesser General Public * License (version 2) as published by the Free Software Foundation. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with "streamable kanji code filter and converter"; * if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA * * The author of this file: * */ /* * The source code included in this files was separated from mbfilter.c * by Moriyoshi Koizumi <[email protected]> on 20 Dec 2002. The file * mbfilter.c is included in this package . * */ #ifndef MBFL_MBFILTER_8BIT_H #define MBFL_MBFILTER_8BIT_H #include "mbfl_defs.h" #include "mbfilter.h" MBFLAPI extern const mbfl_encoding mbfl_encoding_8bit; #endif /* MBFL_MBFILTER_8BIT_H */
1,288
31.225
72
h
php-src
php-src-master/ext/mbstring/libmbfl/mbfl/mbfilter_pass.c
/* * "streamable kanji code filter and converter" * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved. * * LICENSE NOTICES * * This file is part of "streamable kanji code filter and converter", * which is distributed under the terms of GNU Lesser General Public * License (version 2) as published by the Free Software Foundation. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with "streamable kanji code filter and converter"; * if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA * * The author of this file: * */ /* * The source code included in this files was separated from mbfilter.c * by moriyoshi koizumi <[email protected]> on 4 dec 2002. * */ #include <stddef.h> #include "mbfilter.h" #include "mbfilter_pass.h" static const char *mbfl_encoding_pass_aliases[] = {"none", NULL}; const mbfl_encoding mbfl_encoding_pass = { mbfl_no_encoding_pass, "pass", NULL, mbfl_encoding_pass_aliases, NULL, 0, NULL, NULL, NULL, NULL, NULL }; const struct mbfl_convert_vtbl vtbl_pass = { mbfl_no_encoding_pass, mbfl_no_encoding_pass, mbfl_filt_conv_common_ctor, NULL, mbfl_filt_conv_pass, mbfl_filt_conv_common_flush, NULL, }; int mbfl_filt_conv_pass(int c, mbfl_convert_filter *filter) { return (*filter->output_function)(c, filter->data); }
1,647
24.353846
72
c
php-src
php-src-master/ext/mbstring/libmbfl/mbfl/mbfilter_pass.h
/* * "streamable kanji code filter and converter" * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved. * * LICENSE NOTICES * * This file is part of "streamable kanji code filter and converter", * which is distributed under the terms of GNU Lesser General Public * License (version 2) as published by the Free Software Foundation. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with "streamable kanji code filter and converter"; * if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA * * The author of this file: * */ /* * The source code included in this files was separated from mbfilter.c * by moriyoshi koizumi <[email protected]> on 4 dec 2002. * */ #ifndef MBFL_MBFILTER_PASS_H #define MBFL_MBFILTER_PASS_H #include "mbfl_defs.h" #include "mbfilter.h" 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); #endif /* MBFL_MBFILTER_PASS_H */
1,368
31.595238
75
h
php-src
php-src-master/ext/mbstring/libmbfl/mbfl/mbfilter_wchar.c
/* * "streamable kanji code filter and converter" * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved. * * LICENSE NOTICES * * This file is part of "streamable kanji code filter and converter", * which is distributed under the terms of GNU Lesser General Public * License (version 2) as published by the Free Software Foundation. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with "streamable kanji code filter and converter"; * if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA * * The author of this file: * */ /* * The source code included in this file was separated from mbfilter.c * by Moriyoshi Koizumi <[email protected]> on 20 Dec 2002. The file * mbfilter.c is included in this package . * */ #include <stddef.h> #include "mbfilter.h" const mbfl_encoding mbfl_encoding_wchar = { mbfl_no_encoding_wchar, "wchar", NULL, NULL, NULL, MBFL_ENCTYPE_WCS4, NULL, NULL, NULL, NULL, NULL };
1,293
25.958333
72
c
php-src
php-src-master/ext/mbstring/libmbfl/mbfl/mbfilter_wchar.h
/* * "streamable kanji code filter and converter" * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved. * * LICENSE NOTICES * * This file is part of "streamable kanji code filter and converter", * which is distributed under the terms of GNU Lesser General Public * License (version 2) as published by the Free Software Foundation. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with "streamable kanji code filter and converter"; * if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA * * The author of this file: * */ /* * The source code included in this files was separated from mbfilter.c * by Moriyoshi Koizumi <[email protected]> on 20 Dec 2002. The file * mbfilter.c is included in this package . * */ #ifndef MBFL_MBFILTER_WCHAR_H #define MBFL_MBFILTER_WCHAR_H #include "mbfl_defs.h" #include "mbfilter.h" MBFLAPI extern const mbfl_encoding mbfl_encoding_wchar; #endif /* MBFL_MBFILTER_WCHAR_H */
1,292
31.325
72
h
php-src
php-src-master/ext/mbstring/libmbfl/mbfl/mbfl_defs.h
/* * "streamable kanji code filter and converter" * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved. * * LICENSE NOTICES * * This file is part of "streamable kanji code filter and converter", * which is distributed under the terms of GNU Lesser General Public * License (version 2) as published by the Free Software Foundation. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with "streamable kanji code filter and converter"; * if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA * * The author of this file: * */ /* * The source code included in this files was separated from mbfilter.h * by Moriyoshi Koizumi <[email protected]> on 20 Dec 2002. The file * mbfilter.h is included in this package . * */ #ifndef MBFL_DEFS_H #define MBFL_DEFS_H #ifndef NULL #ifdef __cplusplus #define NULL (0L) #else #define NULL (void *)(0L) #endif #endif #ifndef SIZE_MAX #define SIZE_MAX ((size_t)~0) #endif #ifdef WIN32 #ifdef MBFL_DLL_EXPORT #define MBFLAPI __declspec(dllexport) #else #define MBFLAPI __declspec(dllimport) #endif /* MBFL_DLL_EXPORT */ #else #if defined(__GNUC__) && __GNUC__ >= 4 #define MBFLAPI __attribute__((visibility("default"))) #else #define MBFLAPI #endif /* defined(__GNUC__) && __GNUC__ >= 4 */ #endif /* WIN32 */ #endif /* MBFL_DEFS_H */
1,648
26.032787
72
h
php-src
php-src-master/ext/mbstring/libmbfl/mbfl/mbfl_encoding.c
/* * "streamable kanji code filter and converter" * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved. * * LICENSE NOTICES * * This file is part of "streamable kanji code filter and converter", * which is distributed under the terms of GNU Lesser General Public * License (version 2) as published by the Free Software Foundation. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with "streamable kanji code filter and converter"; * if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA * * The author of this file: * */ /* * The source code included in this files was separated from mbfilter.c * by Moriyoshi Koizumi <[email protected]> on 20 Dec 2002. The file * mbfilter.c is included in this package . * */ #include "libmbfl/config.h" #ifdef HAVE_STRINGS_H /* For strcasecmp */ #include <strings.h> #endif #include "mbfl_encoding.h" #include "mbfilter_pass.h" #include "mbfilter_8bit.h" #include "filters/mbfilter_base64.h" #include "filters/mbfilter_cjk.h" #include "filters/mbfilter_qprint.h" #include "filters/mbfilter_uuencode.h" #include "filters/mbfilter_7bit.h" #include "filters/mbfilter_utf7.h" #include "filters/mbfilter_utf7imap.h" #include "filters/mbfilter_utf8.h" #include "filters/mbfilter_utf8_mobile.h" #include "filters/mbfilter_utf16.h" #include "filters/mbfilter_utf32.h" #include "filters/mbfilter_ucs4.h" #include "filters/mbfilter_ucs2.h" #include "filters/mbfilter_htmlent.h" #include "filters/mbfilter_singlebyte.h" #ifndef HAVE_STRCASECMP #ifdef HAVE_STRICMP #define strcasecmp stricmp #endif #endif static const mbfl_encoding *mbfl_encoding_ptr_list[] = { &mbfl_encoding_base64, &mbfl_encoding_uuencode, &mbfl_encoding_html_ent, &mbfl_encoding_qprint, &mbfl_encoding_7bit, &mbfl_encoding_8bit, &mbfl_encoding_ucs4, &mbfl_encoding_ucs4be, &mbfl_encoding_ucs4le, &mbfl_encoding_ucs2, &mbfl_encoding_ucs2be, &mbfl_encoding_ucs2le, &mbfl_encoding_utf32, &mbfl_encoding_utf32be, &mbfl_encoding_utf32le, &mbfl_encoding_utf16, &mbfl_encoding_utf16be, &mbfl_encoding_utf16le, &mbfl_encoding_utf8, &mbfl_encoding_utf7, &mbfl_encoding_utf7imap, &mbfl_encoding_ascii, &mbfl_encoding_euc_jp, &mbfl_encoding_sjis, &mbfl_encoding_eucjp_win, &mbfl_encoding_eucjp2004, &mbfl_encoding_sjis_docomo, &mbfl_encoding_sjis_kddi, &mbfl_encoding_sjis_sb, &mbfl_encoding_sjis_mac, &mbfl_encoding_sjis2004, &mbfl_encoding_utf8_docomo, &mbfl_encoding_utf8_kddi_a, &mbfl_encoding_utf8_kddi_b, &mbfl_encoding_utf8_sb, &mbfl_encoding_cp932, &mbfl_encoding_sjiswin, &mbfl_encoding_cp51932, &mbfl_encoding_jis, &mbfl_encoding_2022jp, &mbfl_encoding_2022jpms, &mbfl_encoding_gb18030, &mbfl_encoding_cp1252, &mbfl_encoding_cp1254, &mbfl_encoding_8859_1, &mbfl_encoding_8859_2, &mbfl_encoding_8859_3, &mbfl_encoding_8859_4, &mbfl_encoding_8859_5, &mbfl_encoding_8859_6, &mbfl_encoding_8859_7, &mbfl_encoding_8859_8, &mbfl_encoding_8859_9, &mbfl_encoding_8859_10, &mbfl_encoding_8859_13, &mbfl_encoding_8859_14, &mbfl_encoding_8859_15, &mbfl_encoding_8859_16, &mbfl_encoding_euc_cn, &mbfl_encoding_cp936, &mbfl_encoding_hz, &mbfl_encoding_euc_tw, &mbfl_encoding_big5, &mbfl_encoding_cp950, &mbfl_encoding_euc_kr, &mbfl_encoding_uhc, &mbfl_encoding_2022kr, &mbfl_encoding_cp1251, &mbfl_encoding_cp866, &mbfl_encoding_koi8r, &mbfl_encoding_koi8u, &mbfl_encoding_armscii8, &mbfl_encoding_cp850, &mbfl_encoding_2022jp_2004, &mbfl_encoding_2022jp_kddi, &mbfl_encoding_cp50220, &mbfl_encoding_cp50221, &mbfl_encoding_cp50222, NULL }; const mbfl_encoding *mbfl_name2encoding(const char *name) { const mbfl_encoding **encoding; for (encoding = mbfl_encoding_ptr_list; *encoding; encoding++) { if (strcasecmp((*encoding)->name, name) == 0) { return *encoding; } } /* search MIME charset name */ for (encoding = mbfl_encoding_ptr_list; *encoding; encoding++) { if ((*encoding)->mime_name) { if (strcasecmp((*encoding)->mime_name, name) == 0) { return *encoding; } } } /* search aliases */ for (encoding = mbfl_encoding_ptr_list; *encoding; encoding++) { if ((*encoding)->aliases) { for (const char **alias = (*encoding)->aliases; *alias; alias++) { if (strcasecmp(*alias, name) == 0) { return *encoding; } } } } return NULL; } const mbfl_encoding *mbfl_no2encoding(enum mbfl_no_encoding no_encoding) { const mbfl_encoding **encoding; for (encoding = mbfl_encoding_ptr_list; *encoding; encoding++) { if ((*encoding)->no_encoding == no_encoding) { return *encoding; } } return NULL; } const char *mbfl_no_encoding2name(enum mbfl_no_encoding no_encoding) { const mbfl_encoding *encoding = mbfl_no2encoding(no_encoding); return encoding ? encoding->name : ""; } const mbfl_encoding **mbfl_get_supported_encodings(void) { return mbfl_encoding_ptr_list; } const char *mbfl_encoding_preferred_mime_name(const mbfl_encoding *encoding) { if (encoding->mime_name && encoding->mime_name[0] != '\0') { return encoding->mime_name; } return NULL; }
5,377
24.488152
76
c
php-src
php-src-master/ext/mbstring/libmbfl/mbfl/mbfl_encoding.h
/* * "streamable kanji code filter and converter" * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved. * * LICENSE NOTICES * * This file is part of "streamable kanji code filter and converter", * which is distributed under the terms of GNU Lesser General Public * License (version 2) as published by the Free Software Foundation. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with "streamable kanji code filter and converter"; * if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA * * The author of this file: * */ /* * The source code included in this files was separated from mbfilter.h * by Moriyoshi Koizumi <[email protected]> on 20 Dec 2002. The file * mbfilter.h is included in this package . * */ #ifndef MBFL_ENCODING_H #define MBFL_ENCODING_H #include "mbfl_defs.h" #include "mbfl_consts.h" #include "zend.h" enum mbfl_no_encoding { mbfl_no_encoding_invalid = -1, mbfl_no_encoding_pass, mbfl_no_encoding_wchar, mbfl_no_encoding_base64, mbfl_no_encoding_uuencode, mbfl_no_encoding_html_ent, mbfl_no_encoding_qprint, mbfl_no_encoding_7bit, mbfl_no_encoding_8bit, mbfl_no_encoding_charset_min, mbfl_no_encoding_ucs4, mbfl_no_encoding_ucs4be, mbfl_no_encoding_ucs4le, mbfl_no_encoding_ucs2, mbfl_no_encoding_ucs2be, mbfl_no_encoding_ucs2le, mbfl_no_encoding_utf32, mbfl_no_encoding_utf32be, mbfl_no_encoding_utf32le, mbfl_no_encoding_utf16, mbfl_no_encoding_utf16be, mbfl_no_encoding_utf16le, mbfl_no_encoding_utf8, mbfl_no_encoding_utf8_docomo, mbfl_no_encoding_utf8_kddi_a, mbfl_no_encoding_utf8_kddi_b, mbfl_no_encoding_utf8_sb, mbfl_no_encoding_utf7, mbfl_no_encoding_utf7imap, mbfl_no_encoding_ascii, mbfl_no_encoding_euc_jp, mbfl_no_encoding_eucjp2004, mbfl_no_encoding_sjis, mbfl_no_encoding_eucjp_win, mbfl_no_encoding_sjis_docomo, mbfl_no_encoding_sjis_kddi, mbfl_no_encoding_sjis_sb, mbfl_no_encoding_sjis_mac, mbfl_no_encoding_sjis2004, mbfl_no_encoding_cp932, mbfl_no_encoding_sjiswin, mbfl_no_encoding_cp51932, mbfl_no_encoding_jis, mbfl_no_encoding_2022jp, mbfl_no_encoding_2022jp_2004, mbfl_no_encoding_2022jp_kddi, mbfl_no_encoding_2022jpms, mbfl_no_encoding_gb18030, mbfl_no_encoding_cp1252, mbfl_no_encoding_cp1254, mbfl_no_encoding_8859_1, mbfl_no_encoding_8859_2, mbfl_no_encoding_8859_3, mbfl_no_encoding_8859_4, mbfl_no_encoding_8859_5, mbfl_no_encoding_8859_6, mbfl_no_encoding_8859_7, mbfl_no_encoding_8859_8, mbfl_no_encoding_8859_9, mbfl_no_encoding_8859_10, mbfl_no_encoding_8859_13, mbfl_no_encoding_8859_14, mbfl_no_encoding_8859_15, mbfl_no_encoding_euc_cn, mbfl_no_encoding_cp936, mbfl_no_encoding_euc_tw, mbfl_no_encoding_big5, mbfl_no_encoding_cp950, mbfl_no_encoding_euc_kr, mbfl_no_encoding_2022kr, mbfl_no_encoding_uhc, mbfl_no_encoding_hz, mbfl_no_encoding_cp1251, mbfl_no_encoding_cp866, mbfl_no_encoding_koi8r, mbfl_no_encoding_koi8u, mbfl_no_encoding_8859_16, mbfl_no_encoding_armscii8, mbfl_no_encoding_cp850, mbfl_no_encoding_cp50220, mbfl_no_encoding_cp50221, mbfl_no_encoding_cp50222, mbfl_no_encoding_charset_max }; struct _mbfl_convert_filter; struct mbfl_convert_vtbl { enum mbfl_no_encoding from; enum mbfl_no_encoding to; void (*filter_ctor)(struct _mbfl_convert_filter *filter); void (*filter_dtor)(struct _mbfl_convert_filter *filter); int (*filter_function)(int c, struct _mbfl_convert_filter *filter); int (*filter_flush)(struct _mbfl_convert_filter *filter); void (*filter_copy)(struct _mbfl_convert_filter *src, struct _mbfl_convert_filter *dest); }; typedef struct { unsigned char *out; unsigned char *limit; uint32_t state; uint32_t errors; uint32_t replacement_char; unsigned int error_mode; zend_string *str; } mb_convert_buf; typedef size_t (*mb_to_wchar_fn)(unsigned char **in, size_t *in_len, uint32_t *out, size_t out_len, unsigned int *state); typedef void (*mb_from_wchar_fn)(uint32_t *in, size_t in_len, mb_convert_buf *out, bool end); typedef bool (*mb_check_fn)(unsigned char *in, size_t in_len); /* When converting encoded text to a buffer of wchars (Unicode codepoints) using `mb_to_wchar_fn`, * the buffer must be at least this size (to work with all supported text encodings) */ #define MBSTRING_MIN_WCHAR_BUFSIZE 5 static inline void mb_convert_buf_init(mb_convert_buf *buf, size_t initsize, uint32_t repl_char, unsigned int err_mode) { buf->state = buf->errors = 0; buf->str = emalloc(_ZSTR_STRUCT_SIZE(initsize)); buf->out = (unsigned char*)ZSTR_VAL(buf->str); buf->limit = buf->out + initsize; buf->replacement_char = repl_char; buf->error_mode = err_mode; } #define MB_CONVERT_BUF_ENSURE(buf, out, limit, needed) \ ZEND_ASSERT(out <= limit); \ if ((limit - out) < (needed)) { \ size_t oldsize = limit - (unsigned char*)ZSTR_VAL((buf)->str); \ size_t newsize = oldsize + MAX(oldsize >> 1, needed); \ zend_string *newstr = erealloc((buf)->str, _ZSTR_STRUCT_SIZE(newsize)); \ out = (unsigned char*)ZSTR_VAL(newstr) + (out - (unsigned char*)ZSTR_VAL((buf)->str)); \ limit = (unsigned char*)ZSTR_VAL(newstr) + newsize; \ (buf)->str = newstr; \ } #define MB_CONVERT_BUF_STORE(buf, _out, _limit) (buf)->out = _out; (buf)->limit = _limit #define MB_CONVERT_BUF_LOAD(buf, _out, _limit) _out = (buf)->out; _limit = (buf)->limit #define MB_CONVERT_ERROR(buf, out, limit, bad_cp, conv_fn) \ MB_CONVERT_BUF_STORE(buf, out, limit); \ mb_illegal_output(bad_cp, conv_fn, buf); \ MB_CONVERT_BUF_LOAD(buf, out, limit) static inline unsigned char* mb_convert_buf_add(unsigned char *out, char c) { *out++ = c; return out; } static inline unsigned char* mb_convert_buf_add2(unsigned char *out, char c1, char c2) { *out++ = c1; *out++ = c2; return out; } static inline unsigned char* mb_convert_buf_add3(unsigned char *out, char c1, char c2, char c3) { *out++ = c1; *out++ = c2; *out++ = c3; return out; } static inline unsigned char* mb_convert_buf_add4(unsigned char *out, char c1, char c2, char c3, char c4) { *out++ = c1; *out++ = c2; *out++ = c3; *out++ = c4; return out; } static inline unsigned char* mb_convert_buf_appends(unsigned char *out, const char *s) { while (*s) { *out++ = *s++; } return out; } static inline unsigned char* mb_convert_buf_appendn(unsigned char *out, const char *s, size_t n) { while (n--) { *out++ = *s++; } return out; } static inline zend_string* mb_convert_buf_result_raw(mb_convert_buf *buf) { ZEND_ASSERT(buf->out <= buf->limit); zend_string *ret = buf->str; /* See `zend_string_alloc` in zend_string.h */ GC_SET_REFCOUNT(ret, 1); GC_TYPE_INFO(ret) = GC_STRING; ZSTR_H(ret) = 0; ZSTR_LEN(ret) = buf->out - (unsigned char*)ZSTR_VAL(ret); *(buf->out) = '\0'; return ret; } typedef struct { enum mbfl_no_encoding no_encoding; const char *name; const char *mime_name; const char **aliases; const unsigned char *mblen_table; unsigned int flag; const struct mbfl_convert_vtbl *input_filter; const struct mbfl_convert_vtbl *output_filter; mb_to_wchar_fn to_wchar; mb_from_wchar_fn from_wchar; mb_check_fn check; } mbfl_encoding; extern const mbfl_encoding mbfl_encoding_utf8; static inline zend_string* mb_convert_buf_result(mb_convert_buf *buf, const mbfl_encoding *enc) { zend_string *ret = mb_convert_buf_result_raw(buf); if (enc == &mbfl_encoding_utf8 && buf->error_mode != MBFL_OUTPUTFILTER_ILLEGAL_MODE_BADUTF8) { GC_ADD_FLAGS(ret, IS_STR_VALID_UTF8); } return ret; } /* Used if we initialize an `mb_convert_buf` but then discover we don't actually * want to return `zend_string` */ static inline void mb_convert_buf_free(mb_convert_buf *buf) { efree(buf->str); } static inline size_t mb_convert_buf_len(mb_convert_buf *buf) { return buf->out - (unsigned char*)ZSTR_VAL(buf->str); } static inline void mb_convert_buf_reset(mb_convert_buf *buf, size_t len) { buf->out = (unsigned char*)ZSTR_VAL(buf->str) + len; ZEND_ASSERT(buf->out <= buf->limit); } MBFLAPI extern const mbfl_encoding *mbfl_name2encoding(const char *name); MBFLAPI extern const mbfl_encoding *mbfl_no2encoding(enum mbfl_no_encoding no_encoding); MBFLAPI extern const mbfl_encoding **mbfl_get_supported_encodings(void); MBFLAPI extern const char *mbfl_no_encoding2name(enum mbfl_no_encoding no_encoding); MBFLAPI extern const char *mbfl_encoding_preferred_mime_name(const mbfl_encoding *encoding); #endif /* MBFL_ENCODING_H */
8,687
28.753425
121
h
php-src
php-src-master/ext/mbstring/libmbfl/mbfl/mbfl_filter_output.c
/* * "streamable kanji code filter and converter" * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved. * * LICENSE NOTICES * * This file is part of "streamable kanji code filter and converter", * which is distributed under the terms of GNU Lesser General Public * License (version 2) as published by the Free Software Foundation. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with "streamable kanji code filter and converter"; * if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA * * The author of this file: * */ /* * The source code included in this file was separated from mbfilter.c * by Moriyoshi Koizumi <[email protected]> on 20 Dec 2002. The file * mbfilter.c is included in this package . * */ #include "mbfl_convert.h" #include "mbfl_filter_output.h" int mbfl_filter_output_pipe(int c, void* data) { mbfl_convert_filter *filter = (mbfl_convert_filter*)data; return (*filter->filter_function)(c, filter); } int mbfl_filter_output_null(int c, void* data) { return 0; }
1,371
30.181818
72
c
php-src
php-src-master/ext/mbstring/libmbfl/mbfl/mbfl_filter_output.h
/* * "streamable kanji code filter and converter" * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved. * * LICENSE NOTICES * * This file is part of "streamable kanji code filter and converter", * which is distributed under the terms of GNU Lesser General Public * License (version 2) as published by the Free Software Foundation. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with "streamable kanji code filter and converter"; * if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA * * The author of this file: * */ /* * The source code included in this files was separated from mbfilter.h * by Moriyoshi Koizumi <[email protected]> on 20 Dec 2002. The file * mbfilter.h is included in this package . * */ #ifndef MBFL_FILTER_OUTPUT_H #define MBFL_FILTER_OUTPUT_H MBFLAPI extern int mbfl_filter_output_pipe(int c, void* data); MBFLAPI extern int mbfl_filter_output_null(int c, void* data); #endif /* MBFL_FILTER_OUTPUT_H */
1,313
33.578947
72
h
php-src
php-src-master/ext/mbstring/libmbfl/mbfl/mbfl_language.c
/* * "streamable kanji code filter and converter" * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved. * * LICENSE NOTICES * * This file is part of "streamable kanji code filter and converter", * which is distributed under the terms of GNU Lesser General Public * License (version 2) as published by the Free Software Foundation. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with "streamable kanji code filter and converter"; * if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA * * The author of this file: * */ /* * The source code included in this file was separated from mbfilter.c * by Moriyoshi Koizumi <[email protected]> on 20 Dec 2002. The file * mbfilter.c is included in this package . * */ #include "libmbfl/config.h" #include <stddef.h> #include <string.h> #ifdef HAVE_STRINGS_H #include <strings.h> #endif #include "mbfl_encoding.h" #include "mbfl_language.h" #include "nls/nls_ja.h" #include "nls/nls_kr.h" #include "nls/nls_zh.h" #include "nls/nls_uni.h" #include "nls/nls_de.h" #include "nls/nls_ru.h" #include "nls/nls_ua.h" #include "nls/nls_en.h" #include "nls/nls_hy.h" #include "nls/nls_tr.h" #include "nls/nls_neutral.h" #ifndef HAVE_STRCASECMP #ifdef HAVE_STRICMP #define strcasecmp stricmp #endif #endif static const mbfl_language *mbfl_language_ptr_table[] = { &mbfl_language_uni, &mbfl_language_japanese, &mbfl_language_korean, &mbfl_language_simplified_chinese, &mbfl_language_traditional_chinese, &mbfl_language_english, &mbfl_language_german, &mbfl_language_russian, &mbfl_language_ukrainian, &mbfl_language_armenian, &mbfl_language_turkish, &mbfl_language_neutral, NULL }; /* language resolver */ const mbfl_language * mbfl_name2language(const char *name) { const mbfl_language *language; int i, j; if (name == NULL) { return NULL; } i = 0; while ((language = mbfl_language_ptr_table[i++]) != NULL){ if (strcasecmp(language->name, name) == 0) { return language; } } i = 0; while ((language = mbfl_language_ptr_table[i++]) != NULL){ if (strcasecmp(language->short_name, name) == 0) { return language; } } /* search aliases */ i = 0; while ((language = mbfl_language_ptr_table[i++]) != NULL) { if (language->aliases != NULL) { j = 0; while (language->aliases[j]) { if (strcasecmp(language->aliases[j], name) == 0) { return language; } j++; } } } return NULL; } const mbfl_language * mbfl_no2language(enum mbfl_no_language no_language) { const mbfl_language *language; int i; i = 0; while ((language = mbfl_language_ptr_table[i++]) != NULL){ if (language->no_language == no_language) { return language; } } return NULL; } enum mbfl_no_language mbfl_name2no_language(const char *name) { const mbfl_language *language; language = mbfl_name2language(name); if (language == NULL) { return mbfl_no_language_invalid; } else { return language->no_language; } } const char * mbfl_no_language2name(enum mbfl_no_language no_language) { const mbfl_language *language; language = mbfl_no2language(no_language); if (language == NULL) { return ""; } else { return language->name; } }
3,512
20.95625
72
c
php-src
php-src-master/ext/mbstring/libmbfl/mbfl/mbfl_language.h
/* * "streamable kanji code filter and converter" * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved. * * LICENSE NOTICES * * This file is part of "streamable kanji code filter and converter", * which is distributed under the terms of GNU Lesser General Public * License (version 2) as published by the Free Software Foundation. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with "streamable kanji code filter and converter"; * if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA * * The author of this file: * */ /* * The source code included in this files was separated from mbfilter.h * by Moriyoshi Koizumi <[email protected]> on 20 Dec 2002. The file * mbfilter.h is included in this package . * */ #ifndef MBFL_LANGUAGE_H #define MBFL_LANGUAGE_H #include "mbfl_defs.h" #include "mbfl_encoding.h" enum mbfl_no_language { mbfl_no_language_invalid = -1, mbfl_no_language_neutral, mbfl_no_language_uni, mbfl_no_language_min, mbfl_no_language_catalan, /* ca */ mbfl_no_language_danish, /* da */ mbfl_no_language_german, /* de */ mbfl_no_language_english, /* en */ mbfl_no_language_estonian, /* et */ mbfl_no_language_greek, /* el */ mbfl_no_language_spanish, /* es */ mbfl_no_language_french, /* fr */ mbfl_no_language_italian, /* it */ mbfl_no_language_japanese, /* ja */ mbfl_no_language_korean, /* ko */ mbfl_no_language_dutch, /* nl */ mbfl_no_language_polish, /* pl */ mbfl_no_language_portuguese, /* pt */ mbfl_no_language_swedish, /* sv */ mbfl_no_language_simplified_chinese, /* zh-cn */ mbfl_no_language_traditional_chinese, /* zh-tw */ mbfl_no_language_russian, /* ru */ mbfl_no_language_ukrainian, /* ua */ mbfl_no_language_armenian, /* hy */ mbfl_no_language_turkish, /* tr */ mbfl_no_language_max }; typedef enum mbfl_no_language mbfl_language_id; /* * language */ typedef struct _mbfl_language { enum mbfl_no_language no_language; const char *name; const char *short_name; const char **aliases; enum mbfl_no_encoding mail_charset; enum mbfl_no_encoding mail_header_encoding; enum mbfl_no_encoding mail_body_encoding; } mbfl_language; MBFLAPI extern const mbfl_language * mbfl_name2language(const char *name); MBFLAPI extern const mbfl_language * mbfl_no2language(enum mbfl_no_language no_language); MBFLAPI extern enum mbfl_no_language mbfl_name2no_language(const char *name); MBFLAPI extern const char * mbfl_no_language2name(enum mbfl_no_language no_language); #endif /* MBFL_LANGUAGE_H */
2,868
31.602273
89
h
php-src
php-src-master/ext/mbstring/libmbfl/mbfl/mbfl_memory_device.c
/* * "streamable kanji code filter and converter" * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved. * * LICENSE NOTICES * * This file is part of "streamable kanji code filter and converter", * which is distributed under the terms of GNU Lesser General Public * License (version 2) as published by the Free Software Foundation. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with "streamable kanji code filter and converter"; * if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA * * The author of this file: * */ /* * The source code included in this files was separated from mbfilter.c * by Moriyoshi Koizumi <[email protected]> on 20 Dec 2002. The file * mbfilter.c is included in this package . * */ #include <stddef.h> #include <string.h> #include "zend.h" #include "mbfl_memory_device.h" /* * memory device output functions */ void mbfl_memory_device_init(mbfl_memory_device *device, size_t initsz, size_t allocsz) { device->buffer = (initsz > 0) ? emalloc(initsz) : NULL; device->length = initsz; device->pos = 0; device->allocsz = MAX(allocsz, MBFL_MEMORY_DEVICE_ALLOC_SIZE); } void mbfl_memory_device_realloc(mbfl_memory_device *device, size_t initsz, size_t allocsz) { if (initsz > device->length) { device->buffer = erealloc(device->buffer, initsz); device->length = initsz; } device->allocsz = MAX(allocsz, MBFL_MEMORY_DEVICE_ALLOC_SIZE); } void mbfl_memory_device_clear(mbfl_memory_device *device) { if (device->buffer) { efree(device->buffer); } device->buffer = NULL; device->length = device->pos = 0; } void mbfl_memory_device_reset(mbfl_memory_device *device) { device->pos = 0; } void mbfl_memory_device_unput(mbfl_memory_device *device) { if (device->pos > 0) { device->pos--; } } mbfl_string* mbfl_memory_device_result(mbfl_memory_device *device, mbfl_string *result) { result->len = device->pos; mbfl_memory_device_output('\0', device); result->val = device->buffer; device->buffer = NULL; device->length = device->pos = 0; return result; } int mbfl_memory_device_output(int c, void *data) { mbfl_memory_device *device = (mbfl_memory_device *)data; if (device->pos >= device->length) { /* reallocate buffer */ if (device->length > SIZE_MAX - device->allocsz) { /* overflow */ return -1; } size_t newlen = device->length + device->allocsz; device->buffer = erealloc(device->buffer, newlen); device->length = newlen; } device->buffer[device->pos++] = (unsigned char)c; return 0; } int mbfl_memory_device_strcat(mbfl_memory_device *device, const char *psrc) { return mbfl_memory_device_strncat(device, psrc, strlen(psrc)); } int mbfl_memory_device_strncat(mbfl_memory_device *device, const char *psrc, size_t len) { if (len > device->length - device->pos) { /* reallocate buffer */ if (len > SIZE_MAX - MBFL_MEMORY_DEVICE_ALLOC_SIZE || device->length > SIZE_MAX - (len + MBFL_MEMORY_DEVICE_ALLOC_SIZE)) { /* overflow */ return -1; } size_t newlen = device->length + len + MBFL_MEMORY_DEVICE_ALLOC_SIZE; device->buffer = erealloc(device->buffer, newlen); device->length = newlen; } unsigned char *w = &device->buffer[device->pos]; memcpy(w, psrc, len); device->pos += len; return 0; } int mbfl_memory_device_devcat(mbfl_memory_device *dest, mbfl_memory_device *src) { return mbfl_memory_device_strncat(dest, (const char*)src->buffer, src->pos); } void mbfl_wchar_device_init(mbfl_wchar_device *device) { device->buffer = NULL; device->length = 0; device->pos = 0; device->allocsz = MBFL_MEMORY_DEVICE_ALLOC_SIZE; } void mbfl_wchar_device_clear(mbfl_wchar_device *device) { if (device->buffer) { efree(device->buffer); } device->buffer = NULL; device->length = device->pos = 0; } int mbfl_wchar_device_output(int c, void *data) { mbfl_wchar_device *device = (mbfl_wchar_device *)data; if (device->pos >= device->length) { /* reallocate buffer */ size_t newlen; if (device->length > SIZE_MAX - device->allocsz) { /* overflow */ return -1; } newlen = device->length + device->allocsz; if (newlen > SIZE_MAX / sizeof(int)) { /* overflow */ return -1; } device->buffer = erealloc(device->buffer, newlen * sizeof(int)); device->length = newlen; } device->buffer[device->pos++] = c; return 0; }
4,649
24.135135
90
c
php-src
php-src-master/ext/mbstring/libmbfl/mbfl/mbfl_memory_device.h
/* * "streamable kanji code filter and converter" * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved. * * LICENSE NOTICES * * This file is part of "streamable kanji code filter and converter", * which is distributed under the terms of GNU Lesser General Public * License (version 2) as published by the Free Software Foundation. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with "streamable kanji code filter and converter"; * if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA * * The author of this file: * */ /* * The source code included in this files was separated from mbfilter.h * by Moriyoshi Koizumi <[email protected]> on 20 Dec 2002. The file * mbfilter.h is included in this package . * */ #ifndef MBFL_MEMORY_DEVICE_H #define MBFL_MEMORY_DEVICE_H #include "mbfl_defs.h" #include "mbfl_string.h" #define MBFL_MEMORY_DEVICE_ALLOC_SIZE 64 typedef struct _mbfl_memory_device { unsigned char *buffer; size_t length; size_t pos; size_t allocsz; } mbfl_memory_device; typedef struct _mbfl_wchar_device { unsigned int *buffer; size_t length; size_t pos; size_t allocsz; } mbfl_wchar_device; MBFLAPI extern void mbfl_memory_device_init( mbfl_memory_device *device, size_t initsz, size_t allocsz); MBFLAPI extern void mbfl_memory_device_realloc( mbfl_memory_device *device, size_t initsz, size_t allocsz); MBFLAPI extern void mbfl_memory_device_clear(mbfl_memory_device *device); MBFLAPI extern void mbfl_memory_device_reset(mbfl_memory_device *device); MBFLAPI extern mbfl_string * mbfl_memory_device_result( mbfl_memory_device *device, mbfl_string *result); MBFLAPI extern void mbfl_memory_device_unput(mbfl_memory_device *device); MBFLAPI extern int mbfl_memory_device_output(int c, void *data); MBFLAPI extern int mbfl_memory_device_strcat(mbfl_memory_device *device, const char *psrc); MBFLAPI extern int mbfl_memory_device_strncat( mbfl_memory_device *device, const char *psrc, size_t len); MBFLAPI extern int mbfl_memory_device_devcat(mbfl_memory_device *dest, mbfl_memory_device *src); MBFLAPI extern void mbfl_wchar_device_init(mbfl_wchar_device *device); MBFLAPI extern int mbfl_wchar_device_output(int c, void *data); MBFLAPI extern void mbfl_wchar_device_clear(mbfl_wchar_device *device); #endif /* MBFL_MEMORY_DEVICE_H */
2,652
35.342466
96
h
php-src
php-src-master/ext/mbstring/libmbfl/mbfl/mbfl_string.c
/* * "streamable kanji code filter and converter" * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved. * * LICENSE NOTICES * * This file is part of "streamable kanji code filter and converter", * which is distributed under the terms of GNU Lesser General Public * License (version 2) as published by the Free Software Foundation. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with "streamable kanji code filter and converter"; * if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA * * The author of this file: * */ /* * The source code included in this file was separated from mbfilter.c * by Moriyoshi Koizumi <[email protected]> on 20 Dec 2002. The file * mbfilter.c is included in this package . * */ #include "mbfl_string.h" #include "mbfilter_pass.h" void mbfl_string_init_set(mbfl_string *string, const mbfl_encoding *encoding) { string->encoding = encoding; string->val = NULL; string->len = 0; } void mbfl_string_init(mbfl_string *string) { mbfl_string_init_set(string, &mbfl_encoding_pass); } void mbfl_string_clear(mbfl_string *string) { if (string->val) { efree(string->val); } mbfl_string_init_set(string, NULL); /* Poison it so any attempt to reuse will fail hard */ }
1,582
28.867925
91
c
php-src
php-src-master/ext/mbstring/libmbfl/mbfl/mbfl_string.h
/* * "streamable kanji code filter and converter" * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved. * * LICENSE NOTICES * * This file is part of "streamable kanji code filter and converter", * which is distributed under the terms of GNU Lesser General Public * License (version 2) as published by the Free Software Foundation. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with "streamable kanji code filter and converter"; * if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA * * The author of this file: * */ /* * The source code included in this files was separated from mbfilter.h * by Moriyoshi Koizumi <[email protected]> on 20 Dec 2002. The file * mbfilter.h is included in this package . * */ #ifndef MBFL_STRING_H #define MBFL_STRING_H #include <stddef.h> #include "mbfl_defs.h" #include "mbfl_encoding.h" #include "mbfl_language.h" /* * string object */ typedef struct _mbfl_string { 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, const mbfl_encoding *encoding); MBFLAPI extern void mbfl_string_clear(mbfl_string *string); #endif /* MBFL_STRING_H */
1,613
29.45283
93
h
php-src
php-src-master/ext/mysqli/mysqli_driver.c
/* +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Georg Richter <[email protected]> | +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <signal.h> #include "php.h" #include "php_ini.h" #include "ext/standard/info.h" #include "php_mysqli_structs.h" #include "zend_exceptions.h" /* {{{ property driver_report_read */ static int driver_report_read(mysqli_object *obj, zval *retval, bool quiet) { ZVAL_LONG(retval, MyG(report_mode)); return SUCCESS; } /* }}} */ /* {{{ property driver_report_write */ static int driver_report_write(mysqli_object *obj, zval *value) { ZEND_ASSERT(Z_TYPE_P(value) == IS_LONG); MyG(report_mode) = Z_LVAL_P(value); return SUCCESS; } /* }}} */ /* {{{ property driver_client_version_read */ static int driver_client_version_read(mysqli_object *obj, zval *retval, bool quiet) { ZVAL_LONG(retval, mysql_get_client_version()); return SUCCESS; } /* }}} */ /* {{{ property driver_client_info_read */ static int driver_client_info_read(mysqli_object *obj, zval *retval, bool quiet) { ZVAL_STRING(retval, (char *)mysql_get_client_info()); return SUCCESS; } /* }}} */ /* {{{ property driver_driver_version_read */ static int driver_driver_version_read(mysqli_object *obj, zval *retval, bool quiet) { if (quiet) { return FAILURE; } zend_error(E_DEPRECATED, "The driver_version property is deprecated"); ZVAL_LONG(retval, MYSQLI_VERSION_ID); return SUCCESS; } /* }}} */ const mysqli_property_entry mysqli_driver_property_entries[] = { {"client_info", sizeof("client_info") - 1, driver_client_info_read, NULL}, {"client_version", sizeof("client_version") - 1, driver_client_version_read, NULL}, {"driver_version", sizeof("driver_version") - 1, driver_driver_version_read, NULL}, {"report_mode", sizeof("report_mode") - 1, driver_report_read, driver_report_write}, {NULL, 0, NULL, NULL} };
2,735
31.963855
85
c
php-src
php-src-master/ext/mysqli/mysqli_exception.c
/* +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Georg Richter <[email protected]> | +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <signal.h> #include "php.h" #include "php_ini.h" #include "ext/standard/info.h" #include "php_mysqli_structs.h" #include "mysqli_priv.h" #include "zend_exceptions.h" void php_mysqli_throw_sql_exception(char *sqlstate, int errorno, char *format, ...) { zval sql_ex; va_list arg; char *message; va_start(arg, format); vspprintf(&message, 0, format, arg); va_end(arg); if (!(MyG(report_mode) & MYSQLI_REPORT_STRICT)) { php_error_docref(NULL, E_WARNING, "(%s/%d): %s", sqlstate, errorno, message); efree(message); return; } object_init_ex(&sql_ex, mysqli_exception_class_entry); if (message) { zend_update_property_string( mysqli_exception_class_entry, Z_OBJ(sql_ex), "message", sizeof("message") - 1, message); } if (sqlstate) { zend_update_property_string( mysqli_exception_class_entry, Z_OBJ(sql_ex), "sqlstate", sizeof("sqlstate") - 1, sqlstate); } else { zend_update_property_string( mysqli_exception_class_entry, Z_OBJ(sql_ex), "sqlstate", sizeof("sqlstate") - 1, "00000"); } efree(message); zend_update_property_long(mysqli_exception_class_entry, Z_OBJ(sql_ex), "code", sizeof("code") - 1, errorno); zend_throw_exception_object(&sql_ex); } PHP_METHOD(mysqli_sql_exception, getSqlState) { zval *prop; zval rv; ZEND_PARSE_PARAMETERS_NONE(); prop = zend_read_property(mysqli_exception_class_entry, Z_OBJ_P(ZEND_THIS), "sqlstate", sizeof("sqlstate")-1, 1, &rv); ZVAL_DEREF(prop); zend_string *str = zval_get_string(prop); RETURN_STR(str); }
2,541
30.775
119
c
php-src
php-src-master/ext/mysqli/mysqli_mysqlnd.h
/* +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Georg Richter <[email protected]> | | Andrey Hristov <[email protected]> | | Ulf Wendel <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef MYSQLI_MYSQLND_H #define MYSQLI_MYSQLND_H #include "ext/mysqlnd/mysqlnd_libmysql_compat.h" #include "ext/mysqlnd/mysqlnd_portability.h" /* Here comes non-libmysql API to have less ifdefs in mysqli*/ #define MYSQLI_CLOSE_EXPLICIT MYSQLND_CLOSE_EXPLICIT #define MYSQLI_CLOSE_IMPLICIT MYSQLND_CLOSE_IMPLICIT #define MYSQLI_CLOSE_DISCONNECTED MYSQLND_CLOSE_DISCONNECTED #define mysqli_result_is_unbuffered(r) ((r)->unbuf) #define mysqli_result_is_unbuffered_and_not_everything_is_fetched(r) ((r)->unbuf && !(r)->unbuf->eof_reached) #define mysqli_server_status(c) mysqlnd_get_server_status((c)) #define mysqli_stmt_get_id(s) ((s)->data->stmt_id) #define mysqli_stmt_warning_count(s) mysqlnd_stmt_warning_count((s)) #define mysqli_stmt_server_status(s) mysqlnd_stmt_server_status((s)) #define mysqli_stmt_get_connection(s) (s)->data->conn #define mysqli_close(c, how) mysqlnd_close((c), (how)) #define mysqli_stmt_close(c, implicit) mysqlnd_stmt_close((c), (implicit)) #define mysqli_free_result(r, implicit) mysqlnd_free_result((r), (implicit)) #define mysqli_async_query(c, q, l) mysqlnd_async_query((c), (q), (l)) #define mysqli_change_user_silent(c, u, p, d, p_len) mysqlnd_change_user_ex((c), (u), (p), (d), true, (size_t)(p_len)) #endif
2,439
53.222222
120
h
php-src
php-src-master/ext/mysqli/mysqli_priv.h
/* +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Georg Richter <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef MYSQLI_PRIV_H #define MYSQLI_PRIV_H #ifdef PHP_MYSQL_UNIX_SOCK_ADDR #ifdef MYSQL_UNIX_ADDR #undef MYSQL_UNIX_ADDR #endif #define MYSQL_UNIX_ADDR PHP_MYSQL_UNIX_SOCK_ADDR #endif extern const zend_function_entry mysqli_functions[]; extern const zend_function_entry mysqli_link_methods[]; extern const zend_function_entry mysqli_stmt_methods[]; extern const zend_function_entry mysqli_result_methods[]; extern const zend_function_entry mysqli_driver_methods[]; extern const zend_function_entry mysqli_warning_methods[]; extern const zend_function_entry mysqli_exception_methods[]; extern const mysqli_property_entry mysqli_link_property_entries[]; extern const mysqli_property_entry mysqli_result_property_entries[]; extern const mysqli_property_entry mysqli_stmt_property_entries[]; extern const mysqli_property_entry mysqli_driver_property_entries[]; extern const mysqli_property_entry mysqli_warning_property_entries[]; extern const zend_property_info mysqli_link_property_info_entries[]; extern const zend_property_info mysqli_result_property_info_entries[]; extern const zend_property_info mysqli_stmt_property_info_entries[]; extern const zend_property_info mysqli_driver_property_info_entries[]; extern const zend_property_info mysqli_warning_property_info_entries[]; extern int php_le_pmysqli(void); extern void php_mysqli_dtor_p_elements(void *data); extern void php_mysqli_close(MY_MYSQL * mysql, int close_type, int resource_status); extern void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flag, int into_object); extern void php_clear_stmt_bind(MY_STMT *stmt); extern void php_clear_mysql(MY_MYSQL *); extern MYSQLI_WARNING *php_get_warnings(MYSQLND_CONN_DATA * mysql); extern void php_clear_warnings(MYSQLI_WARNING *w); extern void php_free_stmt_bind_buffer(BIND_BUFFER bbuf, int type); extern void php_mysqli_report_error(const char *sqlstate, int errorno, const char *error); extern void php_mysqli_report_index(const char *query, unsigned int status); extern void php_mysqli_throw_sql_exception(char *sqlstate, int errorno, char *format, ...); #define PHP_MYSQLI_EXPORT(__type) PHP_MYSQLI_API __type PHP_MYSQLI_EXPORT(zend_object *) mysqli_objects_new(zend_class_entry *); #define MYSQLI_DISABLE_MQ if (mysql->multi_query) { \ mysql_set_server_option(mysql->mysql, MYSQL_OPTION_MULTI_STATEMENTS_OFF); \ mysql->multi_query = 0; \ } #define MYSQLI_ENABLE_MQ if (!mysql->multi_query) { \ mysql_set_server_option(mysql->mysql, MYSQL_OPTION_MULTI_STATEMENTS_ON); \ mysql->multi_query = 1; \ } /* Numbers that cannot be represented as a signed int are converted to a string instead (affects 32-bit builds). */ #define MYSQLI_RETURN_LONG_INT(__val) \ { \ if ((__val) < ZEND_LONG_MAX) { \ RETURN_LONG((zend_long) (__val)); \ } else { \ /* always used with my_ulonglong -> %llu */ \ RETURN_STR(strpprintf(0, MYSQLI_LLU_SPEC, (__val))); \ } \ } #define MYSQLI_STORE_RESULT 0 #define MYSQLI_USE_RESULT 1 #define MYSQLI_ASYNC 8 #define MYSQLI_STORE_RESULT_COPY_DATA 16 /* for mysqli_fetch_assoc */ #define MYSQLI_ASSOC 1 #define MYSQLI_NUM 2 #define MYSQLI_BOTH 3 /* fetch types */ #define FETCH_SIMPLE 1 #define FETCH_RESULT 2 /*** REPORT MODES ***/ #define MYSQLI_REPORT_OFF 0 #define MYSQLI_REPORT_ERROR 1 #define MYSQLI_REPORT_STRICT 2 #define MYSQLI_REPORT_INDEX 4 #define MYSQLI_REPORT_CLOSE 8 #define MYSQLI_REPORT_ALL 255 #define MYSQLI_REPORT_MYSQL_ERROR(mysql) \ if ((MyG(report_mode) & MYSQLI_REPORT_ERROR) && mysql_errno(mysql)) { \ php_mysqli_report_error(mysql_sqlstate(mysql), mysql_errno(mysql), mysql_error(mysql)); \ } #define MYSQLI_REPORT_STMT_ERROR(stmt) \ if ((MyG(report_mode) & MYSQLI_REPORT_ERROR) && mysql_stmt_errno(stmt)) { \ php_mysqli_report_error(mysql_stmt_sqlstate(stmt), mysql_stmt_errno(stmt), mysql_stmt_error(stmt)); \ } void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, bool is_real_connect, bool in_ctor); void php_mysqli_init(INTERNAL_FUNCTION_PARAMETERS, bool is_method); #endif /* MYSQLI_PRIV_H */
5,033
39.272
115
h
php-src
php-src-master/ext/mysqli/mysqli_report.c
/* +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Georg Richter <[email protected]> | +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php.h" #include "php_ini.h" #include "ext/standard/info.h" #include "php_mysqli_structs.h" extern void php_mysqli_throw_sql_exception(char *sqlstate, int errorno, char *format, ...); /* {{{ sets report level */ PHP_FUNCTION(mysqli_report) { zend_long flags; if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &flags) == FAILURE) { RETURN_THROWS(); } MyG(report_mode) = flags; RETURN_TRUE; } /* }}} */ /* {{{ void php_mysqli_report_error(char *sqlstate, int errorno, char *error) */ void php_mysqli_report_error(const char *sqlstate, int errorno, const char *error) { php_mysqli_throw_sql_exception((char *)sqlstate, errorno, "%s", error); } /* }}} */ /* {{{ void php_mysqli_report_index() */ void php_mysqli_report_index(const char *query, unsigned int status) { char index[15]; if (status & SERVER_QUERY_NO_GOOD_INDEX_USED) { strcpy(index, "Bad index"); } else if (status & SERVER_QUERY_NO_INDEX_USED) { strcpy(index, "No index"); } else { return; } php_mysqli_throw_sql_exception("00000", 0, "%s used in query/prepared statement %s", index, query); } /* }}} */
2,130
31.784615
100
c
php-src
php-src-master/ext/mysqli/mysqli_result_iterator.c
/* +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Georg Richter <[email protected]> | | Andrey Hristov <[email protected]> | | Ulf Wendel <[email protected]> | +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <signal.h> #include "php.h" #include "php_ini.h" #include "php_mysqli_structs.h" #include "mysqli_priv.h" #include "zend_interfaces.h" extern const zend_object_iterator_funcs php_mysqli_result_iterator_funcs; typedef struct { zend_object_iterator intern; mysqli_object *result; zval current_row; my_longlong row_num; } php_mysqli_result_iterator; /* {{{ */ zend_object_iterator *php_mysqli_result_get_iterator(zend_class_entry *ce, zval *object, int by_ref) { php_mysqli_result_iterator *iterator; if (by_ref) { zend_throw_error(NULL, "An iterator cannot be used with foreach by reference"); return NULL; } iterator = ecalloc(1, sizeof(php_mysqli_result_iterator)); zend_iterator_init(&iterator->intern); Z_ADDREF_P(object); ZVAL_OBJ(&iterator->intern.data, Z_OBJ_P(object)); iterator->intern.funcs = &php_mysqli_result_iterator_funcs; iterator->result = Z_MYSQLI_P(object); iterator->row_num = -1; return &iterator->intern; } /* }}} */ /* {{{ */ static void php_mysqli_result_iterator_dtor(zend_object_iterator *iter) { php_mysqli_result_iterator *iterator = (php_mysqli_result_iterator*)iter; /* cleanup handled in sxe_object_dtor as we don't always have an iterator wrapper */ zval_ptr_dtor(&iterator->intern.data); zval_ptr_dtor(&iterator->current_row); } /* }}} */ /* {{{ */ static int php_mysqli_result_iterator_valid(zend_object_iterator *iter) { php_mysqli_result_iterator *iterator = (php_mysqli_result_iterator*) iter; return Z_TYPE(iterator->current_row) == IS_ARRAY ? SUCCESS : FAILURE; } /* }}} */ /* {{{ */ static zval *php_mysqli_result_iterator_current_data(zend_object_iterator *iter) { php_mysqli_result_iterator *iterator = (php_mysqli_result_iterator*) iter; return &iterator->current_row; } /* }}} */ /* {{{ */ static void php_mysqli_result_iterator_move_forward(zend_object_iterator *iter) { php_mysqli_result_iterator *iterator = (php_mysqli_result_iterator*) iter; mysqli_object *intern = iterator->result; MYSQL_RES *result; MYSQLI_FETCH_RESOURCE_BY_OBJ(result, MYSQL_RES *, intern, "mysqli_result", MYSQLI_STATUS_VALID); zval_ptr_dtor(&iterator->current_row); php_mysqli_fetch_into_hash_aux(&iterator->current_row, result, MYSQLI_ASSOC); if (Z_TYPE(iterator->current_row) == IS_ARRAY) { iterator->row_num++; } } /* }}} */ /* {{{ */ static void php_mysqli_result_iterator_rewind(zend_object_iterator *iter) { php_mysqli_result_iterator *iterator = (php_mysqli_result_iterator*) iter; mysqli_object *intern = iterator->result; MYSQL_RES *result; MYSQLI_FETCH_RESOURCE_BY_OBJ(result, MYSQL_RES *, intern, "mysqli_result", MYSQLI_STATUS_VALID); if (mysqli_result_is_unbuffered(result)) { if (result->unbuf->eof_reached) { zend_error(E_WARNING, "Data fetched with MYSQLI_USE_RESULT can be iterated only once"); return; } } else { mysql_data_seek(result, 0); } iterator->row_num = -1; php_mysqli_result_iterator_move_forward(iter); } /* }}} */ /* {{{ php_mysqli_result_iterator_current_key */ static void php_mysqli_result_iterator_current_key(zend_object_iterator *iter, zval *key) { php_mysqli_result_iterator *iterator = (php_mysqli_result_iterator*) iter; ZVAL_LONG(key, iterator->row_num); } /* }}} */ /* {{{ php_mysqli_result_iterator_funcs */ const zend_object_iterator_funcs php_mysqli_result_iterator_funcs = { php_mysqli_result_iterator_dtor, php_mysqli_result_iterator_valid, php_mysqli_result_iterator_current_data, php_mysqli_result_iterator_current_key, php_mysqli_result_iterator_move_forward, php_mysqli_result_iterator_rewind, NULL, NULL, /* get_gc */ }; /* }}} */
4,787
29.890323
100
c
php-src
php-src-master/ext/mysqli/mysqli_warning.c
/* +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Georg Richter <[email protected]> | +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <signal.h> #include "php.h" #include "php_ini.h" #include "ext/standard/info.h" #include "php_mysqli_structs.h" #include "mysqli_priv.h" /* Define these in the PHP7 tree to make merging easy process */ #define ZSTR_DUPLICATE (1<<0) #define ZSTR_AUTOFREE (1<<1) #define ZVAL_UTF8_STRING(z, s, flags) ZVAL_STRING((z), (char*)(s)) #define ZVAL_UTF8_STRINGL(z, s, l, flags) ZVAL_STRINGL((z), (char*)(s), (l)) /* {{{ void php_clear_warnings() */ void php_clear_warnings(MYSQLI_WARNING *w) { MYSQLI_WARNING *n; while (w) { n = w; zval_ptr_dtor_str(&(w->reason)); zval_ptr_dtor_str(&(w->sqlstate)); w = w->next; efree(n); } } /* }}} */ /* {{{ MYSQLI_WARNING *php_new_warning */ static MYSQLI_WARNING *php_new_warning(zval * reason, int errorno) { MYSQLI_WARNING *w; w = (MYSQLI_WARNING *)ecalloc(1, sizeof(MYSQLI_WARNING)); ZVAL_COPY(&w->reason, reason); convert_to_string(&w->reason); ZVAL_UTF8_STRINGL(&(w->sqlstate), "HY000", sizeof("HY000") - 1, ZSTR_DUPLICATE); w->errorno = errorno; return w; } /* }}} */ /* {{{ MYSQLI_WARNING *php_get_warnings(MYSQL *mysql) */ MYSQLI_WARNING * php_get_warnings(MYSQLND_CONN_DATA * mysql) { MYSQLI_WARNING *w, *first = NULL, *prev = NULL; MYSQL_RES *result; zval row; if (mysql->m->query(mysql, "SHOW WARNINGS", 13)) { return NULL; } result = mysql->m->use_result(mysql); for (;;) { zval *entry; int mysqli_errno; mysqlnd_fetch_into(result, MYSQLND_FETCH_NUM, &row); if (Z_TYPE(row) != IS_ARRAY) { zval_ptr_dtor(&row); break; } zend_hash_internal_pointer_reset(Z_ARRVAL(row)); /* 0. we don't care about the first */ zend_hash_move_forward(Z_ARRVAL(row)); /* 1. Here comes the error no */ entry = zend_hash_get_current_data(Z_ARRVAL(row)); mysqli_errno = zval_get_long(entry); zend_hash_move_forward(Z_ARRVAL(row)); /* 2. Here comes the reason */ entry = zend_hash_get_current_data(Z_ARRVAL(row)); w = php_new_warning(entry, mysqli_errno); /* Don't destroy entry, because the row destroy will decrease the refcounter. Decreased twice then mysqlnd_free_result() will crash, because it will try to access already freed memory. */ if (!first) { first = w; } if (prev) { prev->next = (void *)w; } prev = w; zval_ptr_dtor(&row); } mysql_free_result(result); return first; } /* }}} */ /* {{{ bool mysqli_warning::next() */ PHP_METHOD(mysqli_warning, next) { MYSQLI_WARNING *w; mysqli_object *obj = Z_MYSQLI_P(ZEND_THIS); if (zend_parse_parameters_none() == FAILURE) { RETURN_THROWS(); } if (obj->ptr) { MYSQLI_FETCH_RESOURCE(w, MYSQLI_WARNING *, ZEND_THIS, "mysqli_warning", MYSQLI_STATUS_VALID); if (w && w->next) { w = w->next; ((MYSQLI_RESOURCE *)(obj->ptr))->ptr = w; RETURN_TRUE; } } RETURN_FALSE; } /* }}} */ /* {{{ property mysqli_warning_message */ static int mysqli_warning_message(mysqli_object *obj, zval *retval, bool quiet) { MYSQLI_WARNING *w; if (!obj->ptr || !((MYSQLI_RESOURCE *)(obj->ptr))->ptr) { if (!quiet) { zend_throw_error(NULL, "%s object is already closed", ZSTR_VAL(obj->zo.ce->name)); } return FAILURE; } w = (MYSQLI_WARNING *)((MYSQLI_RESOURCE *)(obj->ptr))->ptr; ZVAL_COPY(retval, &w->reason); return SUCCESS; } /* }}} */ /* {{{ property mysqli_warning_sqlstate */ static int mysqli_warning_sqlstate(mysqli_object *obj, zval *retval, bool quiet) { MYSQLI_WARNING *w; if (!obj->ptr || !((MYSQLI_RESOURCE *)(obj->ptr))->ptr) { if (!quiet) { zend_throw_error(NULL, "%s object is already closed", ZSTR_VAL(obj->zo.ce->name)); } return FAILURE; } w = (MYSQLI_WARNING *)((MYSQLI_RESOURCE *)(obj->ptr))->ptr; ZVAL_COPY(retval, &w->sqlstate); return SUCCESS; } /* }}} */ /* {{{ property mysqli_warning_error */ static int mysqli_warning_errno(mysqli_object *obj, zval *retval, bool quiet) { MYSQLI_WARNING *w; if (!obj->ptr || !((MYSQLI_RESOURCE *)(obj->ptr))->ptr) { if (!quiet) { zend_throw_error(NULL, "%s object is already closed", ZSTR_VAL(obj->zo.ce->name)); } return FAILURE; } w = (MYSQLI_WARNING *)((MYSQLI_RESOURCE *)(obj->ptr))->ptr; ZVAL_LONG(retval, w->errorno); return SUCCESS; } /* }}} */ PHP_METHOD(mysqli_warning, __construct) { ZEND_PARSE_PARAMETERS_NONE(); zend_throw_error(NULL, "Cannot directly construct mysqli_warning"); } /* {{{ mysqli_warning_property_entries */ const mysqli_property_entry mysqli_warning_property_entries[] = { {"message", sizeof("message") - 1, mysqli_warning_message, NULL}, {"sqlstate", sizeof("sqlstate") - 1, mysqli_warning_sqlstate, NULL}, {"errno", sizeof("errno") - 1, mysqli_warning_errno, NULL}, {NULL, 0, NULL, NULL} }; /* }}} */
5,718
24.53125
95
c
php-src
php-src-master/ext/mysqli/php_mysqli.h
/* +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Georg Richter <[email protected]> | | Andrey Hristov <[email protected]> | | Ulf Wendel <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef PHP_MYSQLI_H #define PHP_MYSQLI_H #define phpext_mysqli_ptr &mysqli_module_entry extern zend_module_entry mysqli_module_entry; #include "php_version.h" #define PHP_MYSQLI_VERSION PHP_VERSION #endif /* PHP_MYSQLI.H */
1,360
45.931034
74
h
php-src
php-src-master/ext/mysqli/php_mysqli_structs.h
/* +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Georg Richter <[email protected]> | | Andrey Hristov <[email protected]> | | Ulf Wendel <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef PHP_MYSQLI_STRUCTS_H #define PHP_MYSQLI_STRUCTS_H /* A little hack to prevent build break, when mysql is used together with * c-client, which also defines LIST. */ #ifdef LIST #undef LIST #endif #include "ext/mysqlnd/mysqlnd.h" #include "mysqli_mysqlnd.h" #define MYSQLI_VERSION_ID 101009 enum mysqli_status { MYSQLI_STATUS_UNKNOWN=0, MYSQLI_STATUS_INITIALIZED, MYSQLI_STATUS_VALID }; typedef struct { char *val; zend_ulong buflen; zend_ulong output_len; zend_ulong type; } VAR_BUFFER; typedef struct { unsigned int var_cnt; VAR_BUFFER *buf; zval *vars; my_bool *is_null; } BIND_BUFFER; typedef struct { MYSQL_STMT *stmt; BIND_BUFFER param; BIND_BUFFER result; char *query; } MY_STMT; typedef struct { MYSQL *mysql; zend_string *hash_key; zval li_read; php_stream *li_stream; unsigned int multi_query; bool persistent; int async_result_fetch_type; } MY_MYSQL; typedef struct { void *ptr; /* resource: (mysql, result, stmt) */ void *info; /* additional buffer */ enum mysqli_status status; /* object status */ } MYSQLI_RESOURCE; typedef struct _mysqli_object { void *ptr; HashTable *prop_handler; zend_object zo; } mysqli_object; /* extends zend_object */ static inline mysqli_object *php_mysqli_fetch_object(zend_object *obj) { return (mysqli_object *)((char*)(obj) - XtOffsetOf(mysqli_object, zo)); } #define Z_MYSQLI_P(zv) php_mysqli_fetch_object(Z_OBJ_P((zv))) typedef struct st_mysqli_warning MYSQLI_WARNING; struct st_mysqli_warning { zval reason; zval sqlstate; int errorno; MYSQLI_WARNING *next; }; typedef struct _mysqli_property_entry { const char *pname; size_t pname_length; int (*r_func)(mysqli_object *obj, zval *retval, bool quiet); int (*w_func)(mysqli_object *obj, zval *value); } mysqli_property_entry; typedef struct { zend_ptr_stack free_links; } mysqli_plist_entry; #ifdef PHP_WIN32 #define PHP_MYSQLI_API __declspec(dllexport) #ifndef L64 #define L64(x) x##i64 #endif typedef __int64 my_longlong; #else # if defined(__GNUC__) && __GNUC__ >= 4 # define PHP_MYSQLI_API __attribute__ ((visibility("default"))) # else # define PHP_MYSQLI_API # endif #ifndef L64 #define L64(x) x##LL #endif typedef int64_t my_longlong; #endif /* we need this for PRIu64 and PRId64 */ #include <inttypes.h> #define MYSQLI_LLU_SPEC "%" PRIu64 #define MYSQLI_LL_SPEC "%" PRId64 #ifdef ZTS #include "TSRM.h" #endif extern zend_class_entry *mysqli_link_class_entry; extern zend_class_entry *mysqli_stmt_class_entry; extern zend_class_entry *mysqli_result_class_entry; extern zend_class_entry *mysqli_driver_class_entry; extern zend_class_entry *mysqli_warning_class_entry; extern zend_class_entry *mysqli_exception_class_entry; extern int php_le_pmysqli(void); extern void php_mysqli_dtor_p_elements(void *data); extern void php_mysqli_close(MY_MYSQL * mysql, int close_type, int resource_status); extern const zend_object_iterator_funcs php_mysqli_result_iterator_funcs; extern zend_object_iterator *php_mysqli_result_get_iterator(zend_class_entry *ce, zval *object, int by_ref); extern void php_mysqli_fetch_into_hash_aux(zval *return_value, MYSQL_RES * result, zend_long fetchtype); #define MYSQLI_DISABLE_MQ if (mysql->multi_query) { \ mysql_set_server_option(mysql->mysql, MYSQL_OPTION_MULTI_STATEMENTS_OFF); \ mysql->multi_query = 0; \ } #define MYSQLI_ENABLE_MQ if (!mysql->multi_query) { \ mysql_set_server_option(mysql->mysql, MYSQL_OPTION_MULTI_STATEMENTS_ON); \ mysql->multi_query = 1; \ } #define MYSQLI_REGISTER_RESOURCE_EX(__ptr, __zval) \ (Z_MYSQLI_P(__zval))->ptr = __ptr; #define MYSQLI_RETVAL_RESOURCE(__ptr, __ce) \ RETVAL_OBJ(mysqli_objects_new(__ce)); \ MYSQLI_REGISTER_RESOURCE_EX(__ptr, return_value) #define MYSQLI_REGISTER_RESOURCE(__ptr, __ce) \ {\ zval *object = getThis(); \ if (!object || !instanceof_function(Z_OBJCE_P(object), mysqli_link_class_entry)) { \ object = return_value; \ ZVAL_OBJ(object, mysqli_objects_new(__ce)); \ } \ MYSQLI_REGISTER_RESOURCE_EX(__ptr, object)\ } #define MYSQLI_FETCH_RESOURCE(__ptr, __type, __id, __name, __check) \ { \ MYSQLI_RESOURCE *my_res; \ mysqli_object *intern = Z_MYSQLI_P(__id); \ if (!(my_res = (MYSQLI_RESOURCE *)intern->ptr)) {\ zend_throw_error(NULL, "%s object is already closed", ZSTR_VAL(intern->zo.ce->name));\ RETURN_THROWS();\ }\ __ptr = (__type)my_res->ptr; \ if (my_res->status < __check) { \ zend_throw_error(NULL, "%s object is not fully initialized", ZSTR_VAL(intern->zo.ce->name)); \ RETURN_THROWS();\ }\ } #define MYSQLI_FETCH_RESOURCE_BY_OBJ(__ptr, __type, __obj, __name, __check) \ { \ MYSQLI_RESOURCE *my_res; \ if (!(my_res = (MYSQLI_RESOURCE *)(__obj->ptr))) {\ zend_throw_error(NULL, "%s object is already closed", ZSTR_VAL(intern->zo.ce->name));\ return;\ }\ __ptr = (__type)my_res->ptr; \ if (my_res->status < __check) { \ zend_throw_error(NULL, "%s object is not fully initialized", ZSTR_VAL(intern->zo.ce->name)); \ return;\ }\ } #define MYSQLI_FETCH_RESOURCE_CONN(__ptr, __id, __check) \ { \ MYSQLI_FETCH_RESOURCE((__ptr), MY_MYSQL *, (__id), "mysqli_link", (__check)); \ if (!(__ptr)->mysql) { \ zend_throw_error(NULL, "%s object is not fully initialized", ZSTR_VAL(Z_OBJCE_P(__id)->name)); \ RETURN_THROWS(); \ } \ } #define MYSQLI_FETCH_RESOURCE_STMT(__ptr, __id, __check) \ { \ MYSQLI_FETCH_RESOURCE((__ptr), MY_STMT *, (__id), "mysqli_stmt", (__check)); \ ZEND_ASSERT((__ptr)->stmt && "Missing statement?"); \ } #define MYSQLI_SET_STATUS(__id, __value) \ { \ mysqli_object *intern = Z_MYSQLI_P(__id); \ ((MYSQLI_RESOURCE *)intern->ptr)->status = __value; \ } \ #define MYSQLI_CLEAR_RESOURCE(__id) \ { \ mysqli_object *intern = Z_MYSQLI_P(__id); \ efree(intern->ptr); \ intern->ptr = NULL; \ } ZEND_BEGIN_MODULE_GLOBALS(mysqli) zend_long num_links; zend_long max_links; zend_long num_active_persistent; zend_long num_inactive_persistent; zend_long max_persistent; bool allow_persistent; zend_ulong default_port; char *default_host; char *default_user; char *default_pw; char *default_socket; bool allow_local_infile; char *local_infile_directory; zend_long error_no; char *error_msg; zend_long report_mode; bool rollback_on_cached_plink; ZEND_END_MODULE_GLOBALS(mysqli) #define MyG(v) ZEND_MODULE_GLOBALS_ACCESSOR(mysqli, v) #if defined(ZTS) && defined(COMPILE_DL_MYSQLI) ZEND_TSRMLS_CACHE_EXTERN() #endif ZEND_EXTERN_MODULE_GLOBALS(mysqli) #endif /* PHP_MYSQLI_STRUCTS.H */
7,672
27.737828
108
h
php-src
php-src-master/ext/mysqlnd/config-win.h
/* Copyright Abandoned 1996 TCX DataKonsult AB & Monty Program KB & Detron HB This file is public domain and comes with NO WARRANTY of any kind */ /* Defines for Win32 to make it compatible for MySQL */ #ifndef _MYSQLND_CONFIG_WIN_H #define _MYSQLND_CONFIG_WIN_H #include <sys/locking.h> #include <windows.h> #include <math.h> /* Because of rint() */ #include <fcntl.h> #include <io.h> #include <malloc.h> #include <stdint.h> #ifndef _WIN64 #ifndef _WIN32 #define _WIN32 /* Compatible with old source */ #endif #ifndef __WIN32__ #define __WIN32__ #endif #endif /* _WIN64 */ #ifndef __WIN__ #define __WIN__ /* To make it easier in VC++ */ #endif /* Type information */ #define SIZEOF_LONG 4 #define SIZEOF_LONG_LONG 8 #ifndef _WIN64 /* Optimized store functions for Intel x86 */ #define sint2korr(A) (*((int16_t *) (A))) #define sint3korr(A) ((int32_t) ((((zend_uchar) (A)[2]) & 128) ? \ (((uint32_t) 255L << 24) | \ (((uint32_t) (zend_uchar) (A)[2]) << 16) |\ (((uint32_t) (zend_uchar) (A)[1]) << 8) | \ ((uint32_t) (zend_uchar) (A)[0])) : \ (((uint32_t) (zend_uchar) (A)[2]) << 16) |\ (((uint32_t) (zend_uchar) (A)[1]) << 8) | \ ((uint32_t) (zend_uchar) (A)[0]))) #define sint4korr(A) (*((int32_t *) (A))) #define uint2korr(A) (*((uint16_t *) (A))) #define uint3korr(A) (int32_t) (*((uint32_t *) (A)) & 0xFFFFFF) #define uint4korr(A) (*((uint32_t *) (A))) #define uint5korr(A) ((uint64_t)(((uint32_t) ((zend_uchar) (A)[0])) +\ (((uint32_t) ((zend_uchar) (A)[1])) << 8) +\ (((uint32_t) ((zend_uchar) (A)[2])) << 16) +\ (((uint32_t) ((zend_uchar) (A)[3])) << 24)) +\ (((uint64_t) ((zend_uchar) (A)[4])) << 32)) #define uint8korr(A) (*((uint64_t *) (A))) #define sint8korr(A) (*((int64_t *) (A))) #define int2store(T,A) *((uint16_t*) (T))= (uint16_t) (A) #define int3store(T,A) { *(T)= (zend_uchar) ((A));\ *(T+1)=(zend_uchar) (((uint32_t) (A) >> 8));\ *(T+2)=(zend_uchar) (((A) >> 16)); } #define int4store(T,A) *((int32_t *) (T))= (int32_t) (A) #define int5store(T,A) { *(T)= (zend_uchar)((A));\ *((T)+1)=(zend_uchar) (((A) >> 8));\ *((T)+2)=(zend_uchar) (((A) >> 16));\ *((T)+3)=(zend_uchar) (((A) >> 24)); \ *((T)+4)=(zend_uchar) (((A) >> 32)); } #define int8store(T,A) *((uint64_t *) (T))= (uint64_t) (A) #define float8get(V,M) { *((int32_t *) &V) = *((int32_t*) M); \ *(((int32_t *) &V)+1) = *(((int32_t*) M)+1); } #define float8store(T,V) { *((int32_t *) T) = *((int32_t*) &V); \ *(((int32_t *) T)+1) = *(((int32_t*) &V)+1); } #define float4get(V,M) { *((int32_t *) &(V)) = *((int32_t*) (M)); } #endif /* _WIN64 */ #endif /* _MYSQLND_CONFIG_WIN_H */
2,743
33.3
77
h
php-src
php-src-master/ext/mysqlnd/mysql_float_to_double.h
/* +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Keyur Govande <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef MYSQL_FLOAT_TO_DOUBLE_H #define MYSQL_FLOAT_TO_DOUBLE_H #include "main/php.h" #include <float.h> #include "main/snprintf.h" #define MAX_CHAR_BUF_LEN 255 #ifndef FLT_DIG # define FLT_DIG 6 #endif /* * Convert from a 4-byte float to a 8-byte decimal by first converting * the float to a string (ignoring localization), and then the string to a double. * The decimals argument specifies the precision of the output. If decimals * is less than zero, then a gcvt(3) like logic is used with the significant * digits set to FLT_DIG i.e. 6. */ static inline double mysql_float_to_double(float fp4, int decimals) { char num_buf[MAX_CHAR_BUF_LEN]; /* Over allocated */ if (decimals < 0) { zend_gcvt(fp4, FLT_DIG, '.', 'e', num_buf); } else { snprintf(num_buf, MAX_CHAR_BUF_LEN, "%.*F", decimals, fp4); } return zend_strtod(num_buf, NULL); } #endif /* MYSQL_FLOAT_TO_DOUBLE_H */
1,880
36.62
82
h