Skip to content

Commit a26ce5b

Browse files
author
Daniel Kroening
authored
Merge pull request #5190 from diffblue/fix_split_string
Fix split_string remove_empty case
2 parents 7f07693 + 77897ac commit a26ce5b

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

src/util/string_utils.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ void split_string(
5050

5151
if(s.empty())
5252
{
53-
result.push_back("");
53+
if(!remove_empty)
54+
result.push_back("");
5455
return;
5556
}
5657

@@ -84,7 +85,7 @@ void split_string(
8485
if(!remove_empty || !new_s.empty())
8586
result.push_back(new_s);
8687

87-
if(result.empty())
88+
if(!remove_empty && result.empty())
8889
result.push_back("");
8990
}
9091

unit/util/string_utils/split_string.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,8 @@ SCENARIO("split_string", "[core][utils][string_utils][split_string]")
113113
expected_resultst expected_results;
114114
expected_results.no_strip_no_remove = {""};
115115
expected_results.strip_no_remove = {""};
116-
117-
// TODO(tkiley): This is probably wrong, since I'd expect removing empty
118-
// TODO(tkiley): elements to return an empty vector here.
119-
expected_results.no_strip_remove_empty = {""};
120-
expected_results.strip_remove_empty = {""};
116+
expected_results.no_strip_remove_empty = {};
117+
expected_results.strip_remove_empty = {};
121118

122119
run_on_all_variants(string, ',', expected_results);
123120
}
@@ -131,9 +128,7 @@ SCENARIO("split_string", "[core][utils][string_utils][split_string]")
131128
expected_results.no_strip_no_remove = {" "};
132129
expected_results.strip_no_remove = {""};
133130
expected_results.no_strip_remove_empty = {" "};
134-
// TODO(tkiley): This is probably wrong, since I'd expect removing empty
135-
// TODO(tkiley): elements to return an empty vector here.
136-
expected_results.strip_remove_empty = {""};
131+
expected_results.strip_remove_empty = {};
137132

138133
run_on_all_variants(string, ',', expected_results);
139134
}

0 commit comments

Comments
 (0)