collator_create.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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_create.h"
  23. #include "intl_data.h"
  24. /* {{{ */
  25. static void collator_ctor(INTERNAL_FUNCTION_PARAMETERS)
  26. {
  27. const char* locale;
  28. int locale_len = 0;
  29. zval* object;
  30. Collator_object* co;
  31. intl_error_reset( NULL TSRMLS_CC );
  32. object = return_value;
  33. /* Parse parameters. */
  34. if( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "s",
  35. &locale, &locale_len ) == FAILURE )
  36. {
  37. intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
  38. "collator_create: unable to parse input params", 0 TSRMLS_CC );
  39. zval_dtor(return_value);
  40. RETURN_NULL();
  41. }
  42. INTL_CHECK_LOCALE_LEN_OBJ(locale_len, return_value);
  43. COLLATOR_METHOD_FETCH_OBJECT;
  44. if(locale_len == 0) {
  45. locale = intl_locale_get_default(TSRMLS_C);
  46. }
  47. /* Open ICU collator. */
  48. co->ucoll = ucol_open( locale, COLLATOR_ERROR_CODE_P( co ) );
  49. INTL_CTOR_CHECK_STATUS(co, "collator_create: unable to open ICU collator");
  50. }
  51. /* }}} */
  52. /* {{{ proto Collator collator_create( string $locale )
  53. * Create collator.
  54. */
  55. PHP_FUNCTION( collator_create )
  56. {
  57. object_init_ex( return_value, Collator_ce_ptr );
  58. collator_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
  59. }
  60. /* }}} */
  61. /* {{{ proto Collator Collator::__construct( string $locale )
  62. * Collator object constructor.
  63. */
  64. PHP_METHOD( Collator, __construct )
  65. {
  66. return_value = getThis();
  67. collator_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
  68. }
  69. /* }}} */
  70. /*
  71. * Local variables:
  72. * tab-width: 4
  73. * c-basic-offset: 4
  74. * End:
  75. * vim600: noet sw=4 ts=4 fdm=marker
  76. * vim<600: noet sw=4 ts=4
  77. */