Mantid
Loading...
Searching...
No Matches
StringTokenizer.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2007 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8
9//----------------------------------------------------------------------
10// Includes
11//----------------------------------------------------------------------
12
13#include <cstddef> //std::size_t
14#include <string>
15#include <vector>
16
17#include "MantidKernel/DllConfig.h"
18
24namespace Mantid {
25namespace Kernel {
26
27class MANTID_KERNEL_DLL StringTokenizer final {
28public:
30 enum Options {
31 TOK_IGNORE_EMPTY = 1,
32 TOK_TRIM = 2,
33 TOK_IGNORE_FINAL_EMPTY_TOKEN = 4
34 };
35 using TokenVec = std::vector<std::string>;
36 using Iterator = std::vector<std::string>::iterator;
37 using ConstIterator = std::vector<std::string>::const_iterator;
39 StringTokenizer() = default;
41 StringTokenizer(const std::string &str, const std::string &separators, unsigned options = 0);
42
44 ~StringTokenizer() = default;
45
49 Iterator begin() { return m_tokens.begin(); }
50
54 Iterator end() { return m_tokens.end(); }
55
59 ConstIterator begin() const { return m_tokens.cbegin(); }
64 ConstIterator end() const { return m_tokens.cend(); }
65
69 ConstIterator cbegin() const { return m_tokens.cbegin(); }
74 ConstIterator cend() const { return m_tokens.cend(); }
75
81 const std::string &operator[](std::size_t index) const { return m_tokens[index]; }
82
88 std::string &operator[](std::size_t index) { return m_tokens[index]; }
89
91 const TokenVec &asVector() { return m_tokens; }
92
98 const std::string &at(std::size_t index) const { return m_tokens.at(index); }
99
105 std::string &at(std::size_t index) { return m_tokens.at(index); }
106
110 std::size_t count() const { return m_tokens.size(); }
111
115 std::size_t size() const noexcept { return m_tokens.size(); }
116
117private:
118 std::vector<std::string> m_tokens;
119};
120} // namespace Kernel
121} // namespace Mantid
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
const std::string & at(std::size_t index) const
Get a const reference to the index'th token.
const std::string & operator[](std::size_t index) const
Get a const reference to the index'th token.
Iterator begin()
Iterator referring to first element in the container.
std::vector< std::string > TokenVec
Options
Specify tokenizer options. These can be combined using + or |.
std::vector< std::string >::const_iterator ConstIterator
std::size_t size() const noexcept
Get the total number of tokens.
std::vector< std::string > m_tokens
Iterator end()
Iterator referring to the past-the-end element in the container.
std::string & operator[](std::size_t index)
Get a const reference to the index'th token.
std::vector< std::string >::iterator Iterator
ConstIterator cend() const
Const iterator referring to the past-the-end element in the container.
std::string & at(std::size_t index)
Get a reference to the index'th token.
~StringTokenizer()=default
Destroys the tokenizer.
StringTokenizer()=default
Constructs an object from an empty string.
ConstIterator cbegin() const
Const iterator referring to first element in the container.
const TokenVec & asVector()
Returns a vector of tokenized strings.
ConstIterator begin() const
Const iterator referring to first element in the container.
ConstIterator end() const
Const iterator referring to the past-the-end element in the container.
std::size_t count() const
Get the total number of tokens.
Helper class which provides the Collimation Length for SANS instruments.