wordI.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include <cctype>
27 
28 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
29 
30 inline void Foam::word::stripInvalid()
31 {
32  // skip stripping unless debug is active to avoid
33  // costly operations
34  if (debug && string::stripInvalid<word>(*this))
35  {
36  std::cerr
37  << "word::stripInvalid() called for word "
38  << this->c_str() << std::endl;
39 
40  if (debug > 1)
41  {
42  std::cerr
43  << " For debug level (= " << debug
44  << ") > 1 this is considered fatal" << std::endl;
45  std::abort();
46  }
47  }
48 }
49 
50 
51 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
52 
53 inline Foam::word::word(const word& w)
54 :
55  string(w)
56 {}
57 
58 
60 :
61  string()
62 {}
63 
64 
65 inline Foam::word::word(const string& s, const bool doStripInvalid)
66 :
67  string(s)
68 {
69  if (doStripInvalid)
70  {
71  stripInvalid();
72  }
73 }
74 
75 
76 inline Foam::word::word(const std::string& s, const bool doStripInvalid)
77 :
78  string(s)
79 {
80  if (doStripInvalid)
81  {
82  stripInvalid();
83  }
84 }
85 
86 
87 inline Foam::word::word(const char* s, const bool doStripInvalid)
88 :
89  string(s)
90 {
91  if (doStripInvalid)
92  {
93  stripInvalid();
94  }
95 }
96 
97 inline Foam::word::word
98 (
99  const char* s,
100  const size_type n,
101  const bool doStripInvalid
102 )
103 :
104  string(s, n)
105 {
106  if (doStripInvalid)
107  {
108  stripInvalid();
109  }
110 }
111 
112 
113 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
114 
115 inline bool Foam::word::valid(char c)
116 {
117  return
118  (
119  !isspace(c)
120  && c != '"' // string quote
121  && c != '\'' // string quote
122  && c != '/' // path separator
123  && c != ';' // end statement
124  && c != '{' // beg subdict
125  && c != '}' // end subdict
126  );
127 }
128 
129 
130 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
131 
132 inline void Foam::word::operator=(const word& q)
133 {
134  string::operator=(q);
135 }
136 
137 
138 inline void Foam::word::operator=(const string& q)
139 {
140  string::operator=(q);
141  stripInvalid();
142 }
143 
144 
145 inline void Foam::word::operator=(const std::string& q)
146 {
147  string::operator=(q);
148  stripInvalid();
149 }
150 
151 
152 inline void Foam::word::operator=(const char* q)
153 {
154  string::operator=(q);
155  stripInvalid();
156 }
157 
158 
159 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
160 
161 inline Foam::word Foam::operator&(const word& a, const word& b)
162 {
163  if (b.size())
164  {
165  string ub = b;
166  ub.string::operator[](0) = char(toupper(ub.string::operator[](0)));
167 
168  return a + ub;
169  }
170  else
171  {
172  return a;
173  }
174 }
175 
176 
177 // ************************************************************************* //
static bool valid(char)
Is this character valid for a word.
Definition: wordI.H:115
void operator=(const word &)
Definition: wordI.H:132
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
word()
Construct null.
Definition: wordI.H:59
tmp< GeometricField< Type, fvPatchField, volMesh > > operator &(const fvMatrix< Type > &, const DimensionedField< Type, volMesh > &)
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:27
A class for handling words, derived from string.
Definition: word.H:59
static int debug
Definition: word.H:74
graph_traits< Graph >::vertices_size_type size_type
Definition: SloanRenumber.C:73
errorManip< error > abort(error &err)
Definition: errorManip.H:131
string()
Construct null.
Definition: stringI.H:30
bool isspace(char c)
Definition: char.H:53
const dimensionedScalar c
Speed of light in a vacuum.
A class for handling character strings derived from std::string.
Definition: string.H:74