From 93298e5301e5010d5459c0483ef531028565bd8d Mon Sep 17 00:00:00 2001 From: tastytea Date: Thu, 6 Jun 2019 18:56:49 +0200 Subject: [PATCH] Splitted export header. --- src/adoc.cpp | 6 ++++- src/adoc.hpp | 52 ++++++++++++++++++++++++++++++++++++++++ src/bookmarks.cpp | 5 +++- src/bookmarks.hpp | 33 +++++++++++++++++++++++++ src/csv.cpp | 2 +- src/csv.hpp | 40 +++++++++++++++++++++++++++++++ src/export.hpp | 44 ---------------------------------- src/main.cpp | 4 +++- tests/test_adoc.cpp | 2 +- tests/test_bookmarks.cpp | 2 +- tests/test_csv.cpp | 2 +- 11 files changed, 141 insertions(+), 51 deletions(-) create mode 100644 src/adoc.hpp create mode 100644 src/bookmarks.hpp create mode 100644 src/csv.hpp diff --git a/src/adoc.cpp b/src/adoc.cpp index f47cde6..1ad99d5 100644 --- a/src/adoc.cpp +++ b/src/adoc.cpp @@ -14,14 +14,18 @@ * along with this program. If not, see . */ +#include +#include #include #include #include #include #include #include "version.hpp" -#include "export.hpp" +#include "time.hpp" +#include "adoc.hpp" +using std::string; using std::cerr; using std::endl; using std::regex; diff --git a/src/adoc.hpp b/src/adoc.hpp new file mode 100644 index 0000000..c15c1a3 --- /dev/null +++ b/src/adoc.hpp @@ -0,0 +1,52 @@ +/* This file is part of remwharead. + * Copyright © 2019 tastytea + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef REMWHAREAD_ADOC_HPP +#define REMWHAREAD_ADOC_HPP + +#include +#include +#include +#include "sqlite.hpp" +#include "export.hpp" + +using std::string; + +namespace Export +{ + class AsciiDoc : protected ExportBase + { + public: + using ExportBase::ExportBase; + + void print() const override; + + private: + using tagmap = std::map>; + using replacemap = const std::map; + + const string replace(string text, const replacemap &replacements) const; + //! Replaces characters in tags that asciidoctor doesn't like. + const string replace_in_tag(const string &text) const; + //! Replaces characters in title that asciidoctor doesn't like. + const string replace_in_title(const string &text) const; + void print_tags(const tagmap &tags) const; + const string get_day(const Database::entry &entry) const; + const string get_time(const Database::entry &entry) const; + }; +} + +#endif // REMWHAREAD_ADOC_HPP diff --git a/src/bookmarks.cpp b/src/bookmarks.cpp index f13cdbc..15885a5 100644 --- a/src/bookmarks.cpp +++ b/src/bookmarks.cpp @@ -15,11 +15,14 @@ */ #include -#include "export.hpp" +#include +#include "sqlite.hpp" +#include "bookmarks.hpp" using std::chrono::system_clock; using std::chrono::duration_cast; using std::chrono::seconds; +using std::string; void Export::Bookmarks::print() const { diff --git a/src/bookmarks.hpp b/src/bookmarks.hpp new file mode 100644 index 0000000..9a15c3f --- /dev/null +++ b/src/bookmarks.hpp @@ -0,0 +1,33 @@ +/* This file is part of remwharead. + * Copyright © 2019 tastytea + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef REMWHAREAD_BOOKMARKS_HPP +#define REMWHAREAD_BOOKMARKS_HPP + +#include "export.hpp" + +namespace Export +{ + //! Export as Netscape bookmark file. + class Bookmarks : protected ExportBase + { + public: + using ExportBase::ExportBase; + virtual void print() const override; + }; +} + +#endif // REMWHAREAD_BOOKMARKS_HPP diff --git a/src/csv.cpp b/src/csv.cpp index 5ebd940..e5852c7 100644 --- a/src/csv.cpp +++ b/src/csv.cpp @@ -15,7 +15,7 @@ */ #include "time.hpp" -#include "export.hpp" +#include "csv.hpp" using std::cerr; using std::endl; diff --git a/src/csv.hpp b/src/csv.hpp new file mode 100644 index 0000000..93c2e09 --- /dev/null +++ b/src/csv.hpp @@ -0,0 +1,40 @@ +/* This file is part of remwharead. + * Copyright © 2019 tastytea + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef REMWHAREAD_CSV_HPP +#define REMWHAREAD_CSV_HPP + +#include +#include "export.hpp" + +using std::string; + +namespace Export +{ + class CSV : protected ExportBase + { + public: + using ExportBase::ExportBase; + + virtual void print() const override; + + private: + //! replaces " with "". + const string quote(string field) const; + }; +} + +#endif // REMWHAREAD_CSV_HPP diff --git a/src/export.hpp b/src/export.hpp index 654439b..45c24d1 100644 --- a/src/export.hpp +++ b/src/export.hpp @@ -19,8 +19,6 @@ #include #include -#include -#include "time.hpp" #include "sqlite.hpp" using std::vector; @@ -41,48 +39,6 @@ namespace Export const vector &_entries; ostream &_out; }; - - class CSV : protected ExportBase - { - public: - using ExportBase::ExportBase; - - virtual void print() const override; - - private: - //! replaces " with "". - const string quote(string field) const; - }; - - - class AsciiDoc : protected ExportBase - { - public: - using ExportBase::ExportBase; - - void print() const override; - - private: - using tagmap = std::map>; - using replacemap = const std::map; - - const string replace(string text, const replacemap &replacements) const; - //! Replaces characters in tags that asciidoctor doesn't like. - const string replace_in_tag(const string &text) const; - //! Replaces characters in title that asciidoctor doesn't like. - const string replace_in_title(const string &text) const; - void print_tags(const tagmap &tags) const; - const string get_day(const Database::entry &entry) const; - const string get_time(const Database::entry &entry) const; - }; - - //! Export as Netscape bookmark file. - class Bookmarks : protected ExportBase - { - public: - using ExportBase::ExportBase; - virtual void print() const override; - }; } #endif // REMWHAREAD_EXPORT_HPP diff --git a/src/main.cpp b/src/main.cpp index c21581a..1d1f5d6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -24,7 +24,9 @@ #include "parse_options.hpp" #include "uri.hpp" #include "types.hpp" -#include "export.hpp" +#include "csv.hpp" +#include "adoc.hpp" +#include "bookmarks.hpp" #include "search.hpp" using std::cout; diff --git a/tests/test_adoc.cpp b/tests/test_adoc.cpp index fe7fa3b..6d213a8 100644 --- a/tests/test_adoc.cpp +++ b/tests/test_adoc.cpp @@ -22,7 +22,7 @@ #include #include "time.hpp" #include "sqlite.hpp" -#include "export.hpp" +#include "adoc.hpp" using std::string; using std::chrono::system_clock; diff --git a/tests/test_bookmarks.cpp b/tests/test_bookmarks.cpp index 4dff41e..b63c170 100644 --- a/tests/test_bookmarks.cpp +++ b/tests/test_bookmarks.cpp @@ -21,7 +21,7 @@ #include #include #include "sqlite.hpp" -#include "export.hpp" +#include "bookmarks.hpp" using std::string; using std::chrono::system_clock; diff --git a/tests/test_csv.cpp b/tests/test_csv.cpp index 27db289..499bdc1 100644 --- a/tests/test_csv.cpp +++ b/tests/test_csv.cpp @@ -22,7 +22,7 @@ #include #include "time.hpp" #include "sqlite.hpp" -#include "export.hpp" +#include "csv.hpp" using std::string; using std::chrono::system_clock;