From: Kevin Day Date: Tue, 5 May 2020 03:01:27 +0000 (-0500) Subject: Update: add back the dynamic_partial functions, add missing functions X-Git-Tag: 0.5.0~291 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=4a2bd06c9aad4fdd7b1753b6ab16e2f8af89b952;p=fll Update: add back the dynamic_partial functions, add missing functions After further review I realized that the dynamic partial behavior is going to be more common. The rip functions are also not the same because it removes leading/trailing whitespace, which may be undesirable. Some of the append_nulless function implementations were missing. Update comments. --- diff --git a/level_1/fl_string/c/string.c b/level_1/fl_string/c/string.c index 9d61eba..41bb209 100644 --- a/level_1/fl_string/c/string.c +++ b/level_1/fl_string/c/string.c @@ -82,6 +82,17 @@ extern "C" { } #endif // _di_fl_string_dynamic_append_ +#ifndef _di_fl_string_dynamic_append_nulless_ + f_return_status fl_string_dynamic_append_nulless(const f_string_dynamic source, f_string_dynamic *destination) { + #ifndef _di_level_1_parameter_checking_ + if (source.used < 1) return f_status_set_error(f_invalid_parameter); + if (destination == 0) return f_status_set_error(f_invalid_parameter); + #endif // _di_level_1_parameter_checking_ + + return private_fl_string_append_nulless(source.string, 0, source.used - 1, destination); + } +#endif // _di_fl_string_dynamic_append_nulless_ + #ifndef _di_fl_string_dynamic_mash_ f_return_status fl_string_dynamic_mash(const f_string glue, const f_string_length glue_length, const f_string_dynamic source, f_string_dynamic *destination) { #ifndef _di_level_1_parameter_checking_ @@ -162,40 +173,180 @@ extern "C" { } #endif // _di_fl_string_dynamic_mish_nulless_ +#ifndef _di_fl_string_dynamic_partial_append_ + f_return_status fl_string_dynamic_partial_append(const f_string_dynamic source, const f_string_location range, f_string_dynamic *destination) { + #ifndef _di_level_1_parameter_checking_ + if (source.used < 1) return f_status_set_error(f_invalid_parameter); + if (range.start > range.stop) return f_status_set_error(f_invalid_parameter); + if (source.used <= range.stop) return f_status_set_error(f_invalid_parameter); + if (destination == 0) return f_status_set_error(f_invalid_parameter); + #endif // _di_level_1_parameter_checking_ + + return private_fl_string_append(source.string, range.start, range.stop, destination); + } +#endif // _di_fl_string_dynamic_partial_append_ + +#ifndef _di_fl_string_dynamic_partial_append_nulless_ + f_return_status fl_string_dynamic_partial_append_nulless(const f_string_dynamic source, const f_string_location range, f_string_dynamic *destination) { + #ifndef _di_level_1_parameter_checking_ + if (source.used < 1) return f_status_set_error(f_invalid_parameter); + if (range.start > range.stop) return f_status_set_error(f_invalid_parameter); + if (source.used <= range.stop) return f_status_set_error(f_invalid_parameter); + if (destination == 0) return f_status_set_error(f_invalid_parameter); + #endif // _di_level_1_parameter_checking_ + + return private_fl_string_append_nulless(source.string, range.start, range.stop, destination); + } +#endif // _di_fl_string_dynamic_append_nulless_ + #ifndef _di_fl_string_dynamic_partial_compare_ - f_return_status fl_string_dynamic_partial_compare(const f_string_dynamic string1, const f_string_dynamic string2, const f_string_location offset1, const f_string_location offset2) { + f_return_status fl_string_dynamic_partial_compare(const f_string_dynamic string1, const f_string_dynamic string2, const f_string_location range1, const f_string_location range2) { #ifndef _di_level_1_parameter_checking_ if (string1.used <= 0) return f_status_set_error(f_invalid_parameter); if (string2.used <= 0) return f_status_set_error(f_invalid_parameter); - if (offset1.start > offset1.stop) return f_status_set_error(f_invalid_parameter); - if (offset2.start > offset2.stop) return f_status_set_error(f_invalid_parameter); + if (range1.start > range1.stop) return f_status_set_error(f_invalid_parameter); + if (range2.start > range2.stop) return f_status_set_error(f_invalid_parameter); - if (string1.used <= offset1.stop) return f_status_set_error(f_invalid_parameter); - if (string2.used <= offset2.stop) return f_status_set_error(f_invalid_parameter); + if (string1.used <= range1.stop) return f_status_set_error(f_invalid_parameter); + if (string2.used <= range2.stop) return f_status_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ - return private_fl_string_compare(string1.string, string2.string, offset1.start, offset2.start, offset1.stop + 1, offset2.stop + 1); + return private_fl_string_compare(string1.string, string2.string, range1.start, range2.start, range1.stop + 1, range2.stop + 1); } #endif // _di_fl_string_dynamic_partial_compare_ #ifndef _di_fl_string_dynamic_partial_compare_trim_ - f_return_status fl_string_dynamic_partial_compare_trim(const f_string_dynamic string1, const f_string_dynamic string2, const f_string_location offset1, const f_string_location offset2) { + f_return_status fl_string_dynamic_partial_compare_trim(const f_string_dynamic string1, const f_string_dynamic string2, const f_string_location range1, const f_string_location range2) { #ifndef _di_level_1_parameter_checking_ if (string1.used <= 0) return f_status_set_error(f_invalid_parameter); if (string2.used <= 0) return f_status_set_error(f_invalid_parameter); - if (offset1.start > offset1.stop) return f_status_set_error(f_invalid_parameter); - if (offset2.start > offset2.stop) return f_status_set_error(f_invalid_parameter); + if (range1.start > range1.stop) return f_status_set_error(f_invalid_parameter); + if (range2.start > range2.stop) return f_status_set_error(f_invalid_parameter); - if (string1.used <= offset1.stop) return f_status_set_error(f_invalid_parameter); - if (string2.used <= offset2.stop) return f_status_set_error(f_invalid_parameter); + if (string1.used <= range1.stop) return f_status_set_error(f_invalid_parameter); + if (string2.used <= range2.stop) return f_status_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ - return private_fl_string_compare_trim(string1.string, string2.string, offset1.start, offset2.start, offset1.stop + 1, offset2.stop + 1); + return private_fl_string_compare_trim(string1.string, string2.string, range1.start, range2.start, range1.stop + 1, range2.stop + 1); } #endif // _di_fl_string_dynamic_partial_compare_trim_ +#ifndef _di_fl_string_dynamic_partial_mash_ + f_return_status fl_string_dynamic_partial_mash(const f_string glue, const f_string_length glue_length, const f_string_dynamic source, const f_string_location range, f_string_dynamic *destination) { + #ifndef _di_level_1_parameter_checking_ + if (glue_length < 1) return f_status_set_error(f_invalid_parameter); + if (source.used < 1) return f_status_set_error(f_invalid_parameter); + if (range.start > range.stop) return f_status_set_error(f_invalid_parameter); + if (source.used <= range.stop) return f_status_set_error(f_invalid_parameter); + if (destination == 0) return f_status_set_error(f_invalid_parameter); + #endif // _di_level_1_parameter_checking_ + + if (destination->used > 0) { + f_status status = private_fl_string_append(glue, 0, glue_length - 1, destination); + + if (f_status_is_error(status)) { + return status; + } + } + + return private_fl_string_append(source.string, range.start, range.stop, destination); + } +#endif // _di_fl_string_dynamic_partial_mash_ + +#ifndef _di_fl_string_dynamic_partial_mash_nulless_ + f_return_status fl_string_dynamic_partial_mash_nulless(const f_string glue, const f_string_length glue_length, const f_string_dynamic source, const f_string_location range, f_string_dynamic *destination) { + #ifndef _di_level_1_parameter_checking_ + if (glue_length < 1) return f_status_set_error(f_invalid_parameter); + if (source.used < 1) return f_status_set_error(f_invalid_parameter); + if (range.start > range.stop) return f_status_set_error(f_invalid_parameter); + if (source.used <= range.stop) return f_status_set_error(f_invalid_parameter); + if (destination == 0) return f_status_set_error(f_invalid_parameter); + #endif // _di_level_1_parameter_checking_ + + if (destination->used > 0) { + f_status status = private_fl_string_append_nulless(glue, 0, glue_length - 1, destination); + + if (f_status_is_error(status)) { + return status; + } + } + + return private_fl_string_append_nulless(source.string, range.start, range.stop, destination); + } +#endif // _di_fl_string_dynamic_partial_mash_nulless_ + +#ifndef _di_fl_string_dynamic_partial_mish_ + f_return_status fl_string_partial_dynamic_mish(const f_string glue, const f_string_length glue_length, const f_string_dynamic source, const f_string_location range, f_string_dynamic *destination) { + #ifndef _di_level_1_parameter_checking_ + if (glue_length < 1) return f_status_set_error(f_invalid_parameter); + if (source.used < 1) return f_status_set_error(f_invalid_parameter); + if (range.start > range.stop) return f_status_set_error(f_invalid_parameter); + if (source.used <= range.stop) return f_status_set_error(f_invalid_parameter); + if (destination == 0) return f_status_set_error(f_invalid_parameter); + #endif // _di_level_1_parameter_checking_ + + if (destination->used > 0) { + f_status status = private_fl_string_prepend(glue, 0, glue_length - 1, destination); + + if (f_status_is_error(status)) { + return status; + } + } + + return private_fl_string_prepend(source.string, range.start, range.stop, destination); + } +#endif // _di_fl_string_dynamic_partial_mish_ + +#ifndef _di_fl_string_dynamic_partial_mish_nulless_ + f_return_status fl_string_dynamic_partial_mish_nulless(const f_string glue, const f_string_length glue_length, const f_string_dynamic source, const f_string_location range, f_string_dynamic *destination) { + #ifndef _di_level_1_parameter_checking_ + if (glue_length < 1) return f_status_set_error(f_invalid_parameter); + if (source.used < 1) return f_status_set_error(f_invalid_parameter); + if (range.start > range.stop) return f_status_set_error(f_invalid_parameter); + if (source.used <= range.stop) return f_status_set_error(f_invalid_parameter); + if (destination == 0) return f_status_set_error(f_invalid_parameter); + #endif // _di_level_1_parameter_checking_ + + if (destination->used > 0) { + f_status status = private_fl_string_prepend_nulless(glue, 0, glue_length - 1, destination); + + if (f_status_is_error(status)) { + return status; + } + } + + return private_fl_string_prepend_nulless(source.string, range.start, range.stop, destination); + } +#endif // _di_fl_string_dynamic_partial_mish_nulless_ + +#ifndef _di_fl_string_dynamic_partial_prepend_ + f_return_status fl_string_dynamic_partial_prepend(const f_string_dynamic source, const f_string_location range, f_string_dynamic *destination) { + #ifndef _di_level_1_parameter_checking_ + if (source.used < 1) return f_status_set_error(f_invalid_parameter); + if (range.start > range.stop) return f_status_set_error(f_invalid_parameter); + if (source.used <= range.stop) return f_status_set_error(f_invalid_parameter); + if (destination == 0) return f_status_set_error(f_invalid_parameter); + #endif // _di_level_1_parameter_checking_ + + return private_fl_string_prepend(source.string, range.start, range.stop, destination); + } +#endif // _di_fl_string_dynamic_partial_prepend_ + +#ifndef _di_fl_string_dynamic_partial_prepend_nulless_ + f_return_status fl_string_dynamic_partial_prepend_nulless(const f_string_dynamic source, const f_string_location range, f_string_dynamic *destination) { + #ifndef _di_level_1_parameter_checking_ + if (source.used < 1) return f_status_set_error(f_invalid_parameter); + if (range.start > range.stop) return f_status_set_error(f_invalid_parameter); + if (source.used <= range.stop) return f_status_set_error(f_invalid_parameter); + if (destination == 0) return f_status_set_error(f_invalid_parameter); + #endif // _di_level_1_parameter_checking_ + + return private_fl_string_prepend_nulless(source.string, range.start, range.stop, destination); + } +#endif // _di_fl_string_dynamic_partial_prepend_nulless + #ifndef _di_fl_string_dynamic_prepend_ f_return_status fl_string_dynamic_prepend(const f_string_dynamic source, f_string_dynamic *destination) { #ifndef _di_level_1_parameter_checking_ @@ -207,31 +358,42 @@ extern "C" { } #endif // _di_fl_string_dynamic_prepend_ +#ifndef _di_fl_string_dynamic_prepend_nulless_ + f_return_status fl_string_dynamic_prepend_nulless(const f_string_dynamic source, f_string_dynamic *destination) { + #ifndef _di_level_1_parameter_checking_ + if (source.used < 1) return f_status_set_error(f_invalid_parameter); + if (destination == 0) return f_status_set_error(f_invalid_parameter); + #endif // _di_level_1_parameter_checking_ + + return private_fl_string_prepend_nulless(source.string, 0, source.used - 1, destination); + } +#endif // _di_fl_string_dynamic_prepend_nulless_ + #ifndef _di_fl_string_dynamic_rip_ - f_return_status fl_string_dynamic_rip(const f_string_dynamic source, const f_string_location offset, f_string_dynamic *destination) { + f_return_status fl_string_dynamic_rip(const f_string_dynamic source, const f_string_location range, f_string_dynamic *destination) { #ifndef _di_level_1_parameter_checking_ - if (offset.stop < offset.start) return f_status_set_error(f_invalid_parameter); + if (range.stop < range.start) return f_status_set_error(f_invalid_parameter); if (source.used <= 0) return f_status_set_error(f_invalid_parameter); - if (source.used <= offset.start) return f_status_set_error(f_invalid_parameter); - if (source.used <= offset.stop) return f_status_set_error(f_invalid_parameter); + if (source.used <= range.start) return f_status_set_error(f_invalid_parameter); + if (source.used <= range.stop) return f_status_set_error(f_invalid_parameter); if (destination == 0) return f_status_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ - return private_fl_string_append(source.string, offset.start, offset.stop, destination); + return private_fl_string_append(source.string, range.start, range.stop, destination); } #endif // _di_fl_string_dynamic_rip_ #ifndef _di_fl_string_dynamic_rip_nulless_ - f_return_status fl_string_dynamic_rip_nulless(const f_string_dynamic source, const f_string_location offset, f_string_dynamic *destination) { + f_return_status fl_string_dynamic_rip_nulless(const f_string_dynamic source, const f_string_location range, f_string_dynamic *destination) { #ifndef _di_level_1_parameter_checking_ - if (offset.stop < offset.start) return f_status_set_error(f_invalid_parameter); + if (range.stop < range.start) return f_status_set_error(f_invalid_parameter); if (source.used <= 0) return f_status_set_error(f_invalid_parameter); - if (source.used <= offset.start) return f_status_set_error(f_invalid_parameter); - if (source.used <= offset.stop) return f_status_set_error(f_invalid_parameter); + if (source.used <= range.start) return f_status_set_error(f_invalid_parameter); + if (source.used <= range.stop) return f_status_set_error(f_invalid_parameter); if (destination == 0) return f_status_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ - return private_fl_string_append_nulless(source.string, offset.start, offset.stop, destination); + return private_fl_string_append_nulless(source.string, range.start, range.stop, destination); } #endif // _di_fl_string_dynamic_rip_nulless_ diff --git a/level_1/fl_string/c/string.h b/level_1/fl_string/c/string.h index 0d681b2..d01393b 100644 --- a/level_1/fl_string/c/string.h +++ b/level_1/fl_string/c/string.h @@ -53,8 +53,7 @@ extern "C" { * f_error_allocation (with error bit) on memory allocation error. * f_error_reallocation (with error bit) on memory reallocation error. * - * @see fl_string_append() - * @see fl_string_dynamic_append() + * @see fl_string_append_nulless() */ #ifndef _di_fl_string_append_ extern f_return_status fl_string_append(const f_string source, const f_string_length start, const f_string_length stop, f_string_dynamic *destination); @@ -81,8 +80,7 @@ extern "C" { * f_error_allocation (with error bit) on memory allocation error. * f_error_reallocation (with error bit) on memory reallocation error. * - * @see fl_string_append_nulless() - * @see fl_string_dynamic_append_nulless() + * @see fl_string_append() */ #ifndef _di_fl_string_append_nulless_ extern f_return_status fl_string_append_nulless(const f_string source, const f_string_length start, const f_string_length stop, f_string_dynamic *destination); @@ -162,8 +160,7 @@ extern "C" { * f_error_allocation (with error bit) on memory allocation error. * f_error_reallocation (with error bit) on memory reallocation error. * - * @see fl_string_append() - * @see fl_string_dynamic_append() + * @see fl_string_dynamic_append_nulless() */ #ifndef _di_fl_string_dynamic_append_ extern f_return_status fl_string_dynamic_append(const f_string_dynamic source, f_string_dynamic *destination); @@ -186,8 +183,7 @@ extern "C" { * f_error_allocation (with error bit) on memory allocation error. * f_error_reallocation (with error bit) on memory reallocation error. * - * @see fl_string_append_nulless() - * @see fl_string_dynamic_append_nulless() + * @see fl_string_dynamic_append() */ #ifndef _di_fl_string_dynamic_append_nulless_ extern f_return_status fl_string_dynamic_append_nulless(const f_string_dynamic source, f_string_dynamic *destination); @@ -265,8 +261,7 @@ extern "C" { * f_error_allocation (with error bit) on memory allocation error. * f_error_reallocation (with error bit) on memory reallocation error. * - * @see fl_string_mash() - * @see fl_string_dynamic_mash() + * @see fl_string_dynamic_mash_nulless() */ #ifndef _di_fl_string_dynamic_mash_ extern f_return_status fl_string_dynamic_mash(const f_string glue, const f_string_length glue_length, const f_string_dynamic source, f_string_dynamic *destination); @@ -295,8 +290,7 @@ extern "C" { * f_error_allocation (with error bit) on memory allocation error. * f_error_reallocation (with error bit) on memory reallocation error. * - * @see fl_string_mash_nulless() - * @see fl_string_dynamic_mash_nulless() + * @see fl_string_dynamic_mash() */ #ifndef _di_fl_string_dynamic_mash_nulless_ extern f_return_status fl_string_dynamic_mash_nulless(const f_string glue, const f_string_length glue_length, const f_string_dynamic source, f_string_dynamic *destination); @@ -323,8 +317,7 @@ extern "C" { * f_error_allocation (with error bit) on memory allocation error. * f_error_reallocation (with error bit) on memory reallocation error. * - * @see fl_string_mish() - * @see fl_string_dynamic_mish() + * @see fl_string_dynamic_mish_nulless() */ #ifndef _di_fl_string_dynamic_mish_ extern f_return_status fl_string_dynamic_mish(const f_string glue, const f_string_length glue_length, const f_string_dynamic source, f_string_dynamic *destination); @@ -353,14 +346,61 @@ extern "C" { * f_error_allocation (with error bit) on memory allocation error. * f_error_reallocation (with error bit) on memory reallocation error. * - * @see fl_string_mish_nulless() - * @see fl_string_dynamic_mish_nulless() + * @see fl_string_dynamic_mish() */ #ifndef _di_fl_string_dynamic_mish_nulless_ extern f_return_status fl_string_dynamic_mish_nulless(const f_string glue, const f_string_length glue_length, const f_string_dynamic source, f_string_dynamic *destination); #endif // _di_fl_string_dynamic_mish_nulless_ /** + * Append the source string onto the destination, but restricted to the given range. + * + * @param source + * The source string to append. + * @param range + * A range within the source to restrict the copy from. + * @param destination + * The destination string the source is appended onto. + * + * @return + * f_none on success. + * f_string_max_size (with error bit) if the combined string is too large. + * f_invalid_parameter (with error bit) if a parameter is invalid. + * f_error_allocation (with error bit) on memory allocation error. + * f_error_reallocation (with error bit) on memory reallocation error. + * + * @see fl_string_dynamic_partial_append_nulless() + */ +#ifndef _di_fl_string_dynamic_partial_append_ + extern f_return_status fl_string_dynamic_partial_append(const f_string_dynamic source, const f_string_location range, f_string_dynamic *destination); +#endif // _di_fl_string_dynamic_partial_append_ + +/** + * Append the source string onto the destination, but restricted to the given range. + * + * Skips over NULL characters from source when appending. + * + * @param source + * The source string to append. + * @param range + * A range within the source to restrict the copy from. + * @param destination + * The destination string the source is appended onto. + * + * @return + * f_none on success. + * f_string_max_size (with error bit) if the combined string is too large. + * f_invalid_parameter (with error bit) if a parameter is invalid. + * f_error_allocation (with error bit) on memory allocation error. + * f_error_reallocation (with error bit) on memory reallocation error. + * + * @see fl_string_dynamic_partial_append() + */ +#ifndef _di_fl_string_dynamic_partial_append_nulless_ + extern f_return_status fl_string_dynamic_partial_append_nulless(const f_string_dynamic source, const f_string_location range, f_string_dynamic *destination); +#endif // _di_fl_string_dynamic_partial_append_nulless_ + +/** * Compare two strings, similar to strncmp(), but restricted to the given ranges. * * This does not stop on NULL. @@ -370,9 +410,9 @@ extern "C" { * String to compare. * @param string2 * String to compare. - * @param offset1 + * @param range1 * A range within the string1 to restrict the comparison to. - * @param offset2 + * @param range2 * A range within the string2 to restrict the comparison to. * * @return @@ -386,7 +426,7 @@ extern "C" { * @see fl_string_dynamic_compare_trim() */ #ifndef _di_fl_string_dynamic_partial_compare_ - extern f_return_status fl_string_dynamic_partial_compare(const f_string_dynamic string1, const f_string_dynamic string2, const f_string_location offset1, const f_string_location offset2); + extern f_return_status fl_string_dynamic_partial_compare(const f_string_dynamic string1, const f_string_dynamic string2, const f_string_location range1, const f_string_location range2); #endif // _di_fl_string_dynamic_partial_compare_ /** @@ -400,9 +440,9 @@ extern "C" { * String to compare. * @param string2 * String to compare. - * @param offset1 + * @param range1 * A range within the string1 to restrict the comparison to. - * @param offset2 + * @param range2 * A range within the string2 to restrict the comparison to. * * @return @@ -416,10 +456,180 @@ extern "C" { * @see fl_string_dynamic_compare_trim() */ #ifndef _di_fl_string_dynamic_partial_compare_trim_ - extern f_return_status fl_string_dynamic_partial_compare_trim(const f_string_dynamic string1, const f_string_dynamic string2, const f_string_location offset1, const f_string_location offset2); + extern f_return_status fl_string_dynamic_partial_compare_trim(const f_string_dynamic string1, const f_string_dynamic string2, const f_string_location range1, const f_string_location range2); #endif // _di_fl_string_dynamic_partial_compare_trim_ /** + * Append the source string onto the destination with the glue in between, but restricted to the given range. + * + * If the destination string is empty, then no glue is appended. + * + * @param glue + * A string to append between the source and destination, such as a space: ' '. + * @param glue_length + * The number of bytes the glue takes up. + * @param source + * The source string to append. + * @param range + * A range within the source to restrict the copy from. + * @param destination + * The destination string the source and glue are appended onto. + * + * @return + * f_none on success. + * f_string_max_size (with error bit) if the combined string is too large. + * f_invalid_parameter (with error bit) if a parameter is invalid. + * f_error_allocation (with error bit) on memory allocation error. + * f_error_reallocation (with error bit) on memory reallocation error. + * + * @see fl_string_dynamic_partial_mash_nulless() + */ +#ifndef _di_fl_string_dynamic_partial_mash_ + extern f_return_status fl_string_dynamic_partial_mash(const f_string glue, const f_string_length glue_length, const f_string_dynamic source, const f_string_location range, f_string_dynamic *destination); +#endif // _di_fl_string_dynamic_partial_mash_ + +/** + * Append the source string onto the destination with the glue in between, but restricted to the given range. + * + * If the destination string is empty, then no glue is appended. + * + * Skips over NULL characters from glue and source when appending. + * + * @param glue + * A string to append between the source and destination, such as a space: ' '. + * @param glue_length + * The number of bytes the glue takes up. + * @param source + * The source string to append. + * @param range + * A range within the source to restrict the copy from. + * @param destination + * The destination string the source and glue are appended onto. + * + * @return + * f_none on success. + * f_string_max_size (with error bit) if the combined string is too large. + * f_invalid_parameter (with error bit) if a parameter is invalid. + * f_error_allocation (with error bit) on memory allocation error. + * f_error_reallocation (with error bit) on memory reallocation error. + * + * @see fl_string_dynamic_partial_mash() + */ +#ifndef _di_fl_string_dynamic_partial_mash_nulless_ + extern f_return_status fl_string_dynamic_partial_mash_nulless(const f_string glue, const f_string_length glue_length, const f_string_dynamic source, const f_string_location range, f_string_dynamic *destination); +#endif // _di_fl_string_dynamic_partial_mash_nulless_ + +/** + * Prepend the source string onto the destination with the glue in between, but restricted to the given range. + * + * If the destination string is empty, then no glue is appended. + * + * @param glue + * A string to append between the source and destination, such as a space: ' '. + * @param glue_length + * The number of bytes the glue takes up. + * @param source + * The source string to append. + * @param range + * A range within the source to restrict the copy from. + * @param destination + * The destination string the source and glue are appended onto. + * + * @return + * f_none on success. + * f_string_max_size (with error bit) if the combined string is too large. + * f_invalid_parameter (with error bit) if a parameter is invalid. + * f_error_allocation (with error bit) on memory allocation error. + * f_error_reallocation (with error bit) on memory reallocation error. + * + * @see fl_string_dynamic_partial_mish_nulless() + */ +#ifndef _di_fl_string_dynamic_partial_mish_ + extern f_return_status fl_string_dynamic_partial_mish(const f_string glue, const f_string_length glue_length, const f_string_dynamic source, const f_string_location range, f_string_dynamic *destination); +#endif // _di_fl_string_dynamic_partial_mish_ + +/** + * Prepend the source string onto the destination with the glue in between, but restricted to the given range. + * + * If the destination string is empty, then no glue is appended. + * + * Skips over NULL characters from glue and source when appending. + * + * @param glue + * A string to append between the source and destination, such as a space: ' '. + * @param glue_length + * The number of bytes the glue takes up. + * @param source + * The source string to append. + * @param range + * A range within the source to restrict the copy from. + * @param destination + * The destination string the source and glue are appended onto. + * + * @return + * f_none on success. + * f_string_max_size (with error bit) if the combined string is too large. + * f_invalid_parameter (with error bit) if a parameter is invalid. + * f_error_allocation (with error bit) on memory allocation error. + * f_error_reallocation (with error bit) on memory reallocation error. + * + * @see fl_string_dynamic_partial_mish() + */ +#ifndef _di_fl_string_dynamic_partial_mish_nulless_ + extern f_return_status fl_string_dynamic_partial_mish_nulless(const f_string glue, const f_string_length glue_length, const f_string_dynamic source, const f_string_location range, f_string_dynamic *destination); +#endif // _di_fl_string_dynamic_partial_mish_nulless_ + +/** + * Prepend the source string onto the destination, but restricted to the given range. + * + * Prepend operations require memory move operations and are therefore likely more expensive than append operations. + * + * @param source + * The source string to prepend. + * @param range + * A range within the source to restrict the copy from. + * @param destination + * The destination string the source is prepended onto. + * + * @return + * f_none on success. + * f_string_max_size (with error bit) if the combined string is too large. + * f_invalid_parameter (with error bit) if a parameter is invalid. + * f_error_allocation (with error bit) on memory allocation error. + * f_error_reallocation (with error bit) on memory reallocation error. + * + * @see fl_string_dynamic_partial_prepend_nulless() + */ +#ifndef _di_fl_string_dynamic_partial_prepend_ + extern f_return_status fl_string_dynamic_partial_prepend(const f_string_dynamic source, const f_string_location range, f_string_dynamic *destination); +#endif // _di_fl_string_dynamic_partial_prepend_ + +/** + * Prepend the source string onto the destination, but restricted to the given range. + * + * Prepend operations require memory move operations and are therefore likely more expensive than append operations. + * + * @param source + * The source string to prepend. + * @param range + * A range within the source to restrict the copy from. + * @param destination + * The destination string the source is prepended onto. + * + * @return + * f_none on success. + * f_string_max_size (with error bit) if the combined string is too large. + * f_invalid_parameter (with error bit) if a parameter is invalid. + * f_error_allocation (with error bit) on memory allocation error. + * f_error_reallocation (with error bit) on memory reallocation error. + * + * @see fl_string_dynamic_partial_prepend() + */ +#ifndef _di_fl_string_dynamic_partial_prepend_nulless_ + extern f_return_status fl_string_dynamic_partial_prepend_nulless(const f_string_dynamic source, const f_string_location range, f_string_dynamic *destination); +#endif // _di_fl_string_dynamic_partial_prepend_nulless_ + +/** * Prepend the source string onto the destination. * * Prepend operations require memory move operations and are therefore likely more expensive than append operations. @@ -436,7 +646,7 @@ extern "C" { * f_error_allocation (with error bit) on memory allocation error. * f_error_reallocation (with error bit) on memory reallocation error. * - * @see fl_string_prepend() + * @see fl_string_dynamic_prepend_nulless() */ #ifndef _di_fl_string_dynamic_prepend_ extern f_return_status fl_string_dynamic_prepend(const f_string_dynamic source, f_string_dynamic *destination); @@ -459,7 +669,7 @@ extern "C" { * f_error_allocation (with error bit) on memory allocation error. * f_error_reallocation (with error bit) on memory reallocation error. * - * @see fl_string_prepend_nulless() + * @see fl_string_dynamic_prepend() */ #ifndef _di_fl_string_dynamic_prepend_nulless_ extern f_return_status fl_string_dynamic_prepend_nulless(const f_string_dynamic source, f_string_dynamic *destination); @@ -473,7 +683,7 @@ extern "C" { * * @param source * The buffer to rip from. - * @param offset + * @param range * A range within the buffer representing the string to rip. * @param destination * The new string, which will be allocated or reallocated as necessary. @@ -485,12 +695,10 @@ extern "C" { * f_error_allocation (with error bit) on memory allocation error. * f_error_reallocation (with error bit) on memory reallocation error. * - * @see fl_string_append() - * @see fl_string_dynamic_append() - * @see fl_string_dynamic_rip() + * @see fl_string_dynamic_rip_nulless() */ #ifndef _di_fl_string_dynamic_rip_ - extern f_return_status fl_string_dynamic_rip(const f_string_dynamic source, const f_string_location offset, f_string_dynamic *destination); + extern f_return_status fl_string_dynamic_rip(const f_string_dynamic source, const f_string_location range, f_string_dynamic *destination); #endif // _di_fl_string_dynamic_rip_ /** @@ -503,7 +711,7 @@ extern "C" { * * @param source * The string to rip from. - * @param offset + * @param range * A range within the buffer representing the string to rip. * @param destination * The new string, which will be allocated or reallocated as necessary. @@ -515,12 +723,10 @@ extern "C" { * f_error_allocation (with error bit) on memory allocation error. * f_error_reallocation (with error bit) on memory reallocation error. * - * @see fl_string_append_nulless() - * @see fl_string_dynamic_append_nulless() - * @see fl_string_dynamic_rip_nulless() + * @see fl_string_dynamic_rip() */ #ifndef _di_fl_string_dynamic_rip_nulless_ - extern f_return_status fl_string_dynamic_rip_nulless(const f_string_dynamic source, const f_string_location offset, f_string_dynamic *destination); + extern f_return_status fl_string_dynamic_rip_nulless(const f_string_dynamic source, const f_string_location range, f_string_dynamic *destination); #endif // _di_fl_string_dynamic_rip_nulless_ /** @@ -713,8 +919,7 @@ extern "C" { * f_error_allocation (with error bit) on memory allocation error. * f_error_reallocation (with error bit) on memory reallocation error. * - * @see fl_string_mash() - * @see fl_string_dynamic_mash() + * @see fl_string_mash_nulless() */ #ifndef _di_fl_string_mash_ extern f_return_status fl_string_mash(const f_string glue, const f_string_length glue_length, const f_string source, const f_string_length start, const f_string_length stop, f_string_dynamic *destination); @@ -747,8 +952,7 @@ extern "C" { * f_error_allocation (with error bit) on memory allocation error. * f_error_reallocation (with error bit) on memory reallocation error. * - * @see fl_string_mash_nulless() - * @see fl_string_dynamic_mash_nulless() + * @see fl_string_mash() */ #ifndef _di_fl_string_mash_nulless_ extern f_return_status fl_string_mash_nulless(const f_string glue, const f_string_length glue_length, const f_string source, const f_string_length start, const f_string_length stop, f_string_dynamic *destination); @@ -779,8 +983,7 @@ extern "C" { * f_error_allocation (with error bit) on memory allocation error. * f_error_reallocation (with error bit) on memory reallocation error. * - * @see fl_string_mish() - * @see fl_string_dynamic_mish() + * @see fl_string_mish_nulless() */ #ifndef _di_fl_string_mish_ extern f_return_status fl_string_mish(const f_string glue, const f_string_length glue_length, const f_string source, const f_string_length start, const f_string_length stop, f_string_dynamic *destination); @@ -813,8 +1016,7 @@ extern "C" { * f_error_allocation (with error bit) on memory allocation error. * f_error_reallocation (with error bit) on memory reallocation error. * - * @see fl_string_mish_nulless() - * @see fl_string_dynamic_mish_nulless() + * @see fl_string_mish() */ #ifndef _di_fl_string_mish_nulless_ extern f_return_status fl_string_mish_nulless(const f_string glue, const f_string_length glue_length, const f_string source, const f_string_length start, const f_string_length stop, f_string_dynamic *destination); @@ -841,7 +1043,7 @@ extern "C" { * f_error_allocation (with error bit) on memory allocation error. * f_error_reallocation (with error bit) on memory reallocation error. * - * @see fl_string_dynamic_prepend() + * @see fl_string_prepend_nulless() */ #ifndef _di_fl_string_prepend_ extern f_return_status fl_string_prepend(const f_string source, const f_string_length start, const f_string_length stop, f_string_dynamic *destination); @@ -870,7 +1072,7 @@ extern "C" { * f_error_allocation (with error bit) on memory allocation error. * f_error_reallocation (with error bit) on memory reallocation error. * - * @see fl_string_dynamic_prepend_nulless() + * @see fl_string_dynamic_prepend() */ #ifndef _di_fl_string_prepend_nulless_ extern f_return_status fl_string_prepend_nulless(const f_string source, const f_string_length start, const f_string_length stop, f_string_dynamic *destination); @@ -898,8 +1100,7 @@ extern "C" { * f_error_allocation (with error bit) on memory allocation error. * f_error_reallocation (with error bit) on memory reallocation error. * - * @see fl_string_append() - * @see fl_string_dynamic_append() + * @see fl_string_rip_nulless() */ #ifndef _di_fl_string_rip_ extern f_return_status fl_string_rip(const f_string source, const f_string_length start, const f_string_length stop, f_string_dynamic *destination); @@ -929,8 +1130,7 @@ extern "C" { * f_error_allocation (with error bit) on memory allocation error. * f_error_reallocation (with error bit) on memory reallocation error. * - * @see fl_string_append_nulless() - * @see fl_string_dynamic_rip_nulless() + * @see fl_string_rip() */ #ifndef _di_fl_string_rip_nulless_ extern f_return_status fl_string_rip_nulless(const f_string source, const f_string_length start, const f_string_length stop, f_string_dynamic *destination); diff --git a/level_1/fl_utf/c/utf.c b/level_1/fl_utf/c/utf.c index 9bf9443..f2ec2f8 100644 --- a/level_1/fl_utf/c/utf.c +++ b/level_1/fl_utf/c/utf.c @@ -60,6 +60,17 @@ extern "C" { } #endif // _di_fl_utf_string_dynamic_append_ +#ifndef _di_fl_utf_string_dynamic_append_nulless_ + f_return_status fl_utf_string_dynamic_append_nulless(const f_utf_string_dynamic source, f_utf_string_dynamic *destination) { + #ifndef _di_level_1_parameter_checking_ + if (source.used < 1) return f_status_set_error(f_invalid_parameter); + if (destination == 0) return f_status_set_error(f_invalid_parameter); + #endif // _di_level_1_parameter_checking_ + + return private_fl_utf_string_append_nulless(source.string, 0, source.used - 1, destination); + } +#endif // _di_fl_utf_string_dynamic_append_nulless_ + #ifndef _di_fl_utf_string_dynamic_mash_ f_return_status fl_utf_string_dynamic_mash(const f_utf_string glue, const f_utf_string_length glue_length, const f_utf_string_dynamic source, f_utf_string_dynamic *destination) { #ifndef _di_level_1_parameter_checking_ @@ -162,40 +173,180 @@ extern "C" { } #endif // _di_f_utf_string_dynamic_compare_trim_ +#ifndef _di_fl_utf_string_dynamic_partial_append_ + f_return_status fl_utf_string_dynamic_partial_append(const f_utf_string_dynamic source, const f_utf_string_location range, f_utf_string_dynamic *destination) { + #ifndef _di_level_1_parameter_checking_ + if (source.used < 1) return f_status_set_error(f_invalid_parameter); + if (range.start > range.stop) return f_status_set_error(f_invalid_parameter); + if (source.used <= range.stop) return f_status_set_error(f_invalid_parameter); + if (destination == 0) return f_status_set_error(f_invalid_parameter); + #endif // _di_level_1_parameter_checking_ + + return private_fl_utf_string_append(source.string, range.start, range.stop, destination); + } +#endif // _di_fl_utf_string_dynamic_partial_append_ + +#ifndef _di_fl_utf_string_dynamic_partial_append_nulless_ + f_return_status fl_utf_string_dynamic_partial_append_nulless(const f_utf_string_dynamic source, const f_utf_string_location range, f_utf_string_dynamic *destination) { + #ifndef _di_level_1_parameter_checking_ + if (source.used < 1) return f_status_set_error(f_invalid_parameter); + if (range.start > range.stop) return f_status_set_error(f_invalid_parameter); + if (source.used <= range.stop) return f_status_set_error(f_invalid_parameter); + if (destination == 0) return f_status_set_error(f_invalid_parameter); + #endif // _di_level_1_parameter_checking_ + + return private_fl_utf_string_append_nulless(source.string, range.start, range.stop, destination); + } +#endif // _di_fl_utf_string_dynamic_partial_append_nulless_ + #ifndef _di_fl_utf_string_dynamic_partial_compare_ - f_return_status fl_utf_string_dynamic_partial_compare(const f_utf_string_dynamic string1, const f_utf_string_dynamic string2, const f_utf_string_location offset1, const f_utf_string_location offset2) { + f_return_status fl_utf_string_dynamic_partial_compare(const f_utf_string_dynamic string1, const f_utf_string_dynamic string2, const f_utf_string_location range1, const f_utf_string_location range2) { #ifndef _di_level_1_parameter_checking_ if (string1.used <= 0) return f_status_set_error(f_invalid_parameter); if (string2.used <= 0) return f_status_set_error(f_invalid_parameter); - if (offset1.start > offset1.stop) return f_status_set_error(f_invalid_parameter); - if (offset2.start > offset2.stop) return f_status_set_error(f_invalid_parameter); + if (range1.start > range1.stop) return f_status_set_error(f_invalid_parameter); + if (range2.start > range2.stop) return f_status_set_error(f_invalid_parameter); - if (string1.used <= offset1.stop) return f_status_set_error(f_invalid_parameter); - if (string2.used <= offset2.stop) return f_status_set_error(f_invalid_parameter); + if (string1.used <= range1.stop) return f_status_set_error(f_invalid_parameter); + if (string2.used <= range2.stop) return f_status_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ - return private_fl_utf_string_compare(string1.string, string2.string, offset1.start, offset2.start, offset1.stop + 1, offset2.stop + 1); + return private_fl_utf_string_compare(string1.string, string2.string, range1.start, range2.start, range1.stop + 1, range2.stop + 1); } #endif // _di_fl_utf_string_dynamic_partial_compare_ #ifndef _di_fl_utf_string_dynamic_partial_compare_trim_ - f_return_status fl_utf_string_dynamic_partial_comparetrim(const f_utf_string_dynamic string1, const f_utf_string_dynamic string2, const f_utf_string_location offset1, const f_utf_string_location offset2) { + f_return_status fl_utf_string_dynamic_partial_comparetrim(const f_utf_string_dynamic string1, const f_utf_string_dynamic string2, const f_utf_string_location range1, const f_utf_string_location range2) { #ifndef _di_level_1_parameter_checking_ if (string1.used <= 0) return f_status_set_error(f_invalid_parameter); if (string2.used <= 0) return f_status_set_error(f_invalid_parameter); - if (offset1.start > offset1.stop) return f_status_set_error(f_invalid_parameter); - if (offset2.start > offset2.stop) return f_status_set_error(f_invalid_parameter); + if (range1.start > range1.stop) return f_status_set_error(f_invalid_parameter); + if (range2.start > range2.stop) return f_status_set_error(f_invalid_parameter); - if (string1.used <= offset1.stop) return f_status_set_error(f_invalid_parameter); - if (string2.used <= offset2.stop) return f_status_set_error(f_invalid_parameter); + if (string1.used <= range1.stop) return f_status_set_error(f_invalid_parameter); + if (string2.used <= range2.stop) return f_status_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ - return private_fl_utf_string_compare_trim(string1.string, string2.string, offset1.start, offset2.start, offset1.stop + 1, offset2.stop + 1); + return private_fl_utf_string_compare_trim(string1.string, string2.string, range1.start, range2.start, range1.stop + 1, range2.stop + 1); } #endif // _di_fl_utf_string_dynamic_partial_compare_trim_ +#ifndef _di_fl_utf_string_dynamic_partial_mash_ + f_return_status fl_utf_string_dynamic_partial_mash(const f_utf_string glue, const f_utf_string_length glue_length, const f_utf_string_dynamic source, const f_utf_string_location range, f_utf_string_dynamic *destination) { + #ifndef _di_level_1_parameter_checking_ + if (glue_length < 1) return f_status_set_error(f_invalid_parameter); + if (source.used < 1) return f_status_set_error(f_invalid_parameter); + if (range.start > range.stop) return f_status_set_error(f_invalid_parameter); + if (source.used <= range.stop) return f_status_set_error(f_invalid_parameter); + if (destination == 0) return f_status_set_error(f_invalid_parameter); + #endif // _di_level_1_parameter_checking_ + + if (destination->used > 0) { + f_status status = private_fl_utf_string_append(glue, 0, glue_length - 1, destination); + + if (f_status_is_error(status)) { + return status; + } + } + + return private_fl_utf_string_append(source.string, range.start, range.stop, destination); + } +#endif // _di_fl_utf_string_dynamic_partial_mash_ + +#ifndef _di_fl_utf_string_dynamic_partial_mash_nulless_ + f_return_status fl_utf_string_dynamic_partial_mash_nulless(const f_utf_string glue, const f_utf_string_length glue_length, const f_utf_string_dynamic source, const f_utf_string_location range, f_utf_string_dynamic *destination) { + #ifndef _di_level_1_parameter_checking_ + if (glue_length < 1) return f_status_set_error(f_invalid_parameter); + if (source.used < 1) return f_status_set_error(f_invalid_parameter); + if (range.start > range.stop) return f_status_set_error(f_invalid_parameter); + if (source.used <= range.stop) return f_status_set_error(f_invalid_parameter); + if (destination == 0) return f_status_set_error(f_invalid_parameter); + #endif // _di_level_1_parameter_checking_ + + if (destination->used > 0) { + f_status status = private_fl_utf_string_append_nulless(glue, 0, glue_length - 1, destination); + + if (f_status_is_error(status)) { + return status; + } + } + + return private_fl_utf_string_append_nulless(source.string, range.start, range.stop, destination); + } +#endif // _di_fl_utf_string_dynamic_partial_mash_nulless_ + +#ifndef _di_fl_utf_string_dynamic_partial_mish_ + f_return_status fl_utf_string_dynamic_partial_mish(const f_utf_string glue, const f_utf_string_length glue_length, const f_utf_string_dynamic source, const f_utf_string_location range, f_utf_string_dynamic *destination) { + #ifndef _di_level_1_parameter_checking_ + if (glue_length < 1) return f_status_set_error(f_invalid_parameter); + if (source.used < 1) return f_status_set_error(f_invalid_parameter); + if (range.start > range.stop) return f_status_set_error(f_invalid_parameter); + if (source.used <= range.stop) return f_status_set_error(f_invalid_parameter); + if (destination == 0) return f_status_set_error(f_invalid_parameter); + #endif // _di_level_1_parameter_checking_ + + if (destination->used > 0) { + f_status status = private_fl_utf_string_prepend(glue, 0, glue_length - 1, destination); + + if (f_status_is_error(status)) { + return status; + } + } + + return private_fl_utf_string_prepend(source.string, range.start, range.stop, destination); + } +#endif // _di_fl_utf_string_dynamic_partial_mish_ + +#ifndef _di_fl_utf_string_dynamic_partial_mish_nulless_ + f_return_status fl_utf_string_dynamic_partial_mish_nulless(const f_utf_string glue, const f_utf_string_length glue_length, const f_utf_string_dynamic source, const f_utf_string_location range, f_utf_string_dynamic *destination) { + #ifndef _di_level_1_parameter_checking_ + if (glue_length < 1) return f_status_set_error(f_invalid_parameter); + if (source.used < 1) return f_status_set_error(f_invalid_parameter); + if (range.start > range.stop) return f_status_set_error(f_invalid_parameter); + if (source.used <= range.stop) return f_status_set_error(f_invalid_parameter); + if (destination == 0) return f_status_set_error(f_invalid_parameter); + #endif // _di_level_1_parameter_checking_ + + if (destination->used > 0) { + f_status status = private_fl_utf_string_prepend_nulless(glue, 0, glue_length - 1, destination); + + if (f_status_is_error(status)) { + return status; + } + } + + return private_fl_utf_string_prepend_nulless(source.string, range.start, range.stop, destination); + } +#endif // _di_fl_utf_string_dynamic_partial_mish_nulless_ + +#ifndef _di_fl_utf_string_dynamic_partial_prepend_ + f_return_status fl_utf_string_dynamic_partial_prepend(const f_utf_string_dynamic source, const f_utf_string_location range, f_utf_string_dynamic *destination) { + #ifndef _di_level_1_parameter_checking_ + if (source.used < 1) return f_status_set_error(f_invalid_parameter); + if (range.start > range.stop) return f_status_set_error(f_invalid_parameter); + if (source.used <= range.stop) return f_status_set_error(f_invalid_parameter); + if (destination == 0) return f_status_set_error(f_invalid_parameter); + #endif // _di_level_1_parameter_checking_ + + return private_fl_utf_string_prepend(source.string, range.start, range.stop, destination); + } +#endif // _di_fl_utf_string_dynamic_partial_prepend_ + +#ifndef _di_fl_utf_string_dynamic_partial_prepend_nulless_ + f_return_status fl_utf_string_dynamic_partial_prepend_nulless(const f_utf_string_dynamic source, const f_utf_string_location range, f_utf_string_dynamic *destination) { + #ifndef _di_level_1_parameter_checking_ + if (source.used < 1) return f_status_set_error(f_invalid_parameter); + if (range.start > range.stop) return f_status_set_error(f_invalid_parameter); + if (source.used <= range.stop) return f_status_set_error(f_invalid_parameter); + if (destination == 0) return f_status_set_error(f_invalid_parameter); + #endif // _di_level_1_parameter_checking_ + + return private_fl_utf_string_prepend_nulless(source.string, range.start, range.stop, destination); + } +#endif // _di_fl_utf_string_dynamic_partial_prepend_nulless_ + #ifndef _di_fl_utf_string_dynamic_prepend_ f_return_status fl_utf_string_dynamic_prepend(const f_utf_string_dynamic source, f_utf_string_dynamic *destination) { #ifndef _di_level_1_parameter_checking_ @@ -207,31 +358,42 @@ extern "C" { } #endif // _di_fl_utf_string_dynamic_prepend_ +#ifndef _di_fl_utf_string_dynamic_prepend_nulless_ + f_return_status fl_utf_string_dynamic_prepend_nulless(const f_utf_string_dynamic source, f_utf_string_dynamic *destination) { + #ifndef _di_level_1_parameter_checking_ + if (source.used < 1) return f_status_set_error(f_invalid_parameter); + if (destination == 0) return f_status_set_error(f_invalid_parameter); + #endif // _di_level_1_parameter_checking_ + + return private_fl_utf_string_prepend_nulless(source.string, 0, source.used - 1, destination); + } +#endif // _di_fl_utf_string_dynamic_prepend_nulless_ + #ifndef _di_fl_utf_string_dynamic_rip_ - f_return_status fl_utf_string_dynamic_rip(const f_utf_string_dynamic source, const f_utf_string_location offset, f_utf_string_dynamic *destination) { + f_return_status fl_utf_string_dynamic_rip(const f_utf_string_dynamic source, const f_utf_string_location range, f_utf_string_dynamic *destination) { #ifndef _di_level_1_parameter_checking_ - if (offset.stop < offset.start) return f_status_set_error(f_invalid_parameter); + if (range.stop < range.start) return f_status_set_error(f_invalid_parameter); if (source.used <= 0) return f_status_set_error(f_invalid_parameter); - if (source.used <= offset.start) return f_status_set_error(f_invalid_parameter); - if (source.used <= offset.stop) return f_status_set_error(f_invalid_parameter); + if (source.used <= range.start) return f_status_set_error(f_invalid_parameter); + if (source.used <= range.stop) return f_status_set_error(f_invalid_parameter); if (destination == 0) return f_status_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ - return private_fl_utf_string_append(source.string, offset.start, offset.stop, destination); + return private_fl_utf_string_append(source.string, range.start, range.stop, destination); } #endif // _di_fl_utf_string_dynamic_rip_ #ifndef _di_fl_utf_string_dynamic_rip_nulless_ - f_return_status fl_utf_string_dynamic_rip_nulless(const f_utf_string_dynamic source, const f_utf_string_location offset, f_utf_string_dynamic *destination) { + f_return_status fl_utf_string_dynamic_rip_nulless(const f_utf_string_dynamic source, const f_utf_string_location range, f_utf_string_dynamic *destination) { #ifndef _di_level_1_parameter_checking_ - if (offset.stop < offset.start) return f_status_set_error(f_invalid_parameter); + if (range.stop < range.start) return f_status_set_error(f_invalid_parameter); if (source.used <= 0) return f_status_set_error(f_invalid_parameter); - if (source.used <= offset.start) return f_status_set_error(f_invalid_parameter); - if (source.used <= offset.stop) return f_status_set_error(f_invalid_parameter); + if (source.used <= range.start) return f_status_set_error(f_invalid_parameter); + if (source.used <= range.stop) return f_status_set_error(f_invalid_parameter); if (destination == 0) return f_status_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ - return private_fl_utf_string_append_nulless(source.string, offset.start, offset.stop, destination); + return private_fl_utf_string_append_nulless(source.string, range.start, range.stop, destination); } #endif // _di_fl_utf_string_dynamic_rip_nulless_ diff --git a/level_1/fl_utf/c/utf.h b/level_1/fl_utf/c/utf.h index b08365b..fd42bfd 100644 --- a/level_1/fl_utf/c/utf.h +++ b/level_1/fl_utf/c/utf.h @@ -53,8 +53,7 @@ extern "C" { * f_error_allocation (with error bit) on memory allocation error. * f_error_reallocation (with error bit) on memory reallocation error. * - * @see fl_utf_string_append() - * @see fl_utf_string_dynamic_append() + * @see fl_utf_string_append_nulless() */ #ifndef _di_fl_utf_string_append_ extern f_return_status fl_utf_string_append(const f_utf_string source, const f_utf_string_length start, const f_utf_string_length stop, f_utf_string_dynamic *destination); @@ -81,8 +80,7 @@ extern "C" { * f_error_allocation (with error bit) on memory allocation error. * f_error_reallocation (with error bit) on memory reallocation error. * - * @see fl_utf_string_append_nulless() - * @see fl_utf_string_dynamic_append_nulless() + * @see fl_utf_string_append() */ #ifndef _di_fl_utf_string_append_nulless_ extern f_return_status fl_utf_string_append_nulless(const f_utf_string source, const f_utf_string_length start, const f_utf_string_length stop, f_utf_string_dynamic *destination); @@ -164,8 +162,7 @@ extern "C" { * f_error_allocation (with error bit) on memory allocation error. * f_error_reallocation (with error bit) on memory reallocation error. * - * @see fl_utf_string_append() - * @see fl_utf_string_dynamic_append() + * @see fl_utf_string_dynamic_append_nulless() */ #ifndef _di_fl_utf_string_dynamic_append_ extern f_return_status fl_utf_string_dynamic_append(const f_utf_string_dynamic source, f_utf_string_dynamic *destination); @@ -188,8 +185,7 @@ extern "C" { * f_error_allocation (with error bit) on memory allocation error. * f_error_reallocation (with error bit) on memory reallocation error. * - * @see fl_utf_string_append_nulless() - * @see fl_utf_string_dynamic_append_nulless() + * @see fl_utf_string_dynamic_append() */ #ifndef _di_fl_utf_string_dynamic_append_nulless_ extern f_return_status fl_utf_string_dynamic_append_nulless(const f_utf_string_dynamic source, f_utf_string_dynamic *destination); @@ -365,6 +361,54 @@ extern "C" { #endif // _di_fl_utf_string_dynamic_mish_nulless_ /** + * Append the source UTF-8 string onto the destination, but restricted to the given range. + * + * @param source + * The source string to append. + * @param range + * A range within the source to restrict the copy from. + * @param destination + * The destination string the source is appended onto. + * + * @return + * f_none on success. + * f_string_max_size (with error bit) if the combined string is too large. + * f_invalid_parameter (with error bit) if a parameter is invalid. + * f_error_allocation (with error bit) on memory allocation error. + * f_error_reallocation (with error bit) on memory reallocation error. + * + * @see fl_utf_string_dynamic_partial_append_nulless() + */ +#ifndef _di_fl_utf_string_dynamic_partial_append_ + extern f_return_status fl_utf_string_dynamic_partial_append(const f_utf_string_dynamic source, const f_utf_string_location range, f_utf_string_dynamic *destination); +#endif // _di_fl_utf_string_dynamic_partial_append_ + +/** + * Append the source UTF-8 string onto the destination, but restricted to the given range. + * + * Skips over NULL characters from source when appending. + * + * @param source + * The source string to append. + * @param range + * A range within the source to restrict the copy from. + * @param destination + * The destination string the source is appended onto. + * + * @return + * f_none on success. + * f_string_max_size (with error bit) if the combined string is too large. + * f_invalid_parameter (with error bit) if a parameter is invalid. + * f_error_allocation (with error bit) on memory allocation error. + * f_error_reallocation (with error bit) on memory reallocation error. + * + * @see fl_utf_string_dynamic_partial_append() + */ +#ifndef _di_fl_utf_string_dynamic_partial_append_nulless_ + extern f_return_status fl_utf_string_dynamic_partial_append_nulless(const f_utf_string_dynamic source, const f_utf_string_location range, f_utf_string_dynamic *destination); +#endif // _di_fl_utf_string_dynamic_partial_append_nulless_ + +/** * Compare two UTF-8 strings, similar to strncmp(), but restricted to the given ranges. * * This does not stop on NULL. @@ -374,9 +418,9 @@ extern "C" { * String to compare. * @param string2 * String to compare. - * @param offset1 + * @param range1 * A range within the string1 to restrict the comparison to. - * @param offset2 + * @param range2 * A range within the string2 to restrict the comparison to. * * @return @@ -391,7 +435,7 @@ extern "C" { * @see fl_utf_string_dynamic_compare_trim() */ #ifndef _di_fl_utf_string_dynamic_partial_compare_ - extern f_return_status fl_utf_string_dynamic_partial_compare(const f_utf_string_dynamic string1, const f_utf_string_dynamic string2, const f_utf_string_location offset1, const f_utf_string_location offset2); + extern f_return_status fl_utf_string_dynamic_partial_compare(const f_utf_string_dynamic string1, const f_utf_string_dynamic string2, const f_utf_string_location range1, const f_utf_string_location range2); #endif // _di_fl_utf_string_dynamic_partial_compare_ /** @@ -405,9 +449,9 @@ extern "C" { * String to compare. * @param string2 * String to compare. - * @param offset1 + * @param range1 * A range within the string1 to restrict the comparison to. - * @param offset2 + * @param range2 * A range within the string2 to restrict the comparison to. * * @return @@ -422,10 +466,180 @@ extern "C" { * @see fl_utf_string_dynamic_compare_trim() */ #ifndef _di_fl_utf_string_dynamic_partial_compare_trim_ - extern f_return_status fl_utf_string_dynamic_partial_compare_trim(const f_utf_string_dynamic string1, const f_utf_string_dynamic string2, const f_utf_string_location offset1, const f_utf_string_location offset2); + extern f_return_status fl_utf_string_dynamic_partial_compare_trim(const f_utf_string_dynamic string1, const f_utf_string_dynamic string2, const f_utf_string_location range1, const f_utf_string_location range2); #endif // _di_fl_utf_string_dynamic_partial_compare_trim_ /** + * Append the UTF-8 source string onto the destination with the glue in between, but restricted to the given range. + * + * If the destination string is empty, then no glue is appended. + * + * @param glue + * A string to append between the source and destination, such as a space: ' '. + * @param glue_length + * The number of bytes the glue takes up. + * @param source + * The source string to append. + * @param range + * A range within the source to restrict the copy from. + * @param destination + * The destination string the source and glue are appended onto. + * + * @return + * f_none on success. + * f_string_max_size (with error bit) if the combined string is too large. + * f_invalid_parameter (with error bit) if a parameter is invalid. + * f_error_allocation (with error bit) on memory allocation error. + * f_error_reallocation (with error bit) on memory reallocation error. + * + * @see fl_utf_string_dynamic_mash_nulless() + */ +#ifndef _di_fl_utf_string_dynamic_partial_mash_ + extern f_return_status fl_utf_string_dynamic_partial_mash(const f_utf_string glue, const f_utf_string_length glue_length, const f_utf_string_dynamic source, const f_utf_string_location range, f_utf_string_dynamic *destination); +#endif // _di_fl_utf_string_dynamic_partial_mash_ + +/** + * Append the UTF-8 source string onto the destination with the glue in between, but restricted to the given range. + * + * If the destination string is empty, then no glue is appended. + * + * Skips over NULL characters from glue and source when appending. + * + * @param glue + * A string to append between the source and destination, such as a space: ' '. + * @param glue_length + * The number of bytes the glue takes up. + * @param source + * The source string to append. + * @param range + * A range within the source to restrict the copy from. + * @param destination + * The destination string the source and glue are appended onto. + * + * @return + * f_none on success. + * f_string_max_size (with error bit) if the combined string is too large. + * f_invalid_parameter (with error bit) if a parameter is invalid. + * f_error_allocation (with error bit) on memory allocation error. + * f_error_reallocation (with error bit) on memory reallocation error. + * + * @see fl_utf_string_dynamic_partial_mash() + */ +#ifndef _di_fl_utf_string_dynamic_partial_mash_nulless_ + extern f_return_status fl_utf_string_dynamic_partial_mash_nulless(const f_utf_string glue, const f_utf_string_length glue_length, const f_utf_string_dynamic source, const f_utf_string_location range, f_utf_string_dynamic *destination); +#endif // _di_fl_utf_string_dynamic_partial_mash_nulless_ + +/** + * Prepend the UTF-8 source string onto the destination with the glue in between, but restricted to the given range. + * + * If the destination string is empty, then no glue is appended. + * + * @param glue + * A string to append between the source and destination, such as a space: ' '. + * @param glue_length + * The number of bytes the glue takes up. + * @param source + * The source string to append. + * @param range + * A range within the source to restrict the copy from. + * @param destination + * The destination string the source and glue are appended onto. + * + * @return + * f_none on success. + * f_string_max_size (with error bit) if the combined string is too large. + * f_invalid_parameter (with error bit) if a parameter is invalid. + * f_error_allocation (with error bit) on memory allocation error. + * f_error_reallocation (with error bit) on memory reallocation error. + * + * @see fl_utf_string_dynamic_partial_mish_nulless() + */ +#ifndef _di_fl_utf_string_dynamic_partial_mish_ + extern f_return_status fl_utf_string_dynamic_partial_mish(const f_utf_string glue, const f_utf_string_length glue_length, const f_utf_string_dynamic source, const f_utf_string_location range, f_utf_string_dynamic *destination); +#endif // _di_fl_utf_string_dynamic_partial_mish_ + +/** + * Prepend the UTF-8 source string onto the destination with the glue in between, but restricted to the given range. + * + * If the destination string is empty, then no glue is appended. + * + * Skips over NULL characters from glue and source when appending. + * + * @param glue + * A string to append between the source and destination, such as a space: ' '. + * @param glue_length + * The number of bytes the glue takes up. + * @param source + * The source string to append. + * @param range + * A range within the source to restrict the copy from. + * @param destination + * The destination string the source and glue are appended onto. + * + * @return + * f_none on success. + * f_string_max_size (with error bit) if the combined string is too large. + * f_invalid_parameter (with error bit) if a parameter is invalid. + * f_error_allocation (with error bit) on memory allocation error. + * f_error_reallocation (with error bit) on memory reallocation error. + * + * @see fl_utf_string_dynamic_partial_mish() + */ +#ifndef _di_fl_utf_string_dynamic_partial_mish_nulless_ + extern f_return_status fl_utf_string_dynamic_partial_mish_nulless(const f_utf_string glue, const f_utf_string_length glue_length, const f_utf_string_dynamic source, const f_utf_string_location range, f_utf_string_dynamic *destination); +#endif // _di_fl_utf_string_dynamic_partial_mish_nulless_ + +/** + * Prepend the source string onto the destination, but restricted to the given range. + * + * Prepend operations require memory move operations and are therefore likely more expensive than append operations. + * + * @param source + * The source string to prepend. + * @param range + * A range within the source to restrict the copy from. + * @param destination + * The destination string the source is prepended onto. + * + * @return + * f_none on success. + * f_string_max_size (with error bit) if the combined string is too large. + * f_invalid_parameter (with error bit) if a parameter is invalid. + * f_error_allocation (with error bit) on memory allocation error. + * f_error_reallocation (with error bit) on memory reallocation error. + * + * @see fl_utf_string_dynamic_partial_prepend_nulless() + */ +#ifndef _di_fl_utf_string_dynamic_partial_prepend_ + extern f_return_status fl_utf_string_dynamic_partial_prepend(const f_utf_string_dynamic source, const f_utf_string_location range, f_utf_string_dynamic *destination); +#endif // _di_fl_utf_string_dynamic_partial_prepend_ + +/** + * Prepend the source string onto the destination, but restricted to the given range. + * + * Prepend operations require memory move operations and are therefore likely more expensive than append operations. + * + * @param source + * The source string to prepend. + * @param range + * A range within the source to restrict the copy from. + * @param destination + * The destination string the source is prepended onto. + * + * @return + * f_none on success. + * f_string_max_size (with error bit) if the combined string is too large. + * f_invalid_parameter (with error bit) if a parameter is invalid. + * f_error_allocation (with error bit) on memory allocation error. + * f_error_reallocation (with error bit) on memory reallocation error. + * + * @see fl_utf_string_dynamic_partial_prepend() + */ +#ifndef _di_fl_utf_string_dynamic_partial_prepend_nulless_ + extern f_return_status fl_utf_string_dynamic_partial_prepend_nulless(const f_utf_string_dynamic source, const f_utf_string_location range, f_utf_string_dynamic *destination); +#endif // _di_fl_utf_string_dynamic_partial_prepend_nulless_ + +/** * Prepend the source string onto the destination. * * Prepend operations require memory move operations and are therefore likely more expensive than append operations. @@ -442,7 +656,7 @@ extern "C" { * f_error_allocation (with error bit) on memory allocation error. * f_error_reallocation (with error bit) on memory reallocation error. * - * @see fl_utf_string_prepend() + * @see fl_utf_string_dynamic_prepend_nulless() */ #ifndef _di_fl_utf_string_dynamic_prepend_ extern f_return_status fl_utf_string_dynamic_prepend(const f_utf_string_dynamic source, f_utf_string_dynamic *destination); @@ -465,7 +679,7 @@ extern "C" { * f_error_allocation (with error bit) on memory allocation error. * f_error_reallocation (with error bit) on memory reallocation error. * - * @see fl_utf_string_prepend_nulless() + * @see fl_utf_string_dynamic_prepend() */ #ifndef _di_fl_utf_string_dynamic_prepend_nulless_ extern f_return_status fl_utf_string_dynamic_prepend_nulless(const f_utf_string_dynamic source, f_utf_string_dynamic *destination); @@ -479,7 +693,7 @@ extern "C" { * * @param source * The buffer to rip from. - * @param offset + * @param range * A range within the buffer representing the string to rip. * @param destination * The new string, which will be allocated or reallocated as necessary. @@ -491,12 +705,10 @@ extern "C" { * f_error_allocation (with error bit) on memory allocation error. * f_error_reallocation (with error bit) on memory reallocation error. * - * @see fl_utf_string_append() - * @see fl_utf_string_dynamic_append() - * @see fl_utf_string_dynamic_rip() + * @see fl_utf_string_dynamic_rip_nulless() */ #ifndef _di_fl_utf_string_dynamic_rip_ - extern f_return_status fl_utf_string_dynamic_rip(const f_utf_string_dynamic source, const f_utf_string_location offset, f_utf_string_dynamic *destination); + extern f_return_status fl_utf_string_dynamic_rip(const f_utf_string_dynamic source, const f_utf_string_location range, f_utf_string_dynamic *destination); #endif // _di_fl_utf_string_dynamic_rip_ /** @@ -509,7 +721,7 @@ extern "C" { * * @param source * The string to rip from. - * @param offset + * @param range * A range within the buffer representing the string to rip. * @param destination * The new string, which will be allocated or reallocated as necessary. @@ -521,12 +733,10 @@ extern "C" { * f_error_allocation (with error bit) on memory allocation error. * f_error_reallocation (with error bit) on memory reallocation error. * - * @see fl_utf_string_append_nulless() - * @see fl_utf_string_dynamic_append_nulless() - * @see fl_utf_string_dynamic_rip_nulless() + * @see fl_utf_string_dynamic_rip() */ #ifndef _di_fl_utf_string_dynamic_rip_nulless_ - extern f_return_status fl_utf_string_dynamic_rip_nulless(const f_utf_string_dynamic source, const f_utf_string_location offset, f_utf_string_dynamic *destination); + extern f_return_status fl_utf_string_dynamic_rip_nulless(const f_utf_string_dynamic source, const f_utf_string_location range, f_utf_string_dynamic *destination); #endif // _di_fl_utf_string_dynamic_rip_nulless_ /** @@ -597,7 +807,7 @@ extern "C" { * f_invalid_utf (with error bit) if a character in the buffer is an invalid UTF-8 character. * f_invalid_parameter (with error bit) if a parameter is invalid * - * @see fl_utf_string_seek_line_untile_graph() + * @see fl_utf_string_seek_line_until_graph() */ #ifndef _di_fl_utf_string_dynamic_seek_line_until_graph_ extern f_return_status fl_utf_string_dynamic_seek_line_until_graph(const f_utf_string_dynamic buffer, f_utf_string_location *location, const f_utf_character placeholder); @@ -733,8 +943,7 @@ extern "C" { * f_error_allocation (with error bit) on memory allocation error. * f_error_reallocation (with error bit) on memory reallocation error. * - * @see fl_utf_string_mash() - * @see fl_utf_string_dynamic_mash() + * @see fl_utf_string_mash_nulless() */ #ifndef _di_fl_utf_string_mash_ extern f_return_status fl_utf_string_mash(const f_utf_string glue, const f_utf_string_length glue_length, const f_utf_string source, const f_utf_string_length start, const f_utf_string_length stop, f_utf_string_dynamic *destination); @@ -767,8 +976,7 @@ extern "C" { * f_error_allocation (with error bit) on memory allocation error. * f_error_reallocation (with error bit) on memory reallocation error. * - * @see fl_utf_string_mash_nulless() - * @see fl_utf_string_dynamic_mash_nulless() + * @see fl_utf_string_mash() */ #ifndef _di_fl_utf_string_mash_nulless_ extern f_return_status fl_utf_string_mash_nulless(const f_utf_string glue, const f_utf_string_length glue_length, const f_utf_string source, const f_utf_string_length start, const f_utf_string_length stop, f_utf_string_dynamic *destination); @@ -799,8 +1007,7 @@ extern "C" { * f_error_allocation (with error bit) on memory allocation error. * f_error_reallocation (with error bit) on memory reallocation error. * - * @see fl_utf_string_mish() - * @see fl_utf_string_dynamic_mish() + * @see fl_utf_string_mish_nulless() */ #ifndef _di_fl_utf_string_mish_ extern f_return_status fl_utf_string_mish(const f_utf_string glue, const f_utf_string_length glue_length, const f_utf_string source, const f_utf_string_length start, const f_utf_string_length stop, f_utf_string_dynamic *destination); @@ -833,8 +1040,7 @@ extern "C" { * f_error_allocation (with error bit) on memory allocation error. * f_error_reallocation (with error bit) on memory reallocation error. * - * @see fl_utf_string_mish_nulless() - * @see fl_utf_string_dynamic_mish_nulless() + * @see fl_utf_string_mish() */ #ifndef _di_fl_utf_string_mish_nulless_ extern f_return_status fl_utf_string_mish_nulless(const f_utf_string glue, const f_utf_string_length glue_length, const f_utf_string source, const f_utf_string_length start, const f_utf_string_length stop, f_utf_string_dynamic *destination); @@ -861,7 +1067,7 @@ extern "C" { * f_error_allocation (with error bit) on memory allocation error. * f_error_reallocation (with error bit) on memory reallocation error. * - * @see fl_utf_string_dynamic_prepend() + * @see fl_utf_string_prepend_nulless() */ #ifndef _di_fl_utf_string_prepend_ extern f_return_status fl_utf_string_prepend(const f_utf_string source, const f_utf_string_length start, const f_utf_string_length stop, f_utf_string_dynamic *destination); @@ -890,7 +1096,7 @@ extern "C" { * f_error_allocation (with error bit) on memory allocation error. * f_error_reallocation (with error bit) on memory reallocation error. * - * @see fl_utf_string_dynamic_prepend_nulless() + * @see fl_utf_string_prepend() */ #ifndef _di_fl_utf_string_prepend_nulless_ extern f_return_status fl_utf_string_prepend_nulless(const f_utf_string source, const f_utf_string_length start, const f_utf_string_length stop, f_utf_string_dynamic *destination); @@ -918,8 +1124,7 @@ extern "C" { * f_error_allocation (with error bit) on memory allocation error. * f_error_reallocation (with error bit) on memory reallocation error. * - * @see fl_utf_string_append() - * @see fl_utf_string_dynamic_append() + * @see fl_utf_string_rip_nulless() */ #ifndef _di_fl_utf_string_rip_ extern f_return_status fl_utf_string_rip(const f_utf_string source, const f_utf_string_length start, const f_utf_string_length stop, f_utf_string_dynamic *destination); @@ -949,8 +1154,7 @@ extern "C" { * f_error_allocation (with error bit) on memory allocation error. * f_error_reallocation (with error bit) on memory reallocation error. * - * @see fl_utf_string_append_nulless() - * @see fl_utf_string_dynamic_rip_nulless() + * @see fl_utf_string_append() */ #ifndef _di_fl_utf_string_rip_nulless_ extern f_return_status fl_utf_string_rip_nulless(const f_utf_string source, const f_utf_string_length start, const f_utf_string_length stop, f_utf_string_dynamic *destination); @@ -975,7 +1179,6 @@ extern "C" { * f_invalid_utf (with error bit) if a character in the buffer is an invalid UTF-8 character. * f_invalid_parameter (with error bit) if a parameter is invalid. * - * @see fl_utf_string_dynamic_seek_line_to_char() * @see fl_utf_string_seek_line_to_char() */ #ifndef _di_fl_utf_string_seek_line_to_ @@ -1000,7 +1203,6 @@ extern "C" { * f_invalid_utf (with error bit) if a character in the buffer is an invalid UTF-8 character. * f_invalid_parameter (with error bit) if a parameter is invalid. * - * @see fl_utf_string_dynamic_seek_line_to() * @see fl_utf_string_seek_line_to() */ #ifndef _di_fl_utf_string_seek_line_to_char_