From beb163603909067aec30d67828d3bc4a4b0d7b25 Mon Sep 17 00:00:00 2001 From: tastytea Date: Sun, 22 Sep 2019 00:59:34 +0200 Subject: [PATCH] 2019-09-22 --- docs/adoc_8hpp_source.html | 2 +- docs/annotated.html | 6 ++-- docs/bookmarks_8hpp_source.html | 2 +- docs/classes.html | 2 +- docs/classremwharead_1_1Database-members.html | 2 +- docs/classremwharead_1_1Database.html | 2 +- ...wharead_1_1Export_1_1AsciiDoc-members.html | 2 +- ...classremwharead_1_1Export_1_1AsciiDoc.html | 2 +- ...haread_1_1Export_1_1Bookmarks-members.html | 2 +- ...lassremwharead_1_1Export_1_1Bookmarks.html | 2 +- ...ssremwharead_1_1Export_1_1CSV-members.html | 2 +- docs/classremwharead_1_1Export_1_1CSV.html | 2 +- ...aread_1_1Export_1_1ExportBase-members.html | 2 +- ...assremwharead_1_1Export_1_1ExportBase.html | 2 +- ...sremwharead_1_1Export_1_1JSON-members.html | 2 +- docs/classremwharead_1_1Export_1_1JSON.html | 6 ++-- ...ssremwharead_1_1Export_1_1RSS-members.html | 2 +- docs/classremwharead_1_1Export_1_1RSS.html | 8 ++--- ...emwharead_1_1Export_1_1Simple-members.html | 2 +- docs/classremwharead_1_1Export_1_1Simple.html | 2 +- docs/classremwharead_1_1Search-members.html | 2 +- docs/classremwharead_1_1Search.html | 2 +- docs/classremwharead_1_1URI-members.html | 2 +- docs/classremwharead_1_1URI.html | 36 +++++++++---------- docs/csv_8hpp_source.html | 2 +- .../dir_529a3e0c72053aaa27e3266821c6a27e.html | 2 +- .../dir_68267d1309a1af8e8297ef4c3efbcdba.html | 2 +- .../dir_a26cd56a311ed2c6b00868ab8167f874.html | 2 +- .../dir_c85d3e3c5052e9ad9ce18c6863244a25.html | 2 +- .../dir_d44c64559bbebec7f509842c48db8b23.html | 2 +- docs/export_8hpp_source.html | 2 +- docs/files.html | 2 +- docs/functions.html | 2 +- docs/functions_func.html | 2 +- docs/functions_rela.html | 2 +- docs/functions_type.html | 2 +- docs/hierarchy.html | 6 ++-- docs/index.html | 2 +- docs/json_8hpp_source.html | 2 +- docs/remwharead_8hpp_source.html | 2 +- docs/rss_8hpp_source.html | 4 +-- docs/search_8hpp_source.html | 2 +- docs/simple_8hpp_source.html | 2 +- docs/sqlite_8hpp_source.html | 2 +- ...mwharead_1_1Database_1_1entry-members.html | 2 +- ...structremwharead_1_1Database_1_1entry.html | 2 +- ...remwharead_1_1archive__answer-members.html | 2 +- docs/structremwharead_1_1archive__answer.html | 2 +- ...ctremwharead_1_1html__extract-members.html | 2 +- docs/structremwharead_1_1html__extract.html | 2 +- docs/time_8hpp.html | 2 +- docs/time_8hpp_source.html | 2 +- docs/types_8hpp.html | 2 +- docs/types_8hpp_source.html | 2 +- docs/uri_8hpp_source.html | 22 ++++++------ 55 files changed, 92 insertions(+), 92 deletions(-) diff --git a/docs/adoc_8hpp_source.html b/docs/adoc_8hpp_source.html index 3370cb0..bff5da6 100644 --- a/docs/adoc_8hpp_source.html +++ b/docs/adoc_8hpp_source.html @@ -22,7 +22,7 @@
remwharead -  0.8.1 +  0.8.2
diff --git a/docs/annotated.html b/docs/annotated.html index 2d016c7..80c39d5 100644 --- a/docs/annotated.html +++ b/docs/annotated.html @@ -22,7 +22,7 @@
remwharead -  0.8.1 +  0.8.2
@@ -74,8 +74,8 @@ $(function() {  CBookmarksExport as Netscape bookmark file  CCSVExport as Comma Separated Values  CExportBaseBase class for exports - CJSONExport as JSON array - CRSSExport as RSS feed + CJSONExport as JSON array + CRSSExport as RSS feed  CSimpleExport as simple list  Carchive_answerThe result of the call to the archive service  CDatabaseStore and retrieve files from/to SQLite diff --git a/docs/bookmarks_8hpp_source.html b/docs/bookmarks_8hpp_source.html index 84bba60..3a44af6 100644 --- a/docs/bookmarks_8hpp_source.html +++ b/docs/bookmarks_8hpp_source.html @@ -22,7 +22,7 @@
remwharead -  0.8.1 +  0.8.2
diff --git a/docs/classes.html b/docs/classes.html index 9a974ea..f439f15 100644 --- a/docs/classes.html +++ b/docs/classes.html @@ -22,7 +22,7 @@
remwharead -  0.8.1 +  0.8.2
diff --git a/docs/classremwharead_1_1Database-members.html b/docs/classremwharead_1_1Database-members.html index fff1966..b2f12f3 100644 --- a/docs/classremwharead_1_1Database-members.html +++ b/docs/classremwharead_1_1Database-members.html @@ -22,7 +22,7 @@
remwharead -  0.8.1 +  0.8.2
diff --git a/docs/classremwharead_1_1Database.html b/docs/classremwharead_1_1Database.html index 3b56edf..ec7a2a9 100644 --- a/docs/classremwharead_1_1Database.html +++ b/docs/classremwharead_1_1Database.html @@ -22,7 +22,7 @@
remwharead -  0.8.1 +  0.8.2
diff --git a/docs/classremwharead_1_1Export_1_1AsciiDoc-members.html b/docs/classremwharead_1_1Export_1_1AsciiDoc-members.html index 213a69d..7cd8312 100644 --- a/docs/classremwharead_1_1Export_1_1AsciiDoc-members.html +++ b/docs/classremwharead_1_1Export_1_1AsciiDoc-members.html @@ -22,7 +22,7 @@
remwharead -  0.8.1 +  0.8.2
diff --git a/docs/classremwharead_1_1Export_1_1AsciiDoc.html b/docs/classremwharead_1_1Export_1_1AsciiDoc.html index a64ece4..7946443 100644 --- a/docs/classremwharead_1_1Export_1_1AsciiDoc.html +++ b/docs/classremwharead_1_1Export_1_1AsciiDoc.html @@ -22,7 +22,7 @@
remwharead -  0.8.1 +  0.8.2
diff --git a/docs/classremwharead_1_1Export_1_1Bookmarks-members.html b/docs/classremwharead_1_1Export_1_1Bookmarks-members.html index 61619fb..5a0da79 100644 --- a/docs/classremwharead_1_1Export_1_1Bookmarks-members.html +++ b/docs/classremwharead_1_1Export_1_1Bookmarks-members.html @@ -22,7 +22,7 @@
remwharead -  0.8.1 +  0.8.2
diff --git a/docs/classremwharead_1_1Export_1_1Bookmarks.html b/docs/classremwharead_1_1Export_1_1Bookmarks.html index e0bebab..b3b0fa0 100644 --- a/docs/classremwharead_1_1Export_1_1Bookmarks.html +++ b/docs/classremwharead_1_1Export_1_1Bookmarks.html @@ -22,7 +22,7 @@
remwharead -  0.8.1 +  0.8.2
diff --git a/docs/classremwharead_1_1Export_1_1CSV-members.html b/docs/classremwharead_1_1Export_1_1CSV-members.html index 1836f9d..d506c28 100644 --- a/docs/classremwharead_1_1Export_1_1CSV-members.html +++ b/docs/classremwharead_1_1Export_1_1CSV-members.html @@ -22,7 +22,7 @@
remwharead -  0.8.1 +  0.8.2
diff --git a/docs/classremwharead_1_1Export_1_1CSV.html b/docs/classremwharead_1_1Export_1_1CSV.html index 3645b31..3db6a23 100644 --- a/docs/classremwharead_1_1Export_1_1CSV.html +++ b/docs/classremwharead_1_1Export_1_1CSV.html @@ -22,7 +22,7 @@
remwharead -  0.8.1 +  0.8.2
diff --git a/docs/classremwharead_1_1Export_1_1ExportBase-members.html b/docs/classremwharead_1_1Export_1_1ExportBase-members.html index 1d1024a..ec9e3eb 100644 --- a/docs/classremwharead_1_1Export_1_1ExportBase-members.html +++ b/docs/classremwharead_1_1Export_1_1ExportBase-members.html @@ -22,7 +22,7 @@
remwharead -  0.8.1 +  0.8.2
diff --git a/docs/classremwharead_1_1Export_1_1ExportBase.html b/docs/classremwharead_1_1Export_1_1ExportBase.html index 2e74ee6..1702ced 100644 --- a/docs/classremwharead_1_1Export_1_1ExportBase.html +++ b/docs/classremwharead_1_1Export_1_1ExportBase.html @@ -22,7 +22,7 @@
remwharead -  0.8.1 +  0.8.2
diff --git a/docs/classremwharead_1_1Export_1_1JSON-members.html b/docs/classremwharead_1_1Export_1_1JSON-members.html index 666e09d..50764ca 100644 --- a/docs/classremwharead_1_1Export_1_1JSON-members.html +++ b/docs/classremwharead_1_1Export_1_1JSON-members.html @@ -22,7 +22,7 @@
remwharead -  0.8.1 +  0.8.2
diff --git a/docs/classremwharead_1_1Export_1_1JSON.html b/docs/classremwharead_1_1Export_1_1JSON.html index 7cffed0..0821bdf 100644 --- a/docs/classremwharead_1_1Export_1_1JSON.html +++ b/docs/classremwharead_1_1Export_1_1JSON.html @@ -22,7 +22,7 @@
remwharead -  0.8.1 +  0.8.2
@@ -74,7 +74,7 @@ $(function() {
-

Export as JSON array. +

Export as JSON array. More...

#include <remwharead/export/json.hpp>

@@ -115,7 +115,7 @@ ostream & _out 

Detailed Description

-

Export as JSON array.

+

Export as JSON array.

Since
0.8.0

Member Function Documentation

diff --git a/docs/classremwharead_1_1Export_1_1RSS-members.html b/docs/classremwharead_1_1Export_1_1RSS-members.html index 199eb9c..4441b07 100644 --- a/docs/classremwharead_1_1Export_1_1RSS-members.html +++ b/docs/classremwharead_1_1Export_1_1RSS-members.html @@ -22,7 +22,7 @@
remwharead -  0.8.1 +  0.8.2
diff --git a/docs/classremwharead_1_1Export_1_1RSS.html b/docs/classremwharead_1_1Export_1_1RSS.html index 2f47e7f..bdf04e7 100644 --- a/docs/classremwharead_1_1Export_1_1RSS.html +++ b/docs/classremwharead_1_1Export_1_1RSS.html @@ -22,7 +22,7 @@
remwharead -  0.8.1 +  0.8.2
@@ -74,7 +74,7 @@ $(function() {
-

Export as RSS feed. +

Export as RSS feed. More...

#include <remwharead/export/rss.hpp>

@@ -115,7 +115,7 @@ ostream & _out 

Detailed Description

-

Export as RSS feed.

+

Export as RSS feed.

Since
0.8.0

Member Function Documentation

@@ -176,7 +176,7 @@ ostream & _outPrint output to std::ostream.

Implements remwharead::Export::ExportBase.

-
39  {
40  try
41  {
42  XMLWriter writer(_out, XMLWriter::CANONICAL);
43  AttributesImpl attrs_rss, attrs_guid;
44  constexpr char timefmt_rfc822[] = "%w, %d %b %Y %H:%M:%S %Z";
45 
46  attrs_rss.addAttribute("", "", "version", "", "2.0");
47  attrs_rss.addAttribute("", "", "xmlns:atom", "",
48  "http://www.w3.org/2005/Atom");
49  attrs_guid.addAttribute("", "", "isPermaLink", "", "false");
50 
51  writer.startDocument();
52  writer.startElement("", "", "rss", attrs_rss);
53  writer.startElement("", "", "channel");
54 
55  writer.startElement("", "", "title");
56  writer.characters("Visited things");
57  writer.endElement("", "", "title");
58 
59  writer.startElement("", "", "link");
60  // FIXME: There has to be an URL here.
61  writer.endElement("", "", "link");
62 
63  writer.startElement("", "", "description");
64  writer.characters("Export from remwharead.");
65  writer.endElement("", "", "description");
66 
67  writer.startElement("", "", "generator");
68  writer.characters(string("remwharead ") + global::version);
69  writer.endElement("", "", "generator");
70 
71  const string now = DateTimeFormatter::format(DateTime(),
72  timefmt_rfc822);
73  writer.startElement("", "", "lastBuildDate");
74  writer.characters(now);
75  writer.endElement("", "", "lastBuildDate");
76 
77  for (const Database::entry &entry : _entries)
78  {
79  writer.startElement("", "", "item");
80 
81  writer.startElement("", "", "title");
82  writer.characters(entry.title);
83  writer.endElement("", "", "title");
84 
85  writer.startElement("", "", "link");
86  writer.characters(entry.uri);
87  writer.endElement("", "", "link");
88 
89  writer.startElement("", "", "guid", attrs_guid);
90  writer.characters(entry.uri + " at " +
91  timepoint_to_string(entry.datetime));
92  writer.endElement("", "", "guid");
93 
94  const time_t time = system_clock::to_time_t(entry.datetime);
95  const string time_visited = DateTimeFormatter::format(
96  Timestamp::fromEpochTime(time), timefmt_rfc822);
97  writer.startElement("", "", "pubDate");
98  writer.characters(time_visited);
99  writer.endElement("", "", "pubDate");
100 
101  string description = entry.description;
102  if (!description.empty())
103  {
104  description += "\n\n";
105  }
106  if (!entry.tags.empty())
107  {
108  description += "Tags: ";
109  for (const string &tag : entry.tags)
110  {
111  description += tag;
112  if (tag != *(entry.tags.rbegin()))
113  {
114  description += ", ";
115  }
116  }
117  }
118  if (!entry.archive_uri.empty())
119  {
120  description += "\n\nArchived version: " + entry.archive_uri;
121  }
122  writer.startElement("", "", "description");
123  writer.characters(description);
124  writer.endElement("", "", "description");
125 
126  writer.endElement("", "", "item");
127  }
128 
129  writer.endElement("", "", "channel");
130  writer.endElement("", "", "rss");
131  writer.endDocument();
132  _out << endl;
133  }
134  catch (std::exception &e)
135  {
136  cerr << "Error in " << __func__ << ": " << e.what() << endl;
137  }
138  }
struct remwharead::Database::entry entry
Describes a database entry.
+
40  {
41  try
42  {
43  XMLWriter writer(_out, XMLWriter::CANONICAL);
44  AttributesImpl attrs_rss, attrs_guid;
45  constexpr char timefmt_rfc822[] = "%w, %d %b %Y %H:%M:%S %Z";
46 
47  attrs_rss.addAttribute("", "", "version", "", "2.0");
48  attrs_rss.addAttribute("", "", "xmlns:atom", "",
49  "http://www.w3.org/2005/Atom");
50  attrs_guid.addAttribute("", "", "isPermaLink", "", "false");
51 
52  writer.startDocument();
53  writer.startElement("", "", "rss", attrs_rss);
54  writer.startElement("", "", "channel");
55 
56  writer.startElement("", "", "title");
57  writer.characters("Visited things");
58  writer.endElement("", "", "title");
59 
60  writer.startElement("", "", "link");
61  writer.endElement("", "", "link");
62 
63  writer.startElement("", "", "description");
64  writer.characters("Export from remwharead.");
65  writer.endElement("", "", "description");
66 
67  writer.startElement("", "", "generator");
68  writer.characters(string("remwharead ") + global::version);
69  writer.endElement("", "", "generator");
70 
71  const string now = DateTimeFormatter::format(DateTime(),
72  timefmt_rfc822);
73  writer.startElement("", "", "lastBuildDate");
74  writer.characters(now);
75  writer.endElement("", "", "lastBuildDate");
76 
77  for (const Database::entry &entry : _entries)
78  {
79  writer.startElement("", "", "item");
80 
81  writer.startElement("", "", "title");
82  if (!entry.title.empty())
83  {
84  writer.characters(entry.title);
85  }
86  else
87  {
88  constexpr std::uint8_t maxlen = 100;
89  string title = entry.description.substr(0, maxlen);
90  if (entry.description.length() > maxlen)
91  {
92  title += " […]";
93  }
94  writer.characters(title);
95  }
96  writer.endElement("", "", "title");
97 
98  writer.startElement("", "", "link");
99  writer.characters(entry.uri);
100  writer.endElement("", "", "link");
101 
102  writer.startElement("", "", "guid", attrs_guid);
103  writer.characters(entry.uri + " at " +
104  timepoint_to_string(entry.datetime));
105  writer.endElement("", "", "guid");
106 
107  const time_t time = system_clock::to_time_t(entry.datetime);
108  const string time_visited = DateTimeFormatter::format(
109  Timestamp::fromEpochTime(time), timefmt_rfc822);
110  writer.startElement("", "", "pubDate");
111  writer.characters(time_visited);
112  writer.endElement("", "", "pubDate");
113 
114  string description = entry.description;
115  if (!description.empty())
116  {
117  description = "<p>" + description + "</p>";
118  }
119  if (!entry.tags.empty())
120  {
121  description += "<p><strong>Tags:</strong> ";
122  for (const string &tag : entry.tags)
123  {
124  description += tag;
125  if (tag != *(entry.tags.rbegin()))
126  {
127  description += ", ";
128  }
129  }
130  description += "</p>";
131  }
132  if (!entry.archive_uri.empty())
133  {
134  description += "<p><strong>Archived version:</strong> "
135  "<a href=\"" + entry.archive_uri + "\">"
136  + entry.archive_uri + "</a>";
137  }
138  writer.startElement("", "", "description");
139  writer.characters(description);
140  writer.endElement("", "", "description");
141 
142  writer.endElement("", "", "item");
143  }
144 
145  writer.endElement("", "", "channel");
146  writer.endElement("", "", "rss");
147  writer.endDocument();
148  _out << endl;
149  }
150  catch (std::exception &e)
151  {
152  cerr << "Error in " << __func__ << ": " << e.what() << endl;
153  }
154  }
struct remwharead::Database::entry entry
Describes a database entry.
diff --git a/docs/classremwharead_1_1Export_1_1Simple-members.html b/docs/classremwharead_1_1Export_1_1Simple-members.html index 42de5b5..996f9ca 100644 --- a/docs/classremwharead_1_1Export_1_1Simple-members.html +++ b/docs/classremwharead_1_1Export_1_1Simple-members.html @@ -22,7 +22,7 @@
remwharead -  0.8.1 +  0.8.2
diff --git a/docs/classremwharead_1_1Export_1_1Simple.html b/docs/classremwharead_1_1Export_1_1Simple.html index 452cbe5..8281f0d 100644 --- a/docs/classremwharead_1_1Export_1_1Simple.html +++ b/docs/classremwharead_1_1Export_1_1Simple.html @@ -22,7 +22,7 @@
remwharead -  0.8.1 +  0.8.2
diff --git a/docs/classremwharead_1_1Search-members.html b/docs/classremwharead_1_1Search-members.html index 4097cab..2ae3033 100644 --- a/docs/classremwharead_1_1Search-members.html +++ b/docs/classremwharead_1_1Search-members.html @@ -22,7 +22,7 @@
remwharead -  0.8.1 +  0.8.2
diff --git a/docs/classremwharead_1_1Search.html b/docs/classremwharead_1_1Search.html index 65fb365..08e34ec 100644 --- a/docs/classremwharead_1_1Search.html +++ b/docs/classremwharead_1_1Search.html @@ -22,7 +22,7 @@
remwharead -  0.8.1 +  0.8.2
diff --git a/docs/classremwharead_1_1URI-members.html b/docs/classremwharead_1_1URI-members.html index bba1762..1593d13 100644 --- a/docs/classremwharead_1_1URI-members.html +++ b/docs/classremwharead_1_1URI-members.html @@ -22,7 +22,7 @@
remwharead -  0.8.1 +  0.8.2
diff --git a/docs/classremwharead_1_1URI.html b/docs/classremwharead_1_1URI.html index 8962b6f..d424e6b 100644 --- a/docs/classremwharead_1_1URI.html +++ b/docs/classremwharead_1_1URI.html @@ -22,7 +22,7 @@
remwharead -  0.8.1 +  0.8.2
@@ -154,7 +154,7 @@ string _uri

Construct object and set URL.

Initializes TLS and sets proxy from the environment variable http_proxy, if possible.

Since
0.6.0
-
63  :_uri(uri)
64  {
65  Poco::Net::initializeSSL();
66 
67  try
68  {
69  HTTPClientSession::ProxyConfig proxy;
70  string proxy_env = Environment::get("http_proxy");
71  size_t pos;
72 
73  // Only keep text between // and /.
74  if ((pos = proxy_env.find("//")) != string::npos)
75  {
76  proxy_env = proxy_env.substr(pos + 2);
77  }
78  if ((pos = proxy_env.find('/')) != string::npos)
79  {
80  proxy_env = proxy_env.substr(0, pos);
81  }
82 
83  if ((pos = proxy_env.find(':')) != string::npos)
84  {
85  proxy.host = proxy_env.substr(0, pos);
86  proxy.port = std::stoi(proxy_env.substr(pos + 1));
87  }
88  else
89  {
90  proxy.host = proxy_env;
91  }
92 
93  HTTPClientSession::setGlobalProxyConfig(proxy);
94  }
95  catch (const std::exception &)
96  {
97  // No proxy found, no problem.
98  }
99  }
+
65  :_uri(uri)
66  {
67  Poco::Net::initializeSSL();
68 
69  try
70  {
71  HTTPClientSession::ProxyConfig proxy;
72  const string env_proxy = Environment::get("http_proxy");
73  const RegEx re_proxy("^(?:https?://)?(?:([^:]+):?([^@]*)@)?"
74  "([^:/]+)(?::([\\d]{1,5}))?/?$");
75  vector<string> matches;
76 
77  if (re_proxy.split(env_proxy, matches) >= 4)
78  {
79  proxy.username = matches[1];
80  proxy.password = matches[2];
81  proxy.host = matches[3];
82  if (!matches[4].empty())
83  {
84  const std::uint32_t &port = std::stoul(matches[4]);
85  if (port > 65535)
86  {
87  throw std::invalid_argument("Port number out of range");
88  }
89  proxy.port = port;
90  }
91  }
92  HTTPClientSession::setGlobalProxyConfig(proxy);
93  }
94  catch (const Poco::RegularExpressionException &e)
95  {
96  cerr << "Error: Proxy could not be set ("
97  << e.displayText() << ")\n";
98  }
99  catch (const std::invalid_argument &e)
100  {
101  cerr << "Error: " << e.what() << endl;
102  }
103  catch (const std::exception &)
104  {
105  // No proxy found, no problem.
106  }
107  }

Member Function Documentation

@@ -175,7 +175,7 @@ string _uri

Save URI in archive and return archive-URI.

Since
0.6.0
-
599  {
600  if (_uri.substr(0, 4) != "http")
601  {
602  return { false, "Only HTTP(S) is archivable.", "" };
603  }
604 
605  try
606  {
607  const string answer = make_request("https://web.archive.org/save/"
608  + _uri, true);
609 
610  if (!answer.empty())
611  {
612  return { true, "", "https://web.archive.org" + answer };
613  }
614  }
615  catch (const Poco::Exception &e)
616  {
617  return { false, e.displayText(), "" };
618  }
619 
620  return { false, "Unknown error.", "" };
621  }
const string make_request(const string &uri, bool archive=false) const
Make a HTTP(S) request.
Definition: uri.cpp:131
+
607  {
608  if (_uri.substr(0, 4) != "http")
609  {
610  return { false, "Only HTTP(S) is archivable.", "" };
611  }
612 
613  try
614  {
615  const string answer = make_request("https://web.archive.org/save/"
616  + _uri, true);
617 
618  if (!answer.empty())
619  {
620  return { true, "", "https://web.archive.org" + answer };
621  }
622  }
623  catch (const Poco::Exception &e)
624  {
625  return { false, e.displayText(), "" };
626  }
627 
628  return { false, "Unknown error.", "" };
629  }
const string make_request(const string &uri, bool archive=false) const
Make a HTTP(S) request.
Definition: uri.cpp:139
@@ -205,8 +205,8 @@ string _uri

Extract the description from an HTML page.

Since
0.6.0
-
222  {
223  const RegEx re_htmlfile(".*\\.(.?html?|xml|rss)$", RegEx::RE_CASELESS);
224  if (_uri.substr(0, 4) == "http" || re_htmlfile.match(_uri))
225  {
226  const RegEx re_desc("description\"[^>]+content=\"([^\"]+)",
227  RegEx::RE_CASELESS);
228  vector<string> matches;
229  re_desc.split(html, matches);
230  if (matches.size() >= 2)
231  {
232  return remove_newlines(unescape_html(matches[1]));
233  }
234  }
235 
236  return "";
237  }
const string unescape_html(string html)
Convert HTML entities to UTF-8.
Definition: uri.cpp:298
-
const string remove_newlines(string text)
Replace newlines with spaces.
Definition: uri.cpp:623
+
230  {
231  const RegEx re_htmlfile(".*\\.(.?html?|xml|rss)$", RegEx::RE_CASELESS);
232  if (_uri.substr(0, 4) == "http" || re_htmlfile.match(_uri))
233  {
234  const RegEx re_desc("description\"[^>]+content=\"([^\"]+)",
235  RegEx::RE_CASELESS);
236  vector<string> matches;
237  re_desc.split(html, matches);
238  if (matches.size() >= 2)
239  {
240  return remove_newlines(unescape_html(matches[1]));
241  }
242  }
243 
244  return "";
245  }
const string unescape_html(string html)
Convert HTML entities to UTF-8.
Definition: uri.cpp:306
+
const string remove_newlines(string text)
Replace newlines with spaces.
Definition: uri.cpp:631
@@ -236,8 +236,8 @@ string _uri

Extract the title from an HTML page.

Since
0.6.0
-
205  {
206  const RegEx re_htmlfile(".*\\.(.?html?|xml|rss)$", RegEx::RE_CASELESS);
207  if (_uri.substr(0, 4) == "http" || re_htmlfile.match(_uri))
208  {
209  const RegEx re_title("<title>([^<]+)", RegEx::RE_CASELESS);
210  vector<string> matches;
211  re_title.split(html, matches);
212  if (matches.size() >= 2)
213  {
214  return remove_newlines(unescape_html(matches[1]));
215  }
216  }
217 
218  return "";
219  }
const string unescape_html(string html)
Convert HTML entities to UTF-8.
Definition: uri.cpp:298
-
const string remove_newlines(string text)
Replace newlines with spaces.
Definition: uri.cpp:623
+
213  {
214  const RegEx re_htmlfile(".*\\.(.?html?|xml|rss)$", RegEx::RE_CASELESS);
215  if (_uri.substr(0, 4) == "http" || re_htmlfile.match(_uri))
216  {
217  const RegEx re_title("<title>([^<]+)", RegEx::RE_CASELESS);
218  vector<string> matches;
219  re_title.split(html, matches);
220  if (matches.size() >= 2)
221  {
222  return remove_newlines(unescape_html(matches[1]));
223  }
224  }
225 
226  return "";
227  }
const string unescape_html(string html)
Convert HTML entities to UTF-8.
Definition: uri.cpp:306
+
const string remove_newlines(string text)
Replace newlines with spaces.
Definition: uri.cpp:631
@@ -258,10 +258,10 @@ string _uri

Download URI and extract title, description and full text.

Since
0.6.0
-
107  {
108  try
109  {
110  const string answer = make_request(_uri);
111  if (!answer.empty())
112  {
113  return
114  {
115  true,
116  "",
117  extract_title(answer),
118  extract_description(answer),
119  strip_html(answer)
120  };
121  }
122  }
123  catch (const Poco::Exception &e)
124  {
125  return { false, e.displayText(), "", "", "" };
126  }
127 
128  return { false, "Unknown error.", "", "", "" };
129  }
const string strip_html(const string &html)
Removes HTML tags and superflous spaces from an HTML page.
Definition: uri.cpp:239
-
const string extract_title(const string &html)
Extract the title from an HTML page.
Definition: uri.cpp:204
-
const string make_request(const string &uri, bool archive=false) const
Make a HTTP(S) request.
Definition: uri.cpp:131
-
const string extract_description(const string &html)
Extract the description from an HTML page.
Definition: uri.cpp:221
+
115  {
116  try
117  {
118  const string answer = make_request(_uri);
119  if (!answer.empty())
120  {
121  return
122  {
123  true,
124  "",
125  extract_title(answer),
126  extract_description(answer),
127  strip_html(answer)
128  };
129  }
130  }
131  catch (const Poco::Exception &e)
132  {
133  return { false, e.displayText(), "", "", "" };
134  }
135 
136  return { false, "Unknown error.", "", "", "" };
137  }
const string strip_html(const string &html)
Removes HTML tags and superflous spaces from an HTML page.
Definition: uri.cpp:247
+
const string extract_title(const string &html)
Extract the title from an HTML page.
Definition: uri.cpp:212
+
const string make_request(const string &uri, bool archive=false) const
Make a HTTP(S) request.
Definition: uri.cpp:139
+
const string extract_description(const string &html)
Extract the description from an HTML page.
Definition: uri.cpp:229
@@ -301,8 +301,8 @@ string _uri

Make a HTTP(S) request.

Since
0.6.0
-
132  {
133  Poco::URI poco_uri(uri);
134  string method =
135  archive ? HTTPRequest::HTTP_HEAD : HTTPRequest::HTTP_GET;
136  string path = poco_uri.getPathAndQuery();
137  if (path.empty())
138  {
139  path = "/";
140  }
141 
142  unique_ptr<HTTPClientSession> session;
143  if (poco_uri.getScheme() == "https")
144  {
145  session = make_unique<HTTPSClientSession>(poco_uri.getHost(),
146  poco_uri.getPort());
147  }
148  else if (poco_uri.getScheme() == "http")
149  {
150  session = make_unique<HTTPClientSession>(poco_uri.getHost(),
151  poco_uri.getPort());
152  }
153  else
154  {
155  throw Poco::Exception("Protocol not supported.");
156  }
157 
158  HTTPRequest request(method, path, HTTPMessage::HTTP_1_1);
159  request.set("User-Agent", string("remwharead/") + global::version);
160 
161  HTTPResponse response;
162 
163  session->sendRequest(request);
164  istream &rs = session->receiveResponse(response);
165 
166  // Not using the constants because some are too new for Debian stretch.
167  switch (response.getStatus())
168  {
169  case 301: // HTTPResponse::HTTP_MOVED_PERMANENTLY
170  case 308: // HTTPResponse::HTTP_PERMANENT_REDIRECT
171  case 302: // HTTPResponse::HTTP_FOUND
172  case 303: // HTTPResponse::HTTP_SEE_OTHER
173  case 307: // HTTPResponse::HTTP_TEMPORARY_REDIRECT
174  {
175  string location = response.get("Location");
176  if (location.substr(0, 4) != "http")
177  {
178  location = poco_uri.getScheme() + "://" + poco_uri.getHost()
179  + location;
180  }
181  return make_request(location);
182  }
183  case HTTPResponse::HTTP_OK:
184  {
185  string answer;
186  if (archive)
187  {
188  answer = response.get("Content-Location");
189  }
190  else
191  {
192  StreamCopier::copyToString(rs, answer);
193  }
194  return answer;
195  }
196  default:
197  {
198  throw Poco::Exception(response.getReason());
199  return "";
200  }
201  }
202  }
const string make_request(const string &uri, bool archive=false) const
Make a HTTP(S) request.
Definition: uri.cpp:131
-
const archive_answer archive()
Save URI in archive and return archive-URI.
Definition: uri.cpp:598
+
140  {
141  Poco::URI poco_uri(uri);
142  string method =
143  archive ? HTTPRequest::HTTP_HEAD : HTTPRequest::HTTP_GET;
144  string path = poco_uri.getPathAndQuery();
145  if (path.empty())
146  {
147  path = "/";
148  }
149 
150  unique_ptr<HTTPClientSession> session;
151  if (poco_uri.getScheme() == "https")
152  {
153  session = make_unique<HTTPSClientSession>(poco_uri.getHost(),
154  poco_uri.getPort());
155  }
156  else if (poco_uri.getScheme() == "http")
157  {
158  session = make_unique<HTTPClientSession>(poco_uri.getHost(),
159  poco_uri.getPort());
160  }
161  else
162  {
163  throw Poco::Exception("Protocol not supported.");
164  }
165 
166  HTTPRequest request(method, path, HTTPMessage::HTTP_1_1);
167  request.set("User-Agent", string("remwharead/") + global::version);
168 
169  HTTPResponse response;
170 
171  session->sendRequest(request);
172  istream &rs = session->receiveResponse(response);
173 
174  // Not using the constants because some are too new for Debian stretch.
175  switch (response.getStatus())
176  {
177  case 301: // HTTPResponse::HTTP_MOVED_PERMANENTLY
178  case 308: // HTTPResponse::HTTP_PERMANENT_REDIRECT
179  case 302: // HTTPResponse::HTTP_FOUND
180  case 303: // HTTPResponse::HTTP_SEE_OTHER
181  case 307: // HTTPResponse::HTTP_TEMPORARY_REDIRECT
182  {
183  string location = response.get("Location");
184  if (location.substr(0, 4) != "http")
185  {
186  location = poco_uri.getScheme() + "://" + poco_uri.getHost()
187  + location;
188  }
189  return make_request(location);
190  }
191  case HTTPResponse::HTTP_OK:
192  {
193  string answer;
194  if (archive)
195  {
196  answer = response.get("Content-Location");
197  }
198  else
199  {
200  StreamCopier::copyToString(rs, answer);
201  }
202  return answer;
203  }
204  default:
205  {
206  throw Poco::Exception(response.getReason());
207  return "";
208  }
209  }
210  }
const string make_request(const string &uri, bool archive=false) const
Make a HTTP(S) request.
Definition: uri.cpp:139
+
const archive_answer archive()
Save URI in archive and return archive-URI.
Definition: uri.cpp:606
@@ -349,7 +349,7 @@ string _uri
Since
0.6.0
-
261  {
262  // NOTE: I did this with regex_replace before, but libstdc++ segfaulted.
263  string out;
264  if (tag.empty())
265  {
266  size_t pos = 0;
267  while (pos != std::string::npos)
268  {
269  size_t startpos = html.find('<', pos);
270  size_t endpos = html.find('>', startpos);
271  out += html.substr(pos, startpos - pos);
272  pos = endpos;
273  if (pos != std::string::npos)
274  {
275  ++pos;
276  }
277  }
278  }
279  else
280  {
281  size_t pos = 0;
282  out = html;
283  while ((pos = out.find("<" + tag)) != std::string::npos)
284  {
285  size_t endpos = out.find("</" + tag, pos);
286  if (endpos == std::string::npos)
287  {
288  break;
289  }
290  endpos += 3 + tag.length(); // tag + </ + >
291  out.replace(pos, endpos - pos, "");
292  }
293  }
294 
295  return out;
296  }
+
269  {
270  // NOTE: I did this with regex_replace before, but libstdc++ segfaulted.
271  string out;
272  if (tag.empty())
273  {
274  size_t pos = 0;
275  while (pos != std::string::npos)
276  {
277  size_t startpos = html.find('<', pos);
278  size_t endpos = html.find('>', startpos);
279  out += html.substr(pos, startpos - pos);
280  pos = endpos;
281  if (pos != std::string::npos)
282  {
283  ++pos;
284  }
285  }
286  }
287  else
288  {
289  size_t pos = 0;
290  out = html;
291  while ((pos = out.find("<" + tag)) != std::string::npos)
292  {
293  size_t endpos = out.find("</" + tag, pos);
294  if (endpos == std::string::npos)
295  {
296  break;
297  }
298  endpos += 3 + tag.length(); // tag + </ + >
299  out.replace(pos, endpos - pos, "");
300  }
301  }
302 
303  return out;
304  }
@@ -378,7 +378,7 @@ string _uri

Replace newlines with spaces.

Since
0.6.0
-
624  {
625  size_t posn = 0;
626  while ((posn = text.find('\n', posn)) != std::string::npos)
627  {
628  text.replace(posn, 1, " ");
629 
630  size_t posr = posn - 1;
631  if (text[posr] == '\r')
632  {
633  text.replace(posr, 1, " ");
634  }
635  ++posn;
636  }
637 
638  return text;
639  }
+
632  {
633  size_t posn = 0;
634  while ((posn = text.find('\n', posn)) != std::string::npos)
635  {
636  text.replace(posn, 1, " ");
637 
638  size_t posr = posn - 1;
639  if (text[posr] == '\r')
640  {
641  text.replace(posr, 1, " ");
642  }
643  ++posn;
644  }
645 
646  return text;
647  }
@@ -407,8 +407,8 @@ string _uri

Removes HTML tags and superflous spaces from an HTML page.

Since
0.6.0
-
240  {
241  string out;
242 
243  out = remove_html_tags(html, "script"); // Remove JavaScript.
244  out = remove_html_tags(out, "style"); // Remove CSS.
245  out = remove_html_tags(out); // Remove tags.
246 
247  size_t pos = 0;
248  while ((pos = out.find("\r", pos)) != std::string::npos) // Remove CR.
249  {
250  out.replace(pos, 1, "");
251  }
252 
253  // Remove whitespace at eol.
254  RegEx("\\s+\n").subst(out, "\n", RegEx::RE_GLOBAL);
255  RegEx("\n{2,}").subst(out, "\n", RegEx::RE_GLOBAL); // Reduce newlines.
256 
257  return unescape_html(out);
258  }
const string unescape_html(string html)
Convert HTML entities to UTF-8.
Definition: uri.cpp:298
-
const string remove_html_tags(const string &html, const string &tag="")
Remove HTML tags.
Definition: uri.cpp:260
+
248  {
249  string out;
250 
251  out = remove_html_tags(html, "script"); // Remove JavaScript.
252  out = remove_html_tags(out, "style"); // Remove CSS.
253  out = remove_html_tags(out); // Remove tags.
254 
255  size_t pos = 0;
256  while ((pos = out.find("\r", pos)) != std::string::npos) // Remove CR.
257  {
258  out.replace(pos, 1, "");
259  }
260 
261  // Remove whitespace at eol.
262  RegEx("\\s+\n").subst(out, "\n", RegEx::RE_GLOBAL);
263  RegEx("\n{2,}").subst(out, "\n", RegEx::RE_GLOBAL); // Reduce newlines.
264 
265  return unescape_html(out);
266  }
const string unescape_html(string html)
Convert HTML entities to UTF-8.
Definition: uri.cpp:306
+
const string remove_html_tags(const string &html, const string &tag="")
Remove HTML tags.
Definition: uri.cpp:268
@@ -438,7 +438,7 @@ string _uri

Convert HTML entities to UTF-8.

Since
0.6.0
-
299  {
300  // Used to convert int to utf-8 char.
301  std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> u8c;
302  const RegEx re_entity("&#(x)?([[:alnum:]]{1,8});");
303  RegEx::MatchVec matches;
304  string::size_type pos = 0;
305 
306  while (re_entity.match(html, pos, matches) != 0)
307  {
308  char32_t codepoint = 0;
309  const string number = html.substr(matches[2].offset,
310  matches[2].length);
311  // 'x' in front of the number means it's hexadecimal, else decimal.
312  if (matches[1].length != 0)
313  {
314  codepoint = std::stoi(number, nullptr, 16);
315  }
316  else
317  {
318  codepoint = std::stoi(number, nullptr, 10);
319  }
320  const string unicode = u8c.to_bytes(codepoint);
321  html.replace(matches[0].offset, matches[0].length, unicode);
322  pos = matches[0].offset + unicode.length();
323  }
324 
325  // Source: https://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_
326  // entity_references#Character_entity_references_in_HTML
327  const array<const std::pair<const string, const char32_t>, 258> names =
328  {{
329  { "exclamation", 0x0021 },
330  { "quot", 0x0022 },
331  { "percent", 0x0025 },
332  { "amp", 0x0026 },
333  { "apos", 0x0027 },
334  { "add", 0x002B },
335  { "lt", 0x003C },
336  { "equal", 0x003D },
337  { "gt", 0x003E },
338  { "nbsp", 0x00A0 },
339  { "iexcl", 0x00A1 },
340  { "cent", 0x00A2 },
341  { "pound", 0x00A3 },
342  { "curren", 0x00A4 },
343  { "yen", 0x00A5 },
344  { "brvbar", 0x00A6 },
345  { "sect", 0x00A7 },
346  { "uml", 0x00A8 },
347  { "copy", 0x00A9 },
348  { "ordf", 0x00AA },
349  { "laquo", 0x00AB },
350  { "not", 0x00AC },
351  { "shy", 0x00AD },
352  { "reg", 0x00AE },
353  { "macr", 0x00AF },
354  { "deg", 0x00B0 },
355  { "plusmn", 0x00B1 },
356  { "sup2", 0x00B2 },
357  { "sup3", 0x00B3 },
358  { "acute", 0x00B4 },
359  { "micro", 0x00B5 },
360  { "para", 0x00B6 },
361  { "middot", 0x00B7 },
362  { "cedil", 0x00B8 },
363  { "sup1", 0x00B9 },
364  { "ordm", 0x00BA },
365  { "raquo", 0x00BB },
366  { "frac14", 0x00BC },
367  { "frac12", 0x00BD },
368  { "frac34", 0x00BE },
369  { "iquest", 0x00BF },
370  { "Agrave", 0x00C0 },
371  { "Aacute", 0x00C1 },
372  { "Acirc", 0x00C2 },
373  { "Atilde", 0x00C3 },
374  { "Auml", 0x00C4 },
375  { "Aring", 0x00C5 },
376  { "AElig", 0x00C6 },
377  { "Ccedil", 0x00C7 },
378  { "Egrave", 0x00C8 },
379  { "Eacute", 0x00C9 },
380  { "Ecirc", 0x00CA },
381  { "Euml", 0x00CB },
382  { "Igrave", 0x00CC },
383  { "Iacute", 0x00CD },
384  { "Icirc", 0x00CE },
385  { "Iuml", 0x00CF },
386  { "ETH", 0x00D0 },
387  { "Ntilde", 0x00D1 },
388  { "Ograve", 0x00D2 },
389  { "Oacute", 0x00D3 },
390  { "Ocirc", 0x00D4 },
391  { "Otilde", 0x00D5 },
392  { "Ouml", 0x00D6 },
393  { "times", 0x00D7 },
394  { "Oslash", 0x00D8 },
395  { "Ugrave", 0x00D9 },
396  { "Uacute", 0x00DA },
397  { "Ucirc", 0x00DB },
398  { "Uuml", 0x00DC },
399  { "Yacute", 0x00DD },
400  { "THORN", 0x00DE },
401  { "szlig", 0x00DF },
402  { "agrave", 0x00E0 },
403  { "aacute", 0x00E1 },
404  { "acirc", 0x00E2 },
405  { "atilde", 0x00E3 },
406  { "auml", 0x00E4 },
407  { "aring", 0x00E5 },
408  { "aelig", 0x00E6 },
409  { "ccedil", 0x00E7 },
410  { "egrave", 0x00E8 },
411  { "eacute", 0x00E9 },
412  { "ecirc", 0x00EA },
413  { "euml", 0x00EB },
414  { "igrave", 0x00EC },
415  { "iacute", 0x00ED },
416  { "icirc", 0x00EE },
417  { "iuml", 0x00EF },
418  { "eth", 0x00F0 },
419  { "ntilde", 0x00F1 },
420  { "ograve", 0x00F2 },
421  { "oacute", 0x00F3 },
422  { "ocirc", 0x00F4 },
423  { "otilde", 0x00F5 },
424  { "ouml", 0x00F6 },
425  { "divide", 0x00F7 },
426  { "oslash", 0x00F8 },
427  { "ugrave", 0x00F9 },
428  { "uacute", 0x00FA },
429  { "ucirc", 0x00FB },
430  { "uuml", 0x00FC },
431  { "yacute", 0x00FD },
432  { "thorn", 0x00FE },
433  { "yuml", 0x00FF },
434  { "OElig", 0x0152 },
435  { "oelig", 0x0153 },
436  { "Scaron", 0x0160 },
437  { "scaron", 0x0161 },
438  { "Yuml", 0x0178 },
439  { "fnof", 0x0192 },
440  { "circ", 0x02C6 },
441  { "tilde", 0x02DC },
442  { "Alpha", 0x0391 },
443  { "Beta", 0x0392 },
444  { "Gamma", 0x0393 },
445  { "Delta", 0x0394 },
446  { "Epsilon", 0x0395 },
447  { "Zeta", 0x0396 },
448  { "Eta", 0x0397 },
449  { "Theta", 0x0398 },
450  { "Iota", 0x0399 },
451  { "Kappa", 0x039A },
452  { "Lambda", 0x039B },
453  { "Mu", 0x039C },
454  { "Nu", 0x039D },
455  { "Xi", 0x039E },
456  { "Omicron", 0x039F },
457  { "Pi", 0x03A0 },
458  { "Rho", 0x03A1 },
459  { "Sigma", 0x03A3 },
460  { "Tau", 0x03A4 },
461  { "Upsilon", 0x03A5 },
462  { "Phi", 0x03A6 },
463  { "Chi", 0x03A7 },
464  { "Psi", 0x03A8 },
465  { "Omega", 0x03A9 },
466  { "alpha", 0x03B1 },
467  { "beta", 0x03B2 },
468  { "gamma", 0x03B3 },
469  { "delta", 0x03B4 },
470  { "epsilon", 0x03B5 },
471  { "zeta", 0x03B6 },
472  { "eta", 0x03B7 },
473  { "theta", 0x03B8 },
474  { "iota", 0x03B9 },
475  { "kappa", 0x03BA },
476  { "lambda", 0x03BB },
477  { "mu", 0x03BC },
478  { "nu", 0x03BD },
479  { "xi", 0x03BE },
480  { "omicron", 0x03BF },
481  { "pi", 0x03C0 },
482  { "rho", 0x03C1 },
483  { "sigmaf", 0x03C2 },
484  { "sigma", 0x03C3 },
485  { "tau", 0x03C4 },
486  { "upsilon", 0x03C5 },
487  { "phi", 0x03C6 },
488  { "chi", 0x03C7 },
489  { "psi", 0x03C8 },
490  { "omega", 0x03C9 },
491  { "thetasym", 0x03D1 },
492  { "upsih", 0x03D2 },
493  { "piv", 0x03D6 },
494  { "ensp", 0x2002 },
495  { "emsp", 0x2003 },
496  { "thinsp", 0x2009 },
497  { "zwnj", 0x200C },
498  { "zwj", 0x200D },
499  { "lrm", 0x200E },
500  { "rlm", 0x200F },
501  { "ndash", 0x2013 },
502  { "mdash", 0x2014 },
503  { "horbar", 0x2015 },
504  { "lsquo", 0x2018 },
505  { "rsquo", 0x2019 },
506  { "sbquo", 0x201A },
507  { "ldquo", 0x201C },
508  { "rdquo", 0x201D },
509  { "bdquo", 0x201E },
510  { "dagger", 0x2020 },
511  { "Dagger", 0x2021 },
512  { "bull", 0x2022 },
513  { "hellip", 0x2026 },
514  { "permil", 0x2030 },
515  { "prime", 0x2032 },
516  { "Prime", 0x2033 },
517  { "lsaquo", 0x2039 },
518  { "rsaquo", 0x203A },
519  { "oline", 0x203E },
520  { "frasl", 0x2044 },
521  { "euro", 0x20AC },
522  { "image", 0x2111 },
523  { "weierp", 0x2118 },
524  { "real", 0x211C },
525  { "trade", 0x2122 },
526  { "alefsym", 0x2135 },
527  { "larr", 0x2190 },
528  { "uarr", 0x2191 },
529  { "rarr", 0x2192 },
530  { "darr", 0x2193 },
531  { "harr", 0x2194 },
532  { "crarr", 0x21B5 },
533  { "lArr", 0x21D0 },
534  { "uArr", 0x21D1 },
535  { "rArr", 0x21D2 },
536  { "dArr", 0x21D3 },
537  { "hArr", 0x21D4 },
538  { "forall", 0x2200 },
539  { "part", 0x2202 },
540  { "exist", 0x2203 },
541  { "empty", 0x2205 },
542  { "nabla", 0x2207 },
543  { "isin", 0x2208 },
544  { "notin", 0x2209 },
545  { "ni", 0x220B },
546  { "prod", 0x220F },
547  { "sum", 0x2211 },
548  { "minus", 0x2212 },
549  { "lowast", 0x2217 },
550  { "radic", 0x221A },
551  { "prop", 0x221D },
552  { "infin", 0x221E },
553  { "ang", 0x2220 },
554  { "and", 0x2227 },
555  { "or", 0x2228 },
556  { "cap", 0x2229 },
557  { "cup", 0x222A },
558  { "int", 0x222B },
559  { "there4", 0x2234 },
560  { "sim", 0x223C },
561  { "cong", 0x2245 },
562  { "asymp", 0x2248 },
563  { "ne", 0x2260 },
564  { "equiv", 0x2261 },
565  { "le", 0x2264 },
566  { "ge", 0x2265 },
567  { "sub", 0x2282 },
568  { "sup", 0x2283 },
569  { "nsub", 0x2284 },
570  { "sube", 0x2286 },
571  { "supe", 0x2287 },
572  { "oplus", 0x2295 },
573  { "otimes", 0x2297 },
574  { "perp", 0x22A5 },
575  { "sdot", 0x22C5 },
576  { "lceil", 0x2308 },
577  { "rceil", 0x2309 },
578  { "lfloor", 0x230A },
579  { "rfloor", 0x230B },
580  { "lang", 0x2329 },
581  { "rang", 0x232A },
582  { "loz", 0x25CA },
583  { "spades", 0x2660 },
584  { "clubs", 0x2663 },
585  { "hearts", 0x2665 },
586  { "diams", 0x2666 }
587  }};
588 
589  for (auto &pair : names)
590  {
591  const RegEx re('&' + pair.first + ';');
592  re.subst(html, u8c.to_bytes(pair.second), RegEx::RE_GLOBAL);
593  }
594 
595  return html;
596  }
+
307  {
308  // Used to convert int to utf-8 char.
309  std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> u8c;
310  const RegEx re_entity("&#(x)?([[:alnum:]]{1,8});");
311  RegEx::MatchVec matches;
312  string::size_type pos = 0;
313 
314  while (re_entity.match(html, pos, matches) != 0)
315  {
316  char32_t codepoint = 0;
317  const string number = html.substr(matches[2].offset,
318  matches[2].length);
319  // 'x' in front of the number means it's hexadecimal, else decimal.
320  if (matches[1].length != 0)
321  {
322  codepoint = std::stoi(number, nullptr, 16);
323  }
324  else
325  {
326  codepoint = std::stoi(number, nullptr, 10);
327  }
328  const string unicode = u8c.to_bytes(codepoint);
329  html.replace(matches[0].offset, matches[0].length, unicode);
330  pos = matches[0].offset + unicode.length();
331  }
332 
333  // Source: https://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_
334  // entity_references#Character_entity_references_in_HTML
335  const array<const std::pair<const string, const char32_t>, 258> names =
336  {{
337  { "exclamation", 0x0021 },
338  { "quot", 0x0022 },
339  { "percent", 0x0025 },
340  { "amp", 0x0026 },
341  { "apos", 0x0027 },
342  { "add", 0x002B },
343  { "lt", 0x003C },
344  { "equal", 0x003D },
345  { "gt", 0x003E },
346  { "nbsp", 0x00A0 },
347  { "iexcl", 0x00A1 },
348  { "cent", 0x00A2 },
349  { "pound", 0x00A3 },
350  { "curren", 0x00A4 },
351  { "yen", 0x00A5 },
352  { "brvbar", 0x00A6 },
353  { "sect", 0x00A7 },
354  { "uml", 0x00A8 },
355  { "copy", 0x00A9 },
356  { "ordf", 0x00AA },
357  { "laquo", 0x00AB },
358  { "not", 0x00AC },
359  { "shy", 0x00AD },
360  { "reg", 0x00AE },
361  { "macr", 0x00AF },
362  { "deg", 0x00B0 },
363  { "plusmn", 0x00B1 },
364  { "sup2", 0x00B2 },
365  { "sup3", 0x00B3 },
366  { "acute", 0x00B4 },
367  { "micro", 0x00B5 },
368  { "para", 0x00B6 },
369  { "middot", 0x00B7 },
370  { "cedil", 0x00B8 },
371  { "sup1", 0x00B9 },
372  { "ordm", 0x00BA },
373  { "raquo", 0x00BB },
374  { "frac14", 0x00BC },
375  { "frac12", 0x00BD },
376  { "frac34", 0x00BE },
377  { "iquest", 0x00BF },
378  { "Agrave", 0x00C0 },
379  { "Aacute", 0x00C1 },
380  { "Acirc", 0x00C2 },
381  { "Atilde", 0x00C3 },
382  { "Auml", 0x00C4 },
383  { "Aring", 0x00C5 },
384  { "AElig", 0x00C6 },
385  { "Ccedil", 0x00C7 },
386  { "Egrave", 0x00C8 },
387  { "Eacute", 0x00C9 },
388  { "Ecirc", 0x00CA },
389  { "Euml", 0x00CB },
390  { "Igrave", 0x00CC },
391  { "Iacute", 0x00CD },
392  { "Icirc", 0x00CE },
393  { "Iuml", 0x00CF },
394  { "ETH", 0x00D0 },
395  { "Ntilde", 0x00D1 },
396  { "Ograve", 0x00D2 },
397  { "Oacute", 0x00D3 },
398  { "Ocirc", 0x00D4 },
399  { "Otilde", 0x00D5 },
400  { "Ouml", 0x00D6 },
401  { "times", 0x00D7 },
402  { "Oslash", 0x00D8 },
403  { "Ugrave", 0x00D9 },
404  { "Uacute", 0x00DA },
405  { "Ucirc", 0x00DB },
406  { "Uuml", 0x00DC },
407  { "Yacute", 0x00DD },
408  { "THORN", 0x00DE },
409  { "szlig", 0x00DF },
410  { "agrave", 0x00E0 },
411  { "aacute", 0x00E1 },
412  { "acirc", 0x00E2 },
413  { "atilde", 0x00E3 },
414  { "auml", 0x00E4 },
415  { "aring", 0x00E5 },
416  { "aelig", 0x00E6 },
417  { "ccedil", 0x00E7 },
418  { "egrave", 0x00E8 },
419  { "eacute", 0x00E9 },
420  { "ecirc", 0x00EA },
421  { "euml", 0x00EB },
422  { "igrave", 0x00EC },
423  { "iacute", 0x00ED },
424  { "icirc", 0x00EE },
425  { "iuml", 0x00EF },
426  { "eth", 0x00F0 },
427  { "ntilde", 0x00F1 },
428  { "ograve", 0x00F2 },
429  { "oacute", 0x00F3 },
430  { "ocirc", 0x00F4 },
431  { "otilde", 0x00F5 },
432  { "ouml", 0x00F6 },
433  { "divide", 0x00F7 },
434  { "oslash", 0x00F8 },
435  { "ugrave", 0x00F9 },
436  { "uacute", 0x00FA },
437  { "ucirc", 0x00FB },
438  { "uuml", 0x00FC },
439  { "yacute", 0x00FD },
440  { "thorn", 0x00FE },
441  { "yuml", 0x00FF },
442  { "OElig", 0x0152 },
443  { "oelig", 0x0153 },
444  { "Scaron", 0x0160 },
445  { "scaron", 0x0161 },
446  { "Yuml", 0x0178 },
447  { "fnof", 0x0192 },
448  { "circ", 0x02C6 },
449  { "tilde", 0x02DC },
450  { "Alpha", 0x0391 },
451  { "Beta", 0x0392 },
452  { "Gamma", 0x0393 },
453  { "Delta", 0x0394 },
454  { "Epsilon", 0x0395 },
455  { "Zeta", 0x0396 },
456  { "Eta", 0x0397 },
457  { "Theta", 0x0398 },
458  { "Iota", 0x0399 },
459  { "Kappa", 0x039A },
460  { "Lambda", 0x039B },
461  { "Mu", 0x039C },
462  { "Nu", 0x039D },
463  { "Xi", 0x039E },
464  { "Omicron", 0x039F },
465  { "Pi", 0x03A0 },
466  { "Rho", 0x03A1 },
467  { "Sigma", 0x03A3 },
468  { "Tau", 0x03A4 },
469  { "Upsilon", 0x03A5 },
470  { "Phi", 0x03A6 },
471  { "Chi", 0x03A7 },
472  { "Psi", 0x03A8 },
473  { "Omega", 0x03A9 },
474  { "alpha", 0x03B1 },
475  { "beta", 0x03B2 },
476  { "gamma", 0x03B3 },
477  { "delta", 0x03B4 },
478  { "epsilon", 0x03B5 },
479  { "zeta", 0x03B6 },
480  { "eta", 0x03B7 },
481  { "theta", 0x03B8 },
482  { "iota", 0x03B9 },
483  { "kappa", 0x03BA },
484  { "lambda", 0x03BB },
485  { "mu", 0x03BC },
486  { "nu", 0x03BD },
487  { "xi", 0x03BE },
488  { "omicron", 0x03BF },
489  { "pi", 0x03C0 },
490  { "rho", 0x03C1 },
491  { "sigmaf", 0x03C2 },
492  { "sigma", 0x03C3 },
493  { "tau", 0x03C4 },
494  { "upsilon", 0x03C5 },
495  { "phi", 0x03C6 },
496  { "chi", 0x03C7 },
497  { "psi", 0x03C8 },
498  { "omega", 0x03C9 },
499  { "thetasym", 0x03D1 },
500  { "upsih", 0x03D2 },
501  { "piv", 0x03D6 },
502  { "ensp", 0x2002 },
503  { "emsp", 0x2003 },
504  { "thinsp", 0x2009 },
505  { "zwnj", 0x200C },
506  { "zwj", 0x200D },
507  { "lrm", 0x200E },
508  { "rlm", 0x200F },
509  { "ndash", 0x2013 },
510  { "mdash", 0x2014 },
511  { "horbar", 0x2015 },
512  { "lsquo", 0x2018 },
513  { "rsquo", 0x2019 },
514  { "sbquo", 0x201A },
515  { "ldquo", 0x201C },
516  { "rdquo", 0x201D },
517  { "bdquo", 0x201E },
518  { "dagger", 0x2020 },
519  { "Dagger", 0x2021 },
520  { "bull", 0x2022 },
521  { "hellip", 0x2026 },
522  { "permil", 0x2030 },
523  { "prime", 0x2032 },
524  { "Prime", 0x2033 },
525  { "lsaquo", 0x2039 },
526  { "rsaquo", 0x203A },
527  { "oline", 0x203E },
528  { "frasl", 0x2044 },
529  { "euro", 0x20AC },
530  { "image", 0x2111 },
531  { "weierp", 0x2118 },
532  { "real", 0x211C },
533  { "trade", 0x2122 },
534  { "alefsym", 0x2135 },
535  { "larr", 0x2190 },
536  { "uarr", 0x2191 },
537  { "rarr", 0x2192 },
538  { "darr", 0x2193 },
539  { "harr", 0x2194 },
540  { "crarr", 0x21B5 },
541  { "lArr", 0x21D0 },
542  { "uArr", 0x21D1 },
543  { "rArr", 0x21D2 },
544  { "dArr", 0x21D3 },
545  { "hArr", 0x21D4 },
546  { "forall", 0x2200 },
547  { "part", 0x2202 },
548  { "exist", 0x2203 },
549  { "empty", 0x2205 },
550  { "nabla", 0x2207 },
551  { "isin", 0x2208 },
552  { "notin", 0x2209 },
553  { "ni", 0x220B },
554  { "prod", 0x220F },
555  { "sum", 0x2211 },
556  { "minus", 0x2212 },
557  { "lowast", 0x2217 },
558  { "radic", 0x221A },
559  { "prop", 0x221D },
560  { "infin", 0x221E },
561  { "ang", 0x2220 },
562  { "and", 0x2227 },
563  { "or", 0x2228 },
564  { "cap", 0x2229 },
565  { "cup", 0x222A },
566  { "int", 0x222B },
567  { "there4", 0x2234 },
568  { "sim", 0x223C },
569  { "cong", 0x2245 },
570  { "asymp", 0x2248 },
571  { "ne", 0x2260 },
572  { "equiv", 0x2261 },
573  { "le", 0x2264 },
574  { "ge", 0x2265 },
575  { "sub", 0x2282 },
576  { "sup", 0x2283 },
577  { "nsub", 0x2284 },
578  { "sube", 0x2286 },
579  { "supe", 0x2287 },
580  { "oplus", 0x2295 },
581  { "otimes", 0x2297 },
582  { "perp", 0x22A5 },
583  { "sdot", 0x22C5 },
584  { "lceil", 0x2308 },
585  { "rceil", 0x2309 },
586  { "lfloor", 0x230A },
587  { "rfloor", 0x230B },
588  { "lang", 0x2329 },
589  { "rang", 0x232A },
590  { "loz", 0x25CA },
591  { "spades", 0x2660 },
592  { "clubs", 0x2663 },
593  { "hearts", 0x2665 },
594  { "diams", 0x2666 }
595  }};
596 
597  for (auto &pair : names)
598  {
599  const RegEx re('&' + pair.first + ';');
600  re.subst(html, u8c.to_bytes(pair.second), RegEx::RE_GLOBAL);
601  }
602 
603  return html;
604  }

The documentation for this class was generated from the following files: