diff --git a/applications/test/string/Test-string.C b/applications/test/string/Test-string.C
index 8fd98245d956cbf2e50889ab3feadfd43a9ffba7..9b8e1688eb036a99ef8450917c65f1406059d934 100644
--- a/applications/test/string/Test-string.C
+++ b/applications/test/string/Test-string.C
@@ -70,7 +70,7 @@ int main(int argc, char *argv[])
         " $(DONOTSUBST) some other <${USER}> with '${__UNKNOWN:-some default}'"
         " value "
         " or with '${HOME:+Home was set}' via :+ alternative"
-        " or with '${__UNKNOWN:+unknown}' empty"
+        " or with '${__UNKNOWN:+unknown}' empty  "
     );
 
     setEnv("FOAM_CASE", cwd(), true);
diff --git a/src/OpenFOAM/primitives/strings/stringOps/stringOps.C b/src/OpenFOAM/primitives/strings/stringOps/stringOps.C
index 21479555c325df8e94fdb2e02735c49a256f406c..1515c5191d9fbbb198709d8abed9338bd7ba29c2 100644
--- a/src/OpenFOAM/primitives/strings/stringOps/stringOps.C
+++ b/src/OpenFOAM/primitives/strings/stringOps/stringOps.C
@@ -742,12 +742,12 @@ std::string::size_type Foam::stringOps::count(const char* str, const char c)
 
 Foam::string Foam::stringOps::expand
 (
-    const std::string& original,
+    const std::string& str,
     const HashTable<string, word, string::hash>& mapping,
     const char sigil
 )
 {
-    string s(original);
+    string s(str);
     inplaceExpand(s, mapping);
     return s;
 }
@@ -877,12 +877,12 @@ void Foam::stringOps::inplaceExpand
 
 Foam::string Foam::stringOps::expand
 (
-    const std::string& original,
+    const std::string& str,
     const dictionary& dict,
     const char sigil
 )
 {
-    string s(original);
+    string s(str);
     inplaceExpand(s, dict, sigil);
     return s;
 }
@@ -917,11 +917,11 @@ void Foam::stringOps::inplaceExpand
 
 Foam::string Foam::stringOps::expand
 (
-    const std::string& original,
+    const std::string& str,
     const bool allowEmpty
 )
 {
-    string s(original);
+    string s(str);
     inplaceExpand(s, allowEmpty);
     return s;
 }
@@ -1036,11 +1036,24 @@ void Foam::stringOps::inplaceTrimRight(std::string& s)
 }
 
 
-Foam::string Foam::stringOps::trim(const std::string& original)
+Foam::string Foam::stringOps::trim(const std::string& str)
 {
-    string s(original);
-    inplaceTrim(s);
-    return s;
+    std::string::size_type beg = 0;
+    std::string::size_type end = str.size();
+
+    // Right
+    while (beg < end && std::isspace(str[end-1]))
+    {
+        --end;
+    }
+
+    // Left
+    while (beg < end && std::isspace(str[beg]))
+    {
+        ++beg;
+    }
+
+    return str.substr(beg, end-beg);
 }
 
 
@@ -1051,9 +1064,9 @@ void Foam::stringOps::inplaceTrim(std::string& s)
 }
 
 
-Foam::string Foam::stringOps::removeComments(const std::string& original)
+Foam::string Foam::stringOps::removeComments(const std::string& str)
 {
-    string s(original);
+    string s(str);
     inplaceRemoveComments(s);
     return s;
 }
@@ -1135,9 +1148,9 @@ void Foam::stringOps::inplaceRemoveComments(std::string& s)
 }
 
 
-Foam::string Foam::stringOps::lower(const std::string& original)
+Foam::string Foam::stringOps::lower(const std::string& str)
 {
-    string s(original);
+    string s(str);
     inplaceLower(s);
     return s;
 }
@@ -1155,9 +1168,9 @@ void Foam::stringOps::inplaceLower(std::string& s)
 }
 
 
-Foam::string Foam::stringOps::upper(const std::string& original)
+Foam::string Foam::stringOps::upper(const std::string& str)
 {
-    string s(original);
+    string s(str);
     inplaceUpper(s);
     return s;
 }
diff --git a/src/OpenFOAM/primitives/strings/stringOps/stringOps.H b/src/OpenFOAM/primitives/strings/stringOps/stringOps.H
index a357f8a169e3f58adabca2b5f12a8e0a52a1b0f5..11167b02f0b86ea75b90344e7b4db1fb9988a385 100644
--- a/src/OpenFOAM/primitives/strings/stringOps/stringOps.H
+++ b/src/OpenFOAM/primitives/strings/stringOps/stringOps.H
@@ -83,7 +83,7 @@ namespace stringOps
     //  \sa stringOps::inplaceExpand() for details
     string expand
     (
-        const std::string& original,
+        const std::string& str,
         const HashTable<string, word, string::hash>& mapping,
         const char sigil = '$'
     );
@@ -206,7 +206,7 @@ namespace stringOps
     //  \sa stringOps::inplaceExpand(std::string&, const dictionary&, char)
     string expand
     (
-        const std::string& original,
+        const std::string& str,
         const dictionary& dict,
         const char sigil = '$'
     );
@@ -232,7 +232,7 @@ namespace stringOps
     //  stringOps::inplaceExpand(std::string&, bool);
     string expand
     (
-        const std::string& original,
+        const std::string& str,
         const bool allowEmpty = false
     );
 
@@ -271,27 +271,27 @@ namespace stringOps
     void inplaceTrimRight(std::string& s);
 
     //- Return string trimmed of leading and trailing whitespace
-    string trim(const std::string& original);
+    string trim(const std::string& str);
 
     //- Trim leading and trailing whitespace inplace
     void inplaceTrim(std::string& s);
 
 
     //- Return string with C/C++ comments removed
-    string removeComments(const std::string& original);
+    string removeComments(const std::string& str);
 
     //- Remove C/C++ comments inplace
     void inplaceRemoveComments(std::string& s);
 
 
     //- Return string transformed with std::tolower on each character
-    string lower(const std::string& original);
+    string lower(const std::string& str);
 
     //- Inplace transform string with std::tolower on each character
     void inplaceLower(std::string& s);
 
     //- Return string transformed with std::toupper on each character
-    string upper(const std::string& original);
+    string upper(const std::string& str);
 
     //- Inplace transform string with std::toupper on each character
     void inplaceUpper(std::string& s);