Trim whitespace around, but not inside, key names in control binding.

An existing static method in the Configuration object to do this was
made public.

Lines like this in controls.conf now work correctly:

Random = R, Left Shift , joy0Button5
This commit is contained in:
Levi Pearson 2017-02-05 12:49:24 -07:00
parent 6c15ac4d5e
commit 7b654f301e
2 changed files with 2 additions and 1 deletions

View File

@ -130,6 +130,7 @@ bool UserInput::MapKey(std::string keyDescription, KeyCode_E key, bool required)
while (std::getline(ss, token, ',')) while (std::getline(ss, token, ','))
{ {
token = Configuration::trimEnds(token);
scanCode = SDL_GetScancodeFromName(token.c_str()); scanCode = SDL_GetScancodeFromName(token.c_str());
bool found = false; bool found = false;

View File

@ -26,6 +26,7 @@ public:
virtual ~Configuration(); virtual ~Configuration();
static void initialize(); static void initialize();
static std::string convertToAbsolutePath(std::string prefix, std::string path); static std::string convertToAbsolutePath(std::string prefix, std::string path);
static std::string trimEnds(std::string str);
// gets the global configuration // gets the global configuration
bool import(std::string keyPrefix, std::string file); bool import(std::string keyPrefix, std::string file);
bool import(std::string collection, std::string keyPrefix, std::string file, bool mustExist = true); bool import(std::string collection, std::string keyPrefix, std::string file, bool mustExist = true);
@ -45,7 +46,6 @@ public:
private: private:
bool getRawProperty(std::string key, std::string &value); bool getRawProperty(std::string key, std::string &value);
bool parseLine(std::string collection, std::string keyPrefix, std::string line, int lineCount); bool parseLine(std::string collection, std::string keyPrefix, std::string line, int lineCount);
std::string trimEnds(std::string str);
typedef std::map<std::string, std::string> PropertiesType; typedef std::map<std::string, std::string> PropertiesType;
typedef std::pair<std::string, std::string> PropertiesPair; typedef std::pair<std::string, std::string> PropertiesPair;