From 60c314150c965fe15279aac22c7b33ba69b6eac7 Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Thu, 14 Feb 2019 09:06:43 +0100
Subject: [PATCH] ENH: ensure self-assignment and self-swapping are a no-op for
 string types

- simplifies their use when reordering lists etc.
  (word, fileName, keyType, wordRe)

- "unfriend" IO operators for string types. They require no internal access

- add compile/uncompile methods to keyType for symmetry with wordRe

- when outputting keyType/wordRe, be more explicit about them using
  writeQuoted()
---
 src/OSspecific/POSIX/regExp.H                 |  2 +-
 src/OSspecific/POSIX/regExpI.H                |  2 +-
 src/OpenFOAM/db/IOstreams/IOstreams/Ostream.C | 17 +++--
 src/OpenFOAM/db/IOstreams/IOstreams/Ostream.H |  2 +-
 src/OpenFOAM/primitives/hashes/SHA1/SHA1.H    | 21 ++----
 src/OpenFOAM/primitives/hashes/SHA1/SHA1I.H   |  2 +-
 .../primitives/strings/fileName/fileName.H    | 36 ++++-----
 .../primitives/strings/fileName/fileNameI.H   | 74 ++++++++++++-------
 .../primitives/strings/fileName/fileNameIO.C  |  4 +-
 .../primitives/strings/keyType/keyType.C      |  9 ++-
 .../primitives/strings/keyType/keyType.H      | 55 ++++++++++----
 .../primitives/strings/keyType/keyTypeI.H     | 46 +++++++++++-
 .../primitives/strings/lists/CStringList.H    | 18 ++---
 .../primitives/strings/lists/hashedWordList.H | 12 +--
 .../primitives/strings/string/string.H        | 25 ++++---
 .../primitives/strings/string/stringI.H       | 12 ++-
 .../primitives/strings/string/stringIO.C      |  8 +-
 src/OpenFOAM/primitives/strings/word/word.H   | 40 +++++-----
 src/OpenFOAM/primitives/strings/word/wordI.H  | 66 +++++++++++------
 src/OpenFOAM/primitives/strings/word/wordIO.C |  6 +-
 .../primitives/strings/wordRe/wordRe.C        | 36 ++++-----
 .../primitives/strings/wordRe/wordRe.H        | 64 ++++++++--------
 .../primitives/strings/wordRe/wordReI.H       | 40 ++++++----
 .../ensight/name/ensightFileName.H            | 10 +--
 .../ensight/name/ensightFileNameI.H           | 24 +++---
 src/fileFormats/ensight/name/ensightVarName.H | 10 +--
 .../ensight/name/ensightVarNameI.H            | 43 ++++++-----
 27 files changed, 402 insertions(+), 282 deletions(-)

diff --git a/src/OSspecific/POSIX/regExp.H b/src/OSspecific/POSIX/regExp.H
index 145dccc0e6c..67a4f5c010f 100644
--- a/src/OSspecific/POSIX/regExp.H
+++ b/src/OSspecific/POSIX/regExp.H
@@ -84,7 +84,7 @@ public:
         //  - range: '[', ']' \n
         //
         // \note The presence of '{', '}' regex bounds is not considered
-        inline static bool meta(const char c);
+        inline static bool meta(char c);
 
 
     // Constructors
diff --git a/src/OSspecific/POSIX/regExpI.H b/src/OSspecific/POSIX/regExpI.H
index 6586de160c4..48d3beb36c6 100644
--- a/src/OSspecific/POSIX/regExpI.H
+++ b/src/OSspecific/POSIX/regExpI.H
@@ -28,7 +28,7 @@ License
 
 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
 
-inline bool Foam::regExp::meta(const char c)
+inline bool Foam::regExp::meta(char c)
 {
     return
     (
diff --git a/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.C b/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.C
index 973e2569a6b..6abfb3da779 100644
--- a/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.C
+++ b/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2016 OpenCFD Ltd.
+    \\  /    A nd           | Copyright (C) 2016-2019 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
                             | Copyright (C) 2011-2016 OpenFOAM Foundation
@@ -35,9 +35,10 @@ License
 
 void Foam::Ostream::decrIndent()
 {
-    if (indentLevel_ == 0)
+    if (!indentLevel_)
     {
-        cerr<< "Ostream::decrIndent() : attempt to decrement 0 indent level"
+        std::cerr
+            << "Ostream::decrIndent() : attempt to decrement 0 indent level"
             << std::endl;
     }
     else
@@ -56,17 +57,17 @@ Foam::Ostream& Foam::Ostream::write(const keyType& kw)
 Foam::Ostream& Foam::Ostream::writeKeyword(const keyType& kw)
 {
     indent();
-    write(kw);
+    writeQuoted(kw, kw.isPattern());
 
     label nSpaces = entryIndentation_ - label(kw.size());
 
-    // pattern is surrounded by quotes
+    // Account for quotes surrounding pattern
     if (kw.isPattern())
     {
         nSpaces -= 2;
     }
 
-    // could also increment by indentSize_ ...
+    // Could also increment by indentSize_ ...
     if (nSpaces < 1)
     {
         nSpaces = 1;
@@ -81,9 +82,9 @@ Foam::Ostream& Foam::Ostream::writeKeyword(const keyType& kw)
 }
 
 
-Foam::Ostream& Foam::Ostream::beginBlock(const keyType& keyword)
+Foam::Ostream& Foam::Ostream::beginBlock(const keyType& kw)
 {
-    indent(); write(keyword); write('\n');
+    indent(); writeQuoted(kw, kw.isPattern()); write('\n');
     beginBlock();
 
     return *this;
diff --git a/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.H b/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.H
index 74048c500f9..5d082d6e284 100644
--- a/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.H
+++ b/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.H
@@ -185,7 +185,7 @@ public:
 
             //- Write begin block group with the given name
             //  Increments indentation, adds newline.
-            virtual Ostream& beginBlock(const keyType& keyword);
+            virtual Ostream& beginBlock(const keyType& kw);
 
             //- Write begin block group without a name
             //  Increments indentation, adds newline.
diff --git a/src/OpenFOAM/primitives/hashes/SHA1/SHA1.H b/src/OpenFOAM/primitives/hashes/SHA1/SHA1.H
index 4b24ed471ef..9b343003439 100644
--- a/src/OpenFOAM/primitives/hashes/SHA1/SHA1.H
+++ b/src/OpenFOAM/primitives/hashes/SHA1/SHA1.H
@@ -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-2016 OpenFOAM Foundation
@@ -55,15 +55,6 @@ SourceFiles
 namespace Foam
 {
 
-// Forward declaration of classes
-class Ostream;
-
-// Forward declaration of friend functions and operators
-class SHA1;
-class SHA1Digest;
-Ostream& operator<<(Ostream&, const SHA1&);
-
-
 /*---------------------------------------------------------------------------*\
                             Class SHA1 Declaration
 \*---------------------------------------------------------------------------*/
@@ -91,6 +82,7 @@ class SHA1
         //- The input processing buffer
         uint32_t buffer_[32];
 
+
     // Private Member Functions
 
         //- Process data block-wise, LEN must be a multiple of 64!
@@ -172,14 +164,13 @@ public:
         //- Convert to a SHA1Digest,
         //  calculate current %digest from appended data
         inline operator SHA1Digest() const;
+};
 
 
-    // Friend Operators
-
-        //- Output the %digest
-        inline friend Ostream& operator<<(Ostream&, const SHA1&);
+// IOstream Operators
 
-};
+//- Output the %digest
+inline Ostream& operator<<(Ostream& os, const SHA1& sha);
 
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
diff --git a/src/OpenFOAM/primitives/hashes/SHA1/SHA1I.H b/src/OpenFOAM/primitives/hashes/SHA1/SHA1I.H
index edb1f3b2c2e..3de5c5a42bd 100644
--- a/src/OpenFOAM/primitives/hashes/SHA1/SHA1I.H
+++ b/src/OpenFOAM/primitives/hashes/SHA1/SHA1I.H
@@ -136,7 +136,7 @@ inline Foam::SHA1::operator Foam::SHA1Digest() const
 
 inline Foam::Ostream& Foam::operator<<(Ostream& os, const SHA1& sha)
 {
-    return os  << sha.digest();
+    return (os << sha.digest());
 }
 
 
diff --git a/src/OpenFOAM/primitives/strings/fileName/fileName.H b/src/OpenFOAM/primitives/strings/fileName/fileName.H
index 6212647de2c..824345ad090 100644
--- a/src/OpenFOAM/primitives/strings/fileName/fileName.H
+++ b/src/OpenFOAM/primitives/strings/fileName/fileName.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2016-2018 OpenCFD Ltd.
+    \\  /    A nd           | Copyright (C) 2016-2019 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
                             | Copyright (C) 2011-2017 OpenFOAM Foundation
@@ -62,10 +62,6 @@ typedef List<word> wordList;
 class wordRe;
 class fileName;
 
-Istream& operator>>(Istream&, fileName&);
-Ostream& operator<<(Ostream&, const fileName&);
-
-
 /*---------------------------------------------------------------------------*\
                           Class fileName Declaration
 \*---------------------------------------------------------------------------*/
@@ -74,12 +70,6 @@ class fileName
 :
     public string
 {
-    // Private Member Functions
-
-        //- Strip invalid characters
-        inline void stripInvalid();
-
-
 public:
 
     //- Enumerations to handle directory entry types.
@@ -94,7 +84,10 @@ public:
 
     // Static data members
 
+        //- The typeName
         static const char* const typeName;
+
+        //- Debugging
         static int debug;
 
         //- An empty fileName
@@ -161,6 +154,8 @@ public:
         //- that ignores duplicate or trailing slashes.
         static bool equals(const std::string& s1, const std::string& s2);
 
+        //- Strip invalid characters
+        inline void stripInvalid();
 
         //- Cleanup filename
         //
@@ -353,15 +348,17 @@ public:
         ) const;
 
 
-    // Member operators
+    // Member Operators
 
     // Assignment
 
         //- Copy assignment, no character validation required
-        fileName& operator=(const fileName&) = default;
+        //  Self-assignment is a no-op.
+        inline fileName& operator=(const fileName& str);
 
         //- Move assignment, no character validation required
-        fileName& operator=(fileName&&) = default;
+        //  Self-assignment is a no-op.
+        inline fileName& operator=(fileName&& str);
 
         //- Copy assignment, no character validation required
         inline fileName& operator=(const word& str);
@@ -390,13 +387,16 @@ public:
         //- Append a path element with '/' separator.
         //  No '/' separator is added if this or the argument are empty.
         fileName& operator/=(const string& other);
+};
 
 
-    // IOstream operators
+// IOstream Operators
 
-        friend Istream& operator>>(Istream& is, fileName& fn);
-        friend Ostream& operator<<(Ostream& os, const fileName& fn);
-};
+//- Read operator
+Istream& operator>>(Istream& is, fileName& val);
+
+//- Write operator
+Ostream& operator<<(Ostream& os, const fileName& val);
 
 
 // Global Operators
diff --git a/src/OpenFOAM/primitives/strings/fileName/fileNameI.H b/src/OpenFOAM/primitives/strings/fileName/fileNameI.H
index 3d64e0d2c6a..fb23263c8c6 100644
--- a/src/OpenFOAM/primitives/strings/fileName/fileNameI.H
+++ b/src/OpenFOAM/primitives/strings/fileName/fileNameI.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2016-2018 OpenCFD Ltd.
+    \\  /    A nd           | Copyright (C) 2016-2019 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
                             | Copyright (C) 2011 OpenFOAM Foundation
@@ -25,32 +25,7 @@ License
 
 \*---------------------------------------------------------------------------*/
 
-#include <iostream>  // for std::cerr
-
-// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
-
-inline void Foam::fileName::stripInvalid()
-{
-    // Skip stripping unless debug is active (to avoid costly operations)
-    if (debug && string::stripInvalid<fileName>(*this))
-    {
-        std::cerr
-            << "fileName::stripInvalid() called for invalid fileName "
-            << this->c_str() << std::endl;
-
-        if (debug > 1)
-        {
-            std::cerr
-                << "    For debug level (= " << debug
-                << ") > 1 this is considered fatal" << std::endl;
-            std::abort();
-        }
-
-        removeRepeated('/');
-        removeTrailing('/');
-    }
-}
-
+#include <iostream>  // For std::cerr
 
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
@@ -134,6 +109,29 @@ inline bool Foam::fileName::valid(char c)
 }
 
 
+inline void Foam::fileName::stripInvalid()
+{
+    // Only strip when debug is active (potentially costly operation)
+    if (debug && string::stripInvalid<fileName>(*this))
+    {
+        std::cerr
+            << "fileName::stripInvalid() called for invalid fileName "
+            << this->c_str() << std::endl;
+
+        if (debug > 1)
+        {
+            std::cerr
+                << "    For debug level (= " << debug
+                << ") > 1 this is considered fatal" << std::endl;
+            std::abort();
+        }
+
+        removeRepeated('/');
+        removeTrailing('/');
+    }
+}
+
+
 inline bool Foam::fileName::isAbsolute(const std::string& str)
 {
     return !str.empty() && str[0] == '/';
@@ -258,6 +256,28 @@ inline Foam::fileName& Foam::fileName::ext(const word& ending)
 
 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
 
+inline Foam::fileName& Foam::fileName::operator=(const fileName& str)
+{
+    // Self-assignment is a no-op
+    if (this != &str)
+    {
+        assign(str);
+    }
+    return *this;
+}
+
+
+inline Foam::fileName& Foam::fileName::operator=(fileName&& str)
+{
+    // Self-assignment is a no-op
+    if (this != &str)
+    {
+        assign(std::move(str));
+    }
+    return *this;
+}
+
+
 inline Foam::fileName& Foam::fileName::operator=(const word& str)
 {
     assign(str);
diff --git a/src/OpenFOAM/primitives/strings/fileName/fileNameIO.C b/src/OpenFOAM/primitives/strings/fileName/fileNameIO.C
index 18a4c541296..c26e2c71f5d 100644
--- a/src/OpenFOAM/primitives/strings/fileName/fileNameIO.C
+++ b/src/OpenFOAM/primitives/strings/fileName/fileNameIO.C
@@ -72,9 +72,9 @@ Foam::Istream& Foam::operator>>(Istream& is, fileName& val)
 }
 
 
-Foam::Ostream& Foam::operator<<(Ostream& os, const fileName& fn)
+Foam::Ostream& Foam::operator<<(Ostream& os, const fileName& val)
 {
-    os.write(fn);
+    os.write(val);
     os.check(FUNCTION_NAME);
     return os;
 }
diff --git a/src/OpenFOAM/primitives/strings/keyType/keyType.C b/src/OpenFOAM/primitives/strings/keyType/keyType.C
index 6f59bc224fb..d15e2497e30 100644
--- a/src/OpenFOAM/primitives/strings/keyType/keyType.C
+++ b/src/OpenFOAM/primitives/strings/keyType/keyType.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2018 OpenCFD Ltd.
+    \\  /    A nd           | Copyright (C) 2018-2019 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
                             | Copyright (C) 2011-2015 OpenFOAM Foundation
@@ -76,12 +76,13 @@ Foam::Istream& Foam::operator>>(Istream& is, keyType& val)
     if (t.isWord())
     {
         val = t.wordToken();
+        val.uncompile();  // Non-regex
     }
     else if (t.isString())
     {
         // Assign from string, treat as regular expression
         val = t.stringToken();
-        val.isPattern_ = true;
+        val.compile();   // As regex
 
         // Flag empty strings as an error
         if (val.empty())
@@ -108,9 +109,9 @@ Foam::Istream& Foam::operator>>(Istream& is, keyType& val)
 }
 
 
-Foam::Ostream& Foam::operator<<(Ostream& os, const keyType& kw)
+Foam::Ostream& Foam::operator<<(Ostream& os, const keyType& val)
 {
-    os.write(kw);
+    os.writeQuoted(val, val.isPattern());
     os.check(FUNCTION_NAME);
     return os;
 }
diff --git a/src/OpenFOAM/primitives/strings/keyType/keyType.H b/src/OpenFOAM/primitives/strings/keyType/keyType.H
index 8da6727abb1..ba04851f4e4 100644
--- a/src/OpenFOAM/primitives/strings/keyType/keyType.H
+++ b/src/OpenFOAM/primitives/strings/keyType/keyType.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2017-2018 OpenCFD Ltd.
+    \\  /    A nd           | Copyright (C) 2017-2019 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
                             | Copyright (C) 2011-2016 OpenFOAM Foundation
@@ -48,13 +48,9 @@ SourceFiles
 namespace Foam
 {
 
-// Forward declarations
-class keyType;
+// Forward Declarations
 class Istream;
 class Ostream;
-Istream& operator>>(Istream& is, keyType& kw);
-Ostream& operator<<(Ostream& os, const keyType& kw);
-
 
 /*---------------------------------------------------------------------------*\
                            Class keyType Declaration
@@ -64,9 +60,9 @@ class keyType
 :
     public word
 {
-    // Private data
+    // Private Data
 
-        //- Is the keyType a pattern (regular expression)
+        //- Treat keyType as a pattern (regular expression)
         bool isPattern_;
 
 
@@ -78,13 +74,13 @@ class keyType
 
 public:
 
-    // Static data members
+    // Static Data Members
 
         //- An empty keyType
         static const keyType null;
 
 
-    // Public data types
+    // Public Data Types
 
         //- Enumeration for search/match modes as bitmask
         //  eg, (keyType::REGEX | keyType::RECURSIVE)
@@ -142,18 +138,40 @@ public:
         //  permit brace-brackets, which are valid for some regexs.
         inline static bool valid(char c);
 
+
+    // Access
+
         //- The keyType is treated as literal, not as pattern.
         inline bool isLiteral() const;
 
         //- The keyType is treated as a pattern, not as literal string.
         inline bool isPattern() const;
 
-        //- Swap contents
+
+    // Infrastructure
+
+        //- Mark as regular expression
+        inline bool compile();
+
+        //- Mark as literal, instead of a regular expression.
+        //  Optionally strip invalid word characters.
+        inline void uncompile(bool doStrip = false);
+
+
+    // Editing
+
+        //- Clear string and set as literal
+        inline void clear();
+
+        //- Swap contents. Self-swapping is a no-op.
         inline void swap(keyType& s);
 
+
+    // Matching/Searching
+
         //- Smart match as regular expression or as a string.
         //  Optionally force a literal match only
-        bool match(const std::string& text, bool literal = false) const;
+        bool match(const std::string& text, bool literal=false) const;
 
 
     // Member Operators
@@ -164,9 +182,11 @@ public:
 
 
         //- Copy assignment, retaining type (literal or regex)
+        //  Self-assignment is a no-op.
         inline void operator=(const keyType& s);
 
         //- Move assignment, retaining type (literal or regex)
+        //  Self-assignment is a no-op.
         inline void operator=(keyType&& s);
 
         //- Assign as word, treat as literal
@@ -177,13 +197,16 @@ public:
 
         //- Assign as word, treat as literal
         inline void operator=(const char* s);
+};
 
 
-    // IOstream Operators
+// IOstream Operators
 
-        friend Istream& operator>>(Istream& is, keyType& kw);
-        friend Ostream& operator<<(Ostream& os, const keyType& kw);
-};
+//- Read operator
+Istream& operator>>(Istream& is, keyType& val);
+
+//- Write operator
+Ostream& operator<<(Ostream& os, const keyType& val);
 
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
diff --git a/src/OpenFOAM/primitives/strings/keyType/keyTypeI.H b/src/OpenFOAM/primitives/strings/keyType/keyTypeI.H
index 0ed0a205d48..0039ded58ac 100644
--- a/src/OpenFOAM/primitives/strings/keyType/keyTypeI.H
+++ b/src/OpenFOAM/primitives/strings/keyType/keyTypeI.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2017 OpenCFD Ltd.
+    \\  /    A nd           | Copyright (C) 2017-2019 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
                             | Copyright (C) 2011-2016 OpenFOAM Foundation
@@ -130,8 +130,40 @@ inline bool Foam::keyType::isPattern() const
 }
 
 
+inline bool Foam::keyType::compile()
+{
+    isPattern_ = true;
+    return true;
+}
+
+
+inline void Foam::keyType::uncompile(bool doStrip)
+{
+    // Only strip when debug is active (potentially costly operation)
+    if (isPattern_ && doStrip && word::debug)
+    {
+        string::stripInvalid<word>(*this);
+    }
+
+    isPattern_ = false;
+}
+
+
+inline void Foam::keyType::clear()
+{
+    word::clear();
+    isPattern_ = false;
+}
+
+
 inline void Foam::keyType::swap(keyType& s)
 {
+    // Self-swapping is a no-op
+    if (this == &s)
+    {
+        return;
+    }
+
     word::swap(static_cast<word&>(s));
     std::swap(isPattern_, s.isPattern_);
 }
@@ -147,6 +179,12 @@ inline bool Foam::keyType::operator()(const std::string& text) const
 
 inline void Foam::keyType::operator=(const keyType& s)
 {
+    // Self-assignment is a no-op
+    if (this == &s)
+    {
+        return;
+    }
+
     assign(s); // Bypasses char checking
     isPattern_ = s.isPattern_;
 }
@@ -154,6 +192,12 @@ inline void Foam::keyType::operator=(const keyType& s)
 
 inline void Foam::keyType::operator=(keyType&& s)
 {
+    // Self-assignment is a no-op
+    if (this == &s)
+    {
+        return;
+    }
+
     clear();
     swap(s);
 }
diff --git a/src/OpenFOAM/primitives/strings/lists/CStringList.H b/src/OpenFOAM/primitives/strings/lists/CStringList.H
index 649293c7a0f..6bb9d9f7efe 100644
--- a/src/OpenFOAM/primitives/strings/lists/CStringList.H
+++ b/src/OpenFOAM/primitives/strings/lists/CStringList.H
@@ -58,20 +58,16 @@ Description
 namespace Foam
 {
 
-// Forward declarations
-class Ostream;
-class CStringList;
+// Forward Declarations
 template<class String> class SubStrings;
 
-Ostream& operator<<(Ostream& os, const CStringList& list);
-
 /*---------------------------------------------------------------------------*\
                          Class CStringList Declaration
 \*---------------------------------------------------------------------------*/
 
 class CStringList
 {
-    // Private data
+    // Private Data
 
         //- Number of strings
         int argc_;
@@ -127,7 +123,7 @@ public:
         inline explicit CStringList(const SubStrings<StringType>& input);
 
 
-    //- Destructor
+    //- Destructor. Invokes clear() to free memory.
     inline ~CStringList();
 
 
@@ -196,13 +192,13 @@ public:
 
         //- Return element at the given index. No bounds checking.
         inline const char* operator[](int i) const;
+};
 
 
-    // IOstream Operators
-
-        friend Ostream& operator<<(Ostream& os, const CStringList& list);
+// IOstream Operators
 
-};
+//- Output space-separated list
+Ostream& operator<<(Ostream& os, const CStringList& list);
 
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
diff --git a/src/OpenFOAM/primitives/strings/lists/hashedWordList.H b/src/OpenFOAM/primitives/strings/lists/hashedWordList.H
index 67aff075ae5..cd401dbb5af 100644
--- a/src/OpenFOAM/primitives/strings/lists/hashedWordList.H
+++ b/src/OpenFOAM/primitives/strings/lists/hashedWordList.H
@@ -47,11 +47,6 @@ SourceFiles
 namespace Foam
 {
 
-// Forward declarations
-class hashedWordList;
-inline Istream& operator>>(Istream& is, hashedWordList& list);
-
-
 /*---------------------------------------------------------------------------*\
                        Class hashedWordList Declaration
 \*---------------------------------------------------------------------------*/
@@ -182,9 +177,6 @@ public:
         //- Move assignment from list of words. Rehashes the indices.
         inline void operator=(wordList&& list);
 
-        //- Read from an input stream. Rehashes the indices.
-        inline friend Istream& operator>>(Istream& is, hashedWordList& list);
-
 
     // Housekeeping
 
@@ -198,6 +190,10 @@ public:
 };
 
 
+//- Read from an input stream. Rehashes the indices.
+inline Istream& operator>>(Istream& is, hashedWordList& list);
+
+
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
 } // End namespace Foam
diff --git a/src/OpenFOAM/primitives/strings/string/string.H b/src/OpenFOAM/primitives/strings/string/string.H
index e7a101f7f43..e64e44061bf 100644
--- a/src/OpenFOAM/primitives/strings/string/string.H
+++ b/src/OpenFOAM/primitives/strings/string/string.H
@@ -63,13 +63,8 @@ namespace Foam
 // Forward Declarations
 class word;
 class wordRe;
-class string;
 class Istream;
 class Ostream;
-Istream& operator>>(Istream& is, string& s);
-Ostream& operator<<(Ostream& os, const string& s);
-Ostream& operator<<(Ostream& os, const std::string& s);
-
 
 /*---------------------------------------------------------------------------*\
                            Class string Declaration
@@ -294,18 +289,30 @@ public:
         bool endsWith(const std::string& text) const;
 
 
+    // Editing
+
+        //- Swap contents. Self-swapping is a no-op.
+        inline void swap(std::string& str);
+
+
     // Member Operators
 
         //- Test for equality. Allows use as a predicate.
         //  \return True when strings match literally.
         inline bool operator()(const std::string& text) const;
+};
 
 
-    // IOstream Operators
+// IOstream Operators
 
-        friend Istream& operator>>(Istream& is, string& s);
-        friend Ostream& operator<<(Ostream& os, const string& s);
-};
+//- Read operator
+Istream& operator>>(Istream& is, string& val);
+
+//- Write operator
+Ostream& operator<<(Ostream& os, const string& val);
+
+//- Write operator
+Ostream& operator<<(Ostream& os, const std::string& val);
 
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
diff --git a/src/OpenFOAM/primitives/strings/string/stringI.H b/src/OpenFOAM/primitives/strings/string/stringI.H
index 2cb9983654c..8d396d628a1 100644
--- a/src/OpenFOAM/primitives/strings/string/stringI.H
+++ b/src/OpenFOAM/primitives/strings/string/stringI.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2017-2018 OpenCFD Ltd.
+    \\  /    A nd           | Copyright (C) 2017-2019 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
                             | Copyright (C) 2011-2015 OpenFOAM Foundation
@@ -262,6 +262,16 @@ inline bool Foam::string::match(const std::string& text) const
 }
 
 
+inline void Foam::string::swap(std::string& str)
+{
+    // Self-swapping is a no-op
+    if (this != &str)
+    {
+        std::string::swap(str);
+    }
+}
+
+
 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
 
 inline bool Foam::string::operator()(const std::string& text) const
diff --git a/src/OpenFOAM/primitives/strings/string/stringIO.C b/src/OpenFOAM/primitives/strings/string/stringIO.C
index bff40cb3622..433fc19e909 100644
--- a/src/OpenFOAM/primitives/strings/string/stringIO.C
+++ b/src/OpenFOAM/primitives/strings/string/stringIO.C
@@ -70,17 +70,17 @@ Foam::Istream& Foam::operator>>(Istream& is, string& val)
 }
 
 
-Foam::Ostream& Foam::operator<<(Ostream& os, const string& s)
+Foam::Ostream& Foam::operator<<(Ostream& os, const string& val)
 {
-    os.write(s);
+    os.write(val);
     os.check(FUNCTION_NAME);
     return os;
 }
 
 
-Foam::Ostream& Foam::operator<<(Ostream& os, const std::string& s)
+Foam::Ostream& Foam::operator<<(Ostream& os, const std::string& val)
 {
-    os.write(string(s));
+    os.write(string(val));
     os.check(FUNCTION_NAME);
     return os;
 }
diff --git a/src/OpenFOAM/primitives/strings/word/word.H b/src/OpenFOAM/primitives/strings/word/word.H
index dcd1476b768..141b83a6df2 100644
--- a/src/OpenFOAM/primitives/strings/word/word.H
+++ b/src/OpenFOAM/primitives/strings/word/word.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2017-2018 OpenCFD Ltd.
+    \\  /    A nd           | Copyright (C) 2017-2019 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
                             | Copyright (C) 2011-2016 OpenFOAM Foundation
@@ -63,18 +63,14 @@ class word
 :
     public string
 {
-    // Private Member Functions
-
-        //- Strip invalid characters from this word
-        //  Trips an abort on invalid characters for debug 2 or greater
-        inline void stripInvalid();
-
-
 public:
 
-    // Static data members
+    // Static Data Members
 
+        //- The typeName
         static const char* const typeName;
+
+        //- Debugging
         static int debug;
 
         //- An empty word
@@ -136,7 +132,6 @@ public:
             const PrimitiveType& val
         );
 
-
         //- Is this character valid for a word?
         inline static bool valid(char c);
 
@@ -155,6 +150,10 @@ public:
             const bool prefix=false
         );
 
+        //- Strip invalid characters from this word
+        //  Trips an abort on invalid characters for debug 2 or greater
+        inline void stripInvalid();
+
 
     // File-like Functions
 
@@ -182,15 +181,17 @@ public:
         inline bool removeExt();
 
 
-    // Member operators
+    // Member Operators
 
     // Assignment
 
-        //- Copy assignment, no character validation required
-        word& operator=(const word&) = default;
+        //- Copy assignment, no character validation required.
+        //  Self-assignment is a no-op
+        inline word& operator=(const word& s);
 
         //- Move assignment, no character validation required
-        word& operator=(word&& w) = default;
+        //  Self-assignment is a no-op
+        inline word& operator=(word&& s);
 
         //- Copy assignment from Foam::string, stripping invalid characters
         inline word& operator=(const string& s);
@@ -206,13 +207,16 @@ public:
 
         //- Copy, stripping invalid characters
         inline word& operator=(const char* s);
+};
 
 
-    // IOstream operators
+// IOstream Operators
 
-        friend Istream& operator>>(Istream& is, word& w);
-        friend Ostream& operator<<(Ostream& os, const word& w);
-};
+//- Read operator
+Istream& operator>>(Istream& is, word& val);
+
+//- Write operator
+Ostream& operator<<(Ostream& os, const word& val);
 
 
 // * * * * * * * * * * * * * * Global Operators  * * * * * * * * * * * * * * //
diff --git a/src/OpenFOAM/primitives/strings/word/wordI.H b/src/OpenFOAM/primitives/strings/word/wordI.H
index fffc3ec3acd..c5749eb50eb 100644
--- a/src/OpenFOAM/primitives/strings/word/wordI.H
+++ b/src/OpenFOAM/primitives/strings/word/wordI.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2018 OpenCFD Ltd.
+    \\  /    A nd           | Copyright (C) 2018-2019 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
                             | Copyright (C) 2011-2017 OpenFOAM Foundation
@@ -56,28 +56,6 @@ inline Foam::word Foam::word::printf
 }
 
 
-// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
-
-inline void Foam::word::stripInvalid()
-{
-    // Skip stripping unless debug is active (to avoid costly operations)
-    if (debug && string::stripInvalid<word>(*this))
-    {
-        std::cerr
-            << "word::stripInvalid() called for word "
-            << this->c_str() << std::endl;
-
-        if (debug > 1)
-        {
-            std::cerr
-                << "    For debug level (= " << debug
-                << ") > 1 this is considered fatal" << std::endl;
-            std::abort();
-        }
-    }
-}
-
-
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
 inline Foam::word::word(const string& s, bool doStrip)
@@ -163,6 +141,26 @@ inline bool Foam::word::valid(char c)
 }
 
 
+inline void Foam::word::stripInvalid()
+{
+    // Only strip when debug is active (potentially costly operation)
+    if (debug && string::stripInvalid<word>(*this))
+    {
+        std::cerr
+            << "word::stripInvalid() called for word "
+            << this->c_str() << std::endl;
+
+        if (debug > 1)
+        {
+            std::cerr
+                << "    For debug level (= " << debug
+                << ") > 1 this is considered fatal" << std::endl;
+            std::abort();
+        }
+    }
+}
+
+
 inline bool Foam::word::hasExt() const
 {
     return string::hasExt();
@@ -177,6 +175,28 @@ inline bool Foam::word::removeExt()
 
 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
 
+inline Foam::word& Foam::word::operator=(const word& s)
+{
+    // Self-assignment is a no-op
+    if (this != &s)
+    {
+        assign(s);
+    }
+    return *this;
+}
+
+
+inline Foam::word& Foam::word::operator=(word&& s)
+{
+    // Self-assignment is a no-op
+    if (this != &s)
+    {
+        assign(std::move(s));
+    }
+    return *this;
+}
+
+
 inline Foam::word& Foam::word::operator=(const string& s)
 {
     assign(s);
diff --git a/src/OpenFOAM/primitives/strings/word/wordIO.C b/src/OpenFOAM/primitives/strings/word/wordIO.C
index 597cad5fd26..370c0cc0ef7 100644
--- a/src/OpenFOAM/primitives/strings/word/wordIO.C
+++ b/src/OpenFOAM/primitives/strings/word/wordIO.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2018 OpenCFD Ltd.
+    \\  /    A nd           | Copyright (C) 2018-2019 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
                             | Copyright (C) 2011-2015 OpenFOAM Foundation
@@ -87,9 +87,9 @@ Foam::Istream& Foam::operator>>(Istream& is, word& val)
 }
 
 
-Foam::Ostream& Foam::operator<<(Ostream& os, const word& w)
+Foam::Ostream& Foam::operator<<(Ostream& os, const word& val)
 {
-    os.write(w);
+    os.write(val);
     os.check(FUNCTION_NAME);
     return os;
 }
diff --git a/src/OpenFOAM/primitives/strings/wordRe/wordRe.C b/src/OpenFOAM/primitives/strings/wordRe/wordRe.C
index 228a68edf73..ef0c70fa3b6 100644
--- a/src/OpenFOAM/primitives/strings/wordRe/wordRe.C
+++ b/src/OpenFOAM/primitives/strings/wordRe/wordRe.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2018 OpenCFD Ltd.
+    \\  /    A nd           | Copyright (C) 2018-2019 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
                             | Copyright (C) 2011-2016 OpenFOAM Foundation
@@ -47,6 +47,21 @@ Foam::wordRe::wordRe(Istream& is)
 
 // * * * * * * * * * * * * * * * IOstream Operators  * * * * * * * * * * * * //
 
+Foam::Ostream& Foam::wordRe::info(Ostream& os) const
+{
+    if (isPattern())
+    {
+        os  << "wordRe(regex) " << *this;
+    }
+    else
+    {
+        os  << "wordRe(plain) \"" << *this << '"';
+    }
+
+    return os;
+}
+
+
 Foam::Istream& Foam::operator>>(Istream& is, wordRe& val)
 {
     token t(is);
@@ -94,27 +109,12 @@ Foam::Istream& Foam::operator>>(Istream& is, wordRe& val)
 }
 
 
-Foam::Ostream& Foam::operator<<(Ostream& os, const wordRe& w)
+Foam::Ostream& Foam::operator<<(Ostream& os, const wordRe& val)
 {
-    os.writeQuoted(w, w.isPattern());
+    os.writeQuoted(val, val.isPattern());
     os.check(FUNCTION_NAME);
     return os;
 }
 
 
-Foam::Ostream& Foam::wordRe::info(Ostream& os) const
-{
-    if (isPattern())
-    {
-        os  << "wordRe(regex) " << *this;
-    }
-    else
-    {
-        os  << "wordRe(plain) \"" << *this << '"';
-    }
-
-    return os;
-}
-
-
 // ************************************************************************* //
diff --git a/src/OpenFOAM/primitives/strings/wordRe/wordRe.H b/src/OpenFOAM/primitives/strings/wordRe/wordRe.H
index e681a1570ca..50496ec98a4 100644
--- a/src/OpenFOAM/primitives/strings/wordRe/wordRe.H
+++ b/src/OpenFOAM/primitives/strings/wordRe/wordRe.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2017-2018 OpenCFD Ltd.
+    \\  /    A nd           | Copyright (C) 2017-2019 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
                             | Copyright (C) 2011-2016 OpenFOAM Foundation
@@ -61,15 +61,10 @@ SourceFiles
 namespace Foam
 {
 
-// Forward declarations
-class wordRe;
+// Forward Declarations
 class Istream;
 class Ostream;
 
-Istream& operator>>(Istream& is, wordRe& w);
-Ostream& operator<<(Ostream& os, const wordRe& w);
-
-
 /*---------------------------------------------------------------------------*\
                            Class wordRe Declaration
 \*---------------------------------------------------------------------------*/
@@ -78,21 +73,21 @@ class wordRe
 :
     public word
 {
-    // Private member data
+    // Private Member Data
 
         //- The regular expression
-        mutable regExp re_;
+        regExp re_;
 
 
 public:
 
-    // Static data members
+    // Static Data Members
 
         //- An empty wordRe
         static const wordRe null;
 
 
-    // Public data types
+    // Public Data Types
 
         //- Enumeration with compile options
         //  Note that 'REGEX' is implicit if 'ICASE' is specified alone.
@@ -109,18 +104,6 @@ public:
         };
 
 
-        //- Is this a meta character?
-        inline static bool meta(const char c);
-
-        //- Is this character valid for a wordRe?
-        //  This is largely identical with what word accepts, but also
-        //  permit brace-brackets, which are valid for some regexs.
-        inline static bool valid(char c);
-
-        //- Test string for regular expression meta characters
-        inline static bool isPattern(const std::string& str);
-
-
     // Constructors
 
         //- Construct null
@@ -169,9 +152,21 @@ public:
 
     // Member Functions
 
+        //- Is this a meta character?
+        inline static bool meta(char c);
+
+        //- Is this character valid for a wordRe?
+        //  This is largely identical with what word accepts, but also
+        //  permit brace-brackets, which are valid for some regexs.
+        inline static bool valid(char c);
+
+        //- Test string for regular expression meta characters
+        inline static bool isPattern(const std::string& str);
+
+
     // Access
 
-        //- The wordRe is treated as literal, not as pattern.
+        //- The wordRe is treated as literal string, not as pattern.
         inline bool isLiteral() const;
 
         //- The wordRe is treated as a pattern, not as literal string.
@@ -181,14 +176,14 @@ public:
     // Infrastructure
 
         //- Compile the regular expression
-        inline bool compile() const;
+        inline bool compile();
 
         //- Possibly compile the regular expression, with greater control
-        inline bool compile(const compOption opt) const;
+        inline bool compile(const compOption opt);
 
         //- Make wordRe a literal again, instead of a regular expression.
         //  Optionally strip invalid word characters.
-        inline void uncompile(bool doStrip = false) const;
+        inline void uncompile(bool doStrip = false);
 
 
     // Editing
@@ -202,7 +197,7 @@ public:
         //- Clear string and regular expression
         inline void clear();
 
-        //- Swap contents
+        //- Swap contents. Self-swapping is a no-op
         inline void swap(wordRe& str);
 
 
@@ -230,6 +225,7 @@ public:
 
 
         //- Copy assignment, retaining type (literal or regex)
+        //  Self-assignment is a no-op.
         inline void operator=(const wordRe& str);
 
         //- Copy word, never a regular expression
@@ -252,14 +248,18 @@ public:
         inline void operator=(const char* str);
 
         //- Move assignment.
+        //  Self-assignment is a no-op.
         inline void operator=(wordRe&& str);
+};
 
 
-    // IOstream Operators
+// IOstream Operators
 
-        friend Istream& operator>>(Istream& is, wordRe& w);
-        friend Ostream& operator<<(Ostream& os, const wordRe& w);
-};
+//- Read operator
+Istream& operator>>(Istream& is, wordRe& val);
+
+//- Write operator
+Ostream& operator<<(Ostream& os, const wordRe& val);
 
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
diff --git a/src/OpenFOAM/primitives/strings/wordRe/wordReI.H b/src/OpenFOAM/primitives/strings/wordRe/wordReI.H
index 1223382443f..02a5df8943d 100644
--- a/src/OpenFOAM/primitives/strings/wordRe/wordReI.H
+++ b/src/OpenFOAM/primitives/strings/wordRe/wordReI.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2017-2018 OpenCFD Ltd.
+    \\  /    A nd           | Copyright (C) 2017-2019 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
                             | Copyright (C) 2011-2016 OpenFOAM Foundation
@@ -27,7 +27,7 @@ License
 
 // * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * //
 
-inline bool Foam::wordRe::meta(const char c)
+inline bool Foam::wordRe::meta(char c)
 {
     return regExp::meta(c);
 }
@@ -171,7 +171,7 @@ inline bool Foam::wordRe::isPattern() const
 }
 
 
-inline bool Foam::wordRe::compile(const compOption opt) const
+inline bool Foam::wordRe::compile(const compOption opt)
 {
     if (opt)
     {
@@ -202,24 +202,18 @@ inline bool Foam::wordRe::compile(const compOption opt) const
 }
 
 
-inline bool Foam::wordRe::compile() const
+inline bool Foam::wordRe::compile()
 {
     return re_.set(*this);
 }
 
 
-inline void Foam::wordRe::uncompile(bool doStrip) const
+inline void Foam::wordRe::uncompile(bool doStrip)
 {
-    if (re_.clear() && doStrip)
+    // Only strip when debug is active (potentially costly operation)
+    if (re_.clear() && doStrip && word::debug)
     {
-        // Skip stripping unless debug is active to avoid costly operations
-        if (word::debug)
-        {
-            string::stripInvalid<word>
-            (
-                const_cast<word&>(static_cast<const word&>(*this))
-            );
-        }
+        string::stripInvalid<word>(*this);
     }
 }
 
@@ -264,6 +258,12 @@ inline void Foam::wordRe::set(const char* str, const compOption opt)
 
 inline void Foam::wordRe::swap(wordRe& str)
 {
+    // Self-swapping is a no-op
+    if (this == &str)
+    {
+        return;
+    }
+
     word::swap(static_cast<word&>(str));
     re_.swap(str.re_);
 }
@@ -279,6 +279,12 @@ inline bool Foam::wordRe::operator()(const std::string& text) const
 
 inline void Foam::wordRe::operator=(const wordRe& str)
 {
+    // Self-assignment is a no-op
+    if (this == &str)
+    {
+        return;
+    }
+
     assign(str);
     if (str.isPattern())
     {
@@ -335,6 +341,12 @@ inline void Foam::wordRe::operator=(const char* str)
 
 inline void Foam::wordRe::operator=(wordRe&& str)
 {
+    // Self-assignment is a no-op
+    if (this == &str)
+    {
+        return;
+    }
+
     clear();
     swap(str);
 }
diff --git a/src/fileFormats/ensight/name/ensightFileName.H b/src/fileFormats/ensight/name/ensightFileName.H
index 57971ad6a03..0be0e17e0db 100644
--- a/src/fileFormats/ensight/name/ensightFileName.H
+++ b/src/fileFormats/ensight/name/ensightFileName.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2016 OpenCFD Ltd.
+    \\  /    A nd           | Copyright (C) 2016-2019 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -56,11 +56,6 @@ class FileName
 :
     public fileName
 {
-    // Private Member Functions
-
-        //- Strip invalid characters
-        inline void stripInvalid();
-
 public:
 
     // Constructors
@@ -80,6 +75,9 @@ public:
         //- Is this character valid for an ensight file-name
         inline static bool valid(char c);
 
+        //- Strip invalid characters
+        inline void stripInvalid();
+
 
     // Member Operators
 
diff --git a/src/fileFormats/ensight/name/ensightFileNameI.H b/src/fileFormats/ensight/name/ensightFileNameI.H
index 495ca6df006..d7243bd27f4 100644
--- a/src/fileFormats/ensight/name/ensightFileNameI.H
+++ b/src/fileFormats/ensight/name/ensightFileNameI.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2016 OpenCFD Ltd.
+    \\  /    A nd           | Copyright (C) 2016-2019 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -53,6 +53,17 @@ inline Foam::ensight::FileName::FileName(const std::string& s)
 
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
+inline bool Foam::ensight::FileName::valid(char c)
+{
+    return
+    (
+        fileName::valid(c)  // includes space, quotes
+     && c != '*'   // wild-card
+     && c != '%'   // structured block continuation
+    );
+}
+
+
 inline void Foam::ensight::FileName::stripInvalid()
 {
     string::stripInvalid<FileName>(*this);
@@ -69,15 +80,4 @@ inline void Foam::ensight::FileName::stripInvalid()
 }
 
 
-inline bool Foam::ensight::FileName::valid(char c)
-{
-    return
-    (
-        fileName::valid(c)  // includes space, quotes
-     && c != '*'   // wild-card
-     && c != '%'   // structured block continuation
-    );
-}
-
-
 // ************************************************************************* //
diff --git a/src/fileFormats/ensight/name/ensightVarName.H b/src/fileFormats/ensight/name/ensightVarName.H
index 4158240ef62..51d6a17565b 100644
--- a/src/fileFormats/ensight/name/ensightVarName.H
+++ b/src/fileFormats/ensight/name/ensightVarName.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2016 OpenCFD Ltd.
+    \\  /    A nd           | Copyright (C) 2016-2019 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -58,11 +58,6 @@ class VarName
 :
     public word
 {
-    // Private Member Functions
-
-        //- Strip invalid characters
-        inline void stripInvalid();
-
 public:
 
     // Constructors
@@ -82,6 +77,9 @@ public:
         //- Is this character valid for an ensight var-name
         inline static bool valid(char c);
 
+        //- Strip invalid characters
+        inline void stripInvalid();
+
 
     // Member Operators
 
diff --git a/src/fileFormats/ensight/name/ensightVarNameI.H b/src/fileFormats/ensight/name/ensightVarNameI.H
index 17bec6125a7..f36ad2102ae 100644
--- a/src/fileFormats/ensight/name/ensightVarNameI.H
+++ b/src/fileFormats/ensight/name/ensightVarNameI.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2016 OpenCFD Ltd.
+    \\  /    A nd           | Copyright (C) 2016-2019 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -51,29 +51,8 @@ inline Foam::ensight::VarName::VarName(const std::string& s)
 }
 
 
-
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
-inline void Foam::ensight::VarName::stripInvalid()
-{
-    string::stripInvalid<VarName>(*this);
-
-    if (empty())
-    {
-        FatalErrorInFunction
-            << "ensight::VarName empty after stripping" << nl
-            << exit(FatalError);
-    }
-
-    // prefix with '_' to avoid starting with leading digits
-    std::string::iterator iter = begin();
-    if (isdigit(*iter))
-    {
-        insert(iter, '_');
-    }
-}
-
-
 inline bool Foam::ensight::VarName::valid(char c)
 {
     return
@@ -97,4 +76,24 @@ inline bool Foam::ensight::VarName::valid(char c)
 }
 
 
+inline void Foam::ensight::VarName::stripInvalid()
+{
+    string::stripInvalid<VarName>(*this);
+
+    if (empty())
+    {
+        FatalErrorInFunction
+            << "ensight::VarName empty after stripping" << nl
+            << exit(FatalError);
+    }
+
+    // Prefix with '_' to avoid starting with leading digits
+    std::string::iterator iter = begin();
+    if (isdigit(*iter))
+    {
+        insert(iter, '_');
+    }
+}
+
+
 // ************************************************************************* //
-- 
GitLab