xref: /php-src/ext/intl/collator/collator_class.h (revision 150456ea)
1 /*
2    +----------------------------------------------------------------------+
3    | This source file is subject to version 3.01 of the PHP license,      |
4    | that is bundled with this package in the file LICENSE, and is        |
5    | available through the world-wide-web at the following url:           |
6    | https://www.php.net/license/3_01.txt                                 |
7    | If you did not receive a copy of the PHP license and are unable to   |
8    | obtain it through the world-wide-web, please send a note to          |
9    | license@php.net so we can mail you a copy immediately.               |
10    +----------------------------------------------------------------------+
11    | Authors: Vadim Savchuk <vsavchuk@productengine.com>                  |
12    |          Dmitry Lakhtyuk <dlakhtyuk@productengine.com>               |
13    +----------------------------------------------------------------------+
14  */
15 
16 #ifndef COLLATOR_CLASS_H
17 #define COLLATOR_CLASS_H
18 
19 #include <php.h>
20 
21 #include "../intl_common.h"
22 #include "../intl_error.h"
23 #include "../intl_data.h"
24 
25 #include <unicode/ucol.h>
26 
27 typedef struct {
28 	// error handling
29 	intl_error  err;
30 
31 	// ICU collator
32 	UCollator*      ucoll;
33 
34 	zend_object     zo;
35 
36 } Collator_object;
37 
38 #define COLLATOR_ERROR(co) (co)->err
39 #define COLLATOR_ERROR_P(co) &(COLLATOR_ERROR(co))
40 
41 #define COLLATOR_ERROR_CODE(co)   INTL_ERROR_CODE(COLLATOR_ERROR(co))
42 #define COLLATOR_ERROR_CODE_P(co) &(INTL_ERROR_CODE(COLLATOR_ERROR(co)))
43 
php_intl_collator_fetch_object(zend_object * obj)44 static inline Collator_object *php_intl_collator_fetch_object(zend_object *obj) {
45 	return (Collator_object *)((char*)(obj) - XtOffsetOf(Collator_object, zo));
46 }
47 #define Z_INTL_COLLATOR_P(zv) php_intl_collator_fetch_object(Z_OBJ_P(zv))
48 
49 void collator_register_Collator_symbols(int module_number);
50 void collator_object_init( Collator_object* co );
51 void collator_object_destroy( Collator_object* co );
52 
53 extern zend_class_entry *Collator_ce_ptr;
54 
55 /* Auxiliary macros */
56 
57 #define COLLATOR_METHOD_INIT_VARS       \
58     zval*             object  = NULL;   \
59     Collator_object*  co      = NULL;   \
60     intl_error_reset( NULL ); \
61 
62 #define COLLATOR_METHOD_FETCH_OBJECT	INTL_METHOD_FETCH_OBJECT(INTL_COLLATOR, co)
63 
64 // Macro to check return value of a ucol_* function call.
65 #define COLLATOR_CHECK_STATUS( co, msg )                                        \
66     intl_error_set_code( NULL, COLLATOR_ERROR_CODE( co ) );           \
67     if( U_FAILURE( COLLATOR_ERROR_CODE( co ) ) )                                \
68     {                                                                           \
69         intl_errors_set_custom_msg( COLLATOR_ERROR_P( co ), msg, 0 ); \
70         RETURN_FALSE;                                                           \
71     }                                                                           \
72 
73 #endif // #ifndef COLLATOR_CLASS_H
74