1
0
Fork 0
forked from AbleOS/ableos
ableos/sysdata/libraries/stn/src/string.hb

46 lines
685 B
Plaintext
Raw Normal View History

length := fn(ptr: ^u8): uint {
len := @as(uint, 0)
loop if *(ptr + len) == 0 break else len += 1
2024-07-19 08:53:45 -05:00
return len
}
2024-09-17 09:52:27 -05:00
// WTFFF is wrong with display_int
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-17 09:52:27 -05:00
*ptr = 48
ptr += 1
} else {
loop if num == 0 break else {
*ptr = num % 10 + 48
ptr += 1
num /= 10
}
2024-09-16 20:45:00 -05:00
}
2024-09-17 09:52:27 -05:00
if negative {
*ptr = 45
ptr += 1
};
*ptr = 0
@inline(reverse, p)
2024-07-19 08:53:45 -05:00
return p
}
2024-09-17 09:52:27 -05:00
reverse := fn(s: ^u8): void {
2024-10-20 06:36:34 -05:00
len := @inline(length, s)
2024-09-17 09:52:27 -05:00
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
2024-07-19 08:53:45 -05:00
}
return
2024-07-20 12:54:58 -05:00
}