From 708e5399ed751afec2efac10768446a80ced633d Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Thu, 19 Sep 2019 22:28:15 -0500 Subject: [PATCH] Update: FSS function documentation, use "location" instead of "input", have f_incomplete_utf use error bit --- level_1/fl_fss/c/fss.c | 188 ++++----- level_1/fl_fss/c/fss.h | 30 +- level_1/fl_fss/c/fss_basic.c | 340 ++++++++-------- level_1/fl_fss/c/fss_basic.h | 133 ++++++- level_1/fl_fss/c/fss_basic_list.c | 354 +++++++++-------- level_1/fl_fss/c/fss_basic_list.h | 134 ++++++- level_1/fl_fss/c/fss_extended.c | 618 +++++++++++++++-------------- level_1/fl_fss/c/fss_extended.h | 133 ++++++- level_1/fl_fss/c/fss_extended_list.c | 736 +++++++++++++++++++++++++++++++++++ level_1/fl_fss/c/fss_extended_list.h | 169 ++++++++ level_1/fl_fss/c/fss_macro.h | 110 +++--- level_1/fl_status/c/status.c | 2 +- level_1/fl_status/c/status.h | 2 +- level_2/fll_fss/c/fss_status.c | 4 +- level_2/fll_status/c/status.c | 4 +- level_2/fll_status/c/status.h | 2 +- level_3/firewall/c/firewall.c | 4 +- specifications/fss.txt | 10 +- 18 files changed, 2125 insertions(+), 848 deletions(-) create mode 100644 level_1/fl_fss/c/fss_extended_list.c create mode 100644 level_1/fl_fss/c/fss_extended_list.h diff --git a/level_1/fl_fss/c/fss.c b/level_1/fl_fss/c/fss.c index 0a00d63..d016e86 100644 --- a/level_1/fl_fss/c/fss.c +++ b/level_1/fl_fss/c/fss.c @@ -5,24 +5,24 @@ extern "C" { #endif #ifndef _di_fl_fss_decrement_buffer_ - f_return_status fl_fss_decrement_buffer(const f_string_dynamic buffer, f_string_location *input, const f_string_length step) { + f_return_status fl_fss_decrement_buffer(const f_string_dynamic buffer, f_string_location *location, const f_string_length step) { #ifndef _di_level_1_parameter_checking_ if (buffer.used <= 0) return f_status_set_error(f_invalid_parameter); - if (input->start < 0) return f_status_set_error(f_invalid_parameter); - if (input->stop < input->start) return f_status_set_error(f_invalid_parameter); - if (input->start >= buffer.used) return f_status_set_error(f_invalid_parameter); + if (location->start < 0) return f_status_set_error(f_invalid_parameter); + if (location->stop < location->start) return f_status_set_error(f_invalid_parameter); + if (location->start >= buffer.used) return f_status_set_error(f_invalid_parameter); if (step < 1) return f_status_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ - if (input->start < 1) return f_none_on_eos; + if (location->start < 1) return f_none_on_eos; f_string_length i = 0; unsigned short width = 0; do { - width = f_macro_utf_byte_width(buffer.string[input->start - 1]); + width = f_macro_utf_byte_width(buffer.string[location->start - 1]); - if (width > input->start) { + if (width > location->start) { if (width > 1) { return f_status_set_error(f_incomplete_utf_on_eos); } @@ -31,7 +31,7 @@ extern "C" { } i++; - input->start -= width; + location->start -= width; } while (i < step); return f_none; @@ -84,13 +84,13 @@ extern "C" { if (f_is_hexidecimal(buffer.string[i]) == f_true) { i++; - f_string_location location = f_string_location_initialize; + f_string_location length = f_string_location_initialize; - location.start = i - 4; - location.stop = i; + length.start = i - 4; + length.stop = i; // 1: A possibly valid header type was found, now convert it into its proper format and save the header type - f_string_to_hexidecimal(buffer.string, &header->type, location); + f_string_to_hexidecimal(buffer.string, &header->type, length); // 2: At this point, we can still know the proper format for the file and still have a invalid header, handle accordingly if (buffer.string[i] == f_fss_type_header_close) { @@ -140,12 +140,12 @@ extern "C" { if (f_is_hexidecimal(buffer.string[i]) == f_true) { i++; - f_string_location location = f_string_location_initialize; + f_string_location length = f_string_location_initialize; - location.start = i - 4; - location.stop = i; + length.start = i - 4; + length.stop = i; - f_string_to_hexidecimal(buffer.string, &header->type, location); + f_string_to_hexidecimal(buffer.string, &header->type, length); header->length = i + 1; @@ -180,9 +180,9 @@ extern "C" { f_status status = f_none; f_string_dynamic buffer = f_string_dynamic_initialize; - f_file_position location = f_file_position_initialize; + f_file_position length = f_file_position_initialize; - // make sure we are in the proper location in the file + // make sure we are in the proper length in the file { int seek_result = f_macro_file_seek_begin(file->address, 0); @@ -190,16 +190,16 @@ extern "C" { } // 1: Prepare the buffer to handle a size of f_fss_max_header_length - location.total_elements = f_fss_max_header_length; + length.total_elements = f_fss_max_header_length; - f_macro_string_dynamic_adjust(status, buffer, location.total_elements + 1); + f_macro_string_dynamic_adjust(status, buffer, length.total_elements + 1); if (f_status_is_error(status)) { return status; } // 2: buffer the file - status = f_file_read_at(file, &buffer, location); + status = f_file_read_at(file, &buffer, length); if (f_status_is_error(status)) { return status; @@ -213,12 +213,12 @@ extern "C" { #endif // _di_fl_fss_identify_file_ #ifndef _di_fl_fss_increment_buffer_ - f_return_status fl_fss_increment_buffer(const f_string_dynamic buffer, f_string_location *input, const f_string_length step) { + f_return_status fl_fss_increment_buffer(const f_string_dynamic buffer, f_string_location *location, const f_string_length step) { #ifndef _di_level_1_parameter_checking_ if (buffer.used <= 0) return f_status_set_error(f_invalid_parameter); - if (input->start < 0) return f_status_set_error(f_invalid_parameter); - if (input->stop < input->start) return f_status_set_error(f_invalid_parameter); - if (input->start >= buffer.used) return f_status_set_error(f_invalid_parameter); + if (location->start < 0) return f_status_set_error(f_invalid_parameter); + if (location->stop < location->start) return f_status_set_error(f_invalid_parameter); + if (location->start >= buffer.used) return f_status_set_error(f_invalid_parameter); if (step < 1) return f_status_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ @@ -226,27 +226,27 @@ extern "C" { unsigned short width = 0; do { - width = f_macro_utf_byte_width(buffer.string[input->start]); + width = f_macro_utf_byte_width(buffer.string[location->start]); - if (input->start + width > input->stop) { + if (location->start + width > location->stop) { if (width > 1) { return f_status_set_error(f_incomplete_utf_on_stop); } - input->start += width; + location->start += width; return f_none_on_stop; } - else if (input->start + width >= buffer.used) { + else if (location->start + width >= buffer.used) { if (width > 1) { return f_status_set_error(f_incomplete_utf_on_eos); } - input->start += width; + location->start += width; return f_none_on_eos; } i++; - input->start += width; + location->start += width; } while (i < step); return f_none; @@ -254,70 +254,70 @@ extern "C" { #endif // _di_fl_fss_increment_buffer_ #ifndef _di_fl_fss_is_graph_ - f_return_status fl_fss_is_graph(const f_string_dynamic buffer, const f_string_location input) { + f_return_status fl_fss_is_graph(const f_string_dynamic buffer, const f_string_location location) { #ifndef _di_level_1_parameter_checking_ if (buffer.used <= 0) return f_status_set_error(f_invalid_parameter); - if (input.start < 0) return f_status_set_error(f_invalid_parameter); - if (input.stop < input.start) return f_status_set_error(f_invalid_parameter); - if (input.start >= buffer.used) return f_status_set_error(f_invalid_parameter); + if (location.start < 0) return f_status_set_error(f_invalid_parameter); + if (location.stop < location.start) return f_status_set_error(f_invalid_parameter); + if (location.start >= buffer.used) return f_status_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ - f_string_length max_width = (input.stop - input.start) + 1; + f_string_length max_width = (location.stop - location.start) + 1; - if (max_width > buffer.used - input.start) { - max_width = buffer.used - input.start; + if (max_width > buffer.used - location.start) { + max_width = buffer.used - location.start; } - return f_utf_is_graph(buffer.string + input.start, max_width); + return f_utf_is_graph(buffer.string + location.start, max_width); } #endif // _di_fl_fss_is_graph_ #ifndef _di_fl_fss_is_space_ - f_return_status fl_fss_is_space(const f_string_dynamic buffer, const f_string_location input) { + f_return_status fl_fss_is_space(const f_string_dynamic buffer, const f_string_location location) { #ifndef _di_level_1_parameter_checking_ if (buffer.used <= 0) return f_status_set_error(f_invalid_parameter); - if (input.start < 0) return f_status_set_error(f_invalid_parameter); - if (input.stop < input.start) return f_status_set_error(f_invalid_parameter); - if (input.start >= buffer.used) return f_status_set_error(f_invalid_parameter); + if (location.start < 0) return f_status_set_error(f_invalid_parameter); + if (location.stop < location.start) return f_status_set_error(f_invalid_parameter); + if (location.start >= buffer.used) return f_status_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ - f_string_length max_width = (input.stop - input.start) + 1; + f_string_length max_width = (location.stop - location.start) + 1; - if (max_width > buffer.used - input.start) { - max_width = buffer.used - input.start; + if (max_width > buffer.used - location.start) { + max_width = buffer.used - location.start; } - return f_utf_is_whitespace(buffer.string + input.start, max_width); + return f_utf_is_whitespace(buffer.string + location.start, max_width); } #endif // _di_fl_fss_is_space_ #ifndef _di_fl_fss_skip_past_whitespace_ - f_return_status fl_fss_skip_past_whitespace(const f_string_dynamic buffer, f_string_location *input) { + f_return_status fl_fss_skip_past_whitespace(const f_string_dynamic buffer, f_string_location *location) { #ifndef _di_level_1_parameter_checking_ if (buffer.used <= 0) return f_status_set_error(f_invalid_parameter); - if (input == 0) return f_status_set_error(f_invalid_parameter); - if (input->start < 0) return f_status_set_error(f_invalid_parameter); - if (input->stop < input->start) return f_status_set_error(f_invalid_parameter); - if (input->start >= buffer.used) return f_status_set_error(f_invalid_parameter); + if (location == 0) return f_status_set_error(f_invalid_parameter); + if (location->start < 0) return f_status_set_error(f_invalid_parameter); + if (location->stop < location->start) return f_status_set_error(f_invalid_parameter); + if (location->start >= buffer.used) return f_status_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ f_status status = f_none; unsigned short width = 0; - f_string_length max_width = (input->stop - input->start) + 1; + f_string_length max_width = (location->stop - location->start) + 1; - if (max_width > buffer.used - input->start) { - max_width = buffer.used - input->start; + if (max_width > buffer.used - location->start) { + max_width = buffer.used - location->start; } - while (buffer.string[input->start] == f_string_eos || (status = f_utf_is_graph(buffer.string + input->start, max_width)) == f_false) { + while (buffer.string[location->start] == f_string_eos || (status = f_utf_is_graph(buffer.string + location->start, max_width)) == f_false) { if (f_status_is_error(status)) { return status; } - if (buffer.string[input->start] == f_string_eol) return f_none_on_eol; + if (buffer.string[location->start] == f_string_eol) return f_none_on_eol; - width = f_macro_utf_byte_width_is(buffer.string[input->start]); + width = f_macro_utf_byte_width_is(buffer.string[location->start]); if (width == 0) { width = 1; @@ -327,19 +327,19 @@ extern "C" { return f_status_set_error(f_incomplete_utf); } else { - if (input->start + width >= buffer.used) return f_status_set_error(f_incomplete_utf_on_eos); - if (input->start + width > input->stop) return f_status_set_error(f_incomplete_utf_on_stop); + if (location->start + width >= buffer.used) return f_status_set_error(f_incomplete_utf_on_eos); + if (location->start + width > location->stop) return f_status_set_error(f_incomplete_utf_on_stop); } - input->start += width; + location->start += width; - if (input->start >= buffer.used) return f_none_on_eos; - if (input->start > input->stop) return f_none_on_stop; + if (location->start >= buffer.used) return f_none_on_eos; + if (location->start > location->stop) return f_none_on_stop; - max_width = (input->stop - input->start) + 1; + max_width = (location->stop - location->start) + 1; - if (max_width > buffer.used - input->start) { - max_width = buffer.used - input->start; + if (max_width > buffer.used - location->start) { + max_width = buffer.used - location->start; } } // while @@ -352,30 +352,30 @@ extern "C" { #endif // _di_fl_fss_skip_past_whitespace_ #ifndef _di_fl_fss_skip_past_all_whitespace_ - f_return_status fl_fss_skip_past_all_whitespace(const f_string_dynamic buffer, f_string_location *input) { + f_return_status fl_fss_skip_past_all_whitespace(const f_string_dynamic buffer, f_string_location *location) { #ifndef _di_level_1_parameter_checking_ if (buffer.used <= 0) return f_status_set_error(f_invalid_parameter); - if (input == 0) return f_status_set_error(f_invalid_parameter); - if (input->start < 0) return f_status_set_error(f_invalid_parameter); - if (input->stop < input->start) return f_status_set_error(f_invalid_parameter); - if (input->start >= buffer.used) return f_status_set_error(f_invalid_parameter); + if (location == 0) return f_status_set_error(f_invalid_parameter); + if (location->start < 0) return f_status_set_error(f_invalid_parameter); + if (location->stop < location->start) return f_status_set_error(f_invalid_parameter); + if (location->start >= buffer.used) return f_status_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ f_status status = f_none; unsigned short width = 0; - f_string_length max_width = (input->stop - input->start) + 1; + f_string_length max_width = (location->stop - location->start) + 1; - if (max_width > buffer.used - input->start) { - max_width = buffer.used - input->start; + if (max_width > buffer.used - location->start) { + max_width = buffer.used - location->start; } - while (buffer.string[input->start] == f_string_eos || (status = f_utf_is_graph(buffer.string + input->start, max_width)) == f_false) { + while (buffer.string[location->start] == f_string_eos || (status = f_utf_is_graph(buffer.string + location->start, max_width)) == f_false) { if (f_status_is_error(status)) { return status; } - width = f_macro_utf_byte_width_is(buffer.string[input->start]); + width = f_macro_utf_byte_width_is(buffer.string[location->start]); if (width == 0) { width = 1; @@ -385,19 +385,19 @@ extern "C" { return f_status_set_error(f_incomplete_utf); } else { - if (input->start + width >= buffer.used) return f_status_set_error(f_incomplete_utf_on_eos); - if (input->start + width > input->stop) return f_status_set_error(f_incomplete_utf_on_stop); + if (location->start + width >= buffer.used) return f_status_set_error(f_incomplete_utf_on_eos); + if (location->start + width > location->stop) return f_status_set_error(f_incomplete_utf_on_stop); } - input->start += width; + location->start += width; - if (input->start >= buffer.used) return f_none_on_eos; - if (input->start > input->stop) return f_none_on_stop; + if (location->start >= buffer.used) return f_none_on_eos; + if (location->start > location->stop) return f_none_on_stop; - max_width = (input->stop - input->start) + 1; + max_width = (location->stop - location->start) + 1; - if (max_width > buffer.used - input->start) { - max_width = buffer.used - input->start; + if (max_width > buffer.used - location->start) { + max_width = buffer.used - location->start; } } // while @@ -410,12 +410,12 @@ extern "C" { #endif // _di_fl_fss_skip_past_all_whitespace_ #ifndef _di_fl_fss_shift_delimiters_ - f_return_status fl_fss_shift_delimiters(f_string_dynamic *buffer, const f_string_location input) { + f_return_status fl_fss_shift_delimiters(f_string_dynamic *buffer, const f_string_location location) { #ifndef _di_level_1_parameter_checking_ if (buffer->used <= 0) return f_status_set_error(f_invalid_parameter); - if (input.start < 0) return f_status_set_error(f_invalid_parameter); - if (input.stop < input.start) return f_status_set_error(f_invalid_parameter); - if (input.start >= buffer->used) return f_status_set_error(f_invalid_parameter); + if (location.start < 0) return f_status_set_error(f_invalid_parameter); + if (location.stop < location.start) return f_status_set_error(f_invalid_parameter); + if (location.start >= buffer->used) return f_status_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ f_string_length position = 0; @@ -423,22 +423,22 @@ extern "C" { unsigned short utf_width = 0; unsigned short i = 0; - position = input.start; + position = location.start; - while (position < buffer->used && position <= input.stop) { + while (position < buffer->used && position <= location.stop) { if (buffer->string[position] == f_fss_delimit_placeholder) { distance++; } // do not waste time trying to process what is only going to be replaced with a delimit placeholder - if (position + distance >= buffer->used || position + distance > input.stop) { + if (position + distance >= buffer->used || position + distance > location.stop) { break; } utf_width = f_macro_utf_byte_width_is(buffer->string[position]); if (utf_width > 1) { - // not enough space in buffer or in input range to process UTF-8 character. - if (position + utf_width >= buffer->used || position + utf_width > input.stop) { + // not enough space in buffer or in location range to process UTF-8 character. + if (position + utf_width >= buffer->used || position + utf_width > location.stop) { return f_status_set_error(f_invalid_utf); } @@ -461,7 +461,7 @@ extern "C" { } if (distance > 0) { - while (position < buffer->used + distance && position <= input.stop) { + while (position < buffer->used + distance && position <= location.stop) { buffer->string[position] = f_fss_delimit_placeholder; ++position; } diff --git a/level_1/fl_fss/c/fss.h b/level_1/fl_fss/c/fss.h index 24b07e1..849c49d 100644 --- a/level_1/fl_fss/c/fss.h +++ b/level_1/fl_fss/c/fss.h @@ -35,7 +35,7 @@ extern "C" { * * @param buffer * The string to process. - * @param input + * @param location * The start and stop positions to be incremented. * The start position will be incremented by step. * @param step @@ -54,7 +54,7 @@ extern "C" { * f_incomplete_utf_on_eos (with error bit) if the end of buffer is reached before the complete UTF-8 character can be processed. */ #ifndef _di_fl_fss_decrement_buffer_ - extern f_return_status fl_fss_decrement_buffer(const f_string_dynamic buffer, f_string_location *input, const f_string_length step); + extern f_return_status fl_fss_decrement_buffer(const f_string_dynamic buffer, f_string_location *location, const f_string_length step); #endif // _di_fl_fss_decrement_buffer_ /** @@ -104,7 +104,7 @@ extern "C" { * * @param buffer * The string to process. - * @param input + * @param location * The start and stop positions to be incremented. * The start position will be incremented by step. * @param step @@ -123,7 +123,7 @@ extern "C" { * f_incomplete_utf_on_eos (with error bit) if the end of buffer is reached before the complete UTF-8 character can be processed. */ #ifndef _di_fl_fss_increment_buffer_ - extern f_return_status fl_fss_increment_buffer(const f_string_dynamic buffer, f_string_location *input, const f_string_length step); + extern f_return_status fl_fss_increment_buffer(const f_string_dynamic buffer, f_string_location *location, const f_string_length step); #endif // _di_fl_fss_increment_buffer_ /** @@ -131,7 +131,7 @@ extern "C" { * * @param buffer * The string to process. - * @param input + * @param location * The character at the start position will be checked against the graph. * @param header * The header data to populate with results of this function. @@ -144,7 +144,7 @@ extern "C" { * f_invalid_parameter (with error bit) if a parameter is invalid. */ #ifndef _di_fl_fss_is_graph_ - extern f_return_status fl_fss_is_graph(const f_string_dynamic buffer, const f_string_location input); + extern f_return_status fl_fss_is_graph(const f_string_dynamic buffer, const f_string_location location); #endif // _di_fl_fss_is_graph_ /** @@ -152,7 +152,7 @@ extern "C" { * * @param buffer * The string to process. - * @param input + * @param location * The character at the start position will be checked against the graph. * @param header * The header data to populate with results of this function. @@ -165,7 +165,7 @@ extern "C" { * f_invalid_parameter (with error bit) if a parameter is invalid. */ #ifndef _di_fl_fss_is_space_ - extern f_return_status fl_fss_is_space(const f_string_dynamic buffer, const f_string_location input); + extern f_return_status fl_fss_is_space(const f_string_dynamic buffer, const f_string_location location); #endif // _di_fl_fss_is_space_ /** @@ -177,7 +177,7 @@ extern "C" { * @param buffer * The string to process. * This gets updated. - * @param input + * @param location * A restriction on where within the buffer the shifting happens. * * @return @@ -186,7 +186,7 @@ extern "C" { * f_invalid_parameter (with error bit) if a parameter is invalid. */ #ifndef _di_fl_fss_shift_delimiters_ - extern f_return_status fl_fss_shift_delimiters(f_string_dynamic *buffer, const f_string_location input); + extern f_return_status fl_fss_shift_delimiters(f_string_dynamic *buffer, const f_string_location location); #endif // _di_fl_fss_shift_delimiters_ /** @@ -194,7 +194,7 @@ extern "C" { * * @param buffer * The string to process. - * @param input + * @param location * The start and stop positions in the buffer being processed. * This increments location->start. * @@ -203,7 +203,7 @@ extern "C" { * f_invalid_parameter (with error bit) if a parameter is invalid. */ #ifndef _di_fl_fss_skip_past_whitespace_ - extern f_return_status fl_fss_skip_past_whitespace(const f_string_dynamic buffer, f_string_location *input); + extern f_return_status fl_fss_skip_past_whitespace(const f_string_dynamic buffer, f_string_location *location); #endif // _di_fl_fss_skip_past_whitespace_ /** @@ -211,16 +211,16 @@ extern "C" { * * @param buffer * The string to process. - * @param input + * @param location * The start and stop positions in the buffer being processed. - * This increments input->start. + * This increments location->start. * * @return * f_none on success. * f_invalid_parameter (with error bit) if a parameter is invalid. */ #ifndef _di_fl_fss_skip_past_all_whitespace_ - extern f_return_status fl_fss_skip_past_all_whitespace(const f_string_dynamic buffer, f_string_location *input); + extern f_return_status fl_fss_skip_past_all_whitespace(const f_string_dynamic buffer, f_string_location *location); #endif // _di_fl_fss_skip_past_all_whitespace_ #ifdef __cplusplus diff --git a/level_1/fl_fss/c/fss_basic.c b/level_1/fl_fss/c/fss_basic.c index 84dba29..7d79f96 100644 --- a/level_1/fl_fss/c/fss_basic.c +++ b/level_1/fl_fss/c/fss_basic.c @@ -5,15 +5,15 @@ extern "C" { #endif #ifndef _di_fl_fss_basic_object_read_ - f_return_status fl_fss_basic_object_read(f_string_dynamic *buffer, f_string_location *input, f_fss_object *found) { + f_return_status fl_fss_basic_object_read(f_string_dynamic *buffer, f_string_location *location, f_fss_object *found) { #ifndef _di_level_1_parameter_checking_ if (buffer == 0) return f_status_set_error(f_invalid_parameter); - if (input == 0) return f_status_set_error(f_invalid_parameter); + if (location == 0) return f_status_set_error(f_invalid_parameter); if (found == 0) return f_status_set_error(f_invalid_parameter); - if (input->start < 0) return f_status_set_error(f_invalid_parameter); - if (input->stop < input->start) return f_status_set_error(f_invalid_parameter); + if (location->start < 0) return f_status_set_error(f_invalid_parameter); + if (location->stop < location->start) return f_status_set_error(f_invalid_parameter); if (buffer->used <= 0) return f_status_set_error(f_invalid_parameter); - if (input->start >= buffer->used) return f_status_set_error(f_invalid_parameter); + if (location->start >= buffer->used) return f_status_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ f_status status = f_none; @@ -21,12 +21,12 @@ extern "C" { // delimits must only be applied once a valid object is found f_string_lengths delimits = f_string_lengths_initialize; - fl_fss_skip_past_whitespace(*buffer, input); - fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) + fl_fss_skip_past_whitespace(*buffer, location); + fl_macro_fss_object_return_on_overflow((*buffer), (*location), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) // return found nothing if this line only contains whitespace and delimit placeholders - if (buffer->string[input->start] == f_fss_basic_close) { - status = fl_fss_increment_buffer(*buffer, input, 1); + if (buffer->string[location->start] == f_fss_basic_close) { + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; return fl_fss_found_no_object; @@ -37,13 +37,13 @@ extern "C" { f_bool has_delimit = f_false; // begin the search - found->start = input->start; + found->start = location->start; // ignore all comment lines - if (buffer->string[input->start] == f_fss_comment) { - fl_macro_fss_object_seek_till_newline((*buffer), (*input), delimits, f_no_data_on_eos, f_no_data_on_stop) + if (buffer->string[location->start] == f_fss_comment) { + fl_macro_fss_object_seek_till_newline((*buffer), (*location), delimits, f_no_data_on_eos, f_no_data_on_stop) - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; return fl_fss_found_no_object; @@ -53,27 +53,27 @@ extern "C" { int8_t quoted = f_string_eos; // identify where the object begins - if (buffer->string[input->start] == f_fss_delimit_slash) { - f_string_length last_slash = input->start; + if (buffer->string[location->start] == f_fss_delimit_slash) { + f_string_length last_slash = location->start; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; - while (input->start <= input->stop && input->start < buffer->used) { - if (buffer->string[input->start] == f_fss_delimit_placeholder) { + while (location->start <= location->stop && location->start < buffer->used) { + if (buffer->string[location->start] == f_fss_delimit_placeholder) { - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; continue; } else { - status = fl_fss_is_graph(*buffer, *input); + status = fl_fss_is_graph(*buffer, *location); if (status == f_false) { - found->stop = input->start - 1; + found->stop = location->start - 1; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; return fl_fss_found_object; @@ -81,20 +81,20 @@ extern "C" { else if (f_status_is_error(status)) { return status; } - else if (buffer->string[input->start] != f_fss_delimit_slash) { + else if (buffer->string[location->start] != f_fss_delimit_slash) { break; } } - last_slash = input->start; + last_slash = location->start; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } // while - fl_macro_fss_object_delimited_return_on_overflow((*buffer), (*input), (*found), delimits, f_none_on_eos, f_none_on_stop) + fl_macro_fss_object_delimited_return_on_overflow((*buffer), (*location), (*found), delimits, f_none_on_eos, f_none_on_stop) - if (buffer->string[input->start] == f_fss_delimit_single_quote || buffer->string[input->start] == f_fss_delimit_double_quote) { + if (buffer->string[location->start] == f_fss_delimit_single_quote || buffer->string[location->start] == f_fss_delimit_double_quote) { if (delimits.used >= delimits.size) { f_status allocation_status = f_none; @@ -109,45 +109,45 @@ extern "C" { delimits.array[delimits.used] = last_slash; delimits.used++; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } } - else if (buffer->string[input->start] == f_fss_delimit_single_quote || buffer->string[input->start] == f_fss_delimit_double_quote) { - quoted = buffer->string[input->start]; + else if (buffer->string[location->start] == f_fss_delimit_single_quote || buffer->string[location->start] == f_fss_delimit_double_quote) { + quoted = buffer->string[location->start]; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; - found->start = input->start; + found->start = location->start; } // identify where the object ends if (quoted == f_string_eos) { status = f_none; - while (buffer->string[input->start] == f_fss_delimit_placeholder || (status = fl_fss_is_graph(*buffer, *input)) == f_true) { - status = fl_fss_increment_buffer(*buffer, input, 1); + while (buffer->string[location->start] == f_fss_delimit_placeholder || (status = fl_fss_is_graph(*buffer, *location)) == f_true) { + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; - fl_macro_fss_object_delimited_return_on_overflow((*buffer), (*input), (*found), delimits, f_none_on_eos, f_none_on_stop) + fl_macro_fss_object_delimited_return_on_overflow((*buffer), (*location), (*found), delimits, f_none_on_eos, f_none_on_stop) } // while if (f_status_is_error(status)) return status; - status = fl_fss_is_space(*buffer, *input); + status = fl_fss_is_space(*buffer, *location); if (status == f_true) { - found->stop = input->start - 1; + found->stop = location->start - 1; fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); - if (buffer->string[input->start] == f_string_eol) { - status = fl_fss_increment_buffer(*buffer, input, 1); + if (buffer->string[location->start] == f_string_eol) { + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; return fl_fss_found_object_no_content; } - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; return fl_fss_found_object; @@ -157,39 +157,39 @@ extern "C" { } } else { - while (input->start <= input->stop && input->start < buffer->used) { - if (buffer->string[input->start] == f_fss_delimit_slash) { - f_string_length first_slash = input->start; + while (location->start <= location->stop && location->start < buffer->used) { + if (buffer->string[location->start] == f_fss_delimit_slash) { + f_string_length first_slash = location->start; f_string_length slash_count = 1; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; - while (input->start <= input->stop && input->start < buffer->used) { - if (buffer->string[input->start] == f_fss_delimit_placeholder) { + while (location->start <= location->stop && location->start < buffer->used) { + if (buffer->string[location->start] == f_fss_delimit_placeholder) { - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; continue; } - else if (buffer->string[input->start] != f_fss_delimit_slash) { + else if (buffer->string[location->start] != f_fss_delimit_slash) { break; } slash_count++; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } // while - fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), delimits, f_status_is_warning(f_unterminated_group_on_eos), f_status_is_warning(f_unterminated_group_on_stop)) + fl_macro_fss_object_return_on_overflow((*buffer), (*location), (*found), delimits, f_status_is_warning(f_unterminated_group_on_eos), f_status_is_warning(f_unterminated_group_on_stop)) - if (buffer->string[input->start] == quoted) { - f_string_length location = input->start; + if (buffer->string[location->start] == quoted) { + f_string_length length = location->start; - input->start = first_slash; + location->start = first_slash; if (slash_count % 2 == 0) { if (delimits.used + (slash_count / 2) >= delimits.size) { @@ -204,9 +204,9 @@ extern "C" { } while (slash_count > 0) { - if (buffer->string[input->start] == f_fss_delimit_slash) { + if (buffer->string[location->start] == f_fss_delimit_slash) { if (slash_count % 2 != 0) { - delimits.array[delimits.used] = input->start; + delimits.array[delimits.used] = location->start; delimits.used++; } @@ -214,22 +214,22 @@ extern "C" { } - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } // while - input->start = location + 1; + location->start = length + 1; - fl_macro_fss_skip_past_delimit_placeholders((*buffer), (*input)) - fl_macro_fss_object_delimited_return_on_overflow((*buffer), (*input), (*found), delimits, f_none_on_eos, f_none_on_stop) + fl_macro_fss_skip_past_delimit_placeholders((*buffer), (*location)) + fl_macro_fss_object_delimited_return_on_overflow((*buffer), (*location), (*found), delimits, f_none_on_eos, f_none_on_stop) - if ((status = fl_fss_is_graph(*buffer, *input)) == f_true) { - while (input->start < buffer->used && input->start <= input->stop && buffer->string[input->start] != f_string_eol) { - status = fl_fss_increment_buffer(*buffer, input, 1); + if ((status = fl_fss_is_graph(*buffer, *location)) == f_true) { + while (location->start < buffer->used && location->start <= location->stop && buffer->string[location->start] != f_string_eol) { + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } // while - fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) + fl_macro_fss_object_return_on_overflow((*buffer), (*location), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) { f_status allocation_status = f_none; @@ -237,20 +237,30 @@ extern "C" { f_macro_string_lengths_delete(allocation_status, delimits); } - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; return fl_fss_found_no_object; } else if (f_status_is_error(status)) { + f_status status2 = f_status_set_fine(status); + + if (status2 == f_failure) { + return f_status_set_error(f_invalid_utf); + } + + if (status2 == f_failure) { + return f_status_set_error(f_incomplete_utf); + } + return status; } - else if (buffer->string[input->start] == f_string_eol) { + else if (buffer->string[location->start] == f_string_eol) { fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); - found->stop = location - 1; + found->stop = length - 1; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; @@ -259,9 +269,9 @@ extern "C" { fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); - found->stop = location - 1; + found->stop = length - 1; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; return fl_fss_found_object; @@ -279,42 +289,42 @@ extern "C" { } while (slash_count > 0) { - if (buffer->string[input->start] == f_fss_delimit_slash) { + if (buffer->string[location->start] == f_fss_delimit_slash) { if (slash_count % 2 != 0) { - delimits.array[delimits.used] = input->start; + delimits.array[delimits.used] = location->start; delimits.used++; } slash_count--; } - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } // while - input->start = location; + location->start = length; } } } - else if (buffer->string[input->start] == quoted) { - found->stop = input->start - 1; + else if (buffer->string[location->start] == quoted) { + found->stop = location->start - 1; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; - while (input->start <= input->stop && input->start < buffer->used) { - if (buffer->string[input->start] == f_string_eol) { + while (location->start <= location->stop && location->start < buffer->used) { + if (buffer->string[location->start] == f_string_eol) { fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; return fl_fss_found_object_no_content; } - else if ((status = fl_fss_is_space(*buffer, *input)) == f_true) { + else if ((status = fl_fss_is_space(*buffer, *location)) == f_true) { fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; return fl_fss_found_object; @@ -322,15 +332,15 @@ extern "C" { else if (f_status_is_error(status)) { return status; } - else if (buffer->string[input->start] != f_fss_delimit_placeholder) { - while (input->start < buffer->used && input->start <= input->stop && buffer->string[input->start] != f_string_eol) { + else if (buffer->string[location->start] != f_fss_delimit_placeholder) { + while (location->start < buffer->used && location->start <= location->stop && buffer->string[location->start] != f_string_eol) { - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } // while - fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) + fl_macro_fss_object_return_on_overflow((*buffer), (*location), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) { f_status allocation_status = f_none; @@ -338,47 +348,47 @@ extern "C" { f_macro_string_lengths_delete(allocation_status, delimits); } - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; return fl_fss_found_no_object; } - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } // while - fl_macro_fss_object_delimited_return_on_overflow((*buffer), (*input), (*found), delimits, f_none_on_eos, f_none_on_stop) + fl_macro_fss_object_delimited_return_on_overflow((*buffer), (*location), (*found), delimits, f_none_on_eos, f_none_on_stop) } - else if (buffer->string[input->start] == f_string_eol) { + else if (buffer->string[location->start] == f_string_eol) { { f_status allocation_status = f_none; f_macro_string_lengths_delete(allocation_status, delimits); } - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; return fl_fss_found_no_object; } - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } // while - fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), delimits, f_status_is_warning(f_unterminated_group_on_eos), f_status_is_warning(f_unterminated_group_on_stop)) + fl_macro_fss_object_return_on_overflow((*buffer), (*location), (*found), delimits, f_status_is_warning(f_unterminated_group_on_eos), f_status_is_warning(f_unterminated_group_on_stop)) } // seek to the end of the line when no valid object is found - while (input->start < buffer->used && input->start <= input->stop && buffer->string[input->start] != f_string_eol) { - status = fl_fss_increment_buffer(*buffer, input, 1); + while (location->start < buffer->used && location->start <= location->stop && buffer->string[location->start] != f_string_eol) { + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } // while - fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) + fl_macro_fss_object_return_on_overflow((*buffer), (*location), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) { f_status allocation_status = f_none; @@ -387,7 +397,7 @@ extern "C" { } - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; return fl_fss_found_no_object; @@ -395,15 +405,15 @@ extern "C" { #endif // _di_fl_fss_basic_object_read_ #ifndef _di_fl_fss_basic_content_read_ - f_return_status fl_fss_basic_content_read(f_string_dynamic *buffer, f_string_location *input, f_fss_content *found) { + f_return_status fl_fss_basic_content_read(f_string_dynamic *buffer, f_string_location *location, f_fss_content *found) { #ifndef _di_level_1_parameter_checking_ if (buffer == 0) return f_status_set_error(f_invalid_parameter); - if (input == 0) return f_status_set_error(f_invalid_parameter); + if (location == 0) return f_status_set_error(f_invalid_parameter); if (found == 0) return f_status_set_error(f_invalid_parameter); - if (input->start < 0) return f_status_set_error(f_invalid_parameter); - if (input->stop < input->start) return f_status_set_error(f_invalid_parameter); + if (location->start < 0) return f_status_set_error(f_invalid_parameter); + if (location->stop < location->start) return f_status_set_error(f_invalid_parameter); if (buffer->used <= 0) return f_status_set_error(f_invalid_parameter); - if (input->start >= buffer->used) return f_status_set_error(f_invalid_parameter); + if (location->start >= buffer->used) return f_status_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ f_status status = f_none; @@ -411,35 +421,35 @@ extern "C" { // delimits must only be applied once a valid object is found f_string_lengths delimits = f_string_lengths_initialize; - fl_fss_skip_past_whitespace(*buffer, input); - fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), delimits, f_none_on_eos, f_none_on_stop) + fl_fss_skip_past_whitespace(*buffer, location); + fl_macro_fss_content_return_on_overflow((*buffer), (*location), (*found), delimits, f_none_on_eos, f_none_on_stop) // return found nothing if this line only contains whitespace and delimit placeholders - if (buffer->string[input->start] == f_string_eol) { - status = fl_fss_increment_buffer(*buffer, input, 1); + if (buffer->string[location->start] == f_string_eol) { + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; return fl_fss_found_no_content; } fl_macro_fss_allocate_content_if_necessary((*found), delimits); - found->array[found->used].start = input->start; + found->array[found->used].start = location->start; // search for valid content do { - fl_macro_fss_skip_past_delimit_placeholders((*buffer), (*input)) - fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*input), (*found), delimits, f_none_on_eos, f_none_on_stop) + fl_macro_fss_skip_past_delimit_placeholders((*buffer), (*location)) + fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*location), (*found), delimits, f_none_on_eos, f_none_on_stop) - if (buffer->string[input->start] == f_fss_basic_close) break; + if (buffer->string[location->start] == f_fss_basic_close) break; - ++input->start; + ++location->start; } while (f_true); - // Save the stop location - found->array[found->used].stop = input->start - 1; + // Save the stop length + found->array[found->used].stop = location->start - 1; found->used++; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; return fl_fss_found_content; @@ -447,7 +457,7 @@ extern "C" { #endif // _di_fl_fss_basic_content_read_ #ifndef _di_fl_fss_basic_object_write_ - f_return_status fl_fss_basic_object_write(f_string_dynamic *buffer, const f_string_dynamic object, f_string_location *input) { + f_return_status fl_fss_basic_object_write(f_string_dynamic *buffer, const f_string_dynamic object, f_string_location *location) { #ifndef _di_level_1_parameter_checking_ if (buffer == 0) return f_status_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ @@ -459,19 +469,19 @@ extern "C" { f_string_length start_position = f_string_initialize; f_string_length pre_allocate_size = 0; - fl_macro_fss_skip_past_delimit_placeholders(object, (*input)) + fl_macro_fss_skip_past_delimit_placeholders(object, (*location)) - if (input->start > input->stop) { + if (location->start > location->stop) { return f_no_data_on_stop; } - else if (input->start >= object.used) { + else if (location->start >= object.used) { return f_no_data_on_eos; } - start_position = input->start; + start_position = location->start; // add an additional 3 to ensure that there is room for the start and stop quotes or a slash delimit and the object open character. - pre_allocate_size = buffer->used + (input->stop - input->start) + 3 + f_fss_default_allocation_step_string; + pre_allocate_size = buffer->used + (location->stop - location->start) + 3 + f_fss_default_allocation_step_string; if (pre_allocate_size > buffer->size) { f_macro_string_dynamic_resize(status, (*buffer), pre_allocate_size); @@ -482,26 +492,26 @@ extern "C" { buffer_position.start = buffer->used; buffer_position.stop = buffer->used; - if (object.string[input->start] == f_fss_delimit_slash) { - while (input->start <= input->stop && input->start < object.used) { - if (object.string[input->start] == f_fss_delimit_placeholder) { - status = fl_fss_increment_buffer(*buffer, input, 1); + if (object.string[location->start] == f_fss_delimit_slash) { + while (location->start <= location->stop && location->start < object.used) { + if (object.string[location->start] == f_fss_delimit_placeholder) { + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; continue; } - else if (object.string[input->start] != f_fss_delimit_slash) { + else if (object.string[location->start] != f_fss_delimit_slash) { break; } - buffer->string[buffer_position.stop] = object.string[input->start]; + buffer->string[buffer_position.stop] = object.string[location->start]; buffer_position.stop++; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } // while - if (object.string[input->start] == f_fss_delimit_single_quote || object.string[input->start] == f_fss_delimit_double_quote) { + if (object.string[location->start] == f_fss_delimit_single_quote || object.string[location->start] == f_fss_delimit_double_quote) { pre_allocate_size++; if (pre_allocate_size > buffer->size) { @@ -511,14 +521,14 @@ extern "C" { } buffer->string[buffer_position.stop] = f_fss_delimit_slash; - buffer->string[buffer_position.stop + 1] = object.string[input->start]; + buffer->string[buffer_position.stop + 1] = object.string[location->start]; buffer_position.stop += 2; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } } - else if (object.string[input->start] == f_fss_delimit_single_quote || object.string[input->start] == f_fss_delimit_double_quote) { + else if (object.string[location->start] == f_fss_delimit_single_quote || object.string[location->start] == f_fss_delimit_double_quote) { pre_allocate_size++; if (pre_allocate_size > buffer->size) { @@ -528,24 +538,24 @@ extern "C" { } buffer->string[buffer_position.stop] = f_fss_delimit_slash; - buffer->string[buffer_position.stop + 1] = object.string[input->start]; + buffer->string[buffer_position.stop + 1] = object.string[location->start]; buffer_position.stop += 2; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } - else if (object.string[input->start] == f_fss_comment) { + else if (object.string[location->start] == f_fss_comment) { quoted = f_true; } - while (input->start <= input->stop && input->start < object.used) { - if (object.string[input->start] == f_fss_delimit_placeholder) { - status = fl_fss_increment_buffer(*buffer, input, 1); + while (location->start <= location->stop && location->start < object.used) { + if (object.string[location->start] == f_fss_delimit_placeholder) { + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; continue; } - else if (object.string[input->start] == f_string_eol) { + else if (object.string[location->start] == f_string_eol) { if (quoted) { buffer->string[buffer_position.stop] = f_fss_delimit_double_quote; buffer_position.stop++; @@ -556,7 +566,7 @@ extern "C" { return f_none_on_eol; } - else if ((status = fl_fss_is_space(*buffer, *input)) == f_true || quoted) { + else if ((status = fl_fss_is_space(*buffer, *location)) == f_true || quoted) { pre_allocate_size++; if (pre_allocate_size > buffer->size) { @@ -566,20 +576,20 @@ extern "C" { } // restart the loop searching for f_fss_delimit_double_quote. - input->start = start_position; + location->start = start_position; buffer_position.stop = buffer_position.start; buffer->string[buffer_position.stop] = f_fss_delimit_double_quote; buffer_position.stop++; - while (input->start <= input->stop && input->start < object.used) { - if (object.string[input->start] == f_fss_delimit_placeholder) { - status = fl_fss_increment_buffer(*buffer, input, 1); + while (location->start <= location->stop && location->start < object.used) { + if (object.string[location->start] == f_fss_delimit_placeholder) { + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; continue; } - else if (object.string[input->start] == f_fss_delimit_double_quote) { + else if (object.string[location->start] == f_fss_delimit_double_quote) { pre_allocate_size++; if (pre_allocate_size > buffer->size) { @@ -591,25 +601,25 @@ extern "C" { buffer->string[buffer_position.stop] = f_fss_delimit_slash; buffer_position.stop++; } - else if (object.string[input->start] == f_fss_delimit_slash) { + else if (object.string[location->start] == f_fss_delimit_slash) { f_string_length slash_count = 0; do { - buffer->string[buffer_position.stop] = object.string[input->start]; + buffer->string[buffer_position.stop] = object.string[location->start]; buffer_position.stop++; slash_count++; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; - fl_macro_fss_skip_past_delimit_placeholders(object, (*input)); + fl_macro_fss_skip_past_delimit_placeholders(object, (*location)); - if (input->start > input->stop || input->start >= object.used) { + if (location->start > location->stop || location->start >= object.used) { break; } - if (object.string[input->start] == f_fss_delimit_double_quote) { + if (object.string[location->start] == f_fss_delimit_double_quote) { pre_allocate_size += slash_count; if (pre_allocate_size > buffer->size) { @@ -620,7 +630,7 @@ extern "C" { break; } - else if (object.string[input->start] != f_fss_delimit_slash) { + else if (object.string[location->start] != f_fss_delimit_slash) { slash_count = 0; break; } @@ -634,7 +644,7 @@ extern "C" { continue; } - else if (object.string[input->start] == f_string_eol) { + else if (object.string[location->start] == f_string_eol) { buffer->string[buffer_position.stop] = f_fss_delimit_double_quote; buffer_position.stop++; @@ -644,9 +654,9 @@ extern "C" { return f_none_on_eol; } - buffer->string[buffer_position.stop] = object.string[input->start]; + buffer->string[buffer_position.stop] = object.string[location->start]; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; buffer_position.stop++; @@ -661,9 +671,9 @@ extern "C" { return status; } - buffer->string[buffer_position.stop] = object.string[input->start]; + buffer->string[buffer_position.stop] = object.string[location->start]; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; buffer_position.stop++; @@ -674,10 +684,10 @@ extern "C" { buffer->used = buffer_position.stop + 1; } - if (input->start > input->stop) { + if (location->start > location->stop) { return f_none_on_stop; } - else if (input->start >= object.used) { + else if (location->start >= object.used) { return f_none_on_eos; } @@ -686,7 +696,7 @@ extern "C" { #endif // _di_fl_fss_basic_object_write_ #ifndef _di_fl_fss_basic_content_write_ - f_return_status fl_fss_basic_content_write(f_string_dynamic *buffer, const f_string_dynamic content, f_string_location *input) { + f_return_status fl_fss_basic_content_write(f_string_dynamic *buffer, const f_string_dynamic content, f_string_location *location) { #ifndef _di_level_1_parameter_checking_ if (buffer == 0) return f_status_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ @@ -709,28 +719,28 @@ extern "C" { if (f_status_is_error(status)) return status; } - while (input->start <= input->stop && input->start < content.used) { - if (content.string[input->start] == f_string_eol){ + while (location->start <= location->stop && location->start < content.used) { + if (content.string[location->start] == f_string_eol){ buffer->string[buffer_position.stop] = f_string_eol; buffer->used = buffer_position.stop + 1; return f_none_on_eos; } - if (content.string[input->start] != f_fss_delimit_placeholder) { - buffer->string[buffer_position.stop] = content.string[input->start]; + if (content.string[location->start] != f_fss_delimit_placeholder) { + buffer->string[buffer_position.stop] = content.string[location->start]; buffer_position.stop++; } - fl_fss_increment_buffer(*buffer, input, 1); + fl_fss_increment_buffer(*buffer, location, 1); } // while buffer->string[buffer_position.stop] = f_string_eol; buffer->used = buffer_position.stop + 1; - if (input->start > input->stop) { + if (location->start > location->stop) { return f_none_on_stop; } - else if (input->start >= content.used) { + else if (location->start >= content.used) { return f_none_on_eos; } diff --git a/level_1/fl_fss/c/fss_basic.h b/level_1/fl_fss/c/fss_basic.h index 7c850fc..c9d5da8 100644 --- a/level_1/fl_fss/c/fss_basic.h +++ b/level_1/fl_fss/c/fss_basic.h @@ -31,32 +31,133 @@ extern "C" { #endif +/** + * Read an fss-0000 object. + * + * This will update the buffer at the given range with any placeholders to unescape any escaped data. + * Calling this more than once on the same buffer range could result in multiple unescaping. + * + * @param buffer + * The buffer to read from. + * This will be updated with delimit placeholders as it is being processed. + * @param location + * 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 set of all locations where a valid object was found. + * + * @return + * fl_fss_found_object on success and object was found (start location is at end of object). + * fl_fss_found_no_object on success and no object was found (start location is after character designating this is not an object). + * f_none_on_stop on success after reaching stopping point (a valid object is not yet confirmed). + * f_none_on_eos on success after reaching the end of the buffer (a valid object is not yet confirmed). + * f_no_data_on_stop no data found after reaching stopping point (essentially only comments are found). + * f_no_data_on_eos no objects found after reaching the end of the buffer (essentially only comments are found). + * f_incomplete_utf_on_stop (with error bit) if the stop location is reached before the complete UTF-8 character can be processed. + * f_incomplete_utf_on_eos (with error bit) if the end of buffer is reached before the complete UTF-8 character can be processed. + * 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_invalid_utf (with error bit) is returned on failure to read/process a UTF-8 character. + * f_reallocation_error (with error bit) on reallocation error. + * f_invalid_parameter (with error bit) if a parameter is invalid. + */ #ifndef _di_fl_fss_basic_object_read_ - /** - * read an fss-0000 object. - */ - extern f_return_status fl_fss_basic_object_read(f_string_dynamic *buffer, f_string_location *input, f_fss_object *found); + extern f_return_status fl_fss_basic_object_read(f_string_dynamic *buffer, f_string_location *location, f_fss_object *found); #endif // _di_fl_fss_basic_object_read_ +/** + * Read an fss-0000 content. + * + * This will update the buffer at the given range with any placeholders to unescape any escaped data. + * Calling this more than once on the same buffer range could result in multiple unescaping. + * + * @param buffer + * The buffer to read from. + * This will be updated with delimit placeholders as it is being processed. + * @param location + * 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 set of all locations where a valid content was found. + * + * @return + * fl_fss_found_content on success and content was found (start location is at end of content). + * fl_fss_found_no_content on success and no content was found (start location is after character designating this is not a content). + * f_none_on_stop on success after reaching stopping point (a valid content is not yet confirmed). + * f_none_on_eos on success after reaching the end of the buffer (a valid content is not yet confirmed). + * f_no_data_on_stop no data found after reaching stopping point (essentially only comments are found). + * f_no_data_on_eos no content found after reaching the end of the buffer (essentially only comments are found). + * f_incomplete_utf_on_stop (with error bit) if the stop location is reached before the complete UTF-8 character can be processed. + * f_incomplete_utf_on_eos (with error bit) if the end of buffer is reached before the complete UTF-8 character can be processed. + * 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_invalid_utf (with error bit) is returned on failure to read/process a UTF-8 character. + * f_reallocation_error (with error bit) on reallocation error. + * f_invalid_parameter (with error bit) if a parameter is invalid. + */ #ifndef _di_fl_fss_basic_content_read_ - /** - * read an fss-0000 content. - */ - extern f_return_status fl_fss_basic_content_read(f_string_dynamic *buffer, f_string_location *input, f_fss_content *found); + extern f_return_status fl_fss_basic_content_read(f_string_dynamic *buffer, f_string_location *location, f_fss_content *found); #endif // _di_fl_fss_basic_content_read_ +/** + * Write an fss-0000 object. + * + * This will write the given string range as a valid object. + * Anything within this range will be escaped as necessary. + * This will stop if EOL is reached. + * + * @param object + * The string to write as (does not stop at NULLS, they are ignored and not written). + * @param location + * The start/stop location within the object string to write as an object. + * @param buffer + * The buffer where the object is written to. + * This will be auto-incremented and must not be a static string. + * + * @return + * f_none on success. + * f_none_on_stop on success after reaching stopping point . + * f_none_on_eos on success after reaching the end of the buffer. + * f_no_data_on_stop no data to write due start location being greater than stop location. + * f_no_data_on_eos no data to write due start location being greater than or equal to buffer size. + * 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_invalid_utf (with error bit) is returned on failure to read/process a UTF-8 character. + * f_reallocation_error (with error bit) on reallocation error. + * f_invalid_parameter (with error bit) if a parameter is invalid. + */ #ifndef _di_fl_fss_basic_object_write_ - /** - * write an fss-0000 object. - */ - extern f_return_status fl_fss_basic_object_write(f_string_dynamic *buffer, const f_string_dynamic object, f_string_location *input); + extern f_return_status fl_fss_basic_object_write(f_string_dynamic *buffer, const f_string_dynamic object, f_string_location *location); #endif // _di_fl_fss_basic_object_write_ +/** + * Write an fss-0000 content. + * + * This will write the given string range as a valid content. + * Anything within this range will be escaped as necessary. + * + * @param content + * The string to write as (does not stop at NULLS, they are ignored and not written). + * @param location + * The start/stop location within the content string to write as an content. + * @param buffer + * The buffer where the content is written to. + * This will be auto-incremented and must not be a static string. + * + * @return + * f_none on success. + * f_none_on_stop on success after reaching stopping point . + * f_none_on_eos on success after reaching the end of the buffer. + * f_no_data_on_stop no data to write due start location being greater than stop location. + * f_no_data_on_eos no data to write due start location being greater than or equal to buffer size. + * 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_invalid_utf (with error bit) is returned on failure to read/process a UTF-8 character. + * f_reallocation_error (with error bit) on reallocation error. + * f_invalid_parameter (with error bit) if a parameter is invalid. + */ #ifndef _di_fl_fss_basic_content_write_ - /** - * write an fss-0000 content. - */ - extern f_return_status fl_fss_basic_content_write(f_string_dynamic *buffer, const f_string_dynamic content, f_string_location *input); + extern f_return_status fl_fss_basic_content_write(f_string_dynamic *buffer, const f_string_dynamic content, f_string_location *location); #endif // _di_fl_fss_basic_content_write_ #ifdef __cplusplus diff --git a/level_1/fl_fss/c/fss_basic_list.c b/level_1/fl_fss/c/fss_basic_list.c index 0eea92f..07f0f0c 100644 --- a/level_1/fl_fss/c/fss_basic_list.c +++ b/level_1/fl_fss/c/fss_basic_list.c @@ -5,15 +5,15 @@ extern "C" { #endif #ifndef _di_fl_fss_basic_list_object_read_ - f_return_status fl_fss_basic_list_object_read(f_string_dynamic *buffer, f_string_location *input, f_fss_object *found) { + f_return_status fl_fss_basic_list_object_read(f_string_dynamic *buffer, f_string_location *location, f_fss_object *found) { #ifndef _di_level_1_parameter_checking_ if (buffer == 0) return f_status_set_error(f_invalid_parameter); - if (input == 0) return f_status_set_error(f_invalid_parameter); + if (location == 0) return f_status_set_error(f_invalid_parameter); if (found == 0) return f_status_set_error(f_invalid_parameter); - if (input->start < 0) return f_status_set_error(f_invalid_parameter); - if (input->stop < input->start) return f_status_set_error(f_invalid_parameter); + if (location->start < 0) return f_status_set_error(f_invalid_parameter); + if (location->stop < location->start) return f_status_set_error(f_invalid_parameter); if (buffer->used <= 0) return f_status_set_error(f_invalid_parameter); - if (input->start >= buffer->used) return f_status_set_error(f_invalid_parameter); + if (location->start >= buffer->used) return f_status_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ f_status status = f_none; @@ -21,73 +21,73 @@ extern "C" { // delimits must only be applied once a valid object is found f_string_lengths delimits = f_string_lengths_initialize; - fl_fss_skip_past_whitespace(*buffer, input); - fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) + fl_fss_skip_past_whitespace(*buffer, location); + fl_macro_fss_object_return_on_overflow((*buffer), (*location), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) // return found nothing if this line only contains whitespace and delimit placeholders - if (buffer->string[input->start] == f_string_eol) { - status = fl_fss_increment_buffer(*buffer, input, 1); + if (buffer->string[location->start] == f_string_eol) { + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; return fl_fss_found_no_object; } // begin the search - found->start = input->start; + found->start = location->start; // ignore all comment lines - if (buffer->string[input->start] == f_fss_comment) { - fl_macro_fss_object_seek_till_newline((*buffer), (*input), delimits, f_no_data_on_eos, f_no_data_on_stop) + if (buffer->string[location->start] == f_fss_comment) { + fl_macro_fss_object_seek_till_newline((*buffer), (*location), delimits, f_no_data_on_eos, f_no_data_on_stop) - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; return fl_fss_found_no_object; } // identify where the object ends - while (input->start < buffer->used && input->start <= input->stop && buffer->string[input->start] != f_string_eol) { - if (buffer->string[input->start] == f_fss_delimit_slash) { - f_string_length first_slash = input->start; + while (location->start < buffer->used && location->start <= location->stop && buffer->string[location->start] != f_string_eol) { + if (buffer->string[location->start] == f_fss_delimit_slash) { + f_string_length first_slash = location->start; f_string_length slash_count = 1; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; - while (input->start < buffer->used && input->start <= input->stop && (buffer->string[input->start] == f_fss_delimit_placeholder || buffer->string[input->start] == f_fss_delimit_slash)) { - if (buffer->string[input->start] == f_fss_delimit_slash) { + while (location->start < buffer->used && location->start <= location->stop && (buffer->string[location->start] == f_fss_delimit_placeholder || buffer->string[location->start] == f_fss_delimit_slash)) { + if (buffer->string[location->start] == f_fss_delimit_slash) { slash_count++; } - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } // while - fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) + fl_macro_fss_object_return_on_overflow((*buffer), (*location), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) - if (buffer->string[input->start] == f_fss_basic_list_open) { - f_string_length stop_point = input->start - 1; + if (buffer->string[location->start] == f_fss_basic_list_open) { + f_string_length stop_point = location->start - 1; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; - while (input->start < buffer->used && input->start <= input->stop) { - if (buffer->string[input->start] == f_string_eol || (status = fl_fss_is_graph(*buffer, *input)) == f_true) { + while (location->start < buffer->used && location->start <= location->stop) { + if (buffer->string[location->start] == f_string_eol || (status = fl_fss_is_graph(*buffer, *location)) == f_true) { break; } if (f_status_is_error(status)) return status; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } // while - fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) + fl_macro_fss_object_return_on_overflow((*buffer), (*location), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) - if (buffer->string[input->start] == f_string_eol) { - f_string_length location = input->start; + if (buffer->string[location->start] == f_string_eol) { + f_string_length length = location->start; - input->start = first_slash; + location->start = first_slash; if (delimits.used + (slash_count / 2) >= delimits.size) { f_status allocation_status = f_none; @@ -102,59 +102,59 @@ extern "C" { if (slash_count % 2 == 0) { while (slash_count > 0) { - if (buffer->string[input->start] == f_fss_delimit_slash) { + if (buffer->string[location->start] == f_fss_delimit_slash) { if (slash_count % 2 != 0) { - delimits.array[delimits.used] = input->start; + delimits.array[delimits.used] = location->start; delimits.used++; } slash_count--; } - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } // while fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); found->stop = stop_point; - input->start = location + 1; + location->start = length + 1; return fl_fss_found_object; } - input->start = location + 1; + location->start = length + 1; return fl_fss_found_no_object; } } continue; } - else if (buffer->string[input->start] == f_fss_basic_list_open) { - f_string_length stop_point = input->start - 1; + else if (buffer->string[location->start] == f_fss_basic_list_open) { + f_string_length stop_point = location->start - 1; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; - while (input->start < buffer->used && input->start <= input->stop) { - if (buffer->string[input->start] == f_string_eol || (status = fl_fss_is_graph(*buffer, *input)) == f_true) { + while (location->start < buffer->used && location->start <= location->stop) { + if (buffer->string[location->start] == f_string_eol || (status = fl_fss_is_graph(*buffer, *location)) == f_true) { break; } if (f_status_is_error(status)) return status; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } // while - fl_macro_fss_object_delimited_return_on_overflow((*buffer), (*input), (*found), delimits, f_none_on_eos, f_none_on_stop) + fl_macro_fss_object_delimited_return_on_overflow((*buffer), (*location), (*found), delimits, f_none_on_eos, f_none_on_stop) - if (buffer->string[input->start] == f_string_eol) { + if (buffer->string[location->start] == f_string_eol) { fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); found->stop = stop_point; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; return fl_fss_found_object; @@ -163,19 +163,19 @@ extern "C" { continue; } - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } // while // seek to the end of the line when no valid object is found - while (input->start < buffer->used && input->start <= input->stop && buffer->string[input->start] != f_string_eol) { - status = fl_fss_increment_buffer(*buffer, input, 1); + while (location->start < buffer->used && location->start <= location->stop && buffer->string[location->start] != f_string_eol) { + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } // while - fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) + fl_macro_fss_object_return_on_overflow((*buffer), (*location), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; return fl_fss_found_no_object; @@ -183,15 +183,15 @@ extern "C" { #endif // _di_fl_fss_basic_list_object_read_ #ifndef _di_fl_fss_basic_list_content_read_ - f_return_status fl_fss_basic_list_content_read(f_string_dynamic *buffer, f_string_location *input, f_fss_content *found) { + f_return_status fl_fss_basic_list_content_read(f_string_dynamic *buffer, f_string_location *location, f_fss_content *found) { #ifndef _di_level_1_parameter_checking_ if (buffer == 0) return f_status_set_error(f_invalid_parameter); - if (input == 0) return f_status_set_error(f_invalid_parameter); + if (location == 0) return f_status_set_error(f_invalid_parameter); if (found == 0) return f_status_set_error(f_invalid_parameter); - if (input->start < 0) return f_status_set_error(f_invalid_parameter); - if (input->stop < input->start) return f_status_set_error(f_invalid_parameter); + if (location->start < 0) return f_status_set_error(f_invalid_parameter); + if (location->stop < location->start) return f_status_set_error(f_invalid_parameter); if (buffer->used <= 0) return f_status_set_error(f_invalid_parameter); - if (input->start >= buffer->used) return f_status_set_error(f_invalid_parameter); + if (location->start >= buffer->used) return f_status_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ f_status status = f_none; @@ -199,80 +199,80 @@ extern "C" { // delimits must only be applied once a valid object is found f_string_lengths delimits = f_string_lengths_initialize; - fl_macro_fss_skip_past_delimit_placeholders((*buffer), (*input)) - fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), delimits, f_none_on_eos, f_none_on_stop) + fl_macro_fss_skip_past_delimit_placeholders((*buffer), (*location)) + fl_macro_fss_content_return_on_overflow((*buffer), (*location), (*found), delimits, f_none_on_eos, f_none_on_stop) fl_macro_fss_allocate_content_if_necessary((*found), delimits); - found->array[found->used].start = input->start; + found->array[found->used].start = location->start; - f_string_length last_newline = input->start; + f_string_length last_newline = location->start; f_bool found_newline = f_false; // identify where the content ends - while (input->start < buffer->used && input->start <= input->stop) { - if (buffer->string[input->start] == f_string_eol) { + while (location->start < buffer->used && location->start <= location->stop) { + if (buffer->string[location->start] == f_string_eol) { found_newline = f_true; - last_newline = input->start; + last_newline = location->start; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; - fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*input), (*found), delimits, f_none_on_eos, f_none_on_stop) + fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*location), (*found), delimits, f_none_on_eos, f_none_on_stop) continue; } - if (buffer->string[input->start] == f_fss_delimit_slash) { - f_string_length first_slash = input->start; + if (buffer->string[location->start] == f_fss_delimit_slash) { + f_string_length first_slash = location->start; f_string_length slash_count = 1; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; - while (input->start < buffer->used && input->start <= input->stop && (buffer->string[input->start] == f_fss_delimit_placeholder || buffer->string[input->start] == f_fss_delimit_slash)) { - if (buffer->string[input->start] == f_fss_delimit_slash) { + while (location->start < buffer->used && location->start <= location->stop && (buffer->string[location->start] == f_fss_delimit_placeholder || buffer->string[location->start] == f_fss_delimit_slash)) { + if (buffer->string[location->start] == f_fss_delimit_slash) { slash_count++; } - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } // while if (found_newline) { - fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*input), (*found), delimits, f_none_on_eos, f_none_on_stop) + fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*location), (*found), delimits, f_none_on_eos, f_none_on_stop) } else { - fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) + fl_macro_fss_content_return_on_overflow((*buffer), (*location), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) } - if (buffer->string[input->start] == f_fss_basic_list_open) { - f_string_length stop_point = input->start - 1; + if (buffer->string[location->start] == f_fss_basic_list_open) { + f_string_length stop_point = location->start - 1; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; - while (input->start < buffer->used && input->start <= input->stop) { - if (buffer->string[input->start] == f_string_eol || (status = fl_fss_is_graph(*buffer, *input)) == f_true) { + while (location->start < buffer->used && location->start <= location->stop) { + if (buffer->string[location->start] == f_string_eol || (status = fl_fss_is_graph(*buffer, *location)) == f_true) { break; } if (f_status_is_error(status)) return status; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } // while if (found_newline) { - fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*input), (*found), delimits, f_none_on_eos, f_none_on_stop) + fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*location), (*found), delimits, f_none_on_eos, f_none_on_stop) } else { - fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) + fl_macro_fss_content_return_on_overflow((*buffer), (*location), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) } - if (buffer->string[input->start] == f_string_eol) { - f_string_length location = input->start; + if (buffer->string[location->start] == f_string_eol) { + f_string_length length = location->start; - input->start = first_slash; + location->start = first_slash; if (slash_count % 2 == 0) { // FIXME: apply delimits?? @@ -280,7 +280,7 @@ extern "C" { fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); found->array[found->used].stop = last_newline; - input->start = last_newline + 1; + location->start = last_newline + 1; found->used++; return fl_fss_found_content; @@ -301,61 +301,61 @@ extern "C" { } while (slash_count > 0) { - if (buffer->string[input->start] == f_fss_delimit_slash) { + if (buffer->string[location->start] == f_fss_delimit_slash) { if (slash_count % 2 != 0) { - delimits.array[delimits.used] = input->start; + delimits.array[delimits.used] = location->start; delimits.used++; } slash_count--; } - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } // while found_newline = f_true; - input->start = location + 1; + location->start = length + 1; } } continue; } - else if (buffer->string[input->start] == f_fss_basic_list_open) { - status = fl_fss_increment_buffer(*buffer, input, 1); + else if (buffer->string[location->start] == f_fss_basic_list_open) { + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; - while (input->start < buffer->used && input->start <= input->stop) { - if (buffer->string[input->start] == f_string_eol || (status = fl_fss_is_graph(*buffer, *input)) == f_true) { + while (location->start < buffer->used && location->start <= location->stop) { + if (buffer->string[location->start] == f_string_eol || (status = fl_fss_is_graph(*buffer, *location)) == f_true) { break; } if (f_status_is_error(status)) return status; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } // while if (found_newline) { - fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*input), (*found), delimits, f_none_on_eos, f_none_on_stop) + fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*location), (*found), delimits, f_none_on_eos, f_none_on_stop) } else { - fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) + fl_macro_fss_content_return_on_overflow((*buffer), (*location), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) } - if (buffer->string[input->start] == f_string_eol) { + if (buffer->string[location->start] == f_string_eol) { if (found_newline) { fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); found->array[found->used].stop = last_newline; - input->start = last_newline + 1; + location->start = last_newline + 1; found->used++; return fl_fss_found_content; } if (!found_newline) { - input->start = last_newline; + location->start = last_newline; } return fl_fss_found_no_content; @@ -364,7 +364,7 @@ extern "C" { continue; } - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } // while @@ -372,22 +372,22 @@ extern "C" { fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); found->array[found->used].stop = last_newline - 1; - input->start = last_newline + 1; + location->start = last_newline + 1; found->used++; - fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*input), (*found), delimits, f_none_on_eos, f_none_on_stop) + fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*location), (*found), delimits, f_none_on_eos, f_none_on_stop) return fl_fss_found_content; } - fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) + fl_macro_fss_content_return_on_overflow((*buffer), (*location), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) return fl_fss_found_no_content; } #endif // _di_fl_fss_basic_list_content_read_ #ifndef _di_fl_fss_basic_list_object_write_ - f_return_status fl_fss_basic_list_object_write(const f_string_dynamic object, f_string_location *input, f_string_dynamic *buffer) { + f_return_status fl_fss_basic_list_object_write(const f_string_dynamic object, f_string_location *location, f_string_dynamic *buffer) { #ifndef _di_level_1_parameter_checking_ if (buffer == 0) return f_status_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ @@ -399,19 +399,19 @@ extern "C" { f_string_length pre_allocate_size = 0; f_string_length start_buffer = 0; - fl_macro_fss_skip_past_delimit_placeholders(object, (*input)) + fl_macro_fss_skip_past_delimit_placeholders(object, (*location)) - if (input->start > input->stop) { + if (location->start > location->stop) { return f_no_data_on_stop; } - else if (input->start >= object.used) { + else if (location->start >= object.used) { return f_no_data_on_eos; } - start_position = input->start; + start_position = location->start; // add an additional 2 to ensure that there is room for the slash delimit and the object open character. - pre_allocate_size = buffer->used + (input->stop - input->start) + 2 + f_fss_default_allocation_step_string; + pre_allocate_size = buffer->used + (location->stop - location->start) + 2 + f_fss_default_allocation_step_string; if (pre_allocate_size > buffer->size) { f_macro_string_dynamic_resize(status, (*buffer), pre_allocate_size); @@ -422,57 +422,57 @@ extern "C" { buffer_position.start = buffer->used; buffer_position.stop = buffer->used; - while (input->start <= input->stop && input->start < object.used) { - if (object.string[input->start] == f_fss_comment) { + while (location->start <= location->stop && location->start < object.used) { + if (object.string[location->start] == f_fss_comment) { // comments are not allowed and this format has no way of "wrapping" a comment. - return f_invalid_data; + return f_status_set_error(f_invalid_data); } - else if ((status = fl_fss_is_graph(object, *input)) == f_true) { + else if ((status = fl_fss_is_graph(object, *location)) == f_true) { break; } else if (f_status_is_error(status)) { return status; } - if (object.string[input->start] != f_fss_delimit_placeholder) { - buffer->string[buffer_position.stop] = object.string[input->start]; + if (object.string[location->start] != f_fss_delimit_placeholder) { + buffer->string[buffer_position.stop] = object.string[location->start]; buffer_position.stop++; } - status = fl_fss_increment_buffer(object, input, 1); + status = fl_fss_increment_buffer(object, location, 1); if (f_status_is_error(status)) return status; } // while - while (input->start <= input->stop && input->start < object.used) { - if (object.string[input->start] == f_fss_delimit_slash) { + while (location->start <= location->stop && location->start < object.used) { + if (object.string[location->start] == f_fss_delimit_slash) { f_string_length slash_count = 1; - buffer->string[buffer_position.stop] = object.string[input->start]; + buffer->string[buffer_position.stop] = object.string[location->start]; buffer_position.stop++; - status = fl_fss_increment_buffer(object, input, 1); + status = fl_fss_increment_buffer(object, location, 1); if (f_status_is_error(status)) return status; - while (input->start <= input->stop && input->start < object.used) { - if (object.string[input->start] == f_fss_delimit_placeholder) { - status = fl_fss_increment_buffer(object, input, 1); + while (location->start <= location->stop && location->start < object.used) { + if (object.string[location->start] == f_fss_delimit_placeholder) { + status = fl_fss_increment_buffer(object, location, 1); if (f_status_is_error(status)) return status; continue; - } else if (object.string[input->start] != f_fss_delimit_slash) { + } else if (object.string[location->start] != f_fss_delimit_slash) { break; } - buffer->string[buffer_position.stop] = object.string[input->start]; + buffer->string[buffer_position.stop] = object.string[location->start]; buffer_position.stop++; - status = fl_fss_increment_buffer(object, input, 1); + status = fl_fss_increment_buffer(object, location, 1); if (f_status_is_error(status)) return status; slash_count++; } // while - if (input->start > input->stop || input->start >= object.used) { + if (location->start > location->stop || location->start >= object.used) { pre_allocate_size += slash_count; if (pre_allocate_size > buffer->size) { @@ -490,7 +490,7 @@ extern "C" { break; } } - else if (object.string[input->start] == f_string_eol) { + else if (object.string[location->start] == f_string_eol) { if (buffer_position.stop == buffer_position.start) { return f_no_data_on_eol; } @@ -498,12 +498,12 @@ extern "C" { break; } - if (object.string[input->start] != f_fss_delimit_placeholder) { - buffer->string[buffer_position.stop] = object.string[input->start]; + if (object.string[location->start] != f_fss_delimit_placeholder) { + buffer->string[buffer_position.stop] = object.string[location->start]; buffer_position.stop++; } - status = fl_fss_increment_buffer(object, input, 1); + status = fl_fss_increment_buffer(object, location, 1); if (f_status_is_error(status)) return status; } // while @@ -511,10 +511,10 @@ extern "C" { buffer->string[buffer_position.stop + 1] = f_string_eol; buffer->used = buffer_position.stop + 2; - if (input->start > input->stop) { + if (location->start > location->stop) { return f_none_on_stop; } - else if (input->start >= object.used) { + else if (location->start >= object.used) { return f_none_on_eos; } @@ -523,7 +523,7 @@ extern "C" { #endif // _di_fl_fss_basic_list_object_write_ #ifndef _di_fl_fss_basic_list_content_write_ - f_return_status fl_fss_basic_list_content_write(const f_string_dynamic content, f_string_location *input, f_string_dynamic *buffer) { + f_return_status fl_fss_basic_list_content_write(const f_string_dynamic content, f_string_location *location, f_string_dynamic *buffer) { #ifndef _di_level_1_parameter_checking_ if (buffer == 0) return f_status_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ @@ -536,19 +536,19 @@ extern "C" { f_string_length start_position = f_string_initialize; f_string_length pre_allocate_size = 0; - fl_macro_fss_skip_past_delimit_placeholders(content, (*input)) + fl_macro_fss_skip_past_delimit_placeholders(content, (*location)) - if (input->start > input->stop) { + if (location->start > location->stop) { return f_no_data_on_stop; } - else if (input->start >= content.used) { + else if (location->start >= content.used) { return f_no_data_on_eos; } - start_position = input->start; + start_position = location->start; // add an additional 2 to ensure that there is room for the slash delimit and the content open character. - pre_allocate_size = buffer->used + (input->stop - input->start) + 2 + f_fss_default_allocation_step_string; + pre_allocate_size = buffer->used + (location->stop - location->start) + 2 + f_fss_default_allocation_step_string; if (pre_allocate_size > buffer->size) { f_macro_string_dynamic_resize(status, (*buffer), pre_allocate_size); @@ -559,55 +559,55 @@ extern "C" { buffer_position.start = buffer->used; buffer_position.stop = buffer->used; - while (input->start <= input->stop && input->start < content.used) { - if (content.string[input->start] == f_fss_delimit_slash && !is_comment) { + while (location->start <= location->stop && location->start < content.used) { + if (content.string[location->start] == f_fss_delimit_slash && !is_comment) { f_string_length slash_count = 1; - buffer->string[buffer_position.stop] = content.string[input->start]; + buffer->string[buffer_position.stop] = content.string[location->start]; buffer_position.stop++; has_graph = f_true; - status = fl_fss_increment_buffer(content, input, 1); + status = fl_fss_increment_buffer(content, location, 1); if (f_status_is_error(status)) return status; - while (input->start <= input->stop && input->start < content.used) { - if (content.string[input->start] == f_fss_delimit_placeholder) { - status = fl_fss_increment_buffer(content, input, 1); + while (location->start <= location->stop && location->start < content.used) { + if (content.string[location->start] == f_fss_delimit_placeholder) { + status = fl_fss_increment_buffer(content, location, 1); if (f_status_is_error(status)) return status; continue; } - else if (content.string[input->start] != f_fss_delimit_slash) { + else if (content.string[location->start] != f_fss_delimit_slash) { break; } - buffer->string[buffer_position.stop] = content.string[input->start]; + buffer->string[buffer_position.stop] = content.string[location->start]; buffer_position.stop++; - status = fl_fss_increment_buffer(content, input, 1); + status = fl_fss_increment_buffer(content, location, 1); if (f_status_is_error(status)) return status; slash_count++; } // while - if (content.string[input->start] == f_fss_basic_list_open) { - f_string_length location = input->start; + if (content.string[location->start] == f_fss_basic_list_open) { + f_string_length length = location->start; - status = fl_fss_increment_buffer(content, input, 1); + status = fl_fss_increment_buffer(content, location, 1); if (f_status_is_error(status)) return status; - while (input->start < content.used && input->start <= input->stop) { - if (content.string[input->start] == f_string_eol || (status = fl_fss_is_graph(content, *input)) == f_true) { + while (location->start < content.used && location->start <= location->stop) { + if (content.string[location->start] == f_string_eol || (status = fl_fss_is_graph(content, *location)) == f_true) { break; } if (f_status_is_error(status)) return status; - status = fl_fss_increment_buffer(content, input, 1); + status = fl_fss_increment_buffer(content, location, 1); if (f_status_is_error(status)) return status; } // while - if (content.string[input->start] == f_string_eol || input->start >= content.used || input->start > input->stop) { + if (content.string[location->start] == f_string_eol || location->start >= content.used || location->start > location->stop) { pre_allocate_size += slash_count + 1; if (pre_allocate_size > buffer->size) { @@ -630,30 +630,30 @@ extern "C" { buffer->string[buffer_position.stop] = f_fss_basic_list_open; buffer_position.stop++; - input->start = location + 1; + location->start = length + 1; continue; } } - else if (content.string[input->start] == f_fss_basic_list_open && !is_comment) { - f_string_length location = input->start; + else if (content.string[location->start] == f_fss_basic_list_open && !is_comment) { + f_string_length length = location->start; has_graph = f_true; - status = fl_fss_increment_buffer(content, input, 1); + status = fl_fss_increment_buffer(content, location, 1); if (f_status_is_error(status)) return status; - while (input->start < content.used && input->start <= input->stop) { - if (content.string[input->start] == f_string_eol || (status = fl_fss_is_graph(content, *input)) == f_true) { + while (location->start < content.used && location->start <= location->stop) { + if (content.string[location->start] == f_string_eol || (status = fl_fss_is_graph(content, *location)) == f_true) { break; } if (f_status_is_error(status)) return status; - status = fl_fss_increment_buffer(content, input, 1); + status = fl_fss_increment_buffer(content, location, 1); if (f_status_is_error(status)) return status; } // while - if (content.string[input->start] == f_string_eol || input->start >= content.used || input->start > input->stop) { + if (content.string[location->start] == f_string_eol || location->start >= content.used || location->start > location->stop) { pre_allocate_size++; if (pre_allocate_size > buffer->size) { @@ -670,39 +670,49 @@ extern "C" { buffer->string[buffer_position.stop] = f_fss_basic_list_open; buffer_position.stop++; - input->start = location + 1; + location->start = length + 1; continue; } - else if (content.string[input->start] == f_fss_comment && !has_graph) { + else if (content.string[location->start] == f_fss_comment && !has_graph) { is_comment = f_true; } - else if (content.string[input->start] == f_string_eol) { + else if (content.string[location->start] == f_string_eol) { has_graph = f_false; is_comment = f_false; } - else if ((status = fl_fss_is_graph(content, *input)) == f_true) { + else if ((status = fl_fss_is_graph(content, *location)) == f_true) { has_graph = f_true; } else if (f_status_is_error(status)) { + f_status status2 = f_status_set_fine(status); + + if (status2 == f_failure) { + return f_status_set_error(f_invalid_utf); + } + + if (status2 == f_failure) { + return f_status_set_error(f_incomplete_utf); + } + return status; } - if (content.string[input->start] != f_fss_delimit_placeholder) { - buffer->string[buffer_position.stop] = content.string[input->start]; + if (content.string[location->start] != f_fss_delimit_placeholder) { + buffer->string[buffer_position.stop] = content.string[location->start]; buffer_position.stop++; } - status = fl_fss_increment_buffer(content, input, 1); + status = fl_fss_increment_buffer(content, location, 1); if (f_status_is_error(status)) return status; } // while buffer->string[buffer_position.stop] = f_string_eol; buffer->used = buffer_position.stop + 1; - if (input->start > input->stop) { + if (location->start > location->stop) { return f_none_on_stop; } - else if (input->start >= content.used) { + else if (location->start >= content.used) { return f_none_on_eos; } diff --git a/level_1/fl_fss/c/fss_basic_list.h b/level_1/fl_fss/c/fss_basic_list.h index 3a8adc5..cf08c45 100644 --- a/level_1/fl_fss/c/fss_basic_list.h +++ b/level_1/fl_fss/c/fss_basic_list.h @@ -32,32 +32,134 @@ extern "C" { #endif +/** + * Read an fss-0002 object. + * + * This will update the buffer at the given range with any placeholders to unescape any escaped data. + * Calling this more than once on the same buffer range could result in multiple unescaping. + * + * @param buffer + * The buffer to read from. + * This will be updated with delimit placeholders as it is being processed. + * @param location + * 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 set of all locations where a valid object was found. + * + * @return + * fl_fss_found_object on success and object was found (start location is at end of object). + * fl_fss_found_no_object on success and no object was found (start location is after character designating this is not an object). + * f_none_on_stop on success after reaching stopping point (a valid object is not yet confirmed). + * f_none_on_eos on success after reaching the end of the buffer (a valid object is not yet confirmed). + * f_no_data_on_stop no data found after reaching stopping point (essentially only comments are found). + * f_no_data_on_eos no objects found after reaching the end of the buffer (essentially only comments are found). + * f_incomplete_utf_on_stop (with error bit) if the stop location is reached before the complete UTF-8 character can be processed. + * f_incomplete_utf_on_eos (with error bit) if the end of buffer is reached before the complete UTF-8 character can be processed. + * 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_invalid_utf (with error bit) is returned on failure to read/process a UTF-8 character. + * f_reallocation_error (with error bit) on reallocation error. + * f_invalid_parameter (with error bit) if a parameter is invalid. + */ #ifndef _di_fl_fss_basic_list_object_read_ - /** - * read an fss-0002 object. - */ - extern f_return_status fl_fss_basic_list_object_read(f_string_dynamic *buffer, f_string_location *input, f_fss_object *found); + extern f_return_status fl_fss_basic_list_object_read(f_string_dynamic *buffer, f_string_location *location, f_fss_object *found); #endif // _di_fl_fss_basic_list_object_read_ +/** + * Read an fss-0002 content. + * + * This will update the buffer at the given range with any placeholders to unescape any escaped data. + * Calling this more than once on the same buffer range could result in multiple unescaping. + * + * @param buffer + * The buffer to read from. + * This will be updated with delimit placeholders as it is being processed. + * @param location + * 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 set of all locations where a valid content was found. + * + * @return + * fl_fss_found_content on success and content was found (start location is at end of content). + * fl_fss_found_no_content on success and no content was found (start location is after character designating this is not a content). + * f_none_on_stop on success after reaching stopping point (a valid content is not yet confirmed). + * f_none_on_eos on success after reaching the end of the buffer (a valid content is not yet confirmed). + * f_no_data_on_stop no data found after reaching stopping point (essentially only comments are found). + * f_no_data_on_eos no content found after reaching the end of the buffer (essentially only comments are found). + * f_incomplete_utf_on_stop (with error bit) if the stop location is reached before the complete UTF-8 character can be processed. + * f_incomplete_utf_on_eos (with error bit) if the end of buffer is reached before the complete UTF-8 character can be processed. + * 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_invalid_utf (with error bit) is returned on failure to read/process a UTF-8 character. + * f_reallocation_error (with error bit) on reallocation error. + * f_invalid_parameter (with error bit) if a parameter is invalid. + */ #ifndef _di_fl_fss_basic_list_content_read_ - /** - * read an fss-0002 content. - */ - extern f_return_status fl_fss_basic_list_content_read(f_string_dynamic *buffer, f_string_location *input, f_fss_content *found); + extern f_return_status fl_fss_basic_list_content_read(f_string_dynamic *buffer, f_string_location *location, f_fss_content *found); #endif // _di_fl_fss_basic_list_content_read_ +/** + * Write an fss-0002 object. + * + * This will write the given string range as a valid object. + * Anything within this range will be escaped as necessary. + * This will stop if EOL is reached. + * + * @param object + * The string to write as (does not stop at NULLS, they are ignored and not written). + * @param location + * The start/stop location within the object string to write as an object. + * @param buffer + * The buffer where the object is written to. + * This will be auto-incremented and must not be a static string. + * + * @return + * f_none on success. + * f_none_on_stop on success after reaching stopping point . + * f_none_on_eos on success after reaching the end of the buffer. + * f_no_data_on_stop no data to write due start location being greater than stop location. + * f_no_data_on_eos no data to write due start location being greater than or equal to buffer size. + * f_no_data_on_eol if there is no data to write and EOL was reached (@todo: review related code and detemine what this is doing). + * 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_invalid_utf (with error bit) is returned on failure to read/process a UTF-8 character. + * f_reallocation_error (with error bit) on reallocation error. + * f_invalid_parameter (with error bit) if a parameter is invalid. + */ #ifndef _di_fl_fss_basic_list_object_write_ - /** - * write an fss-0002 object. - */ - extern f_return_status fl_fss_basic_list_object_write(const f_string_dynamic object, f_string_location *input, f_string_dynamic *buffer); + extern f_return_status fl_fss_basic_list_object_write(const f_string_dynamic object, f_string_location *location, f_string_dynamic *buffer); #endif // _di_fl_fss_basic_list_object_write_ +/** + * Write an fss-0002 content. + * + * This will write the given string range as a valid content. + * Anything within this range will be escaped as necessary. + * + * @param content + * The string to write as (does not stop at NULLS, they are ignored and not written). + * @param location + * The start/stop location within the content string to write as an content. + * @param buffer + * The buffer where the content is written to. + * This will be auto-incremented and must not be a static string. + * + * @return + * f_none on success. + * f_none_on_stop on success after reaching stopping point . + * f_none_on_eos on success after reaching the end of the buffer. + * f_no_data_on_stop no data to write due start location being greater than stop location. + * f_no_data_on_eos no data to write due start location being greater than or equal to buffer size. + * 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_invalid_utf (with error bit) is returned on failure to read/process a UTF-8 character. + * f_reallocation_error (with error bit) on reallocation error. + * f_invalid_parameter (with error bit) if a parameter is invalid. + */ #ifndef _di_fl_fss_basic_list_content_write_ - /** - * write an fss-0002 content. - */ - extern f_return_status fl_fss_basic_list_content_write(const f_string_dynamic content, f_string_location *input, f_string_dynamic *buffer); + extern f_return_status fl_fss_basic_list_content_write(const f_string_dynamic content, f_string_location *location, f_string_dynamic *buffer); #endif // _di_fl_fss_basic_list_content_write_ #ifdef __cplusplus diff --git a/level_1/fl_fss/c/fss_extended.c b/level_1/fl_fss/c/fss_extended.c index 25ccedc..1aaed28 100644 --- a/level_1/fl_fss/c/fss_extended.c +++ b/level_1/fl_fss/c/fss_extended.c @@ -5,15 +5,15 @@ extern "C" { #endif #ifndef _di_fl_fss_extended_object_read_ - f_return_status fl_fss_extended_object_read(f_string_dynamic *buffer, f_string_location *input, f_fss_object *found) { + f_return_status fl_fss_extended_object_read(f_string_dynamic *buffer, f_string_location *location, f_fss_object *found) { #ifndef _di_level_1_parameter_checking_ if (buffer == 0) return f_status_set_error(f_invalid_parameter); - if (input == 0) return f_status_set_error(f_invalid_parameter); + if (location == 0) return f_status_set_error(f_invalid_parameter); if (found == 0) return f_status_set_error(f_invalid_parameter); - if (input->start < 0) return f_status_set_error(f_invalid_parameter); - if (input->stop < input->start) return f_status_set_error(f_invalid_parameter); + if (location->start < 0) return f_status_set_error(f_invalid_parameter); + if (location->stop < location->start) return f_status_set_error(f_invalid_parameter); if (buffer->used <= 0) return f_status_set_error(f_invalid_parameter); - if (input->start >= buffer->used) return f_status_set_error(f_invalid_parameter); + if (location->start >= buffer->used) return f_status_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ f_status status = f_none; @@ -21,12 +21,12 @@ extern "C" { // delimits must only be applied once a valid object is found f_string_lengths delimits = f_string_lengths_initialize; - fl_fss_skip_past_whitespace(*buffer, input); - fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) + fl_fss_skip_past_whitespace(*buffer, location); + fl_macro_fss_object_return_on_overflow((*buffer), (*location), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) // return found nothing if this line only contains whitespace and delimit placeholders - if (buffer->string[input->start] == f_fss_extended_close) { - status = fl_fss_increment_buffer(*buffer, input, 1); + if (buffer->string[location->start] == f_fss_extended_close) { + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; return fl_fss_found_no_object; @@ -37,13 +37,13 @@ extern "C" { f_bool has_delimit = f_false; // begin the search - found->start = input->start; + found->start = location->start; // ignore all comment lines - if (buffer->string[input->start] == f_fss_comment) { - fl_macro_fss_object_seek_till_newline((*buffer), (*input), delimits, f_no_data_on_eos, f_no_data_on_stop) + if (buffer->string[location->start] == f_fss_comment) { + fl_macro_fss_object_seek_till_newline((*buffer), (*location), delimits, f_no_data_on_eos, f_no_data_on_stop) - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; return fl_fss_found_no_object; @@ -53,43 +53,53 @@ extern "C" { int8_t quoted = f_string_eos; // identify where the object begins - if (buffer->string[input->start] == f_fss_delimit_slash) { - f_string_length last_slash = input->start; + if (buffer->string[location->start] == f_fss_delimit_slash) { + f_string_length last_slash = location->start; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; - while (input->start <= input->stop && input->start < buffer->used) { - if (buffer->string[input->start] == f_fss_delimit_placeholder) { - status = fl_fss_increment_buffer(*buffer, input, 1); + while (location->start <= location->stop && location->start < buffer->used) { + if (buffer->string[location->start] == f_fss_delimit_placeholder) { + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; continue; } - else if ((status = fl_fss_is_graph(*buffer, *input)) == f_false) { - found->stop = input->start - 1; + else if ((status = fl_fss_is_graph(*buffer, *location)) == f_false) { + found->stop = location->start - 1; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; return fl_fss_found_object; } else if (f_status_is_error(status)) { + f_status status2 = f_status_set_fine(status); + + if (status2 == f_failure) { + return f_status_set_error(f_invalid_utf); + } + + if (status2 == f_failure) { + return f_status_set_error(f_incomplete_utf); + } + return status; } - else if (buffer->string[input->start] != f_fss_delimit_slash) { + else if (buffer->string[location->start] != f_fss_delimit_slash) { break; } - last_slash = input->start; + last_slash = location->start; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } // while - fl_macro_fss_object_delimited_return_on_overflow((*buffer), (*input), (*found), delimits, f_none_on_eos, f_none_on_stop) + fl_macro_fss_object_delimited_return_on_overflow((*buffer), (*location), (*found), delimits, f_none_on_eos, f_none_on_stop) - if (buffer->string[input->start] == f_fss_delimit_single_quote || buffer->string[input->start] == f_fss_delimit_double_quote) { + if (buffer->string[location->start] == f_fss_delimit_single_quote || buffer->string[location->start] == f_fss_delimit_double_quote) { if (delimits.used >= delimits.size) { f_status allocation_status = f_none; @@ -104,44 +114,44 @@ extern "C" { delimits.array[delimits.used] = last_slash; delimits.used++; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } } - else if (buffer->string[input->start] == f_fss_delimit_single_quote || buffer->string[input->start] == f_fss_delimit_double_quote) { - quoted = buffer->string[input->start]; + else if (buffer->string[location->start] == f_fss_delimit_single_quote || buffer->string[location->start] == f_fss_delimit_double_quote) { + quoted = buffer->string[location->start]; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; - found->start = input->start; + found->start = location->start; } // identify where the object ends if (quoted == f_string_eos) { status = f_none; - while (buffer->string[input->start] == f_fss_delimit_placeholder || (status = fl_fss_is_graph(*buffer, *input)) == f_true) { - status = fl_fss_increment_buffer(*buffer, input, 1); + while (buffer->string[location->start] == f_fss_delimit_placeholder || (status = fl_fss_is_graph(*buffer, *location)) == f_true) { + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; - fl_macro_fss_object_delimited_return_on_overflow((*buffer), (*input), (*found), delimits, f_none_on_eos, f_none_on_stop) + fl_macro_fss_object_delimited_return_on_overflow((*buffer), (*location), (*found), delimits, f_none_on_eos, f_none_on_stop) } // while if (f_status_is_error(status)) return status; - if ((status = fl_fss_is_space(*buffer, *input)) == f_true) { - found->stop = input->start - 1; + if ((status = fl_fss_is_space(*buffer, *location)) == f_true) { + found->stop = location->start - 1; fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); - if (buffer->string[input->start] == f_string_eol) { - status = fl_fss_increment_buffer(*buffer, input, 1); + if (buffer->string[location->start] == f_string_eol) { + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; return fl_fss_found_object_no_content; } - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; return fl_fss_found_object; @@ -151,37 +161,37 @@ extern "C" { } } else { - while (input->start <= input->stop && input->start < buffer->used) { - if (buffer->string[input->start] == f_fss_delimit_slash) { - f_string_length first_slash = input->start; + while (location->start <= location->stop && location->start < buffer->used) { + if (buffer->string[location->start] == f_fss_delimit_slash) { + f_string_length first_slash = location->start; f_string_length slash_count = 1; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; - while (input->start <= input->stop && input->start < buffer->used) { - if (buffer->string[input->start] == f_fss_delimit_placeholder) { - status = fl_fss_increment_buffer(*buffer, input, 1); + while (location->start <= location->stop && location->start < buffer->used) { + if (buffer->string[location->start] == f_fss_delimit_placeholder) { + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; continue; } - else if (buffer->string[input->start] != f_fss_delimit_slash) { + else if (buffer->string[location->start] != f_fss_delimit_slash) { break; } slash_count++; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } // while - fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), delimits, f_status_is_warning(f_unterminated_group_on_eos), f_status_is_warning(f_unterminated_group_on_stop)) + fl_macro_fss_object_return_on_overflow((*buffer), (*location), (*found), delimits, f_status_is_warning(f_unterminated_group_on_eos), f_status_is_warning(f_unterminated_group_on_stop)) - if (buffer->string[input->start] == quoted) { - f_string_length location = input->start; + if (buffer->string[location->start] == quoted) { + f_string_length length = location->start; - input->start = first_slash; + location->start = first_slash; if (delimits.used + (slash_count / 2) >= delimits.size) { f_status allocation_status = f_none; @@ -196,46 +206,56 @@ extern "C" { if (slash_count % 2 == 0) { while (slash_count > 0) { - if (buffer->string[input->start] == f_fss_delimit_slash) { + if (buffer->string[location->start] == f_fss_delimit_slash) { if (slash_count % 2 != 0) { - delimits.array[delimits.used] = input->start; + delimits.array[delimits.used] = location->start; delimits.used++; } slash_count--; } - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } // while - input->start = location + 1; + location->start = length + 1; - fl_macro_fss_skip_past_delimit_placeholders((*buffer), (*input)) - fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), delimits, f_status_is_warning(f_unterminated_group_on_eos), f_status_is_warning(f_unterminated_group_on_stop)) + fl_macro_fss_skip_past_delimit_placeholders((*buffer), (*location)) + fl_macro_fss_object_return_on_overflow((*buffer), (*location), (*found), delimits, f_status_is_warning(f_unterminated_group_on_eos), f_status_is_warning(f_unterminated_group_on_stop)) - if ((status = fl_fss_is_graph(*buffer, *input)) == f_true) { - while (input->start < buffer->used && input->start <= input->stop && buffer->string[input->start] != f_string_eol) { - status = fl_fss_increment_buffer(*buffer, input, 1); + if ((status = fl_fss_is_graph(*buffer, *location)) == f_true) { + while (location->start < buffer->used && location->start <= location->stop && buffer->string[location->start] != f_string_eol) { + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } // while - fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) + fl_macro_fss_object_return_on_overflow((*buffer), (*location), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; return fl_fss_found_no_object; } else if (f_status_is_error(status)) { + f_status status2 = f_status_set_fine(status); + + if (status2 == f_failure) { + return f_status_set_error(f_invalid_utf); + } + + if (status2 == f_failure) { + return f_status_set_error(f_incomplete_utf); + } + return status; } - else if (buffer->string[input->start] == f_string_eol) { + else if (buffer->string[location->start] == f_string_eol) { fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); - found->stop = location - 1; + found->stop = length - 1; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; return fl_fss_found_object_no_content; @@ -243,9 +263,9 @@ extern "C" { fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); - found->stop = location - 1; + found->stop = length - 1; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; return fl_fss_found_object; @@ -263,42 +283,42 @@ extern "C" { } while (slash_count > 0) { - if (buffer->string[input->start] == f_fss_delimit_slash) { + if (buffer->string[location->start] == f_fss_delimit_slash) { if (slash_count % 2 != 0) { - delimits.array[delimits.used] = input->start; + delimits.array[delimits.used] = location->start; delimits.used++; } slash_count--; } - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } // while - input->start = location; + location->start = length; } } } - else if (buffer->string[input->start] == quoted) { - found->stop = input->start - 1; + else if (buffer->string[location->start] == quoted) { + found->stop = location->start - 1; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; - while (input->start <= input->stop && input->start < buffer->used) { - if (buffer->string[input->start] == f_string_eol) { + while (location->start <= location->stop && location->start < buffer->used) { + if (buffer->string[location->start] == f_string_eol) { fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; return fl_fss_found_object_no_content; } - else if ((status = fl_fss_is_space(*buffer, *input)) == f_true) { + else if ((status = fl_fss_is_space(*buffer, *location)) == f_true) { fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; return fl_fss_found_object; @@ -306,49 +326,49 @@ extern "C" { else if (f_status_is_error(status)) { return status; } - else if (buffer->string[input->start] != f_fss_delimit_placeholder) { - while (input->start < buffer->used && input->start <= input->stop && buffer->string[input->start] != f_string_eol) { - status = fl_fss_increment_buffer(*buffer, input, 1); + else if (buffer->string[location->start] != f_fss_delimit_placeholder) { + while (location->start < buffer->used && location->start <= location->stop && buffer->string[location->start] != f_string_eol) { + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } // while - fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) + fl_macro_fss_object_return_on_overflow((*buffer), (*location), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; return fl_fss_found_no_object; } - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } // while - fl_macro_fss_object_delimited_return_on_overflow((*buffer), (*input), (*found), delimits, f_none_on_eos, f_none_on_stop) + fl_macro_fss_object_delimited_return_on_overflow((*buffer), (*location), (*found), delimits, f_none_on_eos, f_none_on_stop) } - else if (buffer->string[input->start] == f_string_eol) { - status = fl_fss_increment_buffer(*buffer, input, 1); + else if (buffer->string[location->start] == f_string_eol) { + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; return fl_fss_found_no_object; } - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } // while - fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), delimits, f_status_is_warning(f_unterminated_group_on_eos), f_status_is_warning(f_unterminated_group_on_stop)) + fl_macro_fss_object_return_on_overflow((*buffer), (*location), (*found), delimits, f_status_is_warning(f_unterminated_group_on_eos), f_status_is_warning(f_unterminated_group_on_stop)) } // seek to the end of the line when no valid object is found - while (input->start < buffer->used && input->start <= input->stop && buffer->string[input->start] != f_string_eol) { - status = fl_fss_increment_buffer(*buffer, input, 1); + while (location->start < buffer->used && location->start <= location->stop && buffer->string[location->start] != f_string_eol) { + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } // while - fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) + fl_macro_fss_object_return_on_overflow((*buffer), (*location), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; return fl_fss_found_no_object; @@ -356,15 +376,15 @@ extern "C" { #endif // _di_fl_fss_extended_object_read_ #ifndef _di_fl_fss_extended_content_read_ - f_return_status fl_fss_extended_content_read(f_string_dynamic *buffer, f_string_location *input, f_fss_content *found) { + f_return_status fl_fss_extended_content_read(f_string_dynamic *buffer, f_string_location *location, f_fss_content *found) { #ifndef _di_level_1_parameter_checking_ if (buffer == 0) return f_status_set_error(f_invalid_parameter); - if (input == 0) return f_status_set_error(f_invalid_parameter); + if (location == 0) return f_status_set_error(f_invalid_parameter); if (found == 0) return f_status_set_error(f_invalid_parameter); - if (input->start < 0) return f_status_set_error(f_invalid_parameter); - if (input->stop < input->start) return f_status_set_error(f_invalid_parameter); + if (location->start < 0) return f_status_set_error(f_invalid_parameter); + if (location->stop < location->start) return f_status_set_error(f_invalid_parameter); if (buffer->used <= 0) return f_status_set_error(f_invalid_parameter); - if (input->start >= buffer->used) return f_status_set_error(f_invalid_parameter); + if (location->start >= buffer->used) return f_status_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ f_status status = f_none; @@ -372,12 +392,12 @@ extern "C" { // delimits must only be applied once a valid object is found f_string_lengths delimits = f_string_lengths_initialize; - fl_fss_skip_past_whitespace(*buffer, input); - fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), delimits, f_none_on_eos, f_none_on_stop) + fl_fss_skip_past_whitespace(*buffer, location); + fl_macro_fss_content_return_on_overflow((*buffer), (*location), (*found), delimits, f_none_on_eos, f_none_on_stop) // return found nothing if this line only contains whitespace and delimit placeholders - if (buffer->string[input->start] == f_fss_extended_close) { - status = fl_fss_increment_buffer(*buffer, input, 1); + if (buffer->string[location->start] == f_fss_extended_close) { + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; return fl_fss_found_no_content; @@ -388,10 +408,10 @@ extern "C" { f_bool continue_main_loop = f_false; - f_string_length location = 0; + f_string_length length = 0; f_array_length already_used = found->used; - while (input->start <= input->stop && input->start < buffer->used) { + while (location->start <= location->stop && location->start < buffer->used) { quoted = f_string_eos; if (found->used >= found->size) { @@ -406,33 +426,33 @@ extern "C" { } // begin the search - found->array[found->used].start = input->start; + found->array[found->used].start = location->start; found->array[found->used].stop = 0; // identify where the content begins - if (buffer->string[input->start] == f_fss_delimit_slash) { - f_string_length last_slash = input->start; + if (buffer->string[location->start] == f_fss_delimit_slash) { + f_string_length last_slash = location->start; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; - while (input->start <= input->stop && input->start < buffer->used) { - if (buffer->string[input->start] == f_fss_delimit_placeholder) { - status = fl_fss_increment_buffer(*buffer, input, 1); + while (location->start <= location->stop && location->start < buffer->used) { + if (buffer->string[location->start] == f_fss_delimit_placeholder) { + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; continue; } - else if ((status = fl_fss_is_graph(*buffer, *input)) == f_false) { - found->array[found->used].stop = input->start - 1; + else if ((status = fl_fss_is_graph(*buffer, *location)) == f_false) { + found->array[found->used].stop = location->start - 1; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; found->used++; - if (buffer->string[input->start] == f_string_eol) { + if (buffer->string[location->start] == f_string_eol) { fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); return fl_fss_found_content; @@ -442,15 +462,25 @@ extern "C" { break; } else if (f_status_is_error(status)) { + f_status status2 = f_status_set_fine(status); + + if (status2 == f_failure) { + return f_status_set_error(f_invalid_utf); + } + + if (status2 == f_failure) { + return f_status_set_error(f_incomplete_utf); + } + return status; } - else if (buffer->string[input->start] != f_fss_delimit_slash) { + else if (buffer->string[location->start] != f_fss_delimit_slash) { break; } - last_slash = input->start; + last_slash = location->start; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } // while @@ -459,9 +489,9 @@ extern "C" { continue; } - fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*input), (*found), delimits, f_none_on_eos, f_none_on_stop) + fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*location), (*found), delimits, f_none_on_eos, f_none_on_stop) - if (buffer->string[input->start] == f_fss_delimit_single_quote || buffer->string[input->start] == f_fss_delimit_double_quote) { + if (buffer->string[location->start] == f_fss_delimit_single_quote || buffer->string[location->start] == f_fss_delimit_double_quote) { if (delimits.used >= delimits.size) { f_status allocation_status = f_none; @@ -476,45 +506,45 @@ extern "C" { delimits.array[delimits.used] = last_slash; delimits.used++; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } } - else if (buffer->string[input->start] == f_fss_delimit_single_quote || buffer->string[input->start] == f_fss_delimit_double_quote) { - quoted = buffer->string[input->start]; + else if (buffer->string[location->start] == f_fss_delimit_single_quote || buffer->string[location->start] == f_fss_delimit_double_quote) { + quoted = buffer->string[location->start]; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; - found->array[found->used].start = input->start; + found->array[found->used].start = location->start; } // identify where the content ends if (quoted == f_string_eos) { status = f_none; - while (buffer->string[input->start] == f_fss_delimit_placeholder || (status = fl_fss_is_graph(*buffer, *input)) == f_true) { - status = fl_fss_increment_buffer(*buffer, input, 1); + while (buffer->string[location->start] == f_fss_delimit_placeholder || (status = fl_fss_is_graph(*buffer, *location)) == f_true) { + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; - fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*input), (*found), delimits, f_none_on_eos, f_none_on_stop) + fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*location), (*found), delimits, f_none_on_eos, f_none_on_stop) } // while if (f_status_is_error(status)) return status; - if ((status = fl_fss_is_space(*buffer, *input)) == f_true) { - found->array[found->used].stop = input->start - 1; + if ((status = fl_fss_is_space(*buffer, *location)) == f_true) { + found->array[found->used].stop = location->start - 1; found->used++; - if (buffer->string[input->start] == f_string_eol) { + if (buffer->string[location->start] == f_string_eol) { fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; return fl_fss_found_content; } - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; continue; @@ -524,36 +554,36 @@ extern "C" { } } else { - while (input->start <= input->stop && input->start < buffer->used) { - if (buffer->string[input->start] == f_fss_delimit_slash) { - f_string_length first_slash = input->start; + while (location->start <= location->stop && location->start < buffer->used) { + if (buffer->string[location->start] == f_fss_delimit_slash) { + f_string_length first_slash = location->start; f_string_length slash_count = 1; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; - while (input->start <= input->stop && input->start < buffer->used) { - if (buffer->string[input->start] == f_fss_delimit_placeholder) { - status = fl_fss_increment_buffer(*buffer, input, 1); + while (location->start <= location->stop && location->start < buffer->used) { + if (buffer->string[location->start] == f_fss_delimit_placeholder) { + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; continue; } - else if (buffer->string[input->start] != f_fss_delimit_slash) { + else if (buffer->string[location->start] != f_fss_delimit_slash) { break; } slash_count++; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } // while - fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), delimits, f_status_is_warning(f_unterminated_group_on_eos), f_status_is_warning(f_unterminated_group_on_stop)) + fl_macro_fss_content_return_on_overflow((*buffer), (*location), (*found), delimits, f_status_is_warning(f_unterminated_group_on_eos), f_status_is_warning(f_unterminated_group_on_stop)) - if (buffer->string[input->start] == quoted) { - location = input->start; - input->start = first_slash; + if (buffer->string[location->start] == quoted) { + length = location->start; + location->start = first_slash; if (slash_count % 2 == 0) { if (delimits.used + (slash_count / 2) >= delimits.size) { @@ -568,46 +598,56 @@ extern "C" { } while (slash_count > 0) { - if (buffer->string[input->start] == f_fss_delimit_slash) { + if (buffer->string[location->start] == f_fss_delimit_slash) { if (slash_count % 2 != 0) { - delimits.array[delimits.used] = input->start; + delimits.array[delimits.used] = location->start; delimits.used++; } slash_count--; } - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } // while - input->start = location + 1; + location->start = length + 1; - fl_macro_fss_skip_past_delimit_placeholders((*buffer), (*input)) - fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*input), (*found), delimits, f_none_on_eos, f_none_on_stop) + fl_macro_fss_skip_past_delimit_placeholders((*buffer), (*location)) + fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*location), (*found), delimits, f_none_on_eos, f_none_on_stop) - if ((status = fl_fss_is_graph(*buffer, *input)) == f_true) { - while (input->start < buffer->used && input->start <= input->stop && buffer->string[input->start] != f_string_eol) { - status = fl_fss_increment_buffer(*buffer, input, 1); + if ((status = fl_fss_is_graph(*buffer, *location)) == f_true) { + while (location->start < buffer->used && location->start <= location->stop && buffer->string[location->start] != f_string_eol) { + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } // while - fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), delimits, f_status_is_warning(f_unterminated_group_on_eos), f_status_is_warning(f_unterminated_group_on_stop)) + fl_macro_fss_content_return_on_overflow((*buffer), (*location), (*found), delimits, f_status_is_warning(f_unterminated_group_on_eos), f_status_is_warning(f_unterminated_group_on_stop)) - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; return f_status_is_warning(f_unterminated_group); } else if (f_status_is_error(status)) { + f_status status2 = f_status_set_fine(status); + + if (status2 == f_failure) { + return f_status_set_error(f_invalid_utf); + } + + if (status2 == f_failure) { + return f_status_set_error(f_incomplete_utf); + } + return status; } - else if (buffer->string[input->start] == f_string_eol) { + else if (buffer->string[location->start] == f_string_eol) { fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); - found->array[found->used].stop = location - 1; + found->array[found->used].stop = length - 1; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; found->used++; @@ -615,9 +655,9 @@ extern "C" { return fl_fss_found_content; } - found->array[found->used].stop = location - 1; + found->array[found->used].stop = length - 1; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; found->used++; @@ -636,42 +676,42 @@ extern "C" { } while (slash_count > 0) { - if (buffer->string[input->start] == f_fss_delimit_slash) { + if (buffer->string[location->start] == f_fss_delimit_slash) { if (slash_count % 2 != 0) { - delimits.array[delimits.used] = input->start; + delimits.array[delimits.used] = location->start; delimits.used++; } slash_count--; } - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } // while - input->start = location; + location->start = length; } } } - else if (buffer->string[input->start] == quoted) { - found->array[found->used].stop = input->start - 1; - status = fl_fss_increment_buffer(*buffer, input, 1); + else if (buffer->string[location->start] == quoted) { + found->array[found->used].stop = location->start - 1; + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; - while (input->start <= input->stop && input->start < buffer->used) { - if (buffer->string[input->start] == f_string_eol) { + while (location->start <= location->stop && location->start < buffer->used) { + if (buffer->string[location->start] == f_string_eol) { fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; found->used++; return fl_fss_found_content; } - else if ((status = fl_fss_is_space(*buffer, *input)) == f_true) { - status = fl_fss_increment_buffer(*buffer, input, 1); + else if ((status = fl_fss_is_space(*buffer, *location)) == f_true) { + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; found->used++; @@ -681,21 +721,21 @@ extern "C" { else if (f_status_is_error(status)) { return status; } - else if (buffer->string[input->start] != f_fss_delimit_placeholder) { - while (input->start < buffer->used && input->start <= input->stop && buffer->string[input->start] != f_string_eol) { - status = fl_fss_increment_buffer(*buffer, input, 1); + else if (buffer->string[location->start] != f_fss_delimit_placeholder) { + while (location->start < buffer->used && location->start <= location->stop && buffer->string[location->start] != f_string_eol) { + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } // while - fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), delimits, f_status_is_warning(f_unterminated_group_on_eos), f_status_is_warning(f_unterminated_group_on_stop)) + fl_macro_fss_content_return_on_overflow((*buffer), (*location), (*found), delimits, f_status_is_warning(f_unterminated_group_on_eos), f_status_is_warning(f_unterminated_group_on_stop)) - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; return f_status_is_warning(f_unterminated_group); } - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } // while @@ -703,12 +743,12 @@ extern "C" { break; } - fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*input), (*found), delimits, f_none_on_eos, f_none_on_stop) + fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*location), (*found), delimits, f_none_on_eos, f_none_on_stop) } - else if (buffer->string[input->start] == f_string_eol) { + else if (buffer->string[location->start] == f_string_eol) { if (found->used == already_used) { - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; return fl_fss_found_no_content; @@ -716,9 +756,9 @@ extern "C" { else { fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); - found->array[found->used].stop = input->start - 1; + found->array[found->used].stop = location->start - 1; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; found->used++; @@ -727,11 +767,11 @@ extern "C" { } } - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } // while - fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), delimits, f_status_is_warning(f_unterminated_group_on_eos), f_status_is_warning(f_unterminated_group_on_stop)) + fl_macro_fss_content_return_on_overflow((*buffer), (*location), (*found), delimits, f_status_is_warning(f_unterminated_group_on_eos), f_status_is_warning(f_unterminated_group_on_stop)) } if (continue_main_loop) { @@ -742,18 +782,18 @@ extern "C" { break; } // while - fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*input), (*found), delimits, f_none_on_eos, f_none_on_stop) + fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*location), (*found), delimits, f_none_on_eos, f_none_on_stop) // seek to the end of the line when no valid content is found - while (input->start < buffer->used && input->start <= input->stop && buffer->string[input->start] != f_string_eol) { - status = fl_fss_increment_buffer(*buffer, input, 1); + while (location->start < buffer->used && location->start <= location->stop && buffer->string[location->start] != f_string_eol) { + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } // while - fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*input), (*found), delimits, f_none_on_eos, f_none_on_stop) + fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*location), (*found), delimits, f_none_on_eos, f_none_on_stop) if (found->used == already_used) { - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; return fl_fss_found_no_content; @@ -761,7 +801,7 @@ extern "C" { fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; return fl_fss_found_content; @@ -769,7 +809,7 @@ extern "C" { #endif // _di_fl_fss_extended_content_read_ #ifndef _di_fl_fss_extended_object_write_ - f_return_status fl_fss_extended_object_write(const f_string_dynamic object, f_string_location *input, f_string_dynamic *buffer) { + f_return_status fl_fss_extended_object_write(const f_string_dynamic object, f_string_location *location, f_string_dynamic *buffer) { #ifndef _di_level_1_parameter_checking_ if (buffer == 0) return f_status_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ @@ -781,19 +821,19 @@ extern "C" { f_string_length start_position = f_string_initialize; f_string_length pre_allocate_size = 0; - fl_macro_fss_skip_past_delimit_placeholders(object, (*input)) + fl_macro_fss_skip_past_delimit_placeholders(object, (*location)) - if (input->start > input->stop) { + if (location->start > location->stop) { return f_no_data_on_stop; } - else if (input->start >= object.used) { + else if (location->start >= object.used) { return f_no_data_on_eos; } - start_position = input->start; + start_position = location->start; // add an additional 3 to ensure that there is room for the start and stop quotes or a slash delimit and the object open character. - pre_allocate_size = buffer->used + (input->stop - input->start) + 3 + f_fss_default_allocation_step_string; + pre_allocate_size = buffer->used + (location->stop - location->start) + 3 + f_fss_default_allocation_step_string; if (pre_allocate_size > buffer->size) { f_macro_string_dynamic_resize(status, (*buffer), pre_allocate_size); @@ -804,25 +844,25 @@ extern "C" { buffer_position.start = buffer->used; buffer_position.stop = buffer->used; - if (object.string[input->start] == f_fss_delimit_slash) { - while (input->start <= input->stop && input->start < object.used) { - if (object.string[input->start] == f_fss_delimit_placeholder) { - status = fl_fss_increment_buffer(*buffer, input, 1); + if (object.string[location->start] == f_fss_delimit_slash) { + while (location->start <= location->stop && location->start < object.used) { + if (object.string[location->start] == f_fss_delimit_placeholder) { + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; continue; - } else if (object.string[input->start] != f_fss_delimit_slash) { + } else if (object.string[location->start] != f_fss_delimit_slash) { break; } - buffer->string[buffer_position.stop] = object.string[input->start]; + buffer->string[buffer_position.stop] = object.string[location->start]; buffer_position.stop++; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } // while - if (object.string[input->start] == f_fss_delimit_single_quote || object.string[input->start] == f_fss_delimit_double_quote) { + if (object.string[location->start] == f_fss_delimit_single_quote || object.string[location->start] == f_fss_delimit_double_quote) { pre_allocate_size++; if (pre_allocate_size > buffer->size) { @@ -832,14 +872,14 @@ extern "C" { } buffer->string[buffer_position.stop] = f_fss_delimit_slash; - buffer->string[buffer_position.stop + 1] = object.string[input->start]; + buffer->string[buffer_position.stop + 1] = object.string[location->start]; buffer_position.stop += 2; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } } - else if (object.string[input->start] == f_fss_delimit_single_quote || object.string[input->start] == f_fss_delimit_double_quote) { + else if (object.string[location->start] == f_fss_delimit_single_quote || object.string[location->start] == f_fss_delimit_double_quote) { pre_allocate_size++; if (pre_allocate_size > buffer->size) { @@ -849,24 +889,24 @@ extern "C" { } buffer->string[buffer_position.stop] = f_fss_delimit_slash; - buffer->string[buffer_position.stop + 1] = object.string[input->start]; + buffer->string[buffer_position.stop + 1] = object.string[location->start]; buffer_position.stop += 2; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } - else if (object.string[input->start] == f_fss_comment) { + else if (object.string[location->start] == f_fss_comment) { quoted = f_true; } - while (input->start <= input->stop && input->start < object.used) { - if (object.string[input->start] == f_fss_delimit_placeholder) { - status = fl_fss_increment_buffer(*buffer, input, 1); + while (location->start <= location->stop && location->start < object.used) { + if (object.string[location->start] == f_fss_delimit_placeholder) { + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; continue; } - else if (object.string[input->start] == f_string_eol) { + else if (object.string[location->start] == f_string_eol) { if (quoted) { buffer->string[buffer_position.stop] = f_fss_delimit_double_quote; buffer_position.stop++; @@ -877,19 +917,19 @@ extern "C" { return f_none_on_eol; } - else if ((status = fl_fss_is_space(*buffer, *input)) == f_true || quoted) { - f_string_length first_space = input->start; + else if ((status = fl_fss_is_space(*buffer, *location)) == f_true || quoted) { + f_string_length first_space = location->start; if (!quoted) { - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; - while (input->start <= input->stop && input->start < object.used && isspace(object.string[input->start])) { - status = fl_fss_increment_buffer(*buffer, input, 1); + while (location->start <= location->stop && location->start < object.used && isspace(object.string[location->start])) { + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } // while - if (input->start > input->stop || input->start >= object.used) { + if (location->start > location->stop || location->start >= object.used) { buffer->string[first_space] = f_fss_extended_open; buffer->used = buffer_position.stop + 1; break; @@ -905,20 +945,20 @@ extern "C" { } // restart the loop searching for f_fss_delimit_double_quote. - input->start = start_position; + location->start = start_position; buffer_position.stop = buffer_position.start; buffer->string[buffer_position.stop] = f_fss_delimit_double_quote; buffer_position.stop++; - while (input->start <= input->stop && input->start < object.used) { - if (object.string[input->start] == f_fss_delimit_placeholder) { - status = fl_fss_increment_buffer(*buffer, input, 1); + while (location->start <= location->stop && location->start < object.used) { + if (object.string[location->start] == f_fss_delimit_placeholder) { + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; continue; } - else if (object.string[input->start] == f_fss_delimit_double_quote) { + else if (object.string[location->start] == f_fss_delimit_double_quote) { pre_allocate_size++; if (pre_allocate_size > buffer->size) { @@ -930,25 +970,25 @@ extern "C" { buffer->string[buffer_position.stop] = f_fss_delimit_slash; buffer_position.stop++; } - else if (object.string[input->start] == f_fss_delimit_slash) { + else if (object.string[location->start] == f_fss_delimit_slash) { f_string_length slash_count = 0; do { - buffer->string[buffer_position.stop] = object.string[input->start]; + buffer->string[buffer_position.stop] = object.string[location->start]; buffer_position.stop++; slash_count++; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; - fl_macro_fss_skip_past_delimit_placeholders(object, (*input)); + fl_macro_fss_skip_past_delimit_placeholders(object, (*location)); - if (input->start > input->stop || input->start >= object.used) { + if (location->start > location->stop || location->start >= object.used) { break; } - if (object.string[input->start] == f_fss_delimit_double_quote) { + if (object.string[location->start] == f_fss_delimit_double_quote) { pre_allocate_size += slash_count; if (pre_allocate_size > buffer->size) { @@ -959,7 +999,7 @@ extern "C" { break; } - else if (object.string[input->start] != f_fss_delimit_slash) { + else if (object.string[location->start] != f_fss_delimit_slash) { slash_count = 0; break; } @@ -973,7 +1013,7 @@ extern "C" { continue; } - else if (object.string[input->start] == f_string_eol) { + else if (object.string[location->start] == f_string_eol) { buffer->string[buffer_position.stop] = f_fss_delimit_double_quote; buffer_position.stop++; @@ -983,9 +1023,9 @@ extern "C" { return f_none_on_eol; } - buffer->string[buffer_position.stop] = object.string[input->start]; + buffer->string[buffer_position.stop] = object.string[location->start]; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; buffer_position.stop++; @@ -1000,9 +1040,9 @@ extern "C" { return status; } - buffer->string[buffer_position.stop] = object.string[input->start]; + buffer->string[buffer_position.stop] = object.string[location->start]; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; buffer_position.stop++; @@ -1013,10 +1053,10 @@ extern "C" { buffer->used = buffer_position.stop + 1; } - if (input->start > input->stop) { + if (location->start > location->stop) { return f_none_on_stop; } - else if (input->start >= object.used) { + else if (location->start >= object.used) { return f_none_on_eos; } @@ -1025,7 +1065,7 @@ extern "C" { #endif // _di_fl_fss_extended_object_write_ #ifndef _di_fl_fss_extended_content_write_ - f_return_status fl_fss_extended_content_write(const f_string_dynamic content, f_string_location *input, f_string_dynamic *buffer) { + f_return_status fl_fss_extended_content_write(const f_string_dynamic content, f_string_location *location, f_string_dynamic *buffer) { #ifndef _di_level_1_parameter_checking_ if (buffer == 0) return f_status_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ @@ -1049,56 +1089,56 @@ extern "C" { if (f_status_is_error(status)) return status; } - fl_macro_fss_skip_past_delimit_placeholders(content, (*input)) + fl_macro_fss_skip_past_delimit_placeholders(content, (*location)) - if (input->start > input->stop) { + if (location->start > location->stop) { return f_no_data_on_stop; } - else if (input->start >= content.used) { + else if (location->start >= content.used) { return f_no_data_on_eos; } - start_position = input->start; + start_position = location->start; // if this first slash is followed by a quote, then that quote must be delimited. - if (content.string[input->start] == f_fss_delimit_slash) { + if (content.string[location->start] == f_fss_delimit_slash) { buffer->string[buffer_position.stop] = f_fss_delimit_slash; buffer_position.stop++; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; - while (input->start <= input->stop && input->start < content.used) { - if (content.string[input->start] == f_fss_delimit_placeholder) { - status = fl_fss_increment_buffer(*buffer, input, 1); + while (location->start <= location->stop && location->start < content.used) { + if (content.string[location->start] == f_fss_delimit_placeholder) { + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; continue; } - if (content.string[input->start] != f_fss_delimit_slash) { + if (content.string[location->start] != f_fss_delimit_slash) { break; } buffer->string[buffer_position.stop] = f_fss_delimit_slash; buffer_position.stop++; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } // while - if (input->start > input->stop) { + if (location->start > location->stop) { buffer->string[buffer_position.stop] = ' '; buffer->used = buffer_position.stop + 1; return f_none_on_stop; } - else if (input->start >= content.used) { + else if (location->start >= content.used) { buffer->string[buffer_position.stop] = ' '; buffer->used = buffer_position.stop + 1; return f_none_on_eos; } - if (content.string[input->start] == f_fss_delimit_single_quote || content.string[input->start] == f_fss_delimit_double_quote) { + if (content.string[location->start] == f_fss_delimit_single_quote || content.string[location->start] == f_fss_delimit_double_quote) { pre_allocate_size++; if (pre_allocate_size > buffer->size) { @@ -1108,14 +1148,14 @@ extern "C" { } buffer->string[buffer_position.stop] = f_fss_delimit_slash; - buffer->string[buffer_position.stop + 1] = content.string[input->start]; + buffer->string[buffer_position.stop + 1] = content.string[location->start]; buffer_position.stop += 2; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } } - else if (content.string[input->start] == f_fss_delimit_single_quote || content.string[input->start] == f_fss_delimit_double_quote) { + else if (content.string[location->start] == f_fss_delimit_single_quote || content.string[location->start] == f_fss_delimit_double_quote) { pre_allocate_size++; if (pre_allocate_size > buffer->size) { @@ -1125,21 +1165,21 @@ extern "C" { } buffer->string[buffer_position.stop] = f_fss_delimit_slash; - buffer->string[buffer_position.stop + 1] = content.string[input->start]; + buffer->string[buffer_position.stop + 1] = content.string[location->start]; buffer_position.stop += 2; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } - while (input->start <= input->stop && input->start < content.used) { - if (content.string[input->start] == f_string_eol) { + while (location->start <= location->stop && location->start < content.used) { + if (content.string[location->start] == f_string_eol) { buffer->string[buffer_position.stop] = ' '; buffer->used = buffer_position.stop + 1; return f_none_on_eol; } - if (content.string[input->start] != f_fss_delimit_placeholder && (status = fl_fss_is_graph(*buffer, *input)) == f_false) { + if (content.string[location->start] != f_fss_delimit_placeholder && (status = fl_fss_is_graph(*buffer, *location)) == f_false) { quoted = f_fss_delimit_double_quote; pre_allocate_size += 2; @@ -1150,7 +1190,7 @@ extern "C" { if (f_status_is_error(status)) return status; } - input->start = start_position; + location->start = start_position; buffer_position.stop = buffer_position.start; buffer->string[buffer_position.stop] = f_fss_delimit_double_quote; buffer_position.stop++; @@ -1160,33 +1200,33 @@ extern "C" { return status; } - buffer->string[buffer_position.stop] = content.string[input->start]; + buffer->string[buffer_position.stop] = content.string[location->start]; buffer_position.stop++; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } // while if (quoted != f_string_eos) { - while (input->start <= input->stop && input->start < content.used) { - if (content.string[input->start] == f_fss_delimit_slash) { + while (location->start <= location->stop && location->start < content.used) { + if (content.string[location->start] == f_fss_delimit_slash) { f_string_length slash_count = 1; buffer->string[buffer_position.stop] = f_fss_delimit_slash; buffer_position.stop++; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; - while (input->start <= input->stop && input->start < content.used) { - if (content.string[input->start] == f_fss_delimit_placeholder) { - status = fl_fss_increment_buffer(*buffer, input, 1); + while (location->start <= location->stop && location->start < content.used) { + if (content.string[location->start] == f_fss_delimit_placeholder) { + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; continue; } - if (content.string[input->start] != f_fss_delimit_slash) { + if (content.string[location->start] != f_fss_delimit_slash) { break; } @@ -1194,11 +1234,11 @@ extern "C" { buffer_position.stop++; slash_count++; - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } // while - if (content.string[input->start] == quoted || input->start > input->stop || input->start >= content.used) { + if (content.string[location->start] == quoted || location->start > location->stop || location->start >= content.used) { pre_allocate_size += slash_count + 1; if (pre_allocate_size > buffer->size) { @@ -1213,7 +1253,7 @@ extern "C" { slash_count--; } // while - if (input->start > input->stop || input->start >= content.used) { + if (location->start > location->stop || location->start >= content.used) { break; } @@ -1222,11 +1262,11 @@ extern "C" { buffer_position.stop += 2; } else { - buffer->string[buffer_position.stop] = content.string[input->start]; + buffer->string[buffer_position.stop] = content.string[location->start]; buffer_position.stop++; } } - else if (content.string[input->start] == quoted) { + else if (content.string[location->start] == quoted) { pre_allocate_size++; if (pre_allocate_size > buffer->size) { @@ -1239,18 +1279,18 @@ extern "C" { buffer->string[buffer_position.stop + 1] = quoted; buffer_position.stop += 2; } - else if (content.string[input->start] == f_string_eol) { + else if (content.string[location->start] == f_string_eol) { buffer->string[buffer_position.stop] = quoted; buffer->string[buffer_position.stop + 1] = ' '; buffer->used = buffer_position.stop + 2; return f_none_on_eol; } - else if (content.string[input->start] != f_fss_delimit_placeholder) { - buffer->string[buffer_position.stop] = content.string[input->start]; + else if (content.string[location->start] != f_fss_delimit_placeholder) { + buffer->string[buffer_position.stop] = content.string[location->start]; buffer_position.stop++; } - status = fl_fss_increment_buffer(*buffer, input, 1); + status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } // while @@ -1261,10 +1301,10 @@ extern "C" { buffer->string[buffer_position.stop] = ' '; buffer->used = buffer_position.stop + 1; - if (input->start > input->stop) { + if (location->start > location->stop) { return f_none_on_stop; } - else if (input->start >= content.used) { + else if (location->start >= content.used) { return f_none_on_eos; } diff --git a/level_1/fl_fss/c/fss_extended.h b/level_1/fl_fss/c/fss_extended.h index 0c77c49..ed168a6 100644 --- a/level_1/fl_fss/c/fss_extended.h +++ b/level_1/fl_fss/c/fss_extended.h @@ -31,32 +31,133 @@ extern "C" { #endif +/** + * Read an fss-0001 object. + * + * This will update the buffer at the given range with any placeholders to unescape any escaped data. + * Calling this more than once on the same buffer range could result in multiple unescaping. + * + * @param buffer + * The buffer to read from. + * This will be updated with delimit placeholders as it is being processed. + * @param location + * 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 set of all locations where a valid object was found. + * + * @return + * fl_fss_found_object on success and object was found (start location is at end of object). + * fl_fss_found_no_object on success and no object was found (start location is after character designating this is not an object). + * f_none_on_stop on success after reaching stopping point (a valid object is not yet confirmed). + * f_none_on_eos on success after reaching the end of the buffer (a valid object is not yet confirmed). + * f_no_data_on_stop no data found after reaching stopping point (essentially only comments are found). + * f_no_data_on_eos no objects found after reaching the end of the buffer (essentially only comments are found). + * f_incomplete_utf_on_stop (with error bit) if the stop location is reached before the complete UTF-8 character can be processed. + * f_incomplete_utf_on_eos (with error bit) if the end of buffer is reached before the complete UTF-8 character can be processed. + * 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_invalid_utf (with error bit) is returned on failure to read/process a UTF-8 character. + * f_reallocation_error (with error bit) on reallocation error. + * f_invalid_parameter (with error bit) if a parameter is invalid. + */ #ifndef _di_fl_fss_extended_object_read_ - /** - * read an fss-0001 object. - */ - extern f_return_status fl_fss_extended_object_read(f_string_dynamic *buffer, f_string_location *input, f_fss_object *found); + extern f_return_status fl_fss_extended_object_read(f_string_dynamic *buffer, f_string_location *location, f_fss_object *found); #endif // _di_fl_fss_extended_object_read_ +/** + * Read an fss-0001 content. + * + * This will update the buffer at the given range with any placeholders to unescape any escaped data. + * Calling this more than once on the same buffer range could result in multiple unescaping. + * + * @param buffer + * The buffer to read from. + * This will be updated with delimit placeholders as it is being processed. + * @param location + * 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 set of all locations where a valid content was found. + * + * @return + * fl_fss_found_content on success and content was found (start location is at end of content). + * fl_fss_found_no_content on success and no content was found (start location is after character designating this is not a content). + * f_none_on_stop on success after reaching stopping point (a valid content is not yet confirmed). + * f_none_on_eos on success after reaching the end of the buffer (a valid content is not yet confirmed). + * f_no_data_on_stop no data found after reaching stopping point (essentially only comments are found). + * f_no_data_on_eos no content found after reaching the end of the buffer (essentially only comments are found). + * f_incomplete_utf_on_stop (with error bit) if the stop location is reached before the complete UTF-8 character can be processed. + * f_incomplete_utf_on_eos (with error bit) if the end of buffer is reached before the complete UTF-8 character can be processed. + * 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_invalid_utf (with error bit) is returned on failure to read/process a UTF-8 character. + * f_reallocation_error (with error bit) on reallocation error. + * f_invalid_parameter (with error bit) if a parameter is invalid. + */ #ifndef _di_fl_fss_extended_content_read_ - /** - * read an fss-0001 content. - */ - extern f_return_status fl_fss_extended_content_read(f_string_dynamic *buffer, f_string_location *input, f_fss_content *found); + extern f_return_status fl_fss_extended_content_read(f_string_dynamic *buffer, f_string_location *location, f_fss_content *found); #endif // _di_fl_fss_extended_content_read_ +/** + * Write an fss-0001 object. + * + * This will write the given string range as a valid object. + * Anything within this range will be escaped as necessary. + * This will stop if EOL is reached. + * + * @param object + * The string to write as (does not stop at NULLS, they are ignored and not written). + * @param location + * The start/stop location within the object string to write as an object. + * @param buffer + * The buffer where the object is written to. + * This will be auto-incremented and must not be a static string. + * + * @return + * f_none on success. + * f_none_on_stop on success after reaching stopping point . + * f_none_on_eos on success after reaching the end of the buffer. + * f_no_data_on_stop no data to write due start location being greater than stop location. + * f_no_data_on_eos no data to write due start location being greater than or equal to buffer size. + * 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_invalid_utf (with error bit) is returned on failure to read/process a UTF-8 character. + * f_reallocation_error (with error bit) on reallocation error. + * f_invalid_parameter (with error bit) if a parameter is invalid. + */ #ifndef _di_fl_fss_extended_object_write_ - /** - * write an fss-0001 object. - */ - extern f_return_status fl_fss_extended_object_write(const f_string_dynamic object, f_string_location *input, f_string_dynamic *buffer); + extern f_return_status fl_fss_extended_object_write(const f_string_dynamic object, f_string_location *location, f_string_dynamic *buffer); #endif // _di_fl_fss_extended_object_write_ +/** + * Write an fss-0001 content. + * + * This will write the given string range as a valid content. + * Anything within this range will be escaped as necessary. + * + * @param content + * The string to write as (does not stop at NULLS, they are ignored and not written). + * @param location + * The start/stop location within the content string to write as an content. + * @param buffer + * The buffer where the content is written to. + * This will be auto-incremented and must not be a static string. + * + * @return + * f_none on success. + * f_none_on_stop on success after reaching stopping point . + * f_none_on_eos on success after reaching the end of the buffer. + * f_no_data_on_stop no data to write due start location being greater than stop location. + * f_no_data_on_eos no data to write due start location being greater than or equal to buffer size. + * 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_invalid_utf (with error bit) is returned on failure to read/process a UTF-8 character. + * f_reallocation_error (with error bit) on reallocation error. + * f_invalid_parameter (with error bit) if a parameter is invalid. + */ #ifndef _di_fl_fss_extended_content_write_ - /** - * write an fss-0001 content. - */ - extern f_return_status fl_fss_extended_content_write(const f_string_dynamic content, f_string_location *input, f_string_dynamic *buffer); + extern f_return_status fl_fss_extended_content_write(const f_string_dynamic content, f_string_location *location, f_string_dynamic *buffer); #endif // _di_fl_fss_extended_content_write_ #ifdef __cplusplus diff --git a/level_1/fl_fss/c/fss_extended_list.c b/level_1/fl_fss/c/fss_extended_list.c new file mode 100644 index 0000000..4e90d9b --- /dev/null +++ b/level_1/fl_fss/c/fss_extended_list.c @@ -0,0 +1,736 @@ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_fl_fss_extended_list_object_read_ + f_return_status fl_fss_extended_list_object_read(f_string_dynamic *buffer, f_string_location *location, f_fss_object *found) { + #ifndef _di_level_1_parameter_checking_ + if (buffer == 0) return f_status_set_error(f_invalid_parameter); + if (location == 0) return f_status_set_error(f_invalid_parameter); + if (found == 0) return f_status_set_error(f_invalid_parameter); + if (location->start < 0) return f_status_set_error(f_invalid_parameter); + if (location->stop < location->start) return f_status_set_error(f_invalid_parameter); + if (buffer->used <= 0) return f_status_set_error(f_invalid_parameter); + if (location->start >= buffer->used) return f_status_set_error(f_invalid_parameter); + #endif // _di_level_1_parameter_checking_ + + f_status status = f_none; + + // delimits must only be applied once a valid object is found + f_string_lengths delimits = f_string_lengths_initialize; + + fl_fss_skip_past_whitespace(*buffer, location); + fl_macro_fss_object_return_on_overflow((*buffer), (*location), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) + + // return found nothing if this line only contains whitespace and delimit placeholders + if (buffer->string[location->start] == f_string_eol) { + status = fl_fss_increment_buffer(*buffer, location, 1); + if (f_status_is_error(status)) return status; + + return fl_fss_found_no_object; + } + + // begin the search + found->start = location->start; + + // ignore all comment lines + if (buffer->string[location->start] == f_fss_comment) { + fl_macro_fss_object_seek_till_newline((*buffer), (*location), delimits, f_no_data_on_eos, f_no_data_on_stop) + + status = fl_fss_increment_buffer(*buffer, location, 1); + if (f_status_is_error(status)) return status; + + return fl_fss_found_no_object; + } + + // identify where the object ends + while (location->start < buffer->used && location->start <= location->stop && buffer->string[location->start] != f_string_eol) { + if (buffer->string[location->start] == f_fss_delimit_slash) { + f_string_length first_slash = location->start; + f_string_length slash_count = 1; + + status = fl_fss_increment_buffer(*buffer, location, 1); + if (f_status_is_error(status)) return status; + + while (location->start < buffer->used && location->start <= location->stop && (buffer->string[location->start] == f_fss_delimit_placeholder || buffer->string[location->start] == f_fss_delimit_slash)) { + if (buffer->string[location->start] == f_fss_delimit_slash) { + slash_count++; + } + + status = fl_fss_increment_buffer(*buffer, location, 1); + if (f_status_is_error(status)) return status; + } // while + + fl_macro_fss_object_return_on_overflow((*buffer), (*location), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) + + if (buffer->string[location->start] == f_fss_extended_list_open) { + f_string_length stop_point = location->start - 1; + + status = fl_fss_increment_buffer(*buffer, location, 1); + if (f_status_is_error(status)) return status; + + while (location->start < buffer->used && location->start <= location->stop) { + if (buffer->string[location->start] == f_string_eol || (status = fl_fss_is_graph(*buffer, *location)) == f_true) { + break; + } + + if (f_status_is_error(status)) return status; + + status = fl_fss_increment_buffer(*buffer, location, 1); + if (f_status_is_error(status)) return status; + } // while + + fl_macro_fss_object_return_on_overflow((*buffer), (*location), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) + + if (buffer->string[location->start] == f_string_eol) { + f_string_length length = location->start; + + location->start = first_slash; + + if (delimits.used + (slash_count / 2) >= delimits.size) { + f_status allocation_status = f_none; + + f_macro_string_lengths_resize(allocation_status, delimits, delimits.size + (slash_count / 2) + f_fss_default_allocation_step); + + if (f_status_is_error(allocation_status)) { + f_macro_string_lengths_delete(allocation_status, delimits); + return allocation_status; + } + } + + if (slash_count % 2 == 0) { + while (slash_count > 0) { + if (buffer->string[location->start] == f_fss_delimit_slash) { + if (slash_count % 2 != 0) { + delimits.array[delimits.used] = location->start; + delimits.used++; + } + + slash_count--; + } + + status = fl_fss_increment_buffer(*buffer, location, 1); + if (f_status_is_error(status)) return status; + } // while + + fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); + + found->stop = stop_point; + location->start = length + 1; + + return fl_fss_found_object; + } + + location->start = length + 1; + return fl_fss_found_no_object; + } + } + + continue; + } + else if (buffer->string[location->start] == f_fss_extended_list_open) { + f_string_length stop_point = location->start - 1; + + status = fl_fss_increment_buffer(*buffer, location, 1); + if (f_status_is_error(status)) return status; + + while (location->start < buffer->used && location->start <= location->stop) { + if (buffer->string[location->start] == f_string_eol || (status = fl_fss_is_graph(*buffer, *location)) == f_true) { + break; + } + + if (f_status_is_error(status)) return status; + + status = fl_fss_increment_buffer(*buffer, location, 1); + if (f_status_is_error(status)) return status; + } // while + + fl_macro_fss_object_delimited_return_on_overflow((*buffer), (*location), (*found), delimits, f_none_on_eos, f_none_on_stop) + + if (buffer->string[location->start] == f_string_eol) { + fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); + + found->stop = stop_point; + + status = fl_fss_increment_buffer(*buffer, location, 1); + if (f_status_is_error(status)) return status; + + return fl_fss_found_object; + } + + continue; + } + + status = fl_fss_increment_buffer(*buffer, location, 1); + if (f_status_is_error(status)) return status; + } // while + + // seek to the end of the line when no valid object is found + while (location->start < buffer->used && location->start <= location->stop && buffer->string[location->start] != f_string_eol) { + status = fl_fss_increment_buffer(*buffer, location, 1); + if (f_status_is_error(status)) return status; + } // while + + fl_macro_fss_object_return_on_overflow((*buffer), (*location), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) + + status = fl_fss_increment_buffer(*buffer, location, 1); + if (f_status_is_error(status)) return status; + + return fl_fss_found_no_object; + } +#endif // _di_fl_fss_extended_list_object_read_ + +#ifndef _di_fl_fss_extended_list_content_read_ + f_return_status fl_fss_extended_list_content_read(f_string_dynamic *buffer, f_string_location *location, f_fss_content *found) { + #ifndef _di_level_1_parameter_checking_ + if (buffer == 0) return f_status_set_error(f_invalid_parameter); + if (location == 0) return f_status_set_error(f_invalid_parameter); + if (found == 0) return f_status_set_error(f_invalid_parameter); + if (location->start < 0) return f_status_set_error(f_invalid_parameter); + if (location->stop < location->start) return f_status_set_error(f_invalid_parameter); + if (buffer->used <= 0) return f_status_set_error(f_invalid_parameter); + if (location->start >= buffer->used) return f_status_set_error(f_invalid_parameter); + #endif // _di_level_1_parameter_checking_ + + f_status status = f_none; + + // delimits must only be applied once a valid object is found + f_string_lengths delimits = f_string_lengths_initialize; + + fl_macro_fss_skip_past_delimit_placeholders((*buffer), (*location)) + fl_macro_fss_content_return_on_overflow((*buffer), (*location), (*found), delimits, f_none_on_eos, f_none_on_stop) + + fl_macro_fss_allocate_content_if_necessary((*found), delimits); + found->array[found->used].start = location->start; + + f_string_length last_newline = location->start; + f_bool found_newline = f_false; + + // identify where the content ends + while (location->start < buffer->used && location->start <= location->stop) { + if (buffer->string[location->start] == f_string_eol) { + found_newline = f_true; + last_newline = location->start; + + status = fl_fss_increment_buffer(*buffer, location, 1); + if (f_status_is_error(status)) return status; + + fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*location), (*found), delimits, f_none_on_eos, f_none_on_stop) + + continue; + } + + if (buffer->string[location->start] == f_fss_delimit_slash) { + f_string_length first_slash = location->start; + f_string_length slash_count = 1; + + status = fl_fss_increment_buffer(*buffer, location, 1); + if (f_status_is_error(status)) return status; + + while (location->start < buffer->used && location->start <= location->stop && (buffer->string[location->start] == f_fss_delimit_placeholder || buffer->string[location->start] == f_fss_delimit_slash)) { + if (buffer->string[location->start] == f_fss_delimit_slash) { + slash_count++; + } + + status = fl_fss_increment_buffer(*buffer, location, 1); + if (f_status_is_error(status)) return status; + } // while + + if (found_newline) { + fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*location), (*found), delimits, f_none_on_eos, f_none_on_stop) + } + else { + fl_macro_fss_content_return_on_overflow((*buffer), (*location), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) + } + + if (buffer->string[location->start] == f_fss_extended_list_open) { + f_string_length stop_point = location->start - 1; + + status = fl_fss_increment_buffer(*buffer, location, 1); + if (f_status_is_error(status)) return status; + + while (location->start < buffer->used && location->start <= location->stop) { + if (buffer->string[location->start] == f_string_eol || (status = fl_fss_is_graph(*buffer, *location)) == f_true) { + break; + } + + if (f_status_is_error(status)) return status; + + status = fl_fss_increment_buffer(*buffer, location, 1); + if (f_status_is_error(status)) return status; + } // while + + if (found_newline) { + fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*location), (*found), delimits, f_none_on_eos, f_none_on_stop) + } + else { + fl_macro_fss_content_return_on_overflow((*buffer), (*location), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) + } + + if (buffer->string[location->start] == f_string_eol) { + f_string_length length = location->start; + + location->start = first_slash; + + if (slash_count % 2 == 0) { + // FIXME: apply delimits?? + if (found_newline) { + fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); + + found->array[found->used].stop = last_newline; + location->start = last_newline + 1; + found->used++; + + return fl_fss_found_content; + } + + return fl_fss_found_no_content; + } + + if (delimits.used + (slash_count / 2) >= delimits.size) { + f_status allocation_status = f_none; + + f_macro_string_lengths_resize(allocation_status, delimits, delimits.size + (slash_count / 2) + f_fss_default_allocation_step); + + if (f_status_is_error(allocation_status)) { + f_macro_string_lengths_delete(allocation_status, delimits); + return allocation_status; + } + } + + while (slash_count > 0) { + if (buffer->string[location->start] == f_fss_delimit_slash) { + if (slash_count % 2 != 0) { + delimits.array[delimits.used] = location->start; + delimits.used++; + } + + slash_count--; + } + + status = fl_fss_increment_buffer(*buffer, location, 1); + if (f_status_is_error(status)) return status; + } // while + + found_newline = f_true; + location->start = length + 1; + } + } + + continue; + } + else if (buffer->string[location->start] == f_fss_extended_list_open) { + status = fl_fss_increment_buffer(*buffer, location, 1); + if (f_status_is_error(status)) return status; + + while (location->start < buffer->used && location->start <= location->stop) { + if (buffer->string[location->start] == f_string_eol || (status = fl_fss_is_graph(*buffer, *location)) == f_true) { + break; + } + + if (f_status_is_error(status)) return status; + + status = fl_fss_increment_buffer(*buffer, location, 1); + if (f_status_is_error(status)) return status; + } // while + + if (found_newline) { + fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*location), (*found), delimits, f_none_on_eos, f_none_on_stop) + } + else { + fl_macro_fss_content_return_on_overflow((*buffer), (*location), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) + } + + if (buffer->string[location->start] == f_string_eol) { + if (found_newline) { + fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); + + found->array[found->used].stop = last_newline; + location->start = last_newline + 1; + found->used++; + + return fl_fss_found_content; + } + + if (!found_newline) { + location->start = last_newline; + } + + return fl_fss_found_no_content; + } + + continue; + } + + status = fl_fss_increment_buffer(*buffer, location, 1); + if (f_status_is_error(status)) return status; + } // while + + if (found_newline) { + fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); + + found->array[found->used].stop = last_newline - 1; + location->start = last_newline + 1; + found->used++; + + fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*location), (*found), delimits, f_none_on_eos, f_none_on_stop) + + return fl_fss_found_content; + } + + fl_macro_fss_content_return_on_overflow((*buffer), (*location), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) + + return fl_fss_found_no_content; + } +#endif // _di_fl_fss_extended_list_content_read_ + +#ifndef _di_fl_fss_extended_list_object_write_ + f_return_status fl_fss_extended_list_object_write(const f_string_dynamic object, f_string_location *location, f_string_dynamic *buffer) { + #ifndef _di_level_1_parameter_checking_ + if (buffer == 0) return f_status_set_error(f_invalid_parameter); + #endif // _di_level_1_parameter_checking_ + + f_status status = f_none; + + f_string_location buffer_position = f_string_location_initialize; + f_string_length start_position = f_string_initialize; + f_string_length pre_allocate_size = 0; + f_string_length start_buffer = 0; + + fl_macro_fss_skip_past_delimit_placeholders(object, (*location)) + + if (location->start > location->stop) { + return f_no_data_on_stop; + } + else if (location->start >= object.used) { + return f_no_data_on_eos; + } + + start_position = location->start; + + // add an additional 2 to ensure that there is room for the slash delimit and the object open character. + pre_allocate_size = buffer->used + (location->stop - location->start) + 2 + f_fss_default_allocation_step_string; + + if (pre_allocate_size > buffer->size) { + f_macro_string_dynamic_resize(status, (*buffer), pre_allocate_size); + + if (f_status_is_error(status)) return status; + } + + buffer_position.start = buffer->used; + buffer_position.stop = buffer->used; + + while (location->start <= location->stop && location->start < object.used) { + if (object.string[location->start] == f_fss_comment) { + // comments are not allowed and this format has no way of "wrapping" a comment. + return f_status_set_error(f_invalid_data); + } + else if ((status = fl_fss_is_graph(object, *location)) == f_true) { + break; + } + else if (f_status_is_error(status)) { + f_status status2 = f_status_set_fine(status); + + if (status2 == f_failure) { + return f_status_set_error(f_invalid_utf); + } + + if (status2 == f_failure) { + return f_status_set_error(f_incomplete_utf); + } + + return status; + } + + if (object.string[location->start] != f_fss_delimit_placeholder) { + buffer->string[buffer_position.stop] = object.string[location->start]; + buffer_position.stop++; + } + + status = fl_fss_increment_buffer(object, location, 1); + if (f_status_is_error(status)) return status; + } // while + + while (location->start <= location->stop && location->start < object.used) { + if (object.string[location->start] == f_fss_delimit_slash) { + f_string_length slash_count = 1; + + buffer->string[buffer_position.stop] = object.string[location->start]; + buffer_position.stop++; + + status = fl_fss_increment_buffer(object, location, 1); + if (f_status_is_error(status)) return status; + + while (location->start <= location->stop && location->start < object.used) { + if (object.string[location->start] == f_fss_delimit_placeholder) { + status = fl_fss_increment_buffer(object, location, 1); + if (f_status_is_error(status)) return status; + + continue; + } else if (object.string[location->start] != f_fss_delimit_slash) { + break; + } + + buffer->string[buffer_position.stop] = object.string[location->start]; + buffer_position.stop++; + + status = fl_fss_increment_buffer(object, location, 1); + if (f_status_is_error(status)) return status; + + slash_count++; + } // while + + if (location->start > location->stop || location->start >= object.used) { + pre_allocate_size += slash_count; + + if (pre_allocate_size > buffer->size) { + f_macro_string_dynamic_resize(status, (*buffer), pre_allocate_size + f_fss_default_allocation_step_string); + + if (f_status_is_error(status)) return status; + } + + while (slash_count > 0) { + buffer->string[buffer_position.stop] = f_fss_delimit_slash; + buffer_position.stop++; + slash_count--; + } // while + + break; + } + } + else if (object.string[location->start] == f_string_eol) { + // @todo: review what this is doing. + if (buffer_position.stop == buffer_position.start) { + return f_no_data_on_eol; + } + + break; + } + + if (object.string[location->start] != f_fss_delimit_placeholder) { + buffer->string[buffer_position.stop] = object.string[location->start]; + buffer_position.stop++; + } + + status = fl_fss_increment_buffer(object, location, 1); + if (f_status_is_error(status)) return status; + } // while + + buffer->string[buffer_position.stop] = f_fss_extended_list_open; + buffer->string[buffer_position.stop + 1] = f_string_eol; + buffer->used = buffer_position.stop + 2; + + if (location->start > location->stop) { + return f_none_on_stop; + } + else if (location->start >= object.used) { + return f_none_on_eos; + } + + return f_none; + } +#endif // _di_fl_fss_extended_list_object_write_ + +#ifndef _di_fl_fss_extended_list_content_write_ + f_return_status fl_fss_extended_list_content_write(const f_string_dynamic content, f_string_location *location, f_string_dynamic *buffer) { + #ifndef _di_level_1_parameter_checking_ + if (buffer == 0) return f_status_set_error(f_invalid_parameter); + #endif // _di_level_1_parameter_checking_ + + f_status status = f_none; + f_bool is_comment = f_false; + f_bool has_graph = f_false; + + f_string_location buffer_position = f_string_location_initialize; + f_string_length start_position = f_string_initialize; + f_string_length pre_allocate_size = 0; + + fl_macro_fss_skip_past_delimit_placeholders(content, (*location)) + + if (location->start > location->stop) { + return f_no_data_on_stop; + } + else if (location->start >= content.used) { + return f_no_data_on_eos; + } + + start_position = location->start; + + // add an additional 2 to ensure that there is room for the slash delimit and the content open character. + pre_allocate_size = buffer->used + (location->stop - location->start) + 2 + f_fss_default_allocation_step_string; + + if (pre_allocate_size > buffer->size) { + f_macro_string_dynamic_resize(status, (*buffer), pre_allocate_size); + + if (f_status_is_error(status)) return status; + } + + buffer_position.start = buffer->used; + buffer_position.stop = buffer->used; + + while (location->start <= location->stop && location->start < content.used) { + if (content.string[location->start] == f_fss_delimit_slash && !is_comment) { + f_string_length slash_count = 1; + + buffer->string[buffer_position.stop] = content.string[location->start]; + buffer_position.stop++; + + has_graph = f_true; + status = fl_fss_increment_buffer(content, location, 1); + if (f_status_is_error(status)) return status; + + while (location->start <= location->stop && location->start < content.used) { + if (content.string[location->start] == f_fss_delimit_placeholder) { + status = fl_fss_increment_buffer(content, location, 1); + if (f_status_is_error(status)) return status; + + continue; + } + else if (content.string[location->start] != f_fss_delimit_slash) { + break; + } + + buffer->string[buffer_position.stop] = content.string[location->start]; + buffer_position.stop++; + + status = fl_fss_increment_buffer(content, location, 1); + if (f_status_is_error(status)) return status; + + slash_count++; + } // while + + if (content.string[location->start] == f_fss_extended_list_open) { + f_string_length length = location->start; + + status = fl_fss_increment_buffer(content, location, 1); + if (f_status_is_error(status)) return status; + + while (location->start < content.used && location->start <= location->stop) { + if (content.string[location->start] == f_string_eol || (status = fl_fss_is_graph(content, *location)) == f_true) { + break; + } + + if (f_status_is_error(status)) return status; + + status = fl_fss_increment_buffer(content, location, 1); + if (f_status_is_error(status)) return status; + } // while + + if (content.string[location->start] == f_string_eol || location->start >= content.used || location->start > location->stop) { + pre_allocate_size += slash_count + 1; + + if (pre_allocate_size > buffer->size) { + f_macro_string_dynamic_resize(status, (*buffer), pre_allocate_size + f_fss_default_allocation_step_string); + + if (f_status_is_error(status)) return status; + } + + while (slash_count > 0) { + buffer->string[buffer_position.stop] = f_fss_delimit_slash; + buffer_position.stop++; + slash_count--; + } // while + + buffer->string[buffer_position.stop] = f_fss_delimit_slash; + buffer_position.stop++; + has_graph = f_false; + is_comment = f_false; + } + + buffer->string[buffer_position.stop] = f_fss_extended_list_open; + buffer_position.stop++; + location->start = length + 1; + continue; + } + } + else if (content.string[location->start] == f_fss_extended_list_open && !is_comment) { + f_string_length length = location->start; + + has_graph = f_true; + + status = fl_fss_increment_buffer(content, location, 1); + if (f_status_is_error(status)) return status; + + while (location->start < content.used && location->start <= location->stop) { + if (content.string[location->start] == f_string_eol || (status = fl_fss_is_graph(content, *location)) == f_true) { + break; + } + + if (f_status_is_error(status)) return status; + + status = fl_fss_increment_buffer(content, location, 1); + if (f_status_is_error(status)) return status; + } // while + + if (content.string[location->start] == f_string_eol || location->start >= content.used || location->start > location->stop) { + pre_allocate_size++; + + if (pre_allocate_size > buffer->size) { + f_macro_string_dynamic_resize(status, (*buffer), pre_allocate_size + f_fss_default_allocation_step_string); + + if (f_status_is_error(status)) return status; + } + + buffer->string[buffer_position.stop] = f_fss_delimit_slash; + buffer_position.stop++; + has_graph = f_false; + is_comment = f_false; + } + + buffer->string[buffer_position.stop] = f_fss_extended_list_open; + buffer_position.stop++; + location->start = length + 1; + continue; + } + else if (content.string[location->start] == f_fss_comment && !has_graph) { + is_comment = f_true; + } + else if (content.string[location->start] == f_string_eol) { + has_graph = f_false; + is_comment = f_false; + } + else if ((status = fl_fss_is_graph(content, *location)) == f_true) { + has_graph = f_true; + } + else if (f_status_is_error(status)) { + f_status status2 = f_status_set_fine(status); + + if (status2 == f_failure) { + return f_status_set_error(f_invalid_utf); + } + + if (status2 == f_failure) { + return f_status_set_error(f_incomplete_utf); + } + + return status; + } + + if (content.string[location->start] != f_fss_delimit_placeholder) { + buffer->string[buffer_position.stop] = content.string[location->start]; + buffer_position.stop++; + } + + status = fl_fss_increment_buffer(content, location, 1); + if (f_status_is_error(status)) return status; + } // while + + buffer->string[buffer_position.stop] = f_string_eol; + buffer->used = buffer_position.stop + 1; + + if (location->start > location->stop) { + return f_none_on_stop; + } + else if (location->start >= content.used) { + return f_none_on_eos; + } + + return f_none; + } +#endif // _di_fl_fss_extended_list_content_write_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_1/fl_fss/c/fss_extended_list.h b/level_1/fl_fss/c/fss_extended_list.h new file mode 100644 index 0000000..7392fcf --- /dev/null +++ b/level_1/fl_fss/c/fss_extended_list.h @@ -0,0 +1,169 @@ +/** + * FLL - Level 1 + * + * Project: FSS + * API Version: 0.5 + * Licenses: lgplv2.1 + * + * This is the fss-0003 implementation. + */ +#ifndef _FL_fss_extended_list_h +#define _FL_fss_extended_list_h + +// libc includes +#include +#include + +// fll-0 includes +#include +#include +#include +#include +#include +#include + +// fll-1 includes +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Read an fss-0003 object. + * + * This will update the buffer at the given range with any placeholders to unescape any escaped data. + * Calling this more than once on the same buffer range could result in multiple unescaping. + * + * @param buffer + * The buffer to read from. + * This will be updated with delimit placeholders as it is being processed. + * @param location + * 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 set of all locations where a valid object was found. + * + * @return + * fl_fss_found_object on success and object was found (start location is at end of object). + * fl_fss_found_no_object on success and no object was found (start location is after character designating this is not an object). + * f_none_on_stop on success after reaching stopping point (a valid object is not yet confirmed). + * f_none_on_eos on success after reaching the end of the buffer (a valid object is not yet confirmed). + * f_no_data_on_stop no data found after reaching stopping point (essentially only comments are found). + * f_no_data_on_eos no objects found after reaching the end of the buffer (essentially only comments are found). + * f_incomplete_utf_on_stop (with error bit) if the stop location is reached before the complete UTF-8 character can be processed. + * f_incomplete_utf_on_eos (with error bit) if the end of buffer is reached before the complete UTF-8 character can be processed. + * 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_invalid_utf (with error bit) is returned on failure to read/process a UTF-8 character. + * f_reallocation_error (with error bit) on reallocation error. + * f_invalid_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_fl_fss_extended_list_object_read_ + extern f_return_status fl_fss_extended_list_object_read(f_string_dynamic *buffer, f_string_location *location, f_fss_object *found); +#endif // _di_fl_fss_extended_list_object_read_ + +/** + * Read an fss-0003 content. + * + * This will update the buffer at the given range with any placeholders to unescape any escaped data. + * Calling this more than once on the same buffer range could result in multiple unescaping. + * + * @param buffer + * The buffer to read from. + * This will be updated with delimit placeholders as it is being processed. + * @param location + * 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 set of all locations where a valid content was found. + * + * @return + * fl_fss_found_content on success and content was found (start location is at end of content). + * fl_fss_found_no_content on success and no content was found (start location is after character designating this is not a content). + * f_none_on_stop on success after reaching stopping point (a valid content is not yet confirmed). + * f_none_on_eos on success after reaching the end of the buffer (a valid content is not yet confirmed). + * f_no_data_on_stop no data found after reaching stopping point (essentially only comments are found). + * f_no_data_on_eos no content found after reaching the end of the buffer (essentially only comments are found). + * f_incomplete_utf_on_stop (with error bit) if the stop location is reached before the complete UTF-8 character can be processed. + * f_incomplete_utf_on_eos (with error bit) if the end of buffer is reached before the complete UTF-8 character can be processed. + * 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_invalid_utf (with error bit) is returned on failure to read/process a UTF-8 character. + * f_reallocation_error (with error bit) on reallocation error. + * f_invalid_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_fl_fss_extended_list_content_read_ + extern f_return_status fl_fss_extended_list_content_read(f_string_dynamic *buffer, f_string_location *location, f_fss_content *found); +#endif // _di_fl_fss_extended_list_content_read_ + +/** + * Write an fss-0003 object. + * + * This will write the given string range as a valid object. + * Anything within this range will be escaped as necessary. + * This will stop if EOL is reached. + * + * @param object + * The string to write as (does not stop at NULLS, they are ignored and not written). + * @param location + * The start/stop location within the object string to write as an object. + * @param buffer + * The buffer where the object is written to. + * This will be auto-incremented and must not be a static string. + * + * @return + * f_none on success. + * f_none_on_stop on success after reaching stopping point . + * f_none_on_eos on success after reaching the end of the buffer. + * f_no_data_on_stop no data to write due start location being greater than stop location. + * f_no_data_on_eos no data to write due start location being greater than or equal to buffer size. + * f_no_data_on_eol if there is no data to write and EOL was reached (@todo: review related code and detemine what this is doing). + * 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_invalid_utf (with error bit) is returned on failure to read/process a UTF-8 character. + * f_reallocation_error (with error bit) on reallocation error. + * f_invalid_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_fl_fss_extended_list_object_write_ + extern f_return_status fl_fss_extended_list_object_write(const f_string_dynamic object, f_string_location *location, f_string_dynamic *buffer); +#endif // _di_fl_fss_extended_list_object_write_ + +/** + * Write an fss-0003 content. + * + * This will write the given string range as a valid content. + * Anything within this range will be escaped as necessary. + * + * @param content + * The string to write as (does not stop at NULLS, they are ignored and not written). + * @param location + * The start/stop location within the content string to write as an content. + * @param buffer + * The buffer where the content is written to. + * This will be auto-incremented and must not be a static string. + * + * @return + * f_none on success. + * f_none_on_stop on success after reaching stopping point . + * f_none_on_eos on success after reaching the end of the buffer. + * f_no_data_on_stop no data to write due start location being greater than stop location. + * f_no_data_on_eos no data to write due start location being greater than or equal to buffer size. + * 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_invalid_utf (with error bit) is returned on failure to read/process a UTF-8 character. + * f_reallocation_error (with error bit) on reallocation error. + * f_invalid_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_fl_fss_extended_list_content_write_ + extern f_return_status fl_fss_extended_list_content_write(const f_string_dynamic content, f_string_location *location, f_string_dynamic *buffer); +#endif // _di_fl_fss_extended_list_content_write_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _FL_fss_extended_list_h diff --git a/level_1/fl_fss/c/fss_macro.h b/level_1/fl_fss/c/fss_macro.h index 4f9496d..9c40334 100644 --- a/level_1/fl_fss/c/fss_macro.h +++ b/level_1/fl_fss/c/fss_macro.h @@ -32,36 +32,36 @@ extern "C" { #endif // _di_fl_macro_fss_apply_delimit_placeholders_ #ifndef _di_fl_macro_fss_skip_past_delimit_placeholders_ - #define fl_macro_fss_skip_past_delimit_placeholders(buffer, input) \ - while (buffer.string[input.start] == f_fss_delimit_placeholder) { \ - ++input.start;\ + #define fl_macro_fss_skip_past_delimit_placeholders(buffer, location) \ + while (buffer.string[location.start] == f_fss_delimit_placeholder) { \ + ++location.start;\ \ - if (input.start >= buffer.used) break; \ - if (input.start > input.stop) break; \ + if (location.start >= buffer.used) break; \ + if (location.start > location.stop) break; \ } // while #endif // _di_fl_macro_fss_skip_past_delimit_placeholders_ #ifndef _di_fl_macro_fss_object_return_on_overflow_ - #define fl_macro_fss_object_return_on_overflow(buffer, input, found, delimits, eos_status, stop_status) \ - if (input.start >= buffer.used) { \ + #define fl_macro_fss_object_return_on_overflow(buffer, location, found, delimits, eos_status, stop_status) \ + if (location.start >= buffer.used) { \ f_status allocation_status = f_none; \ f_macro_string_lengths_delete(allocation_status, delimits); \ \ found.stop = buffer.used - 1; \ return eos_status; \ } \ - else if (input.start > input.stop) { \ + else if (location.start > location.stop) { \ f_status allocation_status = f_none; \ f_macro_string_lengths_delete(allocation_status, delimits); \ \ - found.stop = input.stop; \ + found.stop = location.stop; \ return stop_status; \ } #endif // _di_fl_macro_fss_object_return_on_overflow_ #ifndef _di_fl_macro_fss_object_delimited_return_on_overflow_ - #define fl_macro_fss_object_delimited_return_on_overflow(buffer, input, found, delimits, eos_status, stop_status) \ - if (input.start >= buffer.used) { \ + #define fl_macro_fss_object_delimited_return_on_overflow(buffer, location, found, delimits, eos_status, stop_status) \ + if (location.start >= buffer.used) { \ f_status allocation_status = f_none; \ f_string_length i = 0; \ \ @@ -74,7 +74,7 @@ extern "C" { found.stop = buffer.used - 1; \ return eos_status; \ } \ - else if (input.start > input.stop) { \ + else if (location.start > location.stop) { \ f_status allocation_status = f_none; \ f_string_length i = 0; \ \ @@ -84,32 +84,32 @@ extern "C" { } \ f_macro_string_lengths_delete(allocation_status, delimits); \ \ - found.stop = input.stop; \ + found.stop = location.stop; \ return stop_status; \ } #endif // _di_fl_macro_fss_object_delimited_return_on_overflow_ #ifndef _di_fl_macro_fss_content_return_on_overflow_ - #define fl_macro_fss_content_return_on_overflow(buffer, input, found, delimits, eos_status, stop_status) \ - if (input.start >= buffer.used) { \ + #define fl_macro_fss_content_return_on_overflow(buffer, location, found, delimits, eos_status, stop_status) \ + if (location.start >= buffer.used) { \ f_status allocation_status = f_none; \ f_macro_string_lengths_delete(allocation_status, delimits); \ \ found.array[found.used].stop = buffer.used - 1; \ return eos_status; \ } \ - else if (input.start > input.stop) { \ + else if (location.start > location.stop) { \ f_status allocation_status = f_none; \ f_macro_string_lengths_delete(allocation_status, delimits); \ \ - found.array[found.used].stop = input.stop; \ + found.array[found.used].stop = location.stop; \ return stop_status; \ } #endif // _di_fl_macro_fss_content_return_on_overflow_ #ifndef _di_fl_macro_fss_content_delimited_return_on_overflow_ - #define fl_macro_fss_content_delimited_return_on_overflow(buffer, input, found, delimits, eos_status, stop_status) \ - if (input.start >= buffer.used) { \ + #define fl_macro_fss_content_delimited_return_on_overflow(buffer, location, found, delimits, eos_status, stop_status) \ + if (location.start >= buffer.used) { \ f_status allocation_status = f_none; \ f_string_length i = 0; \ \ @@ -122,7 +122,7 @@ extern "C" { found.array[found.used].stop = buffer.used - 1; \ return eos_status; \ } \ - else if (input.start > input.stop) { \ + else if (location.start > location.stop) { \ f_status allocation_status = f_none; \ f_string_length i = 0; \ \ @@ -132,34 +132,34 @@ extern "C" { } \ f_macro_string_lengths_delete(allocation_status, delimits); \ \ - found.array[found.used].stop = input.stop; \ + found.array[found.used].stop = location.stop; \ return stop_status; \ } #endif // _di_fl_macro_fss_content_delimited_return_on_overflow_ #ifndef _di_fl_macro_fss_content_return_on_overflow_reset_ - #define fl_macro_fss_content_return_on_overflow_reset(buffer, input, found, delimits, eos_status, stop_status, set_stop) \ - if (input.start >= buffer.used) { \ + #define fl_macro_fss_content_return_on_overflow_reset(buffer, location, found, delimits, eos_status, stop_status, set_stop) \ + if (location.start >= buffer.used) { \ f_status allocation_status = f_none; \ f_macro_string_lengths_delete(allocation_status, delimits); \ \ - input.start = set_stop; \ + location.start = set_stop; \ found.array[found.used].stop = set_stop; \ return eos_status; \ } \ - else if (input.start > input.stop) { \ + else if (location.start > location.stop) { \ f_status allocation_status = f_none; \ f_macro_string_lengths_delete(allocation_status, delimits); \ \ - input.start = set_stop; \ + location.start = set_stop; \ found.array[found.used].stop = set_stop; \ return stop_status; \ } #endif // _di_fl_macro_fss_content_return_on_overflow_reset_ #ifndef _di_fl_macro_fss_content_delimited_return_on_overflow_reset_ - #define fl_macro_fss_content_delimited_return_on_overflow_reset(buffer, input, found, delimits, eos_status, stop_status, set_stop) \ - if (input.start >= buffer.used) { \ + #define fl_macro_fss_content_delimited_return_on_overflow_reset(buffer, location, found, delimits, eos_status, stop_status, set_stop) \ + if (location.start >= buffer.used) { \ f_status allocation_status = f_none; \ f_string_length i = 0; \ \ @@ -169,11 +169,11 @@ extern "C" { } \ f_macro_string_lengths_delete(allocation_status, delimits); \ \ - input.start = set_stop; \ + location.start = set_stop; \ found.array[found.used].stop = set_stop; \ return eos_status; \ } \ - else if (input.start > input.stop) { \ + else if (location.start > location.stop) { \ f_status allocation_status = f_none; \ f_string_length i = 0; \ \ @@ -183,7 +183,7 @@ extern "C" { } \ f_macro_string_lengths_delete(allocation_status, delimits); \ \ - input.start = set_stop; \ + location.start = set_stop; \ found.array[found.used].stop = set_stop; \ return stop_status; \ } @@ -205,16 +205,16 @@ extern "C" { #endif // _di_fl_macro_fss_allocate_content_if_necessary_ #ifndef _di_fl_macro_fss_object_seek_till_newline_ - #define fl_macro_fss_object_seek_till_newline(buffer, input, delimits, eos_status, stop_status) \ - while (buffer.string[input.start] != f_string_eol) { \ - ++input.start; \ - if (input.start >= buffer.used) { \ + #define fl_macro_fss_object_seek_till_newline(buffer, location, delimits, eos_status, stop_status) \ + while (buffer.string[location.start] != f_string_eol) { \ + ++location.start; \ + if (location.start >= buffer.used) { \ f_status allocation_status = f_none; \ f_macro_string_lengths_delete(allocation_status, delimits); \ \ return eos_status; \ } \ - if (input.start > input.stop) { \ + if (location.start > location.stop) { \ f_status allocation_status = f_none; \ f_macro_string_lengths_delete(allocation_status, delimits); \ \ @@ -224,10 +224,10 @@ extern "C" { #endif // _di_fl_macro_fss_object_seek_till_newline_ #ifndef _di_fl_macro_fss_object_delimited_seek_till_newline_ - #define fl_macro_fss_object_delimited_seek_till_newline(buffer, input, delimits, eos_status, stop_status) \ - while (buffer.string[input.start] != f_string_eol) { \ - ++input.start; \ - if (input.start >= buffer.used) { \ + #define fl_macro_fss_object_delimited_seek_till_newline(buffer, location, delimits, eos_status, stop_status) \ + while (buffer.string[location.start] != f_string_eol) { \ + ++location.start; \ + if (location.start >= buffer.used) { \ f_status allocation_status = f_none; \ f_string_length i = 0; \ \ @@ -239,7 +239,7 @@ extern "C" { \ return eos_status; \ } \ - if (input.start > input.stop) { \ + if (location.start > location.stop) { \ f_status allocation_status = f_none; \ f_string_length i = 0; \ \ @@ -255,31 +255,31 @@ extern "C" { #endif // _di_fl_macro_fss_object_delimited_seek_till_newline_ #ifndef _di_fl_macro_fss_content_seek_till_newline_ - #define fl_macro_fss_content_seek_till_newline(buffer, input, found, delimits, eos_status, stop_status) \ - while (buffer.string[input.start] != f_string_eol) { \ - ++input.start; \ - if (input.start >= buffer.used) { \ + #define fl_macro_fss_content_seek_till_newline(buffer, location, found, delimits, eos_status, stop_status) \ + while (buffer.string[location.start] != f_string_eol) { \ + ++location.start; \ + if (location.start >= buffer.used) { \ f_status allocation_status = f_none; \ f_macro_string_lengths_delete(allocation_status, delimits); \ \ - found.array[found.used].stop = input.stop; \ + found.array[found.used].stop = location.stop; \ return eos_status; \ } \ - if (input.start > input.stop) { \ + if (location.start > location.stop) { \ f_status allocation_status = f_none; \ f_macro_string_lengths_delete(allocation_status, delimits); \ \ - found.array[found.used].stop = input.stop; \ + found.array[found.used].stop = location.stop; \ return stop_status; \ } \ } // while #endif // _di_fl_macro_fss_content_seek_till_newline_ #ifndef _di_fl_macro_fss_content_delimited_seek_till_newline_ - #define fl_macro_fss_content_delimited_seek_till_newline(buffer, input, found, delimits, eos_status, stop_status) \ - while (buffer.string[input.start] != f_string_eol) { \ - ++input.start; \ - if (input.start >= buffer.used) { \ + #define fl_macro_fss_content_delimited_seek_till_newline(buffer, location, found, delimits, eos_status, stop_status) \ + while (buffer.string[location.start] != f_string_eol) { \ + ++location.start; \ + if (location.start >= buffer.used) { \ f_status allocation_status = f_none; \ f_string_length i = 0; \ \ @@ -289,10 +289,10 @@ extern "C" { } \ f_macro_string_lengths_delete(allocation_status, delimits); \ \ - found.array[found.used].stop = input.stop; \ + found.array[found.used].stop = location.stop; \ return eos_status; \ } \ - if (input.start > input.stop) { \ + if (location.start > location.stop) { \ f_status allocation_status = f_none; \ f_string_length i = 0; \ \ @@ -302,7 +302,7 @@ extern "C" { } \ f_macro_string_lengths_delete(allocation_status, delimits); \ \ - found.array[found.used].stop = input.stop; \ + found.array[found.used].stop = location.stop; \ return stop_status; \ } \ } // while diff --git a/level_1/fl_status/c/status.c b/level_1/fl_status/c/status.c index adfe4a0..5ac5e3f 100644 --- a/level_1/fl_status/c/status.c +++ b/level_1/fl_status/c/status.c @@ -680,7 +680,7 @@ extern "C" { default: *string = 0; - return f_invalid_data; + return f_status_set_error(f_invalid_data); } return f_none; diff --git a/level_1/fl_status/c/status.h b/level_1/fl_status/c/status.h index e8e41f3..288dc39 100644 --- a/level_1/fl_status/c/status.h +++ b/level_1/fl_status/c/status.h @@ -700,7 +700,7 @@ extern "C" { * * @return * f_none on success. - * f_invalid_data if there status is unknown. + * f_invalid_data (with error bit) if there status is unknown. * f_invalid_parameter (with error bit) if a parameter is invalid. */ #ifndef _di_fl_status_to_string_ diff --git a/level_2/fll_fss/c/fss_status.c b/level_2/fll_fss/c/fss_status.c index 5e37e17..55b8e93 100644 --- a/level_2/fll_fss/c/fss_status.c +++ b/level_2/fll_fss/c/fss_status.c @@ -19,7 +19,7 @@ extern "C" { // numbers are not valid status code strings. if ((status = f_is_decimal(string[0])) == f_true) { - return f_invalid_data; + return f_status_set_error(f_invalid_data); } if (f_status_is_error(status)) { @@ -92,7 +92,7 @@ extern "C" { return f_none; } - return f_invalid_data; + return f_status_set_error(f_invalid_data); } #endif // _di_fll_fss_status_from_string_ diff --git a/level_2/fll_status/c/status.c b/level_2/fll_status/c/status.c index b7e64ec..5398a8c 100644 --- a/level_2/fll_status/c/status.c +++ b/level_2/fll_status/c/status.c @@ -19,7 +19,7 @@ extern "C" { // numbers are not valid status code strings. if ((status = f_is_decimal(string[0])) == f_true) { - return f_invalid_data; + return f_status_set_error(f_invalid_data); } if (f_status_is_error(status)) { @@ -1116,7 +1116,7 @@ extern "C" { return f_none; } - return f_invalid_data; + return f_status_set_error(f_invalid_data); } #endif // _di_fll_status_from_string_ diff --git a/level_2/fll_status/c/status.h b/level_2/fll_status/c/status.h index 1ead967..04f3b86 100644 --- a/level_2/fll_status/c/status.h +++ b/level_2/fll_status/c/status.h @@ -40,7 +40,7 @@ extern "C" { * @return * f_none on success. * f_no_data if string is empty. - * f_invalid_data if not found. + * f_invalid_data (with error bit) if not found. * f_invalid_parameter (with error bit) if a parameter is invalid. */ #ifndef _di_fll_status_from_string_ diff --git a/level_3/firewall/c/firewall.c b/level_3/firewall/c/firewall.c index 33ce463..568bd0d 100644 --- a/level_3/firewall/c/firewall.c +++ b/level_3/firewall/c/firewall.c @@ -415,7 +415,7 @@ extern "C" { firewall_delete_local_data(&local); firewall_delete_data(data); - return f_invalid_data; + return f_status_set_error(f_invalid_data); } } @@ -455,7 +455,7 @@ extern "C" { firewall_delete_local_data(&local); firewall_delete_data(data); - return f_invalid_data; + return f_status_set_error(f_invalid_data); } } diff --git a/specifications/fss.txt b/specifications/fss.txt index 97ea0b2..86a2595 100644 --- a/specifications/fss.txt +++ b/specifications/fss.txt @@ -42,12 +42,20 @@ Unlike this specification, a more traditional delimit process would have the abo "Object 1" "This is a single quoted Content." \"Additional unquoted Content\" Object_2 This is multiple\" Contents and the trailing quote does not need to be delimited. -All specifications are expected to support or be of the character encoding utf-8; however, there is no imposed restriction on supporting or using any other encoding. +All specifications are expected to support or be of the character encoding UTF-8; however, there is no imposed restriction on supporting or using any other encoding. Those encodings must only support the appropriate characters required by a given standard for differentiating Objects, Contents, and delimits. Unless explicitly defined, comments are designated by the pound symbol '#' but only if only whitespace is to the left of the pound. There is no support for inline comments. +Unless explicitly defined, all designation characters must be in ASCII. +With designation characters being any character code used to designate how to read a file (such as a colon ':' at the end of a basic list). +This keeps the processing and logic simple, for UTF-8. +Whitespace used for designation characters must include support UTF-8 whitespace characters, unless explicitly designate not to. +Control characters used for designation characters must include support UTF-8 control character support, unless explicitly designate not to. + +The UTF-8 BOM is not allowed as a "BOM", instead it must always be treated as the character represented by its code (unless explicitly allowed). + The follow specifications are defined in this project. Each of these specifications has a common name associated with the specification number. - fss-0000: Basic -- 1.8.3.1