Skip to content

Commit

Permalink
Refs #10976. add extra space in certain versions of poco.
Browse files Browse the repository at this point in the history
  • Loading branch information
quantumsteve committed Feb 27, 2015
1 parent d904ff9 commit 1838b0f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
11 changes: 11 additions & 0 deletions Code/Mantid/Framework/Kernel/inc/MantidKernel/PocoVersion.h.in
Expand Up @@ -31,3 +31,14 @@
/// Patch version of Poco used to build Mantid.
#define POCO_VERSION_PATCH @POCO_VERSION_PATCH@
#endif /* MANTID_KERNEL_POCOVERSION_H_ */

std::string addSpaceIfNeeded(const std::string& str)
{
#if POCO_VERSION_MAJOR > 1
return str;
#elif POCO_VERSION_MAJOR == 1 && POCO_VERSION_MINOR >= 5
return str;
#else
return str + " ";
#endif
}
14 changes: 6 additions & 8 deletions Code/Mantid/Framework/Kernel/src/Strings.cpp
@@ -1,6 +1,7 @@
#include "MantidKernel/Strings.h"
#include "MantidKernel/Exception.h"
#include "MantidKernel/UnitLabel.h"
#include "MantidKernel/PocoVersion.h"

#include <Poco/StringTokenizer.h>
#include <Poco/Path.h>
Expand All @@ -9,6 +10,7 @@
#include <boost/lexical_cast.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/make_shared.hpp>
#include <boost/lexical_cast.hpp>

#include <cmath>
#include <fstream>
Expand Down Expand Up @@ -1040,7 +1042,7 @@ std::vector<int> parseRange(const std::string &str, const std::string &elemSep,
typedef Poco::StringTokenizer Tokenizer;

boost::shared_ptr<Tokenizer> elements;

if (elemSep.find(' ') != std::string::npos) {
// If element separator contains space character it's a special case,
// because in that case
Expand All @@ -1051,10 +1053,8 @@ std::vector<int> parseRange(const std::string &str, const std::string &elemSep,
// and we can
// spot the error. Behaviour is changed in Poco 1.5 and this will not be
// needed.
Tokenizer ranges(str + " ", rangeSep, Tokenizer::TOK_TRIM);
std::string new_str =
join(ranges.begin(), ranges.end(), rangeSep.substr(0, 1));

Tokenizer ranges(addSpaceIfNeeded(str), rangeSep, Tokenizer::TOK_TRIM);
std::string new_str = join(ranges.begin(), ranges.end(), rangeSep.substr(0, 1));
elements = boost::make_shared<Tokenizer>(
new_str, elemSep, Tokenizer::TOK_IGNORE_EMPTY | Tokenizer::TOK_TRIM);
} else {
Expand All @@ -1070,10 +1070,8 @@ std::vector<int> parseRange(const std::string &str, const std::string &elemSep,
for (Tokenizer::Iterator it = elements->begin(); it != elements->end();
it++) {
// See above for the reason space is added
Tokenizer rangeElements(*it + " ", rangeSep, Tokenizer::TOK_TRIM);

Tokenizer rangeElements(addSpaceIfNeeded(*it), rangeSep, Tokenizer::TOK_TRIM);
size_t noOfRangeElements = rangeElements.count();

// A single element
if (noOfRangeElements == 1) {
int element;
Expand Down

0 comments on commit 1838b0f

Please sign in to comment.