spoofchecker_class.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. +----------------------------------------------------------------------+
  3. | This source file is subject to version 3.01 of the PHP license, |
  4. | that is bundled with this package in the file LICENSE, and is |
  5. | available through the world-wide-web at the following url: |
  6. | https://www.php.net/license/3_01.txt |
  7. | If you did not receive a copy of the PHP license and are unable to |
  8. | obtain it through the world-wide-web, please send a note to |
  9. | license@php.net so we can mail you a copy immediately. |
  10. +----------------------------------------------------------------------+
  11. | Authors: Scott MacVicar <scottmac@php.net> |
  12. +----------------------------------------------------------------------+
  13. */
  14. #ifndef SPOOFCHECKER_CLASS_H
  15. #define SPOOFCHECKER_CLASS_H
  16. #include <php.h>
  17. #include "intl_common.h"
  18. #include "intl_error.h"
  19. #include "intl_data.h"
  20. #include <unicode/uspoof.h>
  21. typedef struct {
  22. // error handling
  23. intl_error err;
  24. // ICU Spoofchecker
  25. USpoofChecker* uspoof;
  26. zend_object zo;
  27. } Spoofchecker_object;
  28. static inline Spoofchecker_object *php_intl_spoofchecker_fetch_object(zend_object *obj) {
  29. return (Spoofchecker_object *)((char*)(obj) - XtOffsetOf(Spoofchecker_object, zo));
  30. }
  31. #define Z_INTL_SPOOFCHECKER_P(zv) php_intl_spoofchecker_fetch_object((Z_OBJ_P(zv)))
  32. #define SPOOFCHECKER_ERROR(co) (co)->err
  33. #define SPOOFCHECKER_ERROR_P(co) &(SPOOFCHECKER_ERROR(co))
  34. #define SPOOFCHECKER_ERROR_CODE(co) INTL_ERROR_CODE(SPOOFCHECKER_ERROR(co))
  35. #define SPOOFCHECKER_ERROR_CODE_P(co) &(INTL_ERROR_CODE(SPOOFCHECKER_ERROR(co)))
  36. void spoofchecker_register_Spoofchecker_class(void);
  37. void spoofchecker_object_init(Spoofchecker_object* co);
  38. void spoofchecker_object_destroy(Spoofchecker_object* co);
  39. extern zend_class_entry *Spoofchecker_ce_ptr;
  40. /* Auxiliary macros */
  41. #define SPOOFCHECKER_METHOD_INIT_VARS \
  42. zval* object = ZEND_THIS; \
  43. Spoofchecker_object* co = NULL; \
  44. intl_error_reset(NULL); \
  45. #define SPOOFCHECKER_METHOD_FETCH_OBJECT_NO_CHECK INTL_METHOD_FETCH_OBJECT(INTL_SPOOFCHECKER, co)
  46. #define SPOOFCHECKER_METHOD_FETCH_OBJECT \
  47. SPOOFCHECKER_METHOD_FETCH_OBJECT_NO_CHECK; \
  48. if (co->uspoof == NULL) { \
  49. zend_throw_error(NULL, "Found unconstructed Spoofchecker"); \
  50. RETURN_THROWS(); \
  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)); \
  55. if (U_FAILURE(SPOOFCHECKER_ERROR_CODE(co))) { \
  56. intl_errors_set_custom_msg(SPOOFCHECKER_ERROR_P(co), msg, 0); \
  57. RETURN_FALSE; \
  58. } \
  59. #if U_ICU_VERSION_MAJOR_NUM >= 58
  60. #define SPOOFCHECKER_DEFAULT_RESTRICTION_LEVEL USPOOF_HIGHLY_RESTRICTIVE
  61. #endif
  62. #endif // #ifndef SPOOFCHECKER_CLASS_H