forked from AbleOS/ableos
48 lines
742 B
Plaintext
48 lines
742 B
Plaintext
length := fn(ptr: ^u8): int {
|
|
len := 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 {
|
|
//reverse a string, don't remove digits
|
|
len := 0
|
|
loop if *(s + len) == 0 break else len += 1
|
|
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
|
|
} |