f_status_t status = F_none;
+ f_string_length_t i = 0;
f_string_length_t first = 0;
f_string_length_t size = 0;
- for (f_string_length_t i = 0; i <= length; i++) {
+ for (; i < length; i++) {
- if (i == length) {
- if (i > first) {
- size = i - first;
+ if (source[i]) continue;
- if (destination->used + size > destination->size) {
- status = private_fl_string_dynamic_increase_by(size, destination);
- if (F_status_is_error(status)) return status;
- }
+ if (i && i > first) {
+ size = i - first;
- memcpy(destination->string + destination->used, source + first, size);
- destination->used = destination->used + size;
+ if (destination->used + size > destination->size) {
+ status = private_fl_string_dynamic_increase_by(size, destination);
+ if (F_status_is_error(status)) return status;
}
- break;
+ memcpy(destination->string + destination->used, source + first, size);
+ destination->used = destination->used + size;
}
- if (!source[i]) {
- if (i > 0) {
- if (i > first) {
- size = i - first;
+ while (i + 1 < length && !source[i + 1]) {
+ i++;
+ } // while
- if (destination->used + size > destination->size) {
- status = private_fl_string_dynamic_increase_by(size, destination);
- if (F_status_is_error(status)) return status;
- }
+ first = i + 1;
+ } // for
- memcpy(destination->string + destination->used, source + first, size);
- destination->used = destination->used + size;
- }
- }
+ if (i > first) {
+ size = i - first;
- while (i + 1 < length && !source[i + 1]) {
- i++;
- } // while
-
- first = i + 1;
- continue;
+ if (destination->used + size > destination->size) {
+ status = private_fl_string_dynamic_increase_by(size, destination);
+ if (F_status_is_error(status)) return status;
}
- } // for
+
+ memcpy(destination->string + destination->used, source + first, size);
+ destination->used = destination->used + size;
+ }
return F_none;
}
#ifndef _di_level_1_parameter_checking_
if (source.used <= range.start) return F_status_set_error(F_parameter);
if (source.used <= range.stop) return F_status_set_error(F_parameter);
+ if (range.stop < range.start) return F_status_set_error(F_parameter);
if (!destination) return F_status_set_error(F_parameter);
#endif // _di_level_1_parameter_checking_
if (!source.used) return F_data_not_eos;
+
+ f_string_length_t begin = range.start;
+ f_string_length_t end = range.stop;
+
+ const f_status_t status = private_fl_string_rip_find_range(source.string, &begin, &end);
+
+ if (F_status_is_error(status)) return status;
+ if (status == F_data_not) return status;
+
+ if (!source.used) return F_data_not_eos;
if (range.start > range.stop) return F_data_not_stop;
- return private_fl_string_append(source.string + range.start, (range.stop - range.start) + 1, destination);
+ return private_fl_string_append(source.string + begin, (end - begin) + 1, destination);
}
#endif // _di_fl_string_dynamic_rip_
#ifndef _di_level_1_parameter_checking_
if (source.used <= range.start) return F_status_set_error(F_parameter);
if (source.used <= range.stop) return F_status_set_error(F_parameter);
+ if (range.stop < range.start) return F_status_set_error(F_parameter);
if (!destination) return F_status_set_error(F_parameter);
#endif // _di_level_1_parameter_checking_
if (!source.used) return F_data_not_eos;
+
+ f_string_length_t begin = range.start;
+ f_string_length_t end = range.stop;
+
+ const f_status_t status = private_fl_string_rip_find_range(source.string, &begin, &end);
+
+ if (F_status_is_error(status)) return status;
+ if (status == F_data_not) return status;
+
+ if (!source.used) return F_data_not_eos;
if (range.start > range.stop) return F_data_not_stop;
- return private_fl_string_append_nulless(source.string + range.start, (range.stop - range.start) + 1, destination);
+ return private_fl_string_append_nulless(source.string + begin, (end - begin) + 1, destination);
}
#endif // _di_fl_string_dynamic_rip_nulless_
f_string_length_t begin = 0;
f_string_length_t end = length - 1;
- f_status_t status = private_fl_string_rip_find_range(source, &begin, &end);
+ const f_status_t status = private_fl_string_rip_find_range(source, &begin, &end);
if (F_status_is_error(status)) return status;
if (status == F_data_not) return status;
f_string_length_t begin = 0;
f_string_length_t end = length - 1;
- f_status_t status = private_fl_string_rip_find_range(source, &begin, &end);
+ const f_status_t status = private_fl_string_rip_find_range(source, &begin, &end);
if (F_status_is_error(status)) return status;
if (status == F_data_not) return status;
* Allocate a new string from the provided range in the buffer.
*
* Ignores leading and trailing whitespace.
+ * Ignores leading and trailing NULL characters.
* As a result, resulting size may be smaller than requested range.
*
* @param source
* Allocate a new string from the provided range in the buffer.
*
* Ignores leading and trailing whitespace.
+ * Ignores leading and trailing NULL characters.
* As a result, resulting size may be smaller than requested range.
*
* Skips over NULL characters from source when appending.
* Allocate a new string from the provided range in the string.
*
* Ignores leading and trailing whitespace.
+ * Ignores leading and trailing NULL characters.
* As a result, resulting size may be smaller than requested length.
*
* @param source
* Allocate a new string from the provided range in the string.
*
* Ignores leading and trailing whitespace.
+ * Ignores leading and trailing NULL characters.
* As a result, resulting size may be smaller than requested length.
*
* Skips over NULL characters from source when ripping.