Skip to content

Commit 1604bf5

Browse files
committed
Use new HTML utils in issues.cpp
1 parent af3ca27 commit 1604bf5

File tree

2 files changed

+21
-54
lines changed

2 files changed

+21
-54
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ bin/lists: src/issues.o src/status.o src/sections.o src/mailing_info.o src/repor
4040

4141
bin/section_data: src/section_data.o
4242

43-
bin/list_issues: src/issues.o src/status.o src/sections.o src/list_issues.o src/metadata.o
43+
bin/list_issues: src/issues.o src/status.o src/sections.o src/list_issues.o src/metadata.o src/html_utils.o
4444

4545
bin/set_status: src/set_status.o src/status.o
4646

src/issues.cpp

Lines changed: 20 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "issues.h"
66
#include "metadata.h"
77
#include "status.h"
8+
#include "html_utils.h"
89

910
#include <algorithm>
1011
#include <cassert>
@@ -155,37 +156,16 @@ auto lwg::parse_issue_from_file(std::string tx, std::string const & filename,
155156
issue is;
156157

157158
// Get issue number
158-
std::string_view match = "<issue num=\"";
159-
auto k = tx.find(match);
160-
if (k == std::string::npos) {
161-
throw bad_issue_file{filename, "Unable to find issue number"};
162-
}
163-
k += match.size();
164-
auto l = tx.find('"', k);
165-
auto num = tx.substr(k, l-k);
159+
std::string_view num = lwg::get_attribute_of("num", "issue", tx);
166160
if (!filename.ends_with(std::format("issue{:0>4}.xml", num)))
167161
std::cerr << "warning: issue number " << num << " in " << filename << " does not match issue number\n";
168-
is.num = lwg::stoi(num);
162+
is.num = lwg::stoi(std::string(num));
169163

170164
// Get issue status
171-
match = "status=\"";
172-
k = tx.find(match, l);
173-
if (k == std::string::npos) {
174-
throw bad_issue_file{filename, "Unable to find issue status"};
175-
}
176-
k += match.size();
177-
l = tx.find('"', k);
178-
is.stat = tx.substr(k, l-k);
165+
is.stat = lwg::get_attribute_of("status", "issue", tx);
179166

180167
// Get issue title
181-
match = "<title>";
182-
k = tx.find(match, l);
183-
if (k == std::string::npos) {
184-
throw bad_issue_file{filename, "Unable to find issue title"};
185-
}
186-
k += match.size();
187-
l = tx.find("</title>", k);
188-
is.title = tx.substr(k, l-k);
168+
is.title = lwg::get_element_contents("title", tx);
189169

190170
// Extract doc_prefix from title
191171
if (is.title[0] == '['
@@ -197,9 +177,11 @@ auto lwg::parse_issue_from_file(std::string tx, std::string const & filename,
197177
// std::cout << is.doc_prefix << '\n';
198178
}
199179

180+
std::string::size_type l = 0;
181+
200182
// Get issue sections
201-
match = "<section>";
202-
k = tx.find(match, l);
183+
std::string_view match = "<section>";
184+
auto k = tx.find(match, l);
203185
if (k == std::string::npos) {
204186
throw bad_issue_file{filename, "Unable to find issue section"};
205187
}
@@ -236,26 +218,17 @@ auto lwg::parse_issue_from_file(std::string tx, std::string const & filename,
236218
}
237219

238220
// Get submitter
239-
match = "<submitter>";
240-
k = tx.find(match, l);
241-
if (k == std::string::npos) {
242-
throw bad_issue_file{filename, "Unable to find issue submitter"};
243-
}
244-
k += match.size();
245-
l = tx.find("</submitter>", k);
246-
is.submitter = tx.substr(k, l-k);
221+
is.submitter = lwg::get_element_contents("submitter", tx);
247222

248223
// Get date
249-
match = "<date>";
250-
k = tx.find(match, l);
251-
if (k == std::string::npos) {
252-
throw bad_issue_file{filename, "Unable to find issue date"};
253-
}
254-
k += match.size();
255-
l = tx.find("</date>", k);
224+
auto datestr = lwg::get_element_contents("date", tx);
256225

257226
try {
258-
std::istringstream temp{tx.substr(k, l-k)};
227+
#ifdef __cpp_lib_sstream_from_string_view
228+
std::istringstream temp{datestr};
229+
#else
230+
std::istringstream temp{std::string{datestr}};
231+
#endif
259232
is.date = parse_date(temp);
260233
}
261234
catch(std::exception const & ex) {
@@ -286,21 +259,15 @@ auto lwg::parse_issue_from_file(std::string tx, std::string const & filename,
286259

287260
// Find out if issue has a proposed resolution
288261
if (is_active(is.stat) or "Pending WP" == is.stat) {
289-
match = "<resolution>";
290-
auto k2 = tx.find(match, 0);
291-
if (k2 == std::string::npos) {
292-
is.has_resolution = false;
293-
}
294-
else {
295-
k2 += match.size();
296-
auto l2 = tx.find("</resolution>", k2);
297-
is.resolution = tx.substr(k2, l2 - k2);
262+
try {
263+
is.resolution = lwg::get_element_contents("resolution", tx);
298264
if (is.resolution.length() < 15) {
299265
// Filter small amounts of whitespace between tags, with no actual resolution
300266
is.resolution.clear();
301267
}
302-
// is.has_resolution = l2 - k2 > 15;
303268
is.has_resolution = !is.resolution.empty();
269+
} catch (const std::runtime_error&) {
270+
is.has_resolution = false;
304271
}
305272
}
306273
else {

0 commit comments

Comments
 (0)