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@php.net>                          |
14    +----------------------------------------------------------------------+
15  */
16 
17 #ifndef BREAKITERATOR_CLASS_H
18 #define BREAKITERATOR_CLASS_H
19 
20 //redefinition of inline in PHP headers causes problems, so include this before
21 #include <math.h>
22 
23 #include <php.h>
24 #include "../intl_error.h"
25 #include "../intl_data.h"
26 
27 #ifndef USE_BREAKITERATOR_POINTER
28 typedef void BreakIterator;
29 #else
30 using icu::BreakIterator;
31 #endif
32 
33 typedef struct {
34 	// 	error handling
35 	intl_error  err;
36 
37 	// ICU break iterator
38 	BreakIterator*	biter;
39 
40 	// current text
41 	zval text;
42 
43 	zend_object	zo;
44 } BreakIterator_object;
45 
php_intl_breakiterator_fetch_object(zend_object * obj)46 static inline BreakIterator_object *php_intl_breakiterator_fetch_object(zend_object *obj) {
47 	return (BreakIterator_object *)((char*)(obj) - XtOffsetOf(BreakIterator_object, zo));
48 }
49 #define Z_INTL_BREAKITERATOR_P(zv) php_intl_breakiterator_fetch_object(Z_OBJ_P(zv))
50 
51 #define BREAKITER_ERROR(bio)		(bio)->err
52 #define BREAKITER_ERROR_P(bio)		&(BREAKITER_ERROR(bio))
53 
54 #define BREAKITER_ERROR_CODE(bio)	INTL_ERROR_CODE(BREAKITER_ERROR(bio))
55 #define BREAKITER_ERROR_CODE_P(bio)	&(INTL_ERROR_CODE(BREAKITER_ERROR(bio)))
56 
57 #define BREAKITER_METHOD_INIT_VARS		        INTL_METHOD_INIT_VARS(BreakIterator, bio)
58 #define BREAKITER_METHOD_FETCH_OBJECT_NO_CHECK	INTL_METHOD_FETCH_OBJECT(INTL_BREAKITERATOR, bio)
59 #define BREAKITER_METHOD_FETCH_OBJECT \
60 	BREAKITER_METHOD_FETCH_OBJECT_NO_CHECK; \
61 	if (bio->biter == NULL) \
62 	{ \
63 		intl_errors_set(&bio->err, U_ILLEGAL_ARGUMENT_ERROR, "Found unconstructed BreakIterator", 0); \
64 		RETURN_FALSE; \
65 	}
66 
67 void breakiterator_object_create(zval *object, BreakIterator *break_iter, int brand_new);
68 
69 void breakiterator_object_construct(zval *object, BreakIterator *break_iter);
70 
71 void breakiterator_register_BreakIterator_class(void);
72 
73 extern zend_class_entry *BreakIterator_ce_ptr,
74 						*RuleBasedBreakIterator_ce_ptr;
75 
76 extern zend_object_handlers BreakIterator_handlers;
77 
78 #endif /* #ifndef BREAKITERATOR_CLASS_H */
79