core: move function string_replace before string_replace_regex
parent
7aba5f713f
commit
360f900d92
|
@ -854,41 +854,6 @@ match3 = weechat.string_match("abcdef", "*def", 0) # 1
|
|||
match4 = weechat.string_match("abcdef", "*de*", 0) # 1
|
||||
----
|
||||
|
||||
==== weechat_string_replace
|
||||
|
||||
Replace all occurrences of a string by another string.
|
||||
|
||||
Prototype:
|
||||
|
||||
[source,C]
|
||||
----
|
||||
char *weechat_string_replace (const char *string, const char *search,
|
||||
const char *replace);
|
||||
----
|
||||
|
||||
Arguments:
|
||||
|
||||
* 'string': string
|
||||
* 'search': string to replace
|
||||
* 'replace': replacement for string 'search'
|
||||
|
||||
Return value:
|
||||
|
||||
* string with 'search' replaced by 'replace' (must be freed by calling "free"
|
||||
after use)
|
||||
|
||||
C example:
|
||||
|
||||
[source,C]
|
||||
----
|
||||
char *str = weechat_string_replace ("test", "s", "x"); /* result: "text" */
|
||||
/* ... */
|
||||
free (str);
|
||||
----
|
||||
|
||||
[NOTE]
|
||||
This function is not available in scripting API.
|
||||
|
||||
==== weechat_string_expand_home
|
||||
|
||||
_WeeChat ≥ 0.3.3._
|
||||
|
@ -1264,6 +1229,41 @@ highlight = weechat.string_has_highlight_regex(string, regex)
|
|||
highlight = weechat.string_has_highlight_regex("my test string", "test|word2") # 1
|
||||
----
|
||||
|
||||
==== weechat_string_replace
|
||||
|
||||
Replace all occurrences of a string by another string.
|
||||
|
||||
Prototype:
|
||||
|
||||
[source,C]
|
||||
----
|
||||
char *weechat_string_replace (const char *string, const char *search,
|
||||
const char *replace);
|
||||
----
|
||||
|
||||
Arguments:
|
||||
|
||||
* 'string': string
|
||||
* 'search': string to replace
|
||||
* 'replace': replacement for string 'search'
|
||||
|
||||
Return value:
|
||||
|
||||
* string with 'search' replaced by 'replace' (must be freed by calling "free"
|
||||
after use)
|
||||
|
||||
C example:
|
||||
|
||||
[source,C]
|
||||
----
|
||||
char *str = weechat_string_replace ("test", "s", "x"); /* result: "text" */
|
||||
/* ... */
|
||||
free (str);
|
||||
----
|
||||
|
||||
[NOTE]
|
||||
This function is not available in scripting API.
|
||||
|
||||
==== weechat_string_replace_regex
|
||||
|
||||
_WeeChat ≥ 0.4.4._
|
||||
|
|
|
@ -863,41 +863,6 @@ match3 = weechat.string_match("abcdef", "*def", 0) # 1
|
|||
match4 = weechat.string_match("abcdef", "*de*", 0) # 1
|
||||
----
|
||||
|
||||
==== weechat_string_replace
|
||||
|
||||
Remplacer toutes les occurrences d'une chaîne par une autre chaîne.
|
||||
|
||||
Prototype :
|
||||
|
||||
[source,C]
|
||||
----
|
||||
char *weechat_string_replace (const char *string, const char *search,
|
||||
const char *replace);
|
||||
----
|
||||
|
||||
Paramètres :
|
||||
|
||||
* 'string' : chaîne
|
||||
* 'search' : chaîne à remplacer
|
||||
* 'replace' : remplacement pour la chaîne 'search'
|
||||
|
||||
Valeur de retour :
|
||||
|
||||
* chaîne avec 'search' remplacée par 'replace' (doit être supprimée par un appel
|
||||
à "free" après utilisation)
|
||||
|
||||
Exemple en C :
|
||||
|
||||
[source,C]
|
||||
----
|
||||
char *str = weechat_string_replace ("test, test", "s", "x"); /* résultat : "text" */
|
||||
/* ... */
|
||||
free (str);
|
||||
----
|
||||
|
||||
[NOTE]
|
||||
Cette fonction n'est pas disponible dans l'API script.
|
||||
|
||||
==== weechat_string_expand_home
|
||||
|
||||
_WeeChat ≥ 0.3.3._
|
||||
|
@ -1282,6 +1247,41 @@ highlight = weechat.string_has_highlight_regex(string, regex)
|
|||
highlight = weechat.string_has_highlight_regex("my test string", "test|word2") # 1
|
||||
----
|
||||
|
||||
==== weechat_string_replace
|
||||
|
||||
Remplacer toutes les occurrences d'une chaîne par une autre chaîne.
|
||||
|
||||
Prototype :
|
||||
|
||||
[source,C]
|
||||
----
|
||||
char *weechat_string_replace (const char *string, const char *search,
|
||||
const char *replace);
|
||||
----
|
||||
|
||||
Paramètres :
|
||||
|
||||
* 'string' : chaîne
|
||||
* 'search' : chaîne à remplacer
|
||||
* 'replace' : remplacement pour la chaîne 'search'
|
||||
|
||||
Valeur de retour :
|
||||
|
||||
* chaîne avec 'search' remplacée par 'replace' (doit être supprimée par un appel
|
||||
à "free" après utilisation)
|
||||
|
||||
Exemple en C :
|
||||
|
||||
[source,C]
|
||||
----
|
||||
char *str = weechat_string_replace ("test, test", "s", "x"); /* résultat : "text" */
|
||||
/* ... */
|
||||
free (str);
|
||||
----
|
||||
|
||||
[NOTE]
|
||||
Cette fonction n'est pas disponible dans l'API script.
|
||||
|
||||
==== weechat_string_replace_regex
|
||||
|
||||
_WeeChat ≥ 0.4.4._
|
||||
|
|
|
@ -871,41 +871,6 @@ match3 = weechat.string_match("abcdef", "*def", 0) # 1
|
|||
match4 = weechat.string_match("abcdef", "*de*", 0) # 1
|
||||
----
|
||||
|
||||
==== weechat_string_replace
|
||||
|
||||
Sostituisce tutte le ricorrenze di una stringa con un'altra.
|
||||
|
||||
Prototipo:
|
||||
|
||||
[source,C]
|
||||
----
|
||||
char *weechat_string_replace (const char *string, const char *search,
|
||||
const char *replace);
|
||||
----
|
||||
|
||||
Argomenti:
|
||||
|
||||
* 'string': stringa
|
||||
* 'search': stringa da sostituire
|
||||
* 'replace': sostituzione per la stringa 'search'
|
||||
|
||||
Valore restituito:
|
||||
|
||||
* la stringa dopo 'search' sostituita da 'replace' (deve essere liberata
|
||||
chiamando "free" dopo l'uso)
|
||||
|
||||
Esempio in C:
|
||||
|
||||
[source,C]
|
||||
----
|
||||
char *str = weechat_string_replace ("test", "s", "x"); /* result: "text" */
|
||||
/* ... */
|
||||
free (str);
|
||||
----
|
||||
|
||||
[NOTE]
|
||||
Questa funzione non è disponibile nelle API per lo scripting.
|
||||
|
||||
==== weechat_string_expand_home
|
||||
|
||||
_WeeChat ≥ 0.3.3._
|
||||
|
@ -1297,6 +1262,41 @@ highlight = weechat.string_has_highlight_regex(string, regex)
|
|||
highlight = weechat.string_has_highlight_regex("my test string", "test|word2") # 1
|
||||
----
|
||||
|
||||
==== weechat_string_replace
|
||||
|
||||
Sostituisce tutte le ricorrenze di una stringa con un'altra.
|
||||
|
||||
Prototipo:
|
||||
|
||||
[source,C]
|
||||
----
|
||||
char *weechat_string_replace (const char *string, const char *search,
|
||||
const char *replace);
|
||||
----
|
||||
|
||||
Argomenti:
|
||||
|
||||
* 'string': stringa
|
||||
* 'search': stringa da sostituire
|
||||
* 'replace': sostituzione per la stringa 'search'
|
||||
|
||||
Valore restituito:
|
||||
|
||||
* la stringa dopo 'search' sostituita da 'replace' (deve essere liberata
|
||||
chiamando "free" dopo l'uso)
|
||||
|
||||
Esempio in C:
|
||||
|
||||
[source,C]
|
||||
----
|
||||
char *str = weechat_string_replace ("test", "s", "x"); /* result: "text" */
|
||||
/* ... */
|
||||
free (str);
|
||||
----
|
||||
|
||||
[NOTE]
|
||||
Questa funzione non è disponibile nelle API per lo scripting.
|
||||
|
||||
==== weechat_string_replace_regex
|
||||
|
||||
_WeeChat ≥ 0.4.4._
|
||||
|
|
|
@ -853,41 +853,6 @@ match3 = weechat.string_match("abcdef", "*def", 0) # 1
|
|||
match4 = weechat.string_match("abcdef", "*de*", 0) # 1
|
||||
----
|
||||
|
||||
==== weechat_string_replace
|
||||
|
||||
マッチした全ての文字列を別の文字列で置換。
|
||||
|
||||
プロトタイプ:
|
||||
|
||||
[source,C]
|
||||
----
|
||||
char *weechat_string_replace (const char *string, const char *search,
|
||||
const char *replace);
|
||||
----
|
||||
|
||||
引数:
|
||||
|
||||
* 'string': 文字列
|
||||
* 'search': マッチさせる文字列
|
||||
* 'replace': 'search' を置き換える文字列
|
||||
|
||||
戻り値:
|
||||
|
||||
* 'search' を 'replace' で置き換えた文字列
|
||||
(使用後には必ず "free" を呼び出して領域を開放してください)
|
||||
|
||||
C 言語での使用例:
|
||||
|
||||
[source,C]
|
||||
----
|
||||
char *str = weechat_string_replace ("test", "s", "x"); /* result: "text" */
|
||||
/* ... */
|
||||
free (str);
|
||||
----
|
||||
|
||||
[NOTE]
|
||||
スクリプト API ではこの関数を利用できません。
|
||||
|
||||
==== weechat_string_expand_home
|
||||
|
||||
_WeeChat バージョン 0.3.3 以上で利用可。_
|
||||
|
@ -1264,6 +1229,41 @@ highlight = weechat.string_has_highlight_regex(string, regex)
|
|||
highlight = weechat.string_has_highlight_regex("my test string", "test|word2") # 1
|
||||
----
|
||||
|
||||
==== weechat_string_replace
|
||||
|
||||
マッチした全ての文字列を別の文字列で置換。
|
||||
|
||||
プロトタイプ:
|
||||
|
||||
[source,C]
|
||||
----
|
||||
char *weechat_string_replace (const char *string, const char *search,
|
||||
const char *replace);
|
||||
----
|
||||
|
||||
引数:
|
||||
|
||||
* 'string': 文字列
|
||||
* 'search': マッチさせる文字列
|
||||
* 'replace': 'search' を置き換える文字列
|
||||
|
||||
戻り値:
|
||||
|
||||
* 'search' を 'replace' で置き換えた文字列
|
||||
(使用後には必ず "free" を呼び出して領域を開放してください)
|
||||
|
||||
C 言語での使用例:
|
||||
|
||||
[source,C]
|
||||
----
|
||||
char *str = weechat_string_replace ("test", "s", "x"); /* result: "text" */
|
||||
/* ... */
|
||||
free (str);
|
||||
----
|
||||
|
||||
[NOTE]
|
||||
スクリプト API ではこの関数を利用できません。
|
||||
|
||||
==== weechat_string_replace_regex
|
||||
|
||||
_WeeChat バージョン 0.4.4 以上で利用可。_
|
||||
|
|
|
@ -448,64 +448,6 @@ string_match (const char *string, const char *mask, int case_sensitive)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Replaces a string by new one in a string.
|
||||
*
|
||||
* Note: result must be freed after use.
|
||||
*/
|
||||
|
||||
char *
|
||||
string_replace (const char *string, const char *search, const char *replace)
|
||||
{
|
||||
const char *pos;
|
||||
char *new_string;
|
||||
int length1, length2, length_new, count;
|
||||
|
||||
if (!string || !search || !replace)
|
||||
return NULL;
|
||||
|
||||
length1 = strlen (search);
|
||||
length2 = strlen (replace);
|
||||
|
||||
/* count number of strings to replace */
|
||||
count = 0;
|
||||
pos = string;
|
||||
while (pos && pos[0] && (pos = strstr (pos, search)))
|
||||
{
|
||||
count++;
|
||||
pos += length1;
|
||||
}
|
||||
|
||||
/* easy: no string to replace! */
|
||||
if (count == 0)
|
||||
return strdup (string);
|
||||
|
||||
/* compute needed memory for new string */
|
||||
length_new = strlen (string) - (count * length1) + (count * length2) + 1;
|
||||
|
||||
/* allocate new string */
|
||||
new_string = malloc (length_new);
|
||||
if (!new_string)
|
||||
return strdup (string);
|
||||
|
||||
/* replace all occurrences */
|
||||
new_string[0] = '\0';
|
||||
while (string && string[0])
|
||||
{
|
||||
pos = strstr (string, search);
|
||||
if (pos)
|
||||
{
|
||||
strncat (new_string, string, pos - string);
|
||||
strcat (new_string, replace);
|
||||
pos += length1;
|
||||
}
|
||||
else
|
||||
strcat (new_string, string);
|
||||
string = pos;
|
||||
}
|
||||
return new_string;
|
||||
}
|
||||
|
||||
/*
|
||||
* Expands home in a path.
|
||||
*
|
||||
|
@ -1144,6 +1086,64 @@ string_has_highlight_regex (const char *string, const char *regex)
|
|||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
* Replaces a string by new one in a string.
|
||||
*
|
||||
* Note: result must be freed after use.
|
||||
*/
|
||||
|
||||
char *
|
||||
string_replace (const char *string, const char *search, const char *replace)
|
||||
{
|
||||
const char *pos;
|
||||
char *new_string;
|
||||
int length1, length2, length_new, count;
|
||||
|
||||
if (!string || !search || !replace)
|
||||
return NULL;
|
||||
|
||||
length1 = strlen (search);
|
||||
length2 = strlen (replace);
|
||||
|
||||
/* count number of strings to replace */
|
||||
count = 0;
|
||||
pos = string;
|
||||
while (pos && pos[0] && (pos = strstr (pos, search)))
|
||||
{
|
||||
count++;
|
||||
pos += length1;
|
||||
}
|
||||
|
||||
/* easy: no string to replace! */
|
||||
if (count == 0)
|
||||
return strdup (string);
|
||||
|
||||
/* compute needed memory for new string */
|
||||
length_new = strlen (string) - (count * length1) + (count * length2) + 1;
|
||||
|
||||
/* allocate new string */
|
||||
new_string = malloc (length_new);
|
||||
if (!new_string)
|
||||
return strdup (string);
|
||||
|
||||
/* replace all occurrences */
|
||||
new_string[0] = '\0';
|
||||
while (string && string[0])
|
||||
{
|
||||
pos = strstr (string, search);
|
||||
if (pos)
|
||||
{
|
||||
strncat (new_string, string, pos - string);
|
||||
strcat (new_string, replace);
|
||||
pos += length1;
|
||||
}
|
||||
else
|
||||
strcat (new_string, string);
|
||||
string = pos;
|
||||
}
|
||||
return new_string;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get replacement string for a regex, using array of "match"
|
||||
* (for more info, see function "string_replace_regex").
|
||||
|
|
Loading…
Reference in New Issue