8#include "MantidKernel/DllConfig.h"
18Logger logger(
"Regex");
29template <
typename T>
int StrComp(
const std::string &Text,
const boost::regex &Re, T &Aout,
const int compNum) {
30 boost::sregex_iterator m1(Text.begin(), Text.end(), Re);
31 boost::sregex_iterator empty;
33 if (m1 == empty ||
static_cast<int>((*m1).size()) < compNum)
38 return convert((*m1)[0].str(), Aout);
49template <
typename T>
int StrComp(
const char *Text,
const boost::regex &Re, T &Aout,
const int compNum) {
50 return StrComp(std::string(Text), Re, Aout, compNum);
59int StrLook(
const std::string &Text,
const boost::regex &Re) {
60 boost::sregex_iterator m1(Text.begin(), Text.end(), Re);
61 boost::sregex_iterator empty;
75std::vector<std::string>
StrParts(std::string Sdx,
const boost::regex &Re) {
76 std::vector<std::string> Aout;
77 boost::regex_split(std::back_inserter(Aout), Sdx,
94template <
typename T>
int StrFullCut(std::string &Text,
const boost::regex &Re, T &Aout,
const int compNum) {
95 boost::sregex_iterator m1(Text.begin(), Text.end(), Re);
96 boost::sregex_iterator empty;
100 if (compNum + 1 >=
static_cast<int>(m1->size()))
106 unsigned int zero = 0;
107 Text.erase(m1->position(zero), (*m1)[0].str().length());
122template <
typename T>
int StrFullCut(std::string &Text,
const boost::regex &Re, std::vector<T> &Aout) {
123 boost::sregex_iterator m1(Text.begin(), Text.end(), Re);
124 boost::sregex_iterator empty;
128 logger.information() <<
"SFC :: \n";
130 unsigned int zero = 0;
131 const size_t M0 = m1->position(zero);
133 for (; m1 != empty; m1++) {
138 Aout.emplace_back(
tmp);
140 ML = m1->position(zero) + (*m1)[0].str().length();
142 logger.information() <<
"SFC :: " << M0 <<
" " << ML <<
'\n';
161template <>
int StrFullCut(std::string &Text,
const boost::regex &Re, std::vector<std::string> &Aout) {
162 boost::sregex_iterator m1(Text.begin(), Text.end(), Re);
163 boost::sregex_iterator empty;
167 unsigned int zero = 0;
168 const auto M0 =
static_cast<int>(m1->position(zero));
170 for (; m1 != empty; m1++) {
171 ML =
static_cast<int>(m1->position(zero) + (*m1)[0].str().length());
173 Aout.emplace_back((*m1)[
index].str());
175 logger.information() <<
"SFC :: " << M0 <<
" " << ML <<
'\n';
192template <
typename T>
int StrFullSplit(
const std::string &text,
const boost::regex &Re, std::vector<T> &Aout) {
193 boost::sregex_iterator m1(text.begin(), text.end(), Re);
194 boost::sregex_iterator empty;
195 for (; m1 != empty; m1++)
199 return static_cast<int>(Aout.size());
200 Aout.emplace_back(
tmp);
202 return static_cast<int>(Aout.size());
216template <
typename T>
int StrSingleSplit(
const std::string &text,
const boost::regex &Re, std::vector<T> &Aout) {
217 boost::sregex_iterator m1(text.begin(), text.end(), Re);
218 boost::sregex_iterator empty;
223 return static_cast<int>(Aout.size());
224 Aout.emplace_back(
tmp);
227 return static_cast<int>(Aout.size());
242template <>
int StrSingleSplit(
const std::string &text,
const boost::regex &Re, std::vector<std::string> &Aout) {
243 boost::sregex_iterator m1(text.begin(), text.end(), Re);
244 boost::sregex_iterator empty;
247 Aout.emplace_back((*m1)[
index].str());
260MANTID_KERNEL_DLL
int findPattern(std::istream &fh,
const boost::regex &Re, std::string &Out) {
265 fh.getline(ss, 512,
'\n');
266 while (!fh.fail() && !boost::regex_search(ss, ans, Re, boost::match_default)) {
267 fh.getline(ss, 512,
'\n');
283template <
typename T>
int findComp(std::istream &fh,
const boost::regex &Re, T &Out) {
288 fh.getline(ss, 512,
'\n');
289 while (!fh.fail() && !boost::regex_search(ss, ans, Re, boost::match_default)) {
291 fh.getline(ss, 512,
'\n');
293 if (ans[0].matched) {
294 std::string xout(ans[1].first, ans[1].second);
308template <> MANTID_KERNEL_DLL
int findComp(std::istream &fh,
const boost::regex &Re, std::string &Out) {
313 fh.getline(ss, 512,
'\n');
314 while (!fh.fail() && !boost::regex_search(ss, ans, Re, boost::match_default)) {
316 fh.getline(ss, 512,
'\n');
318 if (ans[0].matched) {
319 Out = std::string(ans[1].first, ans[1].second);
327template MANTID_KERNEL_DLL
int StrFullCut(std::string &,
const boost::regex &, std::string &,
const int);
328template MANTID_KERNEL_DLL
int StrFullCut(std::string &,
const boost::regex &,
int &,
const int);
329template MANTID_KERNEL_DLL
int StrFullCut(std::string &,
const boost::regex &,
double &,
const int);
331template MANTID_KERNEL_DLL
int StrFullSplit(
const std::string &,
const boost::regex &, std::vector<int> &);
332template MANTID_KERNEL_DLL
int StrFullSplit(
const std::string &,
const boost::regex &, std::vector<double> &);
333template MANTID_KERNEL_DLL
int StrFullSplit(
const std::string &,
const boost::regex &, std::vector<std::string> &);
335template MANTID_KERNEL_DLL
int StrSingleSplit(
const std::string &,
const boost::regex &, std::vector<int> &);
336template MANTID_KERNEL_DLL
int StrSingleSplit(
const std::string &,
const boost::regex &, std::vector<double> &);
338template MANTID_KERNEL_DLL
int StrComp(
const char *,
const boost::regex &,
double &,
const int);
339template MANTID_KERNEL_DLL
int StrComp(
const char *,
const boost::regex &,
int &,
const int);
340template MANTID_KERNEL_DLL
int StrComp(
const std::string &,
const boost::regex &,
double &,
const int);
341template MANTID_KERNEL_DLL
int StrComp(
const std::string &,
const boost::regex &,
int &,
const int);
343template MANTID_KERNEL_DLL
int findComp(std::istream &,
const boost::regex &,
int &);
std::map< DeltaEMode::Type, std::string > index
Holds support functions for strings.
MANTID_KERNEL_DLL int findComp(std::istream &, const boost::regex &, T &)
Find a compmonent in a Regex in a file.
MANTID_KERNEL_DLL int StrComp(const char *, const boost::regex &, T &, const int=0)
Find if a pattern matches a string.
MANTID_KERNEL_DLL int findPattern(std::istream &, const boost::regex &, std::string &)
Finds a pattern in a file.
int StrSingleSplit(const std::string &, const boost::regex &, std::vector< T > &)
Split a line searched parts.
int StrFullCut(std::string &, const boost::regex &, T &, const int=-1)
Cut out the searched section and returns component.
int StrFullSplit(const std::string &, const boost::regex &, std::vector< T > &)
Split a line searched parts.
MANTID_KERNEL_DLL int StrLook(const std::string &, const boost::regex &)
Find is a pattern matches.
MANTID_KERNEL_DLL std::vector< std::string > StrParts(std::string, const boost::regex &)
Split a line into component parts.
int convert(const std::string &A, T &out)
Convert a string into a number.