xref: /PHP-8.0/ext/intl/collator/collator.c (revision 5d6e923d)
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    | http://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 #ifdef HAVE_CONFIG_H
17 #include "config.h"
18 #endif
19 
20 #include "collator_class.h"
21 #include "collator.h"
22 
23 #include <unicode/utypes.h>
24 #include <unicode/ucol.h>
25 #include <unicode/ustring.h>
26 
27 /* {{{ collator_register_constants
28  * Register constants common for the both (OO and procedural)
29  * APIs.
30  */
collator_register_constants(INIT_FUNC_ARGS)31 void collator_register_constants( INIT_FUNC_ARGS )
32 {
33 	if( !Collator_ce_ptr )
34 	{
35 		zend_error( E_ERROR, "Collator class not defined" );
36 		return;
37 	}
38 
39 	#define COLLATOR_EXPOSE_CONST(x) REGISTER_LONG_CONSTANT(#x, x, CONST_PERSISTENT | CONST_CS)
40 	#define COLLATOR_EXPOSE_CLASS_CONST(x) zend_declare_class_constant_long( Collator_ce_ptr, ZEND_STRS( #x ) - 1, UCOL_##x );
41 	#define COLLATOR_EXPOSE_CUSTOM_CLASS_CONST(name, value) zend_declare_class_constant_long( Collator_ce_ptr, ZEND_STRS( name ) - 1, value );
42 
43 	/* UColAttributeValue constants */
44 	COLLATOR_EXPOSE_CUSTOM_CLASS_CONST( "DEFAULT_VALUE", UCOL_DEFAULT );
45 
46 	COLLATOR_EXPOSE_CLASS_CONST( PRIMARY );
47 	COLLATOR_EXPOSE_CLASS_CONST( SECONDARY );
48 	COLLATOR_EXPOSE_CLASS_CONST( TERTIARY );
49 	COLLATOR_EXPOSE_CLASS_CONST( DEFAULT_STRENGTH );
50 	COLLATOR_EXPOSE_CLASS_CONST( QUATERNARY );
51 	COLLATOR_EXPOSE_CLASS_CONST( IDENTICAL );
52 
53 	COLLATOR_EXPOSE_CLASS_CONST( OFF );
54 	COLLATOR_EXPOSE_CLASS_CONST( ON );
55 
56 	COLLATOR_EXPOSE_CLASS_CONST( SHIFTED );
57 	COLLATOR_EXPOSE_CLASS_CONST( NON_IGNORABLE );
58 
59 	COLLATOR_EXPOSE_CLASS_CONST( LOWER_FIRST );
60 	COLLATOR_EXPOSE_CLASS_CONST( UPPER_FIRST );
61 
62 	/* UColAttribute constants */
63 	COLLATOR_EXPOSE_CLASS_CONST( FRENCH_COLLATION );
64 	COLLATOR_EXPOSE_CLASS_CONST( ALTERNATE_HANDLING );
65 	COLLATOR_EXPOSE_CLASS_CONST( CASE_FIRST );
66 	COLLATOR_EXPOSE_CLASS_CONST( CASE_LEVEL );
67 	COLLATOR_EXPOSE_CLASS_CONST( NORMALIZATION_MODE );
68 	COLLATOR_EXPOSE_CLASS_CONST( STRENGTH );
69 	COLLATOR_EXPOSE_CLASS_CONST( HIRAGANA_QUATERNARY_MODE );
70 	COLLATOR_EXPOSE_CLASS_CONST( NUMERIC_COLLATION );
71 
72 	/* ULocDataLocaleType constants */
73 	COLLATOR_EXPOSE_CONST( ULOC_ACTUAL_LOCALE );
74 	COLLATOR_EXPOSE_CONST( ULOC_VALID_LOCALE );
75 
76 	/* sort flags */
77 	COLLATOR_EXPOSE_CUSTOM_CLASS_CONST( "SORT_REGULAR", COLLATOR_SORT_REGULAR );
78 	COLLATOR_EXPOSE_CUSTOM_CLASS_CONST( "SORT_STRING",  COLLATOR_SORT_STRING  );
79 	COLLATOR_EXPOSE_CUSTOM_CLASS_CONST( "SORT_NUMERIC", COLLATOR_SORT_NUMERIC );
80 
81 	#undef COLLATOR_EXPOSE_CUSTOM_CLASS_CONST
82 	#undef COLLATOR_EXPOSE_CLASS_CONST
83 	#undef COLLATOR_EXPOSE_CONST
84 }
85 /* }}} */
86