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;
|
||
|
}
|
||
|
}
|
||
|
}
|