remwharead  0.8.0
uri.hpp
1 /* This file is part of remwharead.
2  * Copyright © 2019 tastytea <tastytea@tastytea.de>
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, version 3.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 #ifndef REMWHAREAD_URI_HPP
18 #define REMWHAREAD_URI_HPP
19 
20 #include <string>
21 
22 namespace remwharead
23 {
24  using std::string;
25 
35  typedef struct html_extract
36  {
37  bool successful = false;
38  string error;
39  string title;
40  string description;
41  string fulltext;
42 
43  operator bool();
44  } html_extract;
45 
55  typedef struct archive_answer
56  {
57  bool successful = false;
58  string error;
59  string uri;
60 
61  operator bool();
63 
71  class URI
72  {
73  public:
82  explicit URI(const string &uri);
83  virtual ~URI();
84 
90  const html_extract get();
91 
97  const archive_answer archive();
98 
99  protected:
100  string _uri;
101 
107  const string make_request(const string &uri,
108  bool archive = false) const;
109 
115  const string extract_title(const string &html);
116 
122  const string extract_description(const string &html);
123 
129  const string strip_html(const string &html);
130 
139  const string remove_html_tags(const string &html,
140  const string &tag = "");
141 
147  const string unescape_html(const string &html);
148 
154  const string remove_newlines(string text);
155  };
156 }
157 
158 #endif // REMWHAREAD_URI_HPP
A processed HTML page.
Definition: uri.hpp:35
URI(const string &uri)
Construct object and set URL.
Definition: uri.cpp:64
const string remove_html_tags(const string &html, const string &tag="")
Remove HTML tags.
Definition: uri.cpp:253
const string strip_html(const string &html)
Removes HTML tags and superflous spaces from an HTML page.
Definition: uri.cpp:233
const string remove_newlines(string text)
Replace newlines with spaces.
Definition: uri.cpp:616
const string unescape_html(const string &html)
Convert HTML entities to UTF-8.
Definition: uri.cpp:291
The result of the call to the archive service.
Definition: uri.hpp:55
const html_extract get()
Download URI and extract title, description and full text.
Definition: uri.cpp:108
const string extract_title(const string &html)
Extract the title from an HTML page.
Definition: uri.cpp:206
Download, archive and process an URI.
Definition: uri.hpp:71
const string make_request(const string &uri, bool archive=false) const
Make a HTTP(S) request.
Definition: uri.cpp:133
const archive_answer archive()
Save URI in archive and return archive-URI.
Definition: uri.cpp:591
const string extract_description(const string &html)
Extract the description from an HTML page.
Definition: uri.cpp:219