Annotation of embedaddon/php/ext/intl/intl_data.h, revision 1.1
1.1 ! misho 1: /*
! 2: +----------------------------------------------------------------------+
! 3: | PHP Version 5 |
! 4: +----------------------------------------------------------------------+
! 5: | This source file is subject to version 3.01 of the PHP license, |
! 6: | that is bundled with this package in the file LICENSE, and is |
! 7: | available through the world-wide-web at the following url: |
! 8: | http://www.php.net/license/3_01.txt |
! 9: | If you did not receive a copy of the PHP license and are unable to |
! 10: | obtain it through the world-wide-web, please send a note to |
! 11: | license@php.net so we can mail you a copy immediately. |
! 12: +----------------------------------------------------------------------+
! 13: | Authors: Vadim Savchuk <vsavchuk@productengine.com> |
! 14: | Dmitry Lakhtyuk <dlakhtyuk@productengine.com> |
! 15: | Stanislav Malyshev <stas@zend.com> |
! 16: +----------------------------------------------------------------------+
! 17: */
! 18:
! 19: #ifndef INTL_DATA_H
! 20: #define INTL_DATA_H
! 21:
! 22: #include <unicode/utypes.h>
! 23:
! 24: #include "intl_error.h"
! 25:
! 26: /* Mock object to generalize error handling in sub-modules.
! 27: Sub-module data structures should always have error as first element
! 28: for this to work!
! 29: */
! 30: typedef struct _intl_data {
! 31: zend_object zo;
! 32: intl_error error;
! 33: } intl_object;
! 34:
! 35: #define INTL_METHOD_INIT_VARS(oclass, obj) \
! 36: zval* object = NULL; \
! 37: oclass##_object* obj = NULL; \
! 38: intl_error_reset( NULL TSRMLS_CC );
! 39:
! 40: #define INTL_DATA_ERROR(obj) (((intl_object *)(obj))->error)
! 41: #define INTL_DATA_ERROR_P(obj) (&(INTL_DATA_ERROR((obj))))
! 42: #define INTL_DATA_ERROR_CODE(obj) INTL_ERROR_CODE(INTL_DATA_ERROR((obj)))
! 43:
! 44: #define INTL_METHOD_FETCH_OBJECT(oclass, obj) \
! 45: obj = (oclass##_object *) zend_object_store_get_object( object TSRMLS_CC ); \
! 46: intl_error_reset( INTL_DATA_ERROR_P(obj) TSRMLS_CC ); \
! 47:
! 48: /* Check status by error code, if error - exit */
! 49: #define INTL_CHECK_STATUS(err, msg) \
! 50: intl_error_set_code( NULL, (err) TSRMLS_CC ); \
! 51: if( U_FAILURE((err)) ) \
! 52: { \
! 53: intl_error_set_custom_msg( NULL, msg, 0 TSRMLS_CC ); \
! 54: RETURN_FALSE; \
! 55: }
! 56:
! 57: /* Check status in object, if error - exit */
! 58: #define INTL_METHOD_CHECK_STATUS(obj, msg) \
! 59: intl_error_set_code( NULL, INTL_DATA_ERROR_CODE((obj)) TSRMLS_CC ); \
! 60: if( U_FAILURE( INTL_DATA_ERROR_CODE((obj)) ) ) \
! 61: { \
! 62: intl_errors_set_custom_msg( INTL_DATA_ERROR_P((obj)), msg, 0 TSRMLS_CC ); \
! 63: RETURN_FALSE; \
! 64: }
! 65:
! 66: /* Check status, if error - destroy value and exit */
! 67: #define INTL_CTOR_CHECK_STATUS(obj, msg) \
! 68: intl_error_set_code( NULL, INTL_DATA_ERROR_CODE((obj)) TSRMLS_CC ); \
! 69: if( U_FAILURE( INTL_DATA_ERROR_CODE((obj)) ) ) \
! 70: { \
! 71: intl_errors_set_custom_msg( INTL_DATA_ERROR_P((obj)), msg, 0 TSRMLS_CC ); \
! 72: zval_dtor(return_value); \
! 73: RETURN_NULL(); \
! 74: }
! 75:
! 76: #define INTL_METHOD_RETVAL_UTF8(obj, ustring, ulen, free_it) \
! 77: { \
! 78: char *u8value; \
! 79: int u8len; \
! 80: intl_convert_utf16_to_utf8(&u8value, &u8len, ustring, ulen, &INTL_DATA_ERROR_CODE((obj))); \
! 81: if((free_it)) { \
! 82: efree(ustring); \
! 83: } \
! 84: INTL_METHOD_CHECK_STATUS((obj), "Error converting value to UTF-8"); \
! 85: RETVAL_STRINGL(u8value, u8len, 0); \
! 86: }
! 87:
! 88: #define INTL_MAX_LOCALE_LEN 80
! 89:
! 90: #define INTL_CHECK_LOCALE_LEN(locale_len) \
! 91: if((locale_len) > INTL_MAX_LOCALE_LEN) { \
! 92: intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, \
! 93: "Locale string too long, should be no longer than 80 characters", 0 TSRMLS_CC ); \
! 94: RETURN_NULL(); \
! 95: }
! 96:
! 97: #define INTL_CHECK_LOCALE_LEN_OBJ(locale_len, object) \
! 98: if((locale_len) > INTL_MAX_LOCALE_LEN) { \
! 99: intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, \
! 100: "Locale string too long, should be no longer than 80 characters", 0 TSRMLS_CC ); \
! 101: zval_dtor(object); \
! 102: ZVAL_NULL(object); \
! 103: RETURN_NULL(); \
! 104: }
! 105:
! 106:
! 107: #endif // INTL_DATA_H
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>