xref: /PHP-8.0/ext/intl/collator/collator_attr.c (revision 2b5de6f8)
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 "php_intl.h"
21 #include "collator_class.h"
22 #include "collator_convert.h"
23 
24 #include <unicode/ustring.h>
25 
26 /* {{{ Get collation attribute value. */
PHP_FUNCTION(collator_get_attribute)27 PHP_FUNCTION( collator_get_attribute )
28 {
29 	zend_long attribute, value;
30 
31 	COLLATOR_METHOD_INIT_VARS
32 
33 	/* Parse parameters. */
34 	if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Ol",
35 		&object, Collator_ce_ptr, &attribute ) == FAILURE )
36 	{
37 		RETURN_THROWS();
38 	}
39 
40 	/* Fetch the object. */
41 	COLLATOR_METHOD_FETCH_OBJECT;
42 
43 	value = ucol_getAttribute( co->ucoll, attribute, COLLATOR_ERROR_CODE_P( co ) );
44 	COLLATOR_CHECK_STATUS( co, "Error getting attribute value" );
45 
46 	RETURN_LONG( value );
47 }
48 /* }}} */
49 
50 /* {{{ Set collation attribute. */
PHP_FUNCTION(collator_set_attribute)51 PHP_FUNCTION( collator_set_attribute )
52 {
53 	zend_long attribute, value;
54 	COLLATOR_METHOD_INIT_VARS
55 
56 
57 	/* Parse parameters. */
58 	if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Oll",
59 		&object, Collator_ce_ptr, &attribute, &value ) == FAILURE)
60 	{
61 		RETURN_THROWS();
62 	}
63 
64 	/* Fetch the object. */
65 	COLLATOR_METHOD_FETCH_OBJECT;
66 
67 	/* Set new value for the given attribute. */
68 	ucol_setAttribute( co->ucoll, attribute, value, COLLATOR_ERROR_CODE_P( co ) );
69 	COLLATOR_CHECK_STATUS( co, "Error setting attribute value" );
70 
71 	RETURN_TRUE;
72 }
73 /* }}} */
74 
75 /* {{{ Returns the current collation strength. */
PHP_FUNCTION(collator_get_strength)76 PHP_FUNCTION( collator_get_strength )
77 {
78 	COLLATOR_METHOD_INIT_VARS
79 
80 	/* Parse parameters. */
81 	if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "O",
82 		&object, Collator_ce_ptr ) == FAILURE )
83 	{
84 		RETURN_THROWS();
85 	}
86 
87 	/* Fetch the object. */
88 	COLLATOR_METHOD_FETCH_OBJECT;
89 
90 	/* Get current strength and return it. */
91 	RETURN_LONG( ucol_getStrength( co->ucoll ) );
92 }
93 /* }}} */
94 
95 /* {{{ Set the collation strength. */
PHP_FUNCTION(collator_set_strength)96 PHP_FUNCTION( collator_set_strength )
97 {
98 	zend_long strength;
99 
100 	COLLATOR_METHOD_INIT_VARS
101 
102 	/* Parse parameters. */
103 	if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Ol",
104 		&object, Collator_ce_ptr, &strength ) == FAILURE )
105 	{
106 		RETURN_THROWS();
107 	}
108 
109 	/* Fetch the object. */
110 	COLLATOR_METHOD_FETCH_OBJECT;
111 
112 	/* Set given strength. */
113 	ucol_setStrength( co->ucoll, strength );
114 
115 	RETURN_TRUE;
116 }
117 /* }}} */
118