spoofchecker_class.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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: Scott MacVicar <scottmac@php.net> |
  14. +----------------------------------------------------------------------+
  15. */
  16. #ifndef SPOOFCHECKER_CLASS_H
  17. #define SPOOFCHECKER_CLASS_H
  18. #include <php.h>
  19. #include "intl_common.h"
  20. #include "spoofchecker_create.h"
  21. #include "intl_error.h"
  22. #include "intl_data.h"
  23. #include <unicode/uspoof.h>
  24. typedef struct {
  25. zend_object zo;
  26. // error handling
  27. intl_error err;
  28. // ICU Spoofchecker
  29. USpoofChecker* uspoof;
  30. } Spoofchecker_object;
  31. #define SPOOFCHECKER_ERROR(co) (co)->err
  32. #define SPOOFCHECKER_ERROR_P(co) &(SPOOFCHECKER_ERROR(co))
  33. #define SPOOFCHECKER_ERROR_CODE(co) INTL_ERROR_CODE(SPOOFCHECKER_ERROR(co))
  34. #define SPOOFCHECKER_ERROR_CODE_P(co) &(INTL_ERROR_CODE(SPOOFCHECKER_ERROR(co)))
  35. void spoofchecker_register_Spoofchecker_class(TSRMLS_D);
  36. void spoofchecker_object_init(Spoofchecker_object* co TSRMLS_DC);
  37. void spoofchecker_object_destroy(Spoofchecker_object* co TSRMLS_DC);
  38. extern zend_class_entry *Spoofchecker_ce_ptr;
  39. /* Auxiliary macros */
  40. #define SPOOFCHECKER_METHOD_INIT_VARS \
  41. zval* object = getThis(); \
  42. Spoofchecker_object* co = NULL; \
  43. intl_error_reset(NULL TSRMLS_CC); \
  44. #define SPOOFCHECKER_METHOD_FETCH_OBJECT_NO_CHECK INTL_METHOD_FETCH_OBJECT(Spoofchecker, co)
  45. #define SPOOFCHECKER_METHOD_FETCH_OBJECT \
  46. SPOOFCHECKER_METHOD_FETCH_OBJECT_NO_CHECK; \
  47. if (co->uspoof == NULL) { \
  48. intl_errors_set(&co->err, U_ILLEGAL_ARGUMENT_ERROR, \
  49. "Found unconstructed Spoofchecker", 0 TSRMLS_CC); \
  50. RETURN_FALSE; \
  51. }
  52. // Macro to check return value of a ucol_* function call.
  53. #define SPOOFCHECKER_CHECK_STATUS(co, msg) \
  54. intl_error_set_code(NULL, SPOOFCHECKER_ERROR_CODE(co) TSRMLS_CC); \
  55. if (U_FAILURE(SPOOFCHECKER_ERROR_CODE(co))) { \
  56. intl_errors_set_custom_msg(SPOOFCHECKER_ERROR_P(co), msg, 0 TSRMLS_CC); \
  57. RETURN_FALSE; \
  58. } \
  59. #endif // #ifndef SPOOFCHECKER_CLASS_H