forked from mrtazz/restclient-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.h
More file actions
75 lines (62 loc) · 1.92 KB
/
helpers.h
File metadata and controls
75 lines (62 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
* @file helpers.h
* @brief header file for restclient-cpp helpers
* @author Daniel Schauenberg <[email protected]>
* @version
* @date 2010-10-11
*/
#ifndef INCLUDE_RESTCLIENT_CPP_HELPERS_H_
#define INCLUDE_RESTCLIENT_CPP_HELPERS_H_
#include <string>
#include <cctype>
#include <algorithm>
#include <functional>
#include "restclient-cpp/version.h"
/**
* @brief namespace for all RestClient definitions
*/
namespace RestClient {
/**
* @brief: namespace for all helper functions
*/
namespace Helpers {
/** @struct UploadObject
* @brief This structure represents the payload to upload on POST
* requests
* @var UploadObject::data
* Member 'data' contains the data to upload
* @var UploadObject::length
* Member 'length' contains the length of the data to upload
*/
typedef struct {
const char* data;
size_t length;
} UploadObject;
// writedata callback function
size_t write_callback(void *ptr, size_t size, size_t nmemb,
void *userdata);
// header callback function
size_t header_callback(void *ptr, size_t size, size_t nmemb,
void *userdata);
// read callback function
size_t read_callback(void *ptr, size_t size, size_t nmemb,
void *userdata);
// trim from start
static inline std::string <rim(std::string &s) { // NOLINT
s.erase(s.begin(), std::find_if(s.begin(), s.end(),
[](int c) {return !std::isspace(c);}));
return s;
}
// trim from end
static inline std::string &rtrim(std::string &s) { // NOLINT
s.erase(std::find_if(s.rbegin(), s.rend(),
[](int c) {return !std::isspace(c);}).base(), s.end());
return s;
}
// trim from both ends
static inline std::string &trim(std::string &s) { // NOLINT
return ltrim(rtrim(s));
}
}; // namespace Helpers
}; // namespace RestClient
#endif // INCLUDE_RESTCLIENT_CPP_HELPERS_H_