File: case.c

package info (click to toggle)
dq 20251001-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,376 kB
  • sloc: ansic: 13,644; python: 651; makefile: 382; sh: 336
file content (46 lines) | stat: -rw-r--r-- 1,090 bytes parent folder | download | duplicates (5)
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
#include "case.h"

int case_diffb(const void *yv, long long ylen, const void *xv) {

    unsigned char a, b;
    const unsigned char *y = yv;
    const unsigned char *x = xv;

    while (ylen > 0) {
        a = *x++ - 'A'; b = *y++ - 'A'; --ylen;
        if (a <= 'Z' - 'A') a += 'a'; else a += 'A';
        if (b <= 'Z' - 'A') b += 'a'; else b += 'A';
        if (a != b) return ((int)(unsigned int)b) - ((int)(unsigned int)a);
    }
    return 0;
}

int case_diffs(const void *yv, const void *xv) {

    unsigned char a, b;
    const unsigned char *y = yv;
    const unsigned char *x = xv;

    for (;;) {
        a = *x++ - 'A'; b = *y++ - 'A';
        if (a <= 'Z' - 'A') a += 'a'; else a += 'A';
        if (b <= 'Z' - 'A') b += 'a'; else b += 'A';
        if (a != b) break;
        if (!a) break;
    }
    return ((int)(unsigned int)b) - ((int)(unsigned int)a);
}

void case_lowerb(void *xv, long long len) {

    unsigned char *x = xv;
    unsigned char y;

    while (len > 0) {
        --len;
        y = *x - 'A';
        if (y <= 'Z' - 'A') *x = y + 'a';
        ++x;
    }
}