Send proper timestamps.
[dftpd.git] / String.cpp
blobfa6bd08a885272b3672b086d112d70624d2961f1
1 #include <ctype.h>
2 #include <algorithm>
3 #include "String.hpp"
4 #include "Exceptions.hpp"
6 inline static bool IsSpace( char c )
8 return isspace( c );
11 inline static bool IsNotSpace( char c )
13 return !isspace( c );
16 inline static bool IsSlash( char c )
18 return c == '/';
21 inline static bool IsNotSlash( char c )
23 return c != '/';
26 inline static bool IsComma( char c )
28 return c == ',';
31 inline static bool IsNotComma( char c )
33 return c != ',';
36 PathVector SplitPath( const std::string& str )
38 PathVector ret;
40 typedef std::string::const_iterator Iter;
42 Iter i = str.begin(), j;
44 while( i != str.end() )
46 i = std::find_if( i, str.end(), IsNotSlash );
47 j = std::find_if( i, str.end(), IsSlash );
49 if( i != str.end() )
51 ret.push_back( std::string( i, j ) );
54 i = j;
57 return ret;
60 PortVector SplitPort( const std::string& str )
62 PortVector ret;
64 typedef std::string::const_iterator Iter;
66 Iter i = str.begin(), j;
68 while( i != str.end() )
70 i = std::find_if( i, str.end(), IsNotComma );
71 j = std::find_if( i, str.end(), IsComma );
73 if( i != str.end() )
75 ret.push_back( std::string( i, j ) );
78 i = j;
81 return ret;
84 Command Split( const std::string& str )
86 Command ret;
88 typedef std::string::const_iterator Iter;
90 Iter i = str.begin(), j;
92 while( i != str.end() )
94 i = std::find_if( i, str.end(), IsNotSpace );
95 j = std::find_if( i, str.end(), IsSpace );
97 if( i != str.end() )
99 ret.push_back( std::string( i, j ) );
102 i = j;
105 return ret;
108 Command ParseCommand( const std::string& cmd )
110 Command ret( Split( cmd ) );
112 if( cmd.size() == 0 )
114 throw SyntaxErrorException;
117 ToUpper( ret[0] );
119 return ret;
122 void ToUpper( std::string& str )
124 std::transform( str.begin(), str.end(), str.begin(), toupper );