xref: /PHP-5.5/ext/intl/collator/collator_locale.c (revision 9762609c)
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_locale.h"
25 #include "intl_convert.h"
26 
27 #include <zend_API.h>
28 
29 /* {{{ proto string Collator::getLocale( int $type )
30  * Gets the locale name of the collator. }}} */
31 /* {{{ proto string collator_get_locale( Collator $coll, int $type )
32  * Gets the locale name of the collator.
33  */
PHP_FUNCTION(collator_get_locale)34 PHP_FUNCTION( collator_get_locale )
35 {
36 	long   type        = 0;
37 	char*  locale_name = NULL;
38 
39 	COLLATOR_METHOD_INIT_VARS
40 
41 	/* Parse parameters. */
42 	if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol",
43 		&object, Collator_ce_ptr, &type ) == FAILURE )
44 	{
45 		intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
46 			"collator_get_locale: unable to parse input params", 0 TSRMLS_CC );
47 
48 		RETURN_FALSE;
49 	}
50 
51 	/* Fetch the object. */
52 	COLLATOR_METHOD_FETCH_OBJECT;
53 
54 	if (!co || !co->ucoll) {
55 		intl_error_set_code( NULL, COLLATOR_ERROR_CODE( co ) TSRMLS_CC );
56 		intl_errors_set_custom_msg( COLLATOR_ERROR_P( co ),
57 			"Object not initialized", 0 TSRMLS_CC );
58 		php_error_docref(NULL TSRMLS_CC, E_RECOVERABLE_ERROR, "Object not initialized");
59 
60 		RETURN_FALSE;
61 	}
62 
63 	/* Get locale by specified type. */
64 	locale_name = (char*) ucol_getLocaleByType(
65 		co->ucoll, type, COLLATOR_ERROR_CODE_P( co ) );
66 	COLLATOR_CHECK_STATUS( co, "Error getting locale by type" );
67 
68 	/* Return it. */
69 	RETVAL_STRINGL( locale_name, strlen(locale_name), TRUE );
70 }
71 /* }}} */
72 
73 /*
74  * Local variables:
75  * tab-width: 4
76  * c-basic-offset: 4
77  * End:
78  * vim600: noet sw=4 ts=4 fdm=marker
79  * vim<600: noet sw=4 ts=4
80  */
81