collator_class.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. #include "collator_class.h"
  18. #include "php_intl.h"
  19. #include "collator_attr.h"
  20. #include "collator_compare.h"
  21. #include "collator_sort.h"
  22. #include "collator_convert.h"
  23. #include "collator_locale.h"
  24. #include "collator_create.h"
  25. #include "collator_error.h"
  26. #include "intl_error.h"
  27. #include <unicode/ucol.h>
  28. zend_class_entry *Collator_ce_ptr = NULL;
  29. static zend_object_handlers Collator_handlers;
  30. /*
  31. * Auxiliary functions needed by objects of 'Collator' class
  32. */
  33. /* {{{ Collator_objects_dtor */
  34. static void Collator_objects_dtor(
  35. void *object,
  36. zend_object_handle handle TSRMLS_DC )
  37. {
  38. zend_objects_destroy_object( object, handle TSRMLS_CC );
  39. }
  40. /* }}} */
  41. /* {{{ Collator_objects_free */
  42. void Collator_objects_free( zend_object *object TSRMLS_DC )
  43. {
  44. Collator_object* co = (Collator_object*)object;
  45. zend_object_std_dtor( &co->zo TSRMLS_CC );
  46. collator_object_destroy( co TSRMLS_CC );
  47. efree( co );
  48. }
  49. /* }}} */
  50. /* {{{ Collator_object_create */
  51. zend_object_value Collator_object_create(
  52. zend_class_entry *ce TSRMLS_DC )
  53. {
  54. zend_object_value retval;
  55. Collator_object* intern;
  56. intern = ecalloc( 1, sizeof(Collator_object) );
  57. intl_error_init( COLLATOR_ERROR_P( intern ) TSRMLS_CC );
  58. zend_object_std_init( &intern->zo, ce TSRMLS_CC );
  59. object_properties_init(&intern->zo, ce);
  60. retval.handle = zend_objects_store_put(
  61. intern,
  62. Collator_objects_dtor,
  63. (zend_objects_free_object_storage_t)Collator_objects_free,
  64. NULL TSRMLS_CC );
  65. retval.handlers = &Collator_handlers;
  66. return retval;
  67. }
  68. /* }}} */
  69. /*
  70. * 'Collator' class registration structures & functions
  71. */
  72. /* {{{ Collator methods arguments info */
  73. /* NOTE: modifying 'collator_XX_args' do not forget to
  74. modify approptiate 'collator_XX_args' for
  75. the procedural API.
  76. */
  77. ZEND_BEGIN_ARG_INFO_EX( collator_0_args, 0, 0, 0 )
  78. ZEND_END_ARG_INFO()
  79. ZEND_BEGIN_ARG_INFO_EX( collator_1_arg, 0, 0, 1 )
  80. ZEND_ARG_INFO( 0, arg1 )
  81. ZEND_END_ARG_INFO()
  82. ZEND_BEGIN_ARG_INFO_EX( collator_2_args, 0, 0, 2 )
  83. ZEND_ARG_INFO( 0, arg1 )
  84. ZEND_ARG_INFO( 0, arg2 )
  85. ZEND_END_ARG_INFO()
  86. ZEND_BEGIN_ARG_INFO_EX( collator_sort_args, 0, 0, 1 )
  87. ZEND_ARG_ARRAY_INFO( 1, arr, 0 )
  88. ZEND_ARG_INFO( 0, flags )
  89. ZEND_END_ARG_INFO()
  90. /* }}} */
  91. /* {{{ Collator_class_functions
  92. * Every 'Collator' class method has an entry in this table
  93. */
  94. zend_function_entry Collator_class_functions[] = {
  95. PHP_ME( Collator, __construct, collator_1_arg, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR )
  96. ZEND_FENTRY( create, ZEND_FN( collator_create ), collator_1_arg, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC )
  97. PHP_NAMED_FE( compare, ZEND_FN( collator_compare ), collator_2_args )
  98. PHP_NAMED_FE( sort, ZEND_FN( collator_sort ), collator_sort_args )
  99. PHP_NAMED_FE( sortWithSortKeys, ZEND_FN( collator_sort_with_sort_keys ), collator_sort_args )
  100. PHP_NAMED_FE( asort, ZEND_FN( collator_asort ), collator_sort_args )
  101. PHP_NAMED_FE( getAttribute, ZEND_FN( collator_get_attribute ), collator_1_arg )
  102. PHP_NAMED_FE( setAttribute, ZEND_FN( collator_set_attribute ), collator_2_args )
  103. PHP_NAMED_FE( getStrength, ZEND_FN( collator_get_strength ), collator_0_args )
  104. PHP_NAMED_FE( setStrength, ZEND_FN( collator_set_strength ), collator_1_arg )
  105. PHP_NAMED_FE( getLocale, ZEND_FN( collator_get_locale ), collator_1_arg )
  106. PHP_NAMED_FE( getErrorCode, ZEND_FN( collator_get_error_code ), collator_0_args )
  107. PHP_NAMED_FE( getErrorMessage, ZEND_FN( collator_get_error_message ), collator_0_args )
  108. PHP_NAMED_FE( getSortKey, ZEND_FN( collator_get_sort_key ), collator_2_args )
  109. PHP_FE_END
  110. };
  111. /* }}} */
  112. /* {{{ collator_register_Collator_class
  113. * Initialize 'Collator' class
  114. */
  115. void collator_register_Collator_class( TSRMLS_D )
  116. {
  117. zend_class_entry ce;
  118. /* Create and register 'Collator' class. */
  119. INIT_CLASS_ENTRY( ce, "Collator", Collator_class_functions );
  120. ce.create_object = Collator_object_create;
  121. Collator_ce_ptr = zend_register_internal_class( &ce TSRMLS_CC );
  122. memcpy(&Collator_handlers, zend_get_std_object_handlers(),
  123. sizeof Collator_handlers);
  124. /* Collator has no usable clone semantics - ucol_cloneBinary/ucol_openBinary require binary buffer
  125. for which we don't have the place to keep */
  126. Collator_handlers.clone_obj = NULL;
  127. /* Declare 'Collator' class properties. */
  128. if( !Collator_ce_ptr )
  129. {
  130. zend_error( E_ERROR,
  131. "Collator: attempt to create properties "
  132. "on a non-registered class." );
  133. return;
  134. }
  135. }
  136. /* }}} */
  137. /* {{{ void collator_object_init( Collator_object* co )
  138. * Initialize internals of Collator_object.
  139. * Must be called before any other call to 'collator_object_...' functions.
  140. */
  141. void collator_object_init( Collator_object* co TSRMLS_DC )
  142. {
  143. if( !co )
  144. return;
  145. intl_error_init( COLLATOR_ERROR_P( co ) TSRMLS_CC );
  146. }
  147. /* }}} */
  148. /* {{{ void collator_object_destroy( Collator_object* co )
  149. * Clean up mem allocted by internals of Collator_object
  150. */
  151. void collator_object_destroy( Collator_object* co TSRMLS_DC )
  152. {
  153. if( !co )
  154. return;
  155. if( co->ucoll )
  156. {
  157. ucol_close( co->ucoll );
  158. co->ucoll = NULL;
  159. }
  160. intl_error_reset( COLLATOR_ERROR_P( co ) TSRMLS_CC );
  161. }
  162. /* }}} */
  163. /*
  164. * Local variables:
  165. * tab-width: 4
  166. * c-basic-offset: 4
  167. * End:
  168. * vim600: noet sw=4 ts=4 fdm=marker
  169. * vim<600: noet sw=4 ts=4
  170. */