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