Skip to content
Snippets Groups Projects
Commit 677e3142 authored by Mark OLESEN's avatar Mark OLESEN
Browse files

string trim

parent 373ad6df
No related branches found
No related tags found
No related merge requests found
...@@ -2,13 +2,10 @@ ...@@ -2,13 +2,10 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\/ M anipulation |
-------------------------------------------------------------------------------
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation Copyright (C) 2018-2019 OpenCFD Ltd.
Copyright (C) 2011-2019 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
...@@ -73,7 +70,7 @@ int main() ...@@ -73,7 +70,7 @@ int main()
f1 = f2 + f3 + f2 + f3; f1 = f2 + f3 + f2 + f3;
} }
Info<<"f1 = " << f1 << nl; Info<< "f1 = " << f1 << nl;
} }
{ {
...@@ -83,7 +80,7 @@ int main() ...@@ -83,7 +80,7 @@ int main()
if (tfld1.valid()) if (tfld1.valid())
{ {
Info<<"tmp: " << tfld1() << nl; Info<< "tmp: " << tfld1() << nl;
} }
// Hold on to the old content for a bit // Hold on to the old content for a bit
...@@ -94,18 +91,42 @@ int main() ...@@ -94,18 +91,42 @@ int main()
printInfo(tfld2); printInfo(tfld2);
if (tfld2.valid()) if (tfld2.valid())
{ {
Info<<"tmp: " << tfld2() << nl; Info<< "tmp: " << tfld2() << nl;
} }
tfld2.clear(); tfld2.clear();
Info<<"After clear : "; Info<< "After clear : ";
printInfo(tfld2); printInfo(tfld2);
tfld2.cref(f1); 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); 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; Info<< "\nEnd" << endl;
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2004-2011, 2017-2019 OpenCFD Ltd. Copyright (C) 2017-2019 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
...@@ -49,6 +49,13 @@ SourceFiles ...@@ -49,6 +49,13 @@ SourceFiles
#include <regex.h> #include <regex.h>
#include <string> #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 namespace Foam
...@@ -71,8 +78,16 @@ class regExpPosix ...@@ -71,8 +78,16 @@ class regExpPosix
public: public:
//- Type for matches // Public Types
typedef SubStrings<std::string> results_type;
#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 // Static Member Data
...@@ -190,7 +205,6 @@ public: ...@@ -190,7 +205,6 @@ public:
//- Assign and compile pattern from string. //- Assign and compile pattern from string.
// Matching is case sensitive. // Matching is case sensitive.
inline void operator=(const std::string& pattern); inline void operator=(const std::string& pattern);
}; };
......
...@@ -27,7 +27,6 @@ License ...@@ -27,7 +27,6 @@ License
#include <algorithm> #include <algorithm>
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
inline bool Foam::regExpPosix::meta(char c) inline bool Foam::regExpPosix::meta(char c)
......
...@@ -84,8 +84,11 @@ class regExpCxx ...@@ -84,8 +84,11 @@ class regExpCxx
public: public:
//- Type for matches // Public Types
typedef std::smatch results_type;
//- Type for matches
typedef std::smatch results_type;
// Static Member Data // Static Member Data
......
...@@ -48,6 +48,7 @@ SourceFiles ...@@ -48,6 +48,7 @@ SourceFiles
#include "stringOpsSort.H" #include "stringOpsSort.H"
#include "stringOpsEvaluate.H" #include "stringOpsEvaluate.H"
#include "wordRes.H" #include "wordRes.H"
#include <utility>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
...@@ -256,6 +257,16 @@ namespace stringOps ...@@ -256,6 +257,16 @@ namespace stringOps
// Return true if a replacement was successful. // Return true if a replacement was successful.
bool inplaceReplaceVar(std::string& s, const word& varName); 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 //- Return string trimmed of leading whitespace
string trimLeft(const std::string& s); string trimLeft(const std::string& s);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment