source: protocols/oscar/oscar_util.c @ 509cf60

Last change on this file since 509cf60 was 6042a54, checked in by Wilmer van der Gaast <wilmer@…>, at 2012-10-19T23:38:33Z

Massive cleanup in OSCAR.

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