From 12e55d7d97420ff246e5529326235e74d32e8a92 Mon Sep 17 00:00:00 2001
From: andy <andy>
Date: Mon, 28 Jan 2013 16:43:17 +0000
Subject: [PATCH] ENH: Added helper function to create appropriate graph name
 from string

---
 src/OpenFOAM/graph/graph.C | 21 ++++++++++++++++++---
 src/OpenFOAM/graph/graph.H |  5 ++++-
 2 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/src/OpenFOAM/graph/graph.C b/src/OpenFOAM/graph/graph.C
index 7c59cfc2f69..0ec122dcc32 100644
--- a/src/OpenFOAM/graph/graph.C
+++ b/src/OpenFOAM/graph/graph.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011-2012 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2011-2013 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -41,6 +41,17 @@ namespace Foam
 
 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
 
+Foam::word Foam::graph::wordify(const Foam::string& sname)
+{
+    string wname = sname;
+    wname.replace(' ', '_');
+    wname.replace('(', '_');
+    wname.replace(')', "");
+
+    return word(wname);
+}
+
+
 void Foam::graph::readCurves(Istream& is)
 {
     List<xy> xyData(is);
@@ -54,7 +65,11 @@ void Foam::graph::readCurves(Istream& is)
         y[i] = xyData[i].y_;
     }
 
-    insert(yName_, new curve(yName_, curve::curveStyle::CONTINUOUS, y));
+    insert
+    (
+        wordify(yName_),
+        new curve(wordify(yName_), curve::curveStyle::CONTINUOUS, y)
+    );
 }
 
 
@@ -89,7 +104,7 @@ Foam::graph::graph
     yName_(yName),
     x_(x)
 {
-    insert(yName, new curve(yName, curve::curveStyle::CONTINUOUS, y));
+    insert(wordify(yName), new curve(yName, curve::curveStyle::CONTINUOUS, y));
 }
 
 
diff --git a/src/OpenFOAM/graph/graph.H b/src/OpenFOAM/graph/graph.H
index 2a414980618..b3ff00c37d5 100644
--- a/src/OpenFOAM/graph/graph.H
+++ b/src/OpenFOAM/graph/graph.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2011-2013 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -263,6 +263,9 @@ public:
                 const word& format
             ) const;
 
+            //- Helper function to convert string name into appropriate word
+            static word wordify(const string& sname);
+
 
     // Friend operators
 
-- 
GitLab