Skip to content

Commit

Permalink
Linter fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mmd-osm committed Jul 6, 2024
1 parent 95a6e9f commit c83b1a1
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 22 deletions.
2 changes: 1 addition & 1 deletion include/cgimap/handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*/
class responder {
public:
responder(mime::type);
explicit responder(mime::type);
virtual ~responder() = default;
virtual void write(output_formatter& f,
const std::string &generator,
Expand Down
3 changes: 2 additions & 1 deletion include/cgimap/mime_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#define MIME_TYPES_HPP

#include <string>
#include <string_view>

/**
* simple set of supported mime types.
Expand All @@ -27,7 +28,7 @@ enum class type {
};

std::string to_string(type);
type parse_from(const std::string &);
type parse_from(std::string_view);
}

#endif /* MIME_TYPES_HPP */
8 changes: 3 additions & 5 deletions src/mime_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@
#include "cgimap/mime_types.hpp"
#include <stdexcept>

using std::string;
using std::runtime_error;

namespace mime {
string to_string(type t) {
std::string to_string(type t) {
if (mime::type::any_type == t) {
return "*/*";
} else if (mime::type::text_plain == t) {
Expand All @@ -26,11 +24,11 @@ string to_string(type t) {
return "application/json";
#endif
} else {
throw runtime_error("No string conversion for unspecified MIME type.");
throw std::runtime_error("No string conversion for unspecified MIME type.");
}
}

type parse_from(const std::string &name) {
type parse_from(std::string_view name) {

if (name == "*") {
return mime::type::any_type;
Expand Down
16 changes: 8 additions & 8 deletions src/request_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ string fcgi_get_env(const request &req, const char *name, const char *default_va

// since the map script is so simple i'm just going to assume that
// any time we fail to get an environment variable is a fatal error.
if (v == NULL) {
if (v == nullptr) {
if (default_value) {
v = default_value;
} else {
Expand All @@ -37,22 +37,22 @@ string fcgi_get_env(const request &req, const char *name, const char *default_va

string get_query_string(const request &req) {
// try the query string that's supposed to be present first
const char *query_string = req.get_param("QUERY_STRING");
auto *query_string = req.get_param("QUERY_STRING");

// if that isn't present, then this may be being invoked as part of a
// 404 handler, so look at the request uri instead.
if (query_string == NULL || strlen(query_string) == 0) {
if (query_string == nullptr || strlen(query_string) == 0) {
const char *request_uri = req.get_param("REQUEST_URI");

if ((request_uri == NULL) || (strlen(request_uri) == 0)) {
if ((request_uri == nullptr) || (strlen(request_uri) == 0)) {
// fail. something has obviously gone massively wrong.
throw http::server_error("request didn't set the $QUERY_STRING or $REQUEST_URI environment variables.");
}

const char *request_uri_end = request_uri + strlen(request_uri);
// i think the only valid position for the '?' char is at the beginning
// of the query string.
const char *question_mark = std::find(request_uri, request_uri_end, '?');
auto *question_mark = std::find(request_uri, request_uri_end, '?');
if (question_mark == request_uri_end) {
return string();
} else {
Expand All @@ -67,20 +67,20 @@ string get_query_string(const request &req) {
std::string get_request_path(const request &req) {
const char *request_uri = req.get_param("REQUEST_URI");

if ((request_uri == NULL) || (strlen(request_uri) == 0)) {
if ((request_uri == nullptr) || (strlen(request_uri) == 0)) {
// fall back to PATH_INFO if REQUEST_URI isn't available.
// the former is set by fcgi, the latter by Rack.
request_uri = req.get_param("PATH_INFO");
}

if ((request_uri == NULL) || (strlen(request_uri) == 0)) {
if ((request_uri == nullptr) || (strlen(request_uri) == 0)) {
throw http::server_error("request didn't set the $QUERY_STRING or $REQUEST_URI environment variables.");
}

const char *request_uri_end = request_uri + strlen(request_uri);
// i think the only valid position for the '?' char is at the beginning
// of the query string.
const char *question_mark = std::find(request_uri, request_uri_end, '?');
auto *question_mark = std::find(request_uri, request_uri_end, '?');
if (question_mark == request_uri_end) {
return string(request_uri);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/router.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ std::pair<match_osm_id::match_type, bool> match_osm_id::match(part_iterator &beg
auto& bit = *begin;

if (bit.end() != std::find_if(bit.begin(), bit.end(),
[](unsigned char c)->bool { return !isdigit(c); })) {
[](unsigned char c) { return !isdigit(c); })) {
return {match_type(), true};
}

Expand Down
12 changes: 6 additions & 6 deletions src/routes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,19 +304,19 @@ std::vector<std::string_view> split(std::string_view str, char delim)
{
if (*it == delim)
{
result.emplace_back(&*left, it - left);
result.emplace_back(left, it - left);
left = it + 1;
if (left == str.end())
result.emplace_back(&*it, 0);
result.emplace_back(it, 0);
}
}
if (left != str.end())
result.emplace_back(&*left, str.end() - left);
result.emplace_back(left, str.end() - left);
return result;
}

handler_ptr_t route_resource(request &req, const std::string &path,
const std::unique_ptr<router> &r) {
router* r) {

// strip off the format-spec, if there is one
auto [resource, mime_type] = resource_mime_type(path);
Expand Down Expand Up @@ -344,13 +344,13 @@ handler_ptr_t routes::operator()(request &req) const {
handler_ptr_t hptr;
// check the prefix
if (path.compare(0, common_prefix.size(), common_prefix) == 0) {
hptr = route_resource(req, std::string(path, common_prefix.size()), r);
hptr = route_resource(req, std::string(path, common_prefix.size()), r.get());

#ifdef ENABLE_API07
} else if (path.compare(0, experimental_prefix.size(), experimental_prefix) ==
0) {
hptr = route_resource(req, std::string(path, experimental_prefix.size()),
r_experimental);
r_experimental.get());
#endif /* ENABLE_API07 */
}

Expand Down

0 comments on commit c83b1a1

Please sign in to comment.