2024-07-07 08:35:07 -05:00
|
|
|
length := fn(ptr: ^u8): int {
|
2024-07-19 08:53:45 -05:00
|
|
|
len := 0
|
2024-09-01 22:36:03 -05:00
|
|
|
loop if *(ptr + len) == 0 break else len += 1
|
2024-07-19 08:53:45 -05:00
|
|
|
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-19 08:53:45 -05:00
|
|
|
i := 0
|
|
|
|
if num == 0 {
|
2024-09-01 22:36:03 -05:00
|
|
|
*p = 48
|
2024-07-19 08:53:45 -05:00
|
|
|
return p
|
|
|
|
}
|
2024-09-01 22:36:03 -05:00
|
|
|
loop if num == 0 break else {
|
|
|
|
*(p + i) = num % 10 + 48
|
2024-07-19 08:53:45 -05:00
|
|
|
num /= 10
|
|
|
|
i += 1
|
|
|
|
}
|
2024-09-01 22:36:03 -05:00
|
|
|
@inline(reverse, p);
|
|
|
|
*(p + i) = 0
|
2024-07-19 08:53:45 -05:00
|
|
|
return p
|
2024-07-16 16:42:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
reverse := fn(s: ^u8): void {
|
2024-07-19 08:53:45 -05:00
|
|
|
//reverse a string, don't remove digits
|
|
|
|
len := 0
|
2024-09-01 22:36:03 -05:00
|
|
|
loop if *(s + len) == 0 break else len += 1
|
2024-07-19 08:53:45 -05:00
|
|
|
i := 0
|
|
|
|
j := len - 1
|
2024-09-01 22:36:03 -05:00
|
|
|
temp := 0
|
|
|
|
loop if i >= j break else {
|
|
|
|
temp = *(s + i);
|
2024-07-19 08:53:45 -05:00
|
|
|
*(s + i) = *(s + j);
|
|
|
|
*(s + j) = temp
|
|
|
|
i += 1
|
|
|
|
j -= 1
|
|
|
|
}
|
|
|
|
return
|
2024-07-20 12:54:58 -05:00
|
|
|
}
|