2023-08-28 20:46:50 -07:00
|
|
|
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
|
|
|
# pragma once
|
|
|
|
# include "hashing.cpp"
|
|
|
|
#endif
|
2023-08-21 17:30:13 -07:00
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
#pragma region StrBuilder
|
2024-12-04 23:53:14 -08:00
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
StrBuilder strbuilder_make_length( AllocatorInfo allocator, char const* str, ssize length )
|
2023-07-24 15:35:16 -07:00
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
ssize const header_size = sizeof( StrBuilderHeader );
|
2023-08-21 17:30:13 -07:00
|
|
|
|
|
|
|
s32 alloc_size = header_size + length + 1;
|
|
|
|
void* allocation = alloc( allocator, alloc_size );
|
|
|
|
|
2024-12-08 13:37:04 -08:00
|
|
|
if ( allocation == nullptr ) {
|
2024-12-12 09:55:15 -08:00
|
|
|
StrBuilder null_string = {nullptr};
|
2024-12-08 13:37:04 -08:00
|
|
|
return null_string;
|
|
|
|
}
|
2023-08-21 17:30:13 -07:00
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
StrBuilderHeader*
|
|
|
|
header = rcast(StrBuilderHeader*, allocation);
|
2024-12-08 13:37:04 -08:00
|
|
|
header->Allocator = allocator;
|
|
|
|
header->Capacity = length;
|
|
|
|
header->Length = length;
|
2023-08-21 17:30:13 -07:00
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
StrBuilder result = { rcast( char*, allocation) + header_size };
|
2023-08-21 17:30:13 -07:00
|
|
|
|
|
|
|
if ( length && str )
|
|
|
|
mem_copy( result, str, length );
|
|
|
|
else
|
|
|
|
mem_set( result, 0, alloc_size - header_size );
|
|
|
|
|
|
|
|
result[ length ] = '\0';
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
StrBuilder strbuilder_make_reserve( AllocatorInfo allocator, ssize capacity )
|
2023-08-21 17:30:13 -07:00
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
ssize const header_size = sizeof( StrBuilderHeader );
|
2023-08-21 17:30:13 -07:00
|
|
|
|
|
|
|
s32 alloc_size = header_size + capacity + 1;
|
|
|
|
void* allocation = alloc( allocator, alloc_size );
|
|
|
|
|
2024-12-08 13:37:04 -08:00
|
|
|
if ( allocation == nullptr ) {
|
2024-12-12 09:55:15 -08:00
|
|
|
StrBuilder null_string = {nullptr};
|
2024-12-08 13:37:04 -08:00
|
|
|
return null_string;
|
|
|
|
}
|
2023-08-21 17:30:13 -07:00
|
|
|
mem_set( allocation, 0, alloc_size );
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
StrBuilderHeader*
|
|
|
|
header = rcast(StrBuilderHeader*, allocation);
|
2023-08-21 17:30:13 -07:00
|
|
|
header->Allocator = allocator;
|
|
|
|
header->Capacity = capacity;
|
|
|
|
header->Length = 0;
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
StrBuilder result = { rcast(char*, allocation) + header_size };
|
2023-08-21 17:30:13 -07:00
|
|
|
return result;
|
|
|
|
}
|
2024-12-04 23:53:14 -08:00
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
#pragma endregion StrBuilder
|