[A] add function ft_delete_range

This commit is contained in:
seleznevae
2020-01-19 13:37:31 +03:00
parent bd1c28a2cd
commit e644f0a504
10 changed files with 336 additions and 0 deletions

View File

@@ -233,6 +233,58 @@ size_t ft_row_count(const ft_table_t *table)
return vector_size(table->rows);
}
int ft_delete_range(ft_table_t *table,
size_t top_left_row, size_t top_left_col,
size_t bottom_right_row, size_t bottom_right_col)
{
assert(table && table->rows);
int status = FT_SUCCESS;
size_t rows_n = vector_size(table->rows);
if (top_left_row == FT_CUR_ROW)
top_left_row = table->cur_row;
if (bottom_right_row == FT_CUR_ROW)
bottom_right_row = table->cur_row;
if (top_left_col == FT_CUR_COLUMN)
top_left_col = table->cur_row;
if (bottom_right_col == FT_CUR_COLUMN)
bottom_right_col = table->cur_row;
if (top_left_row > bottom_right_row || top_left_col > bottom_right_col)
return FT_EINVAL;
f_row_t *row = NULL;
size_t i = top_left_row;
while (i < rows_n && i <= bottom_right_row) {
row = VECTOR_AT(table->rows, i, f_row_t *);
status = ft_row_delete_range(row, top_left_col, bottom_right_col);
if (FT_IS_ERROR(status))
goto clear;
++i;
}
size_t n_iterations = MIN(rows_n - 1, bottom_right_row) - top_left_row + 1;
size_t j = 0;
i = top_left_row;
for (j = 0; j < n_iterations; ++j) {
row = VECTOR_AT(table->rows, i, f_row_t *);
if (columns_in_row(row)) {
++i;
} else {
destroy_row(row);
status = vector_erase(table->rows, i);
if (FT_IS_ERROR(status))
goto clear;
}
}
clear:
return status;
}
static int ft_row_printf_impl_(ft_table_t *table, size_t row, const struct f_string_view *fmt, va_list *va)
{
size_t i = 0;