1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-04 16:53:14 +02:00

core: add reverse of string in evaluation of expressions with "rev:" (closes #1200)

This commit is contained in:
Sébastien Helleu
2018-06-02 15:48:31 +02:00
parent ab9a0ec2e6
commit 1abf4040f1
30 changed files with 425 additions and 295 deletions
+40
View File
@@ -162,6 +162,46 @@ string_cut (const char *string, int length, int count_suffix, int screen,
}
}
/*
* Reverses a string.
*
* Note: result must be freed after use.
*/
char *
string_reverse (const char *string)
{
int length, char_size;
const char *ptr_string;
char *result, *ptr_result;
if (!string)
return NULL;
if (!string[0])
return strdup (string);
length = strlen (string);
result = malloc (length + 1);
if (!result)
return NULL;
ptr_string = string;
ptr_result = result + length;
ptr_result[0] = '\0';
while (ptr_string && ptr_string[0])
{
char_size = utf8_char_size (ptr_string);
ptr_result -= char_size;
memcpy (ptr_result, ptr_string, char_size);
ptr_string += char_size;
}
return result;
}
/*
* Converts string to lower case (locale independent).
*/