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: Gustavo Lopes <cataphract@netcabo.pt>                       |
12    +----------------------------------------------------------------------+
13  */
14 
15 #ifndef TRANSLITERATOR_CLASS_H
16 #define TRANSLITERATOR_CLASS_H
17 
18 #include <php.h>
19 
20 #include "intl_common.h"
21 #include "intl_error.h"
22 
23 #include <unicode/utrans.h>
24 
25 typedef struct {
26 	// 	error handling
27 	intl_error  err;
28 
29 	// ICU transliterator
30 	UTransliterator* utrans;
31 
32 	zend_object     zo;
33 } Transliterator_object;
34 
php_intl_transliterator_fetch_object(zend_object * obj)35 static inline Transliterator_object *php_intl_transliterator_fetch_object(zend_object *obj) {
36 	return (Transliterator_object *)((char*)(obj) - XtOffsetOf(Transliterator_object, zo));
37 }
38 #define Z_INTL_TRANSLITERATOR_P(zv) php_intl_transliterator_fetch_object(Z_OBJ_P(zv))
39 
40 #define TRANSLITERATOR_FORWARD UTRANS_FORWARD
41 #define TRANSLITERATOR_REVERSE UTRANS_REVERSE
42 
43 #define TRANSLITERATOR_ERROR( co ) (co)->err
44 #define TRANSLITERATOR_ERROR_P( co ) &(TRANSLITERATOR_ERROR( co ))
45 
46 #define TRANSLITERATOR_ERROR_CODE( co )   INTL_ERROR_CODE(TRANSLITERATOR_ERROR( co ))
47 #define TRANSLITERATOR_ERROR_CODE_P( co ) &(INTL_ERROR_CODE(TRANSLITERATOR_ERROR( co )))
48 
49 #define TRANSLITERATOR_METHOD_INIT_VARS		         INTL_METHOD_INIT_VARS( Transliterator, to )
50 #define TRANSLITERATOR_METHOD_FETCH_OBJECT_NO_CHECK  INTL_METHOD_FETCH_OBJECT( INTL_TRANSLITERATOR, to )
51 #define TRANSLITERATOR_METHOD_FETCH_OBJECT\
52 	TRANSLITERATOR_METHOD_FETCH_OBJECT_NO_CHECK; \
53 	if( to->utrans == NULL ) \
54 	{ \
55 		zend_throw_error(NULL, "Found unconstructed transliterator"); \
56 		RETURN_THROWS(); \
57 	}
58 
59 int transliterator_object_construct( zval *object,
60 									 UTransliterator *utrans,
61 									 UErrorCode *status );
62 
63 void transliterator_register_Transliterator_class( void );
64 
65 extern zend_class_entry *Transliterator_ce_ptr;
66 extern zend_object_handlers Transliterator_handlers;
67 
68 #endif /* #ifndef TRANSLITERATOR_CLASS_H */
69