From 3f6358fea0f656a74e723e94c3b4b29097e7a45e Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Tue, 20 Jul 2010 14:30:07 -0700 Subject: [PATCH] Feature - import.yaml - Not fully implemented (need research on libyaml first), but the file type recognition and stubs are there. --- src/export.cpp | 2 ++ src/import.cpp | 21 ++++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/export.cpp b/src/export.cpp index 37e5856e6..29a3d94b1 100644 --- a/src/export.cpp +++ b/src/export.cpp @@ -245,6 +245,8 @@ int handleExportYAML (std::string &outs) out << task->composeYAML ().c_str (); } + out << "...\n"; + outs = out.str (); context.hooks.trigger ("post-export-command"); } diff --git a/src/import.cpp b/src/import.cpp index 03f192b37..0c5fb95c5 100644 --- a/src/import.cpp +++ b/src/import.cpp @@ -28,11 +28,12 @@ #include #include #include -#include "File.h" -#include "Date.h" -#include "text.h" -#include "util.h" -#include "main.h" +#include +#include +#include +#include +#include +#include extern Context context; @@ -46,6 +47,7 @@ enum fileType task_cmd_line, todo_sh_2_0, csv, + yaml, text }; @@ -152,6 +154,13 @@ static fileType determineFileType (const std::vector & lines) if (commas_on_every_line) return csv; + if (lines.size () > 2 && + lines[0] == "% YAML 1.1\n" && + lines[1] == "---\n") + { + return yaml; + } + // Looks like 'text' is the default case, if there is any data at all. if (lines.size () > 1) return text; @@ -1191,6 +1200,7 @@ int handleImport (std::string &outs) case task_cmd_line: identifier = "This looks like task command line arguments."; break; case todo_sh_2_0: identifier = "This looks like a todo.sh 2.x file."; break; case csv: identifier = "This looks like a CSV file, but not a task export file."; break; + case yaml: identifier = "This looks like a YAML file."; break; case text: identifier = "This looks like a text file with one task per line."; break; case not_a_clue: throw std::string ("Task cannot determine which type of file this is, " @@ -1211,6 +1221,7 @@ int handleImport (std::string &outs) case task_cmd_line: out << importTaskCmdLine (lines); break; case todo_sh_2_0: out << importTodoSh_2_0 (lines); break; case csv: out << importCSV (lines); break; + case yaml: throw std::string ("import.yaml not implemented."); case text: out << importText (lines); break; case not_a_clue: /* to stop the compiler from complaining. */ break; }