mirror of
https://github.com/weechat/weechat.git
synced 2026-06-12 14:14:48 +02:00
core: use function util_parse_int in function string_get_priority_and_name
This commit is contained in:
@@ -55,6 +55,7 @@
|
||||
#include "core-eval.h"
|
||||
#include "core-hashtable.h"
|
||||
#include "core-utf8.h"
|
||||
#include "core-util.h"
|
||||
#include "../gui/gui-chat.h"
|
||||
#include "../gui/gui-color.h"
|
||||
#include "../plugins/plugin.h"
|
||||
@@ -4439,8 +4440,8 @@ string_get_priority_and_name (const char *string,
|
||||
int *priority, const char **name,
|
||||
int default_priority)
|
||||
{
|
||||
char *pos, *str_priority, *error;
|
||||
long number;
|
||||
char *pos, *str_priority;
|
||||
int number;
|
||||
|
||||
if (priority)
|
||||
*priority = default_priority;
|
||||
@@ -4456,17 +4457,15 @@ string_get_priority_and_name (const char *string,
|
||||
str_priority = string_strndup (string, pos - string);
|
||||
if (str_priority)
|
||||
{
|
||||
error = NULL;
|
||||
number = strtol (str_priority, &error, 10);
|
||||
if (error && !error[0])
|
||||
if (util_parse_int (str_priority, 10, &number))
|
||||
{
|
||||
if (priority)
|
||||
*priority = number;
|
||||
if (name)
|
||||
*name = pos + 1;
|
||||
}
|
||||
free (str_priority);
|
||||
}
|
||||
if (name)
|
||||
*name = pos + 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2971,11 +2971,11 @@ TEST(CoreString, GetPriorityAndName)
|
||||
LONGS_EQUAL(500, priority);
|
||||
STRCMP_EQUAL("", ptr_name);
|
||||
|
||||
/* "|" => (0, "") */
|
||||
/* "|" => (default_priority, "") */
|
||||
priority = -1;
|
||||
ptr_name = NULL;
|
||||
string_get_priority_and_name (delimiter, &priority, &ptr_name, 500);
|
||||
LONGS_EQUAL(0, priority);
|
||||
LONGS_EQUAL(500, priority);
|
||||
STRCMP_EQUAL("", ptr_name);
|
||||
|
||||
/* "test" => (default_priority, "test") */
|
||||
@@ -2985,11 +2985,11 @@ TEST(CoreString, GetPriorityAndName)
|
||||
LONGS_EQUAL(500, priority);
|
||||
STRCMP_EQUAL("test", ptr_name);
|
||||
|
||||
/* "|test" => (0, "test") */
|
||||
/* "|test" => (default_priority, "test") */
|
||||
priority = -1;
|
||||
ptr_name = NULL;
|
||||
string_get_priority_and_name (name_prio_empty, &priority, &ptr_name, 500);
|
||||
LONGS_EQUAL(0, priority);
|
||||
LONGS_EQUAL(500, priority);
|
||||
STRCMP_EQUAL("test", ptr_name);
|
||||
|
||||
/* "1234|test" => (1234, "test") */
|
||||
|
||||
Reference in New Issue
Block a user