From 2d246cd5d1d17d7f5d812fc9fd7628333c77b44d Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 12 Mar 2025 16:33:40 +0100 Subject: [PATCH] ENH: add token::read(Istream&) method - can be used to simplify some logic. For example, if ( (tok.read(is) && tok.isWord("FoamFile")) && (tok.read(is) && tok.isPunctuation(token::BEGIN_BLOCK)) ) ... vs if ( (is.good() && (is >> tok) && tok.isWord("FoamFile")) ... && (is.good() && (is >> tok) && tok.isPunctuation(token::BEGIN_BLOCK)) ) ... --- applications/test/ITstream/Test-ITstream.cxx | 20 ++--- src/OpenFOAM/db/IOstreams/token/token.H | 5 ++ src/OpenFOAM/db/IOstreams/token/tokenIO.C | 15 +++- src/OpenFOAM/expressions/value/exprValue.C | 79 +++++++++----------- 4 files changed, 65 insertions(+), 54 deletions(-) diff --git a/applications/test/ITstream/Test-ITstream.cxx b/applications/test/ITstream/Test-ITstream.cxx index 3e239ede7e..6aa034b04a 100644 --- a/applications/test/ITstream/Test-ITstream.cxx +++ b/applications/test/ITstream/Test-ITstream.cxx @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2017-2023 OpenCFD Ltd. + Copyright (C) 2017-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -74,15 +74,11 @@ Ostream& toString(Ostream& os, const List& list) void printTokens(Istream& is) { label count = 0; - token t; - while (is.good()) + + Info<< "stream tokens:" << endl; + for (token tok; tok.read(is); ++count) { - is >> t; - if (t.good()) - { - ++count; - Info<< "token: " << t << endl; - } + Info<< " : " << tok << endl; } Info<< count << " tokens" << endl; @@ -455,6 +451,12 @@ int main(int argc, char *argv[]) "( const char input \"string\" to tokenize )\n" "List