]> granicus.if.org Git - php/commitdiff
Added enchant_dict_quick_check() function.
authorIlia Alshanetsky <iliaa@php.net>
Tue, 9 Mar 2004 00:31:17 +0000 (00:31 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Tue, 9 Mar 2004 00:31:17 +0000 (00:31 +0000)
Made enchant_dict_check() return a boolean.

ext/enchant/CREDITS [new file with mode: 0644]
ext/enchant/enchant.c
ext/enchant/package.xml
ext/enchant/php_enchant.h

diff --git a/ext/enchant/CREDITS b/ext/enchant/CREDITS
new file mode 100644 (file)
index 0000000..481febb
--- /dev/null
@@ -0,0 +1,2 @@
+enchant
+Pierre-Alain Joye, Ilia Alshanetsky
index 02876c3618996365ee9a1464b7e6eeddff52a771..170027934594902a18642079eba58e13c4e1a5e5 100755 (executable)
@@ -13,6 +13,7 @@
   | license@php.net so we can mail you a copy immediately.               |
   +----------------------------------------------------------------------+
   | Author: Pierre-Alain Joye <paj@pearfr.org>                           |
+  |         Ilia Alshanetsky <ilia@prohost.org>                          |
   +----------------------------------------------------------------------+
 
   $Id$
@@ -81,6 +82,7 @@ function_entry enchant_functions[] = {
        PHP_FE(enchant_dict_store_replacement, NULL)
        PHP_FE(enchant_dict_get_error, NULL)
        PHP_FE(enchant_dict_describe, NULL)
+       PHP_FE(enchant_dict_quick_check, third_arg_force_ref)
 
        {NULL, NULL, NULL}      /* Must be the last line in enchant_functions[] */
 };
@@ -496,8 +498,47 @@ PHP_FUNCTION(enchant_broker_describe)
 }
 /* }}} */
 
+PHP_FUNCTION(enchant_dict_quick_check)
+{
+       zval *dict, *sugg = NULL;
+       char *word;
+       int wordlen;
+       enchant_dict *pdict;
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|z/", &dict, &word, &wordlen, &sugg) == FAILURE) {
+               RETURN_FALSE;
+       }
+
+       if (sugg) {
+               zval_dtor(sugg);
+       }
+
+       PHP_ENCHANT_GET_DICT;
+
+       if (enchant_dict_check(pdict->pdict, word, wordlen) > 0) {
+               if (!sugg && ZEND_NUM_ARGS() == 2) {
+                       RETURN_FALSE;
+               }
+
+               int n_sugg;
+               char **suggs;
+
+               array_init(sugg);
+
+               suggs = enchant_dict_suggest(pdict->pdict, word, wordlen, &n_sugg);
+               if (suggs && n_sugg) {
+                       int i;
+                       for (i = 0; i < n_sugg; i++) {
+                               add_next_index_string(sugg, suggs[i], 1);
+                       }
+               }
+               RETURN_FALSE;
+       }
+       RETURN_TRUE;
+}
+
 /* {{{ proto long enchant_dict_check(resource broker)
-    0 if the word is correctly spelled, positive if not, negative if error */
+    If the word is correctly spelled return true, otherwise return false */
 PHP_FUNCTION(enchant_dict_check)
 {
        zval *dict;
@@ -511,7 +552,7 @@ PHP_FUNCTION(enchant_dict_check)
 
        PHP_ENCHANT_GET_DICT;
 
-       RETURN_LONG((long)enchant_dict_check(pdict->pdict, word, wordlen));
+       RETURN_BOOL(!enchant_dict_check(pdict->pdict, word, wordlen));
 }
 /* }}} */
 
index f075f3f9ac5402ed8dfd7d4afee6eacbd486eb4d..a8170bbeaae89cd7bd0cbe20ad3535429f2d4a12 100755 (executable)
    <email>paj@pearfr.org</email>
    <role>lead</role>
   </maintainer>
+  <maintainer>
+   <user>iliaa</user>
+   <name>Ilia Alshanetsky</name>
+   <email>ilia@php.net</email>
+   <role>developer</role>
+  </maintainer>
  </maintainers>
  <description>Enchant is a binder for libenchant. Libenchant provides a common
 API for many spell libraries:
@@ -31,6 +37,7 @@ see www.abisource.com/enchant/</description>
    <file role="src" name="config.w32"/>
    <file role="src" name="enchant.c"/>
    <file role="src" name="php_enchant.h"/>
+   <file role="doc" name="CREDITS"/>
    <dir name="docs" role="doc">
      <dir name="examples">
        <file name="example1.php"/>
index 54ae7910d33b49b01f6524cb38d73ac7a1064625..e0d98730cae5d710ca7ecafe60846979beec06fd 100644 (file)
@@ -59,6 +59,7 @@ PHP_FUNCTION(enchant_dict_is_in_session);
 PHP_FUNCTION(enchant_dict_store_replacement);
 PHP_FUNCTION(enchant_dict_get_error);
 PHP_FUNCTION(enchant_dict_describe);
+PHP_FUNCTION(enchant_dict_quick_check);
 
 #ifdef ZTS
 #define ENCHANT_G(v) TSRMG(enchant_globals_id, zend_enchant_globals *, v)