util/UriExtract: uri_get_suffix() returns std::string_view
No need to copy it to a buffer.
This commit is contained in:
@@ -37,7 +37,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
static const DecoderPlugin *
|
||||
FindContainerDecoderPlugin(const char *suffix)
|
||||
FindContainerDecoderPlugin(std::string_view suffix)
|
||||
{
|
||||
return decoder_plugins_find([suffix](const DecoderPlugin &plugin){
|
||||
return plugin.container_scan != nullptr &&
|
||||
@@ -48,10 +48,8 @@ FindContainerDecoderPlugin(const char *suffix)
|
||||
static const DecoderPlugin *
|
||||
FindContainerDecoderPlugin(Path path)
|
||||
{
|
||||
UriSuffixBuffer suffix_buffer;
|
||||
const char *const suffix = uri_get_suffix(path.ToUTF8Throw().c_str(),
|
||||
suffix_buffer);
|
||||
if (suffix == nullptr)
|
||||
const auto suffix = uri_get_suffix(path.ToUTF8Throw().c_str());
|
||||
if (suffix.empty())
|
||||
return nullptr;
|
||||
|
||||
return FindContainerDecoderPlugin(suffix);
|
||||
|
@@ -6,28 +6,17 @@
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
using std::string_view_literals::operator""sv;
|
||||
|
||||
TEST(UriExtract, Suffix)
|
||||
{
|
||||
EXPECT_EQ((const char *)nullptr, uri_get_suffix("/foo/bar"));
|
||||
EXPECT_EQ((const char *)nullptr, uri_get_suffix("/foo.jpg/bar"));
|
||||
EXPECT_STREQ(uri_get_suffix("/foo/bar.jpg"), "jpg");
|
||||
EXPECT_STREQ(uri_get_suffix("/foo.png/bar.jpg"), "jpg");
|
||||
EXPECT_EQ((const char *)nullptr, uri_get_suffix(".jpg"));
|
||||
EXPECT_EQ((const char *)nullptr, uri_get_suffix("/foo/.jpg"));
|
||||
EXPECT_EQ((const char *)nullptr, uri_get_suffix("/foo/bar").data());
|
||||
EXPECT_EQ((const char *)nullptr, uri_get_suffix("/foo.jpg/bar").data());
|
||||
EXPECT_EQ(uri_get_suffix("/foo/bar.jpg"), "jpg"sv);
|
||||
EXPECT_EQ(uri_get_suffix("/foo.png/bar.jpg"), "jpg"sv);
|
||||
EXPECT_EQ((const char *)nullptr, uri_get_suffix(".jpg").data());
|
||||
EXPECT_EQ((const char *)nullptr, uri_get_suffix("/foo/.jpg").data());
|
||||
|
||||
/* the first overload does not eliminate the query
|
||||
string */
|
||||
EXPECT_STREQ(uri_get_suffix("/foo/bar.jpg?query_string"),
|
||||
"jpg?query_string");
|
||||
|
||||
/* ... but the second one does */
|
||||
UriSuffixBuffer buffer;
|
||||
EXPECT_STREQ(uri_get_suffix("/foo/bar.jpg?query_string", buffer),
|
||||
"jpg");
|
||||
|
||||
/* repeat some of the above tests with the second overload */
|
||||
EXPECT_EQ((const char *)nullptr, uri_get_suffix("/foo/bar", buffer));
|
||||
EXPECT_EQ((const char *)nullptr,
|
||||
uri_get_suffix("/foo.jpg/bar", buffer));
|
||||
EXPECT_STREQ(uri_get_suffix("/foo/bar.jpg", buffer), "jpg");
|
||||
/* eliminate the query string */
|
||||
EXPECT_EQ(uri_get_suffix("/foo/bar.jpg?query_string"), "jpg"sv);
|
||||
}
|
||||
|
Reference in New Issue
Block a user