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