From 8d8a3d26372d9c0a784e181121fc2b360f6fee51 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Thu, 31 Aug 2017 16:47:29 +0200 Subject: Add trailing ,/; to string repr of float vector/matrix This makes it possible to differentiate between a scalar and a one-element vector, and fixes #111. --- src/Utilities.cpp | 9 ++++++--- src/XMLNode.cpp | 9 ++++----- 2 files changed, 10 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/Utilities.cpp b/src/Utilities.cpp index eb34092..c90e67b 100644 --- a/src/Utilities.cpp +++ b/src/Utilities.cpp @@ -77,6 +77,7 @@ std::vector stringToDoubleVector(const std::string &s) out.reserve(100); std::istringstream iss; iss.imbue(std::locale::classic()); + size_t length = s.size(); size_t current = 0; size_t next; do { @@ -88,7 +89,7 @@ std::vector stringToDoubleVector(const std::string &s) iss >> f; out.push_back(f); current = next + 1; - } while (next != std::string::npos); + } while (next != std::string::npos && current != length); return out; } @@ -97,6 +98,7 @@ template std::vector stringToVector(const std::string& s) { std::vector out; + size_t length = s.size(); size_t current = 0; size_t next; do { @@ -104,7 +106,7 @@ std::vector stringToVector(const std::string& s) std::string t = s.substr(current, next - current); out.push_back(stringTo(t)); current = next + 1; - } while (next != std::string::npos); + } while (next != std::string::npos && current != length); return out; } @@ -134,13 +136,14 @@ void splitString(std::vector &items, const std::string& s, const char *delim) { items.clear(); + size_t length = s.size(); size_t current = 0; size_t next; do { next = s.find_first_of(delim, current); items.push_back(s.substr(current, next - current)); current = next + 1; - } while (next != std::string::npos); + } while (next != std::string::npos && current != length); } } diff --git a/src/XMLNode.cpp b/src/XMLNode.cpp index 0ddc511..2bf1330 100644 --- a/src/XMLNode.cpp +++ b/src/XMLNode.cpp @@ -379,9 +379,9 @@ void XMLNode::setContent(float32 _fValue) template static std::string setContentList_internal(T* pfList, int _iSize) { - std::string str = (_iSize > 0) ? StringUtil::toString(pfList[0]) : ""; - for (int i = 1; i < _iSize; i++) { - str += "," + StringUtil::toString(pfList[i]); + std::string str; + for (int i = 0; i < _iSize; i++) { + str += StringUtil::toString(pfList[i]) + ","; } return str; } @@ -422,8 +422,7 @@ static std::string setContentMatrix_internal(T* _pfMatrix, int _iWidth, int _iHe for (int x = 1; x < _iWidth; x++) s << "," << _pfMatrix[x*s1 + y*s2]; - if (y != _iHeight-1) - s << ";"; + s << ";"; } return s.str(); -- cgit v1.2.3