Skip to content

Commit 0d16b15

Browse files
committed
Merge intl extension into core
1 parent 3bab7c1 commit 0d16b15

File tree

158 files changed

+23151
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

158 files changed

+23151
-0
lines changed

ext/intl/CREDITS

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Internationalization
2+
Ed Batutis, Vladimir Iordanov, Dmitry Lakhtyuk, Stanislav Malyshev, Vadim Savchuk, Kirti Velankar

ext/intl/TODO

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
- Document U_* error constants
2+
- For IntlDateFormatter
3+
-- Accept and produce DateTime objects in 5.3 and 6
4+
-- Create convertor from ICU pattern to PHP pattern
5+

ext/intl/collator/collator.c

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
+----------------------------------------------------------------------+
3+
| PHP Version 5 |
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: Vadim Savchuk <vsavchuk@productengine.com> |
14+
| Dmitry Lakhtyuk <dlakhtyuk@productengine.com> |
15+
+----------------------------------------------------------------------+
16+
*/
17+
18+
#ifdef HAVE_CONFIG_H
19+
#include "config.h"
20+
#endif
21+
22+
#include "collator_class.h"
23+
#include "collator.h"
24+
25+
#include <unicode/utypes.h>
26+
#include <unicode/ucol.h>
27+
#include <unicode/ustring.h>
28+
29+
/* {{{ collator_register_constants
30+
* Register constants common for the both (OO and procedural)
31+
* APIs.
32+
*/
33+
void collator_register_constants( INIT_FUNC_ARGS )
34+
{
35+
if( !Collator_ce_ptr )
36+
{
37+
zend_error( E_ERROR, "Collator class not defined" );
38+
return;
39+
}
40+
41+
#define COLLATOR_EXPOSE_CONST(x) REGISTER_LONG_CONSTANT(#x, x, CONST_CS)
42+
#define COLLATOR_EXPOSE_CLASS_CONST(x) zend_declare_class_constant_long( Collator_ce_ptr, ZEND_STRS( #x ) - 1, UCOL_##x TSRMLS_CC );
43+
#define COLLATOR_EXPOSE_CUSTOM_CLASS_CONST(name, value) zend_declare_class_constant_long( Collator_ce_ptr, ZEND_STRS( name ) - 1, value TSRMLS_CC );
44+
45+
// UColAttributeValue constants
46+
COLLATOR_EXPOSE_CUSTOM_CLASS_CONST( "DEFAULT_VALUE", UCOL_DEFAULT );
47+
48+
COLLATOR_EXPOSE_CLASS_CONST( PRIMARY );
49+
COLLATOR_EXPOSE_CLASS_CONST( SECONDARY );
50+
COLLATOR_EXPOSE_CLASS_CONST( TERTIARY );
51+
COLLATOR_EXPOSE_CLASS_CONST( DEFAULT_STRENGTH );
52+
COLLATOR_EXPOSE_CLASS_CONST( QUATERNARY );
53+
COLLATOR_EXPOSE_CLASS_CONST( IDENTICAL );
54+
55+
COLLATOR_EXPOSE_CLASS_CONST( OFF );
56+
COLLATOR_EXPOSE_CLASS_CONST( ON );
57+
58+
COLLATOR_EXPOSE_CLASS_CONST( SHIFTED );
59+
COLLATOR_EXPOSE_CLASS_CONST( NON_IGNORABLE );
60+
61+
COLLATOR_EXPOSE_CLASS_CONST( LOWER_FIRST );
62+
COLLATOR_EXPOSE_CLASS_CONST( UPPER_FIRST );
63+
64+
// UColAttribute constants
65+
COLLATOR_EXPOSE_CLASS_CONST( FRENCH_COLLATION );
66+
COLLATOR_EXPOSE_CLASS_CONST( ALTERNATE_HANDLING );
67+
COLLATOR_EXPOSE_CLASS_CONST( CASE_FIRST );
68+
COLLATOR_EXPOSE_CLASS_CONST( CASE_LEVEL );
69+
COLLATOR_EXPOSE_CLASS_CONST( NORMALIZATION_MODE );
70+
COLLATOR_EXPOSE_CLASS_CONST( STRENGTH );
71+
COLLATOR_EXPOSE_CLASS_CONST( HIRAGANA_QUATERNARY_MODE );
72+
COLLATOR_EXPOSE_CLASS_CONST( NUMERIC_COLLATION );
73+
74+
// ULocDataLocaleType constants
75+
COLLATOR_EXPOSE_CONST( ULOC_ACTUAL_LOCALE );
76+
COLLATOR_EXPOSE_CONST( ULOC_VALID_LOCALE );
77+
78+
// sort flags
79+
COLLATOR_EXPOSE_CUSTOM_CLASS_CONST( "SORT_REGULAR", COLLATOR_SORT_REGULAR );
80+
COLLATOR_EXPOSE_CUSTOM_CLASS_CONST( "SORT_STRING", COLLATOR_SORT_STRING );
81+
COLLATOR_EXPOSE_CUSTOM_CLASS_CONST( "SORT_NUMERIC", COLLATOR_SORT_NUMERIC );
82+
83+
#undef COLLATOR_EXPOSE_CUSTOM_CLASS_CONST
84+
#undef COLLATOR_EXPOSE_CLASS_CONST
85+
#undef COLLATOR_EXPOSE_CONST
86+
}
87+
/* }}} */
88+
89+
/*
90+
* Local variables:
91+
* tab-width: 4
92+
* c-basic-offset: 4
93+
* End:
94+
* vim600: noet sw=4 ts=4 fdm=marker
95+
* vim<600: noet sw=4 ts=4
96+
*/

ext/intl/collator/collator.h

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
+----------------------------------------------------------------------+
3+
| PHP Version 5 |
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: Vadim Savchuk <vsavchuk@productengine.com> |
14+
| Dmitry Lakhtyuk <dlakhtyuk@productengine.com> |
15+
+----------------------------------------------------------------------+
16+
*/
17+
18+
#ifndef COLLATOR_COLLATOR_H
19+
#define CCOLLATOR_COLLATOR_H
20+
21+
#include <php.h>
22+
23+
#define COLLATOR_SORT_REGULAR 0
24+
#define COLLATOR_SORT_STRING 1
25+
#define COLLATOR_SORT_NUMERIC 2
26+
27+
void collator_register_constants( INIT_FUNC_ARGS );
28+
29+
#endif // COLLATOR_COLLATOR_H

ext/intl/collator/collator_attr.c

+157
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
/*
2+
+----------------------------------------------------------------------+
3+
| PHP Version 5 |
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: Vadim Savchuk <vsavchuk@productengine.com> |
14+
| Dmitry Lakhtyuk <dlakhtyuk@productengine.com> |
15+
+----------------------------------------------------------------------+
16+
*/
17+
18+
#ifdef HAVE_CONFIG_H
19+
#include "config.h"
20+
#endif
21+
22+
#include "php_intl.h"
23+
#include "collator_class.h"
24+
#include "collator_convert.h"
25+
#include "collator_attr.h"
26+
27+
#include <unicode/ustring.h>
28+
29+
/* {{{ proto int Collator::getAttribute( int $attr )
30+
* Get collation attribute value. }}} */
31+
/* {{{ proto int collator_get_attribute( Collator $coll, int $attr )
32+
* Get collation attribute value.
33+
*/
34+
PHP_FUNCTION( collator_get_attribute )
35+
{
36+
long attribute, value;
37+
38+
COLLATOR_METHOD_INIT_VARS
39+
40+
// Parse parameters.
41+
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol",
42+
&object, Collator_ce_ptr, &attribute ) == FAILURE )
43+
{
44+
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
45+
"collator_get_attribute: unable to parse input params", 0 TSRMLS_CC );
46+
47+
RETURN_FALSE;
48+
}
49+
50+
// Fetch the object.
51+
COLLATOR_METHOD_FETCH_OBJECT;
52+
53+
value = ucol_getAttribute( co->ucoll, attribute, COLLATOR_ERROR_CODE_P( co ) );
54+
COLLATOR_CHECK_STATUS( co, "Error getting attribute value" );
55+
56+
RETURN_LONG( value );
57+
}
58+
/* }}} */
59+
60+
/* {{{ proto bool Collator::getAttribute( int $attr )
61+
* Get collation attribute value. }}} */
62+
/* {{{ proto bool collator_set_attribute( Collator $coll, int $attr, int $val )
63+
* Set collation attribute.
64+
*/
65+
PHP_FUNCTION( collator_set_attribute )
66+
{
67+
long attribute, value;
68+
COLLATOR_METHOD_INIT_VARS
69+
70+
71+
// Parse parameters.
72+
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oll",
73+
&object, Collator_ce_ptr, &attribute, &value ) == FAILURE)
74+
{
75+
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
76+
"collator_set_attribute: unable to parse input params", 0 TSRMLS_CC );
77+
78+
RETURN_FALSE;
79+
}
80+
81+
// Fetch the object.
82+
COLLATOR_METHOD_FETCH_OBJECT;
83+
84+
// Set new value for the given attribute.
85+
ucol_setAttribute( co->ucoll, attribute, value, COLLATOR_ERROR_CODE_P( co ) );
86+
COLLATOR_CHECK_STATUS( co, "Error setting attribute value" );
87+
88+
RETURN_TRUE;
89+
}
90+
/* }}} */
91+
92+
/* {{{ proto int Collator::getStrength()
93+
* Returns the current collation strength. }}} */
94+
/* {{{ proto int collator_get_strength(Collator coll)
95+
* Returns the current collation strength.
96+
*/
97+
PHP_FUNCTION( collator_get_strength )
98+
{
99+
COLLATOR_METHOD_INIT_VARS
100+
101+
// Parse parameters.
102+
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
103+
&object, Collator_ce_ptr ) == FAILURE )
104+
{
105+
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
106+
"collator_get_strength: unable to parse input params", 0 TSRMLS_CC );
107+
108+
RETURN_FALSE;
109+
}
110+
111+
// Fetch the object.
112+
COLLATOR_METHOD_FETCH_OBJECT;
113+
114+
// Get current strength and return it.
115+
RETURN_LONG( ucol_getStrength( co->ucoll ) );
116+
}
117+
/* }}} */
118+
119+
/* {{{ proto bool Collator::setStrength(int strength)
120+
* Set the collation strength. }}} */
121+
/* {{{ proto bool collator_set_strength(Collator coll, int strength)
122+
* Set the collation strength.
123+
*/
124+
PHP_FUNCTION( collator_set_strength )
125+
{
126+
long strength;
127+
128+
COLLATOR_METHOD_INIT_VARS
129+
130+
// Parse parameters.
131+
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol",
132+
&object, Collator_ce_ptr, &strength ) == FAILURE )
133+
{
134+
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
135+
"collator_set_strength: unable to parse input params", 0 TSRMLS_CC );
136+
137+
RETURN_FALSE;
138+
}
139+
140+
// Fetch the object.
141+
COLLATOR_METHOD_FETCH_OBJECT;
142+
143+
// Set given strength.
144+
ucol_setStrength( co->ucoll, strength );
145+
146+
RETURN_TRUE;
147+
}
148+
/* }}} */
149+
150+
/*
151+
* Local variables:
152+
* tab-width: 4
153+
* c-basic-offset: 4
154+
* End:
155+
* vim600: noet sw=4 ts=4 fdm=marker
156+
* vim<600: noet sw=4 ts=4
157+
*/

ext/intl/collator/collator_attr.h

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
+----------------------------------------------------------------------+
3+
| PHP Version 5 |
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: Vadim Savchuk <vsavchuk@productengine.com> |
14+
| Dmitry Lakhtyuk <dlakhtyuk@productengine.com> |
15+
+----------------------------------------------------------------------+
16+
*/
17+
18+
#ifndef COLLATOR_ATTR_H
19+
#define CCOLLATOR_ATTR_H
20+
21+
#include <php.h>
22+
23+
PHP_FUNCTION( collator_get_attribute );
24+
PHP_FUNCTION( collator_set_attribute );
25+
PHP_FUNCTION( collator_get_strength );
26+
PHP_FUNCTION( collator_set_strength );
27+
28+
#endif // COLLATOR_ATTR_H

0 commit comments

Comments
 (0)