1
0
mirror of https://github.com/Tha14/toxic.git synced 2025-06-30 08:26:45 +02:00

add valid nick function

This commit is contained in:
Jfreegman
2013-11-28 02:53:43 -05:00
parent 7ca087b5e7
commit a04c8964ee
4 changed files with 32 additions and 7 deletions

View File

@ -117,14 +117,14 @@ void alert_window(ToxWindow *self)
/* case-insensitive string compare function for use with qsort - same return logic as strcmp */
int name_compare(const void *nick1, const void *nick2)
{
char s[strlen((const char *) nick1) + 1];
char t[strlen((const char *) nick2) + 1];
char s[TOX_MAX_NAME_LENGTH];
char t[TOX_MAX_NAME_LENGTH];
strcpy(s, (const char *) nick1);
strcpy(t, (const char *) nick2);
int i;
for (i = 0; s[i] != '\0' && t[i] != '\0'; ++i) {
for (i = 0; s[i] && t[i]; ++i) {
s[i] = tolower(s[i]);
t[i] = tolower(t[i]);
@ -134,3 +134,22 @@ int name_compare(const void *nick1, const void *nick2)
return s[i] - t[i];
}
/* Returns true if nick is valid. A valid toxic nick:
- cannot be empty
- cannot start with a space
- must not contain contiguous spaces */
bool valid_nick(uint8_t *nick)
{
if (!nick[0] || nick[0] == ' ')
return false;
int i;
for (i = 0; nick[i]; ++i) {
if (nick[i] == ' ' && nick[i+1] == ' ')
return false;
}
return true;
}