File tree 1 file changed +15
-4
lines changed 1 file changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ Author: Daniel Poetzl
7
7
\*******************************************************************/
8
8
9
9
#include " string_utils.h"
10
+ #include " invariant.h"
10
11
11
12
#include < cassert>
12
13
#include < cctype>
@@ -51,8 +52,14 @@ void split_string(
51
52
bool strip,
52
53
bool remove_empty)
53
54
{
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
+ }
56
63
57
64
if (s.empty ())
58
65
{
@@ -61,7 +68,7 @@ void split_string(
61
68
}
62
69
63
70
std::string::size_type n=s.length ();
64
- assert (n> 0 );
71
+ INVARIANT (n > 0 , " Empty string case should already be handled " );
65
72
66
73
std::string::size_type start=0 ;
67
74
std::string::size_type i;
@@ -101,7 +108,11 @@ void split_string(
101
108
std::string &right,
102
109
bool strip)
103
110
{
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
+ }
105
116
106
117
std::vector<std::string> result;
107
118
You can’t perform that action at this time.
0 commit comments