forked from xaxaxa/workspace
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstringutils.H
More file actions
136 lines (126 loc) · 4.95 KB
/
stringutils.H
File metadata and controls
136 lines (126 loc) · 4.95 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
* */
/*
* stringutils.H
*
* Created on: Apr 9, 2013
* Author: xaxaxa
*/
#ifndef URLPARSER_H_
#define URLPARSER_H_
#include <cpoll/cpoll.H>
#include <string>
namespace cppsp
{
typedef CP::String String;
#ifndef __CPPSP_TOLOWER
#define __CPPSP_TOLOWER
static inline char tolower(char c) {
if (c <= 'Z' && c >= 'A') c = c - 'A' + 'a';
return c;
}
#endif
int urlDecode(const char* in, int inLen, CP::StreamWriter& sw);
static inline int urlDecode(CP::String in, CP::StreamWriter& sw) {
return urlDecode(in.data(), in.length(), sw);
}
CP::String urlDecode(const char* in, int inLen, CP::StringPool& sp);
int urlEncode(const char* in, int inLen, CP::StreamWriter& sw);
static inline int urlEncode(CP::String in, CP::StreamWriter& sw) {
urlEncode(in.data(), in.length(), sw);
}
std::string urlDecode(const char* in, int inLen);
std::string urlEncode(const char* in, int inLen);
static inline std::string urlDecode(const char* in) {
return urlDecode(in, strlen(in));
}
static inline std::string urlEncode(const char* in) {
return urlEncode(in, strlen(in));
}
static inline std::string urlDecode(std::string in) {
return urlDecode(in.data(), in.length());
}
static inline std::string urlEncode(std::string in) {
return urlEncode(in.data(), in.length());
}
typedef Delegate<void(const char* name, int nameLen, const char* value, int valueLen)> queryStringCallback;
void parseQueryString(const char* in, int inLen, queryStringCallback cb, bool decode = true);
void htmlEscape(const char* in, int inLen, CP::StreamWriter& sw);
static inline void htmlEscape(CP::String in, CP::StreamWriter& sw) {
htmlEscape(in.data(), in.length(), sw);
}
std::string htmlEscape(const char* in, int inLen);
static inline std::string htmlEscape(const char* in) {
return htmlEscape(in, strlen(in));
}
static inline std::string htmlEscape(std::string in) {
return htmlEscape(in.data(), in.length());
}
void htmlAttributeEscape(const char* in, int inLen, CP::StreamWriter& sw);
static inline void htmlAttributeEscape(CP::String in, CP::StreamWriter& sw) {
htmlAttributeEscape(in.data(), in.length(), sw);
}
std::string htmlAttributeEscape(const char* in, int inLen);
static inline std::string htmlAttributeEscape(const char* in) {
return htmlAttributeEscape(in, strlen(in));
}
static inline std::string htmlAttributeEscape(std::string in) {
return htmlAttributeEscape(in.data(), in.length());
}
int ci_compare(CP::String s1, CP::String s2);
struct ci_less: std::binary_function<CP::String, CP::String, bool>
{
bool operator()(const CP::String & s1, const CP::String & s2) const {
return ci_compare(s1, s2) < 0;
}
};
/**
Combine two paths. Result is stored in buf. Does not write a null byte.
The memory block pointed to by buf must be at least l1 + l2 bytes.
@return the length of the string written to buf
*/
int combinePath(const char* p1, int l1, const char* p2, int l2, char* buf);
/**
Combine two paths. Result is stored in buf. Does not write a null byte.
The memory block pointed to by buf must be at least strlen(p1) + strlen(p2) bytes.
@return the length of the string written to buf
*/
int combinePath(const char* p1, const char* p2, char* buf);
/**
Combine two paths securely. The resulting path is guaranteed to be under p1. (The user can not use ".." to leave the root directory)
The memory block pointed to by buf must be at least l1 + l2 bytes.
@return the length of the string written to buf
*/
int combinePathChroot(const char* p1, int l1, const char* p2, int l2, char* buf);
/**
Combine two paths securely. The resulting path is guaranteed to be under p1. (The user can not use ".." to leave the root directory)
The memory block pointed to by buf must be at least strlen(p1) + strlen(p2) bytes.
@return the length of the string written to buf
*/
int combinePathChroot(const char* p1, const char* p2, char* buf);
/**
Combine two paths. Result is allocated from sp.
@return the resulting path
*/
String combinePath(String p1, String p2, CP::StringPool& sp);
/**
Combine two paths securely. The resulting path is guaranteed to be under p1. (The user can not use ".." to leave the root directory)
@return the resulting path
*/
String combinePathChroot(String p1, String p2, CP::StringPool& sp);
/**
c should be of at least 32 chars
*/
int rfctime(const tm& time, char* c);
}
#endif /* URLPARSER_H_ */