Skip to content

Commit 68a21c5

Browse files
committed
Fix substring calculation in CSV cell parsing and add lexical_cast for signed and unsigned char
1 parent 92c873e commit 68a21c5

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

include/xtensor/io/xcsv.hpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ namespace xt
6666
}
6767

6868
size_t last = cell.find_last_not_of(' ');
69-
return cell.substr(first, last == std::string::npos ? cell.size() : last + 1);
69+
return cell.substr(first, last == std::string::npos ? cell.size() : last - first + 1);
7070
}
7171

7272
template <>
@@ -93,6 +93,18 @@ namespace xt
9393
return std::stoi(cell);
9494
}
9595

96+
template <>
97+
inline signed char lexical_cast<signed char>(const std::string& cell)
98+
{
99+
return static_cast<signed char>(std::stoi(cell));
100+
}
101+
102+
template <>
103+
inline unsigned char lexical_cast<unsigned char>(const std::string& cell)
104+
{
105+
return static_cast<unsigned char>(std::stoul(cell));
106+
}
107+
96108
template <>
97109
inline long lexical_cast<long>(const std::string& cell)
98110
{

0 commit comments

Comments
 (0)