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 | Copyright (C) 2011 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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
29 
30 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
31 
32 inline void Foam::word::stripInvalid()
33 {
34  // skip stripping unless debug is active to avoid
35  // costly operations
36  if (debug && string::stripInvalid<word>(*this))
37  {
38  std::cerr
39  << "word::stripInvalid() called for word "
40  << this->c_str() << std::endl;
41 
42  if (debug > 1)
43  {
44  std::cerr
45  << " For debug level (= " << debug
46  << ") > 1 this is considered fatal" << std::endl;
47  std::abort();
48  }
49  }
50 }
51 
52 
53 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
54 
55 inline Foam::word::word(const word& w)
56 :
57  string(w)
58 {}
59 
60 
62 :
63  string()
64 {}
65 
66 
67 inline Foam::word::word(const string& s, const bool doStripInvalid)
68 :
69  string(s)
70 {
71  if (doStripInvalid)
72  {
73  stripInvalid();
74  }
75 }
76 
77 
78 inline Foam::word::word(const std::string& s, const bool doStripInvalid)
79 :
80  string(s)
81 {
82  if (doStripInvalid)
83  {
84  stripInvalid();
85  }
86 }
87 
88 
89 inline Foam::word::word(const char* s, const bool doStripInvalid)
90 :
91  string(s)
92 {
93  if (doStripInvalid)
94  {
95  stripInvalid();
96  }
97 }
98 
99 inline Foam::word::word
100 (
101  const char* s,
102  const size_type n,
103  const bool doStripInvalid
104 )
105 :
106  string(s, n)
107 {
108  if (doStripInvalid)
109  {
110  stripInvalid();
111  }
112 }
113 
114 
115 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
116 
117 inline bool Foam::word::valid(char c)
118 {
119  return
120  (
121  !isspace(c)
122  && c != '"' // string quote
123  && c != '\'' // string quote
124  && c != '/' // path separator
125  && c != ';' // end statement
126  && c != '{' // beg subdict
127  && c != '}' // end subdict
128  );
129 }
130 
131 
132 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
133 
134 inline const Foam::word& Foam::word::operator=(const word& q)
135 {
136  string::operator=(q);
137  return *this;
138 }
139 
140 
141 inline const Foam::word& Foam::word::operator=(const string& q)
142 {
143  string::operator=(q);
144  stripInvalid();
145  return *this;
146 }
147 
148 
149 inline const Foam::word& Foam::word::operator=(const std::string& q)
150 {
151  string::operator=(q);
152  stripInvalid();
153  return *this;
154 }
155 
156 
157 inline const Foam::word& Foam::word::operator=(const char* q)
158 {
159  string::operator=(q);
160  stripInvalid();
161  return *this;
162 }
163 
164 
165 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
166 
167 inline Foam::word Foam::operator&(const word& a, const word& b)
168 {
169  if (b.size())
170  {
171  string ub = b;
172  ub.string::operator[](0) = char(toupper(ub.string::operator[](0)));
173 
174  return a + ub;
175  }
176  else
177  {
178  return a;
179  }
180 }
181 
182 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
183 
184 // ************************************************************************* //
static int debug
Definition: word.H:74
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:28
tmp< GeometricField< Type, fvPatchField, volMesh > > operator&(const fvMatrix< Type > &, const DimensionedField< Type, volMesh > &)
string()
Construct null.
Definition: stringI.H:30
A class for handling words, derived from string.
Definition: word.H:59
A class for handling character strings derived from std::string.
Definition: string.H:74
word()
Construct null.
Definition: wordI.H:61
const word & operator=(const word &)
Definition: wordI.H:134
graph_traits< Graph >::vertices_size_type size_type
Definition: SloanRenumber.C:73
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
static bool valid(char)
Is this character valid for a word.
Definition: wordI.H:117
errorManip< error > abort(error &err)
Definition: errorManip.H:131
const dimensionedScalar c
Speed of light in a vacuum.
bool isspace(char c)
Definition: char.H:53