wordI.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) 2011-2017 OpenFOAM Foundation
9 Copyright (C) 2018-2021 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
29#include <iostream> // For std::cerr
30
31// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
32
33template<class PrimitiveType>
35(
36 const char* fmt,
37 const PrimitiveType& val
38)
39{
41 string_printf(output, fmt, val);
42 return output;
43}
44
45
46template<class PrimitiveType>
48(
49 const std::string& fmt,
50 const PrimitiveType& val
51)
52{
54 string_printf(output, fmt, val);
55 return output;
56}
57
58
59inline bool Foam::word::valid(char c)
60{
61 return
62 (
63 !isspace(c)
64 && c != '"' // string quote
65 && c != '\'' // string quote
66 && c != '/' // path separator
67 && c != ';' // end statement
68 && c != '{' // beg block (eg, subdict)
69 && c != '}' // end block (eg, subdict)
70 );
71}
72
73
74// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
75
76inline Foam::word::word(const string& s, bool doStrip)
77:
78 string(s)
79{
80 if (doStrip)
81 {
83 }
84}
85
86
87inline Foam::word::word(string&& s, bool doStrip)
88:
89 string(std::move(s))
90{
91 if (doStrip)
92 {
94 }
95}
96
97
98inline Foam::word::word(std::string&& s, bool doStrip)
99:
100 string(std::move(s))
101{
102 if (doStrip)
103 {
104 stripInvalid();
105 }
106}
107
108
109inline Foam::word::word(const std::string& s, bool doStrip)
110:
111 string(s)
112{
113 if (doStrip)
114 {
115 stripInvalid();
116 }
117}
118
119
120inline Foam::word::word(const char* s, bool doStrip)
121:
122 string(s)
123{
124 if (doStrip)
125 {
126 stripInvalid();
127 }
128}
129
130
131inline Foam::word::word(const char* s, size_type len, bool doStrip)
132:
133 string(s, len)
134{
135 if (doStrip)
136 {
137 stripInvalid();
138 }
139}
140
141
142// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
143
145{
146 // Only strip when debug is active (potentially costly operation)
147 if (debug && string::stripInvalid<word>(*this))
148 {
149 std::cerr
150 << "word::stripInvalid() called for word "
151 << this->c_str() << std::endl;
152
153 if (debug > 1)
154 {
155 std::cerr
156 << " For debug level (= " << debug
157 << ") > 1 this is considered fatal" << std::endl;
158 std::exit(1);
159 }
160 }
161}
162
163
164// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
165
167{
168 // Self-assignment is a no-op
169 if (this != &s)
170 {
171 assign(s);
172 }
173 return *this;
174}
175
176
178{
179 // Self-assignment is a no-op
180 if (this != &s)
181 {
182 assign(std::move(s));
183 }
184 return *this;
185}
186
187
188inline Foam::word& Foam::word::operator=(const string& s)
189{
190 assign(s);
191 stripInvalid();
192 return *this;
193}
194
195
197{
198 assign(std::move(s));
199 stripInvalid();
200 return *this;
201}
202
203
204inline Foam::word& Foam::word::operator=(const std::string& s)
205{
206 assign(s);
207 stripInvalid();
208 return *this;
209}
210
211
212inline Foam::word& Foam::word::operator=(std::string&& s)
213{
214 assign(std::move(s));
215 stripInvalid();
216 return *this;
217}
218
219
221{
222 assign(s);
223 stripInvalid();
224 return *this;
225}
226
227
228// ************************************************************************* //
graph_traits< Graph >::vertices_size_type size_type
Definition: SloanRenumber.C:75
bool valid() const
True if all internal ids are non-negative.
A class for handling character strings derived from std::string.
Definition: string.H:79
static std::string::size_type string_printf(std::string &output, const char *fmt, const PrimitiveType &val)
A printf-style formatter for a primitive.
A class for handling words, derived from Foam::string.
Definition: word.H:68
static word printf(const char *fmt, const PrimitiveType &val)
Use a printf-style formatter for a primitive.
word()=default
Default construct.
word & operator=(const word &s)
Copy assignment, no character validation required.
Definition: wordI.H:166
void stripInvalid()
Strip invalid characters from this word.
Definition: wordI.H:144
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
bool isspace(char c) noexcept
Test for whitespace (C-locale)
Definition: char.H:65
static Ostream & output(Ostream &os, const IntRange< T > &range)
Definition: IntRanges.C:66