From bb49f0e021fb1fbefad44d944233fb1cf72c495c Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Wed, 1 Feb 2012 09:12:54 +0000 Subject: Introducing StringUtils - the place to be if you are a generic string routine :) No more sprintf()! git-svn-id: http://mc-server.googlecode.com/svn/trunk@209 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cServer.cpp | 56 +++++++++++++++++------------------------------------- 1 file changed, 17 insertions(+), 39 deletions(-) (limited to 'source/cServer.cpp') diff --git a/source/cServer.cpp b/source/cServer.cpp index f13fc50dd..826de3bb3 100644 --- a/source/cServer.cpp +++ b/source/cServer.cpp @@ -347,6 +347,10 @@ void ServerTickThread( void * a_Param ) LOG("TICK THREAD STOPPED"); } + + + + void cServer::StartListenThread() { m_pState->pListenThread = new cThread( ServerListenThread, this, "cServer::ServerListenThread" ); @@ -355,50 +359,24 @@ void cServer::StartListenThread() m_pState->pTickThread->Start( true ); } -std::vector< std::string > StringSplit(std::string str, std::string delim) -{ - std::vector< std::string > results; - size_t cutAt; - while( (cutAt = str.find_first_of(delim)) != str.npos ) - { - if(cutAt > 0) - { - results.push_back(str.substr(0,cutAt)); - } - str = str.substr(cutAt+1); - } - if(str.length() > 0) - { - results.push_back(str); - } - return results; -} + + + template -bool from_string(T& t, - const std::string& s, - std::ios_base& (*f)(std::ios_base&)) +bool from_string( + T& t, + const std::string& s, + std::ios_base& (*f)(std::ios_base&) +) { std::istringstream iss(s); return !(iss >> f >> t).fail(); } -std::string & StrToUpper(std::string& s) -{ - std::string::iterator i = s.begin(); - std::string::iterator end = s.end(); - while (i != end) { - *i = (char)toupper(*i); - ++i; - } - return s; -} -int NoCaseCompare( std::string s1, std::string s2 ) -{ - return StrToUpper( s1 ).compare( StrToUpper( s2 ) ); -} + bool cServer::Command( cClientHandle & a_Client, const char* a_Cmd ) { @@ -410,11 +388,11 @@ bool cServer::Command( cClientHandle & a_Client, const char* a_Cmd ) if( Command.length() <= 0 ) return false; if( Command[0] != '/' ) return false; - std::vector< std::string > split = StringSplit( Command, " " ); + AStringVector split = StringSplit( Command, " " ); if( split.size() == 0 ) return false; - if( split[0].compare("/coords") == 0 ) + if (split[0].compare("/coords") == 0) { char c_Str[128]; sprintf_s( c_Str, 128, "[X:%0.2f] [Y:%0.2f] [Z:%0.2f]", a_Client.GetPlayer()->GetPosX(), a_Client.GetPlayer()->GetPosY(), a_Client.GetPlayer()->GetPosZ() ); @@ -426,8 +404,8 @@ bool cServer::Command( cClientHandle & a_Client, const char* a_Cmd ) void cServer::ServerCommand( const char* a_Cmd ) { - std::string Command( a_Cmd ); - std::vector< std::string > split = StringSplit( Command, " " ); + AString Command( a_Cmd ); + AStringVector split = StringSplit( Command, " " ); if( split.size() > 0 ) { if( split[0].compare( "help" ) == 0 ) -- cgit v1.2.3