table-printer: Add append_with_comma_unique

This means we can ensure a flag is only added once
This commit is contained in:
Alexander Larsson
2020-11-12 11:26:15 +01:00
committed by Alexander Larsson
parent cbe8e8ca36
commit bf5329aa69
2 changed files with 35 additions and 0 deletions

View File

@@ -787,6 +787,37 @@ flatpak_table_printer_append_cell_with_comma (FlatpakTablePrinter *printer,
set_cell (printer, r, c, text, -1, 2);
}
void
flatpak_table_printer_append_cell_with_comma_unique (FlatpakTablePrinter *printer,
int r,
int c,
const char *text)
{
Row *row;
Cell *cell;
row = (Row *) g_ptr_array_index (printer->rows, r);
g_assert (row);
cell = (Cell *) g_ptr_array_index (row->cells, c);
g_assert (cell);
/* Look for existing text in comma separated text */
if (cell->text != NULL && *text != 0)
{
gsize len = strlen (text);
const char *match = cell->text;
while ((match = strstr (match, text)) != NULL)
{
if (match[len] == 0 || match[len] == ',' )
return; /* Already in string, do nothing */
/* Look for next match */
match = match + len;
}
}
set_cell (printer, r, c, text, -1, 2);
}
void
flatpak_table_printer_set_decimal_cell (FlatpakTablePrinter *printer,
int r,

View File

@@ -79,6 +79,10 @@ void flatpak_table_printer_append_cell_with_comma (FlatpakTablePr
int row,
int col,
const char *cell);
void flatpak_table_printer_append_cell_with_comma_unique (FlatpakTablePrinter *printer,
int row,
int col,
const char *cell);
void flatpak_table_printer_set_decimal_cell (FlatpakTablePrinter *printer,
int row,
int col,