File tree Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments