restclient-cpp
C++ client for making HTTP/REST requests
helpers.h
Go to the documentation of this file.
1 
9 #ifndef INCLUDE_RESTCLIENT_CPP_HELPERS_H_
10 #define INCLUDE_RESTCLIENT_CPP_HELPERS_H_
11 
12 #include <string>
13 #include <algorithm>
14 #include <functional>
15 
16 #include "restclient-cpp/version.h"
17 
21 namespace RestClient {
22 
26 namespace Helpers {
27 
36  typedef struct {
37  const char* data;
38  size_t length;
39  } UploadObject;
40 
41  // writedata callback function
42  size_t write_callback(void *ptr, size_t size, size_t nmemb,
43  void *userdata);
44 
45  // header callback function
46  size_t header_callback(void *ptr, size_t size, size_t nmemb,
47  void *userdata);
48  // read callback function
49  size_t read_callback(void *ptr, size_t size, size_t nmemb,
50  void *userdata);
51 
52  // trim from start
53  static inline std::string &ltrim(std::string &s) { // NOLINT
54  s.erase(s.begin(), std::find_if(s.begin(), s.end(),
55  std::not1(std::ptr_fun<int, int>(std::isspace))));
56  return s;
57  }
58 
59  // trim from end
60  static inline std::string &rtrim(std::string &s) { // NOLINT
61  s.erase(std::find_if(s.rbegin(), s.rend(),
62  std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
63  return s;
64  }
65 
66  // trim from both ends
67  static inline std::string &trim(std::string &s) { // NOLINT
68  return ltrim(rtrim(s));
69  }
70 }; // namespace Helpers
71 
72 }; // namespace RestClient
73 
74 #endif // INCLUDE_RESTCLIENT_CPP_HELPERS_H_
size_t header_callback(void *ptr, size_t size, size_t nmemb, void *userdata)
header callback for libcurl
Definition: helpers.cc:41
const char * data
Definition: helpers.h:37
size_t write_callback(void *ptr, size_t size, size_t nmemb, void *userdata)
write callback function for libcurl
Definition: helpers.cc:23
This structure represents the payload to upload on POST requests.
Definition: helpers.h:36
size_t read_callback(void *ptr, size_t size, size_t nmemb, void *userdata)
read callback function for libcurl
Definition: helpers.cc:75
size_t length
Definition: helpers.h:38
namespace for all RestClient definitions
Definition: connection.h:23