summaryrefslogtreecommitdiff
path: root/command_line/CmdLine/Src/OSLib/StringExtras.c
blob: a4415ee81e8d3e052761d2183b66420fb0a4064d (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
#include "oslib.h"

char *strcatn(char *d, const char *s, SInt32 max) {
    char *p;

    p = d + strlen(d);
    while (*s && (p - d) + 1 < max)
        *(p++) = *(s++);

    *p = 0;
    return d;
}

char *strcpyn(char *d, const char *s, SInt32 len, SInt32 max) {
    char *p;

    p = d;
    while (len-- && *s && (p - d) + 1 < max)
        *(p++) = *(s++);

    *p = 0;
    return d;
}

int ustrcmp(const char *src, const char *dst) {
    int x;

    do {
        x = tolower(*src) - tolower(*(dst++));
        if (x)
            return x;
    } while (*(src++));

    return 0;
}

int ustrncmp(const char *src, const char *dst, UInt32 len) {
    int x;

    while (len--) {
        x = tolower(*src) - tolower(*(dst++));
        if (x)
            return x;
        if (!*(src++))
            return 0;
    }

    return 0;
}