summaryrefslogtreecommitdiff
path: root/libs/dolphin/src/support/string.c
blob: f55ec794c3901e2a055be603d308c15f630e1e8e (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
#include <charPipeline/structures/dolphinString.h>

u8 Strcat(char* str1, char* str2, char* dst) {
    char* srcCursor = str1;
    char* dstCursor = dst;;

    if (!dst) {
        return 0;
    }
    if (!str1) {
        return 0;
    }
    if (!str2) {
        return 0;
    }

    while ((s8)*srcCursor != 0) {
        *dstCursor = *srcCursor;
        dstCursor++;
        srcCursor++;
    }

    srcCursor = str2;
    while ((s8)*srcCursor != 0) {
        *dstCursor = *srcCursor;
        dstCursor++;
        srcCursor++;
    }

    *dstCursor = 0;
    return 1;
}

void Strcpy(char* dst, char* src) {
    do {
        *dst = *src;
        dst++;
        src++;
    } while ((s8)*src != 0);
}

s8 Strcmp(char* str1, char* str2) {
    char* cursor1 = str1;
    char* cursor2 = str2;
    while (1) {
        if ((s8)*cursor1 < (s8)*cursor2) {
            return 1;
        }
        if ((s8)*cursor1 > (s8)*cursor2) {
            return -1;
        }
        cursor1++;
        cursor2++;
        if ((s8)*cursor1 == 0 || (s8)*cursor2 == 0) {
            return 0;
        }
    }
}

u32 Strlen(char* str) {
    char* cursor = str;
    u32 counter = 0;

    if (!str) {
        return 0;
    }

    while ((s8)*cursor != 0) {
        cursor++;
        counter++;
    }

    return counter;
}