From 32040c277cca23aa12dff9fad285df6e0cbe0920 Mon Sep 17 00:00:00 2001 From: tastytea Date: Mon, 20 May 2019 10:50:49 +0200 Subject: [PATCH] Replaced more regular expressions with search & replace. --- src/csv.cpp | 12 +++++++----- src/export.hpp | 2 +- src/sqlite.cpp | 11 +++++++---- src/uri.cpp | 2 +- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/csv.cpp b/src/csv.cpp index 91b3bf1..4cb7a79 100644 --- a/src/csv.cpp +++ b/src/csv.cpp @@ -14,14 +14,11 @@ * along with this program. If not, see . */ -#include #include "time.hpp" #include "export.hpp" using std::cerr; using std::endl; -using std::regex; -using std::regex_replace; void export_csv(const vector &entries, ostream &out) { @@ -55,7 +52,12 @@ void export_csv(const vector &entries, ostream &out) } } -const string quote_csv(const string &field) +const string quote_csv(string field) { - return regex_replace(field, regex("\""), "\"\""); + size_t pos = 0; + while ((pos = field.find('"', pos)) != std::string::npos) + { + field.replace(pos, 1, "\"\""); + } + return field; } diff --git a/src/export.hpp b/src/export.hpp index c7547a2..22b795c 100644 --- a/src/export.hpp +++ b/src/export.hpp @@ -27,7 +27,7 @@ using std::cout; void export_csv(const vector &entries, ostream &out = cout); //! replaces " with "". -const string quote_csv(const string &field); +const string quote_csv(string field); void export_adoc(const vector &entries, ostream &out = cout); //! Replaces characters in tags that asciidoctor doesn't like. diff --git a/src/sqlite.cpp b/src/sqlite.cpp index cc95dd9..38b9c9e 100644 --- a/src/sqlite.cpp +++ b/src/sqlite.cpp @@ -17,7 +17,6 @@ #include #include #include -#include #include #include #include @@ -26,8 +25,6 @@ using std::cerr; using std::endl; -using std::regex; -using std::regex_replace; Database::Database() : _connected(false) @@ -75,7 +72,13 @@ bool operator ==(const Database::entry &a, const Database::entry &b) const string Database::entry::fulltext_oneline() const { - return regex_replace(fulltext, regex("\n"), "\\n"); + string oneline = fulltext; + size_t pos = 0; + while ((pos = oneline.find('\n', pos)) != std::string::npos) + { + oneline.replace(pos, 1, "\\n"); + } + return oneline; } void Database::store(const Database::entry &data) const diff --git a/src/uri.cpp b/src/uri.cpp index 2b4f6c3..f7fa10f 100644 --- a/src/uri.cpp +++ b/src/uri.cpp @@ -119,7 +119,7 @@ const string URI::strip_html(const string &html) out = remove_html_tags(out); // Remove tags. size_t pos = 0; - while ((pos = out.find("\r")) != std::string::npos) // Remove CR. + while ((pos = out.find("\r", pos)) != std::string::npos) // Remove CR. { out.replace(pos, 1, ""); }