util/MimeType: migrate GetMimeTypeBase() to std::string_view

This commit is contained in:
Max Kellermann
2020-11-04 20:27:28 +01:00
parent bab626c325
commit bb07fd42ce
4 changed files with 21 additions and 23 deletions

View File

@@ -19,16 +19,12 @@
#include "MimeType.hxx"
#include "SplitString.hxx"
#include "StringView.hxx"
#include <cstring>
std::string
GetMimeTypeBase(const char *s) noexcept
std::string_view
GetMimeTypeBase(std::string_view s) noexcept
{
const char *semicolon = std::strchr(s, ';');
return semicolon != nullptr
? std::string(s, semicolon)
: std::string(s);
return StringView(s).Split(';').first;
}
std::map<std::string, std::string>

View File

@@ -20,7 +20,10 @@
#ifndef MPD_MIME_TYPE_HXX
#define MPD_MIME_TYPE_HXX
#include "util/Compiler.h"
#include <string>
#include <string_view>
#include <map>
/**
@@ -28,8 +31,9 @@
* part before the semicolon. If there is no semicolon, it returns
* the string as-is.
*/
std::string
GetMimeTypeBase(const char *s) noexcept;
gcc_pure
std::string_view
GetMimeTypeBase(std::string_view s) noexcept;
/**
* Parse the parameters from a MIME type string. Parameters are