summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog.adoc1
-rw-r--r--doc/de/weechat_scripting.de.adoc1
-rw-r--r--doc/en/weechat_plugin_api.en.adoc12
-rw-r--r--doc/en/weechat_scripting.en.adoc1
-rw-r--r--doc/fr/weechat_plugin_api.fr.adoc12
-rw-r--r--doc/fr/weechat_scripting.fr.adoc1
-rw-r--r--doc/it/weechat_plugin_api.it.adoc11
-rw-r--r--doc/it/weechat_scripting.it.adoc1
-rw-r--r--doc/ja/weechat_plugin_api.ja.adoc12
-rw-r--r--doc/ja/weechat_scripting.ja.adoc1
-rw-r--r--doc/pl/weechat_scripting.pl.adoc1
-rw-r--r--src/plugins/guile/weechat-guile-api.c16
-rw-r--r--src/plugins/javascript/weechat-js-api.cpp16
-rw-r--r--src/plugins/lua/weechat-lua-api.c17
-rw-r--r--src/plugins/perl/weechat-perl-api.c15
-rw-r--r--src/plugins/php/weechat-php-api.c15
-rw-r--r--src/plugins/php/weechat-php-api.h1
-rw-r--r--src/plugins/php/weechat-php.c1
-rw-r--r--src/plugins/python/weechat-python-api.c17
-rw-r--r--src/plugins/ruby/weechat-ruby-api.c21
-rw-r--r--src/plugins/tcl/weechat-tcl-api.c19
-rw-r--r--tests/scripts/python/testapi.py4
22 files changed, 190 insertions, 6 deletions
diff --git a/ChangeLog.adoc b/ChangeLog.adoc
index 024e68d6e..ad8ebd19b 100644
--- a/ChangeLog.adoc
+++ b/ChangeLog.adoc
@@ -21,6 +21,7 @@ https://weechat.org/files/releasenotes/ReleaseNotes-devel.html[release notes]
New features::
* core: allow merge of buffers by name in command /buffer (issue #1108, issue #1159)
+ * api: add function string_format_size in scripting API
* irc: add option "-server" in command /list (issue #1165)
* irc: add indexed ban list, add completion for /unban and /unquiet (issue #597, task #11374, task #10876)
* xfer: add option xfer.network.send_ack (issue #1171)
diff --git a/doc/de/weechat_scripting.de.adoc b/doc/de/weechat_scripting.de.adoc
index 21ca1f525..16ff2b5d8 100644
--- a/doc/de/weechat_scripting.de.adoc
+++ b/doc/de/weechat_scripting.de.adoc
@@ -443,6 +443,7 @@ Liste der Skript API Funktionen:
string_has_highlight +
string_has_highlight_regex +
string_mask_to_regex +
+ string_format_size +
string_remove_color +
string_is_command_char +
string_input_for_buffer +
diff --git a/doc/en/weechat_plugin_api.en.adoc b/doc/en/weechat_plugin_api.en.adoc
index 1c290140d..ebf33d451 100644
--- a/doc/en/weechat_plugin_api.en.adoc
+++ b/doc/en/weechat_plugin_api.en.adoc
@@ -1718,8 +1718,16 @@ char *str = weechat_string_format_size (2097152); /* str == "2.10 MB" */
free (str);
----
-[NOTE]
-This function is not available in scripting API.
+Script (Python):
+
+[source,python]
+----
+# prototype
+str = weechat.string_format_size(size)
+
+# example
+str = weechat.string_format_size(15200) # == "15.2 KB"
+----
==== string_remove_color
diff --git a/doc/en/weechat_scripting.en.adoc b/doc/en/weechat_scripting.en.adoc
index be39a2e49..6d2e829bc 100644
--- a/doc/en/weechat_scripting.en.adoc
+++ b/doc/en/weechat_scripting.en.adoc
@@ -430,6 +430,7 @@ List of functions in script API:
string_has_highlight +
string_has_highlight_regex +
string_mask_to_regex +
+ string_format_size +
string_remove_color +
string_is_command_char +
string_input_for_buffer +
diff --git a/doc/fr/weechat_plugin_api.fr.adoc b/doc/fr/weechat_plugin_api.fr.adoc
index 8b3f45c84..b19787f7c 100644
--- a/doc/fr/weechat_plugin_api.fr.adoc
+++ b/doc/fr/weechat_plugin_api.fr.adoc
@@ -1751,8 +1751,16 @@ char *str = weechat_string_format_size (2097152); /* str == "2.10 Mo" */
free (str);
----
-[NOTE]
-Cette fonction n'est pas disponible dans l'API script.
+Script (Python) :
+
+[source,python]
+----
+# prototype
+str = weechat.string_format_size(size)
+
+# exemple
+str = weechat.string_format_size(15200) # == "15.2 Ko"
+----
==== string_remove_color
diff --git a/doc/fr/weechat_scripting.fr.adoc b/doc/fr/weechat_scripting.fr.adoc
index f5ec58c96..c728869f5 100644
--- a/doc/fr/weechat_scripting.fr.adoc
+++ b/doc/fr/weechat_scripting.fr.adoc
@@ -442,6 +442,7 @@ Liste des fonctions de l'API script :
string_has_highlight +
string_has_highlight_regex +
string_mask_to_regex +
+ string_format_size +
string_remove_color +
string_is_command_char +
string_input_for_buffer +
diff --git a/doc/it/weechat_plugin_api.it.adoc b/doc/it/weechat_plugin_api.it.adoc
index fb9d5c035..08ecdba13 100644
--- a/doc/it/weechat_plugin_api.it.adoc
+++ b/doc/it/weechat_plugin_api.it.adoc
@@ -1790,6 +1790,17 @@ char *str = weechat_string_format_size (2097152); /* str == "2.10 MB" */
free (str);
----
+Script (Python):
+
+[source,python]
+----
+# prototipo
+str = weechat.string_format_size(size)
+
+# esempio
+str = weechat.string_format_size(15200) # == "15.2 KB"
+----
+
==== string_remove_color
Rimuove i colori di WeeChat da una stringa.
diff --git a/doc/it/weechat_scripting.it.adoc b/doc/it/weechat_scripting.it.adoc
index a42bddc92..b8a0c0381 100644
--- a/doc/it/weechat_scripting.it.adoc
+++ b/doc/it/weechat_scripting.it.adoc
@@ -447,6 +447,7 @@ Elenco di funzioni nelle API per gli script:
string_has_highlight +
string_has_highlight_regex +
string_mask_to_regex +
+ string_format_size +
string_remove_color +
string_is_command_char +
string_input_for_buffer +
diff --git a/doc/ja/weechat_plugin_api.ja.adoc b/doc/ja/weechat_plugin_api.ja.adoc
index 4f5776e80..875a0a14a 100644
--- a/doc/ja/weechat_plugin_api.ja.adoc
+++ b/doc/ja/weechat_plugin_api.ja.adoc
@@ -1724,8 +1724,16 @@ char *str = weechat_string_format_size (2097152); /* str == "2.10 MB" */
free (str);
----
-[NOTE]
-スクリプト API ではこの関数を利用できません。
+スクリプト (Python) での使用例:
+
+[source,python]
+----
+# プロトタイプ
+str = weechat.string_format_size(size)
+
+# 例
+str = weechat.string_format_size(15200) # == "15.2 KB"
+----
==== string_remove_color
diff --git a/doc/ja/weechat_scripting.ja.adoc b/doc/ja/weechat_scripting.ja.adoc
index b90a4a5b5..1a1f65923 100644
--- a/doc/ja/weechat_scripting.ja.adoc
+++ b/doc/ja/weechat_scripting.ja.adoc
@@ -438,6 +438,7 @@ link:weechat_plugin_api.ja.html[WeeChat プラグイン API リファレンス]
string_has_highlight +
string_has_highlight_regex +
string_mask_to_regex +
+ string_format_size +
string_remove_color +
string_is_command_char +
string_input_for_buffer +
diff --git a/doc/pl/weechat_scripting.pl.adoc b/doc/pl/weechat_scripting.pl.adoc
index 5cd1ee942..f9a97de08 100644
--- a/doc/pl/weechat_scripting.pl.adoc
+++ b/doc/pl/weechat_scripting.pl.adoc
@@ -436,6 +436,7 @@ Lista funkcji w API skryptów:
string_has_highlight +
string_has_highlight_regex +
string_mask_to_regex +
+ string_format_size +
string_remove_color +
string_is_command_char +
string_input_for_buffer +
diff --git a/src/plugins/guile/weechat-guile-api.c b/src/plugins/guile/weechat-guile-api.c
index 5ab2ff2f4..8a72e8505 100644
--- a/src/plugins/guile/weechat-guile-api.c
+++ b/src/plugins/guile/weechat-guile-api.c
@@ -394,6 +394,21 @@ weechat_guile_api_string_mask_to_regex (SCM mask)
}
SCM
+weechat_guile_api_string_format_size (SCM size)
+{
+ char *result;
+ SCM return_value;
+
+ API_INIT_FUNC(1, "string_format_size", API_RETURN_EMPTY);
+ if (!scm_is_integer (size))
+ API_WRONG_ARGS(API_RETURN_EMPTY);
+
+ result = weechat_string_format_size (scm_to_ulong_long (size));
+
+ API_RETURN_STRING_FREE(result);
+}
+
+SCM
weechat_guile_api_string_remove_color (SCM string, SCM replacement)
{
char *result;
@@ -4863,6 +4878,7 @@ weechat_guile_api_module_init (void *data)
API_DEF_FUNC(string_has_highlight, 2);
API_DEF_FUNC(string_has_highlight_regex, 2);
API_DEF_FUNC(string_mask_to_regex, 1);
+ API_DEF_FUNC(string_format_size, 1);
API_DEF_FUNC(string_remove_color, 2);
API_DEF_FUNC(string_is_command_char, 1);
API_DEF_FUNC(string_input_for_buffer, 1);
diff --git a/src/plugins/javascript/weechat-js-api.cpp b/src/plugins/javascript/weechat-js-api.cpp
index 0fd5c5f3d..67c09d016 100644
--- a/src/plugins/javascript/weechat-js-api.cpp
+++ b/src/plugins/javascript/weechat-js-api.cpp
@@ -74,6 +74,7 @@ extern "C"
{ \
if (((js_args[num] == 's') && (!args[num]->IsString())) \
|| ((js_args[num] == 'i') && (!args[num]->IsInt32())) \
+ || ((js_args[num] == 'n') && (!args[num]->IsNumber())) \
|| ((js_args[num] == 'h') && (!args[num]->IsObject()))) \
{ \
WEECHAT_SCRIPT_MSG_WRONG_ARGS(JS_CURRENT_SCRIPT_NAME, \
@@ -344,6 +345,20 @@ API_FUNC(string_mask_to_regex)
API_RETURN_STRING_FREE(result);
}
+API_FUNC(string_format_size)
+{
+ unsigned long long size;
+ char *result;
+
+ API_INIT_FUNC(1, "string_format_size", "n", API_RETURN_EMPTY);
+
+ size = args[0]->IntegerValue();
+
+ result = weechat_string_format_size (size);
+
+ API_RETURN_STRING_FREE(result);
+}
+
API_FUNC(string_remove_color)
{
char *result;
@@ -4808,6 +4823,7 @@ WeechatJsV8::loadLibs()
API_DEF_FUNC(string_has_highlight);
API_DEF_FUNC(string_has_highlight_regex);
API_DEF_FUNC(string_mask_to_regex);
+ API_DEF_FUNC(string_format_size);
API_DEF_FUNC(string_remove_color);
API_DEF_FUNC(string_is_command_char);
API_DEF_FUNC(string_input_for_buffer);
diff --git a/src/plugins/lua/weechat-lua-api.c b/src/plugins/lua/weechat-lua-api.c
index b1841bfa9..b04c72df5 100644
--- a/src/plugins/lua/weechat-lua-api.c
+++ b/src/plugins/lua/weechat-lua-api.c
@@ -368,6 +368,22 @@ API_FUNC(string_mask_to_regex)
API_RETURN_STRING_FREE(result);
}
+API_FUNC(string_format_size)
+{
+ unsigned long long size;
+ char *result;
+
+ API_INIT_FUNC(1, "string_format_size", API_RETURN_EMPTY);
+ if (lua_gettop (L) < 1)
+ API_WRONG_ARGS(API_RETURN_EMPTY);
+
+ size = lua_tonumber (L, -1);
+
+ result = weechat_string_format_size (size);
+
+ API_RETURN_STRING_FREE(result);
+}
+
API_FUNC(string_remove_color)
{
const char *string, *replacement;
@@ -5141,6 +5157,7 @@ const struct luaL_Reg weechat_lua_api_funcs[] = {
API_DEF_FUNC(string_has_highlight),
API_DEF_FUNC(string_has_highlight_regex),
API_DEF_FUNC(string_mask_to_regex),
+ API_DEF_FUNC(string_format_size),
API_DEF_FUNC(string_remove_color),
API_DEF_FUNC(string_is_command_char),
API_DEF_FUNC(string_input_for_buffer),
diff --git a/src/plugins/perl/weechat-perl-api.c b/src/plugins/perl/weechat-perl-api.c
index c16d58578..5196794a8 100644
--- a/src/plugins/perl/weechat-perl-api.c
+++ b/src/plugins/perl/weechat-perl-api.c
@@ -351,6 +351,20 @@ API_FUNC(string_mask_to_regex)
API_RETURN_STRING_FREE(result);
}
+API_FUNC(string_format_size)
+{
+ char *result;
+ dXSARGS;
+
+ API_INIT_FUNC(1, "string_format_size", API_RETURN_EMPTY);
+ if (items < 1)
+ API_WRONG_ARGS(API_RETURN_EMPTY);
+
+ result = weechat_string_format_size (SvUV (ST (0)));
+
+ API_RETURN_STRING_FREE(result);
+}
+
API_FUNC(string_remove_color)
{
char *result, *string, *replacement;
@@ -5075,6 +5089,7 @@ weechat_perl_api_init (pTHX)
API_DEF_FUNC(string_has_highlight);
API_DEF_FUNC(string_has_highlight_regex);
API_DEF_FUNC(string_mask_to_regex);
+ API_DEF_FUNC(string_format_size);
API_DEF_FUNC(string_remove_color);
API_DEF_FUNC(string_is_command_char);
API_DEF_FUNC(string_input_for_buffer);
diff --git a/src/plugins/php/weechat-php-api.c b/src/plugins/php/weechat-php-api.c
index 38f53911a..19012db25 100644
--- a/src/plugins/php/weechat-php-api.c
+++ b/src/plugins/php/weechat-php-api.c
@@ -443,6 +443,21 @@ API_FUNC(string_mask_to_regex)
API_RETURN_STRING(retval);
}
+API_FUNC(string_format_size)
+{
+ zend_long z_size;
+ char *retval;
+
+ API_INIT_FUNC(1, "string_format_size", API_RETURN_EMPTY);
+ if (zend_parse_parameters (ZEND_NUM_ARGS(),
+ "l", &z_size) == FAILURE)
+ API_WRONG_ARGS(API_RETURN_EMPTY);
+
+ retval = weechat_string_format_size ((unsigned long long)z_size);
+
+ API_RETURN_STRING(retval);
+}
+
API_FUNC(string_remove_color)
{
zend_string *z_string, *z_replacement;
diff --git a/src/plugins/php/weechat-php-api.h b/src/plugins/php/weechat-php-api.h
index c894185ed..eb0e5db69 100644
--- a/src/plugins/php/weechat-php-api.h
+++ b/src/plugins/php/weechat-php-api.h
@@ -57,6 +57,7 @@ PHP_FUNCTION(weechat_string_match);
PHP_FUNCTION(weechat_string_has_highlight);
PHP_FUNCTION(weechat_string_has_highlight_regex);
PHP_FUNCTION(weechat_string_mask_to_regex);
+PHP_FUNCTION(weechat_string_format_size);
PHP_FUNCTION(weechat_string_remove_color);
PHP_FUNCTION(weechat_string_is_command_char);
PHP_FUNCTION(weechat_string_input_for_buffer);
diff --git a/src/plugins/php/weechat-php.c b/src/plugins/php/weechat-php.c
index 58c34403d..720d8bd1d 100644
--- a/src/plugins/php/weechat-php.c
+++ b/src/plugins/php/weechat-php.c
@@ -111,6 +111,7 @@ const zend_function_entry weechat_functions[] = {
PHP_FE(weechat_string_has_highlight, NULL)
PHP_FE(weechat_string_has_highlight_regex, NULL)
PHP_FE(weechat_string_mask_to_regex, NULL)
+ PHP_FE(weechat_string_format_size, NULL)
PHP_FE(weechat_string_remove_color, NULL)
PHP_FE(weechat_string_is_command_char, NULL)
PHP_FE(weechat_string_input_for_buffer, NULL)
diff --git a/src/plugins/python/weechat-python-api.c b/src/plugins/python/weechat-python-api.c
index a6f812a2c..def103a5d 100644
--- a/src/plugins/python/weechat-python-api.c
+++ b/src/plugins/python/weechat-python-api.c
@@ -333,6 +333,22 @@ API_FUNC(string_mask_to_regex)
API_RETURN_STRING_FREE(result);
}
+API_FUNC(string_format_size)
+{
+ unsigned long long size;
+ char *result;
+ PyObject *return_value;
+
+ API_INIT_FUNC(1, "string_format_size", API_RETURN_EMPTY);
+ size = 0;
+ if (!PyArg_ParseTuple (args, "K", &size))
+ API_WRONG_ARGS(API_RETURN_EMPTY);
+
+ result = weechat_string_format_size (size);
+
+ API_RETURN_STRING_FREE(result);
+}
+
API_FUNC(string_remove_color)
{
char *string, *replacement, *result;
@@ -5067,6 +5083,7 @@ PyMethodDef weechat_python_funcs[] =
API_DEF_FUNC(string_has_highlight),
API_DEF_FUNC(string_has_highlight_regex),
API_DEF_FUNC(string_mask_to_regex),
+ API_DEF_FUNC(string_format_size),
API_DEF_FUNC(string_remove_color),
API_DEF_FUNC(string_is_command_char),
API_DEF_FUNC(string_input_for_buffer),
diff --git a/src/plugins/ruby/weechat-ruby-api.c b/src/plugins/ruby/weechat-ruby-api.c
index 60bc49053..2e04a0f10 100644
--- a/src/plugins/ruby/weechat-ruby-api.c
+++ b/src/plugins/ruby/weechat-ruby-api.c
@@ -401,6 +401,26 @@ weechat_ruby_api_string_mask_to_regex (VALUE class, VALUE mask)
}
static VALUE
+weechat_ruby_api_string_format_size (VALUE class, VALUE size)
+{
+ unsigned long long c_size;
+ char *result;
+ VALUE return_value;
+
+ API_INIT_FUNC(1, "string_format_size", API_RETURN_EMPTY);
+ if (NIL_P (size))
+ API_WRONG_ARGS(API_RETURN_EMPTY);
+
+ Check_Type (size, T_FIXNUM);
+
+ c_size = FIX2LONG (size);
+
+ result = weechat_string_format_size (c_size);
+
+ API_RETURN_STRING_FREE(result);
+}
+
+static VALUE
weechat_ruby_api_string_remove_color (VALUE class, VALUE string,
VALUE replacement)
{
@@ -6208,6 +6228,7 @@ weechat_ruby_api_init (VALUE ruby_mWeechat)
API_DEF_FUNC(string_has_highlight, 2);
API_DEF_FUNC(string_has_highlight_regex, 2);
API_DEF_FUNC(string_mask_to_regex, 1);
+ API_DEF_FUNC(string_format_size, 1);
API_DEF_FUNC(string_remove_color, 2);
API_DEF_FUNC(string_is_command_char, 1);
API_DEF_FUNC(string_input_for_buffer, 1);
diff --git a/src/plugins/tcl/weechat-tcl-api.c b/src/plugins/tcl/weechat-tcl-api.c
index 1ad4c1151..7a1df5a7f 100644
--- a/src/plugins/tcl/weechat-tcl-api.c
+++ b/src/plugins/tcl/weechat-tcl-api.c
@@ -488,6 +488,24 @@ API_FUNC(string_mask_to_regex)
API_RETURN_STRING_FREE(result);
}
+API_FUNC(string_format_size)
+{
+ Tcl_Obj *objp;
+ char *result;
+ long size;
+
+ API_INIT_FUNC(1, "string_format_size", API_RETURN_EMPTY);
+ if (objc < 2)
+ API_WRONG_ARGS(API_RETURN_EMPTY);
+
+ if (Tcl_GetLongFromObj (interp, objv[1], &size) != TCL_OK)
+ API_WRONG_ARGS(API_RETURN_EMPTY);
+
+ result = weechat_string_format_size ((unsigned long long)size);
+
+ API_RETURN_STRING_FREE(result);
+}
+
API_FUNC(string_remove_color)
{
Tcl_Obj *objp;
@@ -5542,6 +5560,7 @@ void weechat_tcl_api_init (Tcl_Interp *interp)
API_DEF_FUNC(string_has_highlight);
API_DEF_FUNC(string_has_highlight_regex);
API_DEF_FUNC(string_mask_to_regex);
+ API_DEF_FUNC(string_format_size);
API_DEF_FUNC(string_remove_color);
API_DEF_FUNC(string_is_command_char);
API_DEF_FUNC(string_input_for_buffer);
diff --git a/tests/scripts/python/testapi.py b/tests/scripts/python/testapi.py
index e6b826e63..8bf1ff2ef 100644
--- a/tests/scripts/python/testapi.py
+++ b/tests/scripts/python/testapi.py
@@ -62,6 +62,10 @@ def test_strings():
check(weechat.string_mask_to_regex('test*mask') == 'test.*mask')
check(weechat.string_has_highlight('my test string', 'test,word2') == 1)
check(weechat.string_has_highlight_regex('my test string', 'test|word2') == 1)
+ check(weechat.string_format_size(0) == '0 bytes')
+ check(weechat.string_format_size(1) == '1 byte')
+ check(weechat.string_format_size(2097152) == '2.10 MB')
+ check(weechat.string_format_size(42000000000000) == '42.00 TB')
check(weechat.string_remove_color('test', '?') == 'test')
check(weechat.string_is_command_char('/test') == 1)
check(weechat.string_is_command_char('test') == 0)