From 2e6560159dab6040a7f35766119184185c6df41d Mon Sep 17 00:00:00 2001 From: Harry Jeffery Date: Fri, 17 Oct 2014 16:12:03 +0100 Subject: [PATCH] =?UTF-8?q?Refs=20#10380=20Generalise=20parseOptionsString?= =?UTF-8?q?=20=E2=86=92=20parseKeyValueString?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As a static interface it can now be unit tested appropriately. --- .../inc/MantidQtCustomInterfaces/ReflMainViewPresenter.h | 5 +++-- .../MantidQt/CustomInterfaces/src/ReflMainViewPresenter.cpp | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/ReflMainViewPresenter.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/ReflMainViewPresenter.h index 8536132a6641..d615e3bf891d 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/ReflMainViewPresenter.h +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/ReflMainViewPresenter.h @@ -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 parseKeyValueString(const std::string& str); protected: //The model and backup copy of the original model Mantid::API::ITableWorkspace_sptr m_model; @@ -59,8 +62,6 @@ namespace MantidQt std::string getRunNumber(const Mantid::API::Workspace_sptr& ws); //get an unused group id int getUnusedGroup(std::vector ignoredRows = std::vector()) const; - //parse an options column string - std::map parseOptionsString(const std::string& options) const; //make a transmission workspace Mantid::API::MatrixWorkspace_sptr makeTransWS(const std::string& transString); //Validate a row diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/ReflMainViewPresenter.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/ReflMainViewPresenter.cpp index e97527ce6a50..828280697b27 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/ReflMainViewPresenter.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/ReflMainViewPresenter.cpp @@ -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 ReflMainViewPresenter::parseOptionsString(const std::string& options) const + std::map ReflMainViewPresenter::parseKeyValueString(const std::string& str) { //Tokenise, using '\' as an escape character, ',' as a delimiter and " and ' as quote characters - boost::tokenizer > tok(options, boost::escaped_list_separator("\\", ",", "\"'")); + boost::tokenizer > tok(str, boost::escaped_list_separator("\\", ",", "\"'")); std::map kvp; @@ -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