fix: Check for empty string in strn fns
This commit is contained in:
1 parent
9d81354c3a
commit
58edd07f6b
1 file changed
+6
@@ -104,6 +104,9 @@ std::pair<const char *, size_t> find_trim_strn(std::array<char, N> const &in) {
|
||||
while (i > 0 && (in[i - 1] == ' ' || in[i - 1] == 0)) {
|
||||
i--;
|
||||
}
|
||||
if (i == 0) {
|
||||
return {nullptr, 0};
|
||||
}
|
||||
return {&in[0], i};
|
||||
}
|
||||
|
||||
@@ -116,6 +119,9 @@ std::string to_trim_str(T const &t) {
|
||||
template <class T>
|
||||
std::string to_trim_strn(T const &t) {
|
||||
auto ts = find_trim_strn(t.value());
|
||||
if (ts.second == 0) {
|
||||
return {};
|
||||
}
|
||||
return std::string{ts.first, ts.second};
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user