Skip to content

Commit

Permalink
Fixed cppcheck warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
COM8 committed Nov 24, 2022
1 parent 6f9ddd9 commit ea00eba
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
10 changes: 6 additions & 4 deletions include/cpr/body.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
#define CPR_BODY_H

#include <exception>
#include <fstream>
#include <initializer_list>
#include <string>
#include <vector>
#include <fstream>

#include "cpr/buffer.h"
#include "cpr/cprtypes.h"
Expand All @@ -15,18 +15,20 @@ namespace cpr {

class Body : public StringHolder<Body> {
public:
Body() : StringHolder<Body>() {}
Body() = default;
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
Body(const std::string& body) : StringHolder<Body>(body) {}
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
Body(std::string&& body) : StringHolder<Body>(std::move(body)) {}
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
Body(std::string_view body) : StringHolder<Body>(body) {}
Body(const std::string_view& body) : StringHolder<Body>(body) {}
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
Body(const char* body) : StringHolder<Body>(body) {}
Body(const char* str, size_t len) : StringHolder<Body>(str, len) {}
Body(const std::initializer_list<std::string> args) : StringHolder<Body>(args) {}
// NOLINTNEXTLINE(google-explicit-constructor, cppcoreguidelines-pro-type-reinterpret-cast)
Body(const Buffer& buffer) : StringHolder<Body>(reinterpret_cast<const char*>(buffer.data), static_cast<size_t>(buffer.datalen)) {}
// NOLINTNEXTLINE(google-explicit-constructor)
Body(const File& file) {
std::ifstream is(file.filepath, std::ifstream::binary);
if (!is) {
Expand All @@ -38,7 +40,7 @@ class Body : public StringHolder<Body> {
is.seekg(0, std::ios::beg);
std::string buffer;
buffer.resize(static_cast<size_t>(length));
is.read(&buffer[0], length);
is.read(buffer.data(), length);
str_ = std::move(buffer);
}
Body(const Body& other) = default;
Expand Down
4 changes: 2 additions & 2 deletions include/cpr/cprtypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class StringHolder {
StringHolder() = default;
explicit StringHolder(const std::string& str) : str_(str) {}
explicit StringHolder(std::string&& str) : str_(std::move(str)) {}
explicit StringHolder(std::string_view str) : str_(str) {}
explicit StringHolder(const std::string_view& str) : str_(str) {}
explicit StringHolder(const char* str) : str_(str) {}
StringHolder(const char* str, size_t len) : str_(str, len) {}
StringHolder(const std::initializer_list<std::string> args) {
Expand Down Expand Up @@ -113,7 +113,7 @@ class Url : public StringHolder<Url> {
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
Url(std::string&& url) : StringHolder<Url>(std::move(url)) {}
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
Url(std::string_view url) : StringHolder<Url>(url) {}
Url(const std::string_view& url) : StringHolder<Url>(url) {}
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
Url(const char* url) : StringHolder<Url>(url) {}
Url(const char* str, size_t len) : StringHolder<Url>(std::string(str, len)) {}
Expand Down
3 changes: 2 additions & 1 deletion include/cpr/filesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
#define CPR_FILESYSTEM_H

// Include filesystem into the namespace "fs" from either "filesystem" or "experimental/filesystem" or "boost/filesystem"
// cppcheck-suppress preprocessorErrorDirective
#if __has_include(<filesystem>)
#include <filesystem>
namespace fs = std::filesystem;
#elif __has_include("experimental/filesystem")
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
//cppcheck-suppress preprocessorErrorDirective
// cppcheck-suppress preprocessorErrorDirective
#elif defined(CPR_USE_BOOST_FILESYSTEM) && __has_include(<boost/filesystem.hpp>)
#include <boost/filesystem.hpp>
namespace fs = boost::filesystem;
Expand Down
4 changes: 2 additions & 2 deletions include/cpr/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ namespace cpr {

class Interface : public StringHolder<Interface> {
public:
Interface() : StringHolder<Interface>() {}
Interface() = default;
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
Interface(const std::string& iface) : StringHolder<Interface>(iface) {}
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
Interface(std::string&& iface) : StringHolder<Interface>(std::move(iface)) {}
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
Interface(std::string_view iface) : StringHolder<Interface>(iface) {}
Interface(const std::string_view& iface) : StringHolder<Interface>(iface) {}
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
Interface(const char* iface) : StringHolder<Interface>(iface) {}
Interface(const char* str, size_t len) : StringHolder<Interface>(str, len) {}
Expand Down
4 changes: 2 additions & 2 deletions include/cpr/user_agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
namespace cpr {
class UserAgent : public StringHolder<UserAgent> {
public:
UserAgent() : StringHolder<UserAgent>() {}
UserAgent() = default;
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
UserAgent(const std::string& useragent) : StringHolder<UserAgent>(useragent) {}
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
UserAgent(std::string&& useragent) : StringHolder<UserAgent>(std::move(useragent)) {}
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
UserAgent(std::string_view useragent) : StringHolder<UserAgent>(useragent) {}
UserAgent(const std::string_view& useragent) : StringHolder<UserAgent>(useragent) {}
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
UserAgent(const char* useragent) : StringHolder<UserAgent>(useragent) {}
UserAgent(const char* str, size_t len) : StringHolder<UserAgent>(str, len) {}
Expand Down

0 comments on commit ea00eba

Please sign in to comment.