diff --git a/applications/test/ITstream/Make/files b/applications/test/ITstream/Make/files new file mode 100644 index 0000000000..6b70c4ea83 --- /dev/null +++ b/applications/test/ITstream/Make/files @@ -0,0 +1,3 @@ +Test-ITstream.C + +EXE = $(FOAM_USER_APPBIN)/Test-ITstream diff --git a/applications/test/ITstream/Make/options b/applications/test/ITstream/Make/options new file mode 100644 index 0000000000..18e6fe47af --- /dev/null +++ b/applications/test/ITstream/Make/options @@ -0,0 +1,2 @@ +/* EXE_INC = */ +/* EXE_LIBS = */ diff --git a/applications/test/ITstream/Test-ITstream.C b/applications/test/ITstream/Test-ITstream.C new file mode 100644 index 0000000000..a81e8585ee --- /dev/null +++ b/applications/test/ITstream/Test-ITstream.C @@ -0,0 +1,137 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Description + +\*---------------------------------------------------------------------------*/ + +#include "ListStream.H" +#include "UListStream.H" +#include "wordList.H" +#include "IOstreams.H" +#include "argList.H" +#include "ITstream.H" + +using namespace Foam; + +template +Ostream& toString(Ostream& os, const T& str) +{ + os << str; + return os; +} + + +template<> +Ostream& toString(Ostream& os, const UList& list) +{ + for (const char c : list) + { + os << c; + } + + return os; +} + + +template<> +Ostream& toString(Ostream& os, const List& list) +{ + for (const char c : list) + { + os << c; + } + + return os; +} + + +void printTokens(Istream& is) +{ + label count = 0; + token t; + while (is.good()) + { + is >> t; + if (t.good()) + { + ++count; + Info<<"token: " << t << endl; + } + } + + Info<< count << " tokens" << endl; +} + + +template +void doTest(const string& name, const BUF& input, bool verbose=false) +{ + Info<<"test " << name.c_str() << ":" << nl + <<"====" << nl; + toString(Info, input) + << nl + <<"====" << nl << endl; + + ITstream its(name, input); + Info<< "got " << its.size() << " tokens - index at " + << its.tokenIndex() << endl; + + if (verbose) + { + for (const token& tok : its) + { + Info<< " " << tok.info() << nl; + } + Info<< nl; + } +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// Main program: + +int main(int argc, char *argv[]) +{ + const char* charInput = + "( const char input \"string\" to tokenize )" + "List