collator_locale.c 2.6 KB

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