mirror of
https://github.com/Ed94/gencpp.git
synced 2025-02-23 21:58:37 -08:00
move strbuilder_make_space_for to strings.cpp (not inlined)
This commit is contained in:
parent
6f2d81434e
commit
b6d95e8d70
@ -58,4 +58,41 @@ StrBuilder strbuilder_make_reserve( AllocatorInfo allocator, ssize capacity )
|
||||
return result;
|
||||
}
|
||||
|
||||
bool strbuilder_make_space_for(StrBuilder* str, char const* to_append, ssize add_len)
|
||||
{
|
||||
ssize available = strbuilder_avail_space(* str);
|
||||
|
||||
if (available >= add_len) {
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
ssize new_len, old_size, new_size;
|
||||
void* ptr;
|
||||
void* new_ptr;
|
||||
|
||||
AllocatorInfo allocator = strbuilder_get_header(* str)->Allocator;
|
||||
StrBuilderHeader* header = nullptr;
|
||||
|
||||
new_len = strbuilder_grow_formula(strbuilder_length(* str) + add_len);
|
||||
ptr = strbuilder_get_header(* str);
|
||||
old_size = size_of(StrBuilderHeader) + strbuilder_length(* str) + 1;
|
||||
new_size = size_of(StrBuilderHeader) + new_len + 1;
|
||||
|
||||
new_ptr = resize(allocator, ptr, old_size, new_size);
|
||||
|
||||
if (new_ptr == nullptr)
|
||||
return false;
|
||||
|
||||
header = rcast(StrBuilderHeader*, new_ptr);
|
||||
header->Allocator = allocator;
|
||||
header->Capacity = new_len;
|
||||
|
||||
char** Data = rcast(char**, str);
|
||||
* Data = rcast(char*, header + 1);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma endregion StrBuilder
|
||||
|
@ -122,8 +122,9 @@ struct StrBuilder;
|
||||
|
||||
forceinline usize strbuilder_grow_formula(usize value);
|
||||
|
||||
GEN_API StrBuilder strbuilder_make_reserve (AllocatorInfo allocator, ssize capacity);
|
||||
GEN_API StrBuilder strbuilder_make_length (AllocatorInfo allocator, char const* str, ssize length);
|
||||
GEN_API StrBuilder strbuilder_make_reserve (AllocatorInfo allocator, ssize capacity);
|
||||
GEN_API StrBuilder strbuilder_make_length (AllocatorInfo allocator, char const* str, ssize length);
|
||||
GEN_API bool strbuilder_make_space_for(StrBuilder* str, char const* to_append, ssize add_len);
|
||||
|
||||
StrBuilder strbuilder_make_c_str (AllocatorInfo allocator, char const* str);
|
||||
StrBuilder strbuilder_make_str (AllocatorInfo allocator, Str str);
|
||||
@ -132,7 +133,6 @@ StrBuilder strbuilder_fmt_buf (AllocatorInfo allocator, char
|
||||
StrBuilder strbuilder_join (AllocatorInfo allocator, char const** parts, ssize num_parts, char const* glue);
|
||||
bool strbuilder_are_equal (StrBuilder const lhs, StrBuilder const rhs);
|
||||
bool strbuilder_are_equal_str (StrBuilder const lhs, Str rhs);
|
||||
bool strbuilder_make_space_for (StrBuilder* str, char const* to_append, ssize add_len);
|
||||
bool strbuilder_append_char (StrBuilder* str, char c);
|
||||
bool strbuilder_append_c_str (StrBuilder* str, char const* c_str_to_append);
|
||||
bool strbuilder_append_c_str_len (StrBuilder* str, char const* c_str_to_append, ssize length);
|
||||
@ -522,44 +522,6 @@ ssize strbuilder_length(StrBuilder const str)
|
||||
return header->Length;
|
||||
}
|
||||
|
||||
inline
|
||||
bool strbuilder_make_space_for(StrBuilder* str, char const* to_append, ssize add_len)
|
||||
{
|
||||
ssize available = strbuilder_avail_space(* str);
|
||||
|
||||
if (available >= add_len) {
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
ssize new_len, old_size, new_size;
|
||||
void* ptr;
|
||||
void* new_ptr;
|
||||
|
||||
AllocatorInfo allocator = strbuilder_get_header(* str)->Allocator;
|
||||
StrBuilderHeader* header = nullptr;
|
||||
|
||||
new_len = strbuilder_grow_formula(strbuilder_length(* str) + add_len);
|
||||
ptr = strbuilder_get_header(* str);
|
||||
old_size = size_of(StrBuilderHeader) + strbuilder_length(* str) + 1;
|
||||
new_size = size_of(StrBuilderHeader) + new_len + 1;
|
||||
|
||||
new_ptr = resize(allocator, ptr, old_size, new_size);
|
||||
|
||||
if (new_ptr == nullptr)
|
||||
return false;
|
||||
|
||||
header = rcast(StrBuilderHeader*, new_ptr);
|
||||
header->Allocator = allocator;
|
||||
header->Capacity = new_len;
|
||||
|
||||
char** Data = rcast(char**, str);
|
||||
* Data = rcast(char*, header + 1);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
forceinline
|
||||
b32 strbuilder_starts_with_str(StrBuilder const str, Str substring) {
|
||||
if (substring.Len > strbuilder_length(str))
|
||||
|
Loading…
x
Reference in New Issue
Block a user