codedBase: Added support for arbitrary entry names

Non-alphanumeic characters in the name of the coded object are now *all*
replaced by underscores. This means functions with complex names (i.e.,
like those resulting from command line substitutions) can now be
compiled.
This commit is contained in:
Will Bainbridge
2023-08-30 11:12:41 +01:00
parent b01930e078
commit 5dade27f25
2 changed files with 35 additions and 4 deletions

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -42,6 +42,32 @@ namespace Foam
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
Foam::word Foam::codedBase::codeName(const word& name)
{
word result(name);
if (!isalpha(result[0]))
{
FatalErrorInFunction
<< "Cannot construct code name from function name \"" << name
<< "\" as the first character is not alphabetic"
<< exit(FatalError);
}
for (word::size_type i = 1; i < name.size(); ++ i)
{
const bool valid = isalnum(result[i]) || result[i] == '_';
if (!valid)
{
result[i] = '_';
}
}
return result;
}
void* Foam::codedBase::loadLibrary
(
const fileName& libPath,
@ -367,14 +393,14 @@ Foam::codedBase::codedBase()
Foam::codedBase::codedBase(const word& name, const dictionary& dict)
:
codeName_(name.replaceAll("-", "_")),
codeName_(codeName(name)),
dict_(dict)
{}
Foam::codedBase::codedBase(const dictionary& dict)
:
codeName_(dict.lookup("name")),
codeName_(codeName(dict.lookup("name"))),
dict_(dict)
{}