/[H9]/trunk/tntnet/dynamic/common.h
ViewVC logotype

Contents of /trunk/tntnet/dynamic/common.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 93 - (show annotations) (download)
Thu Nov 29 07:34:54 2007 UTC (16 years, 5 months ago) by torben
File MIME type: text/plain
File size: 881 byte(s)
Finished trim


1 #ifndef _COMMON_H_
2 #define _COMMON_H_
3
4 #include <string>
5
6 inline bool iswhitespace(unsigned char ch)
7 {
8 return (ch == '\r' || ch == '\n' || ch == '\t' || ch == ' ');
9 }
10
11 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 while ( output.size()>0 && iswhitespace(output[0]))
28 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 while ( output.size()>0 && iswhitespace(output[output.size()-1]))
36 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_

  ViewVC Help
Powered by ViewVC 1.1.20