util/SplitString: convert parameter to std::string_view

This commit is contained in:
Max Kellermann 2020-04-03 16:38:55 +02:00
parent ae4fd576bf
commit 870151214d
3 changed files with 9 additions and 7 deletions

View File

@ -591,7 +591,7 @@ UpnpDatabase::Visit(const DatabaseSelection &selection,
{
DatabaseVisitorHelper helper(CheckSelection(selection), visit_song);
auto vpath = SplitString(selection.uri.c_str(), '/');
auto vpath = SplitString(selection.uri, '/');
if (vpath.empty()) {
for (const auto &server : discovery->GetDirectories()) {
if (visit_directory) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2013-2016 Max Kellermann <max.kellermann@gmail.com>
* Copyright 2013-2020 Max Kellermann <max.kellermann@gmail.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -32,13 +32,14 @@
#include "StringStrip.hxx"
std::forward_list<std::string>
SplitString(const char *s, char separator, bool strip) noexcept
SplitString(std::string_view _s, char separator, bool strip) noexcept
{
StringView s(_s);
if (strip)
s = StripLeft(s);
s.StripLeft();
std::forward_list<std::string> list;
if (*s == 0)
if (s.empty())
return list;
auto i = list.before_begin();

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2013-2016 Max Kellermann <max.kellermann@gmail.com>
* Copyright 2013-2020 Max Kellermann <max.kellermann@gmail.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -32,6 +32,7 @@
#include <forward_list>
#include <string>
#include <string_view>
/**
* Split a string at a certain separator character into sub strings
@ -44,6 +45,6 @@
* (and not a list with an empty string).
*/
std::forward_list<std::string>
SplitString(const char *s, char separator, bool strip=true) noexcept;
SplitString(std::string_view s, char separator, bool strip=true) noexcept;
#endif