From e62b23a2e5d55bea8fb2e01968522667a9714f8e Mon Sep 17 00:00:00 2001 From: Steven Hahn <hahnse@ornl.gov> Date: Wed, 2 Nov 2016 18:56:43 -0400 Subject: [PATCH] Use StringTokenizer to split string. --- Framework/Kernel/inc/MantidKernel/Strings.h | 2 +- Framework/Kernel/src/Strings.cpp | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Framework/Kernel/inc/MantidKernel/Strings.h b/Framework/Kernel/inc/MantidKernel/Strings.h index c25114da39e..e1f9f2d8738 100644 --- a/Framework/Kernel/inc/MantidKernel/Strings.h +++ b/Framework/Kernel/inc/MantidKernel/Strings.h @@ -144,7 +144,7 @@ template <typename T> int sectionMCNPX(std::string &A, T &out); MANTID_KERNEL_DLL void writeMCNPX(const std::string &Line, std::ostream &OX); /// Split tring into spc deliminated components -MANTID_KERNEL_DLL std::vector<std::string> StrParts(std::string Ln); +MANTID_KERNEL_DLL std::vector<std::string> StrParts(const std::string &Ln); /// Splits a string into key value pairs MANTID_KERNEL_DLL std::map<std::string, std::string> diff --git a/Framework/Kernel/src/Strings.cpp b/Framework/Kernel/src/Strings.cpp index 94977a619b5..ae7dd875e87 100644 --- a/Framework/Kernel/src/Strings.cpp +++ b/Framework/Kernel/src/Strings.cpp @@ -412,11 +412,10 @@ void writeMCNPX(const std::string &Line, std::ostream &OX) { * @return vector of components */ std::vector<std::string> StrParts(const std::string &Ln) { - std::vector<std::string> Out; - std::string Part; - while (section(Ln, Part)) - Out.push_back(Part); - return Out; + auto tokenizer = Mantid::Kernel::StringTokenizer( + Ln, " ", Mantid::Kernel::StringTokenizer::TOK_TRIM | + Mantid::Kernel::StringTokenizer::TOK_IGNORE_EMPTY); + return tokenizer.asVector(); } /** -- GitLab