1 |
torben |
71 |
#ifndef _COMMON_H_ |
2 |
|
|
#define _COMMON_H_ |
3 |
|
|
|
4 |
|
|
#include <string> |
5 |
|
|
|
6 |
torben |
93 |
inline bool iswhitespace(unsigned char ch) |
7 |
|
|
{ |
8 |
|
|
return (ch == '\r' || ch == '\n' || ch == '\t' || ch == ' '); |
9 |
|
|
} |
10 |
|
|
|
11 |
torben |
71 |
inline std::string nl2br(const std::string& input) |
12 |
|
|
{ |
13 |
|
|
std::string output = input; |
14 |
|
|
|
15 |
|
|
std::string::size_type pos; |
16 |
|
|
while( (pos=output.find( '\n')) != std::string::npos) |
17 |
|
|
{ |
18 |
|
|
output.replace(pos,1, "<br>"); |
19 |
|
|
} |
20 |
|
|
|
21 |
|
|
return output; |
22 |
|
|
} |
23 |
|
|
|
24 |
|
|
inline std::string ltrim(const std::string& input) |
25 |
|
|
{ |
26 |
|
|
std::string output = input; |
27 |
torben |
93 |
while ( output.size()>0 && iswhitespace(output[0])) |
28 |
torben |
71 |
output.erase(0,1); |
29 |
|
|
return output; |
30 |
|
|
} |
31 |
|
|
|
32 |
|
|
inline std::string rtrim(const std::string& input) |
33 |
|
|
{ |
34 |
|
|
std::string output = input; |
35 |
torben |
93 |
while ( output.size()>0 && iswhitespace(output[output.size()-1])) |
36 |
torben |
71 |
output.erase(output.size()-1,1); |
37 |
|
|
return output; |
38 |
|
|
} |
39 |
|
|
|
40 |
|
|
inline std::string trim(const std::string& input) |
41 |
|
|
{ |
42 |
|
|
return ltrim(rtrim(input)); |
43 |
|
|
} |
44 |
|
|
|
45 |
|
|
|
46 |
|
|
#endif // _COMMON_H_ |