- Notifications
You must be signed in to change notification settings - Fork 7.8k
/
Copy pathintl_data.h
134 lines (115 loc) · 5.33 KB
/
intl_data.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
+----------------------------------------------------------------------+
| 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 |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Vadim Savchuk <vsavchuk@productengine.com> |
| Dmitry Lakhtyuk <dlakhtyuk@productengine.com> |
| Stanislav Malyshev <stas@zend.com> |
+----------------------------------------------------------------------+
*/
#ifndefINTL_DATA_H
#defineINTL_DATA_H
#include<unicode/utypes.h>
#include"intl_error.h"
/* Mock object to generalize error handling in sub-modules.
Sub-module data structures should always have error as first element
for this to work!
*/
typedefstruct_intl_data {
intl_errorerror;
zend_objectzo;
} intl_object;
#defineINTL_METHOD_INIT_VARS(oclass, obj) \
zval* object = NULL; \
oclass##_object* obj = NULL; \
intl_error_reset( NULL );
#defineINTL_DATA_ERROR(obj) (((intl_object *)(obj))->error)
#defineINTL_DATA_ERROR_P(obj) (&(INTL_DATA_ERROR((obj))))
#defineINTL_DATA_ERROR_CODE(obj) INTL_ERROR_CODE(INTL_DATA_ERROR((obj)))
#defineINTL_METHOD_FETCH_OBJECT(oclass, obj) \
obj = Z_##oclass##_P( object ); \
intl_error_reset( INTL_DATA_ERROR_P(obj) ); \
/* Check status by error code, if error return false */
#defineINTL_CHECK_STATUS(err, msg) \
intl_error_set_code( NULL, (err) ); \
if( U_FAILURE((err)) ) \
{ \
intl_error_set_custom_msg( NULL, msg, 0 ); \
RETURN_FALSE; \
}
/* Check status by error code, if error return null */
#defineINTL_CHECK_STATUS_OR_NULL(err, msg) \
intl_error_set_code( NULL, (err) ); \
if( U_FAILURE((err)) ) \
{ \
intl_error_set_custom_msg( NULL, msg, 0 ); \
RETURN_NULL(); \
}
/* Check status in object, if error return false */
#defineINTL_METHOD_CHECK_STATUS(obj, msg) \
intl_error_set_code( NULL, INTL_DATA_ERROR_CODE((obj)) ); \
if( U_FAILURE( INTL_DATA_ERROR_CODE((obj)) ) ) \
{ \
intl_errors_set_custom_msg( INTL_DATA_ERROR_P((obj)), msg, 0 ); \
RETURN_FALSE; \
}
/* Check status in object, if error goto a label */
#defineINTL_METHOD_CHECK_STATUS_OR_GOTO(obj, msg, label) \
intl_error_set_code( NULL, INTL_DATA_ERROR_CODE((obj)) ); \
if( U_FAILURE( INTL_DATA_ERROR_CODE((obj)) ) ) \
{ \
intl_errors_set_custom_msg( INTL_DATA_ERROR_P((obj)), msg, 0 ); \
RETVAL_FALSE; \
goto label; \
}
/* Check status in object, if error return null */
#defineINTL_METHOD_CHECK_STATUS_OR_NULL(obj, msg) \
intl_error_set_code( NULL, INTL_DATA_ERROR_CODE((obj)) ); \
if( U_FAILURE( INTL_DATA_ERROR_CODE((obj)) ) ) \
{ \
intl_errors_set_custom_msg( INTL_DATA_ERROR_P((obj)), msg, 0 ); \
zval_ptr_dtor(return_value); \
RETURN_NULL(); \
}
/* Check status in object, if error return FAILURE */
#defineINTL_CTOR_CHECK_STATUS(obj, msg) \
intl_error_set_code( NULL, INTL_DATA_ERROR_CODE((obj)) ); \
if( U_FAILURE( INTL_DATA_ERROR_CODE((obj)) ) ) \
{ \
intl_errors_set_custom_msg( INTL_DATA_ERROR_P((obj)), msg, 0 ); \
return FAILURE; \
}
#defineINTL_METHOD_RETVAL_UTF8(obj, ustring, ulen, free_it) \
{ \
zend_string *u8str; \
u8str = intl_convert_utf16_to_utf8(ustring, ulen, &INTL_DATA_ERROR_CODE((obj))); \
if((free_it)) { \
efree(ustring); \
} \
INTL_METHOD_CHECK_STATUS((obj), "Error converting value to UTF-8"); \
RETVAL_NEW_STR(u8str); \
}
#defineINTL_MAX_LOCALE_LEN (ULOC_FULLNAME_CAPACITY-1)
#defineINTL_CHECK_LOCALE_LEN(locale_len) \
if((locale_len) > INTL_MAX_LOCALE_LEN) { \
char *_msg; \
spprintf(&_msg, 0, "Locale string too long, should be no longer than %d characters", INTL_MAX_LOCALE_LEN); \
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, _msg, 1); \
efree(_msg); \
RETURN_NULL(); \
}
#defineINTL_CHECK_LOCALE_LEN_OR_FAILURE(locale_len) \
if((locale_len) > INTL_MAX_LOCALE_LEN) { \
char *_msg; \
spprintf(&_msg, 0, "Locale string too long, should be no longer than %d characters", INTL_MAX_LOCALE_LEN); \
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, _msg, 1); \
efree(_msg); \
return FAILURE; \
}
#endif// INTL_DATA_H