2023-03-06 14:42:04 +01:00
|
|
|
// SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
// author: Max Kellermann <max.kellermann@gmail.com>
|
2014-12-03 21:39:45 +01:00
|
|
|
|
|
|
|
#include "SplitString.hxx"
|
2016-03-18 14:03:00 +01:00
|
|
|
#include "IterableSplitString.hxx"
|
2017-07-05 17:20:02 +02:00
|
|
|
#include "StringStrip.hxx"
|
2014-12-03 21:39:45 +01:00
|
|
|
|
2020-04-03 16:42:49 +02:00
|
|
|
std::forward_list<std::string_view>
|
2022-07-01 11:13:43 +02:00
|
|
|
SplitString(std::string_view s, char separator, bool strip) noexcept
|
2014-12-03 21:39:45 +01:00
|
|
|
{
|
|
|
|
if (strip)
|
2022-07-01 11:13:43 +02:00
|
|
|
s = StripLeft(s);
|
2014-12-03 21:39:45 +01:00
|
|
|
|
2020-04-03 16:42:49 +02:00
|
|
|
std::forward_list<std::string_view> list;
|
2020-04-03 16:38:55 +02:00
|
|
|
if (s.empty())
|
2014-12-03 21:39:45 +01:00
|
|
|
return list;
|
|
|
|
|
|
|
|
auto i = list.before_begin();
|
|
|
|
|
2016-03-18 14:03:00 +01:00
|
|
|
for (auto value : IterableSplitString(s, separator)) {
|
2020-04-03 16:42:49 +02:00
|
|
|
if (strip)
|
2022-07-01 11:13:43 +02:00
|
|
|
value = Strip(value);
|
2014-12-03 21:39:45 +01:00
|
|
|
|
2020-04-03 16:42:49 +02:00
|
|
|
i = list.emplace_after(i, value);
|
2014-12-03 21:39:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|