[gnome-todo] todo-txt: fix note parsing
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-todo] todo-txt: fix note parsing
- Date: Sun, 3 Jun 2018 01:42:33 +0000 (UTC)
commit a833b70a60a2404410dbfe530c6553e57ffa5d69
Author: Rohit Kaushik <kaushikrohit325 gmail com>
Date: Sat May 26 16:14:23 2018 +0530
todo-txt: fix note parsing
1) The case when note appear as note:"desc" with no
in_description was ignored. It is fixed now.
2) description was being saved even if note was an
empty string. A check for empty string has been
added and note is cached only if description is
not NULL and not empty.
plugins/todo-txt/gtd-provider-todo-txt.c | 2 +-
plugins/todo-txt/gtd-todo-txt-parser.c | 50 +++++++++++++++-----------------
2 files changed, 24 insertions(+), 28 deletions(-)
---
diff --git a/plugins/todo-txt/gtd-provider-todo-txt.c b/plugins/todo-txt/gtd-provider-todo-txt.c
index 12a753e..a96cf09 100644
--- a/plugins/todo-txt/gtd-provider-todo-txt.c
+++ b/plugins/todo-txt/gtd-provider-todo-txt.c
@@ -118,7 +118,7 @@ print_task (GString *output,
g_string_append_printf (output, " due:%s", formatted_time);
}
- if (description)
+ if (description && g_strcmp0 (description, "") != 0)
{
g_autofree gchar *new_description = g_strescape (description, NULL);
g_string_append_printf (output, " note:\"%s\"", new_description);
diff --git a/plugins/todo-txt/gtd-todo-txt-parser.c b/plugins/todo-txt/gtd-todo-txt-parser.c
index 568073d..7b141cc 100644
--- a/plugins/todo-txt/gtd-todo-txt-parser.c
+++ b/plugins/todo-txt/gtd-todo-txt-parser.c
@@ -111,41 +111,37 @@ append_note (const gchar *token,
GtdTodoTxtParserState *state)
{
g_autofree gchar *escaped_token = NULL;
+ guint offset;
- if (!state->in_description && g_str_has_prefix (token , "note:"))
+ offset = 0;
+
+ if (!state->in_description && g_str_has_prefix (token , "note:\""))
+ offset = strlen ("note:\"");
+
+ if (g_str_has_suffix (token, "\""))
{
+ g_autofree gchar *new_token = NULL;
+
+ new_token = g_strdup (token + offset);
+
+ /* Remove the last "\"" */
+ new_token [strlen (new_token) - 1] = '\0';
+
/* Remove the extra "\" added for escaping special character */
- escaped_token = g_strcompress (token + strlen ("note:\""));
+ escaped_token = g_strcompress (new_token);
g_string_append (note, escaped_token);
- g_string_append (note, " ");
- state->in_description = TRUE;
+ /* Set parser state in_description to FALSE */
+ state->in_description = FALSE;
}
- else if (state->in_description)
+ else
{
- if (g_str_has_suffix (token, "\""))
- {
- g_autofree gchar *new_token = NULL;
-
- new_token = g_strdup (token);
-
- /* Remove the last "\"" */
- new_token [strlen (new_token) - 1] = '\0';
-
- /* Remove the extra "\" added for escaping special character */
- escaped_token = g_strcompress (new_token);
- g_string_append (note, escaped_token);
+ /* Remove the extra "\" added for escaping special character */
+ escaped_token = g_strcompress (token + offset);
+ g_string_append (note, escaped_token);
+ g_string_append (note, " ");
- /* Revert back parser state in_description to FALSE */
- state->in_description = FALSE;
- }
- else
- {
- /* Remove the extra "\" added for escaping special character */
- escaped_token = g_strcompress (token);
- g_string_append (note, escaped_token);
- g_string_append (note, " ");
- }
+ state->in_description = TRUE;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]