Merge pull request #283 from barryam3/noexcept

Remove use of exceptions.
This commit is contained in:
yhirose 2019-12-05 21:32:06 -05:00 committed by GitHub
commit 66719ae3d4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1881,38 +1881,39 @@ inline bool parse_multipart_boundary(const std::string &content_type,
} }
inline bool parse_range_header(const std::string &s, Ranges &ranges) { inline bool parse_range_header(const std::string &s, Ranges &ranges) {
try { static auto re_first_range =
static auto re_first_range = std::regex(R"(bytes=(\d*-\d*(?:,\s*\d*-\d*)*))");
std::regex(R"(bytes=(\d*-\d*(?:,\s*\d*-\d*)*))"); std::smatch m;
std::smatch m; if (std::regex_match(s, m, re_first_range)) {
if (std::regex_match(s, m, re_first_range)) { auto pos = m.position(1);
auto pos = m.position(1); auto len = m.length(1);
auto len = m.length(1); bool all_valid_ranges = true;
detail::split( detail::split(
&s[pos], &s[pos + len], ',', [&](const char *b, const char *e) { &s[pos], &s[pos + len], ',', [&](const char *b, const char *e) {
static auto re_another_range = std::regex(R"(\s*(\d*)-(\d*))"); if (!all_valid_ranges) return;
std::cmatch m; static auto re_another_range = std::regex(R"(\s*(\d*)-(\d*))");
if (std::regex_match(b, e, m, re_another_range)) { std::cmatch m;
ssize_t first = -1; if (std::regex_match(b, e, m, re_another_range)) {
if (!m.str(1).empty()) { ssize_t first = -1;
first = static_cast<ssize_t>(std::stoll(m.str(1))); if (!m.str(1).empty()) {
} first = static_cast<ssize_t>(std::stoll(m.str(1)));
ssize_t last = -1;
if (!m.str(2).empty()) {
last = static_cast<ssize_t>(std::stoll(m.str(2)));
}
if (first != -1 && last != -1 && first > last) {
throw std::runtime_error("invalid range error");
}
ranges.emplace_back(std::make_pair(first, last));
} }
});
return true; ssize_t last = -1;
} if (!m.str(2).empty()) {
return false; last = static_cast<ssize_t>(std::stoll(m.str(2)));
} catch (...) { return false; } }
if (first != -1 && last != -1 && first > last) {
all_valid_ranges = false;
return;
}
ranges.emplace_back(std::make_pair(first, last));
}
});
return all_valid_ranges;
}
return false;
} }
class MultipartFormDataParser { class MultipartFormDataParser {