api: add function string_format_size in scripting API

v2.8-utf8proc
Sébastien Helleu 2018-04-07 13:20:58 +02:00
parent ea365cccbf
commit 6de98179bc
22 changed files with 190 additions and 6 deletions

View File

@ -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)

View File

@ -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 +

View File

@ -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

View File

@ -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 +

View File

@ -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

View File

@ -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 +

View File

@ -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.

View File

@ -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 +

View File

@ -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

View File

@ -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 +

View File

@ -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 +

View File

@ -393,6 +393,21 @@ weechat_guile_api_string_mask_to_regex (SCM mask)
API_RETURN_STRING_FREE(result);
}
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)
{
@ -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);

View File

@ -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);

View File

@ -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),

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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)

View File

@ -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),

View File

@ -400,6 +400,26 @@ weechat_ruby_api_string_mask_to_regex (VALUE class, VALUE mask)
API_RETURN_STRING_FREE(result);
}
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);

View File

@ -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);

View File

@ -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)