From 497ec32ed86fedb6d87403597968bf686343f716 Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@Germany>
Date: Fri, 11 Dec 2009 17:31:15 +0100
Subject: [PATCH] Add missing low-level peek() to ISstream.

---
 applications/test/tokenizeTest/tokenizeTest.C  | 8 +++++++-
 src/OpenFOAM/db/IOstreams/Sstreams/ISstream.H  | 6 ++++++
 src/OpenFOAM/db/IOstreams/Sstreams/ISstreamI.H | 6 ++++++
 3 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/applications/test/tokenizeTest/tokenizeTest.C b/applications/test/tokenizeTest/tokenizeTest.C
index cd80997f61d..c8be29cbf35 100644
--- a/applications/test/tokenizeTest/tokenizeTest.C
+++ b/applications/test/tokenizeTest/tokenizeTest.C
@@ -67,9 +67,15 @@ int main(int argc, char *argv[])
             while (is.good())
             {
                 token tok(is);
+                // char ch;
+                // is.get(ch);
+                // is.putback(ch);
+                int lookahead = is.peek();
+
                 if (count == 0)
                 {
-                    Info<< "token: " << tok.info() << endl;
+                    Info<< "token: " << tok.info();
+                    Info<< "  lookahead: '" << char(lookahead) << "'" << endl;
                 }
             }
 
diff --git a/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.H b/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.H
index fe778fa0103..0c6bc9d44be 100644
--- a/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.H
+++ b/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.H
@@ -137,6 +137,12 @@ public:
             //- Raw, low-level get character function.
             inline ISstream& get(char&);
 
+            //- Raw, low-level peek function.
+            //  Does not remove the character from the stream.
+            //  Returns the next character in the stream or EOF if the
+            //  end of file is read.
+            inline int peek();
+
             //- Raw, low-level getline into a string function.
             inline ISstream& getLine(string&);
 
diff --git a/src/OpenFOAM/db/IOstreams/Sstreams/ISstreamI.H b/src/OpenFOAM/db/IOstreams/Sstreams/ISstreamI.H
index 1fedf762296..63b1087547f 100644
--- a/src/OpenFOAM/db/IOstreams/Sstreams/ISstreamI.H
+++ b/src/OpenFOAM/db/IOstreams/Sstreams/ISstreamI.H
@@ -69,6 +69,12 @@ inline Foam::ISstream& Foam::ISstream::get(char& c)
 }
 
 
+inline int Foam::ISstream::peek()
+{
+    return is_.peek();
+}
+
+
 inline Foam::ISstream& Foam::ISstream::getLine(string& s)
 {
     getline(is_, s);
-- 
GitLab