2024-07-07 08:35:07 -05:00
|
|
|
length := fn(ptr: ^u8): int {
|
|
|
|
len := 0;
|
|
|
|
loop if *ptr == 0 break else {
|
|
|
|
len += 1;
|
|
|
|
ptr += 1;
|
|
|
|
}
|
|
|
|
return len;
|
2024-07-16 16:42:49 -05:00
|
|
|
}
|
|
|
|
|
2024-07-16 19:24:24 -05:00
|
|
|
display_int := fn(num: int, p: ^u8): ^u8 {
|
2024-07-16 16:42:49 -05:00
|
|
|
i := 0;
|
|
|
|
if num == 0 {
|
|
|
|
set(p, 48);
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
loop {
|
|
|
|
if num == 0 break;
|
|
|
|
set(p + i, num % 10 + 48);
|
|
|
|
num /= 10;
|
|
|
|
i += 1;
|
|
|
|
}
|
|
|
|
reverse(p);
|
|
|
|
//null terminate
|
|
|
|
set(p + i, 0);
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
reverse := fn(s: ^u8): void {
|
|
|
|
//reverse a string, don't remove digits
|
|
|
|
len := 0;
|
|
|
|
loop {
|
|
|
|
if *(s + len) == 0 break;
|
|
|
|
len += 1;
|
|
|
|
}
|
|
|
|
i := 0;
|
|
|
|
j := len - 1;
|
|
|
|
loop {
|
|
|
|
if i >= j break;
|
|
|
|
temp := *(s + i);
|
|
|
|
*(s + i) = *(s + j);
|
|
|
|
*(s + j) = temp;
|
|
|
|
i += 1;
|
|
|
|
j -= 1;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-07-19 05:47:59 -05:00
|
|
|
set := fn(change: ^u8, new: int): void {
|
2024-07-16 16:42:49 -05:00
|
|
|
*(change) = new;
|
|
|
|
return;
|
|
|
|
}
|