From 5b9394dc291edba7880f5f8c587247d7274293be Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sat, 17 Mar 2012 00:41:06 -0500 Subject: [PATCH] Update: rework the basic write to accept a string location argument This should make things more consistent with how the basic read functions work. --- level_1/fl_fss/c/fss_basic.c | 109 ++++++++++++++++++++----------------------- level_1/fl_fss/c/fss_basic.h | 4 +- 2 files changed, 53 insertions(+), 60 deletions(-) diff --git a/level_1/fl_fss/c/fss_basic.c b/level_1/fl_fss/c/fss_basic.c index d89e5c3..b954712 100644 --- a/level_1/fl_fss/c/fss_basic.c +++ b/level_1/fl_fss/c/fss_basic.c @@ -59,7 +59,7 @@ extern "C"{ fl_macro_fss_skip_past_delimit_placeholders((*buffer), (*input)) fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_none_on_eos, f_none_on_stop) - // A slash only delimits if a delimit quote would follow the slash (or a slash and a delimit quote follows) + // A slash only delimits if a delimit quote would follow the slash if (buffer->string[input->start] == f_fss_delimit_single_quote || buffer->string[input->start] == f_fss_delimit_double_quote) { location = first_slash; has_delimit = f_true; @@ -302,31 +302,27 @@ extern "C"{ #endif // _di_fl_fss_basic_content_read_ #ifndef _di_fl_fss_basic_object_write_ - f_return_status fl_fss_basic_object_write(const f_dynamic_string input, f_dynamic_string *object) { + f_return_status fl_fss_basic_object_write(const f_dynamic_string buffer, f_string_location *input, f_dynamic_string *object) { #ifndef _di_level_1_parameter_checking_ if (object == f_null) return f_invalid_parameter; #endif // _di_level_1_parameter_checking_ f_status status = f_status_initialize; - f_string_location input_position = f_string_location_initialize; f_string_location object_position = f_string_location_initialize; f_string_length start_position = f_string_initialize; f_string_length pre_allocate_size = f_string_length_initialize; - input_position.start = 0; - input_position.stop = input.used; - - fl_macro_fss_skip_past_all_whitespace(input, input_position) + fl_macro_fss_skip_past_all_whitespace(buffer, (*input)) - if (input_position.start >= input.used) { + if (input->start >= buffer.used) { return f_no_data; } - start_position = input_position.start; + start_position = input->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 = object->used + (input_position.stop - input_position.start) + 3 + f_fss_default_allocation_step; + pre_allocate_size = object->used + (input->stop - input->start) + 3 + f_fss_default_allocation_step; if (pre_allocate_size > object->size) { f_resize_dynamic_string(status, (*object), pre_allocate_size); @@ -337,24 +333,24 @@ extern "C"{ object_position.start = object->used; object_position.stop = object->used; - if (input.string[input_position.start] == f_fss_delimit_slash) { + if (buffer.string[input->start] == f_fss_delimit_slash) { f_string_length delimit_slash_count = 0; - while (input_position.start <= input_position.stop) { - if (input.string[input_position.start] == f_fss_delimit_placeholder) { - input_position.start++; + while (input->start <= input->stop) { + if (buffer.string[input->start] == f_fss_delimit_placeholder) { + input->start++; continue; - } else if (input.string[input_position.start] != f_fss_delimit_slash) { + } else if (buffer.string[input->start] != f_fss_delimit_slash) { break; } - object->string[object_position.stop] = input.string[input_position.start]; + object->string[object_position.stop] = buffer.string[input->start]; object_position.stop++; delimit_slash_count++; - input_position.start++; + input->start++; } // while - if (input.string[input_position.start] == f_fss_delimit_single_quote || input.string[input_position.start] == f_fss_delimit_double_quote) { + if (buffer.string[input->start] == f_fss_delimit_single_quote || buffer.string[input->start] == f_fss_delimit_double_quote) { pre_allocate_size += delimit_slash_count + 1; if (pre_allocate_size > object->size) { @@ -369,11 +365,11 @@ extern "C"{ delimit_slash_count--; } // while - object->string[object_position.stop] = input.string[input_position.start]; + object->string[object_position.stop] = buffer.string[input->start]; object_position.stop++; - input_position.start++; + input->start++; } - } else if (input.string[input_position.start] == f_fss_delimit_single_quote || input.string[input_position.start] == f_fss_delimit_double_quote) { + } else if (buffer.string[input->start] == f_fss_delimit_single_quote || buffer.string[input->start] == f_fss_delimit_double_quote) { pre_allocate_size++; if (pre_allocate_size > object->size) { @@ -383,42 +379,42 @@ extern "C"{ } object->string[object_position.stop] = f_fss_delimit_slash; - object->string[object_position.stop + 1] = input.string[input_position.start]; + object->string[object_position.stop + 1] = buffer.string[input->start]; object_position.stop += 2; - input_position.start++; + input->start++; } - while (input_position.start <= input_position.stop) { - if (input.string[input_position.start] == f_fss_delimit_placeholder) { - input_position.start++; + while (input->start <= input->stop) { + if (buffer.string[input->start] == f_fss_delimit_placeholder) { + input->start++; continue; - } else if (isspace(input.string[input_position.start])) { - f_string_length first_space = input_position.start; + } else if (isspace(buffer.string[input->start])) { + f_string_length first_space = input->start; - input_position.start++; + input->start++; - while (input_position.start <= input_position.stop && isspace(input.string[input_position.start])) { - input_position.start++; + while (input->start <= input->stop && isspace(buffer.string[input->start])) { + input->start++; } // while - if (input_position.start > input_position.stop) { + if (input->start > input->stop) { object->string[first_space] = f_fss_basic_open; object->used = object_position.stop + 1; break; } // restart the loop searching for f_fss_delimit_double_quote. - input_position.start = start_position; + input->start = start_position; object_position.stop = object_position.start; object->string[object_position.stop] = f_fss_delimit_double_quote; object_position.stop++; - while (input_position.start <= input_position.stop) { - if (input.string[input_position.start] == f_fss_delimit_placeholder) { - input_position.start++; + while (input->start <= input->stop) { + if (buffer.string[input->start] == f_fss_delimit_placeholder) { + input->start++; continue; - } else if (input.string[input_position.start] == f_fss_delimit_double_quote) { + } else if (buffer.string[input->start] == f_fss_delimit_double_quote) { pre_allocate_size++; if (pre_allocate_size > object->size) { @@ -429,22 +425,22 @@ extern "C"{ object->string[object_position.stop] = f_fss_delimit_slash; object_position.stop++; - } else if (input.string[input_position.start] == f_fss_delimit_slash) { + } else if (buffer.string[input->start] == f_fss_delimit_slash) { f_string_length delimit_slash_count = 0; do { - object->string[object_position.stop] = input.string[input_position.start]; + object->string[object_position.stop] = buffer.string[input->start]; object_position.stop++; delimit_slash_count++; - input_position.start++; + input->start++; - fl_macro_fss_skip_past_delimit_placeholders(input, input_position); + fl_macro_fss_skip_past_delimit_placeholders(buffer, (*input)); - if (input_position.start > input_position.stop) { + if (input->start > input->stop) { break; } - if (input.string[input_position.start] == f_fss_delimit_double_quote) { + if (buffer.string[input->start] == f_fss_delimit_double_quote) { pre_allocate_size += delimit_slash_count; if (pre_allocate_size > object->size) { @@ -454,7 +450,7 @@ extern "C"{ } break; - } else if (input.string[input_position.start] != f_fss_delimit_slash) { + } else if (buffer.string[input->start] != f_fss_delimit_slash) { delimit_slash_count = 0; break; } @@ -469,8 +465,8 @@ extern "C"{ continue; } - object->string[object_position.stop] = input.string[input_position.start]; - input_position.start++; + object->string[object_position.stop] = buffer.string[input->start]; + input->start++; object_position.stop++; } // while @@ -480,8 +476,8 @@ extern "C"{ break; } - object->string[object_position.stop] = input.string[input_position.start]; - input_position.start++; + object->string[object_position.stop] = buffer.string[input->start]; + input->start++; object_position.stop++; } // while @@ -495,7 +491,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(const f_dynamic_string input, f_dynamic_string *content) { + f_return_status fl_fss_basic_content_write(const f_dynamic_string buffer, f_string_location *input, f_dynamic_string *content) { #ifndef _di_level_1_parameter_checking_ if (content == f_null) return f_invalid_parameter; #endif // _di_level_1_parameter_checking_ @@ -503,14 +499,11 @@ extern "C"{ f_status status = f_status_initialize; f_string_location input_position = f_string_location_initialize; - f_string_location content_position = f_string_location_initialize; + f_string_location content_position = f_string_location_initialize; f_string_length pre_allocate_size = f_string_length_initialize; // add an additional 1 to ensure that there is room for the terminating newline. - pre_allocate_size = content->used + (input.used) + 1 + f_fss_default_allocation_step; - - input_position.start = 0; - input_position.stop = input.used; + pre_allocate_size = content->used + (buffer.used) + 1 + f_fss_default_allocation_step; content_position.start = content->used; content_position.stop = content->used; @@ -521,13 +514,13 @@ extern "C"{ if (f_macro_test_for_allocation_errors(status)) return status; } - while (input_position.start <= input_position.stop) { - if (input.string[input_position.start] != f_eol && input.string[input_position.start] != f_fss_delimit_placeholder) { - content->string[content_position.stop] = input.string[input_position.start]; + while (input->start <= input->stop) { + if (buffer.string[input->start] != f_eol && buffer.string[input->start] != f_fss_delimit_placeholder) { + content->string[content_position.stop] = buffer.string[input->start]; content_position.stop++; } - input_position.start++; + input->start++; } // while content->string[content_position.stop] = f_eol; diff --git a/level_1/fl_fss/c/fss_basic.h b/level_1/fl_fss/c/fss_basic.h index c782a21..5bfb5f7 100644 --- a/level_1/fl_fss/c/fss_basic.h +++ b/level_1/fl_fss/c/fss_basic.h @@ -42,12 +42,12 @@ extern "C"{ #ifndef _di_fl_fss_basic_object_write_ // write an fss-0000 object - extern f_return_status fl_fss_basic_object_write(const f_dynamic_string input, f_dynamic_string *object); + extern f_return_status fl_fss_basic_object_write(const f_dynamic_string buffer, f_string_location *input, f_dynamic_string *object); #endif // _di_fl_fss_basic_object_write_ #ifndef _di_fl_fss_basic_content_write_ // write an fss-0000 content - extern f_return_status fl_fss_basic_content_write(const f_dynamic_string input, f_dynamic_string *content); + extern f_return_status fl_fss_basic_content_write(const f_dynamic_string buffer, f_string_location *input, f_dynamic_string *content); #endif // _di_fl_fss_basic_content_write_ #ifdef __cplusplus -- 1.8.3.1