From: Kevin Day Date: Thu, 1 Mar 2012 06:15:11 +0000 (-0600) Subject: Add Project: fl_serialized X-Git-Tag: 0.3.x~13 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=328bd6966c7302db2fa3212e660728d424a0af37;p=fll Add Project: fl_serialized --- diff --git a/level_1/fl_serialized/c/serialized.c b/level_1/fl_serialized/c/serialized.c new file mode 100644 index 0000000..dbaa170 --- /dev/null +++ b/level_1/fl_serialized/c/serialized.c @@ -0,0 +1,137 @@ +/* FLL - Level 1 + * Project: Serialized + * Version: 0.2.0 + * Licenses: lgplv2.1 + * Programmers: Kevin Day + */ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_fl_serialize_ + f_return_status fl_serialize(const f_dynamic_string value, f_serialized *serialized) { + #ifndef _di_level_0_parameter_checking_ + if (serialized == f_null) return f_invalid_parameter; + #endif // _di_level_0_parameter_checking_ + + if (serialized.strategy != f_serialized_strategy_simple) { + return f_unsupported; + } + + f_status status = f_status_initialize; + + if (serialized->used + value.used + 1 >= serialized->size) { + f_resize_serialized(status, (*serialized), serialized->size + value.used + f_serialized_default_allocation_step); + + if (f_macro_test_for_allocation_errors(status)) return status; + } + + memcpy(serialized->string + serialized->used, f_serialized_strategy_simple_splitter, sizeof(f_autochar)); + memcpy(serialized->string + serialized->used + 1, value->string, sizeof(f_autochar) * value.used); + serialized->used += value.used + 1; + + return f_none; + } +#endif // _di_fl_serialize_ + +#ifndef _di_fl_unserialize_ + f_return_status fl_unserialize(const f_serialized *serialized, f_string_locations *locations) { + #ifndef _di_level_0_parameter_checking_ + if (serialized == f_null) return f_invalid_parameter; + if (locations == f_null) return f_invalid_parameter; + #endif // _di_level_0_parameter_checking_ + + if (serialized.strategy != f_serialized_strategy_simple) { + return f_unsupported; + } + + f_status status = f_status_initialize; + + f_array_length i = 0; + f_array_length current = 0; + + f_string_length start = 1; + f_string_length stop = 0; + + while (i < serialized.used) { + if (current == index) { + if (start > stop) { + start = i; + stop = i; + } + + if (serialized.string[i] == f_serialized_strategy_simple_splitter) { + stop = i - 1; + + if (locations->used + 1 >= locations->size) { + f_resize_string_locations(status, (*locations), locations->size + f_serialized_default_allocation_step); + + if (f_macro_test_for_allocation_errors(status)) return status; + } + + locations->array[locations->used].start = start; + locations->array[locations->used].stop = stop; + locations->used++; + + start = 1; + stop = 0; + } + } + else if (serialized.string[i] == f_serialized_strategy_simple_splitter) { + current++; + } + + i++; + } // while + + return f_none; + } +#endif // _di_fl_unserialize_ + +#ifndef _di_fl_unserialize_get_ + f_return_status fl_unserialize_get(const f_serialized serialized, const f_array_length index, f_string_location *location) { + #ifndef _di_level_0_parameter_checking_ + if (serialized == f_null) return f_invalid_parameter; + if (location == f_null) return f_invalid_parameter; + #endif // _di_level_0_parameter_checking_ + + if (serialized.strategy != f_serialized_strategy_simple) { + return f_unsupported; + } + + f_status status = f_status_initialize; + + f_array_length i = 0; + f_array_length current = 0; + + location->start = 1; + location->stop = 0; + + while (i < serialized.used) { + if (current == index){ + if (location->start > location->stop){ + location->start = i; + location->stop = i; + } + + if (serialized.string[i] == f_serialized_strategy_simple_splitter) { + location->stop = i - 1; + break; + } + } + else if (serialized.string[i] == f_serialized_strategy_simple_splitter) { + current++; + } + + i++; + } // while + + return f_none; + } +#endif // _di_fl_unserialize_get_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_1/fl_serialized/c/serialized.h b/level_1/fl_serialized/c/serialized.h new file mode 100644 index 0000000..73a93f8 --- /dev/null +++ b/level_1/fl_serialized/c/serialized.h @@ -0,0 +1,47 @@ +/* FLL - Level 1 + * Project: Serialized + * Version: 0.2.0 + * Licenses: lgplv2.1 + * Programmers: Kevin Day + * Documentation: + * + * Provides string processing functionality for what is to be defined as a serialized string. + * Serialized strings are strings that can hold multiple values in a single variable. + * An example of serialized content is the PATH environment variable where ':" separates data." + */ +#ifndef _FL_serialized_h +#define _FL_serialized_h + +// libc includes +#include + +// fll-0 includes +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_fl_serialize_ + // this function will append a string to the serialize. + extern f_return_status fl_serialize(const f_dynamic_string value, f_serialized *serialized); +#endif // _di_fl_serialize_ + +#ifndef _di_fl_unserialize_ + // this function will unserialize a serialized string and store the results in an array of strings. + extern f_return_status fl_unserialize(const f_serialized serialized, f_string_locations *locations); +#endif // _di_fl_unserialize_ + +#ifndef _di_fl_unserialize_get_ + // this function will pull a single serialized value from the serialized string at the given index. + extern f_return_status fl_unserialize_get(const f_serialized serialized, const f_array_length index, f_string_location *location); +#endif // _di_fl_unserialize_get_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _FL_serialized_h diff --git a/level_1/fl_serialized/data/build/settings b/level_1/fl_serialized/data/build/settings new file mode 100644 index 0000000..527a0a3 --- /dev/null +++ b/level_1/fl_serialized/data/build/settings @@ -0,0 +1,21 @@ +# fss-0000 + +project_name fl_serialized +project_level 1 + +version_major 0 +version_minor 2 +version_micro 0 + +build_compiler gcc +build_libraries -lc +build_sources_library serialized.c +build_sources_program +build_sources_headers serialized.h +build_shared yes + +flags_all -z now +flags_shared +flags_static +flags_library -fPIC +flags_program -fPIE