[A] Add functions to check if table is empty to the API
This commit is contained in:
parent
f17f150e43
commit
71188fd0fb
@ -1,3 +1,9 @@
|
|||||||
|
## v0.4.0
|
||||||
|
|
||||||
|
### API
|
||||||
|
|
||||||
|
- Add functions to check if table is empty to the API.
|
||||||
|
|
||||||
## v0.3.2
|
## v0.3.2
|
||||||
|
|
||||||
### Bug fixes
|
### Bug fixes
|
||||||
|
13
lib/fort.c
13
lib/fort.c
@ -2699,13 +2699,13 @@ void ft_ln(ft_table_t *table)
|
|||||||
table->cur_row++;
|
table->cur_row++;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ft_cur_row(ft_table_t *table)
|
size_t ft_cur_row(const ft_table_t *table)
|
||||||
{
|
{
|
||||||
assert(table);
|
assert(table);
|
||||||
return table->cur_row;
|
return table->cur_row;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ft_cur_col(ft_table_t *table)
|
size_t ft_cur_col(const ft_table_t *table)
|
||||||
{
|
{
|
||||||
assert(table);
|
assert(table);
|
||||||
return table->cur_col;
|
return table->cur_col;
|
||||||
@ -2718,6 +2718,15 @@ void ft_set_cur_cell(ft_table_t *table, size_t row, size_t col)
|
|||||||
table->cur_col = col;
|
table->cur_col = col;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ft_is_empty(const ft_table_t *table)
|
||||||
|
{
|
||||||
|
assert(table);
|
||||||
|
if (table->rows == NULL || (vector_size(table->rows) == 0))
|
||||||
|
return 1;
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int ft_row_printf_impl_(ft_table_t *table, size_t row, const struct f_string_view *fmt, va_list *va)
|
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;
|
size_t i = 0;
|
||||||
|
15
lib/fort.h
15
lib/fort.h
@ -286,7 +286,7 @@ void ft_ln(ft_table_t *table);
|
|||||||
* @return
|
* @return
|
||||||
* Row number of the current cell.
|
* Row number of the current cell.
|
||||||
*/
|
*/
|
||||||
size_t ft_cur_row(ft_table_t *table);
|
size_t ft_cur_row(const ft_table_t *table);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get column number of the current cell.
|
* Get column number of the current cell.
|
||||||
@ -296,7 +296,7 @@ size_t ft_cur_row(ft_table_t *table);
|
|||||||
* @return
|
* @return
|
||||||
* Column number of the current cell.
|
* Column number of the current cell.
|
||||||
*/
|
*/
|
||||||
size_t ft_cur_col(ft_table_t *table);
|
size_t ft_cur_col(const ft_table_t *table);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set current cell position.
|
* Set current cell position.
|
||||||
@ -313,7 +313,16 @@ size_t ft_cur_col(ft_table_t *table);
|
|||||||
*/
|
*/
|
||||||
void ft_set_cur_cell(ft_table_t *table, size_t row, size_t col);
|
void ft_set_cur_cell(ft_table_t *table, size_t row, size_t col);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if table is empty.
|
||||||
|
*
|
||||||
|
* @param table
|
||||||
|
* Pointer to the table.
|
||||||
|
* @return
|
||||||
|
* 1 - table is empty
|
||||||
|
* 0 - some data has been inserted
|
||||||
|
*/
|
||||||
|
int ft_is_empty(const ft_table_t *table);
|
||||||
|
|
||||||
#if defined(FT_CLANG_COMPILER) || defined(FT_GCC_COMPILER)
|
#if defined(FT_CLANG_COMPILER) || defined(FT_GCC_COMPILER)
|
||||||
|
|
||||||
|
17
lib/fort.hpp
17
lib/fort.hpp
@ -1012,7 +1012,7 @@ public:
|
|||||||
* Column number of the current cell.
|
* Column number of the current cell.
|
||||||
*/
|
*/
|
||||||
size_t
|
size_t
|
||||||
cur_col()
|
cur_col() const noexcept
|
||||||
{
|
{
|
||||||
return ft_cur_col(table_);
|
return ft_cur_col(table_);
|
||||||
}
|
}
|
||||||
@ -1024,11 +1024,24 @@ public:
|
|||||||
* Row number of the current cell.
|
* Row number of the current cell.
|
||||||
*/
|
*/
|
||||||
size_t
|
size_t
|
||||||
cur_row()
|
cur_row() const noexcept
|
||||||
{
|
{
|
||||||
return ft_cur_row(table_);
|
return ft_cur_row(table_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if table is empty.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* true - table is empty
|
||||||
|
* false - some data has been inserted
|
||||||
|
*/
|
||||||
|
bool
|
||||||
|
is_empty() const noexcept
|
||||||
|
{
|
||||||
|
return ft_is_empty(table_);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get current cell.
|
* Get current cell.
|
||||||
*
|
*
|
||||||
|
15
src/fort.h
15
src/fort.h
@ -286,7 +286,7 @@ void ft_ln(ft_table_t *table);
|
|||||||
* @return
|
* @return
|
||||||
* Row number of the current cell.
|
* Row number of the current cell.
|
||||||
*/
|
*/
|
||||||
size_t ft_cur_row(ft_table_t *table);
|
size_t ft_cur_row(const ft_table_t *table);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get column number of the current cell.
|
* Get column number of the current cell.
|
||||||
@ -296,7 +296,7 @@ size_t ft_cur_row(ft_table_t *table);
|
|||||||
* @return
|
* @return
|
||||||
* Column number of the current cell.
|
* Column number of the current cell.
|
||||||
*/
|
*/
|
||||||
size_t ft_cur_col(ft_table_t *table);
|
size_t ft_cur_col(const ft_table_t *table);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set current cell position.
|
* Set current cell position.
|
||||||
@ -313,7 +313,16 @@ size_t ft_cur_col(ft_table_t *table);
|
|||||||
*/
|
*/
|
||||||
void ft_set_cur_cell(ft_table_t *table, size_t row, size_t col);
|
void ft_set_cur_cell(ft_table_t *table, size_t row, size_t col);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if table is empty.
|
||||||
|
*
|
||||||
|
* @param table
|
||||||
|
* Pointer to the table.
|
||||||
|
* @return
|
||||||
|
* 1 - table is empty
|
||||||
|
* 0 - some data has been inserted
|
||||||
|
*/
|
||||||
|
int ft_is_empty(const ft_table_t *table);
|
||||||
|
|
||||||
#if defined(FT_CLANG_COMPILER) || defined(FT_GCC_COMPILER)
|
#if defined(FT_CLANG_COMPILER) || defined(FT_GCC_COMPILER)
|
||||||
|
|
||||||
|
17
src/fort.hpp
17
src/fort.hpp
@ -1012,7 +1012,7 @@ public:
|
|||||||
* Column number of the current cell.
|
* Column number of the current cell.
|
||||||
*/
|
*/
|
||||||
size_t
|
size_t
|
||||||
cur_col()
|
cur_col() const noexcept
|
||||||
{
|
{
|
||||||
return ft_cur_col(table_);
|
return ft_cur_col(table_);
|
||||||
}
|
}
|
||||||
@ -1024,11 +1024,24 @@ public:
|
|||||||
* Row number of the current cell.
|
* Row number of the current cell.
|
||||||
*/
|
*/
|
||||||
size_t
|
size_t
|
||||||
cur_row()
|
cur_row() const noexcept
|
||||||
{
|
{
|
||||||
return ft_cur_row(table_);
|
return ft_cur_row(table_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if table is empty.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* true - table is empty
|
||||||
|
* false - some data has been inserted
|
||||||
|
*/
|
||||||
|
bool
|
||||||
|
is_empty() const noexcept
|
||||||
|
{
|
||||||
|
return ft_is_empty(table_);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get current cell.
|
* Get current cell.
|
||||||
*
|
*
|
||||||
|
@ -145,13 +145,13 @@ void ft_ln(ft_table_t *table)
|
|||||||
table->cur_row++;
|
table->cur_row++;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ft_cur_row(ft_table_t *table)
|
size_t ft_cur_row(const ft_table_t *table)
|
||||||
{
|
{
|
||||||
assert(table);
|
assert(table);
|
||||||
return table->cur_row;
|
return table->cur_row;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ft_cur_col(ft_table_t *table)
|
size_t ft_cur_col(const ft_table_t *table)
|
||||||
{
|
{
|
||||||
assert(table);
|
assert(table);
|
||||||
return table->cur_col;
|
return table->cur_col;
|
||||||
@ -164,6 +164,15 @@ void ft_set_cur_cell(ft_table_t *table, size_t row, size_t col)
|
|||||||
table->cur_col = col;
|
table->cur_col = col;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ft_is_empty(const ft_table_t *table)
|
||||||
|
{
|
||||||
|
assert(table);
|
||||||
|
if (table->rows == NULL || (vector_size(table->rows) == 0))
|
||||||
|
return 1;
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int ft_row_printf_impl_(ft_table_t *table, size_t row, const struct f_string_view *fmt, va_list *va)
|
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;
|
size_t i = 0;
|
||||||
|
@ -197,6 +197,7 @@ void test_table_basic(void)
|
|||||||
WHEN("Empty table") {
|
WHEN("Empty table") {
|
||||||
table = ft_create_table();
|
table = ft_create_table();
|
||||||
assert_true(table != NULL);
|
assert_true(table != NULL);
|
||||||
|
assert_true(ft_is_empty(table) == 1);
|
||||||
|
|
||||||
const char *table_str = ft_to_string(table);
|
const char *table_str = ft_to_string(table);
|
||||||
assert_true(table_str != NULL);
|
assert_true(table_str != NULL);
|
||||||
@ -213,6 +214,26 @@ void test_table_basic(void)
|
|||||||
assert_true(table_str != NULL);
|
assert_true(table_str != NULL);
|
||||||
assert_str_equal(table_str, table_str_etalon);
|
assert_str_equal(table_str, table_str_etalon);
|
||||||
#endif /* FT_HAVE_UTF8 */
|
#endif /* FT_HAVE_UTF8 */
|
||||||
|
|
||||||
|
ft_set_cur_cell(table, 5, 6);
|
||||||
|
assert_true(ft_is_empty(table) == 1);
|
||||||
|
ft_destroy_table(table);
|
||||||
|
}
|
||||||
|
|
||||||
|
WHEN("Empty string content") {
|
||||||
|
table = ft_create_table();
|
||||||
|
assert_true(table != NULL);
|
||||||
|
assert_true(ft_is_empty(table) == 1);
|
||||||
|
assert_true(ft_write_ln(table, "") == FT_SUCCESS);
|
||||||
|
assert_true(ft_is_empty(table) == 0);
|
||||||
|
|
||||||
|
const char *table_str = ft_to_string(table);
|
||||||
|
const char *table_str_etalon =
|
||||||
|
"+--+\n"
|
||||||
|
"| |\n"
|
||||||
|
"+--+\n";
|
||||||
|
assert_str_equal(table_str, table_str_etalon);
|
||||||
|
|
||||||
ft_destroy_table(table);
|
ft_destroy_table(table);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,6 +246,7 @@ void test_table_basic(void)
|
|||||||
assert_true(ft_write_ln(table, "3", "c", "234", "3.140000") == FT_SUCCESS);
|
assert_true(ft_write_ln(table, "3", "c", "234", "3.140000") == FT_SUCCESS);
|
||||||
assert_true(ft_write_ln(table, "3", "c", "234", "3.140000") == FT_SUCCESS);
|
assert_true(ft_write_ln(table, "3", "c", "234", "3.140000") == FT_SUCCESS);
|
||||||
assert_true(ft_write_ln(table, "3", "c", "234", "3.140000") == FT_SUCCESS);
|
assert_true(ft_write_ln(table, "3", "c", "234", "3.140000") == FT_SUCCESS);
|
||||||
|
assert_true(ft_is_empty(table) == 0);
|
||||||
|
|
||||||
const char *table_str = ft_to_string(table);
|
const char *table_str = ft_to_string(table);
|
||||||
assert_true(table_str != NULL);
|
assert_true(table_str != NULL);
|
||||||
|
@ -30,6 +30,16 @@ void test_cpp_bug_fixes(void)
|
|||||||
|
|
||||||
void test_cpp_table_basic(void)
|
void test_cpp_table_basic(void)
|
||||||
{
|
{
|
||||||
|
WHEN("Empty table.") {
|
||||||
|
fort::char_table table;
|
||||||
|
assert_true(set_cpp_test_props_for_table(&table));
|
||||||
|
|
||||||
|
std::string table_str = table.to_string();
|
||||||
|
std::string table_str_etalon = "";
|
||||||
|
assert_string_equal(table_str, table_str_etalon);
|
||||||
|
assert_true(table.is_empty());
|
||||||
|
}
|
||||||
|
|
||||||
WHEN("All columns are equal and not empty.") {
|
WHEN("All columns are equal and not empty.") {
|
||||||
fort::char_table table;
|
fort::char_table table;
|
||||||
assert_true(set_cpp_test_props_for_table(&table));
|
assert_true(set_cpp_test_props_for_table(&table));
|
||||||
@ -55,6 +65,7 @@ void test_cpp_table_basic(void)
|
|||||||
"| | | | |\n"
|
"| | | | |\n"
|
||||||
"+---+---+-----+----------+\n";
|
"+---+---+-----+----------+\n";
|
||||||
assert_string_equal(table_str, table_str_etalon);
|
assert_string_equal(table_str, table_str_etalon);
|
||||||
|
assert_true(table.is_empty() == false);
|
||||||
}
|
}
|
||||||
|
|
||||||
WHEN("Checking basic constructors and assignmets.") {
|
WHEN("Checking basic constructors and assignmets.") {
|
||||||
|
Loading…
Reference in New Issue
Block a user