Commit a8f6aa06 authored by yannick legoc's avatar yannick legoc

Modified Database::getServantID by removing the whitespaces of the servant names

parent c285d5e1
......@@ -42,4 +42,12 @@ std::string StringUtilities::replaceText(const std::string& inputString, const s
return result;
}
std::string StringUtilities::stripWhitespaces(const std::string& inputString) {
string result(inputString);
result.erase(remove_if(result.begin(), result.end(), [](char c){ return (c == ' '); }), result.end());
return result;
}
}
......@@ -66,6 +66,11 @@ public:
*/
static std::string replaceText(const std::string& inputString, const std::string& previousWord, const std::string& replacementWord);
/**
* Strips the whitespaces of inputString.
*/
static std::string stripWhitespaces(const std::string& inputString);
};
inline std::list<std::string> StringUtilities::split(const std::string& input, const std::string& separator) {
......
......@@ -40,6 +40,7 @@
#include <common/base/Compare.h>
#include <common/base/PropertyType.h>
#include <common/base/Real.h>
#include <common/base/StringUtilities.h>
#include <common/output/OutputStream.h>
#include <boost/lexical_cast.hpp>
#include <fstream>
......@@ -2136,13 +2137,21 @@ std::string Database::getServantName(unsigned long servantID) {
unsigned long Database::getServantID(const std::string& servantName) {
// We search for the compact servant name: without any whitespace.
// The string servantName can already be compact if it comes from an expression (no whitespace allowed).
string compactServantName = common::StringUtilities::stripWhitespaces(servantName);
// Search among the controllers.
vector<unsigned long> controllerIDs = _IDControllerMap.getKeySet();
for (vector<unsigned long>::const_iterator c = controllerIDs.begin(); c != controllerIDs.end(); c++) {
ScopedLock lock(_lockManager->lockServantForReading(*c, eol));
try {
if (_IDControllerMap.get(*c)->getName() == servantName) {
// Compact the controller name.
string controllerName = common::StringUtilities::stripWhitespaces(_IDControllerMap.get(*c)->getName());
if (controllerName == compactServantName) {
return *c;
}
......@@ -2150,13 +2159,17 @@ unsigned long Database::getServantID(const std::string& servantName) {
}
}
// Search among the drivers.
vector<unsigned long> driverIDs = _IDDriverMap.getKeySet();
for (vector<unsigned long>::const_iterator d = driverIDs.begin(); d != driverIDs.end(); d++) {
ScopedLock lock(_lockManager->lockServantForReading(*d, eol));
try {
if (_IDDriverMap.get(*d)->getName() == servantName) {
// Compact the driver name.
string driverName = common::StringUtilities::stripWhitespaces(_IDDriverMap.get(*d)->getName());
if (driverName == compactServantName) {
return *d;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment