forked from AbleOS/ableos
46 lines
685 B
Plaintext
46 lines
685 B
Plaintext
length := fn(ptr: ^u8): uint {
|
|
len := @as(uint, 0)
|
|
loop if *(ptr + len) == 0 break else len += 1
|
|
return len
|
|
}
|
|
|
|
// WTFFF is wrong with display_int
|
|
display_int := fn(num: int, p: ^u8): ^u8 {
|
|
ptr := p
|
|
negative := num < 0
|
|
if negative {
|
|
num = -num
|
|
}
|
|
if num == 0 {
|
|
*ptr = 48
|
|
ptr += 1
|
|
} else {
|
|
loop if num == 0 break else {
|
|
*ptr = num % 10 + 48
|
|
ptr += 1
|
|
num /= 10
|
|
}
|
|
}
|
|
if negative {
|
|
*ptr = 45
|
|
ptr += 1
|
|
};
|
|
*ptr = 0
|
|
@inline(reverse, p)
|
|
return p
|
|
}
|
|
|
|
reverse := fn(s: ^u8): void {
|
|
len := @inline(length, s)
|
|
i := 0
|
|
j := len - 1
|
|
temp := 0
|
|
loop if i >= j break else {
|
|
temp = *(s + i);
|
|
*(s + i) = *(s + j);
|
|
*(s + j) = temp
|
|
i += 1
|
|
j -= 1
|
|
}
|
|
return
|
|
} |