apio
f1668853dd
Planning to use LLVM to make stuff easier. Also, moved the random sapphire stuff to actual examples in an actual examples/ folder. Also started a standard library even if the compiler is not ready, because why not?? Also, it helps the examples.
33 lines
846 B
SourcePawn
33 lines
846 B
SourcePawn
namespace string {
|
|
|
|
@len (u64) (str string) {
|
|
i8* ptr = (i8*)string;
|
|
u64 length = 0;
|
|
while(ptr[length] != 0)
|
|
{
|
|
length += 1;
|
|
}
|
|
return length;
|
|
}
|
|
|
|
@concat (str) (str a, str b) {
|
|
u64 len_a = len(a);
|
|
u64 len_b = len(b);
|
|
u64 final_size = len_a + len_b;
|
|
i8* chars = i8*(final_size + 1); // TODO: work on allocation
|
|
clone(a,chars,len_a);
|
|
clone(b,chars + len_a,len_b);
|
|
chars[final_size] = 0;
|
|
return (str)chars;
|
|
}
|
|
|
|
@clone (str string, i8* buffer, u64 max_copy_size) {
|
|
u64 chars_cloned = 0;
|
|
i8* ptr = (i8*)string;
|
|
while(chars_cloned <= max_copy_size && ptr[chars_cloned] != 0)
|
|
{
|
|
buffer[chars_cloned] = ptr[chars_cloned];
|
|
chars_cloned += 1;
|
|
}
|
|
}
|
|
} |