diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Utilities.cpp | 9 | ||||
-rw-r--r-- | src/XMLNode.cpp | 9 |
2 files changed, 10 insertions, 8 deletions
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<double> 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<double> 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<typename T> std::vector<T> stringToVector(const std::string& s) { std::vector<T> out; + size_t length = s.size(); size_t current = 0; size_t next; do { @@ -104,7 +106,7 @@ std::vector<T> stringToVector(const std::string& s) std::string t = s.substr(current, next - current); out.push_back(stringTo<T>(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<std::string> &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<typename T> 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(); |