equal
deleted
inserted
replaced
|
1 #include "irc_nm.h" |
|
2 |
|
3 #include <string.h> |
|
4 |
|
5 /** |
|
6 * Compare two nicknames |
|
7 */ |
|
8 int irc_cmp_nick (const char *nick1, const char *nick2) |
|
9 { |
|
10 // XXX: just use strcasecmp for now |
|
11 return strcasecmp(nick1, nick2); |
|
12 } |
|
13 |
|
14 int irc_ncmp_nick (const char *nick1, const char *nick2, size_t n) |
|
15 { |
|
16 // XXX: just use strncasecmp for now |
|
17 return strncasecmp(nick1, nick2, n); |
|
18 } |
|
19 |
|
20 err_t irc_prefix_parse_nick (const char *prefix, char nick[IRC_NICK_MAX]) |
|
21 { |
|
22 const char *bang; |
|
23 |
|
24 // find the ! |
|
25 if ((bang = strchr(prefix, '!')) == NULL) |
|
26 return ERR_INVALID_NM; |
|
27 |
|
28 // too long? |
|
29 if (bang - prefix > IRC_NICK_MAX - 1) |
|
30 return ERR_INVALID_NICK_LENGTH; |
|
31 |
|
32 // copy up to the ! |
|
33 memcpy(nick, prefix, bang - prefix); |
|
34 |
|
35 // terminating NUL |
|
36 nick[bang - prefix] = '\0'; |
|
37 |
|
38 // ok |
|
39 return SUCCESS; |
|
40 } |
|
41 |
|
42 int irc_prefix_cmp_nick (const char *prefix, const char *nick) |
|
43 { |
|
44 const char *bang; |
|
45 |
|
46 // find the ! |
|
47 if ((bang = strchr(prefix, '!')) == NULL) |
|
48 return -ERR_INVALID_NM; |
|
49 |
|
50 // compare up to that |
|
51 if (irc_ncmp_nick(prefix, nick, (bang - prefix)) == 0) |
|
52 // match |
|
53 return 0; |
|
54 |
|
55 else |
|
56 // doesn't match |
|
57 return 1; |
|
58 } |