mirror of
https://github.com/weechat/weechat.git
synced 2026-06-29 14:26:39 +02:00
api: add function string_parse_size
This commit is contained in:
@@ -28,6 +28,7 @@ New features::
|
||||
* api: add info "uptime_current"
|
||||
* api: add function crypto_hash_file
|
||||
* api: add support of priority in function hook_line (issue #1821)
|
||||
* api: add function string_parse_size
|
||||
* buflist: add variable `${hotlist_priority_number}` (integer version of `${hotlist_priority}`)
|
||||
* irc: display SETNAME command in channels and private buffers, add options irc.color.message_setname and irc.look.smart_filter_setname (issue #1805)
|
||||
* irc: add option irc.look.display_pv_nick_change
|
||||
|
||||
@@ -589,6 +589,7 @@ Liste der Skript API Funktionen:
|
||||
string_has_highlight_regex +
|
||||
string_mask_to_regex +
|
||||
string_format_size +
|
||||
string_parse_size +
|
||||
string_color_code_size +
|
||||
string_remove_color +
|
||||
string_is_command_char +
|
||||
|
||||
@@ -1955,6 +1955,51 @@ def string_format_size(size: int) -> str: ...
|
||||
str = weechat.string_format_size(15200) # == "15.2 KB"
|
||||
----
|
||||
|
||||
==== string_parse_size
|
||||
|
||||
_WeeChat ≥ 3.7._
|
||||
|
||||
Parse a string with a size and optional unit and return the size in bytes.
|
||||
|
||||
Prototype:
|
||||
|
||||
[source,c]
|
||||
----
|
||||
unsigned long long weechat_string_parse_size (const char *size);
|
||||
----
|
||||
|
||||
Arguments:
|
||||
|
||||
* _size_: the size as string: float number followed optional spaces and optional
|
||||
unit (lower or upper case), which is one of:
|
||||
** _b_: bytes
|
||||
** _k_: kilobytes (1k = 1000 bytes)
|
||||
** _m_: megabytes (1m = 1000k = 1,000,000 bytes)
|
||||
** _g_: gigabytes (1g = 1000m = 1,000,000,000 bytes)
|
||||
** _t_: terabytes (1t = 1000g = 1,000,000,000,000 bytes)
|
||||
|
||||
Return value:
|
||||
|
||||
* size in bytes, 0 if error
|
||||
|
||||
C example:
|
||||
|
||||
[source,c]
|
||||
----
|
||||
unsigned long long size = weechat_parse_size ("1.34m"); /* size == 1340000 */
|
||||
----
|
||||
|
||||
Script (Python):
|
||||
|
||||
[source,python]
|
||||
----
|
||||
# prototype
|
||||
def string_parse_size(size: str) -> int: ...
|
||||
|
||||
# example
|
||||
size = weechat.string_parse_size("1.34m") # 1340000
|
||||
----
|
||||
|
||||
==== string_color_code_size
|
||||
|
||||
_WeeChat ≥ 3.0._
|
||||
|
||||
@@ -573,6 +573,7 @@ List of functions in script API:
|
||||
string_has_highlight_regex +
|
||||
string_mask_to_regex +
|
||||
string_format_size +
|
||||
string_parse_size +
|
||||
string_color_code_size +
|
||||
string_remove_color +
|
||||
string_is_command_char +
|
||||
|
||||
@@ -1990,6 +1990,53 @@ def string_format_size(size: int) -> str: ...
|
||||
str = weechat.string_format_size(15200) # == "15.2 Ko"
|
||||
----
|
||||
|
||||
==== string_parse_size
|
||||
|
||||
_WeeChat ≥ 3.7._
|
||||
|
||||
Analyser une chaîne avec une taille et une unité optionnelle et retourner
|
||||
la taille en octets.
|
||||
|
||||
Prototype :
|
||||
|
||||
[source,c]
|
||||
----
|
||||
unsigned long long weechat_string_parse_size (const char *size);
|
||||
----
|
||||
|
||||
Paramètres :
|
||||
|
||||
* _size_ : la taille sous forme de chaîne : nombre décimal suivi par des espaces
|
||||
optionnels et une unité optionnelle (en minuscules ou majuscules), qui est une
|
||||
des suivantes :
|
||||
** _b_ : octets
|
||||
** _k_ : kilo-octets (1k = 1000 octets)
|
||||
** _m_ : méga-octets (1m = 1000k = 1 000 000 octets)
|
||||
** _g_ : giga-octets (1g = 1000m = 1 000 000 000 octets)
|
||||
** _t_ : tera-octets (1t = 1000g = 1 000 000 000 000 octets)
|
||||
|
||||
Valeur de retour :
|
||||
|
||||
* taille en octets, 0 si erreur
|
||||
|
||||
Exemple en C :
|
||||
|
||||
[source,c]
|
||||
----
|
||||
unsigned long long size = weechat_parse_size ("1.34m"); /* size == 1340000 */
|
||||
----
|
||||
|
||||
Script (Python) :
|
||||
|
||||
[source,python]
|
||||
----
|
||||
# prototype
|
||||
def string_parse_size(size: str) -> int: ...
|
||||
|
||||
# exemple
|
||||
size = weechat.string_parse_size("1.34m") # 1340000
|
||||
----
|
||||
|
||||
==== string_color_code_size
|
||||
|
||||
_WeeChat ≥ 3.0._
|
||||
|
||||
@@ -593,6 +593,7 @@ Liste des fonctions de l'API script :
|
||||
string_has_highlight_regex +
|
||||
string_mask_to_regex +
|
||||
string_format_size +
|
||||
string_parse_size +
|
||||
string_color_code_size +
|
||||
string_remove_color +
|
||||
string_is_command_char +
|
||||
|
||||
@@ -2044,6 +2044,52 @@ def string_format_size(size: int) -> str: ...
|
||||
str = weechat.string_format_size(15200) # == "15.2 KB"
|
||||
----
|
||||
|
||||
// TRANSLATION MISSING
|
||||
==== string_parse_size
|
||||
|
||||
_WeeChat ≥ 3.7._
|
||||
|
||||
Parse a string with a size and optional unit and return the size in bytes.
|
||||
|
||||
Prototipo:
|
||||
|
||||
[source,c]
|
||||
----
|
||||
unsigned long long weechat_string_parse_size (const char *size);
|
||||
----
|
||||
|
||||
Argomenti:
|
||||
|
||||
* _size_: the size as string: float number followed optional spaces and optional
|
||||
unit (lower or upper case), which is one of:
|
||||
** _b_: bytes
|
||||
** _k_: kilobytes (1k = 1000 bytes)
|
||||
** _m_: megabytes (1m = 1000k = 1,000,000 bytes)
|
||||
** _g_: gigabytes (1g = 1000m = 1,000,000,000 bytes)
|
||||
** _t_: terabytes (1t = 1000g = 1,000,000,000,000 bytes)
|
||||
|
||||
Valore restituito:
|
||||
|
||||
* size in bytes, 0 if error
|
||||
|
||||
Esempio in C:
|
||||
|
||||
[source,c]
|
||||
----
|
||||
unsigned long long size = weechat_parse_size ("1.34m"); /* size == 1340000 */
|
||||
----
|
||||
|
||||
Script (Python):
|
||||
|
||||
[source,python]
|
||||
----
|
||||
# prototipo
|
||||
def string_parse_size(size: str) -> int: ...
|
||||
|
||||
# esempio
|
||||
size = weechat.string_parse_size("1.34m") # 1340000
|
||||
----
|
||||
|
||||
==== string_color_code_size
|
||||
|
||||
_WeeChat ≥ 3.0._
|
||||
|
||||
@@ -603,6 +603,7 @@ Elenco di funzioni nelle API per gli script:
|
||||
string_has_highlight_regex +
|
||||
string_mask_to_regex +
|
||||
string_format_size +
|
||||
string_parse_size +
|
||||
string_color_code_size +
|
||||
string_remove_color +
|
||||
string_is_command_char +
|
||||
|
||||
@@ -1981,6 +1981,52 @@ def string_format_size(size: int) -> str: ...
|
||||
str = weechat.string_format_size(15200) # == "15.2 KB"
|
||||
----
|
||||
|
||||
// TRANSLATION MISSING
|
||||
==== string_parse_size
|
||||
|
||||
_WeeChat ≥ 3.7._
|
||||
|
||||
Parse a string with a size and optional unit and return the size in bytes.
|
||||
|
||||
プロトタイプ:
|
||||
|
||||
[source,c]
|
||||
----
|
||||
unsigned long long weechat_string_parse_size (const char *size);
|
||||
----
|
||||
|
||||
引数:
|
||||
|
||||
* _size_: the size as string: float number followed optional spaces and optional
|
||||
unit (lower or upper case), which is one of:
|
||||
** _b_: bytes
|
||||
** _k_: kilobytes (1k = 1000 bytes)
|
||||
** _m_: megabytes (1m = 1000k = 1,000,000 bytes)
|
||||
** _g_: gigabytes (1g = 1000m = 1,000,000,000 bytes)
|
||||
** _t_: terabytes (1t = 1000g = 1,000,000,000,000 bytes)
|
||||
|
||||
戻り値:
|
||||
|
||||
* size in bytes, 0 if error
|
||||
|
||||
C 言語での使用例:
|
||||
|
||||
[source,c]
|
||||
----
|
||||
unsigned long long size = weechat_parse_size ("1.34m"); /* size == 1340000 */
|
||||
----
|
||||
|
||||
Script (Python):
|
||||
|
||||
[source,python]
|
||||
----
|
||||
# プロトタイプ
|
||||
def string_parse_size(size: str) -> int: ...
|
||||
|
||||
# 例
|
||||
size = weechat.string_parse_size("1.34m") # 1340000
|
||||
----
|
||||
|
||||
==== string_color_code_size
|
||||
|
||||
_WeeChat ≥ 3.0._
|
||||
|
||||
@@ -596,6 +596,7 @@ link:weechat_plugin_api.ja.html[WeeChat プラグイン API リファレンス
|
||||
string_has_highlight_regex +
|
||||
string_mask_to_regex +
|
||||
string_format_size +
|
||||
string_parse_size +
|
||||
string_color_code_size +
|
||||
string_remove_color +
|
||||
string_is_command_char +
|
||||
|
||||
@@ -580,6 +580,7 @@ Lista funkcji w API skryptów:
|
||||
string_has_highlight_regex +
|
||||
string_mask_to_regex +
|
||||
string_format_size +
|
||||
string_parse_size +
|
||||
string_color_code_size +
|
||||
string_remove_color +
|
||||
string_is_command_char +
|
||||
|
||||
@@ -1875,6 +1875,52 @@ def string_format_size(size: int) -> str: ...
|
||||
str = weechat.string_format_size(15200) # == "15.2 KB"
|
||||
----
|
||||
|
||||
// TRANSLATION MISSING
|
||||
==== string_parse_size
|
||||
|
||||
_WeeChat ≥ 3.7._
|
||||
|
||||
Parse a string with a size and optional unit and return the size in bytes.
|
||||
|
||||
Прототип:
|
||||
|
||||
[source,c]
|
||||
----
|
||||
unsigned long long weechat_string_parse_size (const char *size);
|
||||
----
|
||||
|
||||
Аргументи:
|
||||
|
||||
* _size_: the size as string: float number followed optional spaces and optional
|
||||
unit (lower or upper case), which is one of:
|
||||
** _b_: bytes
|
||||
** _k_: kilobytes (1k = 1000 bytes)
|
||||
** _m_: megabytes (1m = 1000k = 1,000,000 bytes)
|
||||
** _g_: gigabytes (1g = 1000m = 1,000,000,000 bytes)
|
||||
** _t_: terabytes (1t = 1000g = 1,000,000,000,000 bytes)
|
||||
|
||||
Повратна вредност:
|
||||
|
||||
* size in bytes, 0 if error
|
||||
|
||||
C пример:
|
||||
|
||||
[source,c]
|
||||
----
|
||||
unsigned long long size = weechat_parse_size ("1.34m"); /* size == 1340000 */
|
||||
----
|
||||
|
||||
Script (Python):
|
||||
|
||||
[source,python]
|
||||
----
|
||||
# прототип
|
||||
def string_parse_size(size: str) -> int: ...
|
||||
|
||||
# пример
|
||||
size = weechat.string_parse_size("1.34m") # 1340000
|
||||
----
|
||||
|
||||
==== string_color_code_size
|
||||
|
||||
_WeeChat ≥ 3.0._
|
||||
|
||||
@@ -532,6 +532,7 @@ weechat_hook_timer(1000, 0, 1, $timer_cb, 'test');
|
||||
string_has_highlight_regex +
|
||||
string_mask_to_regex +
|
||||
string_format_size +
|
||||
string_parse_size +
|
||||
string_color_code_size +
|
||||
string_remove_color +
|
||||
string_is_command_char +
|
||||
|
||||
@@ -2978,6 +2978,97 @@ string_format_size (unsigned long long size)
|
||||
return strdup (str_size);
|
||||
}
|
||||
|
||||
/*
|
||||
* Parses a string with a size and returns the size in bytes.
|
||||
*
|
||||
* The format is "123" or "123X" or "123 X" where 123 is any positive number
|
||||
* as a float (for example: 123 or 4.56) and X the unit, which can be one of
|
||||
* (lower or upper case are accepted):
|
||||
*
|
||||
* b bytes (default if unit is missing)
|
||||
* k kilobytes (1k = 1000 bytes)
|
||||
* m megabytes (1m = 1000k = 1,000,000 bytes)
|
||||
* g gigabytes (1g = 1000m = 1,000,000,000 bytes)
|
||||
* t terabytes (1t = 1000g = 1,000,000,000,000 bytes)
|
||||
*
|
||||
* Note: decimals of the float number are ignored if the unit is bytes
|
||||
* (eg: "5.9" or "5.9B" returns 5).
|
||||
*
|
||||
* Returns the parsed size, 0 if error.
|
||||
*/
|
||||
|
||||
unsigned long long
|
||||
string_parse_size (const char *size)
|
||||
{
|
||||
const char *pos;
|
||||
char *str_number, *error;
|
||||
double number;
|
||||
unsigned long long result;
|
||||
|
||||
str_number = NULL;
|
||||
result = 0;
|
||||
|
||||
if (!size || !size[0])
|
||||
goto end;
|
||||
|
||||
pos = size;
|
||||
while ((pos[0] == '.') || isdigit (pos[0]))
|
||||
{
|
||||
pos++;
|
||||
}
|
||||
|
||||
if (pos == size)
|
||||
goto end;
|
||||
|
||||
str_number = string_strndup (size, pos - size);
|
||||
if (!str_number)
|
||||
goto end;
|
||||
|
||||
number = strtod (str_number, &error);
|
||||
if (!error || error[0])
|
||||
goto end;
|
||||
|
||||
while (pos[0] == ' ')
|
||||
{
|
||||
pos++;
|
||||
}
|
||||
|
||||
if (pos[0] && pos[1])
|
||||
goto end;
|
||||
|
||||
switch (pos[0])
|
||||
{
|
||||
case '\0':
|
||||
result = number;
|
||||
break;
|
||||
case 'b':
|
||||
case 'B':
|
||||
result = number;
|
||||
break;
|
||||
case 'k':
|
||||
case 'K':
|
||||
result = number * 1000.0;
|
||||
break;
|
||||
case 'm':
|
||||
case 'M':
|
||||
result = number * 1000.0 * 1000.0;
|
||||
break;
|
||||
case 'g':
|
||||
case 'G':
|
||||
result = number * 1000.0 * 1000.0 * 1000.0;
|
||||
break;
|
||||
case 't':
|
||||
case 'T':
|
||||
result = number * 1000.0 * 1000.0 * 1000.0 * 1000.0;
|
||||
break;
|
||||
}
|
||||
|
||||
end:
|
||||
if (str_number)
|
||||
free (str_number);
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* Encodes a string in base16 (hexadecimal).
|
||||
*
|
||||
|
||||
@@ -111,6 +111,7 @@ extern char *string_iconv_from_internal (const char *charset,
|
||||
const char *string);
|
||||
extern int string_fprintf (FILE *file, const char *data, ...);
|
||||
extern char *string_format_size (unsigned long long size);
|
||||
extern unsigned long long string_parse_size (const char *size);
|
||||
extern int string_base16_encode (const char *from, int length, char *to);
|
||||
extern int string_base16_decode (const char *from, char *to);
|
||||
extern int string_base32_encode (const char *from, int length, char *to);
|
||||
|
||||
@@ -431,6 +431,20 @@ weechat_guile_api_string_format_size (SCM size)
|
||||
API_RETURN_STRING_FREE(result);
|
||||
}
|
||||
|
||||
SCM
|
||||
weechat_guile_api_string_parse_size (SCM size)
|
||||
{
|
||||
unsigned long long value;
|
||||
|
||||
API_INIT_FUNC(1, "string_parse_size", API_RETURN_LONG(0));
|
||||
if (!scm_is_string (size))
|
||||
API_WRONG_ARGS(API_RETURN_LONG(0));
|
||||
|
||||
value = weechat_string_parse_size (API_SCM_TO_STRING(size));
|
||||
|
||||
API_RETURN_LONG(value);
|
||||
}
|
||||
|
||||
SCM
|
||||
weechat_guile_api_string_color_code_size (SCM string)
|
||||
{
|
||||
@@ -5118,6 +5132,7 @@ weechat_guile_api_module_init (void *data)
|
||||
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_parse_size, 1);
|
||||
API_DEF_FUNC(string_color_code_size, 1);
|
||||
API_DEF_FUNC(string_remove_color, 2);
|
||||
API_DEF_FUNC(string_is_command_char, 1);
|
||||
|
||||
@@ -378,6 +378,19 @@ API_FUNC(string_format_size)
|
||||
API_RETURN_STRING_FREE(result);
|
||||
}
|
||||
|
||||
API_FUNC(string_parse_size)
|
||||
{
|
||||
unsigned long long value;
|
||||
|
||||
API_INIT_FUNC(1, "string_parse_size", "s", API_RETURN_LONG(0));
|
||||
|
||||
v8::String::Utf8Value size(args[0]);
|
||||
|
||||
value = weechat_string_parse_size (*size);
|
||||
|
||||
API_RETURN_LONG(value);
|
||||
}
|
||||
|
||||
API_FUNC(string_color_code_size)
|
||||
{
|
||||
int size;
|
||||
@@ -5060,6 +5073,7 @@ WeechatJsV8::loadLibs()
|
||||
API_DEF_FUNC(string_has_highlight_regex);
|
||||
API_DEF_FUNC(string_mask_to_regex);
|
||||
API_DEF_FUNC(string_format_size);
|
||||
API_DEF_FUNC(string_parse_size);
|
||||
API_DEF_FUNC(string_color_code_size);
|
||||
API_DEF_FUNC(string_remove_color);
|
||||
API_DEF_FUNC(string_is_command_char);
|
||||
|
||||
@@ -423,6 +423,22 @@ API_FUNC(string_format_size)
|
||||
API_RETURN_STRING_FREE(result);
|
||||
}
|
||||
|
||||
API_FUNC(string_parse_size)
|
||||
{
|
||||
const char *size;
|
||||
unsigned long long value;
|
||||
|
||||
API_INIT_FUNC(1, "string_parse_size", API_RETURN_LONG(0));
|
||||
if (lua_gettop (L) < 1)
|
||||
API_WRONG_ARGS(API_RETURN_LONG(0));
|
||||
|
||||
size = lua_tostring (L, -1);
|
||||
|
||||
value = weechat_string_parse_size (size);
|
||||
|
||||
API_RETURN_LONG(value);
|
||||
}
|
||||
|
||||
API_FUNC(string_color_code_size)
|
||||
{
|
||||
const char *string;
|
||||
@@ -5416,6 +5432,7 @@ const struct luaL_Reg weechat_lua_api_funcs[] = {
|
||||
API_DEF_FUNC(string_has_highlight_regex),
|
||||
API_DEF_FUNC(string_mask_to_regex),
|
||||
API_DEF_FUNC(string_format_size),
|
||||
API_DEF_FUNC(string_parse_size),
|
||||
API_DEF_FUNC(string_color_code_size),
|
||||
API_DEF_FUNC(string_remove_color),
|
||||
API_DEF_FUNC(string_is_command_char),
|
||||
|
||||
@@ -383,6 +383,20 @@ API_FUNC(string_format_size)
|
||||
API_RETURN_STRING_FREE(result);
|
||||
}
|
||||
|
||||
API_FUNC(string_parse_size)
|
||||
{
|
||||
unsigned long long value;
|
||||
dXSARGS;
|
||||
|
||||
API_INIT_FUNC(1, "string_parse_size", API_RETURN_LONG(0));
|
||||
if (items < 1)
|
||||
API_WRONG_ARGS(API_RETURN_LONG(0));
|
||||
|
||||
value = weechat_string_parse_size (SvPV_nolen (ST (0))); /* size */
|
||||
|
||||
API_RETURN_LONG(value);
|
||||
}
|
||||
|
||||
API_FUNC(string_color_code_size)
|
||||
{
|
||||
int size;
|
||||
@@ -5367,6 +5381,7 @@ weechat_perl_api_init (pTHX)
|
||||
API_DEF_FUNC(string_has_highlight_regex);
|
||||
API_DEF_FUNC(string_mask_to_regex);
|
||||
API_DEF_FUNC(string_format_size);
|
||||
API_DEF_FUNC(string_parse_size);
|
||||
API_DEF_FUNC(string_color_code_size);
|
||||
API_DEF_FUNC(string_remove_color);
|
||||
API_DEF_FUNC(string_is_command_char);
|
||||
|
||||
@@ -496,6 +496,23 @@ API_FUNC(string_format_size)
|
||||
API_RETURN_STRING_FREE(result);
|
||||
}
|
||||
|
||||
API_FUNC(string_parse_size)
|
||||
{
|
||||
zend_string *z_size;
|
||||
char *size;
|
||||
unsigned long long value;
|
||||
|
||||
API_INIT_FUNC(1, "string_parse_size", API_RETURN_LONG(0));
|
||||
if (zend_parse_parameters (ZEND_NUM_ARGS(), "S", &z_size) == FAILURE)
|
||||
API_WRONG_ARGS(API_RETURN_LONG(0));
|
||||
|
||||
size = ZSTR_VAL(z_size);
|
||||
|
||||
value = weechat_string_parse_size ((const char *)size);
|
||||
|
||||
API_RETURN_LONG(value);
|
||||
}
|
||||
|
||||
API_FUNC(string_color_code_size)
|
||||
{
|
||||
zend_string *z_string;
|
||||
|
||||
@@ -59,6 +59,7 @@ 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_parse_size);
|
||||
PHP_FUNCTION(weechat_string_color_code_size);
|
||||
PHP_FUNCTION(weechat_string_remove_color);
|
||||
PHP_FUNCTION(weechat_string_is_command_char);
|
||||
|
||||
@@ -117,6 +117,7 @@ const zend_function_entry weechat_functions[] = {
|
||||
PHP_FE(weechat_string_has_highlight_regex, arginfo_weechat_string_has_highlight_regex)
|
||||
PHP_FE(weechat_string_mask_to_regex, arginfo_weechat_string_mask_to_regex)
|
||||
PHP_FE(weechat_string_format_size, arginfo_weechat_string_format_size)
|
||||
PHP_FE(weechat_string_parse_size, arginfo_weechat_string_parse_size)
|
||||
PHP_FE(weechat_string_color_code_size, arginfo_weechat_string_color_code_size)
|
||||
PHP_FE(weechat_string_remove_color, arginfo_weechat_string_remove_color)
|
||||
PHP_FE(weechat_string_is_command_char, arginfo_weechat_string_is_command_char)
|
||||
|
||||
@@ -25,6 +25,7 @@ function weechat_string_has_highlight(string $p0, string $p1): int {}
|
||||
function weechat_string_has_highlight_regex(string $p0, string $p1): int {}
|
||||
function weechat_string_mask_to_regex(string $p0): string {}
|
||||
function weechat_string_format_size(int $p0): string {}
|
||||
function weechat_string_parse_size(string $p0): int {}
|
||||
function weechat_string_color_code_size(string $p0): int {}
|
||||
function weechat_string_remove_color(string $p0, string $p1): string {}
|
||||
function weechat_string_is_command_char(string $p0): int {}
|
||||
|
||||
@@ -57,6 +57,8 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_weechat_string_format_size, 0, 1
|
||||
ZEND_ARG_TYPE_INFO(0, p0, IS_LONG, 0)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
#define arginfo_weechat_string_parse_size arginfo_weechat_charset_set
|
||||
|
||||
#define arginfo_weechat_string_color_code_size arginfo_weechat_charset_set
|
||||
|
||||
#define arginfo_weechat_string_remove_color arginfo_weechat_iconv_to_internal
|
||||
|
||||
@@ -633,6 +633,7 @@ plugin_load (const char *filename, int init_plugin, int argc, char **argv)
|
||||
new_plugin->string_split_command = &string_split_command;
|
||||
new_plugin->string_free_split_command = &string_free_split_command;
|
||||
new_plugin->string_format_size = &string_format_size;
|
||||
new_plugin->string_parse_size = &string_parse_size;
|
||||
new_plugin->string_color_code_size = &gui_color_code_size;
|
||||
new_plugin->string_remove_color = &gui_color_decode;
|
||||
new_plugin->string_base_encode = &string_base_encode;
|
||||
|
||||
@@ -369,6 +369,21 @@ API_FUNC(string_format_size)
|
||||
API_RETURN_STRING_FREE(result);
|
||||
}
|
||||
|
||||
API_FUNC(string_parse_size)
|
||||
{
|
||||
char *size;
|
||||
unsigned long long value;
|
||||
|
||||
API_INIT_FUNC(1, "string_parse_size", API_RETURN_LONG(0));
|
||||
size = NULL;
|
||||
if (!PyArg_ParseTuple (args, "s", &size))
|
||||
API_WRONG_ARGS(API_RETURN_LONG(0));
|
||||
|
||||
value = weechat_string_parse_size (size);
|
||||
|
||||
API_RETURN_LONG(value);
|
||||
}
|
||||
|
||||
API_FUNC(string_color_code_size)
|
||||
{
|
||||
char *string;
|
||||
@@ -5281,6 +5296,7 @@ PyMethodDef weechat_python_funcs[] =
|
||||
API_DEF_FUNC(string_has_highlight_regex),
|
||||
API_DEF_FUNC(string_mask_to_regex),
|
||||
API_DEF_FUNC(string_format_size),
|
||||
API_DEF_FUNC(string_parse_size),
|
||||
API_DEF_FUNC(string_color_code_size),
|
||||
API_DEF_FUNC(string_remove_color),
|
||||
API_DEF_FUNC(string_is_command_char),
|
||||
|
||||
@@ -122,6 +122,11 @@ def string_format_size(size: int) -> str:
|
||||
...
|
||||
|
||||
|
||||
def string_parse_size(size: str) -> int:
|
||||
"""`string_parse_size in WeeChat plugin API reference <https://weechat.org/doc/api/#_string_parse_size>`_"""
|
||||
...
|
||||
|
||||
|
||||
def string_color_code_size(string: str) -> int:
|
||||
"""`string_color_code_size in WeeChat plugin API reference <https://weechat.org/doc/api/#_string_color_code_size>`_"""
|
||||
...
|
||||
|
||||
@@ -448,6 +448,25 @@ weechat_ruby_api_string_format_size (VALUE class, VALUE size)
|
||||
API_RETURN_STRING_FREE(result);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
weechat_ruby_api_string_parse_size (VALUE class, VALUE size)
|
||||
{
|
||||
char *c_size;
|
||||
unsigned long long value;
|
||||
|
||||
API_INIT_FUNC(1, "string_parse_size", API_RETURN_LONG(0));
|
||||
if (NIL_P (size))
|
||||
API_WRONG_ARGS(API_RETURN_LONG(0));
|
||||
|
||||
Check_Type (size, T_STRING);
|
||||
|
||||
c_size = StringValuePtr (size);
|
||||
|
||||
value = weechat_string_parse_size (c_size);
|
||||
|
||||
API_RETURN_LONG(value);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
weechat_ruby_api_string_color_code_size (VALUE class, VALUE string)
|
||||
{
|
||||
@@ -6562,6 +6581,7 @@ weechat_ruby_api_init (VALUE ruby_mWeechat)
|
||||
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_parse_size, 1);
|
||||
API_DEF_FUNC(string_color_code_size, 1);
|
||||
API_DEF_FUNC(string_remove_color, 2);
|
||||
API_DEF_FUNC(string_is_command_char, 1);
|
||||
|
||||
@@ -538,6 +538,24 @@ API_FUNC(string_format_size)
|
||||
API_RETURN_STRING_FREE(result);
|
||||
}
|
||||
|
||||
API_FUNC(string_parse_size)
|
||||
{
|
||||
Tcl_Obj *objp;
|
||||
char *size;
|
||||
unsigned long long value;
|
||||
int i;
|
||||
|
||||
API_INIT_FUNC(1, "string_parse_size", API_RETURN_LONG(0));
|
||||
if (objc < 2)
|
||||
API_WRONG_ARGS(API_RETURN_LONG(0));
|
||||
|
||||
size = Tcl_GetStringFromObj (objv[1], &i);
|
||||
|
||||
value = weechat_string_parse_size (size);
|
||||
|
||||
API_RETURN_LONG(value);
|
||||
}
|
||||
|
||||
API_FUNC(string_color_code_size)
|
||||
{
|
||||
Tcl_Obj *objp;
|
||||
@@ -5867,6 +5885,7 @@ void weechat_tcl_api_init (Tcl_Interp *interp)
|
||||
API_DEF_FUNC(string_has_highlight_regex);
|
||||
API_DEF_FUNC(string_mask_to_regex);
|
||||
API_DEF_FUNC(string_format_size);
|
||||
API_DEF_FUNC(string_parse_size);
|
||||
API_DEF_FUNC(string_color_code_size);
|
||||
API_DEF_FUNC(string_remove_color);
|
||||
API_DEF_FUNC(string_is_command_char);
|
||||
|
||||
@@ -68,7 +68,7 @@ struct timeval;
|
||||
* please change the date with current one; for a second change at same
|
||||
* date, increment the 01, otherwise please keep 01.
|
||||
*/
|
||||
#define WEECHAT_PLUGIN_API_VERSION "20220816-01"
|
||||
#define WEECHAT_PLUGIN_API_VERSION "20220925-01"
|
||||
|
||||
/* macros for defining plugin infos */
|
||||
#define WEECHAT_PLUGIN_NAME(__name) \
|
||||
@@ -338,6 +338,7 @@ struct t_weechat_plugin
|
||||
char **(*string_split_command) (const char *command, char separator);
|
||||
void (*string_free_split_command) (char **split_command);
|
||||
char *(*string_format_size) (unsigned long long size);
|
||||
unsigned long long (*string_parse_size) (const char *size);
|
||||
int (*string_color_code_size) (const char *string);
|
||||
char *(*string_remove_color) (const char *string, const char *replacement);
|
||||
int (*string_base_encode) (int base, const char *from, int length,
|
||||
@@ -1302,6 +1303,8 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin);
|
||||
(weechat_plugin->string_free_split_command)(__split_command)
|
||||
#define weechat_string_format_size(__size) \
|
||||
(weechat_plugin->string_format_size)(__size)
|
||||
#define weechat_string_parse_size(__size) \
|
||||
(weechat_plugin->string_parse_size)(__size)
|
||||
#define weechat_string_color_code_size(__string) \
|
||||
(weechat_plugin->string_color_code_size)(__string)
|
||||
#define weechat_string_remove_color(__string, __replacement) \
|
||||
|
||||
@@ -72,6 +72,16 @@ def test_strings():
|
||||
check(weechat.string_format_size(1) == '1 byte')
|
||||
check(weechat.string_format_size(2097152) == '2.10 MB')
|
||||
check(weechat.string_format_size(420000000) == '420.00 MB')
|
||||
check(weechat.string_parse_size('') == 0)
|
||||
check(weechat.string_parse_size('*') == 0)
|
||||
check(weechat.string_parse_size('z') == 0)
|
||||
check(weechat.string_parse_size('1ba') == 0)
|
||||
check(weechat.string_parse_size('1') == 1)
|
||||
check(weechat.string_parse_size('12b') == 12)
|
||||
check(weechat.string_parse_size('123 b') == 123)
|
||||
check(weechat.string_parse_size('1.34k') == 1340)
|
||||
check(weechat.string_parse_size('1.5m') == 1500000)
|
||||
check(weechat.string_parse_size('2.1g') == 2100000000)
|
||||
check(weechat.string_color_code_size('') == 0)
|
||||
check(weechat.string_color_code_size('test') == 0)
|
||||
str_color = weechat.color('yellow,red')
|
||||
|
||||
@@ -1905,6 +1905,84 @@ TEST(CoreString, FormatSize)
|
||||
WEE_FORMAT_SIZE("42.00 TB", 42 * ONE_TB);
|
||||
}
|
||||
|
||||
/*
|
||||
* Tests functions:
|
||||
* string_parse_size
|
||||
*/
|
||||
|
||||
TEST(CoreString, ParseSize)
|
||||
{
|
||||
CHECK(string_parse_size (NULL) == 0ULL);
|
||||
|
||||
CHECK(string_parse_size ("") == 0ULL);
|
||||
CHECK(string_parse_size ("*") == 0ULL);
|
||||
CHECK(string_parse_size ("b") == 0ULL);
|
||||
CHECK(string_parse_size ("k") == 0ULL);
|
||||
CHECK(string_parse_size ("m") == 0ULL);
|
||||
CHECK(string_parse_size ("g") == 0ULL);
|
||||
CHECK(string_parse_size ("t") == 0ULL);
|
||||
CHECK(string_parse_size ("z") == 0ULL);
|
||||
CHECK(string_parse_size ("0z") == 0ULL);
|
||||
|
||||
CHECK(string_parse_size ("0") == 0ULL);
|
||||
CHECK(string_parse_size ("0b") == 0ULL);
|
||||
CHECK(string_parse_size ("0B") == 0ULL);
|
||||
|
||||
CHECK(string_parse_size ("1") == 1ULL);
|
||||
CHECK(string_parse_size ("1b") == 1ULL);
|
||||
CHECK(string_parse_size ("1B") == 1ULL);
|
||||
CHECK(string_parse_size ("1 b") == 1ULL);
|
||||
CHECK(string_parse_size ("1 B") == 1ULL);
|
||||
|
||||
CHECK(string_parse_size ("2") == 2ULL);
|
||||
CHECK(string_parse_size ("2b") == 2ULL);
|
||||
CHECK(string_parse_size ("2B") == 2ULL);
|
||||
|
||||
CHECK(string_parse_size ("42") == 42ULL);
|
||||
CHECK(string_parse_size ("42b") == 42ULL);
|
||||
CHECK(string_parse_size ("42B") == 42ULL);
|
||||
|
||||
/* decimals ignored for bytes */
|
||||
CHECK(string_parse_size ("42.9") == 42ULL);
|
||||
CHECK(string_parse_size ("42.9b") == 42ULL);
|
||||
CHECK(string_parse_size ("42.9B") == 42ULL);
|
||||
|
||||
CHECK(string_parse_size ("999") == 999ULL);
|
||||
CHECK(string_parse_size ("999b") == 999ULL);
|
||||
CHECK(string_parse_size ("999B") == 999ULL);
|
||||
|
||||
CHECK(string_parse_size ("1200") == 1200ULL);
|
||||
CHECK(string_parse_size ("1200b") == 1200ULL);
|
||||
CHECK(string_parse_size ("1200B") == 1200ULL);
|
||||
|
||||
CHECK(string_parse_size ("1k") == 1000ULL);
|
||||
CHECK(string_parse_size ("1K") == 1000ULL);
|
||||
|
||||
CHECK(string_parse_size ("1.34k") == 1340ULL);
|
||||
CHECK(string_parse_size ("1.34K") == 1340ULL);
|
||||
|
||||
CHECK(string_parse_size ("14.08k") == 14080ULL);
|
||||
CHECK(string_parse_size ("14.08K") == 14080ULL);
|
||||
|
||||
CHECK(string_parse_size ("1m") == 1000000ULL);
|
||||
CHECK(string_parse_size ("1M") == 1000000ULL);
|
||||
|
||||
CHECK(string_parse_size ("1.5m") == 1500000ULL);
|
||||
CHECK(string_parse_size ("1.5M") == 1500000ULL);
|
||||
|
||||
CHECK(string_parse_size ("1g") == 1000000000ULL);
|
||||
CHECK(string_parse_size ("1G") == 1000000000ULL);
|
||||
|
||||
CHECK(string_parse_size ("1.2345g") == 1234500000ULL);
|
||||
CHECK(string_parse_size ("1.2345G") == 1234500000ULL);
|
||||
|
||||
CHECK(string_parse_size ("1t") == 1000000000000ULL);
|
||||
CHECK(string_parse_size ("1T") == 1000000000000ULL);
|
||||
|
||||
CHECK(string_parse_size ("1.23456789t") == 1234567890000ULL);
|
||||
CHECK(string_parse_size ("1.23456789T") == 1234567890000ULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Tests functions:
|
||||
* string_base16_encode
|
||||
|
||||
Reference in New Issue
Block a user