From e97b7e7ff51017b530b2fcf833becc417ec20319 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sun, 5 Jul 2020 22:48:43 -0500 Subject: [PATCH] Feature: add additional string comparison functions. Comparing a string range to a non-string range can be messy. Provide new functions to help alleviate this mess. --- level_1/fl_string/c/string.c | 40 ++++++++++++++++ level_1/fl_string/c/string.h | 106 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 146 insertions(+) diff --git a/level_1/fl_string/c/string.c b/level_1/fl_string/c/string.c index 62e4079..cc22f21 100644 --- a/level_1/fl_string/c/string.c +++ b/level_1/fl_string/c/string.c @@ -413,6 +413,26 @@ extern "C" { } #endif // _di_fl_string_dynamic_partial_compare_ +#ifndef _di_fl_string_dynamic_partial_compare_dynamic_ + f_return_status fl_string_dynamic_partial_compare_dynamic(const f_string_static string1, const f_string_static string2, const f_string_range range2) { + #ifndef _di_level_1_parameter_checking_ + if (string2.used <= range2.stop) return F_status_set_error(F_parameter); + #endif // _di_level_1_parameter_checking_ + + return private_fl_string_compare(string1.string, string2.string, 0, range2.start, string1.used, range2.stop + 1); + } +#endif // _di_fl_string_dynamic_partial_compare_dynamic_ + +#ifndef _di_fl_string_dynamic_partial_compare_string_ + f_return_status fl_string_dynamic_partial_compare_string(const f_string string1, const f_string_static string2, const f_string_length length1, const f_string_range range2) { + #ifndef _di_level_1_parameter_checking_ + if (string2.used <= range2.stop) return F_status_set_error(F_parameter); + #endif // _di_level_1_parameter_checking_ + + return private_fl_string_compare(string1, string2.string, 0, range2.start, length1, range2.stop + 1); + } +#endif // _di_fl_string_dynamic_partial_compare_string_ + #ifndef _di_fl_string_dynamic_partial_compare_trim_ f_return_status fl_string_dynamic_partial_compare_trim(const f_string_static string1, const f_string_static string2, const f_string_range range1, const f_string_range range2) { #ifndef _di_level_1_parameter_checking_ @@ -424,6 +444,26 @@ extern "C" { } #endif // _di_fl_string_dynamic_partial_compare_trim_ +#ifndef _di_fl_string_dynamic_partial_compare_trim_dynamic_ + f_return_status fl_string_dynamic_partial_compare_trim_dynamic(const f_string_static string1, const f_string_static string2, const f_string_range range2) { + #ifndef _di_level_1_parameter_checking_ + if (string2.used <= range2.stop) return F_status_set_error(F_parameter); + #endif // _di_level_1_parameter_checking_ + + return private_fl_string_compare_trim(string1.string, string2.string, 0, range2.start, string1.used, range2.stop + 1); + } +#endif // _di_fl_string_dynamic_partial_compare_trim_dynamic_ + +#ifndef _di_fl_string_dynamic_partial_compare_trim_string_ + f_return_status fl_string_dynamic_partial_compare_trim_string(const f_string string1, const f_string_static string2, const f_string_length length1, const f_string_range range2) { + #ifndef _di_level_1_parameter_checking_ + if (string2.used <= range2.stop) return F_status_set_error(F_parameter); + #endif // _di_level_1_parameter_checking_ + + return private_fl_string_compare_trim(string1, string2.string, 0, range2.start, length1, range2.stop + 1); + } +#endif // _di_fl_string_dynamic_partial_compare_trim_string_ + #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_static source, const f_string_range range, f_string_dynamic *destination) { #ifndef _di_level_1_parameter_checking_ diff --git a/level_1/fl_string/c/string.h b/level_1/fl_string/c/string.h index c6d3bb8..9d2909a 100644 --- a/level_1/fl_string/c/string.h +++ b/level_1/fl_string/c/string.h @@ -544,6 +544,112 @@ extern "C" { #endif // _di_fl_string_dynamic_partial_compare_ /** + * Compare two strings, similar to strncmp(), but restricted to the given range for the second string. + * + * This does not stop on NULL. + * NULL characters are ignored. + * + * @param string1 + * String to compare. + * @param string2 + * String to compare. + * @param range2 + * A range within the string2 to restrict the comparison to. + * + * @return + * F_equal_to when both strings equal. + * F_equal_to_not when both strings do not equal. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_fl_string_dynamic_partial_compare_dynamic_ + extern f_return_status fl_string_dynamic_partial_compare_dynamic(const f_string_static string1, const f_string_static string2, const f_string_range range2); +#endif // _di_fl_string_dynamic_partial_compare_dynamic_ + +/** + * Compare two strings, similar to strncmp(), but restricted to the given range for the second string. + * + * This operates with the first string being a traditional string. + * + * This does not stop on NULL. + * NULL characters are ignored. + * + * @param string1 + * String to compare. + * @param string2 + * String to compare. + * @param length1 + * The length of string1. + * @param range2 + * A range within the string2 to restrict the comparison to. + * + * @return + * F_equal_to when both strings equal. + * F_equal_to_not when both strings do not equal. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_fl_string_dynamic_partial_compare_string_ + extern f_return_status fl_string_dynamic_partial_compare_string(const f_string string1, const f_string_static string2, const f_string_length length1, const f_string_range range2); +#endif // _di_fl_string_dynamic_partial_compare_string_ + +/** + * Compare two strings, similar to strncmp(), but restricted to the given range for the second string. + * + * This does not stop on NULL. + * NULL characters are ignored. + * Ignores leading and trailing whitespace. + * + * @param string1 + * String to compare. + * @param string2 + * String to compare. + * @param range2 + * A range within the string2 to restrict the comparison to. + * + * @return + * F_equal_to when both strings equal. + * F_equal_to_not when both strings do not equal. + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors from (with error bit): f_utf_is_whitespace(). + * + * @see f_utf_is_whitespace() + */ +#ifndef _di_fl_string_dynamic_partial_compare_trim_dynamic_ + extern f_return_status fl_string_dynamic_partial_compare_trim_dynamic(const f_string_static string1, const f_string_static string2, const f_string_range range2); +#endif // _di_fl_string_dynamic_partial_compare_trim_dynamic_ + +/** + * Compare two strings, similar to strncmp(), but restricted to the given range for the second string. + * + * This operates with the first string being a traditional string. + * + * This does not stop on NULL. + * NULL characters are ignored. + * Ignores leading and trailing whitespace. + * + * @param string1 + * String to compare. + * @param string2 + * String to compare. + * @param length1 + * The length of string1. + * @param range2 + * A range within the string2 to restrict the comparison to. + * + * @return + * F_equal_to when both strings equal. + * F_equal_to_not when both strings do not equal. + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors from (with error bit): f_utf_is_whitespace(). + * + * @see f_utf_is_whitespace() + */ +#ifndef _di_fl_string_dynamic_partial_compare_trim_string_ + extern f_return_status fl_string_dynamic_partial_compare_trim_string(const f_string string1, const f_string_static string2, const f_string_length length1, const f_string_range range2); +#endif // _di_fl_string_dynamic_partial_compare_trim_string_ + +/** * Compare two strings, similar to strncmp(), but restricted to the given ranges. * * This does not stop on NULL. -- 1.8.3.1