diff --git a/applications/test/tmp/Test-tmp.C b/applications/test/tmp/Test-tmp.C index db7de00cbc7ca5ab6adb6c239a3ed20f554ff2b6..88b081630ab99551ddeb82ce029d2686093a672e 100644 --- a/applications/test/tmp/Test-tmp.C +++ b/applications/test/tmp/Test-tmp.C @@ -2,13 +2,10 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\/ M anipulation | -------------------------------------------------------------------------------- \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2011 OpenFOAM Foundation - Copyright (C) 2011-2019 OpenCFD Ltd. + Copyright (C) 2018-2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -73,7 +70,7 @@ int main() f1 = f2 + f3 + f2 + f3; } - Info<<"f1 = " << f1 << nl; + Info<< "f1 = " << f1 << nl; } { @@ -83,7 +80,7 @@ int main() if (tfld1.valid()) { - Info<<"tmp: " << tfld1() << nl; + Info<< "tmp: " << tfld1() << nl; } // Hold on to the old content for a bit @@ -94,18 +91,42 @@ int main() printInfo(tfld2); if (tfld2.valid()) { - Info<<"tmp: " << tfld2() << nl; + Info<< "tmp: " << tfld2() << nl; } tfld2.clear(); - Info<<"After clear : "; + Info<< "After clear : "; printInfo(tfld2); tfld2.cref(f1); - Info<<"Reset const-ref : "; + Info<< "Reset to const-ref : "; + printInfo(tfld2); + + Info<< "Clear const-ref does not affect tmp: "; + tfld2.clear(); + printInfo(tfld2); + + Info<< "Reset const-ref affects tmp: "; + tfld2.reset(); printInfo(tfld2); + + + // Reset tfld2 from tfld1 + Info<< "Fld2 : "; + printInfo(tfld2); + + for (label i = 0; i < 2; ++i) + { + tfld2.reset + ( + tmp<scalarField>::NewFrom<myScalarField>(4, Zero) + ); + + Info<< "Reset to some other tmp content : "; + printInfo(tfld2); + } } Info<< "\nEnd" << endl; diff --git a/src/OSspecific/POSIX/regExp/regExpPosix.H b/src/OSspecific/POSIX/regExp/regExpPosix.H index 4f3f85249f33c6dcd3d14f319debb452d4f05ee7..09074d5fda582f76ba21409b533f3a7501c693e9 100644 --- a/src/OSspecific/POSIX/regExp/regExpPosix.H +++ b/src/OSspecific/POSIX/regExp/regExpPosix.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2004-2011, 2017-2019 OpenCFD Ltd. + Copyright (C) 2017-2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -49,6 +49,13 @@ SourceFiles #include <regex.h> #include <string> +// Transitional feature - support std::smatch as per C++11 regex +#undef Foam_regExpPosix_cxx + +#ifdef Foam_regExpPosix_cxx +#include <regex> +#endif + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam @@ -71,8 +78,16 @@ class regExpPosix public: - //- Type for matches - typedef SubStrings<std::string> results_type; + // Public Types + + #ifdef Foam_regExpPosix_cxx + //- Type for matches, as per C++11 regex + typedef std::smatch results_type; + #else + //- Type for matches, use OpenFOAM SubStrings container + typedef SubStrings<std::string> results_type; + #endif + // Static Member Data @@ -190,7 +205,6 @@ public: //- Assign and compile pattern from string. // Matching is case sensitive. inline void operator=(const std::string& pattern); - }; diff --git a/src/OSspecific/POSIX/regExp/regExpPosixI.H b/src/OSspecific/POSIX/regExp/regExpPosixI.H index 3d8df849af2a94580c3e6e484bb7acdcaf55b1d2..532d7e688c78fefb1a323ca6b08c5720ea91a789 100644 --- a/src/OSspecific/POSIX/regExp/regExpPosixI.H +++ b/src/OSspecific/POSIX/regExp/regExpPosixI.H @@ -27,7 +27,6 @@ License #include <algorithm> - // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // inline bool Foam::regExpPosix::meta(char c) diff --git a/src/OpenFOAM/primitives/strings/regex/regExpCxx.H b/src/OpenFOAM/primitives/strings/regex/regExpCxx.H index c7323df607870359610e46f25157d2fbbc400e3f..05229123475f4adde86dbccd4a37140e55ca196d 100644 --- a/src/OpenFOAM/primitives/strings/regex/regExpCxx.H +++ b/src/OpenFOAM/primitives/strings/regex/regExpCxx.H @@ -84,8 +84,11 @@ class regExpCxx public: - //- Type for matches - typedef std::smatch results_type; + // Public Types + + //- Type for matches + typedef std::smatch results_type; + // Static Member Data diff --git a/src/OpenFOAM/primitives/strings/stringOps/stringOps.H b/src/OpenFOAM/primitives/strings/stringOps/stringOps.H index 11b0e15da3541c7707c31a4309858568f17807c5..b4a54b2b0cb819d88187d430ac562a60dff6e08a 100644 --- a/src/OpenFOAM/primitives/strings/stringOps/stringOps.H +++ b/src/OpenFOAM/primitives/strings/stringOps/stringOps.H @@ -48,6 +48,7 @@ SourceFiles #include "stringOpsSort.H" #include "stringOpsEvaluate.H" #include "wordRes.H" +#include <utility> // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -256,6 +257,16 @@ namespace stringOps // Return true if a replacement was successful. bool inplaceReplaceVar(std::string& s, const word& varName); + //- Find first and last non-space locations in string or sub-string + //- and return as a (pos, len) pair. + // In the future this might become a std::smatch or a std::stringview + std::pair<size_t, size_t> + findTrim + ( + const std::string& s, + size_t pos = 0, + size_t len = std::string::npos + ); //- Return string trimmed of leading whitespace string trimLeft(const std::string& s);