Merge branch 'upstream/OpenFOAM' into master
[freefoam.git] / src / OpenFOAM / primitives / strings / word / wordI.H
blobf279b7940f39610105a63fe41e68bd79414fc143
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
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.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include <cctype>
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
33 inline void Foam::word::stripInvalid()
35     // skip stripping unless debug is active to avoid
36     // costly operations
37     if (debug && string::stripInvalid<word>(*this))
38     {
39         std::cerr
40             << "word::stripInvalid() called for word "
41             << this->c_str() << std::endl;
43         if (debug > 1)
44         {
45             std::cerr
46                 << "    For debug level (= " << debug
47                 << ") > 1 this is considered fatal" << std::endl;
48             std::abort();
49         }
50     }
54 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
56 inline Foam::word::word(const word& w)
58     string(w)
62 inline Foam::word::word()
64     string()
68 inline Foam::word::word(const string& s, const bool doStripInvalid)
70     string(s)
72     if (doStripInvalid)
73     {
74         stripInvalid();
75     }
79 inline Foam::word::word(const std::string& s, const bool doStripInvalid)
81     string(s)
83     if (doStripInvalid)
84     {
85         stripInvalid();
86     }
90 inline Foam::word::word(const char* s, const bool doStripInvalid)
92     string(s)
94     if (doStripInvalid)
95     {
96         stripInvalid();
97     }
100 inline Foam::word::word
102     const char* s,
103     const size_type n,
104     const bool doStripInvalid
107     string(s, n)
109     if (doStripInvalid)
110     {
111         stripInvalid();
112     }
116 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
118 inline bool Foam::word::valid(char c)
120     return
121     (
122         !isspace(c)
123      && c != '"'   // string quote
124      && c != '\''  // string quote
125      && c != '/'   // path separator
126      && c != ';'   // end statement
127      && c != '{'   // beg subdict
128      && c != '}'   // end subdict
129     );
133 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
135 inline const Foam::word& Foam::word::operator=(const word& q)
137     string::operator=(q);
138     return *this;
142 inline const Foam::word& Foam::word::operator=(const string& q)
144     string::operator=(q);
145     stripInvalid();
146     return *this;
150 inline const Foam::word& Foam::word::operator=(const std::string& q)
152     string::operator=(q);
153     stripInvalid();
154     return *this;
158 inline const Foam::word& Foam::word::operator=(const char* q)
160     string::operator=(q);
161     stripInvalid();
162     return *this;
166 // * * * * * * * * * * * * * * * Friend Operators  * * * * * * * * * * * * * //
168 inline Foam::word Foam::operator&(const word& a, const word& b)
170     if (b.size())
171     {
172         string ub = b;
173         ub.string::operator[](0) = char(toupper(ub.string::operator[](0)));
175         return a + ub;
176     }
177     else
178     {
179         return a;
180     }
183 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
185 // ************************ vim: set sw=4 sts=4 et: ************************ //