blob: 47eb8edb7cce9ca50c95397e24e451ec2d3fc281 (
plain)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
#include "case.h"
#include "str.h"
/**
@file case.c
@author djb
@brief string comparison and helper functions; case insensitive
*/
int case_diffb(register char *s,unsigned int len,register char *t)
{
register unsigned char x;
register unsigned char y;
while (len > 0) {
--len;
x = *s++ - 'A';
if (x <= 'Z' - 'A') x += 'a'; else x += 'A';
y = *t++ - 'A';
if (y <= 'Z' - 'A') y += 'a'; else y += 'A';
if (x != y)
return ((int)(unsigned int) x) - ((int)(unsigned int) y);
}
return 0;
}
int case_diffs(register char *s,register char *t)
{
register unsigned char x;
register unsigned char y;
for (;;) {
x = *s++ - 'A';
if (x <= 'Z' - 'A') x += 'a'; else x += 'A';
y = *t++ - 'A';
if (y <= 'Z' - 'A') y += 'a'; else y += 'A';
if (x != y) break;
if (!x) break;
}
return ((int)(unsigned int) x) - ((int)(unsigned int) y);
}
int case_diffrs(register char *s,register char *t)
{
register unsigned char x = 0;
register unsigned char y = 0;
unsigned int lens = str_len(s);
unsigned int lent = str_len(t);
while (lens > 0 && lent > 0) {
x = s[--lens] - 'A';
if (x <= 'Z' - 'A') x += 'a'; else x += 'A';
y = t[--lent] - 'A';
if (y <= 'Z' - 'A') y += 'a'; else y += 'A';
if (x != y) break;
if (!x) break;
if (!y) break;
}
return ((int)(unsigned int) x) - ((int)(unsigned int) y);
}
void case_lowerb(char *s,unsigned int len)
{
unsigned char x;
while (len > 0) {
--len;
x = *s - 'A';
if (x <= 'Z' - 'A') *s = x + 'a';
++s;
}
}
void case_lowers(char *s)
{
unsigned char x;
while ((x = *s)) {
x -= 'A';
if (x <= 'Z' - 'A') *s = x + 'a';
++s;
}
}
void case_upperb(char *s,unsigned int len)
{
unsigned char x;
while (len > 0) {
--len;
x = *s - 'a';
if (x <= 'z' - 'a') *s = x + 'A';
++s;
}
}
void case_uppers(char *s)
{
unsigned char x;
while ((x = *s)) {
x -= 'a';
if (x <= 'z' - 'a') *s = x + 'A';
++s;
}
}
int case_startb(register char *s,unsigned int len,register char *t)
{
register unsigned char x;
register unsigned char y;
for (;;) {
y = *t++ - 'A';
if (y <= 'Z' - 'A') y += 'a'; else y += 'A';
if (!y) return 1;
if (!len) return 0;
--len;
x = *s++ - 'A';
if (x <= 'Z' - 'A') x += 'a'; else x += 'A';
if (x != y) return 0;
}
}
int case_starts(register char *s,register char *t)
{
register unsigned char x;
register unsigned char y;
for (;;) {
x = *s++ - 'A';
if (x <= 'Z' - 'A') x += 'a'; else x += 'A';
y = *t++ - 'A';
if (y <= 'Z' - 'A') y += 'a'; else y += 'A';
if (!y) return 1;
if (x != y) return 0;
}
}
|