Back to index

php5  5.3.10
collator_locale.c
Go to the documentation of this file.
00001 /*
00002    +----------------------------------------------------------------------+
00003    | PHP Version 5                                                        |
00004    +----------------------------------------------------------------------+
00005    | This source file is subject to version 3.01 of the PHP license,      |
00006    | that is bundled with this package in the file LICENSE, and is        |
00007    | available through the world-wide-web at the following url:           |
00008    | http://www.php.net/license/3_01.txt                                  |
00009    | If you did not receive a copy of the PHP license and are unable to   |
00010    | obtain it through the world-wide-web, please send a note to          |
00011    | license@php.net so we can mail you a copy immediately.               |
00012    +----------------------------------------------------------------------+
00013    | Authors: Vadim Savchuk <vsavchuk@productengine.com>                  |
00014    |          Dmitry Lakhtyuk <dlakhtyuk@productengine.com>               |
00015    +----------------------------------------------------------------------+
00016  */
00017 
00018 #ifdef HAVE_CONFIG_H
00019 #include "config.h"
00020 #endif
00021 
00022 #include "php_intl.h"
00023 #include "collator_class.h"
00024 #include "collator_locale.h"
00025 #include "intl_convert.h"
00026 
00027 #include <zend_API.h>
00028 
00029 /* {{{ proto string Collator::getLocale( int $type )
00030  * Gets the locale name of the collator. }}} */
00031 /* {{{ proto string collator_get_locale( Collator $coll, int $type )
00032  * Gets the locale name of the collator.
00033  */
00034 PHP_FUNCTION( collator_get_locale )
00035 {
00036        long   type        = 0;
00037        char*  locale_name = NULL;
00038 
00039        COLLATOR_METHOD_INIT_VARS
00040 
00041        /* Parse parameters. */
00042        if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol",
00043               &object, Collator_ce_ptr, &type ) == FAILURE )
00044        {
00045               intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
00046                      "collator_get_locale: unable to parse input params", 0 TSRMLS_CC );
00047 
00048               RETURN_FALSE;
00049        }
00050 
00051        /* Fetch the object. */
00052        COLLATOR_METHOD_FETCH_OBJECT;
00053 
00054        if (!co || !co->ucoll) {
00055               intl_error_set_code( NULL, COLLATOR_ERROR_CODE( co ) TSRMLS_CC );
00056               intl_errors_set_custom_msg( COLLATOR_ERROR_P( co ),
00057                      "Object not initialized", 0 TSRMLS_CC );
00058               php_error_docref(NULL TSRMLS_CC, E_RECOVERABLE_ERROR, "Object not initialized");
00059 
00060               RETURN_FALSE;
00061        }
00062 
00063        /* Get locale by specified type. */
00064        locale_name = (char*) ucol_getLocaleByType(
00065               co->ucoll, type, COLLATOR_ERROR_CODE_P( co ) );
00066        COLLATOR_CHECK_STATUS( co, "Error getting locale by type" );
00067 
00068        /* Return it. */
00069        RETVAL_STRINGL( locale_name, strlen(locale_name), TRUE );
00070 }
00071 /* }}} */
00072 
00073 /*
00074  * Local variables:
00075  * tab-width: 4
00076  * c-basic-offset: 4
00077  * End:
00078  * vim600: noet sw=4 ts=4 fdm=marker
00079  * vim<600: noet sw=4 ts=4
00080  */