1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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
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/>.
24 \*---------------------------------------------------------------------------*/
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 inline Foam::string::string()
34 inline Foam::string::string(const std::string& str)
40 // Copy character array
41 inline Foam::string::string(const char* str)
47 // Construct from a given number of characters in a character array
48 inline Foam::string::string(const char* str, const size_type len)
54 // Construct from a single character
55 inline Foam::string::string(const char c)
61 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
63 template<class String>
64 inline bool Foam::string::valid(const string& str)
66 for (const_iterator iter = str.begin(); iter != str.end(); ++iter)
68 if (!String::valid(*iter))
77 template<class String>
78 inline bool Foam::string::stripInvalid(string& str)
80 if (!valid<String>(str))
82 register size_type nValid = 0;
83 iterator iter2 = str.begin();
87 const_iterator iter1 = iter2;
88 iter1 != const_cast<const string&>(str).end();
92 register char c = *iter1;
111 template<class String>
112 inline bool Foam::string::meta(const string& str, const char quote)
115 for (const_iterator iter = str.begin(); iter != str.end(); ++iter)
117 if (quote && *iter == quote)
119 escaped ^= 1; // toggle state
125 else if (String::meta(*iter))
134 template<class String>
136 Foam::string::quotemeta(const string& str, const char quote)
144 sQuoted.reserve(2*str.length());
147 for (const_iterator iter = str.begin(); iter != str.end(); ++iter)
151 escaped ^= 1; // toggle state
157 else if (String::meta(*iter))
165 sQuoted.resize(sQuoted.length());
171 template<class String>
172 inline String Foam::string::validate(const string& str)
175 stripInvalid<String>(ss);
179 inline bool Foam::string::match(const std::string& str) const
182 return (str == *this);
186 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
188 inline Foam::string Foam::string::operator()
198 inline Foam::string Foam::string::operator()(const size_type n) const
204 inline unsigned Foam::string::hash::operator()
210 return Hasher(key.data(), key.size(), seed);
213 // ************************************************************************* //