Menu

[r1401]: / advanced / lib / util / stripcaseeq.c  Maximize  Restore  History

Download this file

70 lines (54 with data), 1.6 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#define _GNU_SOURCE
#include <ctype.h>
#include "bool.h"
#include "girstring.h"
bool
stripcaseeq(const char * const comparand,
const char * const comparator) {
/*----------------------------------------------------------------------------
Compare two strings, ignoring leading and trailing blanks and case.
Return true if the strings are identical, false otherwise.
-----------------------------------------------------------------------------*/
const char *p, *q, *px, *qx;
bool equal;
/* Make p and q point to the first non-blank character in each string.
If there are no non-blank characters, make them point to the terminating
NULL.
*/
p = &comparand[0];
while (*p == ' ')
++p;
q = &comparator[0];
while (*q == ' ')
++q;
/* Make px and qx point to the last non-blank character in each string.
If there are no nonblank characters (which implies the string is
null), make them point to the terminating NULL.
*/
if (*p == '\0')
px = p;
else {
px = p + strlen(p) - 1;
while (*px == ' ')
--px;
}
if (*q == '\0')
qx = q;
else {
qx = q + strlen(q) - 1;
while (*qx == ' ')
--qx;
}
equal = true; /* initial assumption */
/* If the stripped strings aren't the same length,
we know they aren't equal
*/
if (px - p != qx - q)
equal = false;
while (p <= px) {
if (toupper(*p) != toupper(*q))
equal = false;
++p; ++q;
}
return equal;
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.