summaryrefslogtreecommitdiff
path: root/src/message.cpp
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-01-26 10:36:44 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-01-26 10:36:44 +0000
commit3e3e46bc0865164c7a0d54983ecf3ae6d6bf1ace (patch)
tree1da1c68e48c0a8681da515b4db055f154e36306c /src/message.cpp
parentaf8307b9c325dc8a1bbd39b9cb3e4f53f1c54beb (diff)
Merged Andy Church's isnick() and isident() patches - faster, more efficient, and doesnt accidentally allow "-" as the first character of a nickname
Also adapted to iterate over a char* pointer rather than using unsigned int for the for() loops git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@2913 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/message.cpp')
-rw-r--r--src/message.cpp38
1 files changed, 16 insertions, 22 deletions
diff --git a/src/message.cpp b/src/message.cpp
index 0194133da..eb95bde56 100644
--- a/src/message.cpp
+++ b/src/message.cpp
@@ -243,17 +243,17 @@ int isident(const char* n)
{
return 0;
}
- for (unsigned int i = 0; i < strlen(n); i++)
+ for (char* i = n; *i; i++)
{
- if ((n[i] < 33) || (n[i] > 125))
+ if ((*i >= 'A') && (*i <= '}'))
{
- return 0;
+ continue;
}
- /* can't occur ANYWHERE in an Ident! */
- if (strchr("<>,/?:;@'~#=+()*&%$£ \"!",n[i]))
+ if (strchr(".-0123456789",*i))
{
- return 0;
+ continue;
}
+ return 0;
}
return 1;
}
@@ -261,11 +261,7 @@ int isident(const char* n)
int isnick(const char* n)
{
- if (!n)
- {
- return 0;
- }
- if (!strcmp(n,""))
+ if (!n || !*n)
{
return 0;
}
@@ -273,22 +269,20 @@ int isnick(const char* n)
{
return 0;
}
- for (unsigned int i = 0; i != strlen(n); i++)
+ for (char* i = n; *i; i++)
{
- if ((n[i] < 33) || (n[i] > 125))
+ /* can occur anywhere in a nickname */
+ if ((*i >= 'A') && (*i <= '}'))
{
- return 0;
+ continue;
}
- /* can't occur ANYWHERE in a nickname! */
- if (strchr("<>,./?:;@'~#=+()*&%$£ \"!",n[i]))
+ /* can occur anywhere BUT the first char of a nickname */
+ if ((strchr("-0123456789",*i)) && (i > n))
{
- return 0;
- }
- /* can't occur as the first char of a nickname... */
- if ((strchr("0123456789",n[i])) && (!i))
- {
- return 0;
+ continue;
}
+ /* invalid character! abort */
+ return 0;
}
return 1;
}