mirror of
				https://github.com/Ed94/gencpp.git
				synced 2025-11-03 15:26:12 -08:00 
			
		
		
		
	working to towards https://github.com/Ed94/gencpp/issues/56
This commit is contained in:
		@@ -3,27 +3,27 @@
 | 
			
		||||
#	include "hashing.cpp"
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#pragma region String
 | 
			
		||||
#pragma region StrBuilder
 | 
			
		||||
 | 
			
		||||
String string_make_length( AllocatorInfo allocator, char const* str, ssize length )
 | 
			
		||||
StrBuilder strbuilder_make_length( AllocatorInfo allocator, char const* str, ssize length )
 | 
			
		||||
{
 | 
			
		||||
	ssize const header_size = sizeof( StringHeader );
 | 
			
		||||
	ssize const header_size = sizeof( StrBuilderHeader );
 | 
			
		||||
 | 
			
		||||
	s32   alloc_size = header_size + length + 1;
 | 
			
		||||
	void* allocation = alloc( allocator, alloc_size );
 | 
			
		||||
 | 
			
		||||
	if ( allocation == nullptr ) {
 | 
			
		||||
		String null_string = {nullptr};
 | 
			
		||||
		StrBuilder null_string = {nullptr};
 | 
			
		||||
		return null_string;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	StringHeader*
 | 
			
		||||
	header = rcast(StringHeader*, allocation);
 | 
			
		||||
	StrBuilderHeader*
 | 
			
		||||
	header = rcast(StrBuilderHeader*, allocation);
 | 
			
		||||
	header->Allocator = allocator;
 | 
			
		||||
	header->Capacity  = length;
 | 
			
		||||
	header->Length    = length;
 | 
			
		||||
 | 
			
		||||
	String  result = { rcast( char*, allocation) + header_size };
 | 
			
		||||
	StrBuilder  result = { rcast( char*, allocation) + header_size };
 | 
			
		||||
 | 
			
		||||
	if ( length && str )
 | 
			
		||||
		mem_copy( result, str, length );
 | 
			
		||||
@@ -35,27 +35,27 @@ String string_make_length( AllocatorInfo allocator, char const* str, ssize lengt
 | 
			
		||||
	return result;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
String string_make_reserve( AllocatorInfo allocator, ssize capacity )
 | 
			
		||||
StrBuilder strbuilder_make_reserve( AllocatorInfo allocator, ssize capacity )
 | 
			
		||||
{
 | 
			
		||||
	ssize const header_size = sizeof( StringHeader );
 | 
			
		||||
	ssize const header_size = sizeof( StrBuilderHeader );
 | 
			
		||||
 | 
			
		||||
	s32   alloc_size = header_size + capacity + 1;
 | 
			
		||||
	void* allocation = alloc( allocator, alloc_size );
 | 
			
		||||
 | 
			
		||||
	if ( allocation == nullptr ) {
 | 
			
		||||
		String null_string = {nullptr};
 | 
			
		||||
		StrBuilder null_string = {nullptr};
 | 
			
		||||
		return null_string;
 | 
			
		||||
	}
 | 
			
		||||
	mem_set( allocation, 0, alloc_size );
 | 
			
		||||
 | 
			
		||||
	StringHeader*
 | 
			
		||||
	header            = rcast(StringHeader*, allocation);
 | 
			
		||||
	StrBuilderHeader*
 | 
			
		||||
	header            = rcast(StrBuilderHeader*, allocation);
 | 
			
		||||
	header->Allocator = allocator;
 | 
			
		||||
	header->Capacity  = capacity;
 | 
			
		||||
	header->Length    = 0;
 | 
			
		||||
 | 
			
		||||
	String result = { rcast(char*, allocation) + header_size };
 | 
			
		||||
	StrBuilder result = { rcast(char*, allocation) + header_size };
 | 
			
		||||
	return result;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#pragma endregion String
 | 
			
		||||
#pragma endregion StrBuilder
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user