Add text_to_string().

This commit is contained in:
tastytea 2019-11-28 05:09:14 +01:00
parent 138170975a
commit f8fd9b8c6d
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
3 changed files with 26 additions and 20 deletions

View File

@ -118,6 +118,14 @@ public:
*/
size_t remove(const string &uri);
/*!
* @brief Returns tags as comma separated string.
*
* @since 0.9.0
*/
[[nodiscard]]
static string tags_to_string(const vector<string> &tags);
private:
fs::path _dbpath;
std::unique_ptr<Session> _session;

View File

@ -30,19 +30,10 @@ void Export::CSV::print() const
<< R"("Title","Description","Full text")" << "\r\n";
for (const Database::entry &entry : _entries)
{
string strtags;
for (const string &tag : entry.tags)
{
strtags += tag;
if (tag != *(entry.tags.rbegin()))
{
strtags += ",";
}
}
_out << '"' << quote(entry.uri) << "\",\""
<< quote(entry.archive_uri) << "\",\""
<< timepoint_to_string(entry.datetime) << "\",\""
<< quote(strtags) << "\",\""
<< quote(Database::tags_to_string(entry.tags)) << "\",\""
<< quote(entry.title) << "\",\""
<< quote(entry.description) << "\",\""
<< quote(entry.fulltext_oneline()) << '"'<< "\r\n";

View File

@ -84,18 +84,9 @@ void Database::store(const Database::entry &data) const
try
{
const string strdatetime = timepoint_to_string(data.datetime, true);
string strtags;
string strtags = tags_to_string(data.tags);
Statement insert(*_session);
for (const string &tag : data.tags)
{
strtags += tag;
if (tag != *(data.tags.rbegin()))
{
strtags += ",";
}
}
// useRef() uses the const reference.
insert << "INSERT INTO remwharead "
"VALUES(?, ?, ?, ?, ?, ?, ?);",
@ -175,6 +166,22 @@ size_t Database::remove(const string &uri)
return del.execute();
}
string Database::tags_to_string(const vector<string> &tags)
{
string strtags;
for (const string &tag : tags)
{
strtags += tag;
if (tag != *(tags.rbegin()))
{
strtags += ',';
}
}
return strtags;
}
fs::path Database::get_data_home() const
{
fs::path path;