From 274fcfe8d3fc5b54b345d79fab6dd4bbdb544892 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sat, 24 May 2008 16:40:06 +0000 Subject: aux::lowercase, aux::to_lowercase --- osirion.kdevelop.pcs | Bin 710341 -> 714707 bytes osirion.kdevses | 7 +++++-- src/auxiliary/functions.cc | 14 ++++++++++++++ src/auxiliary/functions.h | 6 ++++++ src/core/commandbuffer.cc | 9 +++++++-- src/core/gameserver.cc | 4 +++- src/game/game.cc | 3 ++- 7 files changed, 37 insertions(+), 6 deletions(-) diff --git a/osirion.kdevelop.pcs b/osirion.kdevelop.pcs index 0b2bd06..ca71239 100644 Binary files a/osirion.kdevelop.pcs and b/osirion.kdevelop.pcs differ diff --git a/osirion.kdevses b/osirion.kdevses index 8e8c31c..c1fb79c 100644 --- a/osirion.kdevses +++ b/osirion.kdevses @@ -1,10 +1,13 @@ - + - + + + + diff --git a/src/auxiliary/functions.cc b/src/auxiliary/functions.cc index 2b42bae..b417a4a 100644 --- a/src/auxiliary/functions.cc +++ b/src/auxiliary/functions.cc @@ -76,4 +76,18 @@ const std::string spaces(const std::string &text,size_t n) return s; } +void to_lowercase(std::string &text) +{ + for (std::string::iterator i = text.begin(); i != text.end(); ++i) + (*i) = tolower(*i); +} + +const std::string lowercase(const std::string &text) +{ + std::string t; + for (std::string::const_iterator i = text.begin(); i != text.end(); ++i) + t += tolower(*i); + return t; +} + } diff --git a/src/auxiliary/functions.h b/src/auxiliary/functions.h index cd9ed13..2202b87 100644 --- a/src/auxiliary/functions.h +++ b/src/auxiliary/functions.h @@ -36,6 +36,12 @@ size_t text_length(const std::string &text); /// prepend spaces to a string up to the desired lenght, excluding color codes const std::string spaces(const std::string &text, size_t n); + +/// convert a string to lowercase +void to_lowercase(std::string &text); + +/// return text, converted to lowercase +const std::string lowercase(const std::string &text); } #endif // __INCLUDED_AUX_FUNCTIONS_H__ diff --git a/src/core/commandbuffer.cc b/src/core/commandbuffer.cc index 40517e1..6c4dbca 100644 --- a/src/core/commandbuffer.cc +++ b/src/core/commandbuffer.cc @@ -9,6 +9,7 @@ #include #include +#include "auxiliary/functions.h" #include "sys/sys.h" #include "filesystem/filesystem.h" #include "core/application.h" @@ -57,6 +58,8 @@ void func_set(std::string const &args) if (!(argstream >> varname)) return; + aux::to_lowercase(varname); + std::string value; if (!(argstream >> value)) { return; @@ -136,7 +139,8 @@ void CommandBuffer::exec(std::string const &cmdline) if (!(cmdstream >> command)) return; - + + aux::to_lowercase(command); //con_debug << "Executing '" << cmdline << "'\n"; // is it a function @@ -207,7 +211,8 @@ void CommandBuffer::complete(std::string &input, size_t &pos) std::string partial = input.substr(0, pos); if (!partial.size()) return; - + aux::to_lowercase(partial); + // search function registry for matches std::map::iterator f; for (f = Func::registry.begin(); f != Func::registry.end(); f++) { diff --git a/src/core/gameserver.cc b/src/core/gameserver.cc index 687623e..5d973f1 100644 --- a/src/core/gameserver.cc +++ b/src/core/gameserver.cc @@ -115,6 +115,8 @@ void GameServer::abort() Player *GameServer::find_player(std::string const search) { + using aux::lowercase; + std::istringstream searchstr(search); int id = 0; if (searchstr >> id) { @@ -129,7 +131,7 @@ Player *GameServer::find_player(std::string const search) return 0; for (std::list:: iterator it = players.begin(); it != players.end(); it++) { - if ((*it)->name().find(search) != std::string::npos) + if (lowercase((*it)->name()).find(lowercase(search)) != std::string::npos) return (*it); } diff --git a/src/game/game.cc b/src/game/game.cc index 79c9040..4a77d7d 100644 --- a/src/game/game.cc +++ b/src/game/game.cc @@ -73,6 +73,7 @@ void func_buy(core::Player *player, std::string const &args) std::string helpstr; std::istringstream is(args); is >> shipname; + aux::to_lowercase(shipname); ShipModel *shipmodel = 0; for (std::list::iterator smit = ShipModel::registry.begin(); smit != ShipModel::registry.end(); smit++) { @@ -99,7 +100,7 @@ void func_buy(core::Player *player, std::string const &args) core::server()->broadcast("^B" + player->name() + " ^Bpurchased " + aux::article(shipmodel->name())); player->player_dirty = true; } else { - core::server()->send(player, "Usage: buy [" + helpstr + "^N]"); + core::server()->send(player, "Usage: buy [^B" + helpstr + "^N]"); } } -- cgit v1.2.3