When walking back from the end of the string and handling possible UTF-8 characters, the byte width needs to be properly handled.
The functions in these projects are fl_ and not f_.
Includes minor code cleanup.
f_macro_string_dynamic_resize(status, (*result), size);
}
- if (f_status_is_error(status)) {
- return status;
- }
+ if (f_status_is_error(status)) return status;
memcpy(result->string, string + start, size);
result->used = size;
f_macro_string_dynamic_resize(status, (*result), size);
}
- if (f_status_is_error(status)) {
- return status;
- }
+ if (f_status_is_error(status)) return status;
f_string_length begin = start;
f_string_length end = stop;
// skip past leading whitespace.
for (; begin <= end; begin += width) {
// skip past NULL.
- while (begin < size && string[begin] == f_string_eos) begin++;
+ while (begin < end && string[begin] == f_string_eos) begin++;
if (begin > end) break;
status = f_utf_is_whitespace(string + begin, (end - begin) + 1);
if (status == f_false) break;
- width = f_macro_utf_byte_width_is(string[begin]);
+ width = f_macro_utf_byte_width(string[begin]);
} // for
for (; end > begin; end--) {
// skip past NULL.
+ while (end > begin && string[end] == f_string_eos) end--;
if (string[end] == f_string_eos) continue;
if (end == begin) break;
+ // each UTF-8 character of width 8 is an incomplete part.
+ // go left until either width is 0 (ascii, or > 1) to determine the character.
for (;;) {
width = f_macro_utf_byte_width_is(string[end]);
if (width == 1) {
}
if (status == f_false) break;
+
+ width = f_macro_utf_byte_width(string[end]);
} // for
memcpy(result->string, string + begin, (end - begin) + 1);
}
#endif // _di_fl_string_compare_trim_
-#ifndef _di_f_string_dynamic_compare_
- f_return_status f_string_dynamic_compare(const f_string_dynamic string1, const f_string_dynamic string2) {
+#ifndef _di_fl_string_dynamic_compare_
+ f_return_status fl_string_dynamic_compare(const f_string_dynamic string1, const f_string_dynamic string2) {
#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);
return private_fl_string_compare(string1.string, string2.string, 0, 0, string1.used, string2.used);
}
-#endif // _di_f_string_dynamic_compare_
+#endif // _di_fl_string_dynamic_compare_
-#ifndef _di_f_string_dynamic_compare_trim_
- f_return_status f_string_dynamic_compare_trim(const f_string_dynamic string1, const f_string_dynamic string2) {
+#ifndef _di_fl_string_dynamic_compare_trim_
+ f_return_status fl_string_dynamic_compare_trim(const f_string_dynamic string1, const f_string_dynamic string2) {
#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);
return private_fl_string_compare_trim(string1.string, string2.string, 0, 0, string1.used, string2.used);
}
-#endif // _di_f_string_dynamic_compare_trim_
+#endif // _di_fl_string_dynamic_compare_trim_
#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) {
* @see fl_string_dynamic_partial_compare()
* @see fl_string_dynamic_partial_compare_trim()
*/
-#ifndef _di_f_string_dynamic_compare_
- extern f_return_status f_string_dynamic_compare(const f_string_dynamic string1, const f_string_dynamic string2);
-#endif // _di_f_string_dynamic_compare_
+#ifndef _di_fl_string_dynamic_compare_
+ extern f_return_status fl_string_dynamic_compare(const f_string_dynamic string1, const f_string_dynamic string2);
+#endif // _di_fl_string_dynamic_compare_
/**
* Compare two strings, similar to strncmp().
* @see fl_string_dynamic_partial_compare()
* @see fl_string_dynamic_partial_compare_trim()
*/
-#ifndef _di_f_string_dynamic_compare_trim_
- extern f_return_status f_string_dynamic_compare_trim(const f_string_dynamic string1, const f_string_dynamic string2);
-#endif // _di_f_string_dynamic_compare_trim_
+#ifndef _di_fl_string_dynamic_compare_trim_
+ extern f_return_status fl_string_dynamic_compare_trim(const f_string_dynamic string1, const f_string_dynamic string2);
+#endif // _di_fl_string_dynamic_compare_trim_
/**
* Compare two strings, similar to strncmp(), but restricted to the given ranges.
f_macro_string_dynamic_resize(status, (*result), size);
}
- if (f_status_is_error(status)) {
- return status;
- }
+ if (f_status_is_error(status)) return status;
memcpy(result->string, string + start, size);
result->used = size;
f_macro_string_dynamic_resize(status, (*result), size);
}
- if (f_status_is_error(status)) {
- return status;
- }
+ if (f_status_is_error(status)) return status;
f_utf_string_length begin = start;
f_utf_string_length end = stop;