OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

wordI.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include <cctype>
00028 
00029 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00030 
00031 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00032 
00033 inline void Foam::word::stripInvalid()
00034 {
00035     // skip stripping unless debug is active to avoid
00036     // costly operations
00037     if (debug && string::stripInvalid<word>(*this))
00038     {
00039         std::cerr
00040             << "word::stripInvalid() called for word "
00041             << this->c_str() << std::endl;
00042 
00043         if (debug > 1)
00044         {
00045             std::cerr
00046                 << "    For debug level (= " << debug
00047                 << ") > 1 this is considered fatal" << std::endl;
00048             std::abort();
00049         }
00050     }
00051 }
00052 
00053 
00054 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00055 
00056 inline Foam::word::word(const word& w)
00057 :
00058     string(w)
00059 {}
00060 
00061 
00062 inline Foam::word::word()
00063 :
00064     string()
00065 {}
00066 
00067 
00068 inline Foam::word::word(const string& s, const bool doStripInvalid)
00069 :
00070     string(s)
00071 {
00072     if (doStripInvalid)
00073     {
00074         stripInvalid();
00075     }
00076 }
00077 
00078 
00079 inline Foam::word::word(const std::string& s, const bool doStripInvalid)
00080 :
00081     string(s)
00082 {
00083     if (doStripInvalid)
00084     {
00085         stripInvalid();
00086     }
00087 }
00088 
00089 
00090 inline Foam::word::word(const char* s, const bool doStripInvalid)
00091 :
00092     string(s)
00093 {
00094     if (doStripInvalid)
00095     {
00096         stripInvalid();
00097     }
00098 }
00099 
00100 inline Foam::word::word
00101 (
00102     const char* s,
00103     const size_type n,
00104     const bool doStripInvalid
00105 )
00106 :
00107     string(s, n)
00108 {
00109     if (doStripInvalid)
00110     {
00111         stripInvalid();
00112     }
00113 }
00114 
00115 
00116 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00117 
00118 inline bool Foam::word::valid(char c)
00119 {
00120     return
00121     (
00122         !isspace(c)
00123      && c != '"'   // string quote
00124      && c != '\''  // string quote
00125      && c != '/'   // path separator
00126      && c != ';'   // end statement
00127      && c != '{'   // beg subdict
00128      && c != '}'   // end subdict
00129     );
00130 }
00131 
00132 
00133 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
00134 
00135 inline const Foam::word& Foam::word::operator=(const word& q)
00136 {
00137     string::operator=(q);
00138     return *this;
00139 }
00140 
00141 
00142 inline const Foam::word& Foam::word::operator=(const string& q)
00143 {
00144     string::operator=(q);
00145     stripInvalid();
00146     return *this;
00147 }
00148 
00149 
00150 inline const Foam::word& Foam::word::operator=(const std::string& q)
00151 {
00152     string::operator=(q);
00153     stripInvalid();
00154     return *this;
00155 }
00156 
00157 
00158 inline const Foam::word& Foam::word::operator=(const char* q)
00159 {
00160     string::operator=(q);
00161     stripInvalid();
00162     return *this;
00163 }
00164 
00165 
00166 // * * * * * * * * * * * * * * * Friend Operators  * * * * * * * * * * * * * //
00167 
00168 inline Foam::word Foam::operator&(const word& a, const word& b)
00169 {
00170     if (b.size())
00171     {
00172         string ub = b;
00173         ub.string::operator[](0) = char(toupper(ub.string::operator[](0)));
00174 
00175         return a + ub;
00176     }
00177     else
00178     {
00179         return a;
00180     }
00181 }
00182 
00183 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00184 
00185 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd