Skip to content

Commit

Permalink
Merge pull request #3667 from opensim-org/fix_make-regex-parsing-static
Browse files Browse the repository at this point in the history
Make std::regex parsing have a static lifetime
  • Loading branch information
nickbianco authored Jan 10, 2024
2 parents c8a5577 + 3c532e3 commit 20752f3
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions OpenSim/Common/Component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1174,20 +1174,23 @@ void Component::updateFromXMLNode(SimTK::Xml::Element& node, int versionNumber)

}
if (versionNumber <= 30516) {
static const std::regex s_ConnecteeNamePattern("(socket_|input_)(.*)(_connectee_name)");
static const std::regex s_ConnecteeNamesPattern("(input_)(.*)(_connectee_names)");

// Rename xml tags for socket_*_connectee_name to socket_*
std::string connecteeNameString = "_connectee_name";
for (auto iter = node.element_begin();
iter != node.element_end();
++iter) {
auto tagname = iter->getElementTag();
if (std::regex_match(tagname, std::regex("(socket_|input_)(.*)(_connectee_name)"))) {
if (std::regex_match(tagname, s_ConnecteeNamePattern)) {
auto pos = tagname.find(connecteeNameString);
if (pos != std::string::npos) {
tagname.replace(pos, connecteeNameString.length(), "");
iter->setElementTag(tagname);
}
}
else if (std::regex_match(tagname, std::regex("(input_)(.*)(_connectee_names)"))) {
else if (std::regex_match(tagname, s_ConnecteeNamesPattern)) {
auto pos = tagname.find(connecteeNameString);
if (pos != std::string::npos) {
tagname.replace(pos, connecteeNameString.length()+1, "");
Expand Down

0 comments on commit 20752f3

Please sign in to comment.