mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: add fileName::validate static method (issue #628)
- similar to word::validate to allow stripping of invalid characters without triggering a FatalError. - use this validated fileName in Foam::readDir to avoid problems when a directory contains files with invalid characters in their names - adjust rmDir to handle filenames with invalid characters - fileName::equals() static method to compare strings while ignoring any differences that are solely due to duplicate slashes
This commit is contained in:
@ -51,7 +51,10 @@ template<class TYPE>
|
||||
unsigned testParsing
|
||||
(
|
||||
TYPE (*function)(const std::string&),
|
||||
const List<Tuple2<std::string, bool>>& tests
|
||||
std::initializer_list
|
||||
<
|
||||
Tuple2<bool, std::string>
|
||||
> tests
|
||||
)
|
||||
{
|
||||
unsigned nFail = 0;
|
||||
@ -60,10 +63,10 @@ unsigned testParsing
|
||||
// Expect some failures
|
||||
const bool prev = FatalIOError.throwExceptions();
|
||||
|
||||
for (const Tuple2<std::string, bool>& test : tests)
|
||||
for (const Tuple2<bool, std::string>& test : tests)
|
||||
{
|
||||
const std::string& str = test.first();
|
||||
const bool expected = test.second();
|
||||
const bool expected = test.first();
|
||||
const std::string& str = test.second();
|
||||
|
||||
bool parsed = true;
|
||||
|
||||
@ -124,18 +127,18 @@ int main(int argc, char *argv[])
|
||||
(
|
||||
&readDouble,
|
||||
{
|
||||
{ "", false },
|
||||
{ " ", false },
|
||||
{ " xxx ", false },
|
||||
{ " 1234E-", false },
|
||||
{ " 1234E junk", false },
|
||||
{ " 3.14159 ", true },
|
||||
{ " 31.4159E-1 " , true },
|
||||
{ " 100E1000 " , false },
|
||||
{ " 1E-40 " , true },
|
||||
{ " 1E-305 " , true },
|
||||
{ " 1E-37 " , true },
|
||||
{ " 1E-300 " , true },
|
||||
{ false, "" },
|
||||
{ false, " " },
|
||||
{ false, " xxx " },
|
||||
{ false, " 1234E-" },
|
||||
{ false, " 1234E junk" },
|
||||
{ true, " 3.14159 " },
|
||||
{ true, " 31.4159E-1 " },
|
||||
{ false, " 100E1000 " },
|
||||
{ true, " 1E-40 " },
|
||||
{ true, " 1E-305 " },
|
||||
{ true, " 1E-37 " },
|
||||
{ true, " 1E-300 " },
|
||||
}
|
||||
);
|
||||
}
|
||||
@ -148,14 +151,14 @@ int main(int argc, char *argv[])
|
||||
(
|
||||
&readFloat,
|
||||
{
|
||||
{ " 3.14159 ", true },
|
||||
{ " 31.4159E-1 " , true },
|
||||
{ " 31.4159E200 " , false },
|
||||
{ " 31.4159E20 " , true },
|
||||
{ " 1E-40 " , true },
|
||||
{ " 1E-305 " , true },
|
||||
{ " 1E-37 " , true },
|
||||
{ " 1E-300 " , true },
|
||||
{ true, " 3.14159 " },
|
||||
{ true, " 31.4159E-1 " },
|
||||
{ false, " 31.4159E200 " },
|
||||
{ true, " 31.4159E20 " },
|
||||
{ true, " 1E-40 " },
|
||||
{ true, " 1E-305 " },
|
||||
{ true, " 1E-37 " },
|
||||
{ true, " 1E-300 " },
|
||||
}
|
||||
);
|
||||
}
|
||||
@ -166,15 +169,15 @@ int main(int argc, char *argv[])
|
||||
(
|
||||
&readNasScalar,
|
||||
{
|
||||
{ " 3.14159 ", true },
|
||||
{ " 31.4159E-1 " , true },
|
||||
{ " 314.159-2 " , true },
|
||||
{ " 31.4159E200 " , true },
|
||||
{ " 31.4159E20 " , true },
|
||||
{ " 1E-40 " , true },
|
||||
{ " 1E-305 " , true },
|
||||
{ " 1E-37 " , true },
|
||||
{ " 1E-300 " , true },
|
||||
{ true, " 3.14159 " },
|
||||
{ true, " 31.4159E-1 " },
|
||||
{ true, " 314.159-2 " },
|
||||
{ true, " 31.4159E200 " },
|
||||
{ true, " 31.4159E20 " },
|
||||
{ true, " 1E-40 " },
|
||||
{ true, " 1E-305 " },
|
||||
{ true, " 1E-37 " },
|
||||
{ true, " 1E-300 " },
|
||||
}
|
||||
);
|
||||
}
|
||||
@ -185,12 +188,12 @@ int main(int argc, char *argv[])
|
||||
(
|
||||
&readInt32,
|
||||
{
|
||||
{ " 3.14159 ", false },
|
||||
{ " 31E1 ", false },
|
||||
{ " 31.4159E-1 " , false },
|
||||
{ "100" , true },
|
||||
{ " 2147483644" , true },
|
||||
{ " 2147483700 " , false },
|
||||
{ false, " 3.14159 " },
|
||||
{ false, " 31E1 " },
|
||||
{ false, " 31.4159E-1 " },
|
||||
{ true, "100" },
|
||||
{ true, " 2147483644" },
|
||||
{ false, " 2147483700 " },
|
||||
}
|
||||
);
|
||||
}
|
||||
@ -202,10 +205,10 @@ int main(int argc, char *argv[])
|
||||
(
|
||||
&readUint32,
|
||||
{
|
||||
{ " 2147483644" , true },
|
||||
{ " 2147483700 " , true },
|
||||
{ " 4294967295 " , true },
|
||||
{ " 4294968000 " , false },
|
||||
{ true, "\t2147483644" },
|
||||
{ true, " 2147483700 " },
|
||||
{ true, " 4294967295 " },
|
||||
{ false, " 4294968000 " },
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user