From: Kevin Day Date: Fri, 9 Oct 2020 02:59:36 +0000 (-0500) Subject: Progress: basic list write, with minor basic list read and extended list read changes. X-Git-Tag: 0.5.1~37 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=cc3bedbfc4e6392d7b00ac714430af7867babdc1;p=fll Progress: basic list write, with minor basic list read and extended list read changes. The basic list object write should only handle escaping slashes when it would be escaped. Make sure to return an error when a newline is found. Note that the stop point designates the end of the object so if the end of the object ends in slashes, then these must be escaped. Perform some cleanups that I felt like doing while working on this. --- diff --git a/level_1/fl_fss/c/fss_basic_list.c b/level_1/fl_fss/c/fss_basic_list.c index 5bf96ae..2c47a01 100644 --- a/level_1/fl_fss/c/fss_basic_list.c +++ b/level_1/fl_fss/c/fss_basic_list.c @@ -41,7 +41,7 @@ extern "C" { // ignore all comment lines. if (buffer->string[range->start] == f_fss_comment) { - fl_macro_fss_object_seek_till_newline((*buffer), (*range), delimits, F_data_not_eos, F_data_not_stop) + fl_macro_fss_object_seek_till_newline((*buffer), (*range), delimits, F_data_not_eos, F_data_not_stop); status = f_utf_buffer_increment(*buffer, range, 1); if (F_status_is_error(status)) return status; @@ -49,40 +49,46 @@ extern "C" { return FL_fss_found_object_not; } + f_string_length_t first_slash = 0; + f_string_length_t slash_count = 0; + f_string_length_t start = 0; + f_string_length_t stop = 0; + // identify where the object ends. - while (range->start < buffer->used && range->start <= range->stop && buffer->string[range->start] != f_string_eol[0]) { + while (range->start <= range->stop && range->start < buffer->used && buffer->string[range->start] != f_string_eol[0]) { if (buffer->string[range->start] == f_fss_delimit_slash) { - f_string_length_t first_slash = range->start; - f_string_length_t slash_count = 1; + first_slash = range->start; + slash_count = 1; - status = f_utf_buffer_increment(*buffer, range, 1); - if (F_status_is_error(status)) return status; + for (range->start++; range->start <= range->stop && range->start < buffer->used; range->start++) { - while (range->start < buffer->used && range->start <= range->stop && (buffer->string[range->start] == f_fss_delimit_placeholder || buffer->string[range->start] == f_fss_delimit_slash)) { - - if (buffer->string[range->start] == f_fss_delimit_slash) { - slash_count++; + if (buffer->string[range->start] == f_fss_delimit_placeholder) { + continue; + } else if (buffer->string[range->start] != f_fss_delimit_slash) { + break; } - status = f_utf_buffer_increment(*buffer, range, 1); - if (F_status_is_error(status)) return status; - } // while + slash_count++; + } // for fl_macro_fss_object_return_on_overflow((*buffer), (*range), (*found), delimits, F_data_not_eos, F_data_not_stop); if (buffer->string[range->start] == f_fss_basic_list_open) { - f_string_length_t stop_point = range->start - 1; + stop = range->start - 1; status = f_utf_buffer_increment(*buffer, range, 1); if (F_status_is_error(status)) return status; - while (range->start < buffer->used && range->start <= range->stop) { - if (buffer->string[range->start] == f_string_eol[0]) break; + while (range->start <= range->stop && range->start < buffer->used) { - status = f_fss_is_space(*buffer, *range); + if (buffer->string[range->start] == f_string_eol[0]) { + break; + } + status = f_fss_is_space(*buffer, *range); if (F_status_is_error(status)) return status; + if (status == F_false) break; status = f_utf_buffer_increment(*buffer, range, 1); @@ -92,7 +98,7 @@ extern "C" { fl_macro_fss_object_return_on_overflow((*buffer), (*range), (*found), delimits, F_data_not_eos, F_data_not_stop); if (buffer->string[range->start] == f_string_eol[0]) { - f_string_length_t start = range->start; + start = range->start; range->start = first_slash; @@ -123,7 +129,7 @@ extern "C" { fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); - found->stop = stop_point; + found->stop = stop; range->start = start + 1; return FL_fss_found_object; @@ -137,17 +143,20 @@ extern "C" { continue; } else if (buffer->string[range->start] == f_fss_basic_list_open) { - f_string_length_t stop_point = range->start - 1; + stop = range->start - 1; status = f_utf_buffer_increment(*buffer, range, 1); if (F_status_is_error(status)) return status; - while (range->start < buffer->used && range->start <= range->stop) { - if (buffer->string[range->start] == f_string_eol[0]) break; + while (range->start <= range->stop && range->start < buffer->used) { - status = f_fss_is_space(*buffer, *range); + if (buffer->string[range->start] == f_string_eol[0]) { + break; + } + status = f_fss_is_space(*buffer, *range); if (F_status_is_error(status)) return status; + if (status == F_false) break; status = f_utf_buffer_increment(*buffer, range, 1); @@ -159,7 +168,7 @@ extern "C" { if (buffer->string[range->start] == f_string_eol[0]) { fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); - found->stop = stop_point; + found->stop = stop; status = f_utf_buffer_increment(*buffer, range, 1); if (F_status_is_error(status)) return status; @@ -175,7 +184,7 @@ extern "C" { } // while // seek to the end of the line when no valid object is found. - while (range->start < buffer->used && range->start <= range->stop && buffer->string[range->start] != f_string_eol[0]) { + while (range->start <= range->stop && range->start < buffer->used && buffer->string[range->start] != f_string_eol[0]) { status = f_utf_buffer_increment(*buffer, range, 1); if (F_status_is_error(status)) return status; } // while @@ -206,16 +215,20 @@ extern "C" { f_string_lengths_t delimits = f_string_lengths_t_initialize; fl_macro_fss_skip_past_delimit_placeholders((*buffer), (*range)); - fl_macro_fss_content_return_on_overflow((*buffer), (*range), (*found), delimits, F_none_eos, F_none_stop) + fl_macro_fss_content_return_on_overflow((*buffer), (*range), (*found), delimits, F_none_eos, F_none_stop); fl_macro_fss_allocate_content_if_necessary((*found), delimits); found->array[found->used].start = range->start; f_string_length_t last_newline = range->start; + f_string_length_t first_slash = 0; + f_string_length_t slash_count = 0; + f_string_length_t start = 0; + bool found_newline = F_false; // identify where the content ends. - while (range->start < buffer->used && range->start <= range->stop) { + while (range->start <= range->stop && range->start < buffer->used) { if (buffer->string[range->start] == f_string_eol[0]) { found_newline = F_true; @@ -224,43 +237,42 @@ extern "C" { status = f_utf_buffer_increment(*buffer, range, 1); if (F_status_is_error(status)) return status; - fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*range), (*found), delimits, F_none_eos, F_none_stop) + fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*range), (*found), delimits, F_none_eos, F_none_stop); continue; } if (buffer->string[range->start] == f_fss_delimit_slash) { - f_string_length_t first_slash = range->start; - f_string_length_t slash_count = 1; + first_slash = range->start; + slash_count = 1; - status = f_utf_buffer_increment(*buffer, range, 1); - if (F_status_is_error(status)) return status; + for (range->start++; range->start <= range->stop && range->start < buffer->used; range->start++) { - while (range->start < buffer->used && range->start <= range->stop && (buffer->string[range->start] == f_fss_delimit_placeholder || buffer->string[range->start] == f_fss_delimit_slash)) { - - if (buffer->string[range->start] == f_fss_delimit_slash) { - slash_count++; + if (buffer->string[range->start] == f_fss_delimit_placeholder) { + continue; + } else if (buffer->string[range->start] != f_fss_delimit_slash) { + break; } - status = f_utf_buffer_increment(*buffer, range, 1); - if (F_status_is_error(status)) return status; - } // while + slash_count++; + } // for if (found_newline) { - fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*range), (*found), delimits, F_none_eos, F_none_stop) + fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*range), (*found), delimits, F_none_eos, F_none_stop); } else { - fl_macro_fss_content_return_on_overflow((*buffer), (*range), (*found), delimits, F_data_not_eos, F_data_not_stop) + fl_macro_fss_content_return_on_overflow((*buffer), (*range), (*found), delimits, F_data_not_eos, F_data_not_stop); } if (buffer->string[range->start] == f_fss_basic_list_open) { - f_string_length_t stop_point = range->start - 1; - status = f_utf_buffer_increment(*buffer, range, 1); if (F_status_is_error(status)) return status; - while (range->start < buffer->used && range->start <= range->stop) { - if (buffer->string[range->start] == f_string_eol[0]) break; + while (range->start <= range->stop && range->start < buffer->used) { + + if (buffer->string[range->start] == f_string_eol[0]) { + break; + } status = f_fss_is_space(*buffer, *range); @@ -272,14 +284,14 @@ extern "C" { } // while if (found_newline) { - fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*range), (*found), delimits, F_none_eos, F_none_stop) + fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*range), (*found), delimits, F_none_eos, F_none_stop); } else { - fl_macro_fss_content_return_on_overflow((*buffer), (*range), (*found), delimits, F_data_not_eos, F_data_not_stop) + fl_macro_fss_content_return_on_overflow((*buffer), (*range), (*found), delimits, F_data_not_eos, F_data_not_stop); } if (buffer->string[range->start] == f_string_eol[0]) { - f_string_length_t start = range->start; + start = range->start; range->start = first_slash; @@ -332,8 +344,11 @@ extern "C" { status = f_utf_buffer_increment(*buffer, range, 1); if (F_status_is_error(status)) return status; - while (range->start < buffer->used && range->start <= range->stop) { - if (buffer->string[range->start] == f_string_eol[0]) break; + while (range->start <= range->stop && range->start < buffer->used) { + + if (buffer->string[range->start] == f_string_eol[0]) { + break; + } status = f_fss_is_space(*buffer, *range); @@ -345,19 +360,18 @@ extern "C" { } // while if (found_newline) { - fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*range), (*found), delimits, F_none_eos, F_none_stop) + fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*range), (*found), delimits, F_none_eos, F_none_stop); } else { - fl_macro_fss_content_return_on_overflow((*buffer), (*range), (*found), delimits, F_data_not_eos, F_data_not_stop) + fl_macro_fss_content_return_on_overflow((*buffer), (*range), (*found), delimits, F_data_not_eos, F_data_not_stop); } if (buffer->string[range->start] == f_string_eol[0]) { if (found_newline) { fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); - found->array[found->used].stop = last_newline; + found->array[found->used++].stop = last_newline; range->start = last_newline + 1; - found->used++; return FL_fss_found_content; } @@ -379,16 +393,15 @@ extern "C" { if (found_newline) { fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); - found->array[found->used].stop = last_newline; + found->array[found->used++].stop = last_newline; range->start = last_newline + 1; - found->used++; - fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*range), (*found), delimits, F_none_eos, F_none_stop) + fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*range), (*found), delimits, F_none_eos, F_none_stop); return FL_fss_found_content; } - fl_macro_fss_content_return_on_overflow((*buffer), (*range), (*found), delimits, F_data_not_eos, F_data_not_stop) + fl_macro_fss_content_return_on_overflow((*buffer), (*range), (*found), delimits, F_data_not_eos, F_data_not_stop); return FL_fss_found_content_not; } @@ -402,7 +415,7 @@ extern "C" { f_status_t status = F_none; - fl_macro_fss_skip_past_delimit_placeholders(object, (*range)) + fl_macro_fss_skip_past_delimit_placeholders(object, (*range)); if (range->start > range->stop) { status = F_data_not_stop; @@ -434,6 +447,9 @@ extern "C" { const f_string_length_t used_start = destination->used; f_string_length_t i = 0; + f_string_length_t slash_count = 0; + + f_string_range_t range_next = f_string_range_t_initialize; uint8_t width = 0; @@ -450,20 +466,31 @@ extern "C" { break; } + if (object.string[range->start] == f_fss_eol) { + status = F_status_set_error(F_none_eol); + break; + } + status = f_fss_is_graph(object, *range); if (F_status_is_error(status)) break; if (status == F_true) break; + // objects will not have leading whitespaces, but having this does not generate an invalid object, so just write the spaces. if (object.string[range->start] != f_fss_delimit_placeholder) { - width = f_macro_utf_byte_width(object.string[range->start]); - - status = private_fl_fss_destination_increase_by(width, destination); + status = f_fss_is_space(object, *range); if (F_status_is_error(status)) break; - for (i = 0; i < width; i++) { - destination->string[destination->used++] = object.string[range->start + i]; - } // for + if (status == F_true) { + width = f_macro_utf_byte_width(object.string[range->start]); + + status = private_fl_fss_destination_increase_by(width, destination); + if (F_status_is_error(status)) break; + + for (i = 0; i < width; i++) { + destination->string[destination->used++] = object.string[range->start + i]; + } // for + } } status = f_utf_buffer_increment(object, range, 1); @@ -478,37 +505,29 @@ extern "C" { while (range->start <= range->stop && range->start < object.used) { if (object.string[range->start] == f_fss_delimit_slash) { - f_string_length_t slash_count = 1; + slash_count = 1; - destination->string[destination->used++] = object.string[range->start]; - range->start++; - - while (range->start <= range->stop && range->start < object.used) { + for (range->start++; range->start <= range->stop && range->start < object.used; range->start++) { if (object.string[range->start] == f_fss_delimit_placeholder) { - range->start++; continue; } else if (object.string[range->start] != f_fss_delimit_slash) { break; } - destination->string[destination->used++] = object.string[range->start]; - - range->start++; slash_count++; - } // while + } // for if (F_status_is_error(status)) break; - if (range->start > range->stop || range->start >= object.used) { - status = private_fl_fss_destination_increase_by(slash_count, destination); - if (F_status_is_error(status)) break; + status = private_fl_fss_destination_increase_by(slash_count, destination); + if (F_status_is_error(status)) break; - while (slash_count > 0) { - destination->string[destination->used++] = f_fss_delimit_slash; - slash_count--; - } // while + while (slash_count--) { + destination->string[destination->used++] = f_fss_delimit_slash; + } // while + if (range->start > range->stop || range->start >= object.used) { break; } } @@ -571,8 +590,10 @@ extern "C" { f_string_range_t buffer_position = f_string_range_t_initialize; f_string_length_t start_position = f_string_t_initialize; f_string_length_t size_allocate = 0; + f_string_length_t slash_count = 0; + f_string_length_t start = 0; - fl_macro_fss_skip_past_delimit_placeholders(content, (*range)) + fl_macro_fss_skip_past_delimit_placeholders(content, (*range)); if (range->start > range->stop) { if (destination->used + f_fss_default_allocation_step > f_string_length_t_size) { @@ -588,8 +609,7 @@ extern "C" { if (F_status_is_error(status)) return status; } - destination->string[destination->used] = f_fss_extended_close; - destination->used++; + destination->string[destination->used++] = f_fss_extended_close; return F_data_not_stop; } @@ -613,12 +633,11 @@ extern "C" { while (range->start <= range->stop && range->start < content.used) { if (content.string[range->start] == f_fss_delimit_slash && !is_comment) { - f_string_length_t slash_count = 1; - - destination->string[buffer_position.stop] = content.string[range->start]; - buffer_position.stop++; + slash_count = 1; + destination->string[buffer_position.stop++] = content.string[range->start]; has_graph = F_true; + status = f_utf_buffer_increment(content, range, 1); if (F_status_is_error(status)) return status; @@ -634,8 +653,7 @@ extern "C" { break; } - destination->string[buffer_position.stop] = content.string[range->start]; - buffer_position.stop++; + destination->string[buffer_position.stop++] = content.string[range->start]; status = f_utf_buffer_increment(content, range, 1); if (F_status_is_error(status)) return status; @@ -644,17 +662,18 @@ extern "C" { } // while if (content.string[range->start] == f_fss_basic_list_open) { - f_string_length_t start = range->start; + start = range->start; status = f_utf_buffer_increment(content, range, 1); if (F_status_is_error(status)) return status; while (range->start < content.used && range->start <= range->stop) { + if (content.string[range->start] == f_string_eol[0]) break; status = f_fss_is_space(content, *range); - if (F_status_is_error(status)) return status; + if (status == F_false) break; status = f_utf_buffer_increment(content, range, 1); @@ -669,38 +688,34 @@ extern "C" { if (F_status_is_error(status)) return status; } - while (slash_count > 0) { - destination->string[buffer_position.stop] = f_fss_delimit_slash; - buffer_position.stop++; - slash_count--; + while (slash_count--) { + destination->string[buffer_position.stop++] = f_fss_delimit_slash; } // while - destination->string[buffer_position.stop] = f_fss_delimit_slash; - buffer_position.stop++; + destination->string[buffer_position.stop++] = f_fss_delimit_slash; has_graph = F_false; is_comment = F_false; } - destination->string[buffer_position.stop] = f_fss_basic_list_open; - buffer_position.stop++; + destination->string[buffer_position.stop++] = f_fss_basic_list_open; range->start = start + 1; continue; } } else if (content.string[range->start] == f_fss_basic_list_open && !is_comment) { - f_string_length_t start = range->start; - + start = range->start; has_graph = F_true; status = f_utf_buffer_increment(content, range, 1); if (F_status_is_error(status)) return status; while (range->start < content.used && range->start <= range->stop) { + if (content.string[range->start] == f_string_eol[0]) break; status = f_fss_is_space(content, *range); - if (F_status_is_error(status)) return status; + if (status == F_false) break; status = f_utf_buffer_increment(content, range, 1); @@ -715,14 +730,12 @@ extern "C" { if (F_status_is_error(status)) return status; } - destination->string[buffer_position.stop] = f_fss_delimit_slash; - buffer_position.stop++; + destination->string[buffer_position.stop++] = f_fss_delimit_slash; has_graph = F_false; is_comment = F_false; } - destination->string[buffer_position.stop] = f_fss_basic_list_open; - buffer_position.stop++; + destination->string[buffer_position.stop++] = f_fss_basic_list_open; range->start = start + 1; continue; } @@ -741,8 +754,7 @@ extern "C" { } if (content.string[range->start] != f_fss_delimit_placeholder) { - destination->string[buffer_position.stop] = content.string[range->start]; - buffer_position.stop++; + destination->string[buffer_position.stop++] = content.string[range->start]; } status = f_utf_buffer_increment(content, range, 1); diff --git a/level_1/fl_fss/c/fss_basic_list.h b/level_1/fl_fss/c/fss_basic_list.h index c061fd8..05a1ded 100644 --- a/level_1/fl_fss/c/fss_basic_list.h +++ b/level_1/fl_fss/c/fss_basic_list.h @@ -146,6 +146,7 @@ extern "C" { * F_none_stop on success after reaching stopping point . * F_incomplete_utf (with error bit) is returned on failure to read/process a UTF-8 character due to the character being potentially incomplete. * F_memory_reallocation (with error bit) on reallocation error. + * F_none_eol (with error bit) after reaching an EOL, which is not supported by the standard. * F_parameter (with error bit) if a parameter is invalid. * F_utf (with error bit) is returned on failure to read/process a UTF-8 character. * diff --git a/level_1/fl_fss/c/fss_extended_list.c b/level_1/fl_fss/c/fss_extended_list.c index 3999b16..ec2d891 100644 --- a/level_1/fl_fss/c/fss_extended_list.c +++ b/level_1/fl_fss/c/fss_extended_list.c @@ -58,7 +58,7 @@ extern "C" { } // identify where the object ends. - while (range->start < buffer->used && range->start <= range->stop && buffer->string[range->start] != f_string_eol[0]) { + while (range->start <= range->stop && range->start < buffer->used && buffer->string[range->start] != f_string_eol[0]) { if (buffer->string[range->start] == f_fss_delimit_slash) { f_string_length_t first_slash = range->start; @@ -67,7 +67,7 @@ extern "C" { status = f_utf_buffer_increment(*buffer, range, 1); if (F_status_is_error(status)) return status; - while (range->start < buffer->used && range->start <= range->stop && (buffer->string[range->start] == f_fss_delimit_placeholder || buffer->string[range->start] == f_fss_delimit_slash)) { + while (range->start <= range->stop && range->start < buffer->used && (buffer->string[range->start] == f_fss_delimit_placeholder || buffer->string[range->start] == f_fss_delimit_slash)) { if (buffer->string[range->start] == f_fss_delimit_slash) { slash_count++; } @@ -84,7 +84,7 @@ extern "C" { status = f_utf_buffer_increment(*buffer, range, 1); if (F_status_is_error(status)) return status; - while (range->start < buffer->used && range->start <= range->stop) { + while (range->start <= range->stop && range->start < buffer->used) { if (buffer->string[range->start] == f_string_eol[0] || (status = f_fss_is_graph(*buffer, *range)) == F_true) { break; @@ -149,7 +149,7 @@ extern "C" { status = f_utf_buffer_increment(*buffer, range, 1); if (F_status_is_error(status)) return status; - while (range->start < buffer->used && range->start <= range->stop) { + while (range->start <= range->stop && range->start < buffer->used) { if (buffer->string[range->start] == f_string_eol[0]) break; status = f_fss_is_space(*buffer, *range); @@ -182,7 +182,7 @@ extern "C" { } // while // seek to the end of the line when no valid object is found. - while (range->start < buffer->used && range->start <= range->stop && buffer->string[range->start] != f_string_eol[0]) { + while (range->start <= range->stop && range->start < buffer->used && buffer->string[range->start] != f_string_eol[0]) { status = f_utf_buffer_increment(*buffer, range, 1); if (F_status_is_error(status)) return status; @@ -254,7 +254,7 @@ extern "C" { positions_start.array[0] = range->start; positions_start.used = 1; - while (range->start < buffer->used && range->start <= range->stop) { + while (range->start <= range->stop && range->start < buffer->used) { if (buffer->string[range->start] == f_string_eol[0]) { last_newline = range->start; @@ -288,7 +288,7 @@ extern "C" { return status; } - while (range->start < buffer->used && range->start <= range->stop && (buffer->string[range->start] == f_fss_delimit_placeholder || buffer->string[range->start] == f_fss_delimit_slash)) { + while (range->start <= range->stop && range->start < buffer->used && (buffer->string[range->start] == f_fss_delimit_placeholder || buffer->string[range->start] == f_fss_delimit_slash)) { position_previous = range->start; if (buffer->string[range->start] == f_fss_delimit_slash) { @@ -336,7 +336,7 @@ extern "C" { position_previous = range->start; range->start++; - while (range->start < buffer->used && range->start <= range->stop) { + while (range->start <= range->stop && range->start < buffer->used) { if (buffer->string[range->start] == f_string_eol[0]) { last_newline = range->start; @@ -485,7 +485,7 @@ extern "C" { return status; } - while (range->start < buffer->used && range->start <= range->stop) { + while (range->start <= range->stop && range->start < buffer->used) { if (buffer->string[range->start] == f_string_eol[0]) { break; @@ -561,7 +561,7 @@ extern "C" { } // No valid object open found, seek until EOL. else { - while (range->start < buffer->used && range->start <= range->stop) { + while (range->start <= range->stop && range->start < buffer->used) { if (buffer->string[range->start] == f_string_eol[0]) { last_newline = range->start; @@ -590,7 +590,7 @@ extern "C" { } } else if (buffer->string[range->start] == f_fss_extended_list_close) { - while (range->start < buffer->used && range->start <= range->stop) { + while (range->start <= range->stop && range->start < buffer->used) { position_previous = range->start; status = f_utf_buffer_increment(*buffer, range, 1); @@ -712,7 +712,7 @@ extern "C" { } // No valid object close found, seek until EOL. else { - while (range->start < buffer->used && range->start <= range->stop) { + while (range->start <= range->stop && range->start < buffer->used) { if (buffer->string[range->start] == f_string_eol[0]) { last_newline = range->start; diff --git a/level_1/fl_fss/c/private-fss.c b/level_1/fl_fss/c/private-fss.c index 6d8caf2..a6fc861 100644 --- a/level_1/fl_fss/c/private-fss.c +++ b/level_1/fl_fss/c/private-fss.c @@ -175,11 +175,15 @@ extern "C" { return FL_fss_found_object; } else { + f_string_length_t first_slash = 0; + f_string_length_t slash_count = 0; + f_string_length_t location = 0; + while (range->start <= range->stop && range->start < buffer->used) { if (buffer->string[range->start] == f_fss_delimit_slash) { - f_string_length_t first_slash = range->start; - f_string_length_t slash_count = 1; + first_slash = range->start; + slash_count = 1; status = f_utf_buffer_increment(*buffer, range, 1); if (F_status_is_error(status)) return status; @@ -214,7 +218,7 @@ extern "C" { } if (buffer->string[range->start] == quote_found) { - f_string_length_t location = range->start; + location = range->start; // check to see if there is a whitespace, EOS, or EOL after the quoted, if not, then this is not a closing quoted and delimits do not apply. if (range->start + 1 <= range->stop && range->start + 1 < buffer->used) { @@ -286,7 +290,7 @@ extern "C" { if ((status = f_fss_is_graph(*buffer, *range)) == F_true) { - while (range->start < buffer->used && range->start <= range->stop && buffer->string[range->start] != f_string_eol[0]) { + while (range->start <= range->stop && range->start < buffer->used && buffer->string[range->start] != f_string_eol[0]) { status = f_utf_buffer_increment(*buffer, range, 1); if (F_status_is_error(status)) return status; @@ -358,7 +362,7 @@ extern "C" { else if (buffer->string[range->start] == quote_found) { // check to see if there is a whitespace, EOS, or EOL after the quoted, if not, then this is not a closing quoted. { - f_string_length_t location = range->start; + location = range->start; if (range->start + 1 <= range->stop && range->start + 1 < buffer->used) { range->start++; @@ -416,7 +420,7 @@ extern "C" { } else if (buffer->string[range->start] != f_fss_delimit_placeholder) { - while (range->start < buffer->used && range->start <= range->stop && buffer->string[range->start] != f_string_eol[0]) { + while (range->start <= range->stop && range->start < buffer->used && buffer->string[range->start] != f_string_eol[0]) { status = f_utf_buffer_increment(*buffer, range, 1); if (F_status_is_error(status)) return status; @@ -473,7 +477,7 @@ extern "C" { } // seek to the end of the line when no valid object is found. - while (range->start < buffer->used && range->start <= range->stop && buffer->string[range->start] != f_string_eol[0]) { + while (range->start <= range->stop && range->start < buffer->used && buffer->string[range->start] != f_string_eol[0]) { status = f_utf_buffer_increment(*buffer, range, 1); if (F_status_is_error(status)) return status; diff --git a/level_2/fll_fss/c/fss_basic_list.c b/level_2/fll_fss/c/fss_basic_list.c index eee66b3..f40e33f 100644 --- a/level_2/fll_fss/c/fss_basic_list.c +++ b/level_2/fll_fss/c/fss_basic_list.c @@ -21,24 +21,15 @@ extern "C" { do { if (objects->used == objects->size) { f_macro_fss_objects_t_resize(status2, (*objects), objects->used + f_fss_default_allocation_step); - - if (F_status_is_error(status)) { - return status; - } + if (F_status_is_error(status)) return status; f_macro_fss_contents_t_resize(status2, (*contents), contents->used + f_fss_default_allocation_step); - - if (F_status_is_error(status)) { - return status; - } + if (F_status_is_error(status)) return status; } do { status = fl_fss_basic_list_object_read(buffer, range, &objects->array[objects->used]); - - if (F_status_is_error(status)) { - return status; - } + if (F_status_is_error(status)) return status; if (range->start >= range->stop || range->start >= buffer->used) { if (status == FL_fss_found_object || status == FL_fss_found_object_content_not) { @@ -102,8 +93,13 @@ extern "C" { // If at least some valid object was found, then return F_none equivalents. if (objects->used > initial_used) { - if (status == F_data_not_eos) return F_none_eos; - if (status == F_data_not_stop) return F_none_stop; + if (status == F_data_not_eos) { + return F_none_eos; + } + + if (status == F_data_not_stop) { + return F_none_stop; + } } return status; @@ -111,8 +107,9 @@ extern "C" { else if (status != FL_fss_found_object && status != FL_fss_found_content && status != FL_fss_found_content_not && status != FL_fss_found_object_content_not) { return status; } - // When content is found, the range->start is incremented, if content is found at range->stop, then range->start will be > range.stop. else if (range->start >= range->stop || range->start >= buffer->used) { + + // When content is found, the range->start is incremented, if content is found at range->stop, then range->start will be > range.stop. if (status == FL_fss_found_object || status == FL_fss_found_content || status == FL_fss_found_content_not || status == FL_fss_found_object_content_not) { objects->used++; contents->used++;