Store username in Session.
[dftpd.git] / String.cpp
blob98f40f96ad9b143f9fe86224e7a2d7314ef61759
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 std::vector<std::string> Split( const std::string& str )
18 std::vector<std::string> ret;
20 typedef std::string::const_iterator Iter;
22 Iter i = str.begin(), j;
24 while( i != str.end() )
26 i = std::find_if( i, str.end(), IsNotSpace );
27 j = std::find_if( i, str.end(), IsSpace );
29 if( i != str.end() )
31 ret.push_back( std::string( i, j ) );
34 i = j;
37 return ret;
40 std::vector<std::string> ParseCommand( const std::string& cmd )
42 std::vector<std::string> ret( Split( cmd ) );
44 if( cmd.size() == 0 )
46 throw SyntaxErrorException;
49 ToUpper( ret[0] );
51 return ret;
54 void ToUpper( std::string& str )
56 std::transform( str.begin(), str.end(), str.begin(), toupper );