ableos/sysdata/libraries/stn/src/string.hb

47 lines
629 B
Plaintext
Raw Normal View History

2024-07-07 08:35:07 -05:00
length := fn(ptr: ^u8): int {
2024-07-19 08:53:45 -05:00
len := 0
loop if *(ptr + len) == 0 break else len += 1
2024-07-19 08:53:45 -05:00
return len
}
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-16 20:45:00 -05:00
*p = 48;
*(p + 1) = 0
2024-07-19 08:53:45 -05:00
return p
}
2024-09-16 20:45:00 -05:00
neg := false
if num < 0 {
neg = true
num = -num
}
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-16 20:45:00 -05:00
if neg {
*(p + i) = 45
i += 1
}
reverse(p, i)
2024-07-19 08:53:45 -05:00
return p
}
2024-09-16 20:45:00 -05:00
reverse := fn(p: ^u8, len: int): void {
start := 0
end := len - 1
loop if start >= end break else {
temp := *(p + start);
*(p + start) = *(p + end);
*(p + end) = temp
start += 1
end -= 1
2024-07-19 08:53:45 -05:00
}
return
2024-07-20 12:54:58 -05:00
}