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

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

Parent Directory Parent Directory | Revision Log Revision Log


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


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_

  ViewVC Help
Powered by ViewVC 1.1.20