Refactored Netscape bookmarks export.
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
8ff0d39927
commit
00aa9ffd47
|
@ -21,9 +21,9 @@ using std::chrono::system_clock;
|
|||
using std::chrono::duration_cast;
|
||||
using std::chrono::seconds;
|
||||
|
||||
void export_bookmarks(const vector<Database::entry> &entries, ostream &out)
|
||||
void Export::Bookmarks::print() const
|
||||
{
|
||||
out << "<!DOCTYPE NETSCAPE-Bookmark-file-1>\n"
|
||||
_out << "<!DOCTYPE NETSCAPE-Bookmark-file-1>\n"
|
||||
"<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; "
|
||||
"charset=UTF-8\">\n"
|
||||
"<TITLE>Bookmarks from remwharead</TITLE>\n"
|
||||
|
@ -31,22 +31,23 @@ void export_bookmarks(const vector<Database::entry> &entries, ostream &out)
|
|||
"<DL><p>\n"
|
||||
"<DT><H3>remwharead</H3>\n"
|
||||
"<DL><p>\n";
|
||||
for (const Database::entry & entry : entries)
|
||||
{
|
||||
string title = entry.title;
|
||||
if (title.empty())
|
||||
{
|
||||
title = entry.uri;
|
||||
}
|
||||
system_clock::time_point tp = entry.datetime;
|
||||
system_clock::duration duration = tp.time_since_epoch();
|
||||
string time_seconds =
|
||||
std::to_string(duration_cast<seconds>(duration).count());
|
||||
|
||||
out << "<DT><A HREF=\"" << entry.uri << "\" "
|
||||
<< "ADD_DATE=\"" << time_seconds << "\">"
|
||||
<< title << "</A>\n";
|
||||
for (const Database::entry & entry : _entries)
|
||||
{
|
||||
string title = entry.title;
|
||||
if (title.empty())
|
||||
{
|
||||
title = entry.uri;
|
||||
}
|
||||
out << "</DL><p>\n"
|
||||
<< "</DL><p>\n";
|
||||
system_clock::time_point tp = entry.datetime;
|
||||
system_clock::duration duration = tp.time_since_epoch();
|
||||
string time_seconds =
|
||||
std::to_string(duration_cast<seconds>(duration).count());
|
||||
|
||||
_out << "<DT><A HREF=\"" << entry.uri << "\" "
|
||||
<< "ADD_DATE=\"" << time_seconds << "\">"
|
||||
<< title << "</A>\n";
|
||||
}
|
||||
_out << "</DL><p>\n"
|
||||
<< "</DL><p>\n";
|
||||
}
|
||||
|
|
|
@ -35,6 +35,8 @@ namespace Export
|
|||
explicit ExportBase(const vector<Database::entry> &entries,
|
||||
ostream &out = cout);
|
||||
|
||||
virtual void print() const = 0;
|
||||
|
||||
protected:
|
||||
const vector<Database::entry> &_entries;
|
||||
ostream &_out;
|
||||
|
@ -45,19 +47,20 @@ namespace Export
|
|||
public:
|
||||
using ExportBase::ExportBase;
|
||||
|
||||
void print() const;
|
||||
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;
|
||||
void print() const override;
|
||||
|
||||
private:
|
||||
using tagmap = std::map<string,vector<Database::entry>>;
|
||||
|
@ -72,12 +75,14 @@ namespace Export
|
|||
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;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
//! Export as Netscape bookmark file.
|
||||
void export_bookmarks(const vector<Database::entry> &entries,
|
||||
ostream &out = cout);
|
||||
|
||||
#endif // REMWHAREAD_EXPORT_HPP
|
||||
|
|
|
@ -124,12 +124,12 @@ int main(const int argc, const char *argv[])
|
|||
{
|
||||
if (file.is_open())
|
||||
{
|
||||
export_bookmarks(entries, file);
|
||||
Export::Bookmarks(entries, file).print();
|
||||
file.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
export_bookmarks(entries);
|
||||
Export::Bookmarks(entries).print();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ SCENARIO ("The Bookmarks export works correctly")
|
|||
try
|
||||
{
|
||||
std::ostringstream output;
|
||||
export_bookmarks({ entry }, output);
|
||||
Export::Bookmarks({ entry }, output).print();
|
||||
const string bookmarks = output.str();
|
||||
|
||||
const regex re_top(
|
||||
|
|
Loading…
Reference in New Issue