source:
protocols/oscar/oscar_util.c
@
eb73d05
Last change on this file since eb73d05 was 5ebff60, checked in by , at 2015-02-20T22:50:54Z | |
---|---|
|
|
File size: 1.3 KB |
Rev | Line | |
---|---|---|
[b7d3cc34] | 1 | #include <aim.h> |
2 | #include <ctype.h> | |
3 | ||
4 | /* | |
5 | * int snlen(const char *) | |
[5ebff60] | 6 | * |
[b7d3cc34] | 7 | * This takes a screen name and returns its length without |
[5ebff60] | 8 | * spaces. If there are no spaces in the SN, then the |
[b7d3cc34] | 9 | * return is equal to that of strlen(). |
10 | * | |
11 | */ | |
12 | static int aim_snlen(const char *sn) | |
13 | { | |
14 | int i = 0; | |
15 | const char *curPtr = NULL; | |
16 | ||
[5ebff60] | 17 | if (!sn) { |
[b7d3cc34] | 18 | return 0; |
[5ebff60] | 19 | } |
[b7d3cc34] | 20 | |
21 | curPtr = sn; | |
[5ebff60] | 22 | while ((*curPtr) != (char) '\0') { |
23 | if ((*curPtr) != ' ') { | |
24 | i++; | |
25 | } | |
[b7d3cc34] | 26 | curPtr++; |
27 | } | |
28 | ||
29 | return i; | |
30 | } | |
31 | ||
32 | /* | |
33 | * int sncmp(const char *, const char *) | |
34 | * | |
35 | * This takes two screen names and compares them using the rules | |
36 | * on screen names for AIM/AOL. Mainly, this means case and space | |
37 | * insensitivity (all case differences and spacing differences are | |
38 | * ignored). | |
39 | * | |
40 | * Return: 0 if equal | |
41 | * non-0 if different | |
42 | * | |
43 | */ | |
44 | ||
45 | int aim_sncmp(const char *sn1, const char *sn2) | |
46 | { | |
47 | const char *curPtr1 = NULL, *curPtr2 = NULL; | |
48 | ||
[5ebff60] | 49 | if (aim_snlen(sn1) != aim_snlen(sn2)) { |
[b7d3cc34] | 50 | return 1; |
[5ebff60] | 51 | } |
[b7d3cc34] | 52 | |
53 | curPtr1 = sn1; | |
54 | curPtr2 = sn2; | |
[5ebff60] | 55 | while ((*curPtr1 != (char) '\0') && (*curPtr2 != (char) '\0')) { |
56 | if ((*curPtr1 == ' ') || (*curPtr2 == ' ')) { | |
57 | if (*curPtr1 == ' ') { | |
[b7d3cc34] | 58 | curPtr1++; |
[5ebff60] | 59 | } |
60 | if (*curPtr2 == ' ') { | |
[b7d3cc34] | 61 | curPtr2++; |
[5ebff60] | 62 | } |
[b7d3cc34] | 63 | } else { |
[5ebff60] | 64 | if (g_ascii_toupper(*curPtr1) != g_ascii_toupper(*curPtr2)) { |
[b7d3cc34] | 65 | return 1; |
[5ebff60] | 66 | } |
[b7d3cc34] | 67 | curPtr1++; |
68 | curPtr2++; | |
69 | } | |
70 | } | |
71 | ||
72 | /* Should both be NULL */ | |
[5ebff60] | 73 | if (*curPtr1 != *curPtr2) { |
[b7d3cc34] | 74 | return 1; |
[5ebff60] | 75 | } |
[b7d3cc34] | 76 | |
77 | return 0; | |
78 | } |
Note: See TracBrowser
for help on using the repository browser.