summaryrefslogtreecommitdiffstats
path: root/src/Utilities.cpp
diff options
context:
space:
mode:
authorWillem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl>2017-08-31 16:47:29 +0200
committerWillem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl>2017-10-17 20:35:30 +0200
commit8d8a3d26372d9c0a784e181121fc2b360f6fee51 (patch)
treeb04d799efded02263306f3f41974ed4491b0d571 /src/Utilities.cpp
parent7b25c857ded357c0cb0b481dac6404c27ed0293d (diff)
downloadastra-8d8a3d26372d9c0a784e181121fc2b360f6fee51.tar.gz
astra-8d8a3d26372d9c0a784e181121fc2b360f6fee51.tar.bz2
astra-8d8a3d26372d9c0a784e181121fc2b360f6fee51.tar.xz
astra-8d8a3d26372d9c0a784e181121fc2b360f6fee51.zip
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.
Diffstat (limited to 'src/Utilities.cpp')
-rw-r--r--src/Utilities.cpp9
1 files changed, 6 insertions, 3 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);
}
}