Skip to content

Commit 946411c

Browse files
author
thk123
committed
Allowed split_string to be used on whitespace if not also trying to strip
Also improved comments as I assumed strip would remove whitespace from throughout the string but actually only does the final string
1 parent 61f14d8 commit 946411c

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/util/string_utils.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ Author: Daniel Poetzl
1212
#include <cctype>
1313
#include <algorithm>
1414

15+
/// Remove all whitespace characters from the end of a string. Whitespace
16+
/// in the middle of the string is left unchanged
17+
/// \param s: the string to strip
18+
/// \return The stripped string
1519
std::string strip_string(const std::string &s)
1620
{
1721
auto pred=[](char c){ return std::isspace(c); };
@@ -38,7 +42,7 @@ void split_string(
3842
bool remove_empty)
3943
{
4044
assert(result.empty());
41-
assert(!std::isspace(delim));
45+
assert(!strip || !std::isspace(delim));
4246

4347
if(s.empty())
4448
{

src/util/string_utils.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ std::string strip_string(const std::string &s);
1818

1919
void split_string(
2020
const std::string &s,
21-
char delim, // must not be a whitespace character
21+
char delim, // must not be a whitespace character if strip is enabled
2222
std::vector<std::string> &result,
23-
bool strip=false, // strip whitespace from elements
24-
bool remove_empty=false); // remove empty elements
23+
bool strip = false, // strip whitespace from the end of elements
24+
bool remove_empty = false); // remove empty elements
2525

2626
void split_string(
2727
const std::string &s,

0 commit comments

Comments
 (0)