Update the Object read functions to be in compliance with the latest specification changes.
Review and update the code, fixing any observed problems and perform some clean ups.
I noticed that several of the list functions for Object read are almost identical.
Move this logic into into a shared private function to reduce repeated code.
The runtime tests are also updated.
I still need to review the Content read functions.
I probably may be able to also find similar, if not identical, code for the list write functions as well.
I will review the code and create a private function similar to what is done here if deemed possible and reasonable.
}
if (buffer.string[range->start] == f_fss_delimit_slash_s.string[0]) {
- slash_first = range->start;
+ slash_first = range->start++;
slash_count = 1;
- for (++range->start; range->start <= range->stop && range->start < buffer.used; ++range->start) {
+ for (; range->start <= range->stop && range->start < buffer.used && (buffer.string[range->start] == f_fss_delimit_placeholder_s.string[0] || buffer.string[range->start] == f_fss_delimit_slash_s.string[0]); ++range->start) {
if (state.interrupt) {
status = state.interrupt((void *) &state, 0);
}
if (buffer.string[range->start] == f_fss_delimit_placeholder_s.string[0]) continue;
- if (buffer.string[range->start] != f_fss_delimit_slash_s.string[0]) break;
++slash_count;
} // for
range->start = start + 1;
- status = private_fl_fss_basic_list_write_add_until_end(content, state, range, destination);
+ status = private_fl_fss_list_write_add_until_end(content, state, range, destination);
if (F_status_is_error(status)) break;
continue;
range->start = start + 1;
- status = private_fl_fss_basic_list_write_add_until_end(content, state, range, destination);
+ status = private_fl_fss_list_write_add_until_end(content, state, range, destination);
if (F_status_is_error(status)) break;
continue;
if (!delimits) return F_status_set_error(F_parameter);
#endif // _di_level_1_parameter_checking_
- const f_array_length_t delimits_used = delimits->used;
-
- f_status_t status = f_fss_skip_past_space(state, buffer, range);
- if (F_status_is_error(status)) return status;
-
- if (status == F_none_eol) {
-
- // Move the start position to after the EOL.
- ++range->start;
-
- return F_fss_found_object_not;
- }
-
- if (status == F_none_eos) return F_data_not_eos;
- if (status == F_none_stop) return F_data_not_stop;
-
- // Begin the search.
- found->start = range->start;
-
- // Ignore all comment lines.
- if (buffer.string[range->start] == f_fss_comment_s.string[0]) {
- found->start = 1;
- found->stop = 0;
-
- status = f_fss_seek_to_eol(state, buffer, range);
- if (F_status_is_error(status)) return status;
- if (status == F_none_eos) return F_data_not_eos;
- if (status == F_none_stop) return F_data_not_stop;
-
- // Move the start position to after the EOL.
- ++range->start;
-
- return F_fss_found_object_not;
- }
-
- f_array_length_t slash_first = 0;
- f_array_length_t slash_count = 0;
- f_array_length_t start = 1;
- f_array_length_t stop = 0;
-
- uint8_t graph_first = F_true;
-
- // Identify where the object ends.
- while (range->start <= range->stop && range->start < buffer.used && buffer.string[range->start] != f_fss_eol_s.string[0]) {
-
- if (state.interrupt) {
- status = state.interrupt((void *) &state, 0);
-
- if (F_status_set_fine(status) == F_interrupt) {
- status = F_status_set_error(F_interrupt);
-
- break;
- }
- }
-
- if (buffer.string[range->start] == f_fss_delimit_slash_s.string[0]) {
- slash_first = range->start;
- slash_count = 1;
-
- for (++range->start; range->start <= range->stop && range->start < buffer.used; ++range->start) {
-
- if (state.interrupt) {
- status = state.interrupt((void *) &state, 0);
-
- if (F_status_set_fine(status) == F_interrupt) {
- status = F_status_set_error(F_interrupt);
-
- break;
- }
- }
-
- if (buffer.string[range->start] == f_fss_delimit_placeholder_s.string[0]) continue;
- else if (buffer.string[range->start] != f_fss_delimit_slash_s.string[0]) break;
-
- ++slash_count;
- } // for
-
- private_macro_fl_fss_object_return_on_overflow((buffer), (*range), (*found), (*delimits), delimits_used, F_data_not_eos, F_data_not_stop);
-
- if (buffer.string[range->start] == f_fss_basic_list_open_s.string[0]) {
- graph_first = F_false;
-
- status = f_utf_buffer_increment(buffer, range, 1);
- if (F_status_is_error(status)) return status;
-
- while (range->start <= range->stop && range->start < buffer.used) {
-
- if (state.interrupt) {
- status = state.interrupt((void *) &state, 0);
-
- if (F_status_set_fine(status) == F_interrupt) {
- status = F_status_set_error(F_interrupt);
-
- break;
- }
- }
-
- if (buffer.string[range->start] == f_fss_eol_s.string[0]) break;
-
- status = f_fss_is_space(state, buffer, *range);
- if (F_status_is_error(status) || status == F_false) break;
-
- status = f_utf_buffer_increment(buffer, range, 1);
- if (F_status_is_error(status)) break;
- } // while
-
- private_macro_fl_fss_object_return_on_overflow((buffer), (*range), (*found), (*delimits), delimits_used, F_data_not_eos, F_data_not_stop);
-
- if (buffer.string[range->start] == f_fss_eol_s.string[0]) {
- found->stop = range->start;
- range->start = slash_first;
-
- status = f_array_lengths_increase_by((slash_count / 2) + 1, delimits);
-
- if (F_status_is_error(status)) {
- range->start = found->stop;
-
- break;
- }
-
- if (slash_count % 2 == 0) {
- while (slash_count > 0) {
-
- if (buffer.string[range->start] == f_fss_delimit_slash_s.string[0]) {
- if (slash_count % 2 == 1) {
- delimits->array[delimits->used] = range->start;
- ++delimits->used;
- }
-
- --slash_count;
- }
-
- status = f_utf_buffer_increment(buffer, range, 1);
-
- if (F_status_is_error(status)) {
- range->start = found->stop + 1;
- found->start = 1;
- found->stop = 0;
- delimits->used = delimits_used;
-
- return status;
- }
- } // while
-
- range->start = found->stop + 1;
- found->start = start;
- found->stop = stop + macro_f_utf_byte_width(buffer.string[stop]) - 1;
-
- return F_fss_found_object;
- }
-
- range->start = found->stop + 1;
-
- return F_fss_found_object_not;
- }
- }
- else if (graph_first && buffer.string[range->start] == f_fss_comment_s.string[0]) {
- if (graph_first) {
- graph_first = F_false;
- start = slash_first;
- }
-
- // Comments may only have white space before the '#', therefore only the first slash needs to be delimited.
- status = f_array_lengths_increase(state.step_small, delimits);
- if (F_status_is_error(status)) break;
-
- delimits->array[delimits->used++] = slash_first;
- stop = range->start++;
- }
- else {
- graph_first = F_false;
- stop = range->start;
- }
-
- continue;
- }
-
- if (buffer.string[range->start] == f_fss_basic_list_open_s.string[0]) {
- status = f_utf_buffer_increment(buffer, range, 1);
- if (F_status_is_error(status)) break;
-
- while (range->start <= range->stop && range->start < buffer.used) {
-
- if (state.interrupt) {
- status = state.interrupt((void *) &state, 0);
-
- if (F_status_set_fine(status) == F_interrupt) {
- status = F_status_set_error(F_interrupt);
-
- break;
- }
- }
-
- if (buffer.string[range->start] == f_fss_eol_s.string[0]) break;
-
- status = f_fss_is_space(state, buffer, *range);
- if (F_status_is_error(status) || status == F_false) break;
-
- status = f_utf_buffer_increment(buffer, range, 1);
- if (F_status_is_error(status)) break;
- } // while
-
- private_macro_fl_fss_object_return_on_overflow_delimited((buffer), (*range), (*found), F_none_eos, F_none_stop);
-
- if (buffer.string[range->start] == f_fss_eol_s.string[0]) {
- found->start = start;
- found->stop = stop + macro_f_utf_byte_width(buffer.string[stop]) - 1;
- ++range->start;
-
- return F_fss_found_object;
- }
-
- if (graph_first) {
- graph_first = F_false;
- start = 1;
- stop = 0;
- }
- else {
- stop = range->start;
- }
-
- continue;
- }
- else {
- status = f_fss_is_space(state, buffer, *range);
- if (F_status_is_error(status)) break;
-
- if (status == F_false) {
- if (graph_first) {
- graph_first = F_false;
- start = range->start;
- }
-
- stop = range->start;
- }
- }
-
- status = f_utf_buffer_increment(buffer, range, 1);
- if (F_status_is_error(status)) break;
- } // while
-
- found->start = 1;
- found->stop = 0;
-
- if (F_status_is_error(status)) {
- delimits->used = delimits_used;
-
- return status;
- }
-
- if (status == F_none_eos) return F_data_not_eos;
- if (status == F_none_stop) return F_data_not_stop;
-
- // Seek to the end of the line when no valid object is found.
- status = f_fss_seek_to_eol(state, buffer, range);
-
- // Move the start position to after the EOL.
- ++range->start;
-
- return F_fss_found_object_not;
+ return private_fl_fss_list_object_read(f_fss_basic_list_open_s, buffer, state, range, found, delimits);
}
#endif // _di_fl_fss_basic_list_object_read_
if (complete == f_fss_complete_partial_e || complete == f_fss_complete_partial_trim_e || complete == f_fss_complete_full_e || complete == f_fss_complete_full_trim_e) {
if (complete == f_fss_complete_full_trim_e) {
- status = private_fl_fss_basic_list_write_object_trim(destination_used, state, destination);
+ status = private_fl_fss_list_write_object_trim(destination_used, state, destination);
if (F_status_is_error(status)) {
destination->used = destination_used;
#endif // _di_level_1_parameter_checking_
f_status_t status = f_fss_skip_past_delimit(state, buffer, range);
- if (F_status_is_error(status)) return status;
-
- if (status == F_none_eos || status == F_none_stop) {
- return status;
- }
+ if (F_status_is_error(status) || status == F_none_eos || status == F_none_stop) return status;
status = f_fss_nest_increase(state.step_small, found);
if (F_status_is_error(status)) return status;
f_array_length_t depth = 0;
f_array_length_t position = 0;
-
f_array_length_t position_previous = range->start;
f_array_length_t line_start = range->start;
f_array_length_t newline_last = range->start;
f_array_length_t comment_delimit = 0;
-
f_array_length_t slash_first = 0;
f_array_length_t slash_last = 0;
-
f_array_length_t before_list_open = position_previous;
- bool is_open = F_false;
-
// Designate that this is the first graph character.
// 0x0 = false, 0x1 = true, 0x2 = false, but there is a delimited comment, comment_delimit is set.
uint8_t graph_first = 0x1;
+ uint8_t is_open = F_false;
+ uint8_t is_object = F_false;
// Initialize depth 1 start position.
// Positions_start.used is used as a max depth (such that positions_start.used == max depth + 1).
newline_last = range->start;
position_previous = range->start++;
graph_first = 0x1;
+ line_start = range->start;
if (depth) {
private_macro_fl_fss_nest_return_on_overflow((buffer), (*range), (*found), (*delimits), delimits_used, (*comments), comments_used, positions_start, objects, slashes, F_end_not_nest_eos, F_end_not_nest_stop);
private_macro_fl_fss_nest_return_on_overflow_delimited((buffer), (*range), (*found), positions_start, objects, slashes, F_none_eos, F_none_stop);
}
- line_start = range->start;
-
continue;
}
slash_first = range->start;
slash_last = range->start;
slashes.array[depth] = 1;
-
position_previous = range->start++;
- while (range->start <= range->stop && range->start < buffer.used && (buffer.string[range->start] == f_fss_delimit_placeholder_s.string[0] || buffer.string[range->start] == f_fss_delimit_slash_s.string[0])) {
+ for (; range->start <= range->stop && range->start < buffer.used && (buffer.string[range->start] == f_fss_delimit_placeholder_s.string[0] || buffer.string[range->start] == f_fss_delimit_slash_s.string[0]); ++range->start) {
if (state.interrupt) {
status = state.interrupt((void *) &state, 0);
position_previous = range->start;
- if (buffer.string[range->start] == f_fss_delimit_slash_s.string[0]) {
- slash_last = range->start++;
+ if (buffer.string[position_previous] == f_fss_delimit_slash_s.string[0]) {
+ slash_last = position_previous;
++slashes.array[depth];
}
- else {
- status = f_utf_buffer_increment(buffer, range, 1);
- if (F_status_is_error(status)) break;
- }
- } // while
+ } // for
if (F_status_is_error(status)) break;
if (buffer.string[range->start] != f_fss_delimit_placeholder_s.string[0]) {
status = f_fss_is_space(state, buffer, *range);
- if (F_status_is_error(status)) break;
-
- if (status == F_false) break;
+ if (F_status_is_error(status) || status == F_false) break;
}
position_previous = range->start;
graph_first = 0x1;
if (is_open) {
- bool is_object = F_false;
-
- if (slashes.array[depth] % 2 == 0) {
- is_object = F_true;
- }
-
+ is_object = slashes.array[depth] % 2 == 0 ? F_true : F_false;
range->start = slash_first;
status = f_array_lengths_increase_by((slashes.array[depth] / 2) + 1, delimits);
position_previous = range->start++;
} // while
- if (F_status_is_error(status)) break;
-
// When slashes are even, the object is valid and needs to be processed.
if (is_object) {
- if (++depth >= positions_start.size) {
- status = f_array_lengths_resize(depth + 2, &positions_start);
- if (F_status_is_error(status)) break;
-
+ if (++depth >= objects.size) {
status = f_string_ranges_resize(depth + 2, &objects);
if (F_status_is_error(status)) break;
+ }
- status = f_array_lengths_resize(depth + 2, &slashes);
+ if (depth >= positions_start.size) {
+ status = f_array_lengths_resize(depth + 2, &positions_start);
if (F_status_is_error(status)) break;
}
- if (positions_start.used < depth) {
- objects.used = depth;
- positions_start.used = depth;
- slashes.used = depth;
+ if (depth >= slashes.size) {
+ status = f_array_lengths_resize(depth + 2, &slashes);
+ if (F_status_is_error(status)) break;
}
objects.array[depth].start = line_start;
objects.array[depth].stop = before_list_open;
positions_start.array[depth] = newline_last + 1;
slashes.array[depth] = 0;
+
+ if (objects.used < depth) {
+ objects.used = depth;
+ }
+
+ if (positions_start.used < depth) {
+ positions_start.used = depth;
+ }
+
+ if (slashes.used < depth) {
+ slashes.used = depth;
+ }
}
}
else {
if (buffer.string[range->start] != f_fss_delimit_placeholder_s.string[0]) {
status = f_fss_is_space(state, buffer, *range);
- if (F_status_is_error(status)) break;
-
- if (status == F_false) break;
+ if (F_status_is_error(status) || status == F_false) break;
}
position_previous = range->start;
}
if (buffer.string[range->start] == f_fss_eol_s.string[0]) {
- if (++depth >= positions_start.size) {
- status = f_array_lengths_resize(depth + 2, &positions_start);
- if (F_status_is_error(status)) break;
-
+ if (++depth >= objects.size) {
status = f_string_ranges_resize(depth + 2, &objects);
if (F_status_is_error(status)) break;
+ }
- status = f_array_lengths_resize(depth + 2, &slashes);
+ if (depth >= positions_start.size) {
+ status = f_array_lengths_resize(depth + 2, &positions_start);
if (F_status_is_error(status)) break;
}
- if (positions_start.used <= depth) {
- objects.used = depth;
- positions_start.used = depth;
- slashes.used = depth;
+ if (depth >= slashes.size) {
+ status = f_array_lengths_resize(depth + 2, &slashes);
+ if (F_status_is_error(status)) break;
}
objects.array[depth].start = line_start;
positions_start.array[depth] = range->start + 1;
slashes.array[depth] = 0;
+ if (objects.used <= depth) {
+ objects.used = depth + 1;
+ }
+
+ if (positions_start.used <= depth) {
+ positions_start.used = depth + 1;
+ }
+
+ if (slashes.used <= depth) {
+ slashes.used = depth + 1;
+ }
+
if (graph_first == 0x2) {
status = f_array_lengths_increase(state.step_small, delimits);
if (F_status_is_error(status)) break;
if (buffer.string[range->start] == f_fss_eol_s.string[0]) {
newline_last = range->start;
line_start = range->start + 1;
+ graph_first = 0x1;
break;
}
}
}
else if (buffer.string[range->start] == f_fss_embedded_list_close_s.string[0]) {
- graph_first = 0x0;
-
while (range->start <= range->stop && range->start < buffer.used) {
if (state.interrupt) {
position_previous = range->start;
status = f_utf_buffer_increment(buffer, range, 1);
- if (F_status_is_error(status)) break;
+ if (F_status_is_error(status)) break;
if (buffer.string[range->start] == f_fss_eol_s.string[0]) break;
if (buffer.string[range->start] != f_fss_delimit_placeholder_s.string[0]) {
status = f_fss_is_space(state, buffer, *range);
- if (F_status_is_error(status)) break;
-
- if (status == F_false) break;
+ if (F_status_is_error(status) || status == F_false) break;
}
} // while
}
if (buffer.string[range->start] == f_fss_eol_s.string[0]) {
- status = f_fss_nest_increase(state.step_small, found);
- if (F_status_is_error(status)) break;
+ if (depth >= found->used) {
+ status = f_fss_nest_resize(depth + 2, found);
+ if (F_status_is_error(status)) break;
+ }
- if (found->depth[depth].used == found->depth[depth].size) {
+ if (found->depth[depth].used >= found->depth[depth].size) {
status = f_fss_items_increase(state.step_small, &found->depth[depth]);
if (F_status_is_error(status)) break;
}
}
}
else if (graph_first == 0x1 && buffer.string[range->start] == f_fss_comment_s.string[0]) {
- position = line_start;
- status = f_fss_seek_to_eol(state, buffer, range);
- if (F_status_is_error(status)) break;
+ // The newline_last is initialized to the range->start, which may not actually be a new line.
+ position = (buffer.string[newline_last] == f_string_eol_s.string[0]) ? newline_last + 1 : newline_last;
- status = f_string_ranges_increase(state.step_small, comments);
+ status = f_fss_seek_to_eol(state, buffer, range);
if (F_status_is_error(status)) break;
if (range->start > range->stop || range->start >= buffer.used) {
--range->start;
}
else {
+ if (graph_first == 0x2) {
+ status = f_array_lengths_increase(state.step_small, delimits);
+ if (F_status_is_error(status)) break;
+
+ delimits->array[delimits->used++] = comment_delimit;
+ }
+
newline_last = range->start;
+ graph_first = 0x1;
}
- graph_first = 0x1;
+ status = f_string_ranges_increase(state.step_small, comments);
+ if (F_status_is_error(status)) break;
comments->array[comments->used].start = position;
comments->array[comments->used++].stop = range->start++;
- line_start = range->start;
continue;
}
if (F_status_is_error(status)) return status;
if (range->start > range->stop) {
- if (!depth) return F_status_set_error(F_end_not_stop);
-
- return F_status_set_error(F_end_not_nest_stop);
+ return depth ? F_status_set_error(F_end_not_nest_stop) : F_status_set_error(F_end_not_stop);
}
- if (!depth) return F_status_set_error(F_end_not_eos);
-
- return F_status_set_error(F_end_not_nest_eos);
+ return depth ? F_status_set_error(F_end_not_nest_eos) : F_status_set_error(F_end_not_eos);
}
#endif // _di_fl_fss_embedded_list_content_read_
range->start = start + 1;
- status = private_fl_fss_basic_list_write_add_until_end(content, state, range, destination);
+ status = private_fl_fss_list_write_add_until_end(content, state, range, destination);
if (F_status_is_error(status)) break;
if (content.string[range->start] != f_fss_eol_s.string[0]) {
range->start = start + 1;
- status = private_fl_fss_basic_list_write_add_until_end(content, state, range, destination);
+ status = private_fl_fss_list_write_add_until_end(content, state, range, destination);
if (F_status_is_error(status)) break;
continue;
if (!delimits) return F_status_set_error(F_parameter);
#endif // _di_level_1_parameter_checking_
- const f_array_length_t delimits_used = delimits->used;
-
- f_status_t status = f_fss_skip_past_space(state, buffer, range);
- if (F_status_is_error(status)) return status;
-
- if (status == F_none_eol) {
-
- // Move the start position to after the EOL.
- ++range->start;
-
- return F_fss_found_object_not;
- }
-
- if (status == F_none_eos) return F_data_not_eos;
- if (status == F_none_stop) return F_data_not_stop;
-
- // Return found nothing if this line only contains white space and delimit placeholders.
- if (buffer.string[range->start] == f_fss_eol_s.string[0]) {
-
- // Move the start position to after the EOL.
- ++range->start;
-
- return F_fss_found_object_not;
- }
-
- // Begin the search.
- const f_number_unsigned_t begin = range->start;
- found->start = range->start;
-
- // Ignore all comment lines.
- if (buffer.string[range->start] == f_fss_comment_s.string[0]) {
- status = f_fss_seek_to_eol(state, buffer, range);
-
- if (F_status_is_error(status)) {
- delimits->used = delimits_used;
-
- return status;
- }
-
- if (status == F_none_eos) return F_data_not_eos;
- if (status == F_none_stop) return F_data_not_stop;
-
- // Move the start position to after the EOL.
- ++range->start;
-
- return F_fss_found_object_not;
- }
-
- f_array_length_t start = 0;
- f_array_length_t stop = 0;
- f_array_length_t slash_first = 0;
- f_array_length_t slash_count = 0;
-
- bool graph_first = F_true;
-
- // Identify where the object ends.
- while (range->start <= range->stop && range->start < buffer.used && buffer.string[range->start] != f_fss_eol_s.string[0]) {
-
- if (state.interrupt) {
- status = state.interrupt((void *) &state, 0);
-
- if (F_status_set_fine(status) == F_interrupt) {
- status = F_status_set_error(F_interrupt);
-
- break;
- }
- }
-
- if (buffer.string[range->start] == f_fss_delimit_slash_s.string[0]) {
- slash_first = range->start;
- slash_count = 1;
-
- status = f_utf_buffer_increment(buffer, range, 1);
- if (F_status_is_error(status)) break;
-
- while (range->start <= range->stop && range->start < buffer.used && (buffer.string[range->start] == f_fss_delimit_placeholder_s.string[0] || buffer.string[range->start] == f_fss_delimit_slash_s.string[0])) {
-
- if (state.interrupt) {
- status = state.interrupt((void *) &state, 0);
-
- if (F_status_set_fine(status) == F_interrupt) {
- status = F_status_set_error(F_interrupt);
-
- break;
- }
- }
-
- if (buffer.string[range->start] == f_fss_delimit_slash_s.string[0]) slash_count++;
-
- status = f_utf_buffer_increment(buffer, range, 1);
- if (F_status_is_error(status)) break;
- } // while
-
- if (F_status_is_error(status)) break;
-
- private_macro_fl_fss_object_return_on_overflow((buffer), (*range), (*found), (*delimits), delimits_used, F_data_not_eos, F_data_not_stop);
-
- if (buffer.string[range->start] == f_fss_embedded_list_open_s.string[0]) {
- graph_first = F_false;
- stop = range->start++;
-
- while (range->start <= range->stop && range->start < buffer.used) {
-
- if (state.interrupt) {
- status = state.interrupt((void *) &state, 0);
-
- if (F_status_set_fine(status) == F_interrupt) {
- status = F_status_set_error(F_interrupt);
-
- break;
- }
- }
-
- if (buffer.string[range->start] == f_fss_eol_s.string[0]) break;
-
- status = f_fss_is_graph(state, buffer, *range);
- if (F_status_is_error(status)) break;
-
- if (status == F_true) break;
-
- status = f_utf_buffer_increment(buffer, range, 1);
- if (F_status_is_error(status)) break;
- } // while
-
- private_macro_fl_fss_object_return_on_overflow((buffer), (*range), (*found), (*delimits), delimits_used, F_data_not_eos, F_data_not_stop);
-
- if (buffer.string[range->start] == f_fss_eol_s.string[0]) {
- start = range->start;
-
- range->start = slash_first;
-
- status = f_array_lengths_increase_by((slash_count / 2) + 1, delimits);
- if (F_status_is_error(status)) break;
-
- if (slash_count % 2 == 0) {
- while (slash_count > 0) {
-
- if (buffer.string[range->start] == f_fss_delimit_slash_s.string[0]) {
- if (slash_count % 2 == 1) {
- delimits->array[delimits->used++] = range->start;
- }
-
- --slash_count;
- }
-
- status = f_utf_buffer_increment(buffer, range, 1);
- if (F_status_is_error(status)) break;
- } // while
-
- if (F_status_is_error(status)) break;
-
- if (stop > begin) {
- found->stop = stop - 1;
- }
- else {
- found->start = 1;
- found->stop = 0;
- }
-
- range->start = start + 1;
-
- return F_fss_found_object;
- }
-
- range->start = start + 1;
- return F_fss_found_object_not;
- }
- }
- else if (graph_first && buffer.string[range->start] == f_fss_comment_s.string[0]) {
- graph_first = F_false;
-
- // Comments may only have white space before the '#', therefore only the first slash needs to be delimited.
- status = f_array_lengths_increase(state.step_small, delimits);
- if (F_status_is_error(status)) break;
-
- delimits->array[delimits->used++] = slash_first;
- ++range->start;
- }
- else {
- graph_first = F_false;
- }
-
- continue;
- }
- else if (buffer.string[range->start] == f_fss_embedded_list_open_s.string[0]) {
- graph_first = F_false;
- stop = range->start;
-
- status = f_utf_buffer_increment(buffer, range, 1);
- if (F_status_is_error(status)) break;
-
- while (range->start <= range->stop && range->start < buffer.used) {
-
- if (state.interrupt) {
- status = state.interrupt((void *) &state, 0);
-
- if (F_status_set_fine(status) == F_interrupt) {
- status = F_status_set_error(F_interrupt);
-
- break;
- }
- }
-
- if (buffer.string[range->start] == f_fss_eol_s.string[0]) break;
-
- status = f_fss_is_space(state, buffer, *range);
- if (F_status_is_error(status)) break;
-
- if (status == F_false) break;
-
- status = f_utf_buffer_increment(buffer, range, 1);
- if (F_status_is_error(status)) break;
- } // while
-
- if (F_status_is_error(status)) break;
-
- private_macro_fl_fss_object_return_on_overflow_delimited((buffer), (*range), (*found), F_none_eos, F_none_stop);
-
- if (buffer.string[range->start] == f_fss_eol_s.string[0]) {
- if (stop > begin) {
- found->stop = stop - 1;
- }
- else {
- found->start = 1;
- found->stop = 0;
- }
-
- // Move the start position to after the EOL.
- ++range->start;
-
- return F_fss_found_object;
- }
-
- continue;
- }
- else if (graph_first) {
- status = f_fss_is_space(state, buffer, *range);
- if (F_status_is_error(status)) break;
-
- if (status == F_false) {
- graph_first = F_false;
- }
- }
-
- status = f_utf_buffer_increment(buffer, range, 1);
- if (F_status_is_error(status)) break;
- } // while
-
- if (F_status_is_error(status)) {
- delimits->used = delimits_used;
-
- return status;
- }
-
- // Seek to the end of the line when no valid object is found.
- while (range->start <= range->stop && range->start < buffer.used && buffer.string[range->start] != f_fss_eol_s.string[0]) {
-
- if (state.interrupt) {
- status = state.interrupt((void *) &state, 0);
-
- if (F_status_set_fine(status) == F_interrupt) {
- status = F_status_set_error(F_interrupt);
-
- break;
- }
- }
-
- status = f_utf_buffer_increment(buffer, range, 1);
-
- if (F_status_is_error(status)) {
- delimits->used = delimits_used;
-
- return status;
- }
- } // while
-
- private_macro_fl_fss_object_return_on_overflow((buffer), (*range), (*found), (*delimits), delimits_used, F_data_not_eos, F_data_not_stop);
-
- status = f_utf_buffer_increment(buffer, range, 1);
-
- if (F_status_is_error(status)) {
- delimits->used = delimits_used;
-
- return status;
- }
-
- return F_fss_found_object_not;
+ return private_fl_fss_list_object_read(f_fss_embedded_list_open_s, buffer, state, range, found, delimits);
}
#endif // _di_fl_fss_embedded_list_object_read_
if (complete == f_fss_complete_partial_e || complete == f_fss_complete_partial_trim_e || complete == f_fss_complete_full_e || complete == f_fss_complete_full_trim_e) {
if (complete == f_fss_complete_full_trim_e) {
- status = private_fl_fss_basic_list_write_object_trim(destination_used, state, destination);
+ status = private_fl_fss_list_write_object_trim(destination_used, state, destination);
if (F_status_is_error(status)) {
destination->used = destination_used;
uint8_t content_found = 0;
f_fss_quote_t quote = f_fss_quote_type_none_e;
+ f_string_range_t content_partial = f_string_range_t_initialize;
while (range->start <= range->stop && range->start < buffer.used) {
- f_string_range_t content_partial = f_string_range_t_initialize;
+ content_partial.start = 1;
+ content_partial.stop = 0;
status = private_fl_fss_basic_or_extended_read(buffer, (state.flag & f_fss_state_quote_not_e) ? 0x2 : 0x0, state, range, &content_partial, "e, delimits);
if (!comments) return F_status_set_error(F_parameter);
#endif // _di_level_1_parameter_checking_
- const f_array_length_t delimits_used = delimits->used;
- const f_array_length_t comments_used = comments->used;
-
f_status_t status = f_fss_skip_past_delimit(state, buffer, range);
if (F_status_is_error(status)) return status;
+ const f_array_length_t delimits_used = delimits->used;
+ const f_array_length_t comments_used = comments->used;
+
private_macro_fl_fss_content_with_comments_return_on_overflow((buffer), (*range), (*found), (*delimits), delimits_used, (*comments), comments_used, F_none_eos, F_none_stop);
status = f_string_ranges_increase(state.step_small, found);
if (F_status_is_error(status)) return status;
- found->array[found->used].start = range->start;
-
f_array_length_t newline_last = range->start;
f_array_length_t slash_first = 0;
f_array_length_t slash_count = 0;
f_array_length_t comment_start = 0;
+ found->array[found->used].start = range->start;
+
// Identify where the content ends.
while (range->start <= range->stop && range->start < buffer.used) {
if (F_status_is_error(status)) {
delimits->used = delimits_used;
comments->used = comments_used;
-
- return status;
+ }
+ else {
+ status = F_fss_found_content_not;
}
- return F_fss_found_content_not;
+ return status;
}
#endif // _di_fl_fss_extended_list_content_read_
range->start = start + 1;
- status = private_fl_fss_basic_list_write_add_until_end(content, state, range, destination);
+ status = private_fl_fss_list_write_add_until_end(content, state, range, destination);
if (F_status_is_error(status)) break;
if (content.string[range->start] != f_fss_eol_s.string[0]) {
range->start = start + 1;
- status = private_fl_fss_basic_list_write_add_until_end(content, state, range, destination);
+ status = private_fl_fss_list_write_add_until_end(content, state, range, destination);
if (F_status_is_error(status)) break;
continue;
if (!delimits) return F_status_set_error(F_parameter);
#endif // _di_level_1_parameter_checking_
- const f_array_length_t delimits_used = delimits->used;
-
- f_status_t status = f_fss_skip_past_space(state, buffer, range);
- if (F_status_is_error(status)) return status;
-
- if (status == F_none_eol) {
-
- // Move the start position to after the EOL.
- ++range->start;
-
- return F_fss_found_object_not;
- }
-
- if (status == F_none_eos) return F_data_not_eos;
- if (status == F_none_stop) return F_data_not_stop;
-
- // Return found nothing if this line only contains white space and delimit placeholders.
- if (buffer.string[range->start] == f_fss_eol_s.string[0]) {
-
- // Move the start position to after the EOL.
- ++range->start;
-
- return F_fss_found_object_not;
- }
-
- // Begin the search.
- const f_number_unsigned_t begin = range->start;
- found->start = range->start;
-
- // Ignore all comment lines.
- if (buffer.string[range->start] == f_fss_comment_s.string[0]) {
- status = f_fss_seek_to_eol(state, buffer, range);
-
- if (F_status_is_error(status)) {
- delimits->used = delimits_used;
-
- return status;
- }
-
- if (status == F_none_eos) return F_data_not_eos;
- if (status == F_none_stop) return F_data_not_stop;
-
- // Move the start position to after the EOL.
- ++range->start;
-
- return F_fss_found_object_not;
- }
-
- f_array_length_t start = 0;
- f_array_length_t stop = 0;
- f_array_length_t slash_first = 0;
- f_array_length_t slash_count = 0;
-
- // Designate that this is the first graph character.
- uint8_t graph_first = F_true;
-
- // Identify where the object ends.
- while (range->start <= range->stop && range->start < buffer.used && buffer.string[range->start] != f_fss_eol_s.string[0]) {
-
- if (state.interrupt) {
- status = state.interrupt((void *) &state, 0);
-
- if (F_status_set_fine(status) == F_interrupt) {
- status = F_status_set_error(F_interrupt);
-
- break;
- }
- }
-
- if (buffer.string[range->start] == f_fss_delimit_slash_s.string[0]) {
- slash_first = range->start;
- slash_count = 1;
-
- status = f_utf_buffer_increment(buffer, range, 1);
- if (F_status_is_error(status)) break;
-
- while (range->start <= range->stop && range->start < buffer.used && (buffer.string[range->start] == f_fss_delimit_placeholder_s.string[0] || buffer.string[range->start] == f_fss_delimit_slash_s.string[0])) {
-
- if (state.interrupt) {
- status = state.interrupt((void *) &state, 0);
-
- if (F_status_set_fine(status) == F_interrupt) {
- status = F_status_set_error(F_interrupt);
-
- break;
- }
- }
-
- if (buffer.string[range->start] == f_fss_delimit_slash_s.string[0]) ++slash_count;
-
- status = f_utf_buffer_increment(buffer, range, 1);
- if (F_status_is_error(status)) break;
- } // while
-
- if (F_status_is_error(status)) break;
-
- private_macro_fl_fss_object_return_on_overflow((buffer), (*range), (*found), (*delimits), delimits_used, F_data_not_eos, F_data_not_stop);
-
- if (buffer.string[range->start] == f_fss_extended_list_open_s.string[0]) {
- graph_first = F_false;
- stop = range->start++;
-
- while (range->start <= range->stop && range->start < buffer.used) {
-
- if (state.interrupt) {
- status = state.interrupt((void *) &state, 0);
-
- if (F_status_set_fine(status) == F_interrupt) {
- status = F_status_set_error(F_interrupt);
-
- break;
- }
- }
-
- if (buffer.string[range->start] == f_fss_eol_s.string[0]) break;
-
- status = f_fss_is_graph(state, buffer, *range);
- if (F_status_is_error(status)) break;
-
- if (status == F_true) break;
-
- status = f_utf_buffer_increment(buffer, range, 1);
- if (F_status_is_error(status)) break;
- } // while
-
- private_macro_fl_fss_object_return_on_overflow((buffer), (*range), (*found), (*delimits), delimits_used, F_data_not_eos, F_data_not_stop);
-
- if (buffer.string[range->start] == f_fss_eol_s.string[0]) {
- start = range->start;
- range->start = slash_first;
-
- status = f_array_lengths_increase_by((slash_count / 2) + 1, delimits);
- if (F_status_is_error(status)) break;
-
- if (slash_count % 2 == 0) {
- while (slash_count > 0) {
-
- if (buffer.string[range->start] == f_fss_delimit_slash_s.string[0]) {
- if (slash_count % 2 == 1) {
- delimits->array[delimits->used++] = range->start;
- }
-
- --slash_count;
- }
-
- status = f_utf_buffer_increment(buffer, range, 1);
- if (F_status_is_error(status)) break;
- } // while
-
- if (F_status_is_error(status)) break;
-
- if (stop > begin) {
- found->stop = stop - 1;
- }
- else {
- found->start = 1;
- found->stop = 0;
- }
-
- range->start = start + 1;
-
- return F_fss_found_object;
- }
-
- range->start = start + 1;
-
- return F_fss_found_object_not;
- }
- }
- else if (graph_first && buffer.string[range->start] == f_fss_comment_s.string[0]) {
- graph_first = F_false;
-
- // Comments may only have white space before the '#', therefore only the first slash needs to be delimited.
- status = f_array_lengths_increase(state.step_small, delimits);
- if (F_status_is_error(status)) break;
-
- delimits->array[delimits->used++] = slash_first;
- ++range->start;
- }
- else {
- graph_first = F_false;
- }
-
- continue;
- }
- else if (buffer.string[range->start] == f_fss_extended_list_open_s.string[0]) {
- graph_first = F_false;
- stop = range->start;
-
- status = f_utf_buffer_increment(buffer, range, 1);
- if (F_status_is_error(status)) break;
-
- while (range->start <= range->stop && range->start < buffer.used) {
-
- if (state.interrupt) {
- status = state.interrupt((void *) &state, 0);
-
- if (F_status_set_fine(status) == F_interrupt) {
- status = F_status_set_error(F_interrupt);
-
- break;
- }
- }
-
- if (buffer.string[range->start] == f_fss_eol_s.string[0]) break;
-
- status = f_fss_is_space(state, buffer, *range);
- if (F_status_is_error(status)) break;
-
- if (status == F_false) break;
-
- status = f_utf_buffer_increment(buffer, range, 1);
- if (F_status_is_error(status)) break;
- } // while
-
- if (F_status_is_error(status)) break;
-
- private_macro_fl_fss_object_return_on_overflow_delimited((buffer), (*range), (*found), F_none_eos, F_none_stop);
-
- if (buffer.string[range->start] == f_fss_eol_s.string[0]) {
- if (stop > begin) {
- found->stop = stop - 1;
- }
- else {
- found->start = 1;
- found->stop = 0;
- }
-
- // Move the start position to after the EOL.
- ++range->start;
-
- return F_fss_found_object;
- }
-
- continue;
- }
- else if (graph_first) {
- status = f_fss_is_space(state, buffer, *range);
- if (F_status_is_error(status)) break;
-
- if (status == F_false) {
- graph_first = F_false;
- }
- }
-
- status = f_utf_buffer_increment(buffer, range, 1);
- if (F_status_is_error(status)) break;
- } // while
-
- if (F_status_is_error(status)) {
- delimits->used = delimits_used;
-
- return status;
- }
-
- // Seek to the end of the line when no valid object is found.
- while (range->start <= range->stop && range->start < buffer.used && buffer.string[range->start] != f_fss_eol_s.string[0]) {
-
- if (state.interrupt) {
- status = state.interrupt((void *) &state, 0);
-
- if (F_status_set_fine(status) == F_interrupt) {
- status = F_status_set_error(F_interrupt);
-
- break;
- }
- }
-
- status = f_utf_buffer_increment(buffer, range, 1);
-
- if (F_status_is_error(status)) {
- delimits->used = delimits_used;
-
- return status;
- }
- } // while
-
- private_macro_fl_fss_object_return_on_overflow((buffer), (*range), (*found), (*delimits), delimits_used, F_data_not_eos, F_data_not_stop);
-
- status = f_utf_buffer_increment(buffer, range, 1);
-
- if (F_status_is_error(status)) {
- delimits->used = delimits_used;
-
- return status;
- }
-
- return F_fss_found_object_not;
+ return private_fl_fss_list_object_read(f_fss_extended_list_open_s, buffer, state, range, found, delimits);
}
#endif // _di_fl_fss_extended_list_object_read_
if (complete == f_fss_complete_partial_e || complete == f_fss_complete_partial_trim_e || complete == f_fss_complete_full_e || complete == f_fss_complete_full_trim_e) {
if (complete == f_fss_complete_full_trim_e) {
- status = private_fl_fss_basic_list_write_object_trim(destination_used, state, destination);
+ status = private_fl_fss_list_write_object_trim(destination_used, state, destination);
if (F_status_is_error(status)) {
destination->used = destination_used;
#ifndef _di_private_macro_fl_fss_object_return_on_overflow_
#define private_macro_fl_fss_object_return_on_overflow(buffer, range, found, delimits, delimits_used, eos_status, stop_status) \
if (range.start >= buffer.used) { \
+ found.stop = buffer.used - 1; \
delimits.used = delimits_used; \
- found.start = 1; \
- found.stop = 0; \
return eos_status; \
} \
else if (range.start > range.stop) { \
+ found.stop = range.stop; \
delimits.used = delimits_used; \
- found.start = 1; \
- found.stop = 0; \
return stop_status; \
}
#endif // _di_private_macro_fl_fss_object_return_on_overflow_
#ifndef _di_private_macro_fl_fss_object_return_on_overflow_delimited_
#define private_macro_fl_fss_object_return_on_overflow_delimited(buffer, range, found, eos_status, stop_status) \
if (range.start >= buffer.used) { \
- found.start = 1; \
- found.stop = 0; \
+ found.stop = buffer.used - 1; \
return eos_status; \
} \
else if (range.start > range.stop) { \
- found.start = 1; \
- found.stop = 0; \
+ found.stop = range.stop; \
return stop_status; \
}
#endif // _di_private_macro_fl_fss_object_return_on_overflow_delimited_
extern "C" {
#endif
+#if !defined(_di_fl_fss_basic_list_object_read_) || !defined(_di_fl_fss_embedded_list_object_read_) || !defined(_di_fl_fss_extended_list_object_read_)
+ f_status_t private_fl_fss_list_object_read(const f_string_static_t list_open, const f_string_static_t buffer, f_state_t state, f_string_range_t * const range, f_fss_object_t * const found, f_fss_delimits_t * const delimits) {
+
+ f_status_t status = f_fss_skip_past_space(state, buffer, range);
+ if (F_status_is_error(status)) return status;
+
+ if (status == F_none_eol) {
+
+ // Move the start position to after the EOL.
+ ++range->start;
+
+ return F_fss_found_object_not;
+ }
+
+ if (status == F_none_eos) return F_data_not_eos;
+ if (status == F_none_stop) return F_data_not_stop;
+
+ // Return found nothing if this line only contains white space and delimit placeholders.
+ if (buffer.string[range->start] == f_fss_eol_s.string[0]) {
+
+ // Move the start position to after the EOL.
+ ++range->start;
+
+ return F_fss_found_object_not;
+ }
+
+ // Ignore all comment lines.
+ if (buffer.string[range->start] == f_fss_comment_s.string[0]) {
+ status = f_fss_seek_to_eol(state, buffer, range);
+
+ if (F_status_is_error(status)) return status;
+ if (status == F_none_eos) return F_data_not_eos;
+ if (status == F_none_stop) return F_data_not_stop;
+
+ // Move the start position to after the EOL.
+ ++range->start;
+
+ return F_fss_found_object_not;
+ }
+
+ const f_array_length_t delimits_used = delimits->used;
+
+ f_array_length_t slash_first = 0;
+ f_array_length_t slash_count = 0;
+ f_array_length_t start = 1;
+ f_array_length_t stop = 0;
+
+ uint8_t graph_first = F_true;
+
+ found->start = range->start;
+
+ // Identify where the object ends.
+ while (range->start <= range->stop && range->start < buffer.used && buffer.string[range->start] != f_fss_eol_s.string[0]) {
+
+ if (state.interrupt) {
+ status = state.interrupt((void *) &state, 0);
+
+ if (F_status_set_fine(status) == F_interrupt) {
+ delimits->used = delimits_used;
+
+ return F_status_set_error(F_interrupt);
+ }
+ }
+
+ if (buffer.string[range->start] == f_fss_delimit_slash_s.string[0]) {
+ slash_first = range->start++;
+ slash_count = 1;
+
+ for (; range->start <= range->stop && range->start < buffer.used && (buffer.string[range->start] == f_fss_delimit_placeholder_s.string[0] || buffer.string[range->start] == f_fss_delimit_slash_s.string[0]); ++range->start) {
+
+ if (state.interrupt) {
+ status = state.interrupt((void *) &state, 0);
+
+ if (F_status_set_fine(status) == F_interrupt) {
+ delimits->used = delimits_used;
+
+ return F_status_set_error(F_interrupt);
+ }
+ }
+
+ if (buffer.string[range->start] == f_fss_delimit_slash_s.string[0]) slash_count++;
+ } // for
+
+ private_macro_fl_fss_object_return_on_overflow((buffer), (*range), (*found), (*delimits), delimits_used, F_data_not_eos, F_data_not_stop);
+
+ if (buffer.string[range->start] == list_open.string[0]) {
+ graph_first = F_false;
+ stop = range->start++;
+
+ while (range->start <= range->stop && range->start < buffer.used) {
+
+ if (state.interrupt) {
+ status = state.interrupt((void *) &state, 0);
+
+ if (F_status_set_fine(status) == F_interrupt) {
+ delimits->used = delimits_used;
+
+ return F_status_set_error(F_interrupt);
+ }
+ }
+
+ if (buffer.string[range->start] == f_fss_eol_s.string[0]) break;
+
+ status = f_fss_is_space(state, buffer, *range);
+ if (status == F_false) break;
+
+ if (F_status_is_error_not(status)) {
+ status = f_utf_buffer_increment(buffer, range, 1);
+ }
+
+ if (F_status_is_error(status)) {
+ delimits->used = delimits_used;
+
+ return status;
+ }
+ } // while
+
+ private_macro_fl_fss_object_return_on_overflow((buffer), (*range), (*found), (*delimits), delimits_used, F_data_not_eos, F_data_not_stop);
+
+ if (buffer.string[range->start] == f_fss_eol_s.string[0]) {
+ found->stop = range->start;
+ range->start = slash_first;
+
+ status = f_array_lengths_increase_by((slash_count / 2) + 1, delimits);
+
+ if (F_status_is_error(status)) {
+ range->start = found->stop;
+ delimits->used = delimits_used;
+
+ return status;
+ }
+
+ if (slash_count % 2 == 0) {
+ while (slash_count > 0) {
+
+ if (buffer.string[range->start] == f_fss_delimit_slash_s.string[0]) {
+ if (slash_count % 2 == 1) {
+ delimits->array[delimits->used++] = range->start;
+ }
+
+ --slash_count;
+ ++range->start;
+ }
+ else {
+ status = f_utf_buffer_increment(buffer, range, 1);
+
+ if (F_status_is_error(status)) {
+ range->start = found->stop;
+ delimits->used = delimits_used;
+
+ return status;
+ }
+ }
+ } // while
+
+ range->start = found->stop + 1;
+ found->start = start;
+ found->stop = stop + macro_f_utf_byte_width(buffer.string[stop]) - 1;
+ status = F_fss_found_object;
+ }
+ else {
+ range->start = found->stop + 1;
+ status = F_fss_found_object_not;
+ }
+
+ return status;
+ }
+ }
+ else if (graph_first && buffer.string[range->start] == f_fss_comment_s.string[0]) {
+ if (graph_first) {
+ graph_first = F_false;
+ start = slash_first;
+ }
+
+ // Comments may only have white space before the '#', therefore only the first slash needs to be delimited.
+ status = f_array_lengths_increase(state.step_small, delimits);
+
+ if (F_status_is_error(status)) {
+ delimits->used = delimits_used;
+
+ return status;
+ }
+
+ delimits->array[delimits->used++] = slash_first;
+ stop = range->start++;
+ }
+ else {
+ graph_first = F_false;
+ stop = range->start;
+ }
+
+ continue;
+ }
+ else if (buffer.string[range->start] == list_open.string[0]) {
+ ++range->start;
+
+ while (range->start <= range->stop && range->start < buffer.used) {
+
+ if (state.interrupt) {
+ status = state.interrupt((void *) &state, 0);
+
+ if (F_status_set_fine(status) == F_interrupt) {
+ delimits->used = delimits_used;
+
+ return F_status_set_error(F_interrupt);
+ }
+ }
+
+ if (buffer.string[range->start] == f_fss_eol_s.string[0]) break;
+
+ status = f_fss_is_space(state, buffer, *range);
+ if (status == F_false) break;
+
+ if (F_status_is_error_not(status)) {
+ status = f_utf_buffer_increment(buffer, range, 1);
+ }
+
+ if (F_status_is_error(status)) {
+ delimits->used = delimits_used;
+
+ return status;
+ }
+ } // while
+
+ private_macro_fl_fss_object_return_on_overflow_delimited((buffer), (*range), (*found), F_none_eos, F_none_stop);
+
+ if (buffer.string[range->start] == f_fss_eol_s.string[0]) {
+ found->start = start;
+ found->stop = stop + macro_f_utf_byte_width(buffer.string[stop]) - 1;
+ ++range->start;
+
+ return F_fss_found_object;
+ }
+
+ if (graph_first) {
+ graph_first = F_false;
+ start = 1;
+ stop = 0;
+ }
+ else {
+ stop = range->start;
+ }
+
+ continue;
+ }
+ else {
+ status = f_fss_is_space(state, buffer, *range);
+
+ if (F_status_is_error(status)) {
+ delimits->used = delimits_used;
+
+ return status;
+ }
+
+ if (status == F_false) {
+ if (graph_first) {
+ graph_first = F_false;
+ start = range->start;
+ }
+
+ stop = range->start;
+ }
+ }
+
+ status = f_utf_buffer_increment(buffer, range, 1);
+
+ if (F_status_is_error(status)) {
+ delimits->used = delimits_used;
+
+ return status;
+ }
+ } // while
+
+ if (range->start >= buffer.used || range->start > range->stop) {
+ if (range->start >= buffer.used) {
+ found->stop = buffer.used - 1;
+ status = F_data_not_eos;
+ }
+ else {
+ found->stop = range->stop;
+ status = F_data_not_stop;
+ }
+
+ return status;
+ }
+
+ // Seek to the end of the line when no valid object is found.
+ if (F_status_is_error_not(status)) {
+ status = f_fss_seek_to_eol(state, buffer, range);
+ }
+
+ if (F_status_is_error(status)) {
+ delimits->used = delimits_used;
+ }
+ else {
+ status = F_fss_found_object_not;
+
+ // Move the start position to after the EOL.
+ ++range->start;
+ }
+
+ return status;
+ }
+#endif // !defined(_di_fl_fss_basic_list_object_read_) || !defined(_di_fl_fss_embedded_list_object_read_) || !defined(_di_fl_fss_extended_list_object_read_)
+
#if !defined(_di_fl_fss_basic_list_content_write_) || !defined(_di_fl_fss_extended_list_content_write_) || !defined(_di_fl_fss_embedded_list_content_write_)
- f_status_t private_fl_fss_basic_list_write_add_until_end(const f_string_static_t buffer, f_state_t state, f_string_range_t * const range, f_string_dynamic_t * const destination) {
+ f_status_t private_fl_fss_list_write_add_until_end(const f_string_static_t buffer, f_state_t state, f_string_range_t * const range, f_string_dynamic_t * const destination) {
f_status_t status = F_none;
#endif // !defined(_di_fl_fss_basic_list_content_write_) || !defined(_di_fl_fss_extended_list_content_write_) || !defined(_di_fl_fss_embedded_list_content_write_)
#if !defined(_di_fl_fss_basic_list_object_write_) || !defined(_di_fl_fss_extended_list_object_write_)
- f_status_t private_fl_fss_basic_list_write_object_trim(const f_array_length_t used_start, f_state_t state, f_string_dynamic_t * const destination) {
+ f_status_t private_fl_fss_list_write_object_trim(const f_array_length_t used_start, f_state_t state, f_string_dynamic_t * const destination) {
f_status_t status = F_none;
f_string_range_t destination_range = macro_f_string_range_t_initialize2(destination->used);
// Ignore all comment lines.
if ((flag & 0x1) && buffer.string[range->start] == f_fss_comment_s.string[0]) {
-
- while (buffer.string[range->start] != f_fss_eol_s.string[0]) {
-
- if (state.interrupt) {
- status = state.interrupt((void *) &state, 0);
-
- if (F_status_set_fine(status) == F_interrupt) {
- return F_status_set_error(F_interrupt);
- }
- }
-
- ++range->start;
-
- if (range->start >= buffer.used) {
- return F_data_not_eos;
- }
-
- if (range->start > range->stop) {
- return F_data_not_stop;
- }
- } // while
+ status = f_fss_seek_to_eol(state, buffer, range);
+ if (F_status_is_error(status)) return status;
+ if (range->start >= buffer.used) return F_data_not_eos;
+ if (range->start > range->stop) return F_data_not_stop;
// Move the start position to after the EOL.
++range->start;
// Handle quote support.
f_char_t quote_found = 0;
- if (quote) {
- *quote = f_fss_quote_type_none_e;
- }
+ if (quote) *quote = f_fss_quote_type_none_e;
// Identify where the object begins.
if (buffer.string[range->start] == f_fss_delimit_slash_s.string[0]) {
if (state.interrupt) {
status = state.interrupt((void *) &state, 0);
-
- if (F_status_set_fine(status) == F_interrupt) {
- status = F_status_set_error(F_interrupt);
-
- break;
- }
+ if (F_status_set_fine(status) == F_interrupt) return F_status_set_error(F_interrupt);
}
status = f_fss_is_zero_width(state, buffer, *range);
if (status == F_true) {
status = f_utf_buffer_increment(buffer, range, 1);
- if (F_status_is_error(status)) break;
+ if (F_status_is_error(status)) return status;
continue;
}
}
status = f_utf_buffer_increment(buffer, range, 1);
- if (F_status_is_error(status)) break;
-
- if (buffer.string[range->start] == f_fss_eol_s.string[0]) {
- return F_fss_found_object_content_not;
- }
+ if (F_status_is_error(status)) return status;
- return F_fss_found_object;
+ return buffer.string[range->start] == f_fss_eol_s.string[0] ? F_fss_found_object_content_not : F_fss_found_object;
}
break;
}
status = f_utf_buffer_increment(buffer, range, 1);
- if (F_status_is_error(status)) break;
+ if (F_status_is_error(status)) return status;
} // while
- if (F_status_is_error(status)) return status;
-
if (range->start >= buffer.used) {
found->stop = buffer.used - 1;
if (F_status_is_error(status)) return status;
delimits->array[delimits->used++] = first_slash;
-
- status = f_utf_buffer_increment(buffer, range, 1);
- if (F_status_is_error(status)) return status;
+ ++range->start;
}
}
else if (!(flag & 0x2) && (buffer.string[range->start] == f_fss_quote_single_s.string[0] || buffer.string[range->start] == f_fss_delimit_quote_double_s.string[0] || buffer.string[range->start] == f_fss_quote_backtick_s.string[0])) {
quote_found = buffer.string[range->start];
-
- status = f_utf_buffer_increment(buffer, range, 1);
- if (F_status_is_error(status)) return status;
-
- found->start = range->start;
+ found->start = ++range->start;
}
// Identify where the object ends.
if (state.interrupt) {
status = state.interrupt((void *) &state, 0);
-
- if (F_status_set_fine(status) == F_interrupt) {
- return F_status_set_error(F_interrupt);
- }
+ if (F_status_set_fine(status) == F_interrupt) return F_status_set_error(F_interrupt);
}
if (buffer.string[range->start] == f_fss_delimit_slash_s.string[0]) {
if (state.interrupt) {
status = state.interrupt((void *) &state, 0);
-
- if (F_status_set_fine(status) == F_interrupt) {
- return F_status_set_error(F_interrupt);
- }
+ if (F_status_set_fine(status) == F_interrupt) return F_status_set_error(F_interrupt);
}
if (buffer.string[range->start] == f_fss_delimit_placeholder_s.string[0]) {
status = f_array_lengths_increase_by(slash_count / 2, delimits);
if (F_status_is_error(status)) return status;
- while (slash_count > 0) {
+ while (slash_count) {
if (buffer.string[range->start] == f_fss_delimit_slash_s.string[0]) {
if (slash_count % 2 == 1) {
}
--slash_count;
+ ++range->start;
+ }
+ else {
+ status = f_utf_buffer_increment(buffer, range, 1);
+ if (F_status_is_error(status)) return status;
}
-
- status = f_utf_buffer_increment(buffer, range, 1);
- if (F_status_is_error(status)) return status;
} // while
range->start = location + 1;
if (state.interrupt) {
status = state.interrupt((void *) &state, 0);
-
- if (F_status_set_fine(status) == F_interrupt) {
- return F_status_set_error(F_interrupt);
- }
+ if (F_status_set_fine(status) == F_interrupt) return F_status_set_error(F_interrupt);
}
status = f_utf_buffer_increment(buffer, range, 1);
status = f_array_lengths_increase_by((slash_count / 2) + 1, delimits);
if (F_status_is_error(status)) return status;
- while (slash_count > 0) {
+ while (slash_count) {
if (buffer.string[range->start] == f_fss_delimit_slash_s.string[0]) {
if (slash_count % 2 == 1) {
}
--slash_count;
+ ++range->start;
+ }
+ else {
+ status = f_utf_buffer_increment(buffer, range, 1);
+ if (F_status_is_error(status)) return status;
}
-
- status = f_utf_buffer_increment(buffer, range, 1);
- if (F_status_is_error(status)) return status;
} // while
range->start = location;
if (state.interrupt) {
status = state.interrupt((void *) &state, 0);
-
- if (F_status_set_fine(status) == F_interrupt) {
- return F_status_set_error(F_interrupt);
- }
+ if (F_status_set_fine(status) == F_interrupt) return F_status_set_error(F_interrupt);
}
if (buffer.string[range->start] == f_fss_eol_s.string[0]) {
if (status == F_true) {
status = f_utf_buffer_increment(buffer, range, 1);
- if (F_status_is_error(status)) return status;
- return F_fss_found_object;
+ return F_status_is_error(status) ? status : F_fss_found_object;
}
if (buffer.string[range->start] != f_fss_delimit_placeholder_s.string[0]) {
if (state.interrupt) {
status = state.interrupt((void *) &state, 0);
-
- if (F_status_set_fine(status) == F_interrupt) {
- return F_status_set_error(F_interrupt);
- }
+ if (F_status_set_fine(status) == F_interrupt) return F_status_set_error(F_interrupt);
}
status = f_utf_buffer_increment(buffer, range, 1);
}
status = f_utf_buffer_increment(buffer, range, 1);
- if (F_status_is_error(status)) return status;
- return F_fss_found_object_not;
+ return F_status_is_error(status) ? status : F_fss_found_object_not;
}
status = f_utf_buffer_increment(buffer, range, 1);
if (F_status_is_error(status)) break;
} // while
- if (F_status_is_error(status)) return status;
+ if (F_status_is_error(status)) {
+ found->start = 1;
+ found->stop = 0;
+
+ return status;
+ }
if (range->start > begin) {
found->stop = range->start - 1;
const f_array_length_t input_start = range->start;
const f_array_length_t used_start = destination->used;
- bool quote_is = F_false;
- bool commented = F_false;
+ uint8_t quote_is = F_false;
+ uint8_t commented = F_false;
+ uint8_t width = 0;
f_array_length_t item_first = 0;
f_array_length_t item_total = 0;
f_array_length_t i = 0;
- const f_char_t quote_char = quote == f_fss_quote_type_double_e ? f_string_ascii_quote_double_s.string[0] : f_string_ascii_quote_single_s.string[0];
+ const f_char_t quote_char = quote == f_fss_quote_type_single_e
+ ? f_string_ascii_quote_single_s.string[0]
+ : quote == f_fss_quote_type_backtick_e
+ ? f_string_ascii_grave_s.string[0]
+ : f_string_ascii_quote_double_s.string[0];
// Use placeholders for potential quote and potential delimited quote to avoid doing things such as memmove().
destination->string[destination->used++] = f_fss_delimit_placeholder_s.string[0];
commented = F_true;
}
- uint8_t width = 0;
-
for (; range->start <= range->stop && range->start < object.used; ) {
if (state.interrupt) {
if (F_status_is_error(status)) break;
if (range->start > range->stop || range->start >= object.used) {
-
status = f_string_dynamic_increase_by(item_total + 1, destination);
if (F_status_is_error(status)) break;
status = f_fss_skip_past_delimit(state, object, range);
if (F_status_is_error(status)) return status;
- if (range->start > range->stop || range->start >= object.used) {
- quote_is = F_true;
- }
- else if (object.string[range->start] == object.string[item_first]) {
+ if (range->start > range->stop || range->start >= object.used || object.string[range->start] == object.string[item_first]) {
quote_is = F_true;
}
else {
// The start quote may or may not need to be delimited in this case.
if (destination->string[input_start] == quote_char) {
-
for (i = input_start + macro_f_utf_byte_width(object.string[input_start]); i <= range->stop && i < object.used; i += macro_f_utf_byte_width(object.string[i])) {
if (state.interrupt) {
#endif
/**
+ * Read a standard list Object where the list open is specific to a given FSS standard.
+ *
+ * This will record where delimit placeholders exist but will not apply the delimits.
+ *
+ * @param list_open
+ * The list open character for the given standard.
+ * This must be defined where list_open.used = 1.
+ * @param buffer
+ * The buffer to read from.
+ * @param state
+ * A state for providing flags and handling interrupts during long running operations.
+ * There is no state.handle().
+ * There is no "callbacks" structure.
+ * There is no data structure passed to these functions.
+ *
+ * When state.interrupt() returns, only F_interrupt and F_interrupt_not are processed.
+ * Error bit designates an error but must be passed along with F_interrupt.
+ * All other statuses are ignored.
+ * @param range
+ * The start/stop location within the buffer to be processed.
+ * The start location will be updated as the buffer is being processed.
+ * The start location will represent where the read stopped on return.
+ * A start location past the stop location or buffer used means that the entire range was processed.
+ * @param found
+ * A location where a valid object was found.
+ * @param delimits
+ * A delimits array representing where delimits exist within the buffer.
+ *
+ * @return
+ * F_fss_found_object on success and object was found (start location is at end of object).
+ * F_fss_found_object_not on success and no object was found (start location is after character designating this is not an object).
+ * F_none_eos on success after reaching the end of the buffer (a valid object is not yet confirmed).
+ * F_none_stop on success after reaching stopping point (a valid object is not yet confirmed).
+ * F_data_not_eos no objects found after reaching the end of the buffer (essentially only comments are found).
+ * F_data_not_stop no data found after reaching stopping point (essentially only comments are found).
+ * F_end_not_group_eos if EOS was reached before the a group termination was reached.
+ * F_end_not_group_stop if stop point was reached before the a group termination was reached.
+ *
+ * F_interrupt (with error bit) if stopping due to an interrupt.
+ * F_parameter (with error bit) if a parameter is invalid.
+ *
+ * Errors (with error bit) from: f_array_lengths_increase_by().
+ * Errors (with error bit) from: f_fss_is_graph().
+ * Errors (with error bit) from: f_fss_is_space().
+ * Errors (with error bit) from: f_fss_is_zero_width().
+ * Errors (with error bit) from: f_fss_seek_to_eol().
+ * Errors (with error bit) from: f_fss_skip_past_delimit().
+ * Errors (with error bit) from: f_fss_skip_past_space().
+ * Errors (with error bit) from: f_utf_buffer_increment().
+ *
+ * @see f_array_lengths_increase_by()
+ * @see f_fss_is_graph()
+ * @see f_fss_is_space()
+ * @see f_fss_is_zero_width()
+ * @see f_fss_seek_to_eol()
+ * @see f_fss_skip_past_delimit()
+ * @see f_fss_skip_past_space()
+ * @see f_utf_buffer_increment()
+ *
+ * @see fl_fss_basic_list_object_read()
+ * @see fl_fss_embedded_list_object_read()
+ * @see fl_fss_extended_list_object_read()
+ */
+#if !defined(_di_fl_fss_basic_list_object_read_) || !defined(_di_fl_fss_embedded_list_object_read_) || !defined(_di_fl_fss_extended_list_object_read_)
+ extern f_status_t private_fl_fss_list_object_read(const f_string_static_t list_open, const f_string_static_t buffer, f_state_t state, f_string_range_t * const range, f_fss_object_t * const found, f_fss_delimits_t * const delimits) F_attribute_visibility_internal_d;
+#endif // !defined(_di_fl_fss_basic_list_object_read_) || !defined(_di_fl_fss_embedded_list_object_read_) || !defined(_di_fl_fss_extended_list_object_read_)
+
+/**
* Add all bytes to destination until stop point, buffer end, or EOL.
*
* @param buffer
* @see fl_fss_extended_list_content_write()
*/
#if !defined(_di_fl_fss_basic_list_content_write_) || !defined(_di_fl_fss_extended_list_content_write_) || !defined(_di_fl_fss_embedded_list_content_write_)
- extern f_status_t private_fl_fss_basic_list_write_add_until_end(const f_string_static_t buffer, f_state_t state, f_string_range_t * const range, f_string_dynamic_t * const destination) F_attribute_visibility_internal_d;
+ extern f_status_t private_fl_fss_list_write_add_until_end(const f_string_static_t buffer, f_state_t state, f_string_range_t * const range, f_string_dynamic_t * const destination) F_attribute_visibility_internal_d;
#endif // !defined(_di_fl_fss_basic_list_content_write_) || !defined(_di_fl_fss_extended_list_content_write_) || !defined(_di_fl_fss_embedded_list_content_write_)
/**
* @see fl_fss_extended_list_object_write()
*/
#if !defined(_di_fl_fss_basic_list_object_write_) || !defined(_di_fl_fss_extended_list_object_write_)
- extern f_status_t private_fl_fss_basic_list_write_object_trim(const f_array_length_t used_start, f_state_t state, f_string_dynamic_t * const destination) F_attribute_visibility_internal_d;
+ extern f_status_t private_fl_fss_list_write_object_trim(const f_array_length_t used_start, f_state_t state, f_string_dynamic_t * const destination) F_attribute_visibility_internal_d;
#endif // !defined(_di_fl_fss_basic_list_object_write_) || !defined(_di_fl_fss_extended_list_object_write_)
/**
if (depths.array[depths_index].value_at < items->used && !skip[depths.array[depths_index].value_at]) {
if (depths.array[depths_index].index_name) {
-
if (data->main->parameters.array[fss_embedded_list_read_parameter_trim_e].result == f_console_result_found_e) {
-
if (fl_string_dynamic_partial_compare_except_trim_dynamic(depths.array[depths_index].value_name, data->buffer, items->array[depths.array[depths_index].value_at].object, except_none, *objects_delimits) != F_equal_to) {
skip[depths.array[depths_index].value_at] = F_true;
}
parents_next.skip = skip_next;
parents_next.used = data->nest.depth[parents_depth].used;
- memset(skip_next, F_true, sizeof(skip_next) * parents_next.used);
+ memset(skip_next, F_true, sizeof(bool) * parents_next.used);
f_fss_items_t *items_next = &data->nest.depth[depth_next];
f_fss_items_t *items_previous = 0;
}
if (data->main->parameters.array[fss_embedded_list_read_parameter_columns_e].result == f_console_result_found_e) {
- for (i = 0; i < items->used; ++i) {
+ if (data->main->parameters.array[fss_embedded_list_read_parameter_content_e].result == f_console_result_found_e) {
+ for (i = 0; i < items->used; ++i) {
- if (skip[i]) continue;
+ if (skip[i]) continue;
- fll_print_format("%r%r", data->main->output.to.stream, f_string_ascii_1_s, f_string_eol_s);
+ fll_print_format("%r%r", data->main->output.to.stream, f_string_ascii_1_s, f_string_eol_s);
- return F_none;
- } // for
+ return F_none;
+ } // for
+ }
fll_print_format("%r%r", data->main->output.to.stream, f_string_ascii_0_s, f_string_eol_s);
if (skip[i]) continue;
- if (!items->array[i].content.used) {
+ if (!items->array[i].content.used || items->array[i].content.array[0].start > items->array[i].content.array[0].stop) {
if (include_empty) {
fss_embedded_list_read_print_set_end(data);
}
\"and so does this" "have space"
+ ...
\"and so does this" "have space"
+ ...
привет has space
+привет has space
d
a
привет
-y
+y
"мир"
привет has space
"This is quoted"
AlsoGood
-hi
-привет has space
+hi
+привет has space
a
also_empty
+empty
+d
+a
+привет
+y
+"мир"
+привет has space
+"This is quoted"
+AlsoGood
+hi
+привет has space
+a
+also_empty
d
a
привет
-y
+y
"мир"
привет has space
"This is quoted"
AlsoGood
-hi
-привет has space
+hi
+привет has space
a
also_empty
d
a
привет
-y
+y
"мир"
привет has space
"This is quoted"
AlsoGood
-hi
-привет has space
+hi
+привет has space
a
also_empty
привет has space{
\"and so does this" "have space"
}
+привет has space{
+ ...
+}
привет{
мир
}
-y {
+y{
z
}
"мир"{
}
AlsoGood{
}
-hi {
+hi{
Check this.
}
-привет has space {
+привет has space{
...
}
a{
+empty{
+}
+d{
+ b c
+}
+a{
+ e f
+ g h
+}
+привет{
+ мир
+}
+y{
+ z
+}
+"мир"{
+ quoted, "yep".
+}
+привет has space{
+ \"and so does this" "have space"
+}
+"This is quoted"{
+ But still a valid list.
+}
+AlsoGood{
+}
+hi{
+ Check this.
+}
+привет has space{
+ ...
+}
+a{
+ a second "a".
+}
+also_empty{
+}
привет{
мир
}
-y {
+y{
z
}
"мир"{
}
AlsoGood{
}
-hi {
+hi{
Check this.
}
-привет has space {
+привет has space{
...
}
a{
привет{
мир
}
-y {
+y{
z
}
"мир"{
}
AlsoGood{
}
-hi {
+hi{
Check this.
}
-привет has space {
+привет has space{
...
}
a{
}
a{
}
-a {
+a{
}
{
The object name is an empty string.
+a{
+}
+hi{
+}
+a{
+}
+a{
+}
+{
+ The object name is an empty string.
+}
+{
+}
+""{
+ Quotes aren't supported here, so this is not an empty object..
+\}
+}
}
a{
}
-a {
+a{
}
{
The object name is an empty string.
}
a{
}
-a {
+a{
}
{
The object name is an empty string.
привет has space
empty
hi
-has spaces
+has spaces
+a
+a
+"мир"
+привет has space
+empty
+hi
+has spaces
привет has space
empty
hi
-has spaces
+has spaces
привет has space
empty
hi
-has spaces
+has spaces
-has spaces {
+has spaces{
yep.
fin
}
-\\# even this is not.
+\# even this is not.
привет мир a
}
-has spaces {
+has spaces{
yep.
fin
}
+a{
+a b привет
+c d
+ \# not a comment
+ \\\# nor is this.
+\\# even this is not.
+привет мир a
+
+ \# a valid list:
+ with content.
+}
+a{
+ another "A" list.
+}
+"мир"{
+ quoted, "yep".
+}
+привет has space{
+ But this is not a comment.
+}
+empty{
+}
+hi{
+ not a list\:
+ a b привет
+ c d
+ привет мир a
+
+}
+has spaces{
+ yep.
+ fin
+}
привет мир a
}
-has spaces {
+has spaces{
yep.
fin
}
привет мир a
}
-has spaces {
+has spaces{
yep.
fin
}
привет has space
-привет has space
+привет has space
d
a
привет
-y
+y
"мир"
привет has space
"This is quoted"
AlsoGood
-hi
-привет has space
+hi
+привет has space
a
also_empty
d
a
привет
-y
+y
"мир"
привет has space
"This is quoted"
AlsoGood
-hi
-привет has space
+hi
+привет has space
a
also_empty
d
a
привет
-y
+y
"мир"
привет has space
"This is quoted"
AlsoGood
-hi
-привет has space
+hi
+привет has space
a
also_empty
d
a
привет
-y
+y
"мир"
привет has space
"This is quoted"
AlsoGood
-hi
-привет has space
+hi
+привет has space
a
also_empty
привет has space{
\"and so does this" "have space"
}
-привет has space {
+привет has space{
...
}
привет{
мир
}
-y {
+y{
z
}
"мир"{
}
AlsoGood{
}
-hi {
+hi{
Check this.
}
-привет has space {
+привет has space{
...
}
a{
привет{
мир
}
-y {
+y{
z
}
"мир"{
}
AlsoGood{
}
-hi {
+hi{
Check this.
}
-привет has space {
+привет has space{
...
}
a{
привет{
мир
}
-y {
+y{
z
}
"мир"{
}
AlsoGood{
}
-hi {
+hi{
Check this.
}
-привет has space {
+привет has space{
...
}
a{
привет{
мир
}
-y {
+y{
z
}
"мир"{
}
AlsoGood{
}
-hi {
+hi{
Check this.
}
-привет has space {
+привет has space{
...
}
a{
}
a{
}
-a {
+a{
}
{
The object name is an empty string.
}
a{
}
-a {
+a{
}
{
The object name is an empty string.
}
a{
}
-a {
+a{
}
{
The object name is an empty string.
}
a{
}
-a {
+a{
}
{
The object name is an empty string.
привет has space
empty
hi
-has spaces
+has spaces
привет has space
empty
hi
-has spaces
+has spaces
привет has space
empty
hi
-has spaces
+has spaces
привет has space
empty
hi
-has spaces
+has spaces
-has spaces {
+has spaces{
yep.
fin
}
привет мир a
}
-has spaces {
+has spaces{
yep.
fin
}
привет мир a
}
-has spaces {
+has spaces{
yep.
fin
}
привет мир a
}
-has spaces {
+has spaces{
yep.
fin
}
привет мир a
}
-has spaces {
+has spaces{
yep.
fin
}