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-2016 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 void Foam::word::operator=(const word& q)
135 {
136  string::operator=(q);
137 }
138 
139 
140 inline void Foam::word::operator=(const string& q)
141 {
142  string::operator=(q);
143  stripInvalid();
144 }
145 
146 
147 inline void Foam::word::operator=(const std::string& q)
148 {
149  string::operator=(q);
150  stripInvalid();
151 }
152 
153 
154 inline void Foam::word::operator=(const char* q)
155 {
156  string::operator=(q);
157  stripInvalid();
158 }
159 
160 
161 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
162 
163 inline Foam::word Foam::operator&(const word& a, const word& b)
164 {
165  if (b.size())
166  {
167  string ub = b;
168  ub.string::operator[](0) = char(toupper(ub.string::operator[](0)));
169 
170  return a + ub;
171  }
172  else
173  {
174  return a;
175  }
176 }
177 
178 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
179 
180 // ************************************************************************* //
static bool valid(char)
Is this character valid for a word.
Definition: wordI.H:117
void operator=(const word &)
Definition: wordI.H:134
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
word()
Construct null.
Definition: wordI.H:61
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
tmp< GeometricField< Type, fvPatchField, volMesh > > operator&(const fvMatrix< Type > &, const DimensionedField< Type, volMesh > &)
const dimensionedScalar c
Speed of light in a vacuum.
A class for handling character strings derived from std::string.
Definition: string.H:74