1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-02 07:46:38 +02:00

api: add function "asprintf"

This commit is contained in:
Sébastien Helleu
2024-04-02 19:32:13 +02:00
parent 08bc6404eb
commit 2cf66de423
10 changed files with 360 additions and 2 deletions
+49
View File
@@ -537,6 +537,55 @@ num_files = 2
str = weechat.ngettext("file", "files", num_files)
----
==== asprintf
_WeeChat ≥ 4.3.0._
Format a message in a string allocated by the function.
[NOTE]
This function is defined for systems where the GNU function `asprintf()`
is not available. +
The behavior is almost the same except that `*result` is set to NULL on error.
Prototype:
[source,c]
----
int weechat_asprintf (char **result, const char *fmt, ...);
----
Arguments:
* _result_: pointer to a string pointer
* _fmt_: format string
Return value:
* number of bytes written in `*result` (excluding the final null byte),
a negative value in case of error.
C example:
[source,c]
----
char *str;
if (weechat_asprintf (&str, "%s, %d", "test", 42) >= 0)
{
/* *str == "test, 42" */
/* ... */
free (str);
}
else
{
/* error: *str == NULL */
}
----
[NOTE]
This function is not available in scripting API.
==== strndup
Return duplicated string, with a max number of bytes.
+50
View File
@@ -547,6 +547,56 @@ num_files = 2
str = weechat.ngettext("file", "files", num_files)
----
==== asprintf
_WeeChat ≥ 4.3.0._
Formater un message dans une chaîne allouée par la fonction.
[NOTE]
Cette fonction est définie pour les systèmes où la fonction GNU `asprintf()`
n'est pas disponible. +
Le comportement est quasiment le même à l'exception de `*result` qui est mis à
NULL en cas d'erreur.
Prototype :
[source,c]
----
int weechat_asprintf (char **result, const char *fmt, ...);
----
Paramètres :
* _result_ : pointeur vers un pointeur de chaîne
* _fmt_ : chaîne de formatage
Valeur de retour :
* nombre d'octets écrits dans `*result` (en excluant le caractère nul de fin),
une valeur négative en cas d'erreur.
Exemple en C :
[source,c]
----
char *str;
if (weechat_asprintf (&str, "%s, %d", "test", 42) >= 0)
{
/* *str == "test, 42" */
/* ... */
free (str);
}
else
{
/* erreur : *str == NULL */
}
----
[NOTE]
Cette fonction n'est pas disponible dans l'API script.
==== strndup
Retourner la chaîne dupliquée, avec un nombre maximum d'octets.
+54
View File
@@ -568,6 +568,60 @@ num_files = 2
str = weechat.ngettext("file", "files", num_files)
----
==== asprintf
_WeeChat ≥ 4.3.0._
// TRANSLATION MISSING
Format a message in a string allocated by the function.
// TRANSLATION MISSING
[NOTE]
This function is defined for systems where the GNU function `asprintf()`
is not available. +
The behavior is almost the same except that `*result` is set to NULL on error.
Prototipo:
[source,c]
----
int weechat_asprintf (char **result, const char *fmt, ...);
----
Argomenti:
// TRANSLATION MISSING
* _result_: pointer to a string pointer
// TRANSLATION MISSING
* _fmt_: format string
Valore restituito:
// TRANSLATION MISSING
* number of bytes written in `*result` (excluding the final null byte),
a negative value in case of error.
Esempio in C:
[source,c]
----
char *str;
if (weechat_asprintf (&str, "%s, %d", "test", 42) >= 0)
{
/* *str == "test, 42" */
/* ... */
free (str);
}
else
{
/* error: *str == NULL */
}
----
[NOTE]
Questa funzione non è disponibile nelle API per lo scripting.
==== strndup
// TRANSLATION MISSING
+54
View File
@@ -547,6 +547,60 @@ num_files = 2
str = weechat.ngettext("file", "files", num_files)
----
==== asprintf
_WeeChat ≥ 4.3.0._
// TRANSLATION MISSING
Format a message in a string allocated by the function.
// TRANSLATION MISSING
[NOTE]
This function is defined for systems where the GNU function `asprintf()`
is not available. +
The behavior is almost the same except that `*result` is set to NULL on error.
プロトタイプ:
[source,c]
----
int weechat_asprintf (char **result, const char *fmt, ...);
----
引数:
// TRANSLATION MISSING
* _result_: pointer to a string pointer
// TRANSLATION MISSING
* _fmt_: format string
戻り値:
// TRANSLATION MISSING
* number of bytes written in `*result` (excluding the final null byte),
a negative value in case of error.
C 言語での使用例:
[source,c]
----
char *str;
if (weechat_asprintf (&str, "%s, %d", "test", 42) >= 0)
{
/* *str == "test, 42" */
/* ... */
free (str);
}
else
{
/* error: *str == NULL */
}
----
[NOTE]
スクリプト API ではこの関数を利用できません。
==== strndup
// TRANSLATION MISSING
+54
View File
@@ -512,6 +512,60 @@ num_files = 2
str = weechat.ngettext("file", "files", num_files)
----
==== asprintf
_WeeChat ≥ 4.3.0._
// TRANSLATION MISSING
Format a message in a string allocated by the function.
// TRANSLATION MISSING
[NOTE]
This function is defined for systems where the GNU function `asprintf()`
is not available. +
The behavior is almost the same except that `*result` is set to NULL on error.
Прототип:
[source,c]
----
int weechat_asprintf (char **result, const char *fmt, ...);
----
Аргументи:
// TRANSLATION MISSING
* _result_: pointer to a string pointer
// TRANSLATION MISSING
* _fmt_: format string
Повратна вредност:
// TRANSLATION MISSING
* number of bytes written in `*result` (excluding the final null byte),
a negative value in case of error.
C пример:
[source,c]
----
char *str;
if (weechat_asprintf (&str, "%s, %d", "test", 42) >= 0)
{
/* *str == "test, 42" */
/* ... */
free (str);
}
else
{
/* error: *str == NULL */
}
----
[NOTE]
Ова функција није доступна у API скриптовања.
==== strndup
Враћа дуплирани стринг, са максималним бројем бајтова.