mirror of
https://github.com/Mercantec-GHC/h4-projekt-gruppe-0-sm.git
synced 2025-04-27 16:24:07 +02:00
improve string's vec use
This commit is contained in:
parent
1434772b35
commit
a99992d9d4
@ -52,14 +52,17 @@ StrSlice str_split_next(StrSplitter* splitter)
|
||||
return slice;
|
||||
}
|
||||
|
||||
DEFINE_VEC_IMPL(char, String, string_data, )
|
||||
|
||||
int string_construct(String* string)
|
||||
{
|
||||
int res = string_data_construct(string);
|
||||
if (res != 0) {
|
||||
if (res != 0)
|
||||
return res;
|
||||
}
|
||||
// NOTE: Vec is assumed to be initialized with atleast 1 allocated byte.
|
||||
string->data[0] = '\0';
|
||||
res = string_data_push(string, '\0');
|
||||
if (res != 0)
|
||||
return res;
|
||||
string->size -= 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -82,7 +85,8 @@ int string_push(String* string, char value)
|
||||
|
||||
int string_push_str(String* string, const char* str)
|
||||
{
|
||||
for (size_t i = 0; i < strlen(str); ++i) {
|
||||
size_t len = strlen(str);
|
||||
for (size_t i = 0; i < len; ++i) {
|
||||
int res = string_data_push(string, str[i]);
|
||||
if (res != 0)
|
||||
return res;
|
||||
@ -120,6 +124,8 @@ char* string_copy(const String* string)
|
||||
return copy;
|
||||
}
|
||||
|
||||
DEFINE_VEC_IMPL(char*, RawStrVec, rawstr_vec, )
|
||||
|
||||
#define STR_HASH_SALT_SIZE 32
|
||||
#define STR_HASH_HASH_SIZE 32
|
||||
#define STR_HASH_STR_LEN 128
|
||||
|
@ -25,7 +25,7 @@ typedef struct {
|
||||
StrSplitter str_splitter(const char* text, size_t text_len, const char* split);
|
||||
StrSlice str_split_next(StrSplitter* splitter);
|
||||
|
||||
DEFINE_VEC(char, String, string_data)
|
||||
DECLARE_VEC_TYPE(char, String, string_data, )
|
||||
|
||||
int string_construct(String* string);
|
||||
void string_destroy(String* string);
|
||||
@ -36,7 +36,7 @@ char* string_copy(const String* string);
|
||||
|
||||
#define string_pushf(STRING, ...) string_push_fmt_va(STRING, __VA_ARGS__)
|
||||
|
||||
DEFINE_VEC(char*, RawStrVec, rawstr_vec)
|
||||
DECLARE_VEC_TYPE(char*, RawStrVec, rawstr_vec, )
|
||||
|
||||
#define MAX_HASH_INPUT_LEN 256 - 1
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user