spoofchecker_class.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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: 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. // error handling
  26. intl_error err;
  27. // ICU Spoofchecker
  28. USpoofChecker* uspoof;
  29. zend_object zo;
  30. } Spoofchecker_object;
  31. static inline Spoofchecker_object *php_intl_spoofchecker_fetch_object(zend_object *obj) {
  32. return (Spoofchecker_object *)((char*)(obj) - XtOffsetOf(Spoofchecker_object, zo));
  33. }
  34. #define Z_INTL_SPOOFCHECKER_P(zv) php_intl_spoofchecker_fetch_object((Z_OBJ_P(zv)))
  35. #define SPOOFCHECKER_ERROR(co) (co)->err
  36. #define SPOOFCHECKER_ERROR_P(co) &(SPOOFCHECKER_ERROR(co))
  37. #define SPOOFCHECKER_ERROR_CODE(co) INTL_ERROR_CODE(SPOOFCHECKER_ERROR(co))
  38. #define SPOOFCHECKER_ERROR_CODE_P(co) &(INTL_ERROR_CODE(SPOOFCHECKER_ERROR(co)))
  39. void spoofchecker_register_Spoofchecker_class(void);
  40. void spoofchecker_object_init(Spoofchecker_object* co);
  41. void spoofchecker_object_destroy(Spoofchecker_object* co);
  42. extern zend_class_entry *Spoofchecker_ce_ptr;
  43. /* Auxiliary macros */
  44. #define SPOOFCHECKER_METHOD_INIT_VARS \
  45. zval* object = getThis(); \
  46. Spoofchecker_object* co = NULL; \
  47. intl_error_reset(NULL); \
  48. #define SPOOFCHECKER_METHOD_FETCH_OBJECT_NO_CHECK INTL_METHOD_FETCH_OBJECT(INTL_SPOOFCHECKER, co)
  49. #define SPOOFCHECKER_METHOD_FETCH_OBJECT \
  50. SPOOFCHECKER_METHOD_FETCH_OBJECT_NO_CHECK; \
  51. if (co->uspoof == NULL) { \
  52. intl_errors_set(&co->err, U_ILLEGAL_ARGUMENT_ERROR, \
  53. "Found unconstructed Spoofchecker", 0); \
  54. RETURN_FALSE; \
  55. }
  56. // Macro to check return value of a ucol_* function call.
  57. #define SPOOFCHECKER_CHECK_STATUS(co, msg) \
  58. intl_error_set_code(NULL, SPOOFCHECKER_ERROR_CODE(co)); \
  59. if (U_FAILURE(SPOOFCHECKER_ERROR_CODE(co))) { \
  60. intl_errors_set_custom_msg(SPOOFCHECKER_ERROR_P(co), msg, 0); \
  61. RETURN_FALSE; \
  62. } \
  63. #if U_ICU_VERSION_MAJOR_NUM >= 58
  64. #define SPOOFCHECKER_DEFAULT_RESTRICTION_LEVEL USPOOF_HIGHLY_RESTRICTIVE
  65. #endif
  66. #endif // #ifndef SPOOFCHECKER_CLASS_H