mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: no string quotes when using OSHA1stream (#1301)
- previously would have different SHA1 depending on whether the
string was a C-string, a C++-string or if the SHA1 was calculated
directly or via the OSHA1stream.
- SHA1("string")
- OSHA1stream << "string";
- OSHA1stream << string("string");
By avoiding string quoting on output, they now all deliver the same
result. This also means that the following will no longer change the SHA1
content, since it does not add anything:
osha<< string() << string() << string() << string();
This would have previously add a pair of double quotes each time!
This commit is contained in:
committed by
Andrew Heather
parent
e7a046858e
commit
26a391b1e9
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd |
|
||||
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
| Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||
@ -24,11 +24,10 @@ License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Application
|
||||
testSHA1
|
||||
Test-SHA1
|
||||
|
||||
Description
|
||||
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "OSHA1stream.H"
|
||||
@ -42,15 +41,27 @@ using namespace Foam;
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
SHA1 sha;
|
||||
OSHA1stream osha;
|
||||
SHA1Digest shaDig;
|
||||
|
||||
const std::string str("The quick brown fox jumps over the lazy dog");
|
||||
Info<< shaDig << " : empty" << nl;
|
||||
Info<< SHA1(str) << " : " << str << nl;
|
||||
|
||||
Info<< osha.digest() << " : empty" << nl;
|
||||
|
||||
osha<< "";
|
||||
Info<< osha.digest() << " : still empty" << nl;
|
||||
|
||||
osha<< std::string();
|
||||
Info<< osha.digest() << " : still empty" << nl;
|
||||
|
||||
sha.append(str);
|
||||
Info<< sha << " : appended to empty" << nl;
|
||||
|
||||
osha<< str;
|
||||
Info<< osha.digest() << " : output << to empty" << nl;
|
||||
|
||||
sha.clear();
|
||||
sha.append(str);
|
||||
shaDig = sha;
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd |
|
||||
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
| Copyright (C) 2011 OpenFOAM Foundation
|
||||
@ -211,6 +211,16 @@ public:
|
||||
{}
|
||||
|
||||
|
||||
// Write Functions
|
||||
|
||||
//- Add (unquoted) string contents.
|
||||
// Ensures that SHA1 of C-string or C++-string content are identical.
|
||||
virtual Ostream& write(const string& str)
|
||||
{
|
||||
return writeQuoted(str, false); // Unquoted!
|
||||
}
|
||||
|
||||
|
||||
// Housekeeping
|
||||
|
||||
//- Deprecated(2017-07) clear the SHA1 calculation
|
||||
|
||||
Reference in New Issue
Block a user