Commit 2a913149 authored by Max Kellermann's avatar Max Kellermann

util/UriExtract: pass std::string_view to uri_get_suffix()

parent 35a23210
...@@ -164,7 +164,7 @@ GetChromaprintCommand::DecodeStream(InputStream &is, ...@@ -164,7 +164,7 @@ GetChromaprintCommand::DecodeStream(InputStream &is,
inline void inline void
GetChromaprintCommand::DecodeStream(InputStream &is) GetChromaprintCommand::DecodeStream(InputStream &is)
{ {
const auto suffix = uri_get_suffix(uri.c_str()); const auto suffix = uri_get_suffix(uri);
decoder_plugins_try([this, &is, suffix](const DecoderPlugin &plugin){ decoder_plugins_try([this, &is, suffix](const DecoderPlugin &plugin){
return DecodeStream(is, suffix, plugin); return DecodeStream(is, suffix, plugin);
...@@ -222,7 +222,7 @@ GetChromaprintCommand::DecodeFile(std::string_view suffix, InputStream &is, ...@@ -222,7 +222,7 @@ GetChromaprintCommand::DecodeFile(std::string_view suffix, InputStream &is,
inline void inline void
GetChromaprintCommand::DecodeFile() GetChromaprintCommand::DecodeFile()
{ {
const auto suffix = uri_get_suffix(uri.c_str()); const auto suffix = uri_get_suffix(uri);
if (suffix.empty()) if (suffix.empty())
return; return;
......
...@@ -122,20 +122,21 @@ uri_get_path(std::string_view uri) noexcept ...@@ -122,20 +122,21 @@ uri_get_path(std::string_view uri) noexcept
/* suffixes should be ascii only characters */ /* suffixes should be ascii only characters */
std::string_view std::string_view
uri_get_suffix(const char *uri) noexcept uri_get_suffix(std::string_view _uri) noexcept
{ {
const char *suffix = std::strrchr(uri, '.'); StringView uri(_uri);
if (suffix == nullptr || suffix == uri || const char *dot = uri.FindLast('.');
suffix[-1] == '/' || suffix[-1] == '\\') if (dot == nullptr || dot == uri.data ||
dot[-1] == '/' || dot[-1] == '\\')
return {}; return {};
++suffix; auto suffix = uri.substr(dot + 1);
if (suffix.Find('/') != nullptr || suffix.Find('\\') != nullptr)
if (strpbrk(suffix, "/\\") != nullptr) /* this was not the last path segment */
return {}; return {};
/* remove the query string */ /* remove the query string */
return StringView(suffix).Split('?').first; return suffix.Split('?').first;
} }
const char * const char *
......
...@@ -63,7 +63,7 @@ uri_get_path(std::string_view uri) noexcept; ...@@ -63,7 +63,7 @@ uri_get_path(std::string_view uri) noexcept;
gcc_pure gcc_pure
std::string_view std::string_view
uri_get_suffix(const char *uri) noexcept; uri_get_suffix(std::string_view uri) noexcept;
/** /**
* Returns the URI fragment, i.e. the portion after the '#', but * Returns the URI fragment, i.e. the portion after the '#', but
......
...@@ -48,7 +48,8 @@ FindContainerDecoderPlugin(std::string_view suffix) ...@@ -48,7 +48,8 @@ FindContainerDecoderPlugin(std::string_view suffix)
static const DecoderPlugin * static const DecoderPlugin *
FindContainerDecoderPlugin(Path path) FindContainerDecoderPlugin(Path path)
{ {
const auto suffix = uri_get_suffix(path.ToUTF8Throw().c_str()); const auto path_utf8 = path.ToUTF8Throw();
const auto suffix = uri_get_suffix(path_utf8);
if (suffix.empty()) if (suffix.empty())
return nullptr; return nullptr;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment