Add inv_strpbrk() function and convert equivalent sindex() calls

inv_strpbrk() is the inverse of the standard function strpbrk().

Calls to sindex() where both strings are not NULL and the second string begins with ^ are equivalent
to calls to inv_strpbrk() (but without the ^).  Convert those calls.
This commit is contained in:
Kevin Easton
2017-11-17 17:19:07 +11:00
parent 8c7d9334dd
commit 0d5698d41b
3 changed files with 26 additions and 17 deletions

View File

@@ -3526,7 +3526,7 @@ BUILT_IN_COMMAND(untopic)
ChannelList *chan;
int server;
args = sindex(args, "^ ");
args = inv_strpbrk(args, " ");
if (is_channel(args))
channel = next_arg(args, &args);
@@ -3543,12 +3543,12 @@ BUILT_IN_COMMAND(e_topic)
ChannelList *chan;
int server;
args = sindex(args, "^ ");
args = inv_strpbrk(args, " ");
if (is_channel(args))
{
channel = next_arg(args, &args);
args = sindex(args, "^ ");
args = inv_strpbrk(args, " ");
}
if (!(chan = prepare_command(&server, channel, args ? PC_TOPIC : NO_OP)))

View File

@@ -467,7 +467,7 @@ char *BX_next_arg(char *str, char **new_ptr)
if (!str)
return NULL;
if ((ptr = sindex(str, "^ ")) != NULL)
if ((ptr = inv_strpbrk(str, " ")) != NULL)
{
if ((str = strchr(ptr, ' ')) != NULL)
*str++ = 0;
@@ -614,7 +614,7 @@ char *safe_new_next_arg (char *str, char **new_ptr)
if (!str || !*str)
return empty_string;
if ((ptr = sindex(str, "^ \t")) != NULL)
if ((ptr = inv_strpbrk(str, " \t")) != NULL)
{
if (*ptr == '"')
{
@@ -666,7 +666,7 @@ char *BX_new_new_next_arg (char *str, char **new_ptr, char *type)
if (!str || !*str)
return NULL;
if ((ptr = sindex(str, "^ \t")) != NULL)
if ((ptr = inv_strpbrk(str, " \t")) != NULL)
{
if ((*ptr == '"') || (*ptr == '\''))
{
@@ -1066,6 +1066,23 @@ char *BX_check_nickname (char *nick)
return *nick ? nick : NULL;
}
/* inv_strcpbrk()
*
* Returns a pointer to the first character in a string which is NOT found
* in 'reject'.
*
* This is the inverse of the standard function strpbrk().
*/
char *inv_strpbrk(const char *s, const char *reject)
{
s += strspn(s, reject);
if (!*s)
return NULL;
return (char *)s;
}
/* sindex()
*
* Returns a pointer to the first matching character in a string, or NULL if
@@ -1081,18 +1098,9 @@ char *BX_sindex(const char *string, const char *group)
return NULL;
if (*group == '^')
{
string += strspn(string, group + 1);
}
return inv_strpbrk(string, group + 1);
else
{
string += strcspn(string, group);
}
if (*string)
return (char *)string;
else
return NULL;
return strpbrk(string, group);
}
/* rsindex()