collator_class.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. #ifndef COLLATOR_CLASS_H
  18. #define COLLATOR_CLASS_H
  19. #include <php.h>
  20. #include "../intl_common.h"
  21. #include "../intl_error.h"
  22. #include "../intl_data.h"
  23. #include <unicode/ucol.h>
  24. typedef struct {
  25. // error handling
  26. intl_error err;
  27. // ICU collator
  28. UCollator* ucoll;
  29. zend_object zo;
  30. } Collator_object;
  31. #define COLLATOR_ERROR(co) (co)->err
  32. #define COLLATOR_ERROR_P(co) &(COLLATOR_ERROR(co))
  33. #define COLLATOR_ERROR_CODE(co) INTL_ERROR_CODE(COLLATOR_ERROR(co))
  34. #define COLLATOR_ERROR_CODE_P(co) &(INTL_ERROR_CODE(COLLATOR_ERROR(co)))
  35. static inline Collator_object *php_intl_collator_fetch_object(zend_object *obj) {
  36. return (Collator_object *)((char*)(obj) - XtOffsetOf(Collator_object, zo));
  37. }
  38. #define Z_INTL_COLLATOR_P(zv) php_intl_collator_fetch_object(Z_OBJ_P(zv))
  39. void collator_register_Collator_class( void );
  40. void collator_object_init( Collator_object* co );
  41. void collator_object_destroy( Collator_object* co );
  42. extern zend_class_entry *Collator_ce_ptr;
  43. /* Auxiliary macros */
  44. #define COLLATOR_METHOD_INIT_VARS \
  45. zval* object = NULL; \
  46. Collator_object* co = NULL; \
  47. intl_error_reset( NULL ); \
  48. #define COLLATOR_METHOD_FETCH_OBJECT INTL_METHOD_FETCH_OBJECT(INTL_COLLATOR, co)
  49. // Macro to check return value of a ucol_* function call.
  50. #define COLLATOR_CHECK_STATUS( co, msg ) \
  51. intl_error_set_code( NULL, COLLATOR_ERROR_CODE( co ) ); \
  52. if( U_FAILURE( COLLATOR_ERROR_CODE( co ) ) ) \
  53. { \
  54. intl_errors_set_custom_msg( COLLATOR_ERROR_P( co ), msg, 0 ); \
  55. RETURN_FALSE; \
  56. } \
  57. #endif // #ifndef COLLATOR_CLASS_H