mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
Creation of OpenFOAM-dev repository 15/04/2008
This commit is contained in:
299
src/OpenFOAM/primitives/strings/string/string.C
Normal file
299
src/OpenFOAM/primitives/strings/string/string.C
Normal file
@ -0,0 +1,299 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "string.H"
|
||||
#include "debug.H"
|
||||
#include "OSspecific.H"
|
||||
|
||||
/* * * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * */
|
||||
|
||||
const char* const Foam::string::typeName = "string";
|
||||
int Foam::string::debug(debug::debugSwitch(string::typeName, 0));
|
||||
const Foam::string Foam::string::null;
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
// Count and return the number of a given character in the string
|
||||
Foam::string::size_type Foam::string::count(const char c) const
|
||||
{
|
||||
register size_type cCount=0;
|
||||
|
||||
for
|
||||
(
|
||||
const_iterator iter = begin();
|
||||
iter != end();
|
||||
++iter
|
||||
)
|
||||
{
|
||||
if (*iter == c)
|
||||
{
|
||||
cCount++;
|
||||
}
|
||||
}
|
||||
|
||||
return cCount;
|
||||
}
|
||||
|
||||
|
||||
// Replace first occurence of sub-string oldStr with newStr
|
||||
Foam::string& Foam::string::replace
|
||||
(
|
||||
const string& oldStr,
|
||||
const string& newStr,
|
||||
size_type start
|
||||
)
|
||||
{
|
||||
size_type newStart = start;
|
||||
|
||||
if ((newStart = find(oldStr, newStart)) != npos)
|
||||
{
|
||||
std::string::replace(newStart, oldStr.size(), newStr);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
// Replace all occurences of sub-string oldStr with newStr
|
||||
Foam::string& Foam::string::replaceAll
|
||||
(
|
||||
const string& oldStr,
|
||||
const string& newStr,
|
||||
size_type start
|
||||
)
|
||||
{
|
||||
if (oldStr.size())
|
||||
{
|
||||
size_type newStart = start;
|
||||
|
||||
while ((newStart = find(oldStr, newStart)) != npos)
|
||||
{
|
||||
std::string::replace(newStart, oldStr.size(), newStr);
|
||||
newStart += newStr.size();
|
||||
}
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
// Expand all occurences of environment variables and initial tilde sequences
|
||||
Foam::string& Foam::string::expand()
|
||||
{
|
||||
size_type startEnvar = 0;
|
||||
|
||||
// Expand $VARS
|
||||
// Repeat until nothing more is found
|
||||
while
|
||||
(
|
||||
(startEnvar = find('$', startEnvar)) != npos
|
||||
&& startEnvar < size()-1
|
||||
)
|
||||
{
|
||||
if (startEnvar == 0 || operator[](startEnvar-1) != '\\')
|
||||
{
|
||||
// Find end of first occurrence
|
||||
size_type endEnvar = startEnvar;
|
||||
size_type nd = 0;
|
||||
|
||||
if (operator[](startEnvar+1) == '{')
|
||||
{
|
||||
endEnvar = find('}', startEnvar);
|
||||
nd = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
iterator iter = begin() + startEnvar + 1;
|
||||
|
||||
while (iter != end() && (isalnum(*iter) || *iter == '_'))
|
||||
{
|
||||
++iter;
|
||||
++endEnvar;
|
||||
}
|
||||
}
|
||||
|
||||
if (endEnvar != npos && endEnvar != startEnvar)
|
||||
{
|
||||
string enVar = substr
|
||||
(
|
||||
startEnvar + 1 + nd,
|
||||
endEnvar - startEnvar - 2*nd
|
||||
);
|
||||
|
||||
string enVarString = getEnv(enVar);
|
||||
|
||||
if (enVarString.size())
|
||||
{
|
||||
std::string::replace
|
||||
(
|
||||
startEnvar,
|
||||
endEnvar - startEnvar + 1,
|
||||
enVarString
|
||||
);
|
||||
startEnvar += enVarString.size();
|
||||
}
|
||||
else
|
||||
{
|
||||
//startEnvar = endEnvar;
|
||||
|
||||
FatalErrorIn("string::expand()")
|
||||
<< "Unknown variable name " << enVar << '.'
|
||||
<< exit(FatalError);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
startEnvar++;
|
||||
}
|
||||
}
|
||||
|
||||
if (size())
|
||||
{
|
||||
// Expand initial '.' and './' into cwd
|
||||
if (operator[](0) == '.')
|
||||
{
|
||||
if (size() == 1 || (size() > 1 && operator[](1) == '/'))
|
||||
{
|
||||
std::string::replace(0, 1, cwd());
|
||||
}
|
||||
}
|
||||
else if (operator[](0) == '~')
|
||||
{
|
||||
// Expand initial ~
|
||||
// ~/ => home directory
|
||||
// ~OpenFOAM => site/user OpenFOAM configuration directory
|
||||
// ~user => home directory for specified user
|
||||
|
||||
word user;
|
||||
fileName file;
|
||||
|
||||
if ((startEnvar = find('/')) != npos)
|
||||
{
|
||||
user = substr(1, startEnvar - 1);
|
||||
file = substr(startEnvar + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
user = substr(1);
|
||||
}
|
||||
|
||||
// NB: be a bit lazy and expand ~unknownUser as an
|
||||
// empty string rather than leaving it untouched.
|
||||
// otherwise add extra test
|
||||
if (user == "OpenFOAM")
|
||||
{
|
||||
*this = dotFoam(file);
|
||||
}
|
||||
else
|
||||
{
|
||||
*this = home(user)/file;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
// Remove repeated characters returning true if string changed
|
||||
bool Foam::string::removeRepeated(const char character)
|
||||
{
|
||||
bool changed = false;
|
||||
|
||||
if (character && find(character) != npos)
|
||||
{
|
||||
register string::size_type nChar=0;
|
||||
iterator iter2 = begin();
|
||||
|
||||
register char prev = 0;
|
||||
|
||||
for
|
||||
(
|
||||
string::const_iterator iter1 = iter2;
|
||||
iter1 != end();
|
||||
iter1++
|
||||
)
|
||||
{
|
||||
register char c = *iter1;
|
||||
|
||||
if (prev == c && c == character)
|
||||
{
|
||||
changed = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
*iter2 = prev = c;
|
||||
++iter2;
|
||||
++nChar;
|
||||
}
|
||||
}
|
||||
resize(nChar);
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
|
||||
// Return string with repeated characters removed
|
||||
Foam::string Foam::string::removeRepeated(const char character) const
|
||||
{
|
||||
string s(*this);
|
||||
s.removeRepeated(character);
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
// Remove trailing character returning true if string changed
|
||||
bool Foam::string::removeTrailing(const char character)
|
||||
{
|
||||
bool changed = false;
|
||||
|
||||
string::size_type nChar = size();
|
||||
if (character && nChar > 1 && operator[](nChar-1) == character)
|
||||
{
|
||||
resize(nChar-1);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
|
||||
// Return string with trailing character removed
|
||||
Foam::string Foam::string::removeTrailing(const char character) const
|
||||
{
|
||||
string s(*this);
|
||||
s.removeTrailing(character);
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
228
src/OpenFOAM/primitives/strings/string/string.H
Normal file
228
src/OpenFOAM/primitives/strings/string/string.H
Normal file
@ -0,0 +1,228 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Class
|
||||
Foam::string
|
||||
|
||||
Description
|
||||
A class for handling character strings derived from std::string.
|
||||
|
||||
Strings may contain any characters and therefore are delimited by quotes
|
||||
for IO : "any list of characters".
|
||||
|
||||
Used as a base class for word and fileName.
|
||||
|
||||
See Also
|
||||
Foam::dotFoam() for information about the site/user OpenFOAM
|
||||
configuration directory
|
||||
|
||||
SourceFiles
|
||||
string.C
|
||||
stringIO.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef string_H
|
||||
#define string_H
|
||||
|
||||
#include "char.H"
|
||||
|
||||
#include <string>
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declaration of classes
|
||||
class Istream;
|
||||
class Ostream;
|
||||
|
||||
// Forward declaration of friend functions and operators
|
||||
class string;
|
||||
Istream& operator>>(Istream&, string&);
|
||||
Ostream& operator<<(Ostream&, const string&);
|
||||
Ostream& operator<<(Ostream&, const std::string&);
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class string Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class string
|
||||
:
|
||||
public std::string
|
||||
{
|
||||
public:
|
||||
|
||||
// Static data members
|
||||
|
||||
static const char* const typeName;
|
||||
static int debug;
|
||||
static const string null;
|
||||
|
||||
|
||||
//- Hashing function class
|
||||
class hash
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
inline hash();
|
||||
|
||||
inline size_type operator()(const string& key) const;
|
||||
|
||||
inline size_type operator()
|
||||
(
|
||||
const string& key,
|
||||
const size_type tableSize
|
||||
) const;
|
||||
};
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
inline string();
|
||||
|
||||
//- Construct from std::string
|
||||
inline string(const std::string&);
|
||||
|
||||
//- Construct as copy of character array
|
||||
inline string(const char*);
|
||||
|
||||
//- Construct as copy of specified number of characters
|
||||
inline string(const char*, const size_type);
|
||||
|
||||
//- Construct from a single character
|
||||
inline string(const char);
|
||||
|
||||
//- Construct from Istream
|
||||
string(Istream&);
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
// Access
|
||||
|
||||
//- Count and return the number of a given character in the string
|
||||
size_type count(const char) const;
|
||||
|
||||
//- Is this string type valid
|
||||
template<class String>
|
||||
static inline bool valid(const string&);
|
||||
|
||||
|
||||
// Edit
|
||||
|
||||
//- Strip invalid characters from the given string
|
||||
template<class String>
|
||||
static inline bool stripInvalid(string&);
|
||||
|
||||
//- Return a valid String from the given string
|
||||
template<class String>
|
||||
static inline String validate(const string&);
|
||||
|
||||
//- Replace first occurence of sub-string oldStr with newStr
|
||||
// starting at start
|
||||
string& replace
|
||||
(
|
||||
const string& oldStr,
|
||||
const string& newStr,
|
||||
size_type start = 0
|
||||
);
|
||||
|
||||
//- Replace all occurences of sub-string oldStr with newStr
|
||||
// starting at start
|
||||
string& replaceAll
|
||||
(
|
||||
const string& oldStr,
|
||||
const string& newStr,
|
||||
size_type start = 0
|
||||
);
|
||||
|
||||
//- Expand initial tildes and all occurences of environment variables
|
||||
// Expansion includes:
|
||||
// -# environment variables
|
||||
// - "$VAR", "${VAR}"
|
||||
// -# current directory
|
||||
// - leading "./" : the current directory
|
||||
// -# tilde expansion
|
||||
// - leading "~/" : home directory
|
||||
// - leading "~user" : home directory for specified user
|
||||
// - leading "~OpenFOAM" : site/user OpenFOAM configuration directory
|
||||
//
|
||||
// @sa
|
||||
// Foam::dotFoam
|
||||
string& expand();
|
||||
|
||||
//- Remove repeated characters returning true if string changed
|
||||
bool removeRepeated(const char character);
|
||||
|
||||
//- Return string with repeated characters removed
|
||||
string removeRepeated(const char character) const;
|
||||
|
||||
//- Remove trailing character returning true if string changed
|
||||
bool removeTrailing(const char character);
|
||||
|
||||
//- Return string with trailing character removed
|
||||
string removeTrailing(const char character) const;
|
||||
|
||||
|
||||
// Member Operators
|
||||
|
||||
//- Return the sub-string from the i-th character for @a n characters
|
||||
inline string operator()
|
||||
(
|
||||
const size_type i,
|
||||
const size_type n
|
||||
) const;
|
||||
|
||||
//- Return the sub-string from the first character for @a n characters
|
||||
inline string operator()
|
||||
(
|
||||
const size_type n
|
||||
) const;
|
||||
|
||||
|
||||
// IOstream Operators
|
||||
|
||||
friend Istream& operator>>(Istream&, string&);
|
||||
friend Ostream& operator<<(Ostream&, const string&);
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#include "stringI.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
173
src/OpenFOAM/primitives/strings/string/stringI.H
Normal file
173
src/OpenFOAM/primitives/strings/string/stringI.H
Normal file
@ -0,0 +1,173 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
inline Foam::string::string()
|
||||
{}
|
||||
|
||||
|
||||
inline Foam::string::string(const std::string& stdStr)
|
||||
:
|
||||
std::string(stdStr)
|
||||
{}
|
||||
|
||||
|
||||
// Copy character array
|
||||
inline Foam::string::string(const char* str)
|
||||
:
|
||||
std::string(str)
|
||||
{}
|
||||
|
||||
|
||||
// Construct from a given number of characters in a character array
|
||||
inline Foam::string::string(const char* str, const size_type len)
|
||||
:
|
||||
std::string(str, len)
|
||||
{}
|
||||
|
||||
|
||||
// Construct from a single character
|
||||
inline Foam::string::string(const char c)
|
||||
:
|
||||
std::string(1, c)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class String>
|
||||
inline bool Foam::string::valid(const string& s)
|
||||
{
|
||||
bool iv = false;
|
||||
|
||||
for (const_iterator iter = s.begin(); iter != s.end(); iter++)
|
||||
{
|
||||
if (!String::valid(*iter))
|
||||
{
|
||||
iv = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return !iv;
|
||||
}
|
||||
|
||||
|
||||
template<class String>
|
||||
inline bool Foam::string::stripInvalid(string& s)
|
||||
{
|
||||
if (!valid<String>(s))
|
||||
{
|
||||
register size_type nValid=0;
|
||||
iterator iter2 = s.begin();
|
||||
|
||||
for
|
||||
(
|
||||
const_iterator iter1 = iter2;
|
||||
iter1 != const_cast<const string&>(s).end();
|
||||
iter1++
|
||||
)
|
||||
{
|
||||
register char c = *iter1;
|
||||
|
||||
if (String::valid(c))
|
||||
{
|
||||
*iter2 = c;
|
||||
++iter2;
|
||||
++nValid;
|
||||
}
|
||||
}
|
||||
|
||||
s.resize(nValid);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
template<class String>
|
||||
inline String Foam::string::validate(const string& s)
|
||||
{
|
||||
string ss = s;
|
||||
stripInvalid<String>(ss);
|
||||
return ss;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||
|
||||
inline Foam::string Foam::string::operator()
|
||||
(
|
||||
const size_type i,
|
||||
const size_type n
|
||||
) const
|
||||
{
|
||||
return substr(i, n);
|
||||
}
|
||||
|
||||
|
||||
inline Foam::string Foam::string::operator()(const size_type n) const
|
||||
{
|
||||
return substr(0, n);
|
||||
}
|
||||
|
||||
|
||||
inline Foam::string::hash::hash()
|
||||
{}
|
||||
|
||||
|
||||
inline Foam::string::size_type Foam::string::hash::operator()
|
||||
(
|
||||
const string& key
|
||||
) const
|
||||
{
|
||||
register size_type hashVal = 0;
|
||||
|
||||
for (string::const_iterator iter=key.begin(); iter!=key.end(); ++iter)
|
||||
{
|
||||
hashVal = hashVal<<1 ^ *iter;
|
||||
}
|
||||
|
||||
return hashVal;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::string::size_type Foam::string::hash::operator()
|
||||
(
|
||||
const string& key,
|
||||
const size_type tableSize
|
||||
) const
|
||||
{
|
||||
return ::abs(operator()(key)) % tableSize;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
87
src/OpenFOAM/primitives/strings/string/stringIO.C
Normal file
87
src/OpenFOAM/primitives/strings/string/stringIO.C
Normal file
@ -0,0 +1,87 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "string.H"
|
||||
#include "IOstreams.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::string::string(Istream& is)
|
||||
{
|
||||
is >> *this;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
||||
|
||||
Foam::Istream& Foam::operator>>(Istream& is, string& s)
|
||||
{
|
||||
token t(is);
|
||||
|
||||
if (!t.good())
|
||||
{
|
||||
is.setBad();
|
||||
return is;
|
||||
}
|
||||
|
||||
if (t.isString())
|
||||
{
|
||||
s = t.stringToken();
|
||||
}
|
||||
else
|
||||
{
|
||||
is.setBad();
|
||||
FatalIOErrorIn("operator>>(Istream&, string&)", is)
|
||||
<< "wrong token type - expected string found " << t.info()
|
||||
<< exit(FatalIOError);
|
||||
|
||||
return is;
|
||||
}
|
||||
|
||||
// Check state of Istream
|
||||
is.check("Istream& operator>>(Istream&, string&)");
|
||||
|
||||
return is;
|
||||
}
|
||||
|
||||
|
||||
Foam::Ostream& Foam::operator<<(Ostream& os, const string& s)
|
||||
{
|
||||
os.write(s);
|
||||
os.check("Ostream& operator<<(Ostream&, const string&)");
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
Foam::Ostream& Foam::operator<<(Ostream& os, const std::string& s)
|
||||
{
|
||||
os.write(string(s));
|
||||
os.check("Ostream& operator<<(Ostream&, const std::string&)");
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
Reference in New Issue
Block a user