Commit b8231332 authored by GILLES Sebastien's avatar GILLES Sebastien

#1468 Amend the new code to support properly underscores in entry names.

parent 9f4cc234
......@@ -4674,6 +4674,7 @@
BECF3E4822E99E2C00FF951A /* main_update_lua_file.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = main_update_lua_file.cpp; path = RivlinCube/main_update_lua_file.cpp; sourceTree = "<group>"; };
BECF3E4C22E9B05A00FF951A /* map_in_vector.lua */ = {isa = PBXFileReference; lastKnownFileType = text; path = map_in_vector.lua; sourceTree = "<group>"; };
BECF3E4D22EA00E300FF951A /* no_section.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = no_section.lua; sourceTree = "<group>"; };
BECF3E4F22EA1E4B00FF951A /* entry_with_underscore.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = entry_with_underscore.lua; sourceTree = "<group>"; };
BED13351206519C700A3B0AA /* Penalization.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Penalization.hxx; sourceTree = "<group>"; };
BED13352206519C800A3B0AA /* Penalization.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Penalization.hpp; sourceTree = "<group>"; };
BED748E41906734200BAB761 /* main_test_ondomatic_numbering.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = main_test_ondomatic_numbering.cpp; sourceTree = "<group>"; };
......@@ -10251,6 +10252,7 @@
BEDE16B3204FF5CE00DEFE08 /* redundancy.lua */,
BECF3E4C22E9B05A00FF951A /* map_in_vector.lua */,
BECF3E4D22EA00E300FF951A /* no_section.lua */,
BECF3E4F22EA1E4B00FF951A /* entry_with_underscore.lua */,
BEDE169D204EEB0F00DEFE08 /* main.cpp */,
);
path = LuaOptionFile;
transient = {
-- Time at the beginning of the code (in seconds).
-- Expected format: VALUE
-- Constraint: v >= 0.
init_time = 0.,
-- Time step between two iterations, in seconds.
-- Expected format: VALUE
-- Constraint: v > 0.
timeStep = 0.1,
-- Maximum time, if set to zero run a static case.
-- Expected format: VALUE
-- Constraint: v >= 0.
timeMax = .1
} -- transient
......@@ -265,4 +265,21 @@ BOOST_FIXTURE_TEST_CASE(no_section, TestNS::FixtureNS::Environment)
"[a, b, c, d, e, f]");
}
BOOST_FIXTURE_TEST_CASE(entry_with_underscore, TestNS::FixtureNS::Environment)
{
decltype(auto) environment = Utilities::Environment::CreateOrGetInstance(__FILE__, __LINE__);
decltype(auto) input_file =
environment.SubstituteValues("${MOREFEM_ROOT}/Sources/Test/Utilities/LuaOptionFile/entry_with_underscore.lua");
LuaOptionFile lua(input_file, __FILE__, __LINE__);
std::ostringstream oconv;
Utilities::PrintContainer<>::Do(lua.GetEntryKeyList(), oconv, ", ", "[", "]");
BOOST_CHECK_EQUAL(oconv.str(),
"[transient.init_time, transient.timeStep, transient.timeMax]");
}
PRAGMA_DIAGNOSTIC(pop)
......@@ -118,7 +118,25 @@ namespace MoReFEM
};
struct ReadNameBackward
{
ReadNameBackward(const std::string& content,
std::size_t pos);
//! Check whether the character read is either a letter, a underscore and possibly a letter (only if
//! letter_already_read_ is false for the latter)
bool Test(const char c);
std::string name;
bool letter_already_read_ = false;
};
} // namespace anonymous
......@@ -194,6 +212,42 @@ namespace MoReFEM
}
bool ReadNameBackward::Test(const char c)
{
if (c == '_')
return true;
if (letter_already_read_)
return isalpha(c);
else
{
if (isalpha(c))
{
letter_already_read_ = true;
return true;
}
return isalnum(c);
}
}
ReadNameBackward::ReadNameBackward(const std::string& content,
std::size_t pos)
{
while (Test(content[pos]) && pos > 0)
{
name.push_back(content[pos]);
--pos;
}
if (pos == 0)
name.push_back(content[pos]);
std::reverse(name.begin(), name.end());
}
ExtractKeysFromFile::ExtractKeysFromFile(const std::string& file)
: file_(file)
{
......@@ -296,28 +350,14 @@ namespace MoReFEM
throw Exception(oconv.str(), __FILE__, __LINE__);
}
std::string name;
// Keep doing it while reconstruct the name backwards.
while (!std::isalnum(content_[pos]) && pos > 0)
--pos;
bool letter_already_read = false;
while (std::isalnum(content_[pos]) && pos > 0)
{
if (letter_already_read && !std::isalpha(content_[pos]))
break;
ReadNameBackward read_name_backward(content_, pos);
if (std::isalpha(content_[pos]))
letter_already_read = true;
// Numeric are allowed at the end, but as soon a letter is met numeric are forbidden.
name.push_back(content_[pos]);
--pos;
}
if (pos == 0)
name.push_back(content_[pos]);
std::string name = read_name_backward.name;
if (name.empty())
{
......@@ -326,7 +366,7 @@ namespace MoReFEM
throw Exception(oconv.str(), __FILE__, __LINE__);
}
std::reverse(name.begin(), name.end());
entry_or_section_list_.emplace_back(EntryOrSection(name, equal_pos));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment