util/UriQueryParser: use std::string_view

This commit is contained in:
Max Kellermann
2022-07-01 11:08:20 +02:00
parent ca46b4d7a7
commit 6d23ac67f9
5 changed files with 22 additions and 38 deletions
+12 -12
View File
@@ -30,20 +30,20 @@
#include "UriQueryParser.hxx"
#include "IterableSplitString.hxx"
StringView
UriFindRawQueryParameter(StringView query_string, StringView name) noexcept
{
for (StringView i : IterableSplitString(query_string, '&')) {
if (i.StartsWith(name)) {
if (i.size == name.size)
return "";
using std::string_view_literals::operator""sv;
if (i[name.size] == '=') {
i.skip_front(name.size + 1);
return i;
}
std::string_view
UriFindRawQueryParameter(std::string_view query_string, std::string_view name) noexcept
{
for (const std::string_view i : IterableSplitString(query_string, '&')) {
if (i.starts_with(name)) {
if (i.size() == name.size())
return ""sv;
if (i[name.size()] == '=')
return i.substr(name.size() + 1);
}
}
return nullptr;
return {};
}
+5 -8
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2008-2019 Max Kellermann <max.kellermann@gmail.com>
* Copyright 2008-2022 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
@@ -27,10 +27,9 @@
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef URI_QUERY_PARSER_HXX
#define URI_QUERY_PARSER_HXX
#pragma once
struct StringView;
#include <string_view>
/**
* Find the first query parameter with the given name and return its
@@ -40,7 +39,5 @@ struct StringView;
* or nullptr if the parameter does not exist
*/
[[gnu::pure]]
StringView
UriFindRawQueryParameter(StringView query_string, StringView name) noexcept;
#endif
std::string_view
UriFindRawQueryParameter(std::string_view query_string, std::string_view name) noexcept;