sapphire/core/string.sp

32 lines
800 B
SourcePawn
Raw Permalink Normal View History

2022-06-09 15:24:50 +00:00
let { alloc } in @'core/allocate';
2022-06-02 16:25:01 +00:00
2022-06-09 15:24:50 +00:00
let @len (String string) : u64 in {
let ptr = cast(i8*,string);
let length : u64 = 0;
while(ptr[length] != 0)
{
length += 1;
}
2022-06-09 15:24:50 +00:00
return length;
}
2022-06-09 15:24:50 +00:00
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;
}
2022-06-09 15:24:50 +00:00
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;
}
}