Back to index

php5  5.3.10
intl_data.h
Go to the documentation of this file.
00001 /*
00002    +----------------------------------------------------------------------+
00003    | PHP Version 5                                                        |
00004    +----------------------------------------------------------------------+
00005    | This source file is subject to version 3.01 of the PHP license,      |
00006    | that is bundled with this package in the file LICENSE, and is        |
00007    | available through the world-wide-web at the following url:           |
00008    | http://www.php.net/license/3_01.txt                                  |
00009    | If you did not receive a copy of the PHP license and are unable to   |
00010    | obtain it through the world-wide-web, please send a note to          |
00011    | license@php.net so we can mail you a copy immediately.               |
00012    +----------------------------------------------------------------------+
00013    | Authors: Vadim Savchuk <vsavchuk@productengine.com>                  |
00014    |          Dmitry Lakhtyuk <dlakhtyuk@productengine.com>               |
00015    |          Stanislav Malyshev <stas@zend.com>                          |
00016    +----------------------------------------------------------------------+
00017  */
00018 
00019 #ifndef INTL_DATA_H
00020 #define INTL_DATA_H
00021 
00022 #include <unicode/utypes.h>
00023 
00024 #include "intl_error.h"
00025 
00026 /* Mock object to generalize error handling in sub-modules.
00027    Sub-module data structures should always have error as first element 
00028    for this to work! 
00029 */
00030 typedef struct _intl_data {
00031        zend_object          zo;
00032        intl_error           error;
00033 } intl_object;
00034 
00035 #define INTL_METHOD_INIT_VARS(oclass, obj)              \
00036        zval*             object  = NULL;                \
00037        oclass##_object*  obj     = NULL;                \
00038        intl_error_reset( NULL TSRMLS_CC );                     
00039 
00040 #define INTL_DATA_ERROR(obj)                            (((intl_object *)(obj))->error)
00041 #define INTL_DATA_ERROR_P(obj)                          (&(INTL_DATA_ERROR((obj))))
00042 #define INTL_DATA_ERROR_CODE(obj)                INTL_ERROR_CODE(INTL_DATA_ERROR((obj)))
00043 
00044 #define INTL_METHOD_FETCH_OBJECT(oclass, obj)                                                            \
00045        obj = (oclass##_object *) zend_object_store_get_object( object TSRMLS_CC );  \
00046     intl_error_reset( INTL_DATA_ERROR_P(obj) TSRMLS_CC );                                         \
00047 
00048 /* Check status by error code, if error - exit */
00049 #define INTL_CHECK_STATUS(err, msg)                                                                             \
00050     intl_error_set_code( NULL, (err) TSRMLS_CC );                                                 \
00051     if( U_FAILURE((err)) )                                                                                      \
00052     {                                                                                                                         \
00053         intl_error_set_custom_msg( NULL, msg, 0 TSRMLS_CC );                        \
00054         RETURN_FALSE;                                                                                                  \
00055     }
00056 
00057 /* Check status in object, if error - exit */
00058 #define INTL_METHOD_CHECK_STATUS(obj, msg)                                                                             \
00059     intl_error_set_code( NULL, INTL_DATA_ERROR_CODE((obj)) TSRMLS_CC );                           \
00060     if( U_FAILURE( INTL_DATA_ERROR_CODE((obj)) ) )                                                              \
00061     {                                                                                                                                       \
00062         intl_errors_set_custom_msg( INTL_DATA_ERROR_P((obj)), msg, 0 TSRMLS_CC );   \
00063         RETURN_FALSE;                                                                      \
00064     }
00065 
00066 /* Check status, if error - destroy value and exit */
00067 #define INTL_CTOR_CHECK_STATUS(obj, msg)                                                                        \
00068     intl_error_set_code( NULL, INTL_DATA_ERROR_CODE((obj)) TSRMLS_CC );                           \
00069     if( U_FAILURE( INTL_DATA_ERROR_CODE((obj)) ) )                                                              \
00070     {                                                                                                                                       \
00071         intl_errors_set_custom_msg( INTL_DATA_ERROR_P((obj)), msg, 0 TSRMLS_CC );   \
00072               zval_dtor(return_value);                                                                                        \
00073         RETURN_NULL();                                                                                                               \
00074     }
00075 
00076 #define INTL_METHOD_RETVAL_UTF8(obj, ustring, ulen, free_it)                                                           \
00077 {                                                                                                                                                                       \
00078        char *u8value;                                                                                                                                            \
00079        int u8len;                                                                                                                                                \
00080        intl_convert_utf16_to_utf8(&u8value, &u8len, ustring, ulen, &INTL_DATA_ERROR_CODE((obj))); \
00081        if((free_it)) {                                                                                                                                           \
00082               efree(ustring);                                                                                                                                    \
00083        }                                                                                                                                                                \
00084        INTL_METHOD_CHECK_STATUS((obj), "Error converting value to UTF-8");                                             \
00085        RETVAL_STRINGL(u8value, u8len, 0);                                                                                                   \
00086 }
00087 
00088 #define INTL_MAX_LOCALE_LEN 80
00089 
00090 #define INTL_CHECK_LOCALE_LEN(locale_len)                                                                              \
00091        if((locale_len) > INTL_MAX_LOCALE_LEN) {                                                                        \
00092               intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,                                                          \
00093        "Locale string too long, should be no longer than 80 characters", 0 TSRMLS_CC );    \
00094               RETURN_NULL();                                                                                                                       \
00095        }
00096 
00097 #define INTL_CHECK_LOCALE_LEN_OBJ(locale_len, object)                                                           \
00098        if((locale_len) > INTL_MAX_LOCALE_LEN) {                                                                        \
00099               intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,                                                          \
00100        "Locale string too long, should be no longer than 80 characters", 0 TSRMLS_CC );    \
00101               zval_dtor(object);                                                                                                            \
00102               ZVAL_NULL(object);                                                                                                            \
00103               RETURN_NULL();                                                                                                                       \
00104        }
00105 
00106 
00107 #endif // INTL_DATA_H