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

51 lines
683 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-09-16 15:56:52 -05:00
display_int := fn(num: int, p: ^u8): ^u8 {
ptr := p
negative := num < 0
if negative {
2024-09-16 20:45:00 -05:00
num = -num
}
2024-09-16 15:56:52 -05:00
if num == 0 {
2024-09-16 20:45:00 -05:00
*p = 48;
*(p + 1) = 0
return p
2024-09-16 20:45:00 -05:00
}
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
num /= 10
i += 1
}
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
}