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

string trim

parent 373ad6df
Branches
Tags
No related merge requests found
......@@ -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;
......
......@@ -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);
};
......
......@@ -27,7 +27,6 @@ License
#include <algorithm>
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
inline bool Foam::regExpPosix::meta(char c)
......
......@@ -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
......
......@@ -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);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment