Skip to content

Commit

Permalink
Add enchant_dict_remove()
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsdos committed Jan 18, 2025
1 parent d0d8e68 commit 0c72a2a
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 1 deletion.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ PHP NEWS

- Enchant:
. Added enchant_dict_remove_from_session(). (nielsdos)
. Added enchant_dict_remove(). (nielsdos)

-GD:
. Fixed bug #68629 (Transparent artifacts when using imagerotate). (pierre,
Expand Down
2 changes: 2 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ PHP 8.5 UPGRADE NOTES
- Enchant:
. Added enchant_dict_remove_from_session() to remove a word added to the
spellcheck session via enchant_dict_add_to_session().
. Added enchant_dict_remove() to put a word on the exclusion list and remove
remove it from the session dictionary.

- PGSQL:
. pg_close_stmt offers an alternative way to close a prepared
Expand Down
16 changes: 16 additions & 0 deletions ext/enchant/enchant.c
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,22 @@ PHP_FUNCTION(enchant_dict_add)
}
/* }}} */

PHP_FUNCTION(enchant_dict_remove)
{
zval *dict;
char *word;
size_t wordlen;
enchant_dict *pdict;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "Op", &dict, enchant_dict_ce, &word, &wordlen) == FAILURE) {
RETURN_THROWS();
}

PHP_ENCHANT_GET_DICT;

enchant_dict_remove(pdict->pdict, word, wordlen);
}

/* {{{ add 'word' to this spell-checking session */
PHP_FUNCTION(enchant_dict_add_to_session)
{
Expand Down
2 changes: 2 additions & 0 deletions ext/enchant/enchant.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ function enchant_dict_suggest(EnchantDictionary $dictionary, string $word): arra

function enchant_dict_add(EnchantDictionary $dictionary, string $word): void {}

function enchant_dict_remove(EnchantDictionary $dictionary, string $word): void {}

/**
* @alias enchant_dict_add
*/
Expand Down
6 changes: 5 additions & 1 deletion ext/enchant/enchant_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions ext/enchant/tests/dict_remove.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
--TEST--
enchant_dict_remove() function
--EXTENSIONS--
enchant
--SKIPIF--
<?php
if (!is_array(enchant_broker_list_dicts(enchant_broker_init()))) die("skip no dictionary installed on this machine");
?>
--FILE--
<?php
$broker = enchant_broker_init();
$dicts = enchant_broker_list_dicts($broker);
$newWord = 'myImaginaryWord';

$requestDict = enchant_broker_request_dict($broker, $dicts[0]['lang_tag']);

var_dump(enchant_dict_check($requestDict, $newWord));
enchant_dict_add($requestDict, $newWord);
var_dump(enchant_dict_check($requestDict, $newWord));
var_dump(enchant_dict_is_added($requestDict, $newWord));
enchant_dict_remove($requestDict, $newWord);
var_dump(enchant_dict_check($requestDict, $newWord));
var_dump(enchant_dict_is_added($requestDict, $newWord));
?>
--EXPECT--
bool(false)
bool(true)
bool(true)
bool(false)
bool(false)

0 comments on commit 0c72a2a

Please sign in to comment.