SubStrings.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2017 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::SubStrings
28 
29 Description
30  Sub-ranges of a string with a structure similar to std::match_results,
31  but without the underlying regular expression matching.
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef SubStrings_H
36 #define SubStrings_H
37 
38 #include <string>
39 #include <regex>
40 #include <vector>
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 namespace Foam
45 {
46 
47 /*---------------------------------------------------------------------------*\
48  Class SubStrings Declaration
49 \*---------------------------------------------------------------------------*/
50 
51 template<class String>
52 class SubStrings
53 :
54  public std::vector<std::sub_match<typename String::const_iterator>>
55 {
56 public:
57 
58  // Typedefs
59 
60  //- The element type
61  using value_type =
62  typename std::sub_match<typename String::const_iterator>;
63 
64  //- The const_iterator for the underlying string type
65  using string_iterator = typename String::const_iterator;
66 
67 
68  // Constructors
69 
70  //- Construct null
71  SubStrings() = default;
72 
73 
74  // Member Functions
75 
76  //- The total length of all sub-elements.
77  // Use size() for the number elements.
79  {
80  std::string::size_type len = 0;
81 
82  for (const auto& elem : *this)
83  {
84  len += elem.length();
85  }
86 
87  return len;
88  }
89 
90 
91  //- Append sub-string defined by begin/end iterators
93  {
95  range.first = b;
96  range.second = e;
97  range.matched = true;
98 
99  this->push_back(range);
100  }
101 
102 
103  //- Const reference to the first element,
104  // for consistency with other OpenFOAM containers
105  auto first() const -> decltype(this->front())
106  {
107  return this->front();
108  }
109 
110 
111  //- Const reference to the last element,
112  // for consistency with other OpenFOAM containers
113  auto last() const -> decltype(this->back())
114  {
115  return this->back();
116  }
117 
118 
119  //- Get element pos, converted to a string type.
120  String str(size_t pos) const
121  {
122  return (*this)[pos].str();
123  }
124 
125 };
126 
127 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
128 
129 } // End namespace Foam
130 
131 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
132 
133 #endif
134 
135 // ************************************************************************* //
Foam::SubStrings::str
String str(size_t pos) const
Get element pos, converted to a string type.
Definition: SubStrings.H:119
Foam::SubStrings::length
std::string::size_type length() const
The total length of all sub-elements.
Definition: SubStrings.H:77
Foam::SubStrings::value_type
typename std::sub_match< typename String::const_iterator > value_type
The element type.
Definition: SubStrings.H:61
Foam::SubStrings::last
auto last() const -> decltype(this->back())
Const reference to the last element,.
Definition: SubStrings.H:112
Foam::constant::physicoChemical::b
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:27
Foam::SubStrings::append
void append(string_iterator b, string_iterator e)
Append sub-string defined by begin/end iterators.
Definition: SubStrings.H:91
Foam::SubStrings::SubStrings
SubStrings()=default
Construct null.
size_type
graph_traits< Graph >::vertices_size_type size_type
Definition: SloanRenumber.C:75
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::vector
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:51
range
scalar range
Definition: LISASMDCalcMethod1.H:12
Foam::SubStrings::first
auto first() const -> decltype(this->front())
Const reference to the first element,.
Definition: SubStrings.H:104
Foam::constant::electromagnetic::e
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
Foam::SubStrings::string_iterator
typename String::const_iterator string_iterator
The const_iterator for the underlying string type.
Definition: SubStrings.H:64
Foam::pos
dimensionedScalar pos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:177