new wordRe class - a word that holds a regExp

- a possible future replacement for keyType, but the immediate use is the
    wordReList for grepping through other lists.
  - note that the argList treatment of '(' ... ')' yields quoted strings,
    which we can use for building a wordReList

minor cleanup of regExp class

  - constructor from std::string, match std::string and
    operator=(std::string&)
    rely on automatic conversion to Foam::string
  - ditch partialMatch with sub-groups, it doesn't make much sense
This commit is contained in:
Mark Olesen
2009-01-04 00:33:27 +01:00
parent 1d866d7fe8
commit 2717aa5c7d
19 changed files with 1036 additions and 182 deletions

View File

@ -40,6 +40,25 @@ int main(int argc, char *argv[])
Info<< test << endl;
// test sub-strings via iterators
string::const_iterator iter = test.end();
string::const_iterator iter2 = test.end();
string::size_type fnd = test.find('\\');
if (fnd != string::npos)
{
iter = test.begin() + fnd;
iter2 = iter + 6;
}
Info<< "sub-string via iterators : >";
while (iter != iter2)
{
Info<< *iter;
iter++;
}
Info<< "<\n";
Info<< string(test).replace("kj", "zzz") << endl;
Info<< string(test).replace("kj", "") << endl;
Info<< string(test).replaceAll("kj", "zzz") << endl;

View File

@ -0,0 +1,3 @@
wordReTest.C
EXE = $(FOAM_USER_APPBIN)/wordReTest

View File

View File

@ -0,0 +1,32 @@
/*-------------------------------*- C++ -*---------------------------------*\
| ========= |
| \\ / OpenFOAM |
| \\ / |
| \\ / The Open Source CFD Toolbox |
| \\/ http://www.OpenFOAM.org |
\*-------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// wordRe, string
(
( "a.*" "abc" )
( "a.*" "bac" )
( "a.*" "abcd" )
( "a.*" "def" )
( "d(.*)f" "def" )
( "plain" "def" )
( "plain" "def" )
( "plain\\(0\\)" "def" )
( "plain\(0\)" "ghi" )
( "regex(0)" "ghi" )
( "plain\\\(0\\\)" "ghi" )
( "this" "def" )
( "this" "this" )
( plain\\(0\\) "def" )
( plain\(0\) "ghi" )
( plain\\\(0\\\) "ghi" )
( "done" "done" )
)
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -0,0 +1,105 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
\*---------------------------------------------------------------------------*/
#include "IOstreams.H"
#include "IOobject.H"
#include "IFstream.H"
#include "List.H"
#include "Tuple2.H"
#include "wordRe.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
wordRe wre;
std::string s1("this .* file");
Foam::string s2("this .* file");
const char * s3 = "this .* file";
Info<< wordRe(s1).info() << endl;
Info<< wordRe(s2, false).info() << endl;
Info<< wordRe(s2).info() << endl;
Info<< wordRe(s3, true).info() << endl;
wre = "this .* file";
Info<< wre.info() << endl;
wre = s1;
Info<< wre.info() << endl;
wre.uncompile();
Info<< wre.info() << " uncompiled" << endl;
wre = "something";
Info<< wre.info() << " before" << endl;
wre.uncompile();
Info<< wre.info() << " uncompiled" << endl;
wre.compile(true);
Info<< wre.info() << " after auto-detect" << endl;
wre = "something .* value";
Info<< wre.info() << " before" << endl;
wre.uncompile();
Info<< wre.info() << " uncompiled" << endl;
wre.compile(true);
Info<< wre.info() << " after auto-detect" << endl;
wre.uncompile();
Info<< wre.info() << " uncompiled" << endl;
wre.recompile();
Info<< wre.info() << " recompiled" << endl;
IOobject::writeDivider(Info);
List<Tuple2<wordRe, string> > rawList(IFstream("testRegexps")());
Info<< "input list:" << rawList << endl;
IOobject::writeDivider(Info);
Info<< endl;
forAll(rawList, elemI)
{
const wordRe& wre = rawList[elemI].first();
const string& str = rawList[elemI].second();
Info<< wre.info()
<< " equals:" << (wre == str)
<< "(" << wre.match(str, true) << ")"
<< " match:" << wre.match(str)
<< " str=" << str
<< endl;
}
Info<< endl;
return 0;
}
// ************************************************************************* //