summaryrefslogtreecommitdiff
path: root/ext/intl/spoofchecker
diff options
context:
space:
mode:
authorScott MacVicar <scottmac@php.net>2011-01-13 07:46:59 +0000
committerScott MacVicar <scottmac@php.net>2011-01-13 07:46:59 +0000
commitb2c4503fbe920a5a343008ccbd037b1f5e31eded (patch)
tree9aea4e5bb8f2994fb76c58418f02aef1ffae0282 /ext/intl/spoofchecker
parentd90394851c7f86ee86afa466ae3b31757666a3a9 (diff)
downloadphp-git-b2c4503fbe920a5a343008ccbd037b1f5e31eded.tar.gz
intl: Add Spoofchecker cloning, fix typo in prototype, rename some variables and tidy syntax.
Diffstat (limited to 'ext/intl/spoofchecker')
-rwxr-xr-xext/intl/spoofchecker/spoofchecker_class.c28
-rwxr-xr-xext/intl/spoofchecker/spoofchecker_create.c4
-rwxr-xr-xext/intl/spoofchecker/spoofchecker_main.c40
3 files changed, 48 insertions, 24 deletions
diff --git a/ext/intl/spoofchecker/spoofchecker_class.c b/ext/intl/spoofchecker/spoofchecker_class.c
index 1b7b5573bd..3f00cdf15f 100755
--- a/ext/intl/spoofchecker/spoofchecker_class.c
+++ b/ext/intl/spoofchecker/spoofchecker_class.c
@@ -117,6 +117,31 @@ zend_function_entry Spoofchecker_class_functions[] = {
};
/* }}} */
+static zend_object_value spoofchecker_clone_obj(zval *object TSRMLS_DC) /* {{{ */
+{
+ zend_object_value new_obj_val;
+ zend_object_handle handle = Z_OBJ_HANDLE_P(object);
+ Spoofchecker_object *sfo, *new_sfo;
+
+ sfo = (Spoofchecker_object *) zend_object_store_get_object(object TSRMLS_CC);
+ intl_error_reset(SPOOFCHECKER_ERROR_P(sfo) TSRMLS_CC);
+
+ new_obj_val = Spoofchecker_ce_ptr->create_object(Spoofchecker_ce_ptr TSRMLS_CC);
+ new_sfo = (Spoofchecker_object *)zend_object_store_get_object_by_handle(new_obj_val.handle TSRMLS_CC);
+ /* clone standard parts */
+ zend_objects_clone_members(&new_sfo->zo, new_obj_val, &sfo->zo, handle TSRMLS_CC);
+ /* clone internal object */
+ new_sfo->uspoof = uspoof_clone(sfo->uspoof, SPOOFCHECKER_ERROR_CODE_P(new_sfo));
+ if(U_FAILURE(SPOOFCHECKER_ERROR_CODE(new_sfo))) {
+ /* set up error in case error handler is interested */
+ intl_error_set( NULL, SPOOFCHECKER_ERROR_CODE(new_sfo), "Failed to clone SpoofChecker object", 0 TSRMLS_CC );
+ Spoofchecker_objects_dtor(new_sfo, new_obj_val.handle TSRMLS_CC); /* free new object */
+ zend_error(E_ERROR, "Failed to clone SpoofChecker object");
+ }
+ return new_obj_val;
+}
+/* }}} */
+
/* {{{ spoofchecker_register_Spoofchecker_class
* Initialize 'Spoofchecker' class
*/
@@ -131,8 +156,7 @@ void spoofchecker_register_Spoofchecker_class(TSRMLS_D)
memcpy(&Spoofchecker_handlers, zend_get_std_object_handlers(),
sizeof Spoofchecker_handlers);
- /* Doesn't make sense to clone */
- Spoofchecker_handlers.clone_obj = NULL;
+ Spoofchecker_handlers.clone_obj = spoofchecker_clone_obj;
if (!Spoofchecker_ce_ptr) {
zend_error(E_ERROR,
diff --git a/ext/intl/spoofchecker/spoofchecker_create.c b/ext/intl/spoofchecker/spoofchecker_create.c
index 91c06ec55d..3659551ede 100755
--- a/ext/intl/spoofchecker/spoofchecker_create.c
+++ b/ext/intl/spoofchecker/spoofchecker_create.c
@@ -29,13 +29,13 @@
PHP_METHOD(Spoofchecker, __construct)
{
int checks;
- SPOOFCHECKER_METHOD_INIT_VARS
+ SPOOFCHECKER_METHOD_INIT_VARS;
if (zend_parse_parameters_none() == FAILURE) {
return;
}
- SPOOFCHECKER_METHOD_FETCH_OBJECT
+ SPOOFCHECKER_METHOD_FETCH_OBJECT;
co->uspoof = uspoof_open(SPOOFCHECKER_ERROR_CODE_P(co));
INTL_CTOR_CHECK_STATUS(co, "spoofchecker: unable to open ICU Spoof Checker");
diff --git a/ext/intl/spoofchecker/spoofchecker_main.c b/ext/intl/spoofchecker/spoofchecker_main.c
index f6010a326f..1db1b1a508 100755
--- a/ext/intl/spoofchecker/spoofchecker_main.c
+++ b/ext/intl/spoofchecker/spoofchecker_main.c
@@ -21,7 +21,7 @@
#include "php_intl.h"
#include "spoofchecker_class.h"
-/* {{{ proto void Spoofchecker::isSuspicious( string $text[, int $error_code ] )
+/* {{{ proto bool Spoofchecker::isSuspicious( string $text[, int $error_code ] )
* Checks if a given text contains any suspicious characters
*/
PHP_METHOD(Spoofchecker, isSuspicious)
@@ -29,14 +29,14 @@ PHP_METHOD(Spoofchecker, isSuspicious)
int ret;
char *text;
int text_len;
- zval *issued_found = NULL;
- SPOOFCHECKER_METHOD_INIT_VARS
+ zval *error_code = NULL;
+ SPOOFCHECKER_METHOD_INIT_VARS;
- if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|z", &text, &text_len, &issued_found)) {
+ if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|z", &text, &text_len, &error_code)) {
return;
}
- SPOOFCHECKER_METHOD_FETCH_OBJECT
+ SPOOFCHECKER_METHOD_FETCH_OBJECT;
ret = uspoof_checkUTF8(co->uspoof, text, text_len, NULL, SPOOFCHECKER_ERROR_CODE_P(co));
@@ -45,15 +45,15 @@ PHP_METHOD(Spoofchecker, isSuspicious)
return;
}
- if (issued_found) {
- zval_dtor(issued_found);
- ZVAL_LONG(issued_found, ret);
+ if (error_code) {
+ zval_dtor(error_code);
+ ZVAL_LONG(error_code, ret);
}
RETVAL_BOOL(ret != 0);
}
/* }}} */
-/* {{{ proto void Spoofchecker::areConfusable( string $str1, string $str2[, int $error_code ] )
+/* {{{ proto bool Spoofchecker::areConfusable( string $str1, string $str2[, int $error_code ] )
* Checks if a given text contains any confusable characters
*/
PHP_METHOD(Spoofchecker, areConfusable)
@@ -61,15 +61,15 @@ PHP_METHOD(Spoofchecker, areConfusable)
int ret;
char *s1, *s2;
int s1_len, s2_len;
- zval *issued_found = NULL;
- SPOOFCHECKER_METHOD_INIT_VARS
+ zval *error_code = NULL;
+ SPOOFCHECKER_METHOD_INIT_VARS;
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|z", &s1, &s1_len,
- &s2, &s2_len, &issued_found)) {
+ &s2, &s2_len, &error_code)) {
return;
}
- SPOOFCHECKER_METHOD_FETCH_OBJECT
+ SPOOFCHECKER_METHOD_FETCH_OBJECT;
ret = uspoof_areConfusableUTF8(co->uspoof, s1, s1_len, s2, s2_len, SPOOFCHECKER_ERROR_CODE_P(co));
@@ -78,9 +78,9 @@ PHP_METHOD(Spoofchecker, areConfusable)
return;
}
- if (issued_found) {
- zval_dtor(issued_found);
- ZVAL_LONG(issued_found, ret);
+ if (error_code) {
+ zval_dtor(error_code);
+ ZVAL_LONG(error_code, ret);
}
RETVAL_BOOL(ret != 0);
}
@@ -94,13 +94,13 @@ PHP_METHOD(Spoofchecker, setAllowedLocales)
int ret;
char *locales;
int locales_len;
- SPOOFCHECKER_METHOD_INIT_VARS
+ SPOOFCHECKER_METHOD_INIT_VARS;
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &locales, &locales_len)) {
return;
}
- SPOOFCHECKER_METHOD_FETCH_OBJECT
+ SPOOFCHECKER_METHOD_FETCH_OBJECT;
uspoof_setAllowedLocales(co->uspoof, locales, SPOOFCHECKER_ERROR_CODE_P(co));
@@ -118,13 +118,13 @@ PHP_METHOD(Spoofchecker, setChecks)
{
int ret;
long checks;
- SPOOFCHECKER_METHOD_INIT_VARS
+ SPOOFCHECKER_METHOD_INIT_VARS;
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &checks)) {
return;
}
- SPOOFCHECKER_METHOD_FETCH_OBJECT
+ SPOOFCHECKER_METHOD_FETCH_OBJECT;
uspoof_setChecks(co->uspoof, checks, SPOOFCHECKER_ERROR_CODE_P(co));