sapphire/core/string.sp
2022-06-09 17:24:50 +02:00

32 lines
800 B
SourcePawn

let { alloc } in @'core/allocate';
let @len (String string) : u64 in {
let ptr = cast(i8*,string);
let length : u64 = 0;
while(ptr[length] != 0)
{
length += 1;
}
return length;
}
let @concat (String a, String b) : String in {
let len_a = len(a);
let len_b = len(b);
let final_size = len_a + len_b;
let chars = cast(i8*,alloc.memalloc(final_size + 1));
clone(a,chars,len_a);
clone(b,chars + len_a,len_b);
chars[final_size] = 0;
return (String)chars;
}
let @clone (str string, i8* buffer, u64 max_copy_size) in {
let chars_cloned : u64 = 0;
let ptr = cast(i8*,string);
while(chars_cloned <= max_copy_size and ptr[chars_cloned] != 0)
{
buffer[chars_cloned] = ptr[chars_cloned];
chars_cloned += 1;
}
}