Skip to content

Commit

Permalink
Refs #10380 Generalise parseOptionsString → parseKeyValueString
Browse files Browse the repository at this point in the history
As a static interface it can now be unit tested appropriately.
  • Loading branch information
Harry Jeffery committed Oct 17, 2014
1 parent 4f6f946 commit 2e65601
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Expand Up @@ -41,6 +41,9 @@ namespace MantidQt
ReflMainViewPresenter(ReflMainView* view);
virtual ~ReflMainViewPresenter() = 0;
virtual void notify(int flag);

//Public for the purposes of unit testing
static std::map<std::string,std::string> parseKeyValueString(const std::string& str);
protected:
//The model and backup copy of the original model
Mantid::API::ITableWorkspace_sptr m_model;
Expand All @@ -59,8 +62,6 @@ namespace MantidQt
std::string getRunNumber(const Mantid::API::Workspace_sptr& ws);
//get an unused group id
int getUnusedGroup(std::vector<size_t> ignoredRows = std::vector<size_t>()) const;
//parse an options column string
std::map<std::string,std::string> parseOptionsString(const std::string& options) const;
//make a transmission workspace
Mantid::API::MatrixWorkspace_sptr makeTransWS(const std::string& transString);
//Validate a row
Expand Down
Expand Up @@ -60,10 +60,10 @@ namespace MantidQt
Parses a string in the format `a = 1,b=2, c = "1,2,3,4", d = 5.0, e='a,b,c'` into a map of key/value pairs
@param options The input string
*/
std::map<std::string,std::string> ReflMainViewPresenter::parseOptionsString(const std::string& options) const
std::map<std::string,std::string> ReflMainViewPresenter::parseKeyValueString(const std::string& str)
{
//Tokenise, using '\' as an escape character, ',' as a delimiter and " and ' as quote characters
boost::tokenizer<boost::escaped_list_separator<char> > tok(options, boost::escaped_list_separator<char>("\\", ",", "\"'"));
boost::tokenizer<boost::escaped_list_separator<char> > tok(str, boost::escaped_list_separator<char>("\\", ",", "\"'"));

std::map<std::string,std::string> kvp;

Expand Down Expand Up @@ -380,7 +380,7 @@ namespace MantidQt
algReflOne->setProperty("ThetaIn", theta);

//Parse and set any user-specified options
auto optionsMap = parseOptionsString(options);
auto optionsMap = parseKeyValueString(options);
for(auto kvp = optionsMap.begin(); kvp != optionsMap.end(); ++kvp)
{
try
Expand Down

0 comments on commit 2e65601

Please sign in to comment.