-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
txt.c
62 lines (47 loc) · 919 Bytes
/
txt.c
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
/*
* Copyright 2019 Katherine Flavel
*
* See LICENCE for the full copyright terms.
*/
#include <assert.h>
#include <stddef.h>
#include <ctype.h>
#include "txt.h"
int
txtcasecmp(const struct txt *t1, const struct txt *t2)
{
size_t i;
assert(t1 != NULL);
assert(t2 != NULL);
if (t1->n < t2->n) {
return -1;
}
if (t1->n > t2->n) {
return +1;
}
for (i = 0; i < t1->n; i++) {
if (tolower((unsigned char) t1->p[i]) != tolower((unsigned char) t2->p[i])) {
return (int) (unsigned char) t1->p[i] - (int) (unsigned char) t2->p[i];
}
}
return 0;
}
int
txtcmp(const struct txt *t1, const struct txt *t2)
{
size_t i;
assert(t1 != NULL);
assert(t2 != NULL);
if (t1->n < t2->n) {
return -1;
}
if (t1->n > t2->n) {
return +1;
}
for (i = 0; i < t1->n; i++) {
if (t1->p[i] != t2->p[i]) {
return (int) (unsigned char) t1->p[i] - (int) (unsigned char) t2->p[i];
}
}
return 0;
}