mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: provide word::validated() static method
- Constructs a validated word, in which all invalid characters have been stripped out and any leading digit is '_'-prefixed. Words with leading digits cause parse issues when read back later. - Replaces previous functionally identical code from src/conversion -- COMP: test against nullObject instead of checking address for null pointer.
This commit is contained in:
@ -166,77 +166,6 @@ std::string Foam::ccm::reader::ccmReadOptstr
|
||||
}
|
||||
|
||||
|
||||
Foam::word Foam::ccm::reader::validateWord
|
||||
(
|
||||
const std::string& str
|
||||
)
|
||||
{
|
||||
std::string::size_type ngood = 0;
|
||||
bool prefix = false;
|
||||
bool first = true;
|
||||
|
||||
for
|
||||
(
|
||||
std::string::const_iterator iter = str.begin();
|
||||
iter != str.end();
|
||||
++iter
|
||||
)
|
||||
{
|
||||
if (word::valid(*iter))
|
||||
{
|
||||
++ngood;
|
||||
if (first)
|
||||
{
|
||||
first = false;
|
||||
|
||||
// Start with a digit? need to prefix with '_'
|
||||
if (isdigit(*iter))
|
||||
{
|
||||
prefix = true;
|
||||
++ngood;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ngood == str.size() && !prefix)
|
||||
{
|
||||
return str;
|
||||
}
|
||||
|
||||
Foam::word out;
|
||||
out.resize(ngood);
|
||||
ngood = 0;
|
||||
|
||||
Foam::word::iterator iter2 = out.begin();
|
||||
for
|
||||
(
|
||||
std::string::const_iterator iter1 = str.begin();
|
||||
iter1 != str.end();
|
||||
++iter1
|
||||
)
|
||||
{
|
||||
register char c = *iter1;
|
||||
|
||||
if (Foam::word::valid(c))
|
||||
{
|
||||
if (prefix)
|
||||
{
|
||||
prefix = false;
|
||||
*(iter2++) = '_';
|
||||
++ngood;
|
||||
}
|
||||
*(iter2++) = c;
|
||||
++ngood;
|
||||
}
|
||||
}
|
||||
|
||||
out.resize(ngood);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
// Read map data and check error
|
||||
void Foam::ccm::reader::readMap
|
||||
(
|
||||
@ -435,7 +364,7 @@ void Foam::ccm::reader::readProblemDescription_boundaryRegion
|
||||
}
|
||||
else
|
||||
{
|
||||
dict.add(opt, validateWord(str));
|
||||
dict.add(opt, word::validated(str));
|
||||
}
|
||||
}
|
||||
|
||||
@ -476,7 +405,7 @@ void Foam::ccm::reader::readProblemDescription_boundaryRegion
|
||||
|
||||
if (!str.empty())
|
||||
{
|
||||
dict.add(opt, validateWord(str));
|
||||
dict.add(opt, word::validated(str));
|
||||
}
|
||||
}
|
||||
|
||||
@ -541,7 +470,7 @@ void Foam::ccm::reader::readProblemDescription_cellTable
|
||||
str = "zone_" + ::Foam::name(Id);
|
||||
}
|
||||
|
||||
dict.add(opt, validateWord(str));
|
||||
dict.add(opt, word::validated(str));
|
||||
}
|
||||
|
||||
|
||||
@ -553,7 +482,7 @@ void Foam::ccm::reader::readProblemDescription_cellTable
|
||||
|
||||
if (!str.empty())
|
||||
{
|
||||
dict.add(opt, validateWord(str));
|
||||
dict.add(opt, word::validated(str));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -320,9 +320,6 @@ private:
|
||||
// return empty string on failure
|
||||
std::string ccmReadOptstr(const char* opt, ccmID node);
|
||||
|
||||
//- Strip invalid characters, prefix leading digit with '_'
|
||||
static word validateWord(const std::string&);
|
||||
|
||||
//- Read map data and check error
|
||||
void readMap(const ccmID& mapId, labelList& data);
|
||||
|
||||
|
||||
@ -31,80 +31,6 @@ License
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
Foam::word Foam::fileFormats::FIREMeshReader::validateWord
|
||||
(
|
||||
const std::string& str
|
||||
)
|
||||
{
|
||||
std::string::size_type ngood = 0;
|
||||
bool prefix = false;
|
||||
bool first = true;
|
||||
|
||||
for
|
||||
(
|
||||
std::string::const_iterator iter = str.begin();
|
||||
iter != str.end();
|
||||
++iter
|
||||
)
|
||||
{
|
||||
if (word::valid(*iter))
|
||||
{
|
||||
++ngood;
|
||||
if (first)
|
||||
{
|
||||
first = false;
|
||||
|
||||
// start with a digit? need to prefix with '_'
|
||||
if (isdigit(*iter))
|
||||
{
|
||||
prefix = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (prefix)
|
||||
{
|
||||
++ngood;
|
||||
}
|
||||
else if (ngood == str.size())
|
||||
{
|
||||
return str;
|
||||
}
|
||||
|
||||
Foam::word out;
|
||||
out.resize(ngood);
|
||||
ngood = 0;
|
||||
|
||||
Foam::word::iterator iter2 = out.begin();
|
||||
for
|
||||
(
|
||||
std::string::const_iterator iter1 = str.begin();
|
||||
iter1 != str.end();
|
||||
++iter1
|
||||
)
|
||||
{
|
||||
register char c = *iter1;
|
||||
|
||||
if (Foam::word::valid(c))
|
||||
{
|
||||
if (prefix)
|
||||
{
|
||||
prefix = false;
|
||||
*(iter2++) = '_';
|
||||
++ngood;
|
||||
}
|
||||
*(iter2++) = c;
|
||||
++ngood;
|
||||
}
|
||||
}
|
||||
|
||||
out.resize(ngood);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
void Foam::fileFormats::FIREMeshReader::readPoints
|
||||
(
|
||||
ISstream& is,
|
||||
@ -229,7 +155,7 @@ void Foam::fileFormats::FIREMeshReader::readSelections(ISstream& is)
|
||||
// index starting at 1
|
||||
const label selId = ++nCellSelections;
|
||||
|
||||
cellTable_.setName(selId, validateWord(name));
|
||||
cellTable_.setName(selId, word::validated(name));
|
||||
cellTable_.setMaterial(selId, "fluid");
|
||||
|
||||
for (label i = 0; i < count; ++i)
|
||||
@ -244,7 +170,7 @@ void Foam::fileFormats::FIREMeshReader::readSelections(ISstream& is)
|
||||
// index starting at 0
|
||||
const label selId = nFaceSelections++;
|
||||
|
||||
faceNames.append(validateWord(name));
|
||||
faceNames.append(word::validated(name));
|
||||
|
||||
for (label i = 0; i < count; ++i)
|
||||
{
|
||||
|
||||
@ -83,10 +83,6 @@ protected:
|
||||
void operator=(const FIREMeshReader&) = delete;
|
||||
|
||||
|
||||
//- Validate word (eg, avoid leading digits)
|
||||
static word validateWord(const std::string&);
|
||||
|
||||
|
||||
//- Read the mesh from the file(s)
|
||||
virtual bool readGeometry(const scalar scaleFactor = 1.0);
|
||||
|
||||
|
||||
@ -194,7 +194,7 @@ Foam::label Foam::checkFireEdges
|
||||
thisEdge.flip();
|
||||
}
|
||||
|
||||
if (&points)
|
||||
if (notNull(points))
|
||||
{
|
||||
forAll(thisEdge, keyI)
|
||||
{
|
||||
@ -220,7 +220,7 @@ Foam::label Foam::checkFireEdges
|
||||
{
|
||||
labelList keys = strayPoints.sortedToc();
|
||||
|
||||
if (&points)
|
||||
if (notNull(points))
|
||||
{
|
||||
forAll(keys, keyI)
|
||||
{
|
||||
@ -257,10 +257,9 @@ Foam::label Foam::checkFireEdges
|
||||
{
|
||||
label nPoints = -1;
|
||||
|
||||
if (&points)
|
||||
if (notNull(points))
|
||||
{
|
||||
nPoints = points.size();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -287,10 +286,7 @@ Foam::label Foam::checkFireEdges
|
||||
}
|
||||
|
||||
|
||||
Foam::label Foam::checkFireEdges
|
||||
(
|
||||
const polyMesh& mesh
|
||||
)
|
||||
Foam::label Foam::checkFireEdges(const polyMesh& mesh)
|
||||
{
|
||||
return checkFireEdges(mesh.faces(), mesh.pointFaces(), mesh.points());
|
||||
}
|
||||
|
||||
@ -50,9 +50,9 @@ class polyMesh;
|
||||
//- check edge connectivity
|
||||
label checkFireEdges
|
||||
(
|
||||
const faceList&,
|
||||
const faceList& faces,
|
||||
const labelListList& pointFaces,
|
||||
const UList<point>& = UList<point>::null()
|
||||
const UList<point>& points = UList<point>::null()
|
||||
);
|
||||
|
||||
|
||||
@ -60,12 +60,12 @@ label checkFireEdges
|
||||
label checkFireEdges
|
||||
(
|
||||
const faceList&,
|
||||
const UList<point>& = UList<point>::null()
|
||||
const UList<point>& points = UList<point>::null()
|
||||
);
|
||||
|
||||
|
||||
//- check edge connectivity
|
||||
label checkFireEdges(const polyMesh&);
|
||||
label checkFireEdges(const polyMesh& mesh);
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
Reference in New Issue
Block a user