diff --git a/4coder_combined_write_commands.cpp b/4coder_combined_write_commands.cpp index 83917a3e..c2684be0 100644 --- a/4coder_combined_write_commands.cpp +++ b/4coder_combined_write_commands.cpp @@ -178,15 +178,13 @@ snippet_lister__parameterized(Application_Links *app, Snippet_Array snippet_arra int32_t option_count = snippet_array.count; Lister_Option *options = push_array(arena, Lister_Option, option_count); for (int32_t i = 0; i < snippet_array.count; i += 1){ - options[i].string = snippet_array.snippets[i].name; - options[i].status = snippet_array.snippets[i].text; + options[i].string = make_string_slowly(snippet_array.snippets[i].name); + options[i].status = make_string_slowly(snippet_array.snippets[i].text); options[i].user_data = IntAsPtr(i); } begin_integrated_lister__basic_list(app, "Snippet:", activate_snippet, &snippet_array, sizeof(snippet_array), - options, option_count, - 0, - &view); + options, option_count, 0, &view); end_temp_memory(temp); } diff --git a/4coder_function_list.cpp b/4coder_function_list.cpp index e716917d..1ac2b6e0 100644 --- a/4coder_function_list.cpp +++ b/4coder_function_list.cpp @@ -10,6 +10,43 @@ // iterating tokens is now. // +static Buffered_Write_Stream +make_buffered_write_stream(Buffer_ID output_buffer_id, Partition *buffering_arena){ + Buffered_Write_Stream stream = {}; + stream.output_buffer_id = output_buffer_id; + stream.buffering_arena = buffering_arena; + stream.buffer = push_array(buffering_arena, char, 0); + return(stream); +} + +static void +buffered_write_stream_flush(Application_Links *app, Buffered_Write_Stream *stream){ + Buffer_Summary buffer = get_buffer(app, stream->output_buffer_id, AccessProtected); + int32_t buffer_size = (int32_t)(push_array(stream->buffering_arena, char, 0) - stream->buffer); + buffer_replace_range(app, &buffer, buffer.size, buffer.size, stream->buffer, buffer_size); + stream->buffering_arena->pos -= buffer_size; +} + +static void +buffered_write_stream_write(Application_Links *app, Buffered_Write_Stream *stream, String text){ + for (;text.size > 0;){ + char *buffered = push_array(stream->buffering_arena, char, text.size); + if (buffered != 0){ + memcpy(buffered, text.str, text.size); + text.size = 0; + } + else{ + int32_t partial_size = partition_remaining(stream->buffering_arena); + buffered = push_array(stream->buffering_arena, char, partial_size); + Assert(partial_size < text.size); + memcpy(buffered, text.str, partial_size); + text.size -= partial_size; + text.str += partial_size; + buffered_write_stream_flush(app, stream); + } + } +} + static Get_Positions_Results get_function_positions(Application_Links *app, Buffer_Summary *buffer, int32_t token_index, Function_Positions *positions_array, int32_t positions_max){ Get_Positions_Results result = {}; @@ -143,26 +180,17 @@ get_function_positions(Application_Links *app, Buffer_Summary *buffer, int32_t t } static void -print_positions(Application_Links *app, Buffer_Summary *buffer, Function_Positions *positions_array, int32_t positions_count, Buffer_Summary *output_buffer, Partition *part){ - - Temp_Memory temp = begin_temp_memory(part); - - Partition extra_memory_ = partition_sub_part(part, (4<<10)); - Partition *extra_memory = &extra_memory_; - - char *str_ptr = (char*)partition_current(part); - int32_t part_size = 0; +print_positions_buffered(Application_Links *app, Buffer_Summary *buffer, Function_Positions *positions_array, int32_t positions_count, Buffered_Write_Stream *stream){ String buffer_name = make_string(buffer->buffer_name, buffer->buffer_name_len); - int32_t size = output_buffer->size; for (int32_t i = 0; i < positions_count; ++i){ Function_Positions *positions = &positions_array[i]; - Temp_Memory extra_temp = begin_temp_memory(extra_memory); int32_t local_index = positions->sig_start_index; int32_t end_index = positions->sig_end_index; int32_t open_paren_pos = positions->open_paren_pos; + int32_t line_number = buffer_get_line_number(app, buffer, open_paren_pos); Assert(end_index > local_index); @@ -170,105 +198,60 @@ print_positions(Application_Links *app, Buffer_Summary *buffer, Function_Positio Cpp_Token sig_chunk[sig_chunk_size]; Stream_Tokens sig_stream = {}; if (init_stream_tokens(&sig_stream, app, buffer, local_index, sig_chunk, sig_chunk_size)){ + buffered_write_stream_write(app, stream, buffer_name); + buffered_write_stream_write(app, stream, make_lit_string(":")); + { + char space[64]; + String integer_string = make_fixed_width_string(space); + append_int_to_str(&integer_string, line_number); + buffered_write_stream_write(app, stream, integer_string); + } + buffered_write_stream_write(app, stream, make_lit_string(": ")); + bool32 still_looping = false; do{ + Cpp_Token prev_token = {}; for (; local_index < sig_stream.end; ++local_index){ Cpp_Token *token = &sig_stream.tokens[local_index]; - if (!(token->flags & CPP_TFLAG_PP_BODY) && token->type != CPP_TOKEN_COMMENT){ - bool32 delete_space_before = false; - bool32 space_after = false; - - switch (token->type){ - case CPP_TOKEN_PARENTHESE_OPEN: - case CPP_TOKEN_PARENTHESE_CLOSE: - { - delete_space_before = true; - }break; - - case CPP_TOKEN_IDENTIFIER: - case CPP_TOKEN_STAR: - { - space_after = true; - }break; - - case CPP_TOKEN_COMMA: - { - delete_space_before = true; - space_after = true; - }break; + if ((token->flags & CPP_TFLAG_PP_BODY) == 0 && token->type != CPP_TOKEN_COMMENT){ + char space[2 << 10]; + int32_t token_size = token->size; + if (token_size > sizeof(space)){ + token_size = sizeof(space); } + buffer_read_range(app, buffer, token->start, token->start + token_size, space); - if (token->flags & CPP_TFLAG_IS_KEYWORD){ - space_after = true; - } + bool32 insert_space = (/**/ + (prev_token.type == CPP_TOKEN_IDENTIFIER || + prev_token.type == CPP_TOKEN_STAR || + prev_token.type == CPP_TOKEN_COMMA || + (prev_token.flags & CPP_TFLAG_IS_KEYWORD) != 0 + ) && + !(token->type == CPP_TOKEN_PARENTHESE_OPEN || + token->type == CPP_TOKEN_PARENTHESE_CLOSE || + token->type == CPP_TOKEN_COMMA + ) + ); - if (delete_space_before){ - int32_t pos = extra_memory->pos - 1; - char *base = ((char*)(extra_memory->base)); - if (pos >= 0 && base[pos] == ' '){ - extra_memory->pos = pos; - } - } - - char *token_str = push_array(extra_memory, char, token->size + space_after); - if (token_str != 0){ - buffer_read_range(app, buffer, token->start, token->start + token->size, token_str); - if (space_after){ - token_str[token->size] = ' '; - } - } - else{ - goto finish_print; + if (insert_space){ + buffered_write_stream_write(app, stream, make_lit_string(" ")); } + buffered_write_stream_write(app, stream, make_string(space, token_size)); + prev_token = *token; } if (local_index == end_index){ - goto finish_print; + goto doublebreak; } } still_looping = forward_stream_tokens(&sig_stream); }while(still_looping); + doublebreak:; - finish_print:; - { - int32_t sig_size = extra_memory->pos; - String sig = make_string(extra_memory->base, sig_size); - - int32_t line_number = buffer_get_line_number(app, buffer, open_paren_pos); - int32_t line_number_len = int_to_str_size(line_number); - - int32_t append_len = buffer_name.size + 1 + line_number_len + 1 + 1 + sig_size + 1; - - char *out_space = push_array(part, char, append_len); - if (out_space == 0){ - buffer_replace_range(app, output_buffer, size, size, str_ptr, part_size); - size += part_size; - - end_temp_memory(temp); - temp = begin_temp_memory(part); - - part_size = 0; - out_space = push_array(part, char, append_len); - } - - part_size += append_len; - String out = make_string(out_space, 0, append_len); - append(&out, buffer_name); - append(&out, ':'); - append_int_to_str(&out, line_number); - append(&out, ':'); - append(&out, ' '); - append(&out, sig); - append(&out, '\n'); - } + buffered_write_stream_write(app, stream, make_lit_string("\n")); } - - end_temp_memory(extra_temp); } - - buffer_replace_range(app, output_buffer, size, size, str_ptr, part_size); - end_temp_memory(temp); } static void @@ -291,6 +274,8 @@ list_all_functions(Application_Links *app, Partition *part, Buffer_Summary *opti int32_t positions_max = (4<<10)/sizeof(Function_Positions); Function_Positions *positions_array = push_array(part, Function_Positions, positions_max); + Buffered_Write_Stream buffered_write_stream = make_buffered_write_stream(decls_buffer.buffer_id, part); + for (Buffer_Summary buffer_it = get_buffer_first(app, AccessAll); buffer_it.exists; get_buffer_next(app, &buffer_it, AccessAll)){ @@ -312,7 +297,8 @@ list_all_functions(Application_Links *app, Partition *part, Buffer_Summary *opti token_index = get_positions_results.next_token_index; still_looping = get_positions_results.still_looping; - print_positions(app, &buffer, positions_array, positions_count, &decls_buffer, part); + print_positions_buffered(app, &buffer, positions_array, positions_count, &buffered_write_stream); + //print_positions(app, &buffer, positions_array, positions_count, &decls_buffer, part); }while(still_looping); if (optional_target_buffer != 0){ @@ -320,6 +306,8 @@ list_all_functions(Application_Links *app, Partition *part, Buffer_Summary *opti } } + buffered_write_stream_flush(app, &buffered_write_stream); + View_Summary view = get_active_view(app, AccessAll); view_set_buffer(app, &view, decls_buffer.buffer_id, 0); diff --git a/4coder_function_list.h b/4coder_function_list.h index 7d9db9cd..37316be4 100644 --- a/4coder_function_list.h +++ b/4coder_function_list.h @@ -19,6 +19,12 @@ struct Get_Positions_Results{ bool32 still_looping; }; +struct Buffered_Write_Stream{ + Buffer_ID output_buffer_id; + Partition *buffering_arena; + char *buffer; +}; + #endif // BOTTOM diff --git a/4coder_generated/command_metadata.h b/4coder_generated/command_metadata.h index 8ee7c589..204f015d 100644 --- a/4coder_generated/command_metadata.h +++ b/4coder_generated/command_metadata.h @@ -270,7 +270,7 @@ static Command_Metadata fcoder_metacmd_table[228] = { { PROC_LINKS(close_all_code, 0), "close_all_code", 14, "Closes any buffer with a filename ending with an extension configured to be recognized as a code file type.", 107, "w:\\4ed\\code\\4coder_project_commands.cpp", 39, 1060 }, { PROC_LINKS(close_build_panel, 0), "close_build_panel", 17, "If the special build panel is open, closes it.", 46, "w:\\4ed\\code\\4coder_build_commands.cpp", 37, 203 }, { PROC_LINKS(close_panel, 0), "close_panel", 11, "Closes the currently active panel if it is not the only panel open.", 67, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 484 }, -{ PROC_LINKS(command_lister, 0), "command_lister", 14, "Opens an interactive list of all registered commands.", 53, "w:\\4ed\\code\\4coder_lists.cpp", 28, 938 }, +{ PROC_LINKS(command_lister, 0), "command_lister", 14, "Opens an interactive list of all registered commands.", 53, "w:\\4ed\\code\\4coder_lists.cpp", 28, 935 }, { PROC_LINKS(copy, 0), "copy", 4, "Copy the text in the range from the cursor to the mark onto the clipboard.", 74, "w:\\4ed\\code\\4coder_clipboard.cpp", 32, 26 }, { PROC_LINKS(cursor_mark_swap, 0), "cursor_mark_swap", 16, "Swaps the position of the cursor and the mark.", 46, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 96 }, { PROC_LINKS(cut, 0), "cut", 3, "Cut the text in the range from the cursor to the mark onto the clipboard.", 73, "w:\\4ed\\code\\4coder_clipboard.cpp", 32, 35 }, @@ -311,18 +311,18 @@ static Command_Metadata fcoder_metacmd_table[228] = { { PROC_LINKS(if0_off, 0), "if0_off", 7, "Surround the range between the cursor and mark with an '#if 0' and an '#endif'", 78, "w:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 81 }, { PROC_LINKS(increase_face_size, 0), "increase_face_size", 18, "Increase the size of the face used by the current buffer.", 57, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 562 }, { PROC_LINKS(increase_line_wrap, 0), "increase_line_wrap", 18, "Increases the current buffer's width for line wrapping.", 55, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 540 }, -{ PROC_LINKS(interactive_kill_buffer, 0), "interactive_kill_buffer", 23, "Interactively kill an open buffer.", 34, "w:\\4ed\\code\\4coder_lists.cpp", 28, 751 }, -{ PROC_LINKS(interactive_new, 0), "interactive_new", 15, "Interactively creates a new file.", 33, "w:\\4ed\\code\\4coder_lists.cpp", 28, 856 }, -{ PROC_LINKS(interactive_open, 0), "interactive_open", 16, "Interactively opens a file.", 27, "w:\\4ed\\code\\4coder_lists.cpp", 28, 884 }, -{ PROC_LINKS(interactive_open_or_new, 0), "interactive_open_or_new", 23, "Interactively open a file out of the file system.", 49, "w:\\4ed\\code\\4coder_lists.cpp", 28, 822 }, -{ PROC_LINKS(interactive_switch_buffer, 0), "interactive_switch_buffer", 25, "Interactively switch to an open buffer.", 39, "w:\\4ed\\code\\4coder_lists.cpp", 28, 732 }, +{ PROC_LINKS(interactive_kill_buffer, 0), "interactive_kill_buffer", 23, "Interactively kill an open buffer.", 34, "w:\\4ed\\code\\4coder_lists.cpp", 28, 748 }, +{ PROC_LINKS(interactive_new, 0), "interactive_new", 15, "Interactively creates a new file.", 33, "w:\\4ed\\code\\4coder_lists.cpp", 28, 853 }, +{ PROC_LINKS(interactive_open, 0), "interactive_open", 16, "Interactively opens a file.", 27, "w:\\4ed\\code\\4coder_lists.cpp", 28, 881 }, +{ PROC_LINKS(interactive_open_or_new, 0), "interactive_open_or_new", 23, "Interactively open a file out of the file system.", 49, "w:\\4ed\\code\\4coder_lists.cpp", 28, 819 }, +{ PROC_LINKS(interactive_switch_buffer, 0), "interactive_switch_buffer", 25, "Interactively switch to an open buffer.", 39, "w:\\4ed\\code\\4coder_lists.cpp", 28, 729 }, { PROC_LINKS(kill_buffer, 0), "kill_buffer", 11, "Kills the current buffer.", 25, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1538 }, { PROC_LINKS(kill_rect, 0), "kill_rect", 9, "Delete characters in a rectangular region. Range testing is done by unwrapped-xy coordinates.", 93, "w:\\4ed\\code\\4coder_experiments.cpp", 34, 26 }, { PROC_LINKS(left_adjust_view, 0), "left_adjust_view", 16, "Sets the left size of the view near the x position of the cursor.", 65, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 133 }, -{ PROC_LINKS(list_all_functions_all_buffers, 0), "list_all_functions_all_buffers", 30, "Creates a jump list of lines from all buffers that appear to define or declare functions.", 89, "w:\\4ed\\code\\4coder_function_list.cpp", 36, 355 }, -{ PROC_LINKS(list_all_functions_all_buffers_lister, 0), "list_all_functions_all_buffers_lister", 37, "Creates a lister of locations that look like function definitions and declarations all buffers.", 95, "w:\\4ed\\code\\4coder_function_list.cpp", 36, 361 }, -{ PROC_LINKS(list_all_functions_current_buffer, 0), "list_all_functions_current_buffer", 33, "Creates a jump list of lines of the current buffer that appear to define or declare functions.", 94, "w:\\4ed\\code\\4coder_function_list.cpp", 36, 332 }, -{ PROC_LINKS(list_all_functions_current_buffer_lister, 0), "list_all_functions_current_buffer_lister", 40, "Creates a lister of locations that look like function definitions and declarations in the buffer.", 97, "w:\\4ed\\code\\4coder_function_list.cpp", 36, 342 }, +{ PROC_LINKS(list_all_functions_all_buffers, 0), "list_all_functions_all_buffers", 30, "Creates a jump list of lines from all buffers that appear to define or declare functions.", 89, "w:\\4ed\\code\\4coder_function_list.cpp", 36, 343 }, +{ PROC_LINKS(list_all_functions_all_buffers_lister, 0), "list_all_functions_all_buffers_lister", 37, "Creates a lister of locations that look like function definitions and declarations all buffers.", 95, "w:\\4ed\\code\\4coder_function_list.cpp", 36, 349 }, +{ PROC_LINKS(list_all_functions_current_buffer, 0), "list_all_functions_current_buffer", 33, "Creates a jump list of lines of the current buffer that appear to define or declare functions.", 94, "w:\\4ed\\code\\4coder_function_list.cpp", 36, 320 }, +{ PROC_LINKS(list_all_functions_current_buffer_lister, 0), "list_all_functions_current_buffer_lister", 40, "Creates a lister of locations that look like function definitions and declarations in the buffer.", 97, "w:\\4ed\\code\\4coder_function_list.cpp", 36, 330 }, { PROC_LINKS(list_all_locations, 0), "list_all_locations", 18, "Queries the user for a string and lists all exact case-sensitive matches found in all open buffers.", 99, "w:\\4ed\\code\\4coder_search.cpp", 29, 769 }, { PROC_LINKS(list_all_locations_case_insensitive, 0), "list_all_locations_case_insensitive", 35, "Queries the user for a string and lists all exact case-insensitive matches found in all open buffers.", 101, "w:\\4ed\\code\\4coder_search.cpp", 29, 783 }, { PROC_LINKS(list_all_locations_of_identifier, 0), "list_all_locations_of_identifier", 32, "Reads a token or word under the cursor and lists all exact case-sensitive mathces in all open buffers.", 102, "w:\\4ed\\code\\4coder_search.cpp", 29, 797 }, @@ -375,7 +375,7 @@ static Command_Metadata fcoder_metacmd_table[228] = { { PROC_LINKS(newline_or_goto_position_sticky, 0), "newline_or_goto_position_sticky", 31, "If the buffer in the active view is writable, inserts a character, otherwise performs goto_jump_at_cursor.", 106, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 573 }, { PROC_LINKS(open_all_code, 0), "open_all_code", 13, "Open all code in the current directory. File types are determined by extensions. An extension is considered code based on the extensions specified in 4coder.config.", 164, "w:\\4ed\\code\\4coder_project_commands.cpp", 39, 1067 }, { PROC_LINKS(open_all_code_recursive, 0), "open_all_code_recursive", 23, "Works as open_all_code but also runs in all subdirectories.", 59, "w:\\4ed\\code\\4coder_project_commands.cpp", 39, 1074 }, -{ PROC_LINKS(open_color_tweaker, 0), "open_color_tweaker", 18, "Opens the 4coder theme selector list.", 37, "w:\\4ed\\code\\4coder_lists.cpp", 28, 900 }, +{ PROC_LINKS(open_color_tweaker, 0), "open_color_tweaker", 18, "Opens the 4coder theme selector list.", 37, "w:\\4ed\\code\\4coder_lists.cpp", 28, 897 }, { PROC_LINKS(open_file_in_quotes, 0), "open_file_in_quotes", 19, "Reads a filename from surrounding '\"' characters and attempts to open the corresponding file.", 94, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1445 }, { PROC_LINKS(open_in_other, 0), "open_in_other", 13, "Interactively opens a file in the other panel.", 46, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1600 }, { PROC_LINKS(open_long_braces, 0), "open_long_braces", 16, "At the cursor, insert a '{' and '}' separated by a blank line.", 62, "w:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 57 }, @@ -449,7 +449,7 @@ static Command_Metadata fcoder_metacmd_table[228] = { { PROC_LINKS(show_scrollbar, 0), "show_scrollbar", 14, "Sets the current view to show it's scrollbar.", 45, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 493 }, { PROC_LINKS(snipe_token_or_word, 0), "snipe_token_or_word", 19, "Delete a single, whole token on or to the left of the cursor and post it to the clipboard.", 90, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1270 }, { PROC_LINKS(snipe_token_or_word_right, 0), "snipe_token_or_word_right", 25, "Delete a single, whole token on or to the right of the cursor and post it to the clipboard.", 91, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1276 }, -{ PROC_LINKS(snippet_lister, 0), "snippet_lister", 14, "Opens a snippet lister for inserting whole pre-written snippets of text.", 72, "w:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 193 }, +{ PROC_LINKS(snippet_lister, 0), "snippet_lister", 14, "Opens a snippet lister for inserting whole pre-written snippets of text.", 72, "w:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 191 }, { PROC_LINKS(suppress_mouse, 0), "suppress_mouse", 14, "Hides the mouse and causes all mosue input (clicks, position, wheel) to be ignored.", 83, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 234 }, { PROC_LINKS(swap_buffers_between_panels, 0), "swap_buffers_between_panels", 27, "Set the other non-active panel to view the buffer that the active panel views, and switch to that panel.", 104, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1505 }, { PROC_LINKS(to_lowercase, 0), "to_lowercase", 12, "Converts all ascii text in the range between the cursor and the mark to lowercase.", 82, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 391 }, diff --git a/4coder_jump_lister.cpp b/4coder_jump_lister.cpp index 9a0bd62e..ca641d7d 100644 --- a/4coder_jump_lister.cpp +++ b/4coder_jump_lister.cpp @@ -81,8 +81,8 @@ open_jump_lister(Application_Links *app, Partition *scratch, Heap *heap, managed_object_load_data(app, stored_jumps, i, 1, &stored); String line = {}; read_line(app, scratch, &list_buffer, stored.list_line, &line); - options[i].string = line.str; - options[i].status = 0; + options[i].string = line; + memset(&options[i].status, 0, sizeof(options[i].status)); options[i].user_data = IntAsPtr(i); int32_t aligned_size = line.size + 1 + 7; aligned_size = aligned_size - aligned_size%8; diff --git a/4coder_lib/4coder_string.h b/4coder_lib/4coder_string.h index eea1c758..12b224c9 100644 --- a/4coder_lib/4coder_string.h +++ b/4coder_lib/4coder_string.h @@ -1,5 +1,5 @@ /* -4coder_string.h - Version 1.0.117 +4coder_string.h - Version 1.0.121 no warranty implied; use at your own risk This software is in the public domain. Where that dedication is not @@ -12,7 +12,37 @@ To use in C mode: #define FSTRING_C // TOP +// 4tech_standard_preamble.h +#if !defined(FTECH_INTEGERS) +#define FTECH_INTEGERS +#include +typedef int8_t i8_4tech; +typedef int16_t i16_4tech; +typedef int32_t i32_4tech; +typedef int64_t i64_4tech; +typedef uint8_t u8_4tech; +typedef uint16_t u16_4tech; +typedef uint32_t u32_4tech; +typedef uint64_t u64_4tech; + +#if defined(FTECH_32_BIT) +typedef u32_4tech umem_4tech; +#else +typedef u64_4tech umem_4tech; +#endif + +typedef float f32_4tech; +typedef double f64_4tech; + +typedef int8_t b8_4tech; +typedef int32_t b32_4tech; +#endif + +#if !defined(Assert) +# define Assert(n) do{ if (!(n)) *(int*)0 = 0xA11E; }while(0) +#endif +// standard preamble end #if !defined(FSTRING_LINK) # define FSTRING_LINK static @@ -27,7 +57,7 @@ To use in C mode: #define FSTRING_C #endif #if !defined(FSTRING_GUARD) -#define literal(s) (s), (sizeof(s)-1) +#define literal(s) (s), (sizeof(s) - 1) typedef struct String{ char *str; @@ -280,7 +310,7 @@ FSTRING_LINK b32_4tech string_set_match(void *str_set, i32_4tech ite // #if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech +FSTRING_INLINE b32_4tech char_is_slash(char c) { return (c == '\\' || c == '/'); @@ -288,7 +318,7 @@ char_is_slash(char c) #endif #if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech +FSTRING_INLINE b32_4tech char_is_upper(char c) { return (c >= 'A' && c <= 'Z'); @@ -296,7 +326,7 @@ char_is_upper(char c) #endif #if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech +FSTRING_INLINE b32_4tech char_is_upper_utf8(char c) { return ((c >= 'A' && c <= 'Z') || (unsigned char)c >= 128); @@ -304,7 +334,7 @@ char_is_upper_utf8(char c) #endif #if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech +FSTRING_INLINE b32_4tech char_is_lower(char c) { return (c >= 'a' && c <= 'z'); @@ -312,7 +342,7 @@ char_is_lower(char c) #endif #if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech +FSTRING_INLINE b32_4tech char_is_lower_utf8(u8_4tech c) { return ((c >= 'a' && c <= 'z') || (unsigned char)c >= 128); @@ -320,7 +350,7 @@ char_is_lower_utf8(u8_4tech c) #endif #if !defined(FSTRING_GUARD) - FSTRING_INLINE char +FSTRING_INLINE char char_to_upper(char c) { return (c >= 'a' && c <= 'z') ? c + (char)('A' - 'a') : c; @@ -328,7 +358,7 @@ char_to_upper(char c) #endif #if !defined(FSTRING_GUARD) - FSTRING_INLINE char +FSTRING_INLINE char char_to_lower(char c) { return (c >= 'A' && c <= 'Z') ? c - (char)('A' - 'a') : c; @@ -336,7 +366,7 @@ char_to_lower(char c) #endif #if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech +FSTRING_INLINE b32_4tech char_is_whitespace(char c) { return (c == ' ' || c == '\n' || c == '\r' || c == '\t'); @@ -344,7 +374,7 @@ char_is_whitespace(char c) #endif #if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech +FSTRING_INLINE b32_4tech char_is_alpha_numeric(char c) { return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_'); @@ -352,7 +382,7 @@ char_is_alpha_numeric(char c) #endif #if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech +FSTRING_INLINE b32_4tech char_is_alpha_numeric_utf8(u8_4tech c) { return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_' || (unsigned char)c >= 128); @@ -360,7 +390,7 @@ char_is_alpha_numeric_utf8(u8_4tech c) #endif #if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech +FSTRING_INLINE b32_4tech char_is_alpha_numeric_true(char c) { return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9')); @@ -368,7 +398,7 @@ char_is_alpha_numeric_true(char c) #endif #if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech +FSTRING_INLINE b32_4tech char_is_alpha_numeric_true_utf8(u8_4tech c) { return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || (unsigned char)c >= 128); @@ -376,7 +406,7 @@ char_is_alpha_numeric_true_utf8(u8_4tech c) #endif #if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech +FSTRING_INLINE b32_4tech char_is_alpha(char c) { return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_'); @@ -384,7 +414,7 @@ char_is_alpha(char c) #endif #if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech +FSTRING_INLINE b32_4tech char_is_alpha_utf8(u8_4tech c) { return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || (unsigned char)c >= 128); @@ -392,7 +422,7 @@ char_is_alpha_utf8(u8_4tech c) #endif #if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech +FSTRING_INLINE b32_4tech char_is_alpha_true(char c) { return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')); @@ -400,7 +430,7 @@ char_is_alpha_true(char c) #endif #if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech +FSTRING_INLINE b32_4tech char_is_alpha_true_utf8(u8_4tech c) { return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (unsigned char)c >= 128); @@ -408,7 +438,7 @@ char_is_alpha_true_utf8(u8_4tech c) #endif #if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech +FSTRING_INLINE b32_4tech char_is_hex(char c) { return ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f')); @@ -416,7 +446,7 @@ char_is_hex(char c) #endif #if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech +FSTRING_INLINE b32_4tech char_is_hex_utf8(u8_4tech c) { return ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f') || (unsigned char)c >= 128); @@ -424,7 +454,7 @@ char_is_hex_utf8(u8_4tech c) #endif #if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech +FSTRING_INLINE b32_4tech char_is_numeric(char c) { return (c >= '0' && c <= '9'); @@ -432,7 +462,7 @@ char_is_numeric(char c) #endif #if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech +FSTRING_INLINE b32_4tech char_is_numeric_utf8(u8_4tech c) { return ((c >= '0' && c <= '9') || (unsigned char)c >= 128); @@ -446,7 +476,7 @@ char_is_numeric_utf8(u8_4tech c) #if !defined(FSTRING_GUARD) - FSTRING_INLINE String +FSTRING_INLINE String make_string_cap(void *str, i32_4tech size, i32_4tech mem_size){ String result; result.str = (char*)str; @@ -457,14 +487,14 @@ make_string_cap(void *str, i32_4tech size, i32_4tech mem_size){ #endif #if !defined(FSTRING_GUARD) - FSTRING_INLINE String +FSTRING_INLINE String make_string(void *str, i32_4tech size){ return(make_string(str, size, size)); } #endif #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech +FSTRING_LINK i32_4tech str_size(char *str) { i32_4tech i = 0; @@ -476,7 +506,7 @@ str_size(char *str) #endif #if !defined(FSTRING_GUARD) - FSTRING_INLINE String +FSTRING_INLINE String make_string_slowly(void *str) { String result; @@ -489,7 +519,7 @@ make_string_slowly(void *str) #if !defined(FSTRING_GUARD) - FSTRING_INLINE String +FSTRING_INLINE String substr_tail(String str, i32_4tech start) { String result; @@ -501,7 +531,7 @@ substr_tail(String str, i32_4tech start) #endif #if !defined(FSTRING_GUARD) - FSTRING_INLINE String +FSTRING_INLINE String substr(String str, i32_4tech start, i32_4tech size) { String result; @@ -516,7 +546,7 @@ substr(String str, i32_4tech start, i32_4tech size) #endif #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK String +FSTRING_LINK String skip_whitespace(String str) { String result = {}; @@ -529,7 +559,7 @@ skip_whitespace(String str) #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK String +FSTRING_LINK String skip_whitespace_measure(String str, i32_4tech *skip_length) { String result = {}; @@ -542,7 +572,7 @@ skip_whitespace_measure(String str, i32_4tech *skip_length) #endif #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK String +FSTRING_LINK String chop_whitespace(String str) { String result = {}; @@ -554,7 +584,7 @@ chop_whitespace(String str) #endif #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK String +FSTRING_LINK String skip_chop_whitespace(String str) { str = skip_whitespace(str); @@ -565,7 +595,7 @@ skip_chop_whitespace(String str) #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK String +FSTRING_LINK String skip_chop_whitespace_measure(String str, i32_4tech *skip_length) { str = skip_whitespace_measure(str, skip_length); @@ -575,7 +605,7 @@ skip_chop_whitespace_measure(String str, i32_4tech *skip_length) #endif #if !defined(FSTRING_GUARD) - FSTRING_INLINE String +FSTRING_INLINE String tailstr(String str) { String result; @@ -593,7 +623,7 @@ tailstr(String str) #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech +FSTRING_LINK b32_4tech match_cc(char *a, char *b){ for (i32_4tech i = 0;; ++i){ if (a[i] != b[i]){ @@ -608,7 +638,7 @@ match_cc(char *a, char *b){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech +FSTRING_LINK b32_4tech match_sc(String a, char *b){ i32_4tech i = 0; for (; i < a.size; ++i){ @@ -625,7 +655,7 @@ match_sc(String a, char *b){ #if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech +FSTRING_INLINE b32_4tech match_cs(char *a, String b){ return(match_sc(b,a)); } @@ -633,7 +663,7 @@ match_cs(char *a, String b){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech +FSTRING_LINK b32_4tech match_ss(String a, String b){ if (a.size != b.size){ return 0; @@ -649,7 +679,7 @@ match_ss(String a, String b){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech +FSTRING_LINK b32_4tech match_part_ccl(char *a, char *b, i32_4tech *len){ if (a == 0){ a = ""; @@ -671,7 +701,7 @@ match_part_ccl(char *a, char *b, i32_4tech *len){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech +FSTRING_LINK b32_4tech match_part_scl(String a, char *b, i32_4tech *len){ if (b == 0){ b = ""; @@ -689,7 +719,7 @@ match_part_scl(String a, char *b, i32_4tech *len){ #if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech +FSTRING_INLINE b32_4tech match_part_cc(char *a, char *b){ i32_4tech x; return match_part_ccl(a,b,&x); @@ -698,7 +728,7 @@ match_part_cc(char *a, char *b){ #if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech +FSTRING_INLINE b32_4tech match_part_sc(String a, char *b){ i32_4tech x; return match_part_scl(a,b,&x); @@ -707,7 +737,7 @@ match_part_sc(String a, char *b){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech +FSTRING_LINK b32_4tech match_part_cs(char *a, String b){ for (i32_4tech i = 0; i != b.size; ++i){ if (a[i] != b.str[i]){ @@ -720,7 +750,7 @@ match_part_cs(char *a, String b){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech +FSTRING_LINK b32_4tech match_part_ss(String a, String b){ if (a.size < b.size){ return(0); @@ -736,7 +766,7 @@ match_part_ss(String a, String b){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech +FSTRING_LINK b32_4tech match_insensitive_cc(char *a, char *b){ for (i32_4tech i = 0;; ++i){ if (char_to_upper(a[i]) != @@ -752,7 +782,7 @@ match_insensitive_cc(char *a, char *b){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech +FSTRING_LINK b32_4tech match_insensitive_sc(String a, char *b){ i32_4tech i = 0; for (; i < a.size; ++i){ @@ -770,7 +800,7 @@ match_insensitive_sc(String a, char *b){ #if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech +FSTRING_INLINE b32_4tech match_insensitive_cs(char *a, String b){ return match_insensitive_sc(b,a); } @@ -778,7 +808,7 @@ match_insensitive_cs(char *a, String b){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech +FSTRING_LINK b32_4tech match_insensitive_ss(String a, String b){ if (a.size != b.size){ return 0; @@ -795,7 +825,7 @@ match_insensitive_ss(String a, String b){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech +FSTRING_LINK b32_4tech match_part_insensitive_ccl(char *a, char *b, i32_4tech *len){ i32_4tech i; for (i = 0; b[i] != 0; ++i){ @@ -810,7 +840,7 @@ match_part_insensitive_ccl(char *a, char *b, i32_4tech *len){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech +FSTRING_LINK b32_4tech match_part_insensitive_scl(String a, char *b, i32_4tech *len){ i32_4tech i; for (i = 0; b[i] != 0; ++i){ @@ -826,7 +856,7 @@ match_part_insensitive_scl(String a, char *b, i32_4tech *len){ #if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech +FSTRING_INLINE b32_4tech match_part_insensitive_cc(char *a, char *b){ i32_4tech x; return match_part_insensitive_ccl(a,b,&x); @@ -835,7 +865,7 @@ match_part_insensitive_cc(char *a, char *b){ #if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech +FSTRING_INLINE b32_4tech match_part_insensitive_sc(String a, char *b){ i32_4tech x; return match_part_insensitive_scl(a,b,&x); @@ -844,7 +874,7 @@ match_part_insensitive_sc(String a, char *b){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech +FSTRING_LINK b32_4tech match_part_insensitive_cs(char *a, String b){ for (i32_4tech i = 0; i != b.size; ++i){ if (char_to_upper(a[i]) != char_to_upper(b.str[i])){ @@ -857,7 +887,7 @@ match_part_insensitive_cs(char *a, String b){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech +FSTRING_LINK b32_4tech match_part_insensitive_ss(String a, String b){ if (a.size < b.size){ return(0); @@ -873,7 +903,7 @@ match_part_insensitive_ss(String a, String b){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech +FSTRING_LINK i32_4tech compare_cc(char *a, char *b){ i32_4tech i = 0, r = 0; while (a[i] == b[i] && a[i] != 0){ @@ -886,7 +916,7 @@ compare_cc(char *a, char *b){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech +FSTRING_LINK i32_4tech compare_sc(String a, char *b){ i32_4tech i = 0, r = 0; while (i < a.size && a.str[i] == b[i]){ @@ -909,7 +939,7 @@ compare_sc(String a, char *b){ #if !defined(FSTRING_GUARD) - FSTRING_INLINE i32_4tech +FSTRING_INLINE i32_4tech compare_cs(char *a, String b){ i32_4tech r = -compare_sc(b,a); return(r); @@ -918,7 +948,7 @@ compare_cs(char *a, String b){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech +FSTRING_LINK i32_4tech compare_ss(String a, String b){ i32_4tech i = 0, r = 0; i32_4tech m = a.size; @@ -946,7 +976,7 @@ compare_ss(String a, String b){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech +FSTRING_LINK i32_4tech find_c_char(char *str, i32_4tech start, char character){ i32_4tech i = start; while (str[i] != character && str[i] != 0) ++i; @@ -956,7 +986,7 @@ find_c_char(char *str, i32_4tech start, char character){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech +FSTRING_LINK i32_4tech find_s_char(String str, i32_4tech start, char character){ i32_4tech i = start; while (i < str.size && str.str[i] != character) ++i; @@ -966,7 +996,7 @@ find_s_char(String str, i32_4tech start, char character){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech +FSTRING_LINK i32_4tech rfind_s_char(String str, i32_4tech start, char character){ i32_4tech i = start; while (i >= 0 && str.str[i] != character) --i; @@ -976,7 +1006,7 @@ rfind_s_char(String str, i32_4tech start, char character){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech +FSTRING_LINK i32_4tech find_c_chars(char *str, i32_4tech start, char *characters){ i32_4tech i = start, j; while (str[i] != 0){ @@ -993,7 +1023,7 @@ find_c_chars(char *str, i32_4tech start, char *characters){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech +FSTRING_LINK i32_4tech find_s_chars(String str, i32_4tech start, char *characters){ i32_4tech i = start, j; while (i < str.size){ @@ -1010,7 +1040,7 @@ find_s_chars(String str, i32_4tech start, char *characters){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech +FSTRING_LINK i32_4tech find_substr_c(char *str, i32_4tech start, String seek){ i32_4tech i, j, k; b32_4tech hit; @@ -1039,7 +1069,7 @@ find_substr_c(char *str, i32_4tech start, String seek){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech +FSTRING_LINK i32_4tech find_substr_s(String str, i32_4tech start, String seek){ i32_4tech stop_at, i, j, k; b32_4tech hit; @@ -1068,7 +1098,7 @@ find_substr_s(String str, i32_4tech start, String seek){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech +FSTRING_LINK i32_4tech rfind_substr_s(String str, i32_4tech start, String seek){ i32_4tech i, j, k; b32_4tech hit; @@ -1099,7 +1129,7 @@ rfind_substr_s(String str, i32_4tech start, String seek){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech +FSTRING_LINK i32_4tech find_substr_insensitive_c(char *str, i32_4tech start, String seek){ i32_4tech i, j, k; b32_4tech hit; @@ -1133,7 +1163,7 @@ find_substr_insensitive_c(char *str, i32_4tech start, String seek){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech +FSTRING_LINK i32_4tech find_substr_insensitive_s(String str, i32_4tech start, String seek){ i32_4tech i, j, k; i32_4tech stop_at; @@ -1169,7 +1199,7 @@ find_substr_insensitive_s(String str, i32_4tech start, String seek){ #if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech +FSTRING_INLINE b32_4tech has_substr_c(char *s, String seek){ return (s[find_substr_c(s, 0, seek)] != 0); } @@ -1177,7 +1207,7 @@ has_substr_c(char *s, String seek){ #if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech +FSTRING_INLINE b32_4tech has_substr_s(String s, String seek){ return (find_substr_s(s, 0, seek) < s.size); } @@ -1185,7 +1215,7 @@ has_substr_s(String s, String seek){ #if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech +FSTRING_INLINE b32_4tech has_substr_insensitive_c(char *s, String seek){ return (s[find_substr_insensitive_c(s, 0, seek)] != 0); } @@ -1193,7 +1223,7 @@ has_substr_insensitive_c(char *s, String seek){ #if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech +FSTRING_INLINE b32_4tech has_substr_insensitive_s(String s, String seek){ return (find_substr_insensitive_s(s, 0, seek) < s.size); } @@ -1205,7 +1235,7 @@ has_substr_insensitive_s(String s, String seek){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech +FSTRING_LINK i32_4tech copy_fast_unsafe_cc(char *dest, char *src){ char *start = dest; while (*src != 0){ @@ -1219,7 +1249,7 @@ copy_fast_unsafe_cc(char *dest, char *src){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech +FSTRING_LINK i32_4tech copy_fast_unsafe_cs(char *dest, String src){ i32_4tech i = 0; while (i != src.size){ @@ -1232,7 +1262,7 @@ copy_fast_unsafe_cs(char *dest, String src){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech +FSTRING_LINK b32_4tech copy_checked_ss(String *dest, String src){ char *dest_str; i32_4tech i; @@ -1250,7 +1280,7 @@ copy_checked_ss(String *dest, String src){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech +FSTRING_LINK b32_4tech copy_checked_cs(char *dest, i32_4tech dest_cap, String src){ i32_4tech i; if (dest_cap < src.size){ @@ -1265,7 +1295,7 @@ copy_checked_cs(char *dest, i32_4tech dest_cap, String src){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech +FSTRING_LINK b32_4tech copy_partial_sc(String *dest, char *src){ i32_4tech i = 0; i32_4tech memory_size = dest->memory_size; @@ -1284,7 +1314,7 @@ copy_partial_sc(String *dest, char *src){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech +FSTRING_LINK b32_4tech copy_partial_ss(String *dest, String src){ char *dest_str = dest->str; i32_4tech memory_size = dest->memory_size; @@ -1303,7 +1333,7 @@ copy_partial_ss(String *dest, String src){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech +FSTRING_LINK b32_4tech copy_partial_cs(char *dest, i32_4tech dest_cap, String src){ b32_4tech result = 0; i32_4tech copy_size = dest_cap; @@ -1321,7 +1351,7 @@ copy_partial_cs(char *dest, i32_4tech dest_cap, String src){ #if !defined(FSTRING_GUARD) - FSTRING_INLINE i32_4tech +FSTRING_INLINE i32_4tech copy_cc(char *dest, char *src){ return copy_fast_unsafe_cc(dest, src); } @@ -1329,7 +1359,7 @@ copy_cc(char *dest, char *src){ #if !defined(FSTRING_GUARD) - FSTRING_INLINE void +FSTRING_INLINE void copy_ss(String *dest, String src){ copy_checked_ss(dest, src); } @@ -1337,7 +1367,7 @@ copy_ss(String *dest, String src){ #if !defined(FSTRING_GUARD) - FSTRING_INLINE void +FSTRING_INLINE void copy_sc(String *dest, char *src){ copy_partial_sc(dest, src); } @@ -1345,7 +1375,7 @@ copy_sc(String *dest, char *src){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech +FSTRING_LINK b32_4tech append_checked_ss(String *dest, String src){ String end; end = tailstr(*dest); @@ -1359,7 +1389,7 @@ append_checked_ss(String *dest, String src){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech +FSTRING_LINK b32_4tech append_partial_sc(String *dest, char *src){ String end = tailstr(*dest); b32_4tech result = copy_partial_sc(&end, src); @@ -1370,7 +1400,7 @@ append_partial_sc(String *dest, char *src){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech +FSTRING_LINK b32_4tech append_partial_ss(String *dest, String src){ String end = tailstr(*dest); b32_4tech result = copy_partial_ss(&end, src); @@ -1381,7 +1411,7 @@ append_partial_ss(String *dest, String src){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech +FSTRING_LINK b32_4tech append_s_char(String *dest, char c){ b32_4tech result = 0; if (dest->size < dest->memory_size){ @@ -1394,7 +1424,7 @@ append_s_char(String *dest, char c){ #if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech +FSTRING_INLINE b32_4tech append_ss(String *dest, String src){ return append_partial_ss(dest, src); } @@ -1402,14 +1432,14 @@ append_ss(String *dest, String src){ #if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech +FSTRING_INLINE b32_4tech append_sc(String *dest, char *src){ return append_partial_sc(dest, src); } #endif #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech +FSTRING_LINK b32_4tech terminate_with_null(String *str){ b32_4tech result = 0; if (str->size < str->memory_size){ @@ -1421,7 +1451,7 @@ terminate_with_null(String *str){ #endif #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech +FSTRING_LINK b32_4tech append_padding(String *dest, char c, i32_4tech target_size){ b32_4tech result = 1; i32_4tech offset = target_size - dest->size; @@ -1444,7 +1474,7 @@ append_padding(String *dest, char c, i32_4tech target_size){ // #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK void +FSTRING_LINK void string_interpret_escapes(String src, char *dst) { i32_4tech mode = 0; @@ -1481,7 +1511,7 @@ string_interpret_escapes(String src, char *dst) #endif #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK void +FSTRING_LINK void replace_char(String *str, char replace, char with){ char *s = str->str; i32_4tech i = 0; @@ -1528,7 +1558,7 @@ replace_range_str(String *str, i32_4tech first, i32_4tech one_past_last, String #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK void +FSTRING_LINK void replace_str_ss(String *str, String replace, String with){ i32_4tech i = 0; for (;;){ @@ -1544,7 +1574,7 @@ replace_str_ss(String *str, String replace, String with){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK void +FSTRING_LINK void replace_str_sc(String *str, String replace, char *with){ String w = make_string_slowly(with); replace_str_ss(str, replace, w); @@ -1553,7 +1583,7 @@ replace_str_sc(String *str, String replace, char *with){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK void +FSTRING_LINK void replace_str_cs(String *str, char *replace, String with){ String r = make_string_slowly(replace); replace_str_ss(str, r, with); @@ -1562,7 +1592,7 @@ replace_str_cs(String *str, char *replace, String with){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK void +FSTRING_LINK void replace_str_cc(String *str, char *replace, char *with){ String r = make_string_slowly(replace); String w = make_string_slowly(with); @@ -1572,7 +1602,7 @@ replace_str_cc(String *str, char *replace, char *with){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK void +FSTRING_LINK void to_lower_cc(char *src, char *dst){ for (; *src != 0; ++src){ *dst++ = char_to_lower(*src); @@ -1583,7 +1613,7 @@ to_lower_cc(char *src, char *dst){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK void +FSTRING_LINK void to_lower_ss(String *dst, String src){ i32_4tech i = 0; i32_4tech size = src.size; @@ -1601,7 +1631,7 @@ to_lower_ss(String *dst, String src){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK void +FSTRING_LINK void to_lower_s(String *str){ i32_4tech i = 0; i32_4tech size = str->size; @@ -1614,7 +1644,7 @@ to_lower_s(String *str){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK void +FSTRING_LINK void to_upper_cc(char *src, char *dst){ for (; *src != 0; ++src){ *dst++ = char_to_upper(*src); @@ -1625,7 +1655,7 @@ to_upper_cc(char *src, char *dst){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK void +FSTRING_LINK void to_upper_ss(String *dst, String src){ i32_4tech i = 0; i32_4tech size = src.size; @@ -1643,7 +1673,7 @@ to_upper_ss(String *dst, String src){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK void +FSTRING_LINK void to_upper_s(String *str){ i32_4tech i = 0; i32_4tech size = str->size; @@ -1656,7 +1686,7 @@ to_upper_s(String *str){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK void +FSTRING_LINK void to_camel_cc(char *src, char *dst){ char *c, ch; i32_4tech is_first = 1; @@ -1686,7 +1716,7 @@ to_camel_cc(char *src, char *dst){ // #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech +FSTRING_LINK i32_4tech int_to_str_size(i32_4tech x){ i32_4tech size = 1; if (x < 0){ @@ -1702,7 +1732,7 @@ int_to_str_size(i32_4tech x){ #endif #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech +FSTRING_LINK b32_4tech int_to_str(String *dest, i32_4tech x){ b32_4tech result = 1; char *str = dest->str; @@ -1749,7 +1779,7 @@ int_to_str(String *dest, i32_4tech x){ #endif #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech +FSTRING_LINK b32_4tech append_int_to_str(String *dest, i32_4tech x){ String last_part = tailstr(*dest); b32_4tech result = int_to_str(&last_part, x); @@ -1761,7 +1791,7 @@ append_int_to_str(String *dest, i32_4tech x){ #endif #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech +FSTRING_LINK i32_4tech u64_to_str_size(uint64_t x){ i32_4tech size = 1; x /= 10; @@ -1774,7 +1804,7 @@ u64_to_str_size(uint64_t x){ #endif #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech +FSTRING_LINK b32_4tech u64_to_str(String *dest, uint64_t x){ b32_4tech result = 1; char *str = dest->str; @@ -1813,7 +1843,7 @@ u64_to_str(String *dest, uint64_t x){ #endif #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech +FSTRING_LINK b32_4tech append_u64_to_str(String *dest, uint64_t x){ String last_part = tailstr(*dest); b32_4tech result = u64_to_str(&last_part, x); @@ -1848,7 +1878,7 @@ get_float_vars(float x){ #endif #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech +FSTRING_LINK i32_4tech float_to_str_size(float x){ Float_To_Str_Variables vars = get_float_vars(x); i32_4tech size = vars.negative + int_to_str_size(vars.int_part) + 1 + int_to_str_size(vars.dec_part); @@ -1857,7 +1887,7 @@ float_to_str_size(float x){ #endif #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech +FSTRING_LINK b32_4tech append_float_to_str(String *dest, float x){ b32_4tech result = 1; Float_To_Str_Variables vars = get_float_vars(x); @@ -1875,7 +1905,7 @@ append_float_to_str(String *dest, float x){ #endif #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech +FSTRING_LINK b32_4tech float_to_str(String *dest, float x){ b32_4tech result = 1; dest->size = 0; @@ -1886,7 +1916,7 @@ float_to_str(String *dest, float x){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech +FSTRING_LINK i32_4tech str_is_int_c(char *str){ b32_4tech result = 1; for (; *str; ++str){ @@ -1901,7 +1931,7 @@ str_is_int_c(char *str){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech +FSTRING_LINK b32_4tech str_is_int_s(String str){ b32_4tech result = 1; for (i32_4tech i = 0; i < str.size; ++i){ @@ -1916,7 +1946,7 @@ str_is_int_s(String str){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech +FSTRING_LINK i32_4tech str_to_int_c(char *str){ i32_4tech x = 0; for (; *str; ++str){ @@ -1935,7 +1965,7 @@ str_to_int_c(char *str){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech +FSTRING_LINK i32_4tech str_to_int_s(String str){ i32_4tech x, i; if (str.size == 0){ @@ -1953,7 +1983,7 @@ str_to_int_s(String str){ #endif #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech +FSTRING_LINK i32_4tech hexchar_to_int(char c){ i32_4tech x = 0; if (c >= '0' && c <= '9'){ @@ -1970,14 +2000,14 @@ hexchar_to_int(char c){ #endif #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK char +FSTRING_LINK char int_to_hexchar(i32_4tech x){ return (x<10)?((char)x+'0'):((char)x+'a'-10); } #endif #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK u32_4tech +FSTRING_LINK u32_4tech hexstr_to_int(String str){ u32_4tech x; i32_4tech i; @@ -1996,7 +2026,7 @@ hexstr_to_int(String str){ #endif #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech +FSTRING_LINK b32_4tech color_to_hexstr(String *s, u32_4tech color){ b32_4tech result = 0; i32_4tech i; @@ -2025,7 +2055,7 @@ color_to_hexstr(String *s, u32_4tech color){ #endif #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech +FSTRING_LINK b32_4tech hexstr_to_color(String s, u32_4tech *out){ b32_4tech result = 0; u32_4tech color = 0; @@ -2050,7 +2080,7 @@ hexstr_to_color(String s, u32_4tech *out){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech +FSTRING_LINK i32_4tech reverse_seek_slash_pos(String str, i32_4tech pos){ i32_4tech i = str.size - 1 - pos; while (i >= 0 && !char_is_slash(str.str[i])){ @@ -2061,21 +2091,21 @@ reverse_seek_slash_pos(String str, i32_4tech pos){ #endif #if !defined(FSTRING_GUARD) - FSTRING_INLINE i32_4tech +FSTRING_INLINE i32_4tech reverse_seek_slash(String str){ return(reverse_seek_slash_pos(str, 0)); } #endif #if !defined(FSTRING_GUARD) - FSTRING_INLINE String +FSTRING_INLINE String front_of_directory(String dir){ return substr_tail(dir, reverse_seek_slash(dir) + 1); } #endif #if !defined(FSTRING_GUARD) - FSTRING_INLINE String +FSTRING_INLINE String path_of_directory(String dir){ return substr(dir, 0, reverse_seek_slash(dir) + 1); } @@ -2083,7 +2113,7 @@ path_of_directory(String dir){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech +FSTRING_LINK b32_4tech set_last_folder_sc(String *dir, char *folder_name, char slash){ b32_4tech result = 0; i32_4tech size = reverse_seek_slash(*dir) + 1; @@ -2102,7 +2132,7 @@ set_last_folder_sc(String *dir, char *folder_name, char slash){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech +FSTRING_LINK b32_4tech set_last_folder_ss(String *dir, String folder_name, char slash){ b32_4tech result = 0; i32_4tech size = reverse_seek_slash(*dir) + 1; @@ -2120,7 +2150,7 @@ set_last_folder_ss(String *dir, String folder_name, char slash){ #endif #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK String +FSTRING_LINK String file_extension(String str){ i32_4tech i; for (i = str.size - 1; i >= 0; --i){ @@ -2132,7 +2162,7 @@ file_extension(String str){ #endif #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech +FSTRING_LINK b32_4tech remove_extension(String *str){ b32_4tech result = 0; i32_4tech i; @@ -2148,7 +2178,7 @@ remove_extension(String *str){ #endif #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech +FSTRING_LINK b32_4tech remove_last_folder(String *str){ b32_4tech result = 0; i32_4tech end = reverse_seek_slash_pos(*str, 1); @@ -2162,7 +2192,7 @@ remove_last_folder(String *str){ #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech +FSTRING_LINK b32_4tech string_set_match_table(void *str_set, i32_4tech item_size, i32_4tech count, String str, i32_4tech *match_index){ b32_4tech result = 0; i32_4tech i = 0; @@ -2179,7 +2209,7 @@ string_set_match_table(void *str_set, i32_4tech item_size, i32_4tech count, Stri #endif #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech +FSTRING_LINK b32_4tech string_set_match(String *str_set, i32_4tech count, String str, i32_4tech *match_index){ b32_4tech result = string_set_match_table(str_set, sizeof(String), count, str, match_index); return(result); @@ -2187,7 +2217,7 @@ string_set_match(String *str_set, i32_4tech count, String str, i32_4tech *match_ #endif #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK String +FSTRING_LINK String get_first_double_line(String source){ String line = {}; i32_4tech pos0 = find_substr_s(source, 0, make_lit_string("\n\n")); @@ -2201,7 +2231,7 @@ get_first_double_line(String source){ #endif #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK String +FSTRING_LINK String get_next_double_line(String source, String line){ String next = {}; i32_4tech pos = (i32_4tech)(line.str - source.str) + line.size; @@ -2226,7 +2256,7 @@ get_next_double_line(String source, String line){ #endif #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK String +FSTRING_LINK String get_next_word(String source, String prev_word){ String word = {}; @@ -2257,7 +2287,7 @@ get_next_word(String source, String prev_word){ #endif #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK String +FSTRING_LINK String get_first_word(String source){ String start_str = make_string(source.str, 0); String word = get_next_word(source, start_str); @@ -2266,26 +2296,30 @@ get_first_word(String source){ #endif #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK String +FSTRING_LINK String string_push(Partition *part, i32_4tech size){ String result = {}; - result.str = push_array(part, char, size); - if (result.str != 0){ - result.memory_size = size; + if (size > 0){ + result.str = push_array(part, char, size); + if (result.str != 0){ + result.memory_size = size; + } } return(result); } #endif #if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK String +FSTRING_LINK String string_push_copy(Partition *part, String str){ String result = {}; - result.str = push_array(part, char, str.size + 1); - if (result.str != 0){ - result.memory_size = str.size + 1; - copy(&result, str); - result.str[result.size] = 0; + if (str.str != 0){ + result.str = push_array(part, char, str.size + 1); + if (result.str != 0){ + result.memory_size = str.size + 1; + copy(&result, str); + result.str[result.size] = 0; + } } return(result); } diff --git a/4coder_lists.cpp b/4coder_lists.cpp index 585e8584..1b7573b4 100644 --- a/4coder_lists.cpp +++ b/4coder_lists.cpp @@ -354,10 +354,7 @@ begin_integrated_lister__basic_list(Application_Links *app, char *query_string, init_lister_state(state, heap, arena_size); lister_first_init(&state->arena, &state->lister, user_data, user_data_size); for (int32_t i = 0; i < option_count; i += 1){ - lister_add_item(&state->arena, &state->lister, - make_string_slowly(options[i].string), - make_string_slowly(options[i].status), - options[i].user_data, 0); + lister_add_item(&state->arena, &state->lister, options[i].string, options[i].status, options[i].user_data, 0); } lister_set_query_string(&state->lister, query_string); state->lister.handlers = lister_get_default_handlers(); @@ -946,8 +943,8 @@ CUSTOM_DOC("Opens an interactive list of all registered commands.") int32_t option_count = command_one_past_last_id; Lister_Option *options = push_array(arena, Lister_Option, option_count); for (int32_t i = 0; i < command_one_past_last_id; i += 1){ - options[i].string = fcoder_metacmd_table[i].name; - options[i].status = fcoder_metacmd_table[i].description; + options[i].string = make_string_slowly(fcoder_metacmd_table[i].name); + options[i].status = make_string_slowly(fcoder_metacmd_table[i].description); options[i].user_data = (void*)fcoder_metacmd_table[i].proc; } begin_integrated_lister__basic_list(app, "Command:", activate_command, 0, 0, diff --git a/4coder_project_commands.cpp b/4coder_project_commands.cpp index bf8cc83d..77e79e3c 100644 --- a/4coder_project_commands.cpp +++ b/4coder_project_commands.cpp @@ -1539,10 +1539,8 @@ CUSTOM_DOC("Open a lister of all commands in the currently loaded project.") int32_t option_count = current_project.command_array.count; Lister_Option *options = push_array(arena, Lister_Option, option_count); for (int32_t i = 0; i < current_project.command_array.count; i += 1){ - String string = string_push_copy(arena, current_project.command_array.commands[i].name); - String status = string_push_copy(arena, current_project.command_array.commands[i].cmd); - options[i].string = string.str; - options[i].status = status.str; + options[i].string = string_push_copy(arena, current_project.command_array.commands[i].name); + options[i].status = string_push_copy(arena, current_project.command_array.commands[i].cmd); options[i].user_data = IntAsPtr(i); } begin_integrated_lister__basic_list(app, "Command:", activate_project_command, 0, 0, diff --git a/4coder_ui_helper.h b/4coder_ui_helper.h index a60a0ca2..73a60dcc 100644 --- a/4coder_ui_helper.h +++ b/4coder_ui_helper.h @@ -86,8 +86,8 @@ struct Lister_State{ //////////////////////////////// struct Lister_Option{ - char *string; - char *status; + String string; + String status; void *user_data; }; diff --git a/string/4coder_string.h b/string/4coder_string.h deleted file mode 100644 index 0c9e58eb..00000000 --- a/string/4coder_string.h +++ /dev/null @@ -1,2436 +0,0 @@ -/* -4coder_string.h - Version 1.0.118 -no warranty implied; use at your own risk - -This software is in the public domain. Where that dedication is not -recognized, you are granted a perpetual, irrevocable license to copy, -distribute, and modify this file as you see fit. - -To include implementation: #define FSTRING_IMPLEMENTATION -To use in C mode: #define FSTRING_C -*/ - -// TOP - - - -#if !defined(FSTRING_LINK) -# define FSTRING_LINK static -#endif - -#if !defined(FSTRING_INLINE) -# if defined(FSTRING_C) -# define FSTRING_INLINE static -# else -# define FSTRING_INLINE inline -# endif -#endif - -#if !defined(FSTRING_GUARD) -#define literal(s) (s), (sizeof(s)-1) - -typedef struct String{ - char *str; - i32_4tech size; - i32_4tech memory_size; -} String; - -static String null_string = {}; -#endif - -#if !defined(FCODER_STRING_H) -#define FCODER_STRING_H - -FSTRING_INLINE b32_4tech char_is_slash(char c); -FSTRING_INLINE b32_4tech char_is_upper(char c); -FSTRING_INLINE b32_4tech char_is_upper_utf8(char c); -FSTRING_INLINE b32_4tech char_is_lower(char c); -FSTRING_INLINE b32_4tech char_is_lower_utf8(u8_4tech c); -FSTRING_INLINE char char_to_upper(char c); -FSTRING_INLINE char char_to_lower(char c); -FSTRING_INLINE b32_4tech char_is_whitespace(char c); -FSTRING_INLINE b32_4tech char_is_alpha_numeric(char c); -FSTRING_INLINE b32_4tech char_is_alpha_numeric_utf8(u8_4tech c); -FSTRING_INLINE b32_4tech char_is_alpha_numeric_true(char c); -FSTRING_INLINE b32_4tech char_is_alpha_numeric_true_utf8(u8_4tech c); -FSTRING_INLINE b32_4tech char_is_alpha(char c); -FSTRING_INLINE b32_4tech char_is_alpha_utf8(u8_4tech c); -FSTRING_INLINE b32_4tech char_is_alpha_true(char c); -FSTRING_INLINE b32_4tech char_is_alpha_true_utf8(u8_4tech c); -FSTRING_INLINE b32_4tech char_is_hex(char c); -FSTRING_INLINE b32_4tech char_is_hex_utf8(u8_4tech c); -FSTRING_INLINE b32_4tech char_is_numeric(char c); -FSTRING_INLINE b32_4tech char_is_numeric_utf8(u8_4tech c); -FSTRING_INLINE String make_string_cap(void *str, i32_4tech size, i32_4tech mem_size); -FSTRING_INLINE String make_string(void *str, i32_4tech size); -#ifndef make_lit_string -# define make_lit_string(s) (make_string_cap((char*)(s), sizeof(s)-1, sizeof(s))) -#endif -#ifndef lit -# define lit(s) make_lit_string(s) -#endif -#ifndef make_fixed_width_string -# define make_fixed_width_string(s) (make_string_cap((char*)(s), 0, sizeof(s))) -#endif -#ifndef expand_str -# define expand_str(s) ((s).str), ((s).size) -#endif -FSTRING_LINK i32_4tech str_size(char *str); -FSTRING_INLINE String make_string_slowly(void *str); -FSTRING_INLINE String substr_tail(String str, i32_4tech start); -FSTRING_INLINE String substr(String str, i32_4tech start, i32_4tech size); -FSTRING_LINK String skip_whitespace(String str); -FSTRING_LINK String skip_whitespace_measure(String str, i32_4tech *skip_length); -FSTRING_LINK String chop_whitespace(String str); -FSTRING_LINK String skip_chop_whitespace(String str); -FSTRING_LINK String skip_chop_whitespace_measure(String str, i32_4tech *skip_length); -FSTRING_INLINE String tailstr(String str); -FSTRING_LINK b32_4tech match_cc(char *a, char *b); -FSTRING_LINK b32_4tech match_sc(String a, char *b); -FSTRING_INLINE b32_4tech match_cs(char *a, String b); -FSTRING_LINK b32_4tech match_ss(String a, String b); -FSTRING_LINK b32_4tech match_part_ccl(char *a, char *b, i32_4tech *len); -FSTRING_LINK b32_4tech match_part_scl(String a, char *b, i32_4tech *len); -FSTRING_INLINE b32_4tech match_part_cc(char *a, char *b); -FSTRING_INLINE b32_4tech match_part_sc(String a, char *b); -FSTRING_LINK b32_4tech match_part_cs(char *a, String b); -FSTRING_LINK b32_4tech match_part_ss(String a, String b); -FSTRING_LINK b32_4tech match_insensitive_cc(char *a, char *b); -FSTRING_LINK b32_4tech match_insensitive_sc(String a, char *b); -FSTRING_INLINE b32_4tech match_insensitive_cs(char *a, String b); -FSTRING_LINK b32_4tech match_insensitive_ss(String a, String b); -FSTRING_LINK b32_4tech match_part_insensitive_ccl(char *a, char *b, i32_4tech *len); -FSTRING_LINK b32_4tech match_part_insensitive_scl(String a, char *b, i32_4tech *len); -FSTRING_INLINE b32_4tech match_part_insensitive_cc(char *a, char *b); -FSTRING_INLINE b32_4tech match_part_insensitive_sc(String a, char *b); -FSTRING_LINK b32_4tech match_part_insensitive_cs(char *a, String b); -FSTRING_LINK b32_4tech match_part_insensitive_ss(String a, String b); -FSTRING_LINK i32_4tech compare_cc(char *a, char *b); -FSTRING_LINK i32_4tech compare_sc(String a, char *b); -FSTRING_INLINE i32_4tech compare_cs(char *a, String b); -FSTRING_LINK i32_4tech compare_ss(String a, String b); -FSTRING_LINK i32_4tech find_c_char(char *str, i32_4tech start, char character); -FSTRING_LINK i32_4tech find_s_char(String str, i32_4tech start, char character); -FSTRING_LINK i32_4tech rfind_s_char(String str, i32_4tech start, char character); -FSTRING_LINK i32_4tech find_c_chars(char *str, i32_4tech start, char *characters); -FSTRING_LINK i32_4tech find_s_chars(String str, i32_4tech start, char *characters); -FSTRING_LINK i32_4tech find_substr_c(char *str, i32_4tech start, String seek); -FSTRING_LINK i32_4tech find_substr_s(String str, i32_4tech start, String seek); -FSTRING_LINK i32_4tech rfind_substr_s(String str, i32_4tech start, String seek); -FSTRING_LINK i32_4tech find_substr_insensitive_c(char *str, i32_4tech start, String seek); -FSTRING_LINK i32_4tech find_substr_insensitive_s(String str, i32_4tech start, String seek); -FSTRING_INLINE b32_4tech has_substr_c(char *s, String seek); -FSTRING_INLINE b32_4tech has_substr_s(String s, String seek); -FSTRING_INLINE b32_4tech has_substr_insensitive_c(char *s, String seek); -FSTRING_INLINE b32_4tech has_substr_insensitive_s(String s, String seek); -FSTRING_LINK i32_4tech copy_fast_unsafe_cc(char *dest, char *src); -FSTRING_LINK i32_4tech copy_fast_unsafe_cs(char *dest, String src); -FSTRING_LINK b32_4tech copy_checked_ss(String *dest, String src); -FSTRING_LINK b32_4tech copy_checked_cs(char *dest, i32_4tech dest_cap, String src); -FSTRING_LINK b32_4tech copy_partial_sc(String *dest, char *src); -FSTRING_LINK b32_4tech copy_partial_ss(String *dest, String src); -FSTRING_LINK b32_4tech copy_partial_cs(char *dest, i32_4tech dest_cap, String src); -FSTRING_INLINE i32_4tech copy_cc(char *dest, char *src); -FSTRING_INLINE void copy_ss(String *dest, String src); -FSTRING_INLINE void copy_sc(String *dest, char *src); -FSTRING_LINK b32_4tech append_checked_ss(String *dest, String src); -FSTRING_LINK b32_4tech append_partial_sc(String *dest, char *src); -FSTRING_LINK b32_4tech append_partial_ss(String *dest, String src); -FSTRING_LINK b32_4tech append_s_char(String *dest, char c); -FSTRING_INLINE b32_4tech append_ss(String *dest, String src); -FSTRING_INLINE b32_4tech append_sc(String *dest, char *src); -FSTRING_LINK b32_4tech terminate_with_null(String *str); -FSTRING_LINK b32_4tech append_padding(String *dest, char c, i32_4tech target_size); -FSTRING_LINK void string_interpret_escapes(String src, char *dst); -FSTRING_LINK void replace_char(String *str, char replace, char with); -FSTRING_LINK void replace_str_ss(String *str, String replace, String with); -FSTRING_LINK void replace_str_sc(String *str, String replace, char *with); -FSTRING_LINK void replace_str_cs(String *str, char *replace, String with); -FSTRING_LINK void replace_str_cc(String *str, char *replace, char *with); -FSTRING_LINK void to_lower_cc(char *src, char *dst); -FSTRING_LINK void to_lower_ss(String *dst, String src); -FSTRING_LINK void to_lower_s(String *str); -FSTRING_LINK void to_upper_cc(char *src, char *dst); -FSTRING_LINK void to_upper_ss(String *dst, String src); -FSTRING_LINK void to_upper_s(String *str); -FSTRING_LINK void to_camel_cc(char *src, char *dst); -FSTRING_LINK i32_4tech int_to_str_size(i32_4tech x); -FSTRING_LINK b32_4tech int_to_str(String *dest, i32_4tech x); -FSTRING_LINK b32_4tech append_int_to_str(String *dest, i32_4tech x); -FSTRING_LINK i32_4tech u64_to_str_size(uint64_t x); -FSTRING_LINK b32_4tech u64_to_str(String *dest, uint64_t x); -FSTRING_LINK b32_4tech append_u64_to_str(String *dest, uint64_t x); -FSTRING_LINK i32_4tech float_to_str_size(float x); -FSTRING_LINK b32_4tech append_float_to_str(String *dest, float x); -FSTRING_LINK b32_4tech float_to_str(String *dest, float x); -FSTRING_LINK i32_4tech str_is_int_c(char *str); -FSTRING_LINK b32_4tech str_is_int_s(String str); -FSTRING_LINK i32_4tech str_to_int_c(char *str); -FSTRING_LINK i32_4tech str_to_int_s(String str); -FSTRING_LINK i32_4tech hexchar_to_int(char c); -FSTRING_LINK char int_to_hexchar(i32_4tech x); -FSTRING_LINK u32_4tech hexstr_to_int(String str); -FSTRING_LINK b32_4tech color_to_hexstr(String *s, u32_4tech color); -FSTRING_LINK b32_4tech hexstr_to_color(String s, u32_4tech *out); -FSTRING_LINK i32_4tech reverse_seek_slash_pos(String str, i32_4tech pos); -FSTRING_INLINE i32_4tech reverse_seek_slash(String str); -FSTRING_INLINE String front_of_directory(String dir); -FSTRING_INLINE String path_of_directory(String dir); -FSTRING_LINK b32_4tech set_last_folder_sc(String *dir, char *folder_name, char slash); -FSTRING_LINK b32_4tech set_last_folder_ss(String *dir, String folder_name, char slash); -FSTRING_LINK String file_extension(String str); -FSTRING_LINK b32_4tech remove_extension(String *str); -FSTRING_LINK b32_4tech remove_last_folder(String *str); -FSTRING_LINK b32_4tech string_set_match_table(void *str_set, i32_4tech item_size, i32_4tech count, String str, i32_4tech *match_index); -FSTRING_LINK b32_4tech string_set_match(String *str_set, i32_4tech count, String str, i32_4tech *match_index); -FSTRING_LINK String get_first_double_line(String source); -FSTRING_LINK String get_next_double_line(String source, String line); -FSTRING_LINK String get_next_word(String source, String prev_word); -FSTRING_LINK String get_first_word(String source); -FSTRING_LINK String string_push(Partition *part, i32_4tech size); -FSTRING_LINK String string_push_copy(Partition *part, String str); - -#endif - -#if !defined(FSTRING_C) && !defined(FSTRING_GUARD) - -FSTRING_INLINE String make_string(void *str, i32_4tech size, i32_4tech mem_size){return(make_string_cap(str,size,mem_size));} -FSTRING_INLINE String substr(String str, i32_4tech start){return(substr_tail(str,start));} -FSTRING_LINK String skip_whitespace(String str, i32_4tech *skip_length){return(skip_whitespace_measure(str,skip_length));} -FSTRING_LINK String skip_chop_whitespace(String str, i32_4tech *skip_length){return(skip_chop_whitespace_measure(str,skip_length));} -FSTRING_LINK b32_4tech match(char *a, char *b){return(match_cc(a,b));} -FSTRING_LINK b32_4tech match(String a, char *b){return(match_sc(a,b));} -FSTRING_INLINE b32_4tech match(char *a, String b){return(match_cs(a,b));} -FSTRING_LINK b32_4tech match(String a, String b){return(match_ss(a,b));} -FSTRING_LINK b32_4tech match_part(char *a, char *b, i32_4tech *len){return(match_part_ccl(a,b,len));} -FSTRING_LINK b32_4tech match_part(String a, char *b, i32_4tech *len){return(match_part_scl(a,b,len));} -FSTRING_INLINE b32_4tech match_part(char *a, char *b){return(match_part_cc(a,b));} -FSTRING_INLINE b32_4tech match_part(String a, char *b){return(match_part_sc(a,b));} -FSTRING_LINK b32_4tech match_part(char *a, String b){return(match_part_cs(a,b));} -FSTRING_LINK b32_4tech match_part(String a, String b){return(match_part_ss(a,b));} -FSTRING_LINK b32_4tech match_insensitive(char *a, char *b){return(match_insensitive_cc(a,b));} -FSTRING_LINK b32_4tech match_insensitive(String a, char *b){return(match_insensitive_sc(a,b));} -FSTRING_INLINE b32_4tech match_insensitive(char *a, String b){return(match_insensitive_cs(a,b));} -FSTRING_LINK b32_4tech match_insensitive(String a, String b){return(match_insensitive_ss(a,b));} -FSTRING_LINK b32_4tech match_part_insensitive(char *a, char *b, i32_4tech *len){return(match_part_insensitive_ccl(a,b,len));} -FSTRING_LINK b32_4tech match_part_insensitive(String a, char *b, i32_4tech *len){return(match_part_insensitive_scl(a,b,len));} -FSTRING_INLINE b32_4tech match_part_insensitive(char *a, char *b){return(match_part_insensitive_cc(a,b));} -FSTRING_INLINE b32_4tech match_part_insensitive(String a, char *b){return(match_part_insensitive_sc(a,b));} -FSTRING_LINK b32_4tech match_part_insensitive(char *a, String b){return(match_part_insensitive_cs(a,b));} -FSTRING_LINK b32_4tech match_part_insensitive(String a, String b){return(match_part_insensitive_ss(a,b));} -FSTRING_LINK i32_4tech compare(char *a, char *b){return(compare_cc(a,b));} -FSTRING_LINK i32_4tech compare(String a, char *b){return(compare_sc(a,b));} -FSTRING_INLINE i32_4tech compare(char *a, String b){return(compare_cs(a,b));} -FSTRING_LINK i32_4tech compare(String a, String b){return(compare_ss(a,b));} -FSTRING_LINK i32_4tech find(char *str, i32_4tech start, char character){return(find_c_char(str,start,character));} -FSTRING_LINK i32_4tech find(String str, i32_4tech start, char character){return(find_s_char(str,start,character));} -FSTRING_LINK i32_4tech rfind(String str, i32_4tech start, char character){return(rfind_s_char(str,start,character));} -FSTRING_LINK i32_4tech find(char *str, i32_4tech start, char *characters){return(find_c_chars(str,start,characters));} -FSTRING_LINK i32_4tech find(String str, i32_4tech start, char *characters){return(find_s_chars(str,start,characters));} -FSTRING_LINK i32_4tech find_substr(char *str, i32_4tech start, String seek){return(find_substr_c(str,start,seek));} -FSTRING_LINK i32_4tech find_substr(String str, i32_4tech start, String seek){return(find_substr_s(str,start,seek));} -FSTRING_LINK i32_4tech rfind_substr(String str, i32_4tech start, String seek){return(rfind_substr_s(str,start,seek));} -FSTRING_LINK i32_4tech find_substr_insensitive(char *str, i32_4tech start, String seek){return(find_substr_insensitive_c(str,start,seek));} -FSTRING_LINK i32_4tech find_substr_insensitive(String str, i32_4tech start, String seek){return(find_substr_insensitive_s(str,start,seek));} -FSTRING_INLINE b32_4tech has_substr(char *s, String seek){return(has_substr_c(s,seek));} -FSTRING_INLINE b32_4tech has_substr(String s, String seek){return(has_substr_s(s,seek));} -FSTRING_INLINE b32_4tech has_substr_insensitive(char *s, String seek){return(has_substr_insensitive_c(s,seek));} -FSTRING_INLINE b32_4tech has_substr_insensitive(String s, String seek){return(has_substr_insensitive_s(s,seek));} -FSTRING_LINK i32_4tech copy_fast_unsafe(char *dest, char *src){return(copy_fast_unsafe_cc(dest,src));} -FSTRING_LINK i32_4tech copy_fast_unsafe(char *dest, String src){return(copy_fast_unsafe_cs(dest,src));} -FSTRING_LINK b32_4tech copy_checked(String *dest, String src){return(copy_checked_ss(dest,src));} -FSTRING_LINK b32_4tech copy_checked(char *dest, i32_4tech dest_cap, String src){return(copy_checked_cs(dest,dest_cap,src));} -FSTRING_LINK b32_4tech copy_partial(String *dest, char *src){return(copy_partial_sc(dest,src));} -FSTRING_LINK b32_4tech copy_partial(String *dest, String src){return(copy_partial_ss(dest,src));} -FSTRING_LINK b32_4tech copy_partial(char *dest, i32_4tech dest_cap, String src){return(copy_partial_cs(dest,dest_cap,src));} -FSTRING_INLINE i32_4tech copy(char *dest, char *src){return(copy_cc(dest,src));} -FSTRING_INLINE void copy(String *dest, String src){return(copy_ss(dest,src));} -FSTRING_INLINE void copy(String *dest, char *src){return(copy_sc(dest,src));} -FSTRING_LINK b32_4tech append_checked(String *dest, String src){return(append_checked_ss(dest,src));} -FSTRING_LINK b32_4tech append_partial(String *dest, char *src){return(append_partial_sc(dest,src));} -FSTRING_LINK b32_4tech append_partial(String *dest, String src){return(append_partial_ss(dest,src));} -FSTRING_LINK b32_4tech append(String *dest, char c){return(append_s_char(dest,c));} -FSTRING_INLINE b32_4tech append(String *dest, String src){return(append_ss(dest,src));} -FSTRING_INLINE b32_4tech append(String *dest, char *src){return(append_sc(dest,src));} -FSTRING_LINK void replace_str(String *str, String replace, String with){return(replace_str_ss(str,replace,with));} -FSTRING_LINK void replace_str(String *str, String replace, char *with){return(replace_str_sc(str,replace,with));} -FSTRING_LINK void replace_str(String *str, char *replace, String with){return(replace_str_cs(str,replace,with));} -FSTRING_LINK void replace_str(String *str, char *replace, char *with){return(replace_str_cc(str,replace,with));} -FSTRING_LINK void to_lower(char *src, char *dst){return(to_lower_cc(src,dst));} -FSTRING_LINK void to_lower(String *dst, String src){return(to_lower_ss(dst,src));} -FSTRING_LINK void to_lower(String *str){return(to_lower_s(str));} -FSTRING_LINK void to_upper(char *src, char *dst){return(to_upper_cc(src,dst));} -FSTRING_LINK void to_upper(String *dst, String src){return(to_upper_ss(dst,src));} -FSTRING_LINK void to_upper(String *str){return(to_upper_s(str));} -FSTRING_LINK void to_camel(char *src, char *dst){return(to_camel_cc(src,dst));} -FSTRING_LINK i32_4tech str_is_int(char *str){return(str_is_int_c(str));} -FSTRING_LINK b32_4tech str_is_int(String str){return(str_is_int_s(str));} -FSTRING_LINK i32_4tech str_to_int(char *str){return(str_to_int_c(str));} -FSTRING_LINK i32_4tech str_to_int(String str){return(str_to_int_s(str));} -FSTRING_LINK i32_4tech reverse_seek_slash(String str, i32_4tech pos){return(reverse_seek_slash_pos(str,pos));} -FSTRING_LINK b32_4tech set_last_folder(String *dir, char *folder_name, char slash){return(set_last_folder_sc(dir,folder_name,slash));} -FSTRING_LINK b32_4tech set_last_folder(String *dir, String folder_name, char slash){return(set_last_folder_ss(dir,folder_name,slash));} -FSTRING_LINK b32_4tech string_set_match(void *str_set, i32_4tech item_size, i32_4tech count, String str, i32_4tech *match_index){return(string_set_match_table(str_set,item_size,count,str,match_index));} - -#endif - - -// -// Character Helpers -// - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -char_is_slash(char c) -{ - return (c == '\\' || c == '/'); -} -#endif - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -char_is_upper(char c) -{ - return (c >= 'A' && c <= 'Z'); -} -#endif - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -char_is_upper_utf8(char c) -{ - return ((c >= 'A' && c <= 'Z') || (unsigned char)c >= 128); -} -#endif - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -char_is_lower(char c) -{ - return (c >= 'a' && c <= 'z'); -} -#endif - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -char_is_lower_utf8(u8_4tech c) -{ - return ((c >= 'a' && c <= 'z') || (unsigned char)c >= 128); -} -#endif - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE char -char_to_upper(char c) -{ - return (c >= 'a' && c <= 'z') ? c + (char)('A' - 'a') : c; -} -#endif - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE char -char_to_lower(char c) -{ - return (c >= 'A' && c <= 'Z') ? c - (char)('A' - 'a') : c; -} -#endif - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -char_is_whitespace(char c) -{ - return (c == ' ' || c == '\n' || c == '\r' || c == '\t'); -} -#endif - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -char_is_alpha_numeric(char c) -{ - return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_'); -} -#endif - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -char_is_alpha_numeric_utf8(u8_4tech c) -{ - return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_' || (unsigned char)c >= 128); -} -#endif - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -char_is_alpha_numeric_true(char c) -{ - return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9')); -} -#endif - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -char_is_alpha_numeric_true_utf8(u8_4tech c) -{ - return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || (unsigned char)c >= 128); -} -#endif - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -char_is_alpha(char c) -{ - return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_'); -} -#endif - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -char_is_alpha_utf8(u8_4tech c) -{ - return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || (unsigned char)c >= 128); -} -#endif - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -char_is_alpha_true(char c) -{ - return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')); -} -#endif - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -char_is_alpha_true_utf8(u8_4tech c) -{ - return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (unsigned char)c >= 128); -} -#endif - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -char_is_hex(char c) -{ - return ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f')); -} -#endif - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -char_is_hex_utf8(u8_4tech c) -{ - return ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f') || (unsigned char)c >= 128); -} -#endif - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -char_is_numeric(char c) -{ - return (c >= '0' && c <= '9'); -} -#endif - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -char_is_numeric_utf8(u8_4tech c) -{ - return ((c >= '0' && c <= '9') || (unsigned char)c >= 128); -} -#endif - - -// -// String Making Functions -// - - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE String -make_string_cap(void *str, i32_4tech size, i32_4tech mem_size){ - String result; - result.str = (char*)str; - result.size = size; - result.memory_size = mem_size; - return(result); -} -#endif - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE String -make_string(void *str, i32_4tech size){ - return(make_string(str, size, size)); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech -str_size(char *str) -{ - i32_4tech i = 0; - if (str != 0){ - for (;str[i];++i); - } - return(i); -} -#endif - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE String -make_string_slowly(void *str) -{ - String result; - result.str = (char*)str; - result.size = str_size((char*)str); - result.memory_size = result.size + 1; - return(result); -} -#endif - - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE String -substr_tail(String str, i32_4tech start) -{ - String result; - result.str = str.str + start; - result.size = str.size - start; - result.memory_size = 0; - return(result); -} -#endif - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE String -substr(String str, i32_4tech start, i32_4tech size) -{ - String result; - result.str = str.str + start; - result.size = size; - if (start + size > str.size){ - result.size = str.size - start; - } - result.memory_size = 0; - return(result); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK String -skip_whitespace(String str) -{ - String result = {}; - i32_4tech i = 0; - for (; i < str.size && char_is_whitespace(str.str[i]); ++i); - result = substr(str, i, str.size - i); - return(result); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK String -skip_whitespace_measure(String str, i32_4tech *skip_length) -{ - String result = {}; - i32_4tech i = 0; - for (; i < str.size && char_is_whitespace(str.str[i]); ++i); - result = substr(str, i, str.size - i); - *skip_length = i; - return(result); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK String -chop_whitespace(String str) -{ - String result = {}; - i32_4tech i = str.size; - for (; i > 0 && char_is_whitespace(str.str[i-1]); --i); - result = substr(str, 0, i); - return(result); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK String -skip_chop_whitespace(String str) -{ - str = skip_whitespace(str); - str = chop_whitespace(str); - return(str); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK String -skip_chop_whitespace_measure(String str, i32_4tech *skip_length) -{ - str = skip_whitespace_measure(str, skip_length); - str = chop_whitespace(str); - return(str); -} -#endif - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE String -tailstr(String str) -{ - String result; - result.str = str.str + str.size; - result.memory_size = str.memory_size - str.size; - result.size = 0; - return(result); -} -#endif - - -// -// String Comparison -// - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -match_cc(char *a, char *b){ - for (i32_4tech i = 0;; ++i){ - if (a[i] != b[i]){ - return 0; - } - if (a[i] == 0){ - return 1; - } - } -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -match_sc(String a, char *b){ - i32_4tech i = 0; - for (; i < a.size; ++i){ - if (a.str[i] != b[i]){ - return 0; - } - } - if (b[i] != 0){ - return 0; - } - return 1; -} -#endif - - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -match_cs(char *a, String b){ - return(match_sc(b,a)); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -match_ss(String a, String b){ - if (a.size != b.size){ - return 0; - } - for (i32_4tech i = 0; i < b.size; ++i){ - if (a.str[i] != b.str[i]){ - return 0; - } - } - return 1; -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -match_part_ccl(char *a, char *b, i32_4tech *len){ - if (a == 0){ - a = ""; - } - if (b == 0){ - b = ""; - } - - i32_4tech i; - for (i = 0; b[i] != 0; ++i){ - if (a[i] != b[i]){ - return(0); - } - } - *len = i; - return(1); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -match_part_scl(String a, char *b, i32_4tech *len){ - if (b == 0){ - b = ""; - } - i32_4tech i; - for (i = 0; b[i] != 0; ++i){ - if (i == a.size || a.str[i] != b[i]){ - return(0); - } - } - *len = i; - return(1); -} -#endif - - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -match_part_cc(char *a, char *b){ - i32_4tech x; - return match_part_ccl(a,b,&x); -} -#endif - - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -match_part_sc(String a, char *b){ - i32_4tech x; - return match_part_scl(a,b,&x); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -match_part_cs(char *a, String b){ - for (i32_4tech i = 0; i != b.size; ++i){ - if (a[i] != b.str[i]){ - return 0; - } - } - return 1; -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -match_part_ss(String a, String b){ - if (a.size < b.size){ - return(0); - } - for (i32_4tech i = 0; i < b.size; ++i){ - if (a.str[i] != b.str[i]){ - return(0); - } - } - return(1); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -match_insensitive_cc(char *a, char *b){ - for (i32_4tech i = 0;; ++i){ - if (char_to_upper(a[i]) != - char_to_upper(b[i])){ - return 0; - } - if (a[i] == 0){ - return 1; - } - } -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -match_insensitive_sc(String a, char *b){ - i32_4tech i = 0; - for (; i < a.size; ++i){ - if (char_to_upper(a.str[i]) != - char_to_upper(b[i])){ - return 0; - } - } - if (b[i] != 0){ - return 0; - } - return 1; -} -#endif - - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -match_insensitive_cs(char *a, String b){ - return match_insensitive_sc(b,a); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -match_insensitive_ss(String a, String b){ - if (a.size != b.size){ - return 0; - } - for (i32_4tech i = 0; i < b.size; ++i){ - if (char_to_upper(a.str[i]) != - char_to_upper(b.str[i])){ - return 0; - } - } - return 1; -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -match_part_insensitive_ccl(char *a, char *b, i32_4tech *len){ - i32_4tech i; - for (i = 0; b[i] != 0; ++i){ - if (char_to_upper(a[i]) != char_to_upper(b[i])){ - return 0; - } - } - *len = i; - return 1; -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -match_part_insensitive_scl(String a, char *b, i32_4tech *len){ - i32_4tech i; - for (i = 0; b[i] != 0; ++i){ - if (char_to_upper(a.str[i]) != char_to_upper(b[i]) || - i == a.size){ - return 0; - } - } - *len = i; - return 1; -} -#endif - - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -match_part_insensitive_cc(char *a, char *b){ - i32_4tech x; - return match_part_insensitive_ccl(a,b,&x); -} -#endif - - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -match_part_insensitive_sc(String a, char *b){ - i32_4tech x; - return match_part_insensitive_scl(a,b,&x); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -match_part_insensitive_cs(char *a, String b){ - for (i32_4tech i = 0; i != b.size; ++i){ - if (char_to_upper(a[i]) != char_to_upper(b.str[i])){ - return(0); - } - } - return(1); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -match_part_insensitive_ss(String a, String b){ - if (a.size < b.size){ - return(0); - } - for (i32_4tech i = 0; i < b.size; ++i){ - if (char_to_upper(a.str[i]) != char_to_upper(b.str[i])){ - return(0); - } - } - return(1); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech -compare_cc(char *a, char *b){ - i32_4tech i = 0, r = 0; - while (a[i] == b[i] && a[i] != 0){ - ++i; - } - r = (a[i] > b[i]) - (a[i] < b[i]); - return(r); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech -compare_sc(String a, char *b){ - i32_4tech i = 0, r = 0; - while (i < a.size && a.str[i] == b[i]){ - ++i; - } - if (i < a.size){ - r = (a.str[i] > b[i]) - (a.str[i] < b[i]); - } - else{ - if (b[i] == 0){ - r = 0; - } - else{ - r = -1; - } - } - return(r); -} -#endif - - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE i32_4tech -compare_cs(char *a, String b){ - i32_4tech r = -compare_sc(b,a); - return(r); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech -compare_ss(String a, String b){ - i32_4tech i = 0, r = 0; - i32_4tech m = a.size; - if (b.size < m){ - m = b.size; - } - while (i < m && a.str[i] == b.str[i]){ - ++i; - } - - if (i < m){ - r = (a.str[i] > b.str[i]) - (b.str[i] > a.str[i]); - } - else{ - r = (a.size > b.size) - (b.size > a.size); - } - - return(r); -} -#endif - -// -// Finding Characters and Substrings -// - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech -find_c_char(char *str, i32_4tech start, char character){ - i32_4tech i = start; - while (str[i] != character && str[i] != 0) ++i; - return(i); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech -find_s_char(String str, i32_4tech start, char character){ - i32_4tech i = start; - while (i < str.size && str.str[i] != character) ++i; - return(i); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech -rfind_s_char(String str, i32_4tech start, char character){ - i32_4tech i = start; - while (i >= 0 && str.str[i] != character) --i; - return(i); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech -find_c_chars(char *str, i32_4tech start, char *characters){ - i32_4tech i = start, j; - while (str[i] != 0){ - for (j = 0; characters[j]; ++j){ - if (str[i] == characters[j]){ - return(i); - } - } - ++i; - } - return(i); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech -find_s_chars(String str, i32_4tech start, char *characters){ - i32_4tech i = start, j; - while (i < str.size){ - for (j = 0; characters[j]; ++j){ - if (str.str[i] == characters[j]){ - return(i); - } - } - ++i; - } - return(i); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech -find_substr_c(char *str, i32_4tech start, String seek){ - i32_4tech i, j, k; - b32_4tech hit; - - if (seek.size == 0){ - i = str_size(str); - return(i); - } - for (i = start; str[i]; ++i){ - if (str[i] == seek.str[0]){ - hit = 1; - for (j = 1, k = i+1; j < seek.size; ++j, ++k){ - if (str[k] != seek.str[j]){ - hit = 0; - break; - } - } - if (hit){ - return(i); - } - } - } - return(i); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech -find_substr_s(String str, i32_4tech start, String seek){ - i32_4tech stop_at, i, j, k; - b32_4tech hit; - - if (seek.size == 0){ - return str.size; - } - stop_at = str.size - seek.size + 1; - for (i = start; i < stop_at; ++i){ - if (str.str[i] == seek.str[0]){ - hit = 1; - for (j = 1, k = i+1; j < seek.size; ++j, ++k){ - if (str.str[k] != seek.str[j]){ - hit = 0; - break; - } - } - if (hit){ - return i; - } - } - } - return(str.size); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech -rfind_substr_s(String str, i32_4tech start, String seek){ - i32_4tech i, j, k; - b32_4tech hit; - - if (seek.size == 0){ - return -1; - } - if (start + seek.size > str.size){ - start = str.size - seek.size; - } - for (i = start; i >= 0; --i){ - if (str.str[i] == seek.str[0]){ - hit = 1; - for (j = 1, k = i+1; j < seek.size; ++j, ++k){ - if (str.str[k] != seek.str[j]){ - hit = 0; - break; - } - } - if (hit){ - return i; - } - } - } - return -1; -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech -find_substr_insensitive_c(char *str, i32_4tech start, String seek){ - i32_4tech i, j, k; - b32_4tech hit; - char a_upper, b_upper; - char first_test_char; - - if (seek.size == 0){ - return str_size(str); - } - first_test_char = char_to_upper(seek.str[0]); - for (i = start; str[i]; ++i){ - a_upper = char_to_upper(str[i]); - if (a_upper == first_test_char){ - hit = 1; - for (j = 1, k = i+1; j < seek.size; ++j, ++k){ - a_upper = char_to_upper(str[k]); - b_upper = char_to_upper(seek.str[j]); - if (a_upper != b_upper){ - hit = 0; - break; - } - } - if (hit){ - return i; - } - } - } - return i; -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech -find_substr_insensitive_s(String str, i32_4tech start, String seek){ - i32_4tech i, j, k; - i32_4tech stop_at; - b32_4tech hit; - char a_upper, b_upper; - char first_test_char; - - if (seek.size == 0){ - return str.size; - } - stop_at = str.size - seek.size + 1; - first_test_char = char_to_upper(seek.str[0]); - for (i = start; i < stop_at; ++i){ - a_upper = char_to_upper(str.str[i]); - if (a_upper == first_test_char){ - hit = 1; - for (j = 1, k = i+1; j < seek.size; ++j, ++k){ - a_upper = char_to_upper(str.str[k]); - b_upper = char_to_upper(seek.str[j]); - if (a_upper != b_upper){ - hit = 0; - break; - } - } - if (hit){ - return i; - } - } - } - return str.size; -} -#endif - - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -has_substr_c(char *s, String seek){ - return (s[find_substr_c(s, 0, seek)] != 0); -} -#endif - - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -has_substr_s(String s, String seek){ - return (find_substr_s(s, 0, seek) < s.size); -} -#endif - - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -has_substr_insensitive_c(char *s, String seek){ - return (s[find_substr_insensitive_c(s, 0, seek)] != 0); -} -#endif - - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -has_substr_insensitive_s(String s, String seek){ - return (find_substr_insensitive_s(s, 0, seek) < s.size); -} -#endif - -// -// String Copies and Appends -// - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech -copy_fast_unsafe_cc(char *dest, char *src){ - char *start = dest; - while (*src != 0){ - *dest = *src; - ++dest; - ++src; - } - return (i32_4tech)(dest - start); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech -copy_fast_unsafe_cs(char *dest, String src){ - i32_4tech i = 0; - while (i != src.size){ - dest[i] = src.str[i]; - ++i; - } - return(src.size); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -copy_checked_ss(String *dest, String src){ - char *dest_str; - i32_4tech i; - if (dest->memory_size < src.size){ - return 0; - } - dest_str = dest->str; - for (i = 0; i < src.size; ++i){ - dest_str[i] = src.str[i]; - } - dest->size = src.size; - return 1; -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -copy_checked_cs(char *dest, i32_4tech dest_cap, String src){ - i32_4tech i; - if (dest_cap < src.size){ - return 0; - } - for (i = 0; i < src.size; ++i){ - dest[i] = src.str[i]; - } - return 1; -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -copy_partial_sc(String *dest, char *src){ - i32_4tech i = 0; - i32_4tech memory_size = dest->memory_size; - char *dest_str = dest->str; - while (src[i] != 0){ - if (i >= memory_size){ - return 0; - } - dest_str[i] = src[i]; - ++i; - } - dest->size = i; - return 1; -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -copy_partial_ss(String *dest, String src){ - char *dest_str = dest->str; - i32_4tech memory_size = dest->memory_size; - b32_4tech result = 0; - if (memory_size >= src.size){ - result = 1; - memory_size = src.size; - } - for (i32_4tech i = 0; i < memory_size; ++i){ - dest_str[i] = src.str[i]; - } - dest->size = memory_size; - return(result); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -copy_partial_cs(char *dest, i32_4tech dest_cap, String src){ - b32_4tech result = 0; - i32_4tech copy_size = dest_cap; - i32_4tech i; - if (dest_cap >= src.size){ - result = 1; - copy_size = src.size; - } - for (i = 0; i < copy_size; ++i){ - dest[i] = src.str[i]; - } - return(result); -} -#endif - - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE i32_4tech -copy_cc(char *dest, char *src){ - return copy_fast_unsafe_cc(dest, src); -} -#endif - - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE void -copy_ss(String *dest, String src){ - copy_checked_ss(dest, src); -} -#endif - - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE void -copy_sc(String *dest, char *src){ - copy_partial_sc(dest, src); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -append_checked_ss(String *dest, String src){ - String end; - end = tailstr(*dest); - b32_4tech result = copy_checked_ss(&end, src); - // NOTE(allen): This depends on end.size still being 0 if - // the check failed and no coppy occurred. - dest->size += end.size; - return result; -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -append_partial_sc(String *dest, char *src){ - String end = tailstr(*dest); - b32_4tech result = copy_partial_sc(&end, src); - dest->size += end.size; - return result; -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -append_partial_ss(String *dest, String src){ - String end = tailstr(*dest); - b32_4tech result = copy_partial_ss(&end, src); - dest->size += end.size; - return result; -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -append_s_char(String *dest, char c){ - b32_4tech result = 0; - if (dest->size < dest->memory_size){ - dest->str[dest->size++] = c; - result = 1; - } - return result; -} -#endif - - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -append_ss(String *dest, String src){ - return append_partial_ss(dest, src); -} -#endif - - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -append_sc(String *dest, char *src){ - return append_partial_sc(dest, src); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -terminate_with_null(String *str){ - b32_4tech result = 0; - if (str->size < str->memory_size){ - str->str[str->size] = 0; - result = 1; - } - return(result); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -append_padding(String *dest, char c, i32_4tech target_size){ - b32_4tech result = 1; - i32_4tech offset = target_size - dest->size; - i32_4tech r = 0; - if (offset > 0){ - for (r = 0; r < offset; ++r){ - if (append_s_char(dest, c) == 0){ - result = 0; - break; - } - } - } - return(result); -} -#endif - - -// -// Other Edits -// - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK void -string_interpret_escapes(String src, char *dst) -{ - i32_4tech mode = 0; - i32_4tech j = 0; - for (i32_4tech i = 0; i < src.size; ++i){ - switch (mode){ - case 0: - { - if (src.str[i] == '\\'){ - mode = 1; - } - else{ - dst[j++] = src.str[i]; - } - }break; - - case 1: - { - char c = src.str[i]; - switch (c){ - case '\\':{dst[j++] = '\\';} break; - case 'n': {dst[j++] = '\n';} break; - case 't': {dst[j++] = '\t';} break; - case '"': {dst[j++] = '"'; } break; - case '0': {dst[j++] = '\0';} break; - default: {dst[j++] = '\\'; dst[j++] = c;}break; - } - mode = 0; - }break; - } - } - dst[j] = 0; -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK void -replace_char(String *str, char replace, char with){ - char *s = str->str; - i32_4tech i = 0; - for (i = 0; i < str->size; ++i, ++s){ - if (*s == replace) *s = with; - } -} -#endif - -#if !defined(FSTRING_GUARD) -void -block_move(void *a_ptr, void *b_ptr, i32_4tech s){ - u8_4tech *a = (u8_4tech*)a_ptr; - u8_4tech *b = (u8_4tech*)b_ptr; - if (a < b){ - for (i32_4tech i = 0; i < s; ++i, ++a, ++b){ - *a = *b; - } - } - else if (a > b){ - a = a + s - 1; - b = b + s - 1; - for (i32_4tech i = 0; i < s; ++i, --a, --b){ - *a = *b; - } - } -} - -void -replace_range_str(String *str, i32_4tech first, i32_4tech one_past_last, String with){ - i32_4tech shift = with.size - (one_past_last - first); - i32_4tech new_size = str->size + shift; - if (new_size <= str->memory_size){ - if (shift != 0){ - char *tail = str->str + one_past_last; - char *new_tail_pos = tail + shift; - block_move(new_tail_pos, tail, str->size - one_past_last); - } - block_move(str->str + first, with.str, with.size); - str->size += shift; - } -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK void -replace_str_ss(String *str, String replace, String with){ - i32_4tech i = 0; - for (;;){ - i = find_substr_s(*str, i, replace); - if (i >= str->size){ - break; - } - replace_range_str(str, i, i + replace.size, with); - i += with.size; - } -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK void -replace_str_sc(String *str, String replace, char *with){ - String w = make_string_slowly(with); - replace_str_ss(str, replace, w); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK void -replace_str_cs(String *str, char *replace, String with){ - String r = make_string_slowly(replace); - replace_str_ss(str, r, with); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK void -replace_str_cc(String *str, char *replace, char *with){ - String r = make_string_slowly(replace); - String w = make_string_slowly(with); - replace_str_ss(str, r, w); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK void -to_lower_cc(char *src, char *dst){ - for (; *src != 0; ++src){ - *dst++ = char_to_lower(*src); - } - *dst++ = 0; -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK void -to_lower_ss(String *dst, String src){ - i32_4tech i = 0; - i32_4tech size = src.size; - char *c = src.str; - char *d = dst->str; - - if (dst->memory_size >= size){ - for (; i < size; ++i){ - *d++ = char_to_lower(*c++); - } - dst->size = size; - } -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK void -to_lower_s(String *str){ - i32_4tech i = 0; - i32_4tech size = str->size; - char *c = str->str; - for (; i < size; ++c, ++i){ - *c = char_to_lower(*c); - } -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK void -to_upper_cc(char *src, char *dst){ - for (; *src != 0; ++src){ - *dst++ = char_to_upper(*src); - } - *dst++ = 0; -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK void -to_upper_ss(String *dst, String src){ - i32_4tech i = 0; - i32_4tech size = src.size; - char *c = src.str; - char *d = dst->str; - - if (dst->memory_size >= size){ - for (; i < size; ++i){ - *d++ = char_to_upper(*c++); - } - dst->size = size; - } -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK void -to_upper_s(String *str){ - i32_4tech i = 0; - i32_4tech size = str->size; - char *c = str->str; - for (; i < size; ++c, ++i){ - *c = char_to_upper(*c); - } -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK void -to_camel_cc(char *src, char *dst){ - char *c, ch; - i32_4tech is_first = 1; - for (c = src; *c != 0; ++c){ - ch = *c; - if (char_is_alpha_numeric_true(ch)){ - if (is_first){ - is_first = 0; - ch = char_to_upper(ch); - } - else{ - ch = char_to_lower(ch); - } - } - else{ - is_first = 1; - } - *dst++ = ch; - } - *dst = 0; -} -#endif - - -// -// String <-> Number Conversions -// - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech -int_to_str_size(i32_4tech x){ - i32_4tech size = 1; - if (x < 0){ - size = 2; - } - x /= 10; - while (x != 0){ - x /= 10; - ++size; - } - return(size); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -int_to_str(String *dest, i32_4tech x){ - b32_4tech result = 1; - char *str = dest->str; - i32_4tech memory_size = dest->memory_size; - i32_4tech size, i, j; - b32_4tech negative; - - if (x == 0){ - str[0] = '0'; - dest->size = 1; - } - else{ - size = 0; - negative = 0; - if (x < 0){ - negative = 1; - x = -x; - str[size++] = '-'; - } - while (x != 0){ - if (size == memory_size){ - result = 0; - break; - } - i = x % 10; - x /= 10; - str[size++] = (char)('0' + i); - } - if (result){ - // NOTE(allen): Start i = 0 if not negative, start i = 1 if is negative because - should not be flipped if it is negative :) - for (i = negative, j = size-1; i < j; ++i, --j){ - char temp = str[i]; - str[i] = str[j]; - str[j] = temp; - } - dest->size = size; - } - else{ - dest->size = 0; - } - } - return(result); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -append_int_to_str(String *dest, i32_4tech x){ - String last_part = tailstr(*dest); - b32_4tech result = int_to_str(&last_part, x); - if (result){ - dest->size += last_part.size; - } - return(result); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech -u64_to_str_size(uint64_t x){ - i32_4tech size = 1; - x /= 10; - while (x != 0){ - x /= 10; - ++size; - } - return(size); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -u64_to_str(String *dest, uint64_t x){ - b32_4tech result = 1; - char *str = dest->str; - i32_4tech memory_size = dest->memory_size; - i32_4tech size, i, j; - - if (x == 0){ - str[0] = '0'; - dest->size = 1; - } - else{ - size = 0; - while (x != 0){ - if (size == memory_size){ - result = 0; - break; - } - i = x % 10; - x /= 10; - str[size++] = (char)('0' + i); - } - if (result){ - for (i = 0, j = size-1; i < j; ++i, --j){ - char temp = str[i]; - str[i] = str[j]; - str[j] = temp; - } - dest->size = size; - } - else{ - dest->size = 0; - } - } - return(result); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -append_u64_to_str(String *dest, uint64_t x){ - String last_part = tailstr(*dest); - b32_4tech result = u64_to_str(&last_part, x); - if (result){ - dest->size += last_part.size; - } - return(result); -} -#endif - -#if !defined(FSTRING_GUARD) -typedef struct Float_To_Str_Variables{ - b32_4tech negative; - i32_4tech int_part; - i32_4tech dec_part; -} Float_To_Str_Variables; - -static Float_To_Str_Variables -get_float_vars(float x){ - Float_To_Str_Variables vars = {}; - - if (x < 0){ - vars.negative = 1; - x = -x; - } - - vars.int_part = (i32_4tech)(x); - vars.dec_part = (i32_4tech)((x - vars.int_part) * 1000); - - return(vars); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech -float_to_str_size(float x){ - Float_To_Str_Variables vars = get_float_vars(x); - i32_4tech size = vars.negative + int_to_str_size(vars.int_part) + 1 + int_to_str_size(vars.dec_part); - return(size); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -append_float_to_str(String *dest, float x){ - b32_4tech result = 1; - Float_To_Str_Variables vars = get_float_vars(x); - - if (vars.negative){ - append_s_char(dest, '-'); - } - - append_int_to_str(dest, vars.int_part); - append_s_char(dest, '.'); - append_int_to_str(dest, vars.dec_part); - - return(result); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -float_to_str(String *dest, float x){ - b32_4tech result = 1; - dest->size = 0; - append_float_to_str(dest, x); - return(result); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech -str_is_int_c(char *str){ - b32_4tech result = 1; - for (; *str; ++str){ - if (!char_is_numeric(*str)){ - result = 0; - break; - } - } - return(result); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -str_is_int_s(String str){ - b32_4tech result = 1; - for (i32_4tech i = 0; i < str.size; ++i){ - if (!char_is_numeric(str.str[i])){ - result = 0; - break; - } - } - return(result); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech -str_to_int_c(char *str){ - i32_4tech x = 0; - for (; *str; ++str){ - if (*str >= '0' && *str <= '9'){ - x *= 10; - x += *str - '0'; - } - else{ - x = 0; - break; - } - } - return(x); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech -str_to_int_s(String str){ - i32_4tech x, i; - if (str.size == 0){ - x = 0; - } - else{ - x = str.str[0] - '0'; - for (i = 1; i < str.size; ++i){ - x *= 10; - x += str.str[i] - '0'; - } - } - return(x); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech -hexchar_to_int(char c){ - i32_4tech x = 0; - if (c >= '0' && c <= '9'){ - x = c-'0'; - } - else if (c > 'F'){ - x = c+(10-'a'); - } - else{ - x = c+(10-'A'); - } - return(x); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK char -int_to_hexchar(i32_4tech x){ - return (x<10)?((char)x+'0'):((char)x+'a'-10); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK u32_4tech -hexstr_to_int(String str){ - u32_4tech x; - i32_4tech i; - if (str.size == 0){ - x = 0; - } - else{ - x = hexchar_to_int(str.str[0]); - for (i = 1; i < str.size; ++i){ - x *= 0x10; - x += hexchar_to_int(str.str[i]); - } - } - return(x); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -color_to_hexstr(String *s, u32_4tech color){ - b32_4tech result = 0; - i32_4tech i; - - if (s->memory_size == 7 || s->memory_size == 8){ - result = 1; - s->size = 6; - s->str[6] = 0; - color = color & 0x00FFFFFF; - for (i = 5; i >= 0; --i){ - s->str[i] = int_to_hexchar(color & 0xF); - color >>= 4; - } - } - else if (s->memory_size > 8){ - result = 1; - s->size = 8; - s->str[8] = 0; - for (i = 7; i >= 0; --i){ - s->str[i] = int_to_hexchar(color & 0xF); - color >>= 4; - } - } - return(result); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -hexstr_to_color(String s, u32_4tech *out){ - b32_4tech result = 0; - u32_4tech color = 0; - if (s.size == 6){ - result = 1; - color = (u32_4tech)hexstr_to_int(s); - color |= (0xFF << 24); - *out = color; - } - else if (s.size == 8){ - result = 1; - color = (u32_4tech)hexstr_to_int(s); - *out = color; - } - return(result); -} -#endif - -// -// Directory String Management -// - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech -reverse_seek_slash_pos(String str, i32_4tech pos){ - i32_4tech i = str.size - 1 - pos; - while (i >= 0 && !char_is_slash(str.str[i])){ - --i; - } - return i; -} -#endif - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE i32_4tech -reverse_seek_slash(String str){ - return(reverse_seek_slash_pos(str, 0)); -} -#endif - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE String -front_of_directory(String dir){ - return substr_tail(dir, reverse_seek_slash(dir) + 1); -} -#endif - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE String -path_of_directory(String dir){ - return substr(dir, 0, reverse_seek_slash(dir) + 1); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -set_last_folder_sc(String *dir, char *folder_name, char slash){ - b32_4tech result = 0; - i32_4tech size = reverse_seek_slash(*dir) + 1; - dir->size = size; - if (append_sc(dir, folder_name)){ - if (append_s_char(dir, slash)){ - result = 1; - } - } - if (!result){ - dir->size = size; - } - return(result); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -set_last_folder_ss(String *dir, String folder_name, char slash){ - b32_4tech result = 0; - i32_4tech size = reverse_seek_slash(*dir) + 1; - dir->size = size; - if (append_ss(dir, folder_name)){ - if (append_s_char(dir, slash)){ - result = 1; - } - } - if (!result){ - dir->size = size; - } - return(result); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK String -file_extension(String str){ - i32_4tech i; - for (i = str.size - 1; i >= 0; --i){ - if (str.str[i] == '.') break; - } - ++i; - return(make_string(str.str+i, str.size-i)); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -remove_extension(String *str){ - b32_4tech result = 0; - i32_4tech i; - for (i = str->size - 1; i >= 0; --i){ - if (str->str[i] == '.') break; - } - if (i >= 0){ - result = 1; - str->size = i + 1; - } - return(result); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -remove_last_folder(String *str){ - b32_4tech result = 0; - i32_4tech end = reverse_seek_slash_pos(*str, 1); - if (end >= 0){ - result = 1; - str->size = end + 1; - } - return(result); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -string_set_match_table(void *str_set, i32_4tech item_size, i32_4tech count, String str, i32_4tech *match_index){ - b32_4tech result = 0; - i32_4tech i = 0; - uint8_t *ptr = (uint8_t*)str_set; - for (; i < count; ++i, ptr += item_size){ - if (match_ss(*(String*)ptr, str)){ - *match_index = i; - result = 1; - break; - } - } - return(result); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -string_set_match(String *str_set, i32_4tech count, String str, i32_4tech *match_index){ - b32_4tech result = string_set_match_table(str_set, sizeof(String), count, str, match_index); - return(result); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK String -get_first_double_line(String source){ - String line = {}; - i32_4tech pos0 = find_substr_s(source, 0, make_lit_string("\n\n")); - i32_4tech pos1 = find_substr_s(source, 0, make_lit_string("\r\n\r\n")); - if (pos1 < pos0){ - pos0 = pos1; - } - line = substr(source, 0, pos0); - return(line); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK String -get_next_double_line(String source, String line){ - String next = {}; - i32_4tech pos = (i32_4tech)(line.str - source.str) + line.size; - i32_4tech start = 0, pos0 = 0, pos1 = 0; - - if (pos < source.size){ - //Assert(source.str[pos] == '\n' || source.str[pos] == '\r'); - start = pos + 1; - - if (start < source.size){ - pos0 = find_substr_s(source, start, make_lit_string("\n\n")); - pos1 = find_substr_s(source, start, make_lit_string("\r\n\r\n")); - if (pos1 < pos0){ - pos0 = pos1; - } - next = substr(source, start, pos0 - start); - } - } - - return(next); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK String -get_next_word(String source, String prev_word){ - - String word = {}; - i32_4tech pos0 = (i32_4tech)(prev_word.str - source.str) + prev_word.size; - i32_4tech pos1 = 0; - char c = 0; - - for (; pos0 < source.size; ++pos0){ - c = source.str[pos0]; - if (!(char_is_whitespace(c) || c == '(' || c == ')')){ - break; - } - } - - if (pos0 < source.size){ - for (pos1 = pos0; pos1 < source.size; ++pos1){ - c = source.str[pos1]; - if (char_is_whitespace(c) || c == '(' || c == ')'){ - break; - } - } - - word = substr(source, pos0, pos1 - pos0); - } - - return(word); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK String -get_first_word(String source){ - String start_str = make_string(source.str, 0); - String word = get_next_word(source, start_str); - return(word); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK String -string_push(Partition *part, i32_4tech size){ - String result = {}; - result.str = push_array(part, char, size); - if (result.str != 0){ - result.memory_size = size; - } - return(result); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK String -string_push_copy(Partition *part, String str){ - String result = {}; - result.str = push_array(part, char, str.size + 1); - if (result.str != 0){ - result.memory_size = str.size + 1; - copy(&result, str); - result.str[result.size] = 0; - } - return(result); -} -#endif - -// TODO(allen): eliminate this. -#ifndef FSTRING_EXPERIMENTAL -#define FSTRING_EXPERIMENTAL - -// NOTE(allen): experimental section, things below here are -// not promoted to public API level yet. - -typedef struct Absolutes{ - String a[8]; - i32_4tech count; -} Absolutes; - -static void -get_absolutes(String name, Absolutes *absolutes, b32_4tech implicit_first, b32_4tech implicit_last){ - if (name.size != 0){ - i32_4tech count = 0; - i32_4tech max = (sizeof(absolutes->a)/sizeof(*absolutes->a)) - 1; - if (implicit_last) --max; - - String str; - str.str = name.str; - str.size = 0; - str.memory_size = 0; - b32_4tech prev_was_wild = 0; - - if (implicit_first){ - absolutes->a[count++] = str; - prev_was_wild = 1; - } - - i32_4tech i; - for (i = 0; i < name.size; ++i){ - if (name.str[i] == '*' && count < max){ - if (!prev_was_wild){ - str.memory_size = str.size; - absolutes->a[count++] = str; - str.size = 0; - } - str.str = name.str + i + 1; - prev_was_wild = 1; - } - else{ - ++str.size; - prev_was_wild = 0; - } - } - - str.memory_size = str.size; - absolutes->a[count++] = str; - - if (implicit_last){ - str.size = 0; - str.memory_size = 0; - absolutes->a[count++] = str; - } - - absolutes->count = count; - } - else{ - absolutes->count = 0; - } -} - -static b32_4tech -wildcard_match_c(Absolutes *absolutes, char *x, i32_4tech case_sensitive){ - b32_4tech r = 1; - - if (absolutes->count > 0){ - String *a = absolutes->a; - - b32_4tech (*match_func)(char*, String); - b32_4tech (*match_part_func)(char*, String); - - if (case_sensitive){ - match_func = match_cs; - match_part_func = match_part_cs; - } - else{ - match_func = match_insensitive_cs; - match_part_func = match_part_insensitive_cs; - } - - if (absolutes->count == 1){ - r = match_func(x, *a); - } - else{ - if (!match_part_func(x, *a)){ - r = 0; - } - else{ - String *max = a + absolutes->count - 1; - x += a->size; - ++a; - while (a < max){ - if (*x == 0){ - r = 0; - break; - } - if (match_part_func(x, *a)){ - x += a->size; - ++a; - } - else{ - ++x; - } - } - if (r && a->size > 0){ - r = 0; - while (*x != 0){ - if (match_part_func(x, *a) && *(x + a->size) == 0){ - r = 1; - break; - } - else{ - ++x; - } - } - } - } - } - } - return(r); -} - -static b32_4tech -wildcard_match_s(Absolutes *absolutes, String x, i32_4tech case_sensitive){ - terminate_with_null(&x); - return(wildcard_match_c(absolutes, x.str, case_sensitive)); -} - -#endif - -#if defined(FSTRING_IMPLEMENTATION) -#undef FSTRING_IMPLEMENTATION -#define FSTRING_IMPL_GUARD -#endif - -#if !defined(FSTRING_GUARD) -#define FSTRING_GUARD -#endif - -// BOTTOM - diff --git a/string/4coder_string_build_num.txt b/string/4coder_string_build_num.txt index bf4e0e24..8ba864e9 100644 --- a/string/4coder_string_build_num.txt +++ b/string/4coder_string_build_num.txt @@ -1,5 +1,5 @@ 1 0 -119 +122 diff --git a/string/internal_4coder_string.cpp b/string/internal_4coder_string.cpp index c32dc8e9..784b751a 100644 --- a/string/internal_4coder_string.cpp +++ b/string/internal_4coder_string.cpp @@ -34,7 +34,7 @@ FSTRING_BEGIN #endif #if !defined(FSTRING_GUARD) -#define literal(s) (s), (sizeof(s)-1) +#define literal(s) (s), (sizeof(s) - 1) typedef struct String{ char *str; @@ -2128,9 +2128,11 @@ DOC_PARAM(part, A partition on which the string will be allocated.) DOC_PARAM(size, The number of bytes to allocated for the new string.) DOC_RETURN(If successfull returns an empty string with capacity equal to the size parameter, otherwise returns a null string.)*/{ String result = {}; - result.str = push_array(part, char, size); - if (result.str != 0){ - result.memory_size = size; + if (size > 0){ + result.str = push_array(part, char, size); + if (result.str != 0){ + result.memory_size = size; + } } return(result); } @@ -2141,11 +2143,13 @@ DOC_PARAM(part, A partition on which the string will be allocated.) DOC_PARAM(str, The source string to copy into the new string. The copy includes a null terminator whther or not the source does.) DOC_RETURN(If successfull returns a string copy of str, otherwise returns a null string.)*/{ String result = {}; - result.str = push_array(part, char, str.size + 1); - if (result.str != 0){ - result.memory_size = str.size + 1; - copy(&result, str); - result.str[result.size] = 0; + if (str.str != 0){ + result.str = push_array(part, char, str.size + 1); + if (result.str != 0){ + result.memory_size = str.size + 1; + copy(&result, str); + result.str[result.size] = 0; + } } return(result); } diff --git a/todo.txt b/todo.txt index e18b1ba5..bb3cd630 100644 --- a/todo.txt +++ b/todo.txt @@ -14,8 +14,8 @@ [x] High CPU usage in listers (endless animation bug) [x] Panel resizing doesn't work [x] On windows file lister: /foo/bar.txt - [] Notepad like mode clicking to new view doesn't snap the mark - [] Notepad like mode replacing text with cursor at end of selection in middle of long file + [x] Notepad like mode clicking to new view doesn't snap the mark + [x] Notepad like mode replacing text with cursor at end of selection in middle of long file [] Tab when no valid completions in open file lister [] Graphics problem (fonts not rendering) [] Texture binding changes too often problem.