From c93bf09d690213b92321326b5a03c7fa85c1a671 Mon Sep 17 00:00:00 2001 From: berce <75228263+bercedev@users.noreply.github.com> Date: Tue, 20 Oct 2026 23:30:03 +0300 Subject: [PATCH] Trim whitespace around the items of a comma-separated tag value XMLTag::value(std::vector&) kept the spaces after each comma, so a PartList written as "Part1, Part2" looked for a part named " Part2" and the model failed with "Failed building parts." The items are now trimmed, which also drops the 256-character buffer the items were copied into. Closes #137 --- FECore/XMLReader.cpp | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/FECore/XMLReader.cpp b/FECore/XMLReader.cpp index 0369c3983..4e156393f 100644 --- a/FECore/XMLReader.cpp +++ b/FECore/XMLReader.cpp @@ -206,27 +206,30 @@ int XMLTag::value(int* pi, int n) return nr; } +//----------------------------------------------------------------------------- +// An item of a comma-separated list, from sz up to sze (or the end of the +// string when sze is null), without the whitespace around it. So "a, b" lists +// "a" and "b", not "a" and " b". +static std::string listItem(const char* sz, const char* sze) +{ + std::string s = (sze ? std::string(sz, sze - sz) : std::string(sz)); + size_t n0 = s.find_first_not_of(" \t\r\n"); + if (n0 == std::string::npos) return std::string(); + size_t n1 = s.find_last_not_of(" \t\r\n"); + return s.substr(n0, n1 - n0 + 1); +} + //----------------------------------------------------------------------------- int XMLTag::value(std::vector& stringList, int n) { stringList.clear(); - char tmp[256] = { 0 }; - const char* sz = m_szval.c_str(); int nr = 0; for (int i = 0; i 0) strncpy(tmp, sz, l); - tmp[l] = 0; - - stringList.push_back(tmp); - } - else stringList.push_back(sz); + stringList.push_back(listItem(sz, sze)); nr++; if (sze) sz = sze + 1; @@ -240,21 +243,11 @@ void XMLTag::value(std::vector& stringList) { stringList.clear(); - char tmp[256] = { 0 }; - const char* sz = m_szval.c_str(); while (sz && *sz) { const char* sze = strchr(sz, ','); - if (sze) - { - int l = (int)(sze - sz); - if (l > 0) strncpy(tmp, sz, l); - tmp[l] = 0; - - stringList.push_back(tmp); - } - else stringList.push_back(sz); + stringList.push_back(listItem(sz, sze)); if (sze) sz = sze + 1; else break;