From f616975e28d6bcae3c5364da5c3ea7ae4f80809c Mon Sep 17 00:00:00 2001 From: Alessio Quaglino Date: Fri, 31 May 2024 01:17:08 -0700 Subject: [PATCH] Forward fix for MJCF parsing: A recent libc++ update does not natively accept ".x" float format ('.' being the first character) but rather requires "0.x". PiperOrigin-RevId: 638946382 Change-Id: I3ccb1b5fedc6749a3459916b41148629933fb8c4 --- src/xml/xml_util.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/xml/xml_util.cc b/src/xml/xml_util.cc index eec0dd39..651e3586 100644 --- a/src/xml/xml_util.cc +++ b/src/xml/xml_util.cc @@ -481,6 +481,16 @@ bool mjXUtil::ReadAttrValues(XMLElement* elem, const char* attr, // read numbers for (int i = 0; (max < 0 || i < max) && !strm.eof(); ++i) { strm >> token; + + // some C++ libraries do not allow .x instead of 0.x + if (!token.empty()) { + if (token[0] == std::string(".")[0]) { + token = "0" + token; + } else if (token[0] == std::string("-")[0] && token[1] == std::string(".")[0]) { + token.insert(1, "0"); + } + } + std::istringstream token_strm(token); token_strm >> item; if (token_strm.fail() || !token_strm.eof()) {