mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: rationalize some string methods.
- silently deprecate 'startsWith', 'endsWith' methods
(added in 2016: 2b14360662), in favour of
'starts_with', 'ends_with' methods, corresponding to C++20 and
allowing us to cull then in a few years.
- handle single character versions of starts_with, ends_with.
- add single character version of removeEnd and silently deprecate
removeTrailing which did the same thing.
- drop the const versions of removeRepeated, removeTrailing.
Unused and with potential confusion.
STYLE: use shrink_to_fit(), erase()
This commit is contained in:
committed by
Andrew Heather
parent
ea214727a5
commit
7c1190f0b1
@ -83,7 +83,7 @@ int main(int argc, char *argv[])
|
||||
const word& item
|
||||
: DirLister::files(".").where
|
||||
(
|
||||
[](const word& val){ return val.startsWith("T"); }
|
||||
[](const word& val){ return val.starts_with('T'); }
|
||||
)
|
||||
)
|
||||
{
|
||||
@ -135,7 +135,7 @@ int main(int argc, char *argv[])
|
||||
<< "~~~~~~~~~~" << nl
|
||||
<< DirLister(".").list<fileName>
|
||||
(
|
||||
[](const word& val){ return val.startsWith("D"); },
|
||||
[](const word& val){ return val.starts_with('D'); },
|
||||
false
|
||||
)
|
||||
<< nl;
|
||||
|
||||
@ -353,7 +353,7 @@ int main(int argc, char *argv[])
|
||||
<< word::printf("formatted '%08d'", val) << "\n";
|
||||
}
|
||||
|
||||
// test startsWith, endsWith methods
|
||||
// test starts_with, ends_with methods
|
||||
{
|
||||
string empty; //;
|
||||
string input1 = "shorter input";
|
||||
@ -362,64 +362,64 @@ int main(int argc, char *argv[])
|
||||
stringList checks{"match", "long", "", "short", "text", "s", "l", "t"};
|
||||
|
||||
Info<< nl;
|
||||
Info<< "check startsWith:" << nl
|
||||
Info<< "check starts_with:" << nl
|
||||
<< "~~~~~~~~~~~~~~~~~" << nl;
|
||||
|
||||
Info<<"input: " << empty << nl;
|
||||
for (const string& test : checks)
|
||||
{
|
||||
Info<< " startsWith(" << test << ") = "
|
||||
<< Switch(empty.startsWith(test)) << nl;
|
||||
Info<< " starts_with(" << test << ") = "
|
||||
<< Switch(empty.starts_with(test)) << nl;
|
||||
}
|
||||
Info<<"input: " << input1 << nl;
|
||||
for (const string& test : checks)
|
||||
{
|
||||
Info<< " startsWith(" << test << ") = "
|
||||
<< Switch(input1.startsWith(test)) << nl;
|
||||
Info<< " starts_with(" << test << ") = "
|
||||
<< Switch(input1.starts_with(test)) << nl;
|
||||
}
|
||||
Info<<"input: " << input2 << nl;
|
||||
for (const string& test : checks)
|
||||
{
|
||||
Info<< " startsWith(" << test << ") = "
|
||||
<< Switch(input2.startsWith(test)) << nl;
|
||||
Info<< " starts_with(" << test << ") = "
|
||||
<< Switch(input2.starts_with(test)) << nl;
|
||||
}
|
||||
|
||||
|
||||
Info<< nl;
|
||||
Info<< "check endsWith:" << nl
|
||||
Info<< "check ends_with:" << nl
|
||||
<< "~~~~~~~~~~~~~~~~~" << nl;
|
||||
|
||||
Info<<"input: " << empty << nl;
|
||||
for (const string& test : checks)
|
||||
{
|
||||
Info<< " endsWith(" << test << ") = "
|
||||
<< Switch(empty.endsWith(test)) << nl;
|
||||
Info<< " ends_with(" << test << ") = "
|
||||
<< Switch(empty.ends_with(test)) << nl;
|
||||
}
|
||||
Info<<"input: " << input1 << nl;
|
||||
for (const string& test : checks)
|
||||
{
|
||||
Info<< " endsWith(" << test << ") = "
|
||||
<< Switch(input1.endsWith(test)) << nl;
|
||||
Info<< " ends_with(" << test << ") = "
|
||||
<< Switch(input1.ends_with(test)) << nl;
|
||||
}
|
||||
Info<<"input: " << input2 << nl;
|
||||
for (const string& test : checks)
|
||||
{
|
||||
Info<< " endsWith(" << test << ") = "
|
||||
<< Switch(input2.endsWith(test)) << nl;
|
||||
Info<< " ends_with(" << test << ") = "
|
||||
<< Switch(input2.ends_with(test)) << nl;
|
||||
}
|
||||
|
||||
Info<< nl;
|
||||
Info<< "check endsWith as applied to field names:" << nl
|
||||
Info<< "check ends_with as applied to field names:" << nl
|
||||
<< "~~~~~~~~~~~~~~~~~" << nl;
|
||||
|
||||
string input3 = "field_0";
|
||||
string input4 = "_0";
|
||||
|
||||
Info<<input3 << " endsWith(\"_0\") = "
|
||||
<< Switch(input3.endsWith("_0")) << nl;
|
||||
Info<<input3 << " ends_with(\"_0\") = "
|
||||
<< Switch(input3.ends_with("_0")) << nl;
|
||||
|
||||
Info<<input4 << " endsWith(\"_0\") = "
|
||||
<< Switch(input4.endsWith("_0")) << nl;
|
||||
Info<<input4 << " ends_with(\"_0\") = "
|
||||
<< Switch(input4.ends_with("_0")) << nl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -175,7 +175,7 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
nodeStream.getLine(line);
|
||||
}
|
||||
while (line.size() && line[0] == '#');
|
||||
while (line.starts_with('#'));
|
||||
|
||||
IStringStream nodeLine(line);
|
||||
|
||||
@ -252,7 +252,7 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
eleStream.getLine(line);
|
||||
}
|
||||
while (line.size() && line[0] == '#');
|
||||
while (line.starts_with('#'));
|
||||
|
||||
IStringStream eleLine(line);
|
||||
|
||||
@ -368,7 +368,7 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
faceStream.getLine(line);
|
||||
}
|
||||
while (line.size() && line[0] == '#');
|
||||
while (line.starts_with('#'));
|
||||
|
||||
IStringStream faceLine(line);
|
||||
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||
Copyright (C) 2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -51,7 +52,7 @@ string getLine(std::ifstream& is)
|
||||
{
|
||||
std::getline(is, line);
|
||||
}
|
||||
while (line.size() && line[0] == '#');
|
||||
while (line.starts_with('#'));
|
||||
|
||||
return line;
|
||||
}
|
||||
|
||||
@ -40,7 +40,7 @@ Foam::autoPtr<Foam::helpType> Foam::helpType::New
|
||||
{
|
||||
// special treatment for -help
|
||||
// exit without stack trace
|
||||
if (helpTypeName.startsWith("-help"))
|
||||
if (helpTypeName.starts_with("-help"))
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Valid helpType selections:" << nl
|
||||
|
||||
@ -678,7 +678,7 @@ void Foam::vtkPVFoam::Update
|
||||
// Suppress caching of Lagrangian since it normally always changes.
|
||||
cachedVtp_.filterKeys
|
||||
(
|
||||
[](const word& k){ return k.startsWith("lagrangian/"); },
|
||||
[](const word& k){ return k.starts_with("lagrangian/"); },
|
||||
true // prune
|
||||
);
|
||||
}
|
||||
|
||||
@ -179,7 +179,7 @@ void Foam::vtkPVFoam::convertMeshPatches()
|
||||
}
|
||||
}
|
||||
|
||||
if (longName.startsWith("group/"))
|
||||
if (longName.starts_with("group/"))
|
||||
{
|
||||
// Patch group. Collect patch faces.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user