You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
3.0 KiB

11 years ago
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 7 |
  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_create.h"
  23. #include "intl_data.h"
  24. /* {{{ */
  25. static void collator_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor)
  26. {
  27. const char* locale;
  28. size_t locale_len = 0;
  29. zval* object;
  30. Collator_object* co;
  31. int zpp_flags = is_constructor ? ZEND_PARSE_PARAMS_THROW : 0;
  32. intl_error_reset( NULL );
  33. object = return_value;
  34. /* Parse parameters. */
  35. if( zend_parse_parameters_ex( zpp_flags, ZEND_NUM_ARGS(), "s",
  36. &locale, &locale_len ) == FAILURE )
  37. {
  38. intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
  39. "collator_create: unable to parse input params", 0 );
  40. zval_dtor(return_value);
  41. RETURN_NULL();
  42. }
  43. INTL_CHECK_LOCALE_LEN_OBJ(locale_len, return_value);
  44. COLLATOR_METHOD_FETCH_OBJECT;
  45. if(locale_len == 0) {
  46. locale = intl_locale_get_default();
  47. }
  48. /* Open ICU collator. */
  49. co->ucoll = ucol_open( locale, COLLATOR_ERROR_CODE_P( co ) );
  50. INTL_CTOR_CHECK_STATUS(co, "collator_create: unable to open ICU collator");
  51. }
  52. /* }}} */
  53. /* {{{ proto Collator collator_create( string $locale )
  54. * Create collator.
  55. */
  56. PHP_FUNCTION( collator_create )
  57. {
  58. object_init_ex( return_value, Collator_ce_ptr );
  59. collator_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
  60. }
  61. /* }}} */
  62. /* {{{ proto Collator Collator::__construct( string $locale )
  63. * Collator object constructor.
  64. */
  65. PHP_METHOD( Collator, __construct )
  66. {
  67. zend_error_handling error_handling;
  68. zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
  69. return_value = getThis();
  70. collator_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
  71. if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) {
  72. if (!EG(exception)) {
  73. zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0);
  74. }
  75. }
  76. zend_restore_error_handling(&error_handling);
  77. }
  78. /* }}} */
  79. /*
  80. * Local variables:
  81. * tab-width: 4
  82. * c-basic-offset: 4
  83. * End:
  84. * vim600: noet sw=4 ts=4 fdm=marker
  85. * vim<600: noet sw=4 ts=4
  86. */