util/SplitString: use std::string_view
This commit is contained in:
parent
e6bb6c59ec
commit
ea3f044cd8
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2020 Max Kellermann <max.kellermann@gmail.com>
|
* Copyright 2013-2022 Max Kellermann <max.kellermann@gmail.com>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@ -32,11 +32,10 @@
|
|||||||
#include "StringStrip.hxx"
|
#include "StringStrip.hxx"
|
||||||
|
|
||||||
std::forward_list<std::string_view>
|
std::forward_list<std::string_view>
|
||||||
SplitString(std::string_view _s, char separator, bool strip) noexcept
|
SplitString(std::string_view s, char separator, bool strip) noexcept
|
||||||
{
|
{
|
||||||
StringView s(_s);
|
|
||||||
if (strip)
|
if (strip)
|
||||||
s.StripLeft();
|
s = StripLeft(s);
|
||||||
|
|
||||||
std::forward_list<std::string_view> list;
|
std::forward_list<std::string_view> list;
|
||||||
if (s.empty())
|
if (s.empty())
|
||||||
@ -46,7 +45,7 @@ SplitString(std::string_view _s, char separator, bool strip) noexcept
|
|||||||
|
|
||||||
for (auto value : IterableSplitString(s, separator)) {
|
for (auto value : IterableSplitString(s, separator)) {
|
||||||
if (strip)
|
if (strip)
|
||||||
value.Strip();
|
value = Strip(value);
|
||||||
|
|
||||||
i = list.emplace_after(i, value);
|
i = list.emplace_after(i, value);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2020 Max Kellermann <max.kellermann@gmail.com>
|
* Copyright 2013-2022 Max Kellermann <max.kellermann@gmail.com>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@ -27,8 +27,7 @@
|
|||||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SPLIT_STRING_HXX
|
#pragma once
|
||||||
#define SPLIT_STRING_HXX
|
|
||||||
|
|
||||||
#include <forward_list>
|
#include <forward_list>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
@ -45,5 +44,3 @@
|
|||||||
*/
|
*/
|
||||||
std::forward_list<std::string_view>
|
std::forward_list<std::string_view>
|
||||||
SplitString(std::string_view s, char separator, bool strip=true) noexcept;
|
SplitString(std::string_view s, char separator, bool strip=true) noexcept;
|
||||||
|
|
||||||
#endif
|
|
||||||
|
Loading…
Reference in New Issue
Block a user