Skip to content

Commit d3ff0a1

Browse files
author
thk123
committed
Replace asserts in string utils
1 parent be07a05 commit d3ff0a1

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/util/string_utils.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Author: Daniel Poetzl
77
\*******************************************************************/
88

99
#include "string_utils.h"
10+
#include "invariant.h"
1011

1112
#include <cassert>
1213
#include <cctype>
@@ -51,8 +52,14 @@ void split_string(
5152
bool strip,
5253
bool remove_empty)
5354
{
54-
assert(result.empty());
55-
assert(!strip || !std::isspace(delim));
55+
if(!result.empty())
56+
throw std::invalid_argument("result: vector must be empty");
57+
58+
if(strip && std::isspace(delim))
59+
{
60+
throw std::invalid_argument(
61+
"delim can't be a space character if using strip");
62+
}
5663

5764
if(s.empty())
5865
{
@@ -61,7 +68,7 @@ void split_string(
6168
}
6269

6370
std::string::size_type n=s.length();
64-
assert(n>0);
71+
INVARIANT(n > 0, "Empty string case should already be handled");
6572

6673
std::string::size_type start=0;
6774
std::string::size_type i;
@@ -101,7 +108,11 @@ void split_string(
101108
std::string &right,
102109
bool strip)
103110
{
104-
assert(!std::isspace(delim));
111+
if(strip && std::isspace(delim))
112+
{
113+
throw std::invalid_argument(
114+
"delim can't be a space character if using strip");
115+
}
105116

106117
std::vector<std::string> result;
107118

0 commit comments

Comments
 (0)