mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-06-18 01:52:22 -07:00
deduplicate string escaping paths in eval/cfg/etc
This commit is contained in:
@@ -1607,6 +1607,103 @@ indented_from_string(Arena *arena, String8 string)
|
||||
return result;
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Text Escaping
|
||||
|
||||
internal String8
|
||||
escaped_from_raw_str8(Arena *arena, String8 string)
|
||||
{
|
||||
Temp scratch = scratch_begin(&arena, 1);
|
||||
String8List parts = {0};
|
||||
U64 start_split_idx = 0;
|
||||
for(U64 idx = 0; idx <= string.size; idx += 1)
|
||||
{
|
||||
U8 byte = (idx < string.size) ? string.str[idx] : 0;
|
||||
B32 split = 1;
|
||||
String8 separator_replace = {0};
|
||||
switch(byte)
|
||||
{
|
||||
default:{split = 0;}break;
|
||||
case 0: {}break;
|
||||
case '\a': {separator_replace = str8_lit("\\a");}break;
|
||||
case '\b': {separator_replace = str8_lit("\\b");}break;
|
||||
case '\f': {separator_replace = str8_lit("\\f");}break;
|
||||
case '\n': {separator_replace = str8_lit("\\n");}break;
|
||||
case '\r': {separator_replace = str8_lit("\\r");}break;
|
||||
case '\t': {separator_replace = str8_lit("\\t");}break;
|
||||
case '\v': {separator_replace = str8_lit("\\v");}break;
|
||||
case '\\': {separator_replace = str8_lit("\\\\");}break;
|
||||
case '"': {separator_replace = str8_lit("\\\"");}break;
|
||||
case '?': {separator_replace = str8_lit("\\?");}break;
|
||||
}
|
||||
if(split)
|
||||
{
|
||||
String8 substr = str8_substr(string, r1u64(start_split_idx, idx));
|
||||
start_split_idx = idx+1;
|
||||
str8_list_push(scratch.arena, &parts, substr);
|
||||
if(separator_replace.size != 0)
|
||||
{
|
||||
str8_list_push(scratch.arena, &parts, separator_replace);
|
||||
}
|
||||
}
|
||||
}
|
||||
StringJoin join = {0};
|
||||
String8 result = str8_list_join(arena, &parts, &join);
|
||||
scratch_end(scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal String8
|
||||
raw_from_escaped_str8(Arena *arena, String8 string)
|
||||
{
|
||||
Temp scratch = scratch_begin(&arena, 1);
|
||||
String8List strs = {0};
|
||||
U64 start = 0;
|
||||
for(U64 idx = 0; idx <= string.size; idx += 1)
|
||||
{
|
||||
if(idx == string.size || string.str[idx] == '\\' || string.str[idx] == '\r')
|
||||
{
|
||||
String8 str = str8_substr(string, r1u64(start, idx));
|
||||
if(str.size != 0)
|
||||
{
|
||||
str8_list_push(scratch.arena, &strs, str);
|
||||
}
|
||||
start = idx+1;
|
||||
}
|
||||
if(idx < string.size && string.str[idx] == '\\')
|
||||
{
|
||||
U8 next_char = string.str[idx+1];
|
||||
U8 replace_byte = 0;
|
||||
switch(next_char)
|
||||
{
|
||||
default:{}break;
|
||||
case 'a': replace_byte = 0x07; break;
|
||||
case 'b': replace_byte = 0x08; break;
|
||||
case 'e': replace_byte = 0x1b; break;
|
||||
case 'f': replace_byte = 0x0c; break;
|
||||
case 'n': replace_byte = 0x0a; break;
|
||||
case 'r': replace_byte = 0x0d; break;
|
||||
case 't': replace_byte = 0x09; break;
|
||||
case 'v': replace_byte = 0x0b; break;
|
||||
case '\\':replace_byte = '\\'; break;
|
||||
case '\'':replace_byte = '\''; break;
|
||||
case '"': replace_byte = '"'; break;
|
||||
case '?': replace_byte = '?'; break;
|
||||
}
|
||||
String8 replace_string = push_str8_copy(scratch.arena, str8(&replace_byte, 1));
|
||||
str8_list_push(scratch.arena, &strs, replace_string);
|
||||
if(replace_byte == '\\' || replace_byte == '"' || replace_byte == '\'')
|
||||
{
|
||||
idx += 1;
|
||||
start += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
String8 result = str8_list_join(arena, &strs, 0);
|
||||
scratch_end(scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Text Wrapping
|
||||
|
||||
|
||||
@@ -331,6 +331,12 @@ internal String8 string_from_elapsed_time(Arena *arena, DateTime dt);
|
||||
|
||||
internal String8 indented_from_string(Arena *arena, String8 string);
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Text Escaping
|
||||
|
||||
internal String8 escaped_from_raw_str8(Arena *arena, String8 string);
|
||||
internal String8 raw_from_escaped_str8(Arena *arena, String8 string);
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Text Wrapping
|
||||
|
||||
|
||||
@@ -1359,12 +1359,6 @@ d_frame_index(void)
|
||||
return d_state->frame_index;
|
||||
}
|
||||
|
||||
internal Arena *
|
||||
d_frame_arena(void)
|
||||
{
|
||||
return d_state->frame_arenas[d_state->frame_index%ArrayCount(d_state->frame_arenas)];
|
||||
}
|
||||
|
||||
//- rjf: control state
|
||||
|
||||
internal D_RunKind
|
||||
@@ -1385,79 +1379,6 @@ d_ctrl_targets_running(void)
|
||||
return d_state->ctrl_is_running;
|
||||
}
|
||||
|
||||
//- rjf: config serialization
|
||||
|
||||
internal String8
|
||||
d_cfg_escaped_from_raw_string(Arena *arena, String8 string)
|
||||
{
|
||||
Temp scratch = scratch_begin(&arena, 1);
|
||||
String8List parts = {0};
|
||||
U64 split_start_idx = 0;
|
||||
for(U64 idx = 0; idx <= string.size; idx += 1)
|
||||
{
|
||||
U8 byte = (idx < string.size ? string.str[idx] : 0);
|
||||
if(byte == 0 || byte == '\"' || byte == '\\')
|
||||
{
|
||||
String8 part = str8_substr(string, r1u64(split_start_idx, idx));
|
||||
str8_list_push(scratch.arena, &parts, part);
|
||||
switch(byte)
|
||||
{
|
||||
default:{}break;
|
||||
case '\"':{str8_list_push(scratch.arena, &parts, str8_lit("\\\""));}break;
|
||||
case '\\':{str8_list_push(scratch.arena, &parts, str8_lit("\\\\"));}break;
|
||||
}
|
||||
split_start_idx = idx+1;
|
||||
}
|
||||
}
|
||||
StringJoin join = {0};
|
||||
String8 result = str8_list_join(arena, &parts, &join);
|
||||
scratch_end(scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal String8
|
||||
d_cfg_raw_from_escaped_string(Arena *arena, String8 string)
|
||||
{
|
||||
Temp scratch = scratch_begin(&arena, 1);
|
||||
String8List parts = {0};
|
||||
U64 split_start_idx = 0;
|
||||
U64 extra_advance = 0;
|
||||
for(U64 idx = 0; idx <= string.size; ((idx += 1+extra_advance), extra_advance=0))
|
||||
{
|
||||
U8 byte = (idx < string.size ? string.str[idx] : 0);
|
||||
if(byte == 0 || byte == '\\')
|
||||
{
|
||||
String8 part = str8_substr(string, r1u64(split_start_idx, idx));
|
||||
str8_list_push(scratch.arena, &parts, part);
|
||||
if(byte == '\\' && idx+1 < string.size)
|
||||
{
|
||||
switch(string.str[idx+1])
|
||||
{
|
||||
default:{}break;
|
||||
case '"': {extra_advance = 1; str8_list_push(scratch.arena, &parts, str8_lit("\""));}break;
|
||||
case '\\':{extra_advance = 1; str8_list_push(scratch.arena, &parts, str8_lit("\\"));}break;
|
||||
}
|
||||
}
|
||||
split_start_idx = idx+1+extra_advance;
|
||||
}
|
||||
}
|
||||
StringJoin join = {0};
|
||||
String8 result = str8_list_join(arena, &parts, &join);
|
||||
scratch_end(scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal String8List
|
||||
d_cfg_strings_from_core(Arena *arena, String8 root_path, D_CfgSrc source)
|
||||
{
|
||||
ProfBeginFunction();
|
||||
|
||||
String8List strs = {0};
|
||||
|
||||
ProfEnd();
|
||||
return strs;
|
||||
}
|
||||
|
||||
//- rjf: active entity based queries
|
||||
|
||||
internal DI_KeyList
|
||||
@@ -1757,10 +1678,6 @@ d_init(void)
|
||||
Arena *arena = arena_alloc();
|
||||
d_state = push_array(arena, D_State, 1);
|
||||
d_state->arena = arena;
|
||||
for(U64 idx = 0; idx < ArrayCount(d_state->frame_arenas); idx += 1)
|
||||
{
|
||||
d_state->frame_arenas[idx] = arena_alloc();
|
||||
}
|
||||
d_state->cmds_arena = arena_alloc();
|
||||
d_state->output_log_key = hs_hash_from_data(str8_lit("df_output_log_key"));
|
||||
d_state->ctrl_entity_store = ctrl_entity_store_alloc();
|
||||
@@ -1802,7 +1719,6 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P
|
||||
Temp scratch = scratch_begin(&arena, 1);
|
||||
D_EventList result = {0};
|
||||
d_state->frame_index += 1;
|
||||
arena_clear(d_frame_arena());
|
||||
d_state->frame_eval_memread_endt_us = os_now_microseconds() + 5000;
|
||||
B32 ctrl_running_pre_tick = d_state->ctrl_is_running;
|
||||
|
||||
|
||||
@@ -423,9 +423,6 @@ struct D_State
|
||||
U64 frame_index;
|
||||
U64 frame_eval_memread_endt_us;
|
||||
|
||||
// rjf: frame info
|
||||
Arena *frame_arenas[2];
|
||||
|
||||
// rjf: commands
|
||||
Arena *cmds_arena;
|
||||
D_CmdList cmds;
|
||||
@@ -577,18 +574,12 @@ internal CTRL_Event d_ctrl_last_stop_event(void);
|
||||
|
||||
//- rjf: frame data
|
||||
internal U64 d_frame_index(void);
|
||||
internal Arena *d_frame_arena(void);
|
||||
|
||||
//- rjf: control state
|
||||
internal D_RunKind d_ctrl_last_run_kind(void);
|
||||
internal U64 d_ctrl_last_run_frame_idx(void);
|
||||
internal B32 d_ctrl_targets_running(void);
|
||||
|
||||
//- rjf: config serialization
|
||||
internal String8 d_cfg_escaped_from_raw_string(Arena *arena, String8 string);
|
||||
internal String8 d_cfg_raw_from_escaped_string(Arena *arena, String8 string);
|
||||
internal String8List d_cfg_strings_from_core(Arena *arena, String8 root_path, D_CfgSrc source);
|
||||
|
||||
//- rjf: active entity based queries
|
||||
internal DI_KeyList d_push_active_dbgi_key_list(Arena *arena);
|
||||
|
||||
|
||||
@@ -1944,7 +1944,7 @@ d_commit_eval_value_string(E_Eval dst_eval, String8 string)
|
||||
{
|
||||
string = str8_chop(string, 1);
|
||||
}
|
||||
commit_data = e_raw_from_escaped_string(scratch.arena, string);
|
||||
commit_data = raw_from_escaped_str8(scratch.arena, string);
|
||||
commit_data.size += 1;
|
||||
if(type_kind == E_TypeKind_Ptr)
|
||||
{
|
||||
@@ -2117,7 +2117,7 @@ d_file_path_from_eval_string(Arena *arena, String8 string)
|
||||
E_Eval eval = e_eval_from_string(scratch.arena, string);
|
||||
if(eval.expr->kind == E_ExprKind_LeafFilePath)
|
||||
{
|
||||
result = d_cfg_raw_from_escaped_string(arena, eval.expr->string);
|
||||
result = raw_from_escaped_str8(arena, eval.expr->string);
|
||||
}
|
||||
scratch_end(scratch);
|
||||
}
|
||||
@@ -2128,7 +2128,7 @@ internal String8
|
||||
d_eval_string_from_file_path(Arena *arena, String8 string)
|
||||
{
|
||||
Temp scratch = scratch_begin(&arena, 1);
|
||||
String8 string_escaped = d_cfg_escaped_from_raw_string(scratch.arena, string);
|
||||
String8 string_escaped = escaped_from_raw_str8(scratch.arena, string);
|
||||
String8 result = push_str8f(arena, "file:\"%S\"", string_escaped);
|
||||
scratch_end(scratch);
|
||||
return result;
|
||||
@@ -6379,7 +6379,7 @@ df_window_frame(DF_Window *ws)
|
||||
DF_View *view = df_selected_tab_from_panel(panel);
|
||||
df_regs()->panel = df_handle_from_panel(panel);
|
||||
df_regs()->view = df_handle_from_view(view);
|
||||
df_regs()->file_path = d_file_path_from_eval_string(d_frame_arena(), str8(view->query_buffer, view->query_string_size));
|
||||
df_regs()->file_path = d_file_path_from_eval_string(df_frame_arena(), str8(view->query_buffer, view->query_string_size));
|
||||
}
|
||||
|
||||
//- rjf: build view container
|
||||
@@ -8494,7 +8494,7 @@ df_cfg_strings_from_gfx(Arena *arena, String8 root_path, D_CfgSrc source)
|
||||
}
|
||||
else
|
||||
{
|
||||
entity_name_escaped = d_cfg_escaped_from_raw_string(arena, e->string);
|
||||
entity_name_escaped = escaped_from_raw_str8(arena, e->string);
|
||||
}
|
||||
EntityInfoFlags info_flags = 0;
|
||||
if(entity_name_escaped.size != 0) { info_flags |= EntityInfoFlag_HasName; }
|
||||
@@ -8723,7 +8723,7 @@ df_cfg_strings_from_gfx(Arena *arena, String8 root_path, D_CfgSrc source)
|
||||
query_raw = push_str8f(scratch.arena, "file:\"%S\"", query_file_path);
|
||||
}
|
||||
}
|
||||
String8 query_sanitized = d_cfg_escaped_from_raw_string(scratch.arena, query_raw);
|
||||
String8 query_sanitized = escaped_from_raw_str8(scratch.arena, query_raw);
|
||||
str8_list_pushf(arena, &strs, "query:{\"%S\"} ", query_sanitized);
|
||||
scratch_end(scratch);
|
||||
}
|
||||
@@ -8921,8 +8921,8 @@ df_cfg_strings_from_gfx(Arena *arena, String8 root_path, D_CfgSrc source)
|
||||
//- rjf: serialize fonts
|
||||
if(source == D_CfgSrc_User)
|
||||
{
|
||||
String8 code_font_path_escaped = d_cfg_escaped_from_raw_string(arena, df_state->cfg_code_font_path);
|
||||
String8 main_font_path_escaped = d_cfg_escaped_from_raw_string(arena, df_state->cfg_main_font_path);
|
||||
String8 code_font_path_escaped = escaped_from_raw_str8(arena, df_state->cfg_code_font_path);
|
||||
String8 main_font_path_escaped = escaped_from_raw_str8(arena, df_state->cfg_main_font_path);
|
||||
str8_list_push(arena, &strs, str8_lit("/// fonts /////////////////////////////////////////////////////////////////////\n"));
|
||||
str8_list_push(arena, &strs, str8_lit("\n"));
|
||||
str8_list_pushf(arena, &strs, "code_font: \"%S\"\n", code_font_path_escaped);
|
||||
@@ -10493,7 +10493,7 @@ df_frame(void)
|
||||
// rjf: standalone string literals under an entity -> name
|
||||
if(child->flags & MD_NodeFlag_StringLiteral && child->first == &md_nil_node)
|
||||
{
|
||||
String8 string = d_cfg_raw_from_escaped_string(scratch.arena, child->string);
|
||||
String8 string = raw_from_escaped_str8(scratch.arena, child->string);
|
||||
if(d_entity_kind_flags_table[t->entity->kind] & DF_EntityKindFlag_NameIsPath)
|
||||
{
|
||||
string = path_absolute_dst_from_relative_dst_src(scratch.arena, string, cfg_folder);
|
||||
@@ -10504,7 +10504,7 @@ df_frame(void)
|
||||
// rjf: standalone string literals under an entity, with a numeric child -> name & text location
|
||||
if(child->flags & MD_NodeFlag_StringLiteral && child->first->flags & MD_NodeFlag_Numeric && child->first->first == &md_nil_node)
|
||||
{
|
||||
String8 string = d_cfg_raw_from_escaped_string(scratch.arena, child->string);
|
||||
String8 string = raw_from_escaped_str8(scratch.arena, child->string);
|
||||
if(d_entity_kind_flags_table[t->entity->kind] & DF_EntityKindFlag_NameIsPath)
|
||||
{
|
||||
string = path_absolute_dst_from_relative_dst_src(scratch.arena, string, cfg_folder);
|
||||
@@ -10529,7 +10529,7 @@ df_frame(void)
|
||||
str8_match(child->string, str8_lit("label"), StringMatchFlag_CaseInsensitive)) &&
|
||||
child->first != &md_nil_node)
|
||||
{
|
||||
String8 string = d_cfg_raw_from_escaped_string(scratch.arena, child->first->string);
|
||||
String8 string = raw_from_escaped_str8(scratch.arena, child->first->string);
|
||||
if(d_entity_kind_flags_table[t->entity->kind] & DF_EntityKindFlag_NameIsPath)
|
||||
{
|
||||
string = path_absolute_dst_from_relative_dst_src(scratch.arena, string, cfg_folder);
|
||||
@@ -10890,7 +10890,7 @@ df_frame(void)
|
||||
String8 view_query = str8_lit("");
|
||||
{
|
||||
String8 escaped_query = md_child_from_string(op, str8_lit("query"), 0)->first->string;
|
||||
view_query = d_cfg_raw_from_escaped_string(scratch.arena, escaped_query);
|
||||
view_query = raw_from_escaped_str8(scratch.arena, escaped_query);
|
||||
}
|
||||
|
||||
// rjf: convert file queries from relative to absolute
|
||||
@@ -11273,12 +11273,10 @@ df_frame(void)
|
||||
}
|
||||
}
|
||||
String8 path = df_cfg_path_from_src(src);
|
||||
String8List d_strs = d_cfg_strings_from_core(scratch.arena, path, src);
|
||||
String8List df_strs = df_cfg_strings_from_gfx(scratch.arena, path, src);
|
||||
String8 header = push_str8f(scratch.arena, "// raddbg %s file\n\n", d_cfg_src_string_table[src].str);
|
||||
String8List strs = {0};
|
||||
str8_list_push(scratch.arena, &strs, header);
|
||||
str8_list_concat_in_place(&strs, &d_strs);
|
||||
str8_list_concat_in_place(&strs, &df_strs);
|
||||
String8 data = str8_list_join(scratch.arena, &strs, 0);
|
||||
String8 data_indented = indented_from_string(scratch.arena, data);
|
||||
|
||||
@@ -2347,7 +2347,7 @@ df_watch_view_build(DF_View *view, DF_WatchViewState *ewv, B32 modifiable, U32 d
|
||||
df_push_regs();
|
||||
{
|
||||
df_regs()->view = df_handle_from_view(canvas_view);
|
||||
df_regs()->file_path = d_file_path_from_eval_string(d_frame_arena(), str8(canvas_view->query_buffer, canvas_view->query_string_size));
|
||||
df_regs()->file_path = d_file_path_from_eval_string(df_frame_arena(), str8(canvas_view->query_buffer, canvas_view->query_string_size));
|
||||
}
|
||||
|
||||
//- rjf: build
|
||||
@@ -6536,7 +6536,7 @@ DF_VIEW_UI_FUNCTION_DEF(text)
|
||||
//
|
||||
if(path.size != 0)
|
||||
{
|
||||
df_regs()->lines = d_lines_from_file_path_line_num(d_frame_arena(), path, df_regs()->cursor.line);
|
||||
df_regs()->lines = d_lines_from_file_path_line_num(df_frame_arena(), path, df_regs()->cursor.line);
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
@@ -6887,7 +6887,7 @@ DF_VIEW_UI_FUNCTION_DEF(disasm)
|
||||
U64 off = dasm_line_array_code_off_from_idx(&dasm_info.lines, df_regs()->cursor.line-1);
|
||||
df_regs()->vaddr_range = r1u64(base_vaddr+off, base_vaddr+off);
|
||||
df_regs()->voff_range = ctrl_voff_range_from_vaddr_range(dasm_module, df_regs()->vaddr_range);
|
||||
df_regs()->lines = d_lines_from_dbgi_key_voff(d_frame_arena(), &dbgi_key, df_regs()->voff_range.min);
|
||||
df_regs()->lines = d_lines_from_dbgi_key_voff(df_frame_arena(), &dbgi_key, df_regs()->voff_range.min);
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
|
||||
@@ -20,100 +20,6 @@ e_hash_from_string(U64 seed, String8 string)
|
||||
return result;
|
||||
}
|
||||
|
||||
internal String8
|
||||
e_raw_from_escaped_string(Arena *arena, String8 string)
|
||||
{
|
||||
Temp scratch = scratch_begin(&arena, 1);
|
||||
String8List strs = {0};
|
||||
U64 start = 0;
|
||||
for(U64 idx = 0; idx <= string.size; idx += 1)
|
||||
{
|
||||
if(idx == string.size || string.str[idx] == '\\' || string.str[idx] == '\r')
|
||||
{
|
||||
String8 str = str8_substr(string, r1u64(start, idx));
|
||||
if(str.size != 0)
|
||||
{
|
||||
str8_list_push(scratch.arena, &strs, str);
|
||||
}
|
||||
start = idx+1;
|
||||
}
|
||||
if(idx < string.size && string.str[idx] == '\\')
|
||||
{
|
||||
U8 next_char = string.str[idx+1];
|
||||
U8 replace_byte = 0;
|
||||
switch(next_char)
|
||||
{
|
||||
default:{}break;
|
||||
case 'a': replace_byte = 0x07; break;
|
||||
case 'b': replace_byte = 0x08; break;
|
||||
case 'e': replace_byte = 0x1b; break;
|
||||
case 'f': replace_byte = 0x0c; break;
|
||||
case 'n': replace_byte = 0x0a; break;
|
||||
case 'r': replace_byte = 0x0d; break;
|
||||
case 't': replace_byte = 0x09; break;
|
||||
case 'v': replace_byte = 0x0b; break;
|
||||
case '\\':replace_byte = '\\'; break;
|
||||
case '\'':replace_byte = '\''; break;
|
||||
case '"': replace_byte = '"'; break;
|
||||
case '?': replace_byte = '?'; break;
|
||||
}
|
||||
String8 replace_string = push_str8_copy(scratch.arena, str8(&replace_byte, 1));
|
||||
str8_list_push(scratch.arena, &strs, replace_string);
|
||||
if(replace_byte == '\\' || replace_byte == '"' || replace_byte == '\'')
|
||||
{
|
||||
idx += 1;
|
||||
start += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
String8 result = str8_list_join(arena, &strs, 0);
|
||||
scratch_end(scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal String8
|
||||
e_escaped_from_raw_string(Arena *arena, String8 string)
|
||||
{
|
||||
Temp scratch = scratch_begin(&arena, 1);
|
||||
String8List parts = {0};
|
||||
U64 start_split_idx = 0;
|
||||
for(U64 idx = 0; idx <= string.size; idx += 1)
|
||||
{
|
||||
U8 byte = (idx < string.size) ? string.str[idx] : 0;
|
||||
B32 split = 1;
|
||||
String8 separator_replace = {0};
|
||||
switch(byte)
|
||||
{
|
||||
default:{split = 0;}break;
|
||||
case 0: {}break;
|
||||
case '\a': {separator_replace = str8_lit("\\a");}break;
|
||||
case '\b': {separator_replace = str8_lit("\\b");}break;
|
||||
case '\f': {separator_replace = str8_lit("\\f");}break;
|
||||
case '\n': {separator_replace = str8_lit("\\n");}break;
|
||||
case '\r': {separator_replace = str8_lit("\\r");}break;
|
||||
case '\t': {separator_replace = str8_lit("\\t");}break;
|
||||
case '\v': {separator_replace = str8_lit("\\v");}break;
|
||||
case '\\': {separator_replace = str8_lit("\\\\");}break;
|
||||
case '"': {separator_replace = str8_lit("\\\"");}break;
|
||||
case '?': {separator_replace = str8_lit("\\?");}break;
|
||||
}
|
||||
if(split)
|
||||
{
|
||||
String8 substr = str8_substr(string, r1u64(start_split_idx, idx));
|
||||
start_split_idx = idx+1;
|
||||
str8_list_push(scratch.arena, &parts, substr);
|
||||
if(separator_replace.size != 0)
|
||||
{
|
||||
str8_list_push(scratch.arena, &parts, separator_replace);
|
||||
}
|
||||
}
|
||||
}
|
||||
StringJoin join = {0};
|
||||
String8 result = str8_list_join(arena, &parts, &join);
|
||||
scratch_end(scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Message Functions
|
||||
|
||||
|
||||
@@ -144,8 +144,6 @@ struct E_Module
|
||||
//~ rjf: Basic Helper Functions
|
||||
|
||||
internal U64 e_hash_from_string(U64 seed, String8 string);
|
||||
internal String8 e_raw_from_escaped_string(Arena *arena, String8 string);
|
||||
internal String8 e_escaped_from_raw_string(Arena *arena, String8 string);
|
||||
#define e_value_u64(v) (E_Value){.u64 = (v)}
|
||||
|
||||
////////////////////////////////
|
||||
|
||||
@@ -782,7 +782,7 @@ e_append_strings_from_expr(Arena *arena, E_Expr *expr, String8List *out)
|
||||
}break;
|
||||
case E_ExprKind_LeafFilePath:
|
||||
{
|
||||
str8_list_pushf(arena, out, "file:\"%S\"", e_escaped_from_raw_string(arena, expr->string));
|
||||
str8_list_pushf(arena, out, "file:\"%S\"", escaped_from_raw_str8(arena, expr->string));
|
||||
}break;
|
||||
case E_ExprKind_LeafF64:
|
||||
{
|
||||
@@ -1756,7 +1756,7 @@ e_parse_expr_from_text_tokens__prec(Arena *arena, String8 text, E_TokenArray *to
|
||||
if(token_string.size > 1 && token_string.str[0] == '\'' && token_string.str[1] != '\'')
|
||||
{
|
||||
String8 char_literal_escaped = str8_skip(str8_chop(token_string, 1), 1);
|
||||
String8 char_literal_raw = e_raw_from_escaped_string(scratch.arena, char_literal_escaped);
|
||||
String8 char_literal_raw = raw_from_escaped_str8(scratch.arena, char_literal_escaped);
|
||||
U8 char_val = char_literal_raw.size > 0 ? char_literal_raw.str[0] : 0;
|
||||
atom = e_push_expr(arena, E_ExprKind_LeafU64, token_string.str);
|
||||
atom->value.u64 = (U64)char_val;
|
||||
@@ -1773,7 +1773,7 @@ e_parse_expr_from_text_tokens__prec(Arena *arena, String8 text, E_TokenArray *to
|
||||
if(str8_match(resolution_qualifier, str8_lit("file"), 0))
|
||||
{
|
||||
String8 string_value_escaped = str8_chop(str8_skip(token_string, 1), 1);
|
||||
String8 string_value_raw = e_raw_from_escaped_string(arena, string_value_escaped);
|
||||
String8 string_value_raw = raw_from_escaped_str8(arena, string_value_escaped);
|
||||
atom = e_push_expr(arena, E_ExprKind_LeafFilePath, token_string.str);
|
||||
atom->string = string_value_raw;
|
||||
it += 1;
|
||||
@@ -1781,7 +1781,7 @@ e_parse_expr_from_text_tokens__prec(Arena *arena, String8 text, E_TokenArray *to
|
||||
else
|
||||
{
|
||||
String8 string_value_escaped = str8_chop(str8_skip(token_string, 1), 1);
|
||||
String8 string_value_raw = e_raw_from_escaped_string(arena, string_value_escaped);
|
||||
String8 string_value_raw = raw_from_escaped_str8(arena, string_value_escaped);
|
||||
atom = e_push_expr(arena, E_ExprKind_LeafStringLiteral, token_string.str);
|
||||
atom->string = string_value_raw;
|
||||
it += 1;
|
||||
|
||||
Reference in New Issue
Block a user