xref: /PHP-7.3/ext/intl/collator/collator_class.h (revision bdeb220f)
1 /*
2    +----------------------------------------------------------------------+
3    | PHP Version 7                                                        |
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    +----------------------------------------------------------------------+
16  */
17 
18 #ifndef COLLATOR_CLASS_H
19 #define COLLATOR_CLASS_H
20 
21 #include <php.h>
22 
23 #include "../intl_common.h"
24 #include "../intl_error.h"
25 #include "../intl_data.h"
26 
27 #include <unicode/ucol.h>
28 
29 typedef struct {
30 	// error handling
31 	intl_error  err;
32 
33 	// ICU collator
34 	UCollator*      ucoll;
35 
36 	zend_object     zo;
37 
38 } Collator_object;
39 
40 #define COLLATOR_ERROR(co) (co)->err
41 #define COLLATOR_ERROR_P(co) &(COLLATOR_ERROR(co))
42 
43 #define COLLATOR_ERROR_CODE(co)   INTL_ERROR_CODE(COLLATOR_ERROR(co))
44 #define COLLATOR_ERROR_CODE_P(co) &(INTL_ERROR_CODE(COLLATOR_ERROR(co)))
45 
php_intl_collator_fetch_object(zend_object * obj)46 static inline Collator_object *php_intl_collator_fetch_object(zend_object *obj) {
47 	return (Collator_object *)((char*)(obj) - XtOffsetOf(Collator_object, zo));
48 }
49 #define Z_INTL_COLLATOR_P(zv) php_intl_collator_fetch_object(Z_OBJ_P(zv))
50 
51 void collator_register_Collator_class( void );
52 void collator_object_init( Collator_object* co );
53 void collator_object_destroy( Collator_object* co );
54 
55 extern zend_class_entry *Collator_ce_ptr;
56 
57 /* Auxiliary macros */
58 
59 #define COLLATOR_METHOD_INIT_VARS       \
60     zval*             object  = NULL;   \
61     Collator_object*  co      = NULL;   \
62     intl_error_reset( NULL ); \
63 
64 #define COLLATOR_METHOD_FETCH_OBJECT	INTL_METHOD_FETCH_OBJECT(INTL_COLLATOR, co)
65 
66 // Macro to check return value of a ucol_* function call.
67 #define COLLATOR_CHECK_STATUS( co, msg )                                        \
68     intl_error_set_code( NULL, COLLATOR_ERROR_CODE( co ) );           \
69     if( U_FAILURE( COLLATOR_ERROR_CODE( co ) ) )                                \
70     {                                                                           \
71         intl_errors_set_custom_msg( COLLATOR_ERROR_P( co ), msg, 0 ); \
72         RETURN_FALSE;                                                           \
73     }                                                                           \
74 
75 #endif // #ifndef COLLATOR_CLASS_H
76