Skip to content
Permalink
Browse files

api: add argument "strip_items" in function string_split

  • Loading branch information...
flashcode committed Jun 15, 2019
1 parent 866a29c commit 917815635415b523eaf58ed4c65757247d5cca99
Showing with 473 additions and 195 deletions.
  1. +1 −0 ChangeLog.adoc
  2. +22 −6 doc/en/weechat_plugin_api.en.adoc
  3. +22 −6 doc/fr/weechat_plugin_api.fr.adoc
  4. +23 −6 doc/it/weechat_plugin_api.it.adoc
  5. +23 −6 doc/ja/weechat_plugin_api.ja.adoc
  6. +4 −2 src/core/hook/wee-hook-command.c
  7. +1 −1 src/core/hook/wee-hook-focus.c
  8. +1 −0 src/core/hook/wee-hook-line.c
  9. +3 −3 src/core/wee-command.c
  10. +2 −2 src/core/wee-completion.c
  11. +1 −0 src/core/wee-config-file.c
  12. +13 −7 src/core/wee-config.c
  13. +1 −0 src/core/wee-input.c
  14. +1 −0 src/core/wee-secure.c
  15. +86 −14 src/core/wee-string.c
  16. +4 −3 src/core/wee-string.h
  17. +1 −1 src/core/wee-upgrade-file.c
  18. +2 −2 src/core/wee-url.c
  19. +2 −2 src/core/wee-util.c
  20. +1 −1 src/gui/curses/gui-curses-bar-window.c
  21. +2 −1 src/gui/curses/gui-curses-color.c
  22. +1 −0 src/gui/gui-bar-window.c
  23. +2 −1 src/gui/gui-bar.c
  24. +8 −8 src/gui/gui-buffer.c
  25. +1 −1 src/gui/gui-chat.c
  26. +1 −1 src/gui/gui-color.c
  27. +1 −0 src/gui/gui-completion.c
  28. +1 −0 src/gui/gui-filter.c
  29. +1 −1 src/gui/gui-line.c
  30. +1 −1 src/plugins/alias/alias-completion.c
  31. +1 −1 src/plugins/alias/alias.c
  32. +2 −1 src/plugins/buflist/buflist-config.c
  33. +1 −1 src/plugins/buflist/buflist-mouse.c
  34. +2 −2 src/plugins/exec/exec-buffer.c
  35. +1 −0 src/plugins/exec/exec-config.c
  36. +1 −1 src/plugins/fset/fset-buffer.c
  37. +1 −1 src/plugins/fset/fset-command.c
  38. +1 −0 src/plugins/fset/fset-completion.c
  39. +1 −0 src/plugins/fset/fset-config.c
  40. +1 −1 src/plugins/irc/irc-color.c
  41. +10 −10 src/plugins/irc/irc-command.c
  42. +9 −3 src/plugins/irc/irc-config.c
  43. +4 −4 src/plugins/irc/irc-info.c
  44. +1 −0 src/plugins/irc/irc-input.c
  45. +5 −5 src/plugins/irc/irc-message.c
  46. +3 −3 src/plugins/irc/irc-mode.c
  47. +6 −1 src/plugins/irc/irc-notify.c
  48. +12 −4 src/plugins/irc/irc-protocol.c
  49. +5 −4 src/plugins/irc/irc-redirect.c
  50. +6 −3 src/plugins/irc/irc-server.c
  51. +2 −0 src/plugins/irc/irc-upgrade.c
  52. +2 −2 src/plugins/plugin-api-info.c
  53. +1 −1 src/plugins/plugin-script-api.c
  54. +3 −3 src/plugins/plugin-script.c
  55. +1 −0 src/plugins/plugin.c
  56. +1 −1 src/plugins/python/weechat-python.c
  57. +4 −2 src/plugins/relay/irc/relay-irc.c
  58. +1 −1 src/plugins/relay/relay-client.c
  59. +2 −1 src/plugins/relay/relay-config.c
  60. +1 −1 src/plugins/relay/relay-info.c
  61. +3 −2 src/plugins/relay/weechat/relay-weechat-msg.c
  62. +14 −8 src/plugins/relay/weechat/relay-weechat-protocol.c
  63. +5 −3 src/plugins/script/script-action.c
  64. +1 −0 src/plugins/script/script-completion.c
  65. +3 −1 src/plugins/script/script-config.c
  66. +6 −3 src/plugins/script/script-repo.c
  67. +2 −1 src/plugins/spell/spell-bar-item.c
  68. +1 −0 src/plugins/spell/spell-config.c
  69. +3 −3 src/plugins/spell/spell-speller.c
  70. +1 −0 src/plugins/trigger/trigger-buffer.c
  71. +6 −2 src/plugins/trigger/trigger-callback.c
  72. +5 −2 src/plugins/trigger/trigger-command.c
  73. +3 −2 src/plugins/trigger/trigger-completion.c
  74. +2 −0 src/plugins/trigger/trigger.c
  75. +7 −5 src/plugins/weechat-plugin.h
  76. +1 −0 src/plugins/xfer/xfer.c
  77. +1 −1 tests/unit/core/test-core-hook.cpp
  78. +85 −29 tests/unit/core/test-core-string.cpp
@@ -20,6 +20,7 @@ https://weechat.org/files/releasenotes/ReleaseNotes-devel.html[release notes]

New features::

* api: add argument "strip_items" in function string_split
* exec: evaluate option exec.command.shell, change default value to "${env:SHELL}" (issue #1356)

Bug fixes::
@@ -1483,7 +1483,7 @@ This function is not available in scripting API.

==== string_split

_Updated in 2.5._
_Updated in 2.5, 2.6._

Split a string according to one or more delimiter(s).

@@ -1492,13 +1492,16 @@ Prototype:
[source,C]
----
char **weechat_string_split (const char *string, const char *separators,
int flags, int num_items_max, int *num_items);
const char *strip_items, int flags,
int num_items_max, int *num_items);
----

Arguments:

* _string_: string to split
* _separators_: delimiters used for split
* _strip_items_: chars to strip from returned items (left/right);
optional, can be NULL
* _flags_: combination values to change the default behavior; if the value is 0,
the default behavior is used (no strip of separators at beginning/end of string,
multiple separators are kept as-is so empty strings can be returned);
@@ -1536,7 +1539,7 @@ C example:
char **argv;
int argc;
argv = weechat_string_split ("abc de fghi ", " ", 0, 0, &argc);
argv = weechat_string_split ("abc de fghi ", " ", NULL, 0, 0, &argc);
/* result: argv[0] == "abc"
argv[1] == "de"
argv[2] == ""
@@ -1547,7 +1550,7 @@ argv = weechat_string_split ("abc de fghi ", " ", 0, 0, &argc);
*/
weechat_string_free_split (argv);
argv = weechat_string_split ("abc de fghi ", " ",
argv = weechat_string_split ("abc de fghi ", " ", NULL,
WEECHAT_STRING_SPLIT_STRIP_LEFT
| WEECHAT_STRING_SPLIT_STRIP_RIGHT
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS,
@@ -1560,7 +1563,7 @@ argv = weechat_string_split ("abc de fghi ", " ",
*/
weechat_string_free_split (argv);
argv = weechat_string_split ("abc de fghi ", " ",
argv = weechat_string_split ("abc de fghi ", " ", NULL,
WEECHAT_STRING_SPLIT_STRIP_LEFT
| WEECHAT_STRING_SPLIT_STRIP_RIGHT
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS
@@ -1574,7 +1577,7 @@ argv = weechat_string_split ("abc de fghi ", " ",
*/
weechat_string_free_split (argv);
argv = weechat_string_split ("abc de fghi ", " ",
argv = weechat_string_split ("abc de fghi ", " ", NULL,
WEECHAT_STRING_SPLIT_STRIP_LEFT
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS
| WEECHAT_STRING_SPLIT_KEEP_EOL,
@@ -1586,6 +1589,19 @@ argv = weechat_string_split ("abc de fghi ", " ",
argc == 3
*/
weechat_string_free_split (argv);
argv = weechat_string_split (" abc, de,, fghi ", ",", " ",
WEECHAT_STRING_SPLIT_STRIP_LEFT
| WEECHAT_STRING_SPLIT_STRIP_RIGHT
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS,
0, &argc);
/* result: argv[0] == "abc"
argv[1] == "de"
argv[2] == "fghi"
argv[3] == NULL
argc == 3
*/
weechat_string_free_split (argv);
----

[NOTE]
@@ -1509,7 +1509,7 @@ Cette fonction n'est pas disponible dans l'API script.

==== string_split

_Mis à jour dans la 2.5._
_Mis à jour dans la 2.5, 2.6._

Découper une chaîne à l'aide de délimiteur(s).

@@ -1518,13 +1518,16 @@ Prototype :
[source,C]
----
char **weechat_string_split (const char *string, const char *separators,
int flags, int num_items_max, int *num_items);
const char *strip_items, int flags,
int num_items_max, int *num_items);
----

Paramètres :

* _string_ : chaîne à découper
* _separators_ : délimiteurs utilisés pour le découpage
* _strip_items_ : caractères à supprimer des chaînes retournées (gauche/droite) ;
optionnel, peut être NULL
* _flags_ : combinaison de valeurs pour changer le comportement par défaut ;
si la valeur est 0, le comportement par défaut est utilisé (pas de suppression
des séparateurs en début/fin de chaîne, plusieurs séparateurs consécutifs
@@ -1564,7 +1567,7 @@ Exemples en C :
char **argv;
int argc;
argv = weechat_string_split ("abc de fghi ", " ", 0, 0, &argc);
argv = weechat_string_split ("abc de fghi ", " ", NULL, 0, 0, &argc);
/* résultat : argv[0] == "abc"
argv[1] == "de"
argv[2] == ""
@@ -1575,7 +1578,7 @@ argv = weechat_string_split ("abc de fghi ", " ", 0, 0, &argc);
*/
weechat_string_free_split (argv);
argv = weechat_string_split ("abc de fghi ", " ",
argv = weechat_string_split ("abc de fghi ", " ", NULL,
WEECHAT_STRING_SPLIT_STRIP_LEFT
| WEECHAT_STRING_SPLIT_STRIP_RIGHT
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS,
@@ -1588,7 +1591,7 @@ argv = weechat_string_split ("abc de fghi ", " ",
*/
weechat_string_free_split (argv);
argv = weechat_string_split ("abc de fghi ", " ",
argv = weechat_string_split ("abc de fghi ", " ", NULL,
WEECHAT_STRING_SPLIT_STRIP_LEFT
| WEECHAT_STRING_SPLIT_STRIP_RIGHT
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS
@@ -1602,7 +1605,7 @@ argv = weechat_string_split ("abc de fghi ", " ",
*/
weechat_string_free_split (argv);
argv = weechat_string_split ("abc de fghi ", " ",
argv = weechat_string_split ("abc de fghi ", " ", NULL,
WEECHAT_STRING_SPLIT_STRIP_LEFT
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS
| WEECHAT_STRING_SPLIT_KEEP_EOL,
@@ -1614,6 +1617,19 @@ argv = weechat_string_split ("abc de fghi ", " ",
argc == 3
*/
weechat_string_free_split (argv);
argv = weechat_string_split (" abc, de,, fghi ", ",", " ",
WEECHAT_STRING_SPLIT_STRIP_LEFT
| WEECHAT_STRING_SPLIT_STRIP_RIGHT
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS,
0, &argc);
/* résultat : argv[0] == "abc"
argv[1] == "de"
argv[2] == "fghi"
argv[3] == NULL
argc == 3
*/
weechat_string_free_split (argv);
----

[NOTE]
@@ -1555,7 +1555,7 @@ Questa funzione non è disponibile nelle API per lo scripting.
==== string_split

// TRANSLATION MISSING
_Updated in 2.5._
_Updated in 2.5, 2.6._

Divide una stringa in base a uno o più delimitatori.

@@ -1564,13 +1564,17 @@ Prototipo:
[source,C]
----
char **weechat_string_split (const char *string, const char *separators,
int flags, int num_items_max, int *num_items);
const char *strip_items, int flags,
int num_items_max, int *num_items);
----

Argomenti:

* _string_: stringa da dividere
* _separators_: delimitatori usati per dividere
// TRANSLATION MISSING
* _strip_items_: chars to strip from returned items (left/right);
optional, can be NULL
* _flags_: combination values to change the default behavior; if the value is 0,
the default behavior is used (no strip of separators at beginning/end of string,
multiple separators are kept as-is so empty strings can be returned);
@@ -1609,7 +1613,7 @@ Esempi:
char **argv;
int argc;
argv = weechat_string_split ("abc de fghi ", " ", 0, 0, &argc);
argv = weechat_string_split ("abc de fghi ", " ", NULL, 0, 0, &argc);
/* result: argv[0] == "abc"
argv[1] == "de"
argv[2] = ""
@@ -1620,7 +1624,7 @@ argv = weechat_string_split ("abc de fghi ", " ", 0, 0, &argc);
*/
weechat_string_free_split (argv);
argv = weechat_string_split ("abc de fghi ", " ",
argv = weechat_string_split ("abc de fghi ", " ", NULL,
WEECHAT_STRING_SPLIT_STRIP_LEFT
| WEECHAT_STRING_SPLIT_STRIP_RIGHT
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS,
@@ -1633,7 +1637,7 @@ argv = weechat_string_split ("abc de fghi ", " ",
*/
weechat_string_free_split (argv);
argv = weechat_string_split ("abc de fghi ", " ",
argv = weechat_string_split ("abc de fghi ", " ", NULL,
WEECHAT_STRING_SPLIT_STRIP_LEFT
| WEECHAT_STRING_SPLIT_STRIP_RIGHT
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS
@@ -1647,7 +1651,7 @@ argv = weechat_string_split ("abc de fghi ", " ",
*/
weechat_string_free_split (argv);
argv = weechat_string_split ("abc de fghi ", " ",
argv = weechat_string_split ("abc de fghi ", " ", NULL,
WEECHAT_STRING_SPLIT_STRIP_LEFT
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS
| WEECHAT_STRING_SPLIT_KEEP_EOL,
@@ -1659,6 +1663,19 @@ argv = weechat_string_split ("abc de fghi ", " ",
argc == 3
*/
weechat_string_free_split (argv);
argv = weechat_string_split (" abc, de,, fghi ", ",", " ",
WEECHAT_STRING_SPLIT_STRIP_LEFT
| WEECHAT_STRING_SPLIT_STRIP_RIGHT
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS,
0, &argc);
/* result: argv[0] == "abc"
argv[1] == "de"
argv[2] == "fghi"
argv[3] == NULL
argc == 3
*/
weechat_string_free_split (argv);
----

[NOTE]
@@ -1489,7 +1489,7 @@ if (weechat_string_regcomp (&my_regex, "([0-9]{4})-([0-9]{2})-([0-9]{2})",

==== string_split

_WeeChat バージョン 2.5 で更新。_
_WeeChat バージョン 2.5、2.6 で更新。_

1 つ以上の区切り文字に従って文字列を分割。

@@ -1498,13 +1498,17 @@ _WeeChat バージョン 2.5 で更新。_
[source,C]
----
char **weechat_string_split (const char *string, const char *separators,
int flags, int num_items_max, int *num_items);
const char *strip_items, int flags,
int num_items_max, int *num_items);
----

引数:

* _string_: 分割する文字列
* _separators_: 分割に使う区切り文字
// TRANSLATION MISSING
* _strip_items_: chars to strip from returned items (left/right);
optional, can be NULL
* _flags_:
デフォルト動作を変更するビットフラグの組合せ値; 値が 0 の場合、デフォルト動作
(文字列の先頭と末尾にある区切り文字を削除しない、連続する区切り文字を 1 つにまとめない)
@@ -1542,7 +1546,7 @@ C 言語での使用例:
char **argv;
int argc;
argv = weechat_string_split ("abc de fghi ", " ", 0, 0, &argc);
argv = weechat_string_split ("abc de fghi ", " ", NULL, 0, 0, &argc);
/* result: argv[0] == "abc"
argv[1] == "de"
argv[2] == ""
@@ -1553,7 +1557,7 @@ argv = weechat_string_split ("abc de fghi ", " ", 0, 0, &argc);
*/
weechat_string_free_split (argv);
argv = weechat_string_split ("abc de fghi ", " ",
argv = weechat_string_split ("abc de fghi ", " ", NULL,
WEECHAT_STRING_SPLIT_STRIP_LEFT
| WEECHAT_STRING_SPLIT_STRIP_RIGHT
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS,
@@ -1566,7 +1570,7 @@ argv = weechat_string_split ("abc de fghi ", " ",
*/
weechat_string_free_split (argv);
argv = weechat_string_split ("abc de fghi ", " ",
argv = weechat_string_split ("abc de fghi ", " ", NULL,
WEECHAT_STRING_SPLIT_STRIP_LEFT
| WEECHAT_STRING_SPLIT_STRIP_RIGHT
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS
@@ -1580,7 +1584,7 @@ argv = weechat_string_split ("abc de fghi ", " ",
*/
weechat_string_free_split (argv);
argv = weechat_string_split ("abc de fghi ", " ",
argv = weechat_string_split ("abc de fghi ", " ", NULL,
WEECHAT_STRING_SPLIT_STRIP_LEFT
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS
| WEECHAT_STRING_SPLIT_KEEP_EOL,
@@ -1592,6 +1596,19 @@ argv = weechat_string_split ("abc de fghi ", " ",
argc == 3
*/
weechat_string_free_split (argv);
argv = weechat_string_split (" abc, de,, fghi ", ",", " ",
WEECHAT_STRING_SPLIT_STRIP_LEFT
| WEECHAT_STRING_SPLIT_STRIP_RIGHT
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS,
0, &argc);
/* result: argv[0] == "abc"
argv[1] == "de"
argv[2] == "fghi"
argv[3] == NULL
argc == 3
*/
weechat_string_free_split (argv);
----

[NOTE]
@@ -174,6 +174,7 @@ hook_command_build_completion (struct t_hook_command *hook_command)
hook_command->cplt_template_args[i] = string_split (
hook_command->cplt_templates[i],
" ",
NULL,
WEECHAT_STRING_SPLIT_STRIP_LEFT
| WEECHAT_STRING_SPLIT_STRIP_RIGHT
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS,
@@ -218,6 +219,7 @@ hook_command_build_completion (struct t_hook_command *hook_command)
items = string_split (
hook_command->cplt_template_args[j][i],
"|",
NULL,
WEECHAT_STRING_SPLIT_STRIP_LEFT
| WEECHAT_STRING_SPLIT_STRIP_RIGHT
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS,
@@ -349,7 +351,7 @@ hook_command_exec (struct t_gui_buffer *buffer, int any_plugin,
if (hook_command_run_exec (buffer, string) == WEECHAT_RC_OK_EAT)
return HOOK_COMMAND_EXEC_OK;

argv = string_split (string, " ",
argv = string_split (string, " ", NULL,
WEECHAT_STRING_SPLIT_STRIP_LEFT
| WEECHAT_STRING_SPLIT_STRIP_RIGHT
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS,
@@ -359,7 +361,7 @@ hook_command_exec (struct t_gui_buffer *buffer, int any_plugin,
string_free_split (argv);
return HOOK_COMMAND_EXEC_NOT_FOUND;
}
argv_eol = string_split (string, " ",
argv_eol = string_split (string, " ", NULL,
WEECHAT_STRING_SPLIT_STRIP_LEFT
| WEECHAT_STRING_SPLIT_STRIP_RIGHT
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS
@@ -233,7 +233,7 @@ hook_focus_get_data (struct t_hashtable *hashtable_focus1,
keys = hashtable_get_string (hashtable1, "keys");
if (keys)
{
list_keys = string_split (keys, ",",
list_keys = string_split (keys, ",", NULL,
WEECHAT_STRING_SPLIT_STRIP_LEFT
| WEECHAT_STRING_SPLIT_STRIP_RIGHT
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS,
@@ -79,6 +79,7 @@ hook_line (struct t_weechat_plugin *plugin, const char *buffer_type,
new_hook_line->buffers = string_split (
(buffer_name && buffer_name[0]) ? buffer_name : "*",
",",
NULL,
WEECHAT_STRING_SPLIT_STRIP_LEFT
| WEECHAT_STRING_SPLIT_STRIP_RIGHT
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS,

0 comments on commit 9178156

Please sign in to comment.
You can’t perform that action at this time.