From ec38e7a408682d26f5c858637400412387987aff Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 22 Feb 2018 09:28:03 +0100 Subject: [PATCH] ENH: prevent conversion of string to regExp in stringListOps (closes #739) * For most cases, this conversion would be largely unintentional and also less efficient. If the regex is desirable, the caller should invoke it explicitly. For example, findStrings(regExp(str), listOfStrings); Or use one of the keyType, wordRe, wordRes variants instead. If string is to be used as a plain (non-regex) matcher, this can be directly invoked findMatchingStrings(str, listOfStrings); or using the ListOps instead: findIndices(listOfStrings, str); * provide function interfaces for keyType. --- .../test/stringList/Test-stringList.C | 6 +- .../changeDictionary/changeDictionary.C | 9 +- .../surface/surfacePatch/surfacePatch.C | 1 + .../polyBoundaryMesh/polyBoundaryMesh.C | 113 +++++++------- .../meshes/polyMesh/zones/ZoneMesh/ZoneMesh.C | 63 ++++---- .../primitives/strings/lists/stringListOps.H | 146 ++++++++++++------ src/conversion/ensight/mesh/ensightMesh.C | 12 +- .../faMesh/faBoundaryMesh/faBoundaryMesh.C | 33 ++-- .../ParticleErosion/ParticleErosion.C | 27 ++-- .../ParticleErosion/ParticleErosion.H | 2 +- .../PatchPostProcessing/PatchPostProcessing.C | 32 ++-- .../PatchPostProcessing/PatchPostProcessing.H | 2 +- .../patchInteractionDataList.C | 8 +- .../coordinateSystems/coordinateSystems.C | 26 ++-- .../triSurfaceLoader/triSurfaceLoader.C | 8 +- .../curvatureSeparation/curvatureSeparation.C | 2 +- 16 files changed, 264 insertions(+), 226 deletions(-) diff --git a/applications/test/stringList/Test-stringList.C b/applications/test/stringList/Test-stringList.C index 60db8cfc7c..0ed3416202 100644 --- a/applications/test/stringList/Test-stringList.C +++ b/applications/test/stringList/Test-stringList.C @@ -53,7 +53,7 @@ int main(int argc, char *argv[]) Info<< "stringList " << strLst << nl; - labelList matches = findStrings(".*ee.*", strLst); + labelList matches = findStrings(regExp(".*ee.*"), strLst); Info<< "matches found for regexp .*ee.* :" << nl << matches << nl; forAll(matches, i) @@ -71,7 +71,7 @@ int main(int argc, char *argv[]) } Info<< endl; - stringList subLst = subsetStrings(".*ee.*", strLst); + stringList subLst = subsetStrings(regExp(".*ee.*"), strLst); Info<< "subset stringList: " << subLst << nl; subLst = subsetStrings(reLst, strLst); @@ -80,7 +80,7 @@ int main(int argc, char *argv[]) inplaceSubsetStrings(reLst, strLst); Info<< "subsetted stringList: " << strLst << nl; - inplaceSubsetStrings(".*l.*", strLst); + inplaceSubsetStrings(regExp(".*l.*"), strLst); Info<< "subsetted stringList: " << strLst << nl; Info<< "\nEnd\n" << endl; diff --git a/applications/utilities/preProcessing/changeDictionary/changeDictionary.C b/applications/utilities/preProcessing/changeDictionary/changeDictionary.C index e0697c2861..5942e46429 100644 --- a/applications/utilities/preProcessing/changeDictionary/changeDictionary.C +++ b/applications/utilities/preProcessing/changeDictionary/changeDictionary.C @@ -178,7 +178,6 @@ bool addEntry } - // List of indices into thisKeys labelList findMatches ( @@ -194,19 +193,19 @@ labelList findMatches { // Wildcard match matches = findStrings(key, thisKeys); - } else if (shortcuts.size()) { // See if patchGroups expand to valid thisKeys labelList indices = findStrings(key, shortcutNames); - forAll(indices, i) + + for (const label idx : indices) { - const word& name = shortcutNames[indices[i]]; + const word& name = shortcutNames[idx]; const wordList& keys = shortcuts[name]; forAll(keys, j) { - label index = thisKeys.find(keys[j]); + const label index = thisKeys.find(keys[j]); if (index != -1) { matches.append(index); diff --git a/applications/utilities/surface/surfacePatch/surfacePatch.C b/applications/utilities/surface/surfacePatch/surfacePatch.C index 22a2bfb747..4d9ed0247f 100644 --- a/applications/utilities/surface/surfacePatch/surfacePatch.C +++ b/applications/utilities/surface/surfacePatch/surfacePatch.C @@ -137,6 +137,7 @@ int main(int argc, char *argv[]) labelList regionIDs = findStrings(regionName, surf.regions()); + if (modifier().modify(regionIDs, surf)) { changed = true; diff --git a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C index 7f77ccd6f7..b1e1dac7f1 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C +++ b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C @@ -576,63 +576,65 @@ Foam::labelList Foam::polyBoundaryMesh::findIndices { DynamicList