BUG: UListIO: byteSize overflowing on really big faceLists
[OpenFOAM-2.0.x.git] / src / OpenFOAM / primitives / strings / string / stringI.H
blob9d81da04f1c08dcda00f8a47a072e563080cfae3
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.
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
19     for more details.
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 \*---------------------------------------------------------------------------*/
26 #include <iostream>
28 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
30 inline Foam::string::string()
34 inline Foam::string::string(const std::string& str)
36     std::string(str)
40 // Copy character array
41 inline Foam::string::string(const char* str)
43     std::string(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)
50     std::string(str, len)
54 // Construct from a single character
55 inline Foam::string::string(const char c)
57     std::string(1, 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)
67     {
68         if (!String::valid(*iter))
69         {
70             return false;
71         }
72     }
73     return true;
77 template<class String>
78 inline bool Foam::string::stripInvalid(string& str)
80     if (!valid<String>(str))
81     {
82         register size_type nValid = 0;
83         iterator iter2 = str.begin();
85         for
86         (
87             const_iterator iter1 = iter2;
88             iter1 != const_cast<const string&>(str).end();
89             iter1++
90         )
91         {
92             register char c = *iter1;
94             if (String::valid(c))
95             {
96                 *iter2 = c;
97                 ++iter2;
98                 ++nValid;
99             }
100         }
102         str.resize(nValid);
104         return true;
105     }
107     return false;
111 template<class String>
112 inline bool Foam::string::meta(const string& str, const char quote)
114     int escaped = 0;
115     for (const_iterator iter = str.begin(); iter != str.end(); ++iter)
116     {
117         if (quote && *iter == quote)
118         {
119             escaped ^= 1;  // toggle state
120         }
121         else if (escaped)
122         {
123             escaped = false;
124         }
125         else if (String::meta(*iter))
126         {
127             return true;
128         }
129     }
130     return false;
134 template<class String>
135 inline Foam::string
136 Foam::string::quotemeta(const string& str, const char quote)
138     if (!quote)
139     {
140         return str;
141     }
143     string sQuoted;
144     sQuoted.reserve(2*str.length());
146     int escaped = 0;
147     for (const_iterator iter = str.begin(); iter != str.end(); ++iter)
148     {
149         if (*iter == quote)
150         {
151             escaped ^= 1;  // toggle state
152         }
153         else if (escaped)
154         {
155             escaped = 0;
156         }
157         else if (String::meta(*iter))
158         {
159             sQuoted += quote;
160         }
162         sQuoted += *iter;
163     }
165     sQuoted.resize(sQuoted.length());
167     return sQuoted;
171 template<class String>
172 inline String Foam::string::validate(const string& str)
174     string ss = str;
175     stripInvalid<String>(ss);
176     return ss;
179 inline bool Foam::string::match(const std::string& str) const
181     // check as string
182     return (str == *this);
186 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
188 inline Foam::string Foam::string::operator()
190     const size_type i,
191     const size_type n
192 ) const
194     return substr(i, n);
198 inline Foam::string Foam::string::operator()(const size_type n) const
200     return substr(0, n);
204 inline unsigned Foam::string::hash::operator()
206     const string& key,
207     unsigned seed
208 ) const
210     return Hasher(key.data(), key.size(), seed);
213 // ************************************************************************* //