Commit d11f08e6 authored by Mark Olesen's avatar Mark Olesen

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!
parent 49cb728c
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2004-2010, 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 | Copyright (C) 2004-2010 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2004-2010, 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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment