Merge branch 'codegen'
This commit is contained in:
@@ -1,16 +1,22 @@
|
||||
/**
|
||||
* THIS FILE IS AUTOMATICALLY GENERATED. ANY MODIFICATIONS TO IT WILL BE OVERWRITTEN
|
||||
*/
|
||||
|
||||
#include "./dbl_list.h"
|
||||
#include "../../common/aliases/aliases.h"
|
||||
#include <stddef.h>
|
||||
|
||||
internal DBL_LIST(void) node_to_list(DBL_NODE(void) *node);
|
||||
typedef struct str8 Str8;
|
||||
|
||||
DBL_NODE(void) *_dbl_list_get(const DBL_LIST(void) *list, u64 index) {
|
||||
internal Str8List str8_node_to_list(Str8Node *node);
|
||||
|
||||
Str8Node *wapp_str8_list_get(const Str8List *list, u64 index) {
|
||||
if (index >= list->node_count) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DBL_NODE(void) *output = NULL;
|
||||
DBL_NODE(void) *current = list->first;
|
||||
Str8Node *output = NULL;
|
||||
Str8Node *current = list->first;
|
||||
for (u64 i = 1; i <= index; ++i) {
|
||||
current = current->next;
|
||||
}
|
||||
@@ -18,15 +24,14 @@ DBL_NODE(void) *_dbl_list_get(const DBL_LIST(void) *list, u64 index) {
|
||||
output = current;
|
||||
|
||||
return output;
|
||||
|
||||
}
|
||||
|
||||
void _dbl_list_push_front(DBL_LIST(void) *list, DBL_NODE(void) *node) {
|
||||
void wapp_str8_list_push_front(Str8List *list, Str8Node *node) {
|
||||
if (!list || !node || !(node->item)) {
|
||||
return;
|
||||
}
|
||||
|
||||
DBL_LIST(void) node_list = node_to_list(node);
|
||||
Str8List node_list = str8_node_to_list(node);
|
||||
|
||||
if (list->node_count == 0) {
|
||||
*list = node_list;
|
||||
@@ -35,22 +40,21 @@ void _dbl_list_push_front(DBL_LIST(void) *list, DBL_NODE(void) *node) {
|
||||
|
||||
list->node_count += node_list.node_count;
|
||||
|
||||
DBL_NODE(void) *first = list->first;
|
||||
Str8Node *first = list->first;
|
||||
if (first) {
|
||||
first->prev = node_list.last;
|
||||
}
|
||||
|
||||
list->first = node_list.first;
|
||||
list->first = node_list.first;
|
||||
node_list.last->next = first;
|
||||
|
||||
}
|
||||
|
||||
void _dbl_list_push_back(DBL_LIST(void) *list, DBL_NODE(void) *node) {
|
||||
void wapp_str8_list_push_back(Str8List *list, Str8Node *node) {
|
||||
if (!list || !node || !(node->item)) {
|
||||
return;
|
||||
}
|
||||
|
||||
DBL_LIST(void) node_list = node_to_list(node);
|
||||
Str8List node_list = str8_node_to_list(node);
|
||||
|
||||
if (list->node_count == 0) {
|
||||
*list = node_list;
|
||||
@@ -59,50 +63,48 @@ void _dbl_list_push_back(DBL_LIST(void) *list, DBL_NODE(void) *node) {
|
||||
|
||||
list->node_count += node_list.node_count;
|
||||
|
||||
DBL_NODE(void) *last = list->last;
|
||||
Str8Node *last = list->last;
|
||||
if (last) {
|
||||
last->next = node_list.first;
|
||||
}
|
||||
|
||||
list->last = node_list.last;
|
||||
list->last = node_list.last;
|
||||
node_list.first->prev = last;
|
||||
|
||||
}
|
||||
|
||||
void _dbl_list_insert(DBL_LIST(void) *list, DBL_NODE(void) *node, u64 index) {
|
||||
void wapp_str8_list_insert(Str8List *list, Str8Node *node, u64 index) {
|
||||
if (!list || !node || !(node->item)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (index == 0) {
|
||||
_dbl_list_push_front(list, node);
|
||||
wapp_str8_list_push_front(list, node);
|
||||
return;
|
||||
} else if (index == list->node_count) {
|
||||
_dbl_list_push_back(list, node);
|
||||
wapp_str8_list_push_back(list, node);
|
||||
return;
|
||||
}
|
||||
|
||||
DBL_NODE(void) *dst_node = _dbl_list_get(list, index);
|
||||
Str8Node *dst_node = wapp_str8_list_get(list, index);
|
||||
if (!dst_node) {
|
||||
return;
|
||||
}
|
||||
|
||||
DBL_LIST(void) node_list = node_to_list(node);
|
||||
Str8List node_list = str8_node_to_list(node);
|
||||
|
||||
list->node_count += node_list.node_count;
|
||||
|
||||
DBL_NODE(void) *prev = dst_node->prev;
|
||||
Str8Node *prev = dst_node->prev;
|
||||
|
||||
dst_node->prev = node_list.last;
|
||||
prev->next = node_list.first;
|
||||
|
||||
node_list.first->prev = prev;
|
||||
node_list.last->next = dst_node;
|
||||
|
||||
}
|
||||
|
||||
DBL_NODE(void) *_dbl_list_pop_front(DBL_LIST(void) *list) {
|
||||
DBL_NODE(void) *output = NULL;
|
||||
Str8Node *wapp_str8_list_pop_front(Str8List *list) {
|
||||
Str8Node *output = NULL;
|
||||
|
||||
if (!list || list->node_count == 0) {
|
||||
goto RETURN_STR8_LIST_POP_FRONT;
|
||||
@@ -111,22 +113,21 @@ DBL_NODE(void) *_dbl_list_pop_front(DBL_LIST(void) *list) {
|
||||
output = list->first;
|
||||
|
||||
if (list->node_count == 1) {
|
||||
*list = (DBL_LIST(void)){0};
|
||||
*list = (Str8List){0};
|
||||
goto RETURN_STR8_LIST_POP_FRONT;
|
||||
}
|
||||
|
||||
--(list->node_count);
|
||||
list->first = output->next;
|
||||
list->first = output->next;
|
||||
|
||||
output->prev = output->next = NULL;
|
||||
|
||||
RETURN_STR8_LIST_POP_FRONT:
|
||||
return output;
|
||||
|
||||
}
|
||||
|
||||
DBL_NODE(void) *_dbl_list_pop_back(DBL_LIST(void) *list) {
|
||||
DBL_NODE(void) *output = NULL;
|
||||
Str8Node *wapp_str8_list_pop_back(Str8List *list) {
|
||||
Str8Node *output = NULL;
|
||||
|
||||
if (!list || list->node_count == 0) {
|
||||
goto RETURN_STR8_LIST_POP_BACK;
|
||||
@@ -135,35 +136,34 @@ DBL_NODE(void) *_dbl_list_pop_back(DBL_LIST(void) *list) {
|
||||
output = list->last;
|
||||
|
||||
if (list->node_count == 1) {
|
||||
*list = (DBL_LIST(void)){0};
|
||||
*list = (Str8List){0};
|
||||
goto RETURN_STR8_LIST_POP_BACK;
|
||||
}
|
||||
|
||||
--(list->node_count);
|
||||
list->last = output->prev;
|
||||
list->last = output->prev;
|
||||
|
||||
output->prev = output->next = NULL;
|
||||
|
||||
RETURN_STR8_LIST_POP_BACK:
|
||||
return output;
|
||||
|
||||
}
|
||||
|
||||
DBL_NODE(void) *_dbl_list_remove(DBL_LIST(void) *list, u64 index) {
|
||||
DBL_NODE(void) *output = NULL;
|
||||
Str8Node *wapp_str8_list_remove(Str8List *list, u64 index) {
|
||||
Str8Node *output = NULL;
|
||||
if (!list) {
|
||||
goto RETURN_STR8_LIST_REMOVE;
|
||||
}
|
||||
|
||||
if (index == 0) {
|
||||
output = _dbl_list_pop_front(list);
|
||||
output = wapp_str8_list_pop_front(list);
|
||||
goto RETURN_STR8_LIST_REMOVE;
|
||||
} else if (index == list->node_count) {
|
||||
output = _dbl_list_pop_back(list);
|
||||
output = wapp_str8_list_pop_back(list);
|
||||
goto RETURN_STR8_LIST_REMOVE;
|
||||
}
|
||||
|
||||
output = _dbl_list_get(list, index);
|
||||
output = wapp_str8_list_get(list, index);
|
||||
if (!output) {
|
||||
goto RETURN_STR8_LIST_REMOVE;
|
||||
}
|
||||
@@ -177,23 +177,21 @@ DBL_NODE(void) *_dbl_list_remove(DBL_LIST(void) *list, u64 index) {
|
||||
|
||||
RETURN_STR8_LIST_REMOVE:
|
||||
return output;
|
||||
|
||||
}
|
||||
|
||||
void _dbl_list_empty(DBL_LIST(void) *list) {
|
||||
void wapp_str8_list_empty(Str8List *list) {
|
||||
if (!list) {
|
||||
return;
|
||||
}
|
||||
|
||||
u64 count = list->node_count;
|
||||
for (u64 i = 0; i < count; ++i) {
|
||||
_dbl_list_pop_back(list);
|
||||
wapp_str8_list_pop_back(list);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal DBL_LIST(void) node_to_list(DBL_NODE(void) *node) {
|
||||
DBL_LIST(void) output = {.first = node, .last = node, .node_count = 1};
|
||||
internal Str8List str8_node_to_list(Str8Node *node) {
|
||||
Str8List output = {.first = node, .last = node, .node_count = 1};
|
||||
|
||||
while (output.first->prev != NULL) {
|
||||
output.first = output.first->prev;
|
||||
@@ -207,3 +205,4 @@ internal DBL_LIST(void) node_to_list(DBL_NODE(void) *node) {
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
@@ -1,3 +1,7 @@
|
||||
/**
|
||||
* THIS FILE IS AUTOMATICALLY GENERATED. ANY MODIFICATIONS TO IT WILL BE OVERWRITTEN
|
||||
*/
|
||||
|
||||
#ifndef DBL_LIST_H
|
||||
#define DBL_LIST_H
|
||||
|
||||
@@ -7,66 +11,32 @@
|
||||
BEGIN_C_LINKAGE
|
||||
#endif // !__cplusplus
|
||||
|
||||
#define DBL_NODE(T) T##Node
|
||||
#define DBL_LIST(T) T##List
|
||||
#define wapp_str8_list_node(ITEM_PTR) ((Str8Node){.item = ITEM_PTR})
|
||||
|
||||
#define CAST_NODE(NODE) ((DBL_NODE(void))(NODE))
|
||||
#define CAST_LIST(LIST) ((DBL_LIST(void))(LIST))
|
||||
typedef struct str8 Str8;
|
||||
|
||||
#define CAST_NODE_PTR(NODE_PTR) ((DBL_NODE(void)*)(NODE_PTR))
|
||||
#define CAST_LIST_PTR(LIST_PTR) ((DBL_LIST(void)*)(LIST_PTR))
|
||||
typedef struct Str8Node Str8Node;
|
||||
struct Str8Node {
|
||||
Str8 *item;
|
||||
Str8Node *prev;
|
||||
Str8Node *next;
|
||||
};
|
||||
|
||||
#define DBL_LIST_DECL(T) typedef struct DBL_NODE(T) DBL_NODE(T); \
|
||||
struct DBL_NODE(T) { \
|
||||
T *item; \
|
||||
DBL_NODE(T) *prev; \
|
||||
DBL_NODE(T) *next; \
|
||||
}; \
|
||||
\
|
||||
typedef struct DBL_LIST(T) DBL_LIST(T); \
|
||||
struct DBL_LIST(T) { \
|
||||
DBL_NODE(T) *first; \
|
||||
DBL_NODE(T) *last; \
|
||||
u64 node_count; \
|
||||
}
|
||||
typedef struct Str8List Str8List;
|
||||
struct Str8List {
|
||||
Str8Node *first;
|
||||
Str8Node *last;
|
||||
u64 node_count;
|
||||
};
|
||||
|
||||
DBL_LIST_DECL(void);
|
||||
|
||||
#define wapp_dbl_list_node_from_item(T, ITEM_PTR) \
|
||||
((DBL_NODE(T)){ .item = ITEM_PTR })
|
||||
|
||||
#define wapp_dbl_list_get(T, LIST_PTR, INDEX) \
|
||||
(DBL_NODE(T)*)_dbl_list_get(CAST_LIST_PTR(LIST_PTR), INDEX)
|
||||
|
||||
#define wapp_dbl_list_push_front(LIST_PTR, NODE_PTR) \
|
||||
_dbl_list_push_front(CAST_LIST_PTR(LIST_PTR), CAST_NODE_PTR(NODE_PTR))
|
||||
|
||||
#define wapp_dbl_list_push_back(LIST_PTR, NODE_PTR) \
|
||||
_dbl_list_push_back(CAST_LIST_PTR(LIST_PTR), CAST_NODE_PTR(NODE_PTR))
|
||||
|
||||
#define wapp_dbl_list_insert(LIST_PTR, NODE_PTR, INDEX) \
|
||||
_dbl_list_insert(CAST_LIST_PTR(LIST_PTR), CAST_NODE_PTR(NODE_PTR), INDEX)
|
||||
|
||||
#define wapp_dbl_list_pop_front(T, LIST_PTR) \
|
||||
(DBL_NODE(T)*)_dbl_list_pop_front(CAST_LIST_PTR(LIST_PTR))
|
||||
|
||||
#define wapp_dbl_list_pop_back(T, LIST_PTR) \
|
||||
(DBL_NODE(T)*)_dbl_list_pop_back(CAST_LIST_PTR(LIST_PTR))
|
||||
|
||||
#define wapp_dbl_list_remove(T, LIST_PTR, INDEX) \
|
||||
(DBL_NODE(T)*)_dbl_list_remove(CAST_LIST_PTR(LIST_PTR), INDEX)
|
||||
|
||||
#define wapp_dbl_list_empty(LIST_PTR) \
|
||||
_dbl_list_empty(CAST_LIST_PTR(LIST_PTR))
|
||||
|
||||
DBL_NODE(void) *_dbl_list_get(const DBL_LIST(void) *list, u64 index);
|
||||
void _dbl_list_push_front(DBL_LIST(void) *list, DBL_NODE(void) *node);
|
||||
void _dbl_list_push_back(DBL_LIST(void) *list, DBL_NODE(void) *node);
|
||||
void _dbl_list_insert(DBL_LIST(void) *list, DBL_NODE(void) *node, u64 index);
|
||||
DBL_NODE(void) *_dbl_list_pop_front(DBL_LIST(void) *list);
|
||||
DBL_NODE(void) *_dbl_list_pop_back(DBL_LIST(void) *list);
|
||||
DBL_NODE(void) *_dbl_list_remove(DBL_LIST(void) *list, u64 index);
|
||||
void _dbl_list_empty(DBL_LIST(void) *list);
|
||||
Str8Node *wapp_str8_list_get(const Str8List *list, u64 index);
|
||||
void wapp_str8_list_push_front(Str8List *list, Str8Node *node);
|
||||
void wapp_str8_list_push_back(Str8List *list, Str8Node *node);
|
||||
void wapp_str8_list_insert(Str8List *list, Str8Node *node, u64 index);
|
||||
Str8Node *wapp_str8_list_pop_front(Str8List *list);
|
||||
Str8Node *wapp_str8_list_pop_back(Str8List *list);
|
||||
Str8Node *wapp_str8_list_remove(Str8List *list, u64 index);
|
||||
void wapp_str8_list_empty(Str8List *list);
|
||||
|
||||
#ifdef __cplusplus
|
||||
END_C_LINKAGE
|
||||
|
@@ -4,13 +4,13 @@
|
||||
#include "../../mem/allocator/mem_allocator.h"
|
||||
#include "../../mem/arena/mem_arena_allocator.h"
|
||||
#include "../../strings/str8/str8.h"
|
||||
#include "../../strings/str8/str8_list.h"
|
||||
#include "../../../containers/dbl_list/dbl_list.h"
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
u32 wapp_cpath_join_path(Str8 *dst, const DBL_LIST(Str8) *parts) {
|
||||
u32 wapp_cpath_join_path(Str8 *dst, const Str8List *parts) {
|
||||
if (!dst || !parts) {
|
||||
return CPATH_JOIN_INVALID_ARGS;
|
||||
}
|
||||
@@ -28,12 +28,12 @@ u32 wapp_cpath_join_path(Str8 *dst, const DBL_LIST(Str8) *parts) {
|
||||
}
|
||||
|
||||
// Handle first node
|
||||
const DBL_NODE(Str8) *first_node = wapp_dbl_list_get(Str8, parts, 0);
|
||||
const Str8Node *first_node = wapp_str8_list_get(parts, 0);
|
||||
wapp_str8_copy_str8_capped(dst, first_node->item);
|
||||
|
||||
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
||||
// MSVC Spectre mitigation warnings
|
||||
const DBL_NODE(Str8) *node = first_node;
|
||||
const Str8Node *node = first_node;
|
||||
u64 node_index = 1;
|
||||
bool running = true;
|
||||
while (running && node->next) {
|
||||
@@ -91,7 +91,7 @@ Str8 *dirup(const Allocator *allocator, Str8RO *path, u64 levels) {
|
||||
goto RETURN_DIRUP;
|
||||
}
|
||||
|
||||
DBL_LIST(Str8) *parts = wapp_str8_split(&tmp_arena, path, &separator);
|
||||
Str8List *parts = wapp_str8_split(&tmp_arena, path, &separator);
|
||||
if (!parts) {
|
||||
goto RETURN_DIRUP;
|
||||
}
|
||||
@@ -105,7 +105,7 @@ Str8 *dirup(const Allocator *allocator, Str8RO *path, u64 levels) {
|
||||
wapp_str8_push_back(output, absolute ? PATH_SEP : '.');
|
||||
} else {
|
||||
for (u64 i = 0; i < levels; ++i) {
|
||||
wapp_dbl_list_pop_back(Str8, parts);
|
||||
wapp_str8_list_pop_back(parts);
|
||||
}
|
||||
|
||||
u64 alignment = sizeof(void *) * 2;
|
||||
|
@@ -28,7 +28,7 @@ enum {
|
||||
CPATH_JOIN_INSUFFICIENT_DST_CAPACITY,
|
||||
};
|
||||
|
||||
u32 wapp_cpath_join_path(Str8 *dst, const DBL_LIST(Str8) *parts);
|
||||
u32 wapp_cpath_join_path(Str8 *dst, const Str8List *parts);
|
||||
Str8 *dirup(const Allocator *allocator, Str8RO *path, u64 levels);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@@ -4,6 +4,7 @@
|
||||
#include "../../../mem/allocator/mem_allocator.h"
|
||||
#include "../../../mem/arena/mem_arena_allocator.h"
|
||||
#include "../../../strings/str8/str8.h"
|
||||
#include "../../../../containers/dbl_list/dbl_list.h"
|
||||
#include "../../../../common/aliases/aliases.h"
|
||||
#include "../../../../common/misc/misc_utils.h"
|
||||
#include <stdarg.h>
|
||||
@@ -18,7 +19,7 @@
|
||||
internal inline CMDResult execute_command(Str8RO *cmd, CMDOutHandling out_handling, Str8 *out_buf);
|
||||
internal inline CMDError get_command_output(FILE *fp, CMDOutHandling out_handling, Str8 *out_buf);
|
||||
|
||||
CMDResult wapp_shell_commander_execute(CMDOutHandling out_handling, Str8 *out_buf, const DBL_LIST(Str8) *cmd) {
|
||||
CMDResult wapp_shell_commander_execute(CMDOutHandling out_handling, Str8 *out_buf, const Str8List *cmd) {
|
||||
if (!cmd) {
|
||||
return CMD_NO_EXIT(SHELL_ERR_INVALID_ARGS);
|
||||
}
|
||||
|
@@ -14,7 +14,7 @@ BEGIN_C_LINKAGE
|
||||
|
||||
#define CMD_NO_EXIT(ERR) ((CMDResult){.exited = false, .exit_code = EXIT_FAILURE, .error = ERR})
|
||||
|
||||
CMDResult wapp_shell_commander_execute(CMDOutHandling out_handling, Str8 *out_buf, const DBL_LIST(Str8) *cmd);
|
||||
CMDResult wapp_shell_commander_execute(CMDOutHandling out_handling, Str8 *out_buf, const Str8List *cmd);
|
||||
|
||||
external CMDError get_output_status(FILE *fp, i32 *status_out);
|
||||
|
||||
|
@@ -1,7 +1,5 @@
|
||||
#include "str8.h"
|
||||
#include "str8_list.h"
|
||||
#include "../../../common/aliases/aliases.h"
|
||||
#include "../../../containers/dbl_list/dbl_list.h"
|
||||
#include "../../mem/allocator/mem_allocator.h"
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
@@ -302,19 +300,19 @@ i64 wapp_str8_rfind(Str8RO *str, Str8RO substr) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
DBL_LIST(Str8) *wapp_str8_split_with_max(const Allocator *allocator, Str8RO *str, Str8RO *delimiter, i64 max_splits) {
|
||||
Str8List *wapp_str8_split_with_max(const Allocator *allocator, Str8RO *str, Str8RO *delimiter, i64 max_splits) {
|
||||
if (!allocator || !str || !delimiter) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DBL_LIST(Str8) *output = wapp_mem_allocator_alloc(allocator, sizeof(DBL_LIST(Str8)));
|
||||
Str8List *output = wapp_mem_allocator_alloc(allocator, sizeof(Str8List));
|
||||
|
||||
if (delimiter->size > str->size) {
|
||||
Str8 *full = wapp_str8_alloc_str8(allocator, str);
|
||||
DBL_NODE(Str8) *node = wapp_mem_allocator_alloc(allocator, sizeof(DBL_NODE(Str8)));
|
||||
Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node));
|
||||
if (node) {
|
||||
node->item = full;
|
||||
wapp_dbl_list_push_back(output, node);
|
||||
wapp_str8_list_push_back(output, node);
|
||||
}
|
||||
|
||||
goto RETURN_STR8_SPLIT;
|
||||
@@ -332,10 +330,10 @@ DBL_LIST(Str8) *wapp_str8_split_with_max(const Allocator *allocator, Str8RO *str
|
||||
}
|
||||
|
||||
before_str = wapp_str8_alloc_substr(allocator, str, start, start + end);
|
||||
DBL_NODE(Str8) *node = wapp_mem_allocator_alloc(allocator, sizeof(DBL_NODE(Str8)));
|
||||
Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node));
|
||||
if (node) {
|
||||
node->item = before_str;
|
||||
wapp_dbl_list_push_back(output, node);
|
||||
wapp_str8_list_push_back(output, node);
|
||||
}
|
||||
|
||||
wapp_mem_allocator_free(allocator, (void **)&rest, sizeof(Str8));
|
||||
@@ -346,30 +344,30 @@ DBL_LIST(Str8) *wapp_str8_split_with_max(const Allocator *allocator, Str8RO *str
|
||||
}
|
||||
|
||||
// Ensure the last part of the string after the delimiter is added to the list
|
||||
rest = wapp_str8_alloc_substr(allocator, str, start, str->size);
|
||||
DBL_NODE(Str8) *node = wapp_mem_allocator_alloc(allocator, sizeof(DBL_NODE(Str8)));
|
||||
rest = wapp_str8_alloc_substr(allocator, str, start, str->size);
|
||||
Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node));
|
||||
if (node) {
|
||||
node->item = rest;
|
||||
wapp_dbl_list_push_back(output, node);
|
||||
wapp_str8_list_push_back(output, node);
|
||||
}
|
||||
|
||||
RETURN_STR8_SPLIT:
|
||||
return output;
|
||||
}
|
||||
|
||||
DBL_LIST(Str8) *wapp_str8_rsplit_with_max(const Allocator *allocator, Str8RO *str, Str8RO *delimiter, i64 max_splits) {
|
||||
Str8List *wapp_str8_rsplit_with_max(const Allocator *allocator, Str8RO *str, Str8RO *delimiter, i64 max_splits) {
|
||||
if (!allocator || !str || !delimiter) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DBL_LIST(Str8) *output = wapp_mem_allocator_alloc(allocator, sizeof(DBL_LIST(Str8)));
|
||||
Str8List *output = wapp_mem_allocator_alloc(allocator, sizeof(Str8List));
|
||||
|
||||
if (delimiter->size > str->size) {
|
||||
Str8 *full = wapp_str8_alloc_str8(allocator, str);
|
||||
DBL_NODE(Str8) *node = wapp_mem_allocator_alloc(allocator, sizeof(DBL_NODE(Str8)));
|
||||
Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node));
|
||||
if (node) {
|
||||
node->item = full;
|
||||
wapp_dbl_list_push_back(output, node);
|
||||
wapp_str8_list_push_back(output, node);
|
||||
}
|
||||
|
||||
goto RETURN_STR8_SPLIT;
|
||||
@@ -386,10 +384,10 @@ DBL_LIST(Str8) *wapp_str8_rsplit_with_max(const Allocator *allocator, Str8RO *st
|
||||
}
|
||||
|
||||
after_str = wapp_str8_alloc_substr(allocator, rest, end + delimiter->size, str->size);
|
||||
DBL_NODE(Str8) *node = wapp_mem_allocator_alloc(allocator, sizeof(DBL_NODE(Str8)));
|
||||
Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node));
|
||||
if (node) {
|
||||
node->item = after_str;
|
||||
wapp_dbl_list_push_front(output, node);
|
||||
wapp_str8_list_push_front(output, node);
|
||||
}
|
||||
|
||||
wapp_mem_allocator_free(allocator, (void **)&rest, sizeof(Str8));
|
||||
@@ -399,17 +397,17 @@ DBL_LIST(Str8) *wapp_str8_rsplit_with_max(const Allocator *allocator, Str8RO *st
|
||||
}
|
||||
|
||||
rest = wapp_str8_alloc_substr(allocator, str, 0, rest->size);
|
||||
DBL_NODE(Str8) *node = wapp_mem_allocator_alloc(allocator, sizeof(DBL_NODE(Str8)));
|
||||
Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node));
|
||||
if (node) {
|
||||
node->item = rest;
|
||||
wapp_dbl_list_push_front(output, node);
|
||||
wapp_str8_list_push_front(output, node);
|
||||
}
|
||||
|
||||
RETURN_STR8_SPLIT:
|
||||
return output;
|
||||
}
|
||||
|
||||
Str8 *wapp_str8_join(const Allocator *allocator, const DBL_LIST(Str8) *list, Str8RO *delimiter) {
|
||||
Str8 *wapp_str8_join(const Allocator *allocator, const Str8List *list, Str8RO *delimiter) {
|
||||
if (!allocator || !list || !delimiter) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -419,11 +417,11 @@ Str8 *wapp_str8_join(const Allocator *allocator, const DBL_LIST(Str8) *list, Str
|
||||
|
||||
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
||||
// MSVC Spectre mitigation warnings
|
||||
DBL_NODE(Str8) *node;
|
||||
Str8Node *node;
|
||||
u64 node_index = 0;
|
||||
bool running = true;
|
||||
while (running) {
|
||||
node = wapp_dbl_list_get(Str8, list, node_index);
|
||||
node = wapp_str8_list_get(list, node_index);
|
||||
wapp_str8_concat_capped(output, node->item);
|
||||
if (node_index + 1 < list->node_count) {
|
||||
wapp_str8_concat_capped(output, delimiter);
|
||||
@@ -435,3 +433,17 @@ Str8 *wapp_str8_join(const Allocator *allocator, const DBL_LIST(Str8) *list, Str
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
u64 wapp_str8_list_total_size(const Str8List *list) {
|
||||
if (!list) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
u64 output = 0;
|
||||
for (u64 i = 0; i < list->node_count; ++i) {
|
||||
Str8Node *node = wapp_str8_list_get(list, i);
|
||||
output += node->item->size;
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
@@ -1,7 +1,6 @@
|
||||
#ifndef STR8_H
|
||||
#define STR8_H
|
||||
|
||||
#include "./str8_list.h"
|
||||
#include "../../../common/aliases/aliases.h"
|
||||
#include "../../../containers/dbl_list/dbl_list.h"
|
||||
#include "../../mem/allocator/mem_allocator.h"
|
||||
@@ -85,15 +84,16 @@ i64 wapp_str8_rfind(Str8RO *str, Str8RO substr);
|
||||
*/
|
||||
#define wapp_str8_split(ALLOCATOR, STR, DELIMITER) wapp_str8_split_with_max(ALLOCATOR, STR, DELIMITER, -1)
|
||||
#define wapp_str8_rsplit(ALLOCATOR, STR, DELIMITER) wapp_str8_rsplit_with_max(ALLOCATOR, STR, DELIMITER, -1)
|
||||
DBL_LIST(Str8) *wapp_str8_split_with_max(const Allocator *allocator, Str8RO *str, Str8RO *delimiter, i64 max_splits);
|
||||
DBL_LIST(Str8) *wapp_str8_rsplit_with_max(const Allocator *allocator, Str8RO *str, Str8RO *delimiter, i64 max_splits);
|
||||
Str8 *wapp_str8_join(const Allocator *allocator, const DBL_LIST(Str8) *list, Str8RO *delimiter);
|
||||
Str8List *wapp_str8_split_with_max(const Allocator *allocator, Str8RO *str, Str8RO *delimiter, i64 max_splits);
|
||||
Str8List *wapp_str8_rsplit_with_max(const Allocator *allocator, Str8RO *str, Str8RO *delimiter, i64 max_splits);
|
||||
Str8 *wapp_str8_join(const Allocator *allocator, const Str8List *list, Str8RO *delimiter);
|
||||
|
||||
/**
|
||||
* Str8 list utilities
|
||||
*/
|
||||
#define wapp_str8_node_from_cstr(STRING) wapp_dbl_list_node_from_item(Str8, &wapp_str8_lit(STRING))
|
||||
#define wapp_str8_node_from_str8(STRING) wapp_dbl_list_node_from_item(Str8, &(STRING))
|
||||
#define wapp_str8_node_from_cstr(STRING) wapp_str8_list_node(&wapp_str8_lit(STRING))
|
||||
#define wapp_str8_node_from_str8(STRING) wapp_str8_list_node(&(STRING))
|
||||
u64 wapp_str8_list_total_size(const Str8List *list);
|
||||
|
||||
#ifdef __cplusplus
|
||||
END_C_LINKAGE
|
||||
|
@@ -1,18 +0,0 @@
|
||||
#include "./str8_list.h"
|
||||
#include "./str8.h"
|
||||
#include "../../../common/aliases/aliases.h"
|
||||
#include "../../../containers/dbl_list/dbl_list.h"
|
||||
|
||||
u64 wapp_str8_list_total_size(const DBL_LIST(Str8) *list) {
|
||||
if (!list) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
u64 output = 0;
|
||||
for (u64 i = 0; i < list->node_count; ++i) {
|
||||
DBL_NODE(Str8) *node = wapp_dbl_list_get(Str8, list, i);
|
||||
output += node->item->size;
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
@@ -1,25 +0,0 @@
|
||||
/**
|
||||
* THIS FILE IS AUTOMATICALLY GENERATED. ANY MODIFICATIONS TO IT WILL BE OVERWRITTEN
|
||||
*/
|
||||
|
||||
#ifndef STR8_LIST_H
|
||||
#define STR8_LIST_H
|
||||
|
||||
#include "../../../common/aliases/aliases.h"
|
||||
#include "../../../containers/dbl_list/dbl_list.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
BEGIN_C_LINKAGE
|
||||
#endif // !__cplusplus
|
||||
|
||||
typedef struct str8 Str8;
|
||||
|
||||
DBL_LIST_DECL(Str8);
|
||||
|
||||
u64 wapp_str8_list_total_size(const DBL_LIST(Str8) *list);
|
||||
|
||||
#ifdef __cplusplus
|
||||
END_C_LINKAGE
|
||||
#endif // !__cplusplus
|
||||
|
||||
#endif // !STR8_LIST_H
|
@@ -3,7 +3,6 @@
|
||||
|
||||
#include "wapp_core.h"
|
||||
#include "strings/str8/str8.c"
|
||||
#include "strings/str8/str8_list.c"
|
||||
#include "os/shell/termcolour/posix/termcolour_posix.c"
|
||||
#include "os/shell/termcolour/win/termcolour_win.c"
|
||||
#include "os/shell/termcolour/termcolour.c"
|
||||
@@ -18,5 +17,6 @@
|
||||
#include "mem/allocator/mem_allocator.c"
|
||||
#include "mem/arena/mem_arena.c"
|
||||
#include "mem/arena/mem_arena_allocator.c"
|
||||
#include "../containers/wapp_containers.c"
|
||||
|
||||
#endif // !WAPP_CORE_C
|
||||
|
@@ -2,7 +2,6 @@
|
||||
#define WAPP_CORE_H
|
||||
|
||||
#include "strings/str8/str8.h"
|
||||
#include "strings/str8/str8_list.h"
|
||||
#include "os/shell/termcolour/termcolour.h"
|
||||
#include "os/shell/termcolour/terminal_colours.h"
|
||||
#include "os/shell/commander/commander.h"
|
||||
@@ -18,5 +17,6 @@
|
||||
#include "mem/arena/mem_arena_allocator.h"
|
||||
#include "mem/arena/mem_arena.h"
|
||||
#include "../common/wapp_common.h"
|
||||
#include "../containers/wapp_containers.h"
|
||||
|
||||
#endif // !WAPP_CORE_H
|
||||
|
Reference in New Issue
Block a user