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-2019 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 != '$' // variable indicator
124  && c != ';' // end statement
125  && c != '{' // beg subdict
126  && c != '}' // end subdict
127  );
128 }
129 
130 
132 {
133  word w(*this);
134  w[0] = toupper(w[0]);
135  return w;
136 }
137 
138 
139 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
140 
141 inline void Foam::word::operator=(const word& q)
142 {
144 }
145 
146 
147 inline void Foam::word::operator=(const string& q)
148 {
150  stripInvalid();
151 }
152 
153 
154 inline void Foam::word::operator=(const std::string& q)
155 {
157  stripInvalid();
158 }
159 
160 
161 inline void Foam::word::operator=(const char* q)
162 {
164  stripInvalid();
165 }
166 
167 
168 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
169 
170 inline Foam::word Foam::operator&(const word& a, const word& b)
171 {
172  if (b.size())
173  {
174  string ub = b;
175  ub.string::operator[](0) = char(toupper(ub.string::operator[](0)));
176 
177  return a + ub;
178  }
179  else
180  {
181  return a;
182  }
183 }
184 
185 
186 // ************************************************************************* //
static bool valid(char)
Is this character valid for a word.
Definition: wordI.H:115
void operator=(const word &)
Definition: wordI.H:141
const dimensionedScalar b
Wien displacement law constant: default SI units: [m K].
Definition: createFields.H:27
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
const dimensionedScalar c
Speed of light in a vacuum.
word()
Construct null.
Definition: wordI.H:59
tmp< GeometricField< Type, fvPatchField, volMesh > > operator &(const fvMatrix< Type > &, const DimensionedField< Type, volMesh > &)
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
void operator=(const string &)
Definition: stringI.H:229
A class for handling character strings derived from std::string.
Definition: string.H:76
word capitalise() const
Return the word with the first letter capitalised.
Definition: wordI.H:131