|
From: Lasse Kärkkäi. <tr...@us...> - 2011-01-26 23:03:10
|
Module: performous
Branch: opengl2
Commit: 87b23cdd5bca9ee2fd9feca033f35f28b1a9ecdf
Author: Lasse Karkkainen <tro...@tr...>
Date: Wed Jan 26 23:43:52 2011 +0100
Do not parse forced instruments with regex
---
game/joystick.cc | 29 +++++++++++------------------
1 files changed, 11 insertions(+), 18 deletions(-)
diff --git a/game/joystick.cc b/game/joystick.cc
index af75206..663c12c 100644
--- a/game/joystick.cc
+++ b/game/joystick.cc
@@ -334,32 +334,25 @@ void input::SDL::init() {
readControllers(g_instruments, getConfigDir() / "controllers.xml");
std::map<unsigned int, input::Instrument> forced_type;
- std::string regexp_match_force("^([0-9]+):(\\(");
- for(input::Instruments::iterator it = g_instruments.begin() ; it != g_instruments.end() ; ++it) {
- if(it == g_instruments.begin())
- regexp_match_force += it->first;
- else
- regexp_match_force += "|" + it->first;
- }
- regexp_match_force += "\\))$";
- boost::regex match_force(regexp_match_force);
- boost::match_results<const char*> what;
-
ConfigItem::StringList const& instruments = config["game/instruments"].sl();
for (ConfigItem::StringList::const_iterator it = instruments.begin(); it != instruments.end(); ++it) {
- if (!regex_search(it->c_str(), what, match_force)) {
- std::clog << "controllers/error: " << *it << "\" is not a valid instrument forced value" << std::endl;
+ std::istringstream iss(*it);
+ unsigned sdl_id;
+ char ch;
+ std::string type;
+ if (!(iss >> sdl_id >> ch >> type) || ch != ':') {
+ std::clog << "controllers/error: \"" << *it << "\" invalid syntax, should be SDL_ID:CONTROLLER_TYPE" << std::endl;
continue;
} else {
- unsigned int sdl_id = boost::lexical_cast<unsigned int>(what[1]);
- std::string instrument_type(what[2]);
-
- for(input::Instruments::const_iterator it2 = g_instruments.begin() ; it2 != g_instruments.end() ; ++it2) {
- if(instrument_type == it2->first) {
+ bool found = false;
+ for (input::Instruments::const_iterator it2 = g_instruments.begin(); it2 != g_instruments.end(); ++it2) {
+ if (type == it2->first) {
forced_type.insert(std::pair<unsigned int,input::Instrument>(sdl_id, input::Instrument(it2->second)));
+ found = true;
break;
}
}
+ if (!found) std::clog << "controllers/error: Controller type \"" << type << "\" unknown" << std::endl;
}
}
|