-
BackgroundFeel++ uses JSON files to define models, boundary conditions, materials, and post-processing configurations. Proposed ChangeWe suggest using Reasons for Choosing
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I would also favor using .fpp.json over alternatives like
While .fson or .fon might simplify certain filesystem operations, the benefits of clarity, schema validation support, and overall tooling integration make .fpp.json the preferred choice I think. Here are two possible helper functions : one manipulating strings, the other using #include <iostream>
#include <string>
#include <filesystem>
bool hasCompoundExtension(const std::string & filename, const std::string & compound_ext)
{
if (filename.size() < compound_ext.size())
{
return false;
}
return (filename.compare(filename.size() - compound_ext.size(), compound_ext.size(), compound_ext) == 0);
}
bool hasCompoundExtensionFS(const std::filesystem::path & filePath, const std::string & firstExt, const std::string & secondExt)
{
// Check that the final extension matches the second extension (e.g., ".json")
if (filePath.extension() != secondExt)
{
return false;
}
// Get the stem (the filename without the final extension)
std::filesystem::path stem = filePath.stem();
// Check if the stem has an extension matching the first extension (e.g., ".fpp")
return (stem.extension() == firstExt);
}
int main()
{
std::string file1 = "config.fpp.json";
std::string file2 = "settings.json";
std::string file3 = "data.fpp.json.bak";
std::cout << file1 << " is "
<< (hasCompoundExtension(file1, ".fpp.json") ? "" : "not ")
<< "a file with compound extension .fpp.json\n";
std::cout << file2 << " is "
<< (hasCompoundExtension(file2, ".fpp.json") ? "" : "not ")
<< "a file with compound extension .fpp.json\n";
std::cout << file3 << " is "
<< (hasCompoundExtension(file3, ".fpp.json") ? "" : "not ")
<< "a file with compound extension .fpp.json\n";
std::cout << file1 << " is "
<< (hasCompoundExtensionFS(file1, ".fpp", ".json") ? "" : "not ")
<< "a file with compound extension .fpp.json\n";
std::cout << file2 << " is "
<< (hasCompoundExtensionFS(file2, ".fpp", ".json") ? "" : "not ")
<< "a file with compound extension .fpp.json\n";
std::cout << file3 << " is "
<< (hasCompoundExtensionFS(file3, ".fpp", ".json") ? "" : "not ")
<< "a file with compound extension .fpp.json\n";
return 0;
} here is the output (I added a test_fppjson) > ./feelpp_test_fppjson
config.fpp.json is a file with compound extension .fpp.json
settings.json is not a file with compound extension .fpp.json
data.fpp.json.bak is not a file with compound extension .fpp.json
config.fpp.json is a file with compound extension .fpp.json
settings.json is not a file with compound extension .fpp.json
data.fpp.json.bak is not a file with compound extension .fpp.json @vincentchabannes what do you think ? |
Beta Was this translation helpful? Give feedback.
I would also favor using .fpp.json over alternatives like
.fson
or.fon
for several reasons: