make parsing of entries easier

This commit is contained in:
Florian Stinglmayr 2025-04-28 10:21:41 +02:00
parent 6aeafe34c3
commit 9f8b696028
3 changed files with 19 additions and 3 deletions

View File

@ -21,6 +21,8 @@ G_DECLARE_DERIVABLE_TYPE(
EDJournalEntry *ed_journal_entry_new(void); EDJournalEntry *ed_journal_entry_new(void);
EDJournalEntry *ed_journal_entry_new_parse(gchar const *line, GError **error);
EDErrorCode ed_journal_entry_parse(EDJournalEntry *self, EDErrorCode ed_journal_entry_parse(EDJournalEntry *self,
gchar const *line, gchar const *line,
GError **error); GError **error);

View File

@ -45,6 +45,22 @@ EDJournalEntry *ed_journal_entry_new(void)
); );
} }
EDJournalEntry *ed_journal_entry_new_parse(gchar const *line, GError **error)
{
EDJournalEntry *e = ed_journal_entry_new();
return_if_true(e == NULL, NULL);
EDErrorCode ret = ed_error_internal;
ret = ed_journal_entry_parse(e, line, error);
if (ED_ERROR(ret)) {
g_clear_object(&e);
return NULL;
}
return e;
}
EDErrorCode ed_journal_entry_parse(EDJournalEntry *self, EDErrorCode ed_journal_entry_parse(EDJournalEntry *self,
gchar const *line, gchar const *line,
GError **error) GError **error)

View File

@ -252,11 +252,9 @@ static EDErrorCode ed_journal_file_load(EDJournalFile *self,
linelen = 0; linelen = 0;
} }
entry = ed_journal_entry_new(); entry = ed_journal_entry_new_parse(line, NULL);
goto_if_true(entry == NULL, done); goto_if_true(entry == NULL, done);
ret = ed_journal_entry_parse(entry, line, NULL);
g_free(line); g_free(line);
line = NULL; line = NULL;
linelen = 0; linelen = 0;