util/UriExtract: use std::string_view instead of StringView
This commit is contained in:
@@ -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
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@@ -29,9 +29,9 @@
|
|||||||
|
|
||||||
#include "UriExtract.hxx"
|
#include "UriExtract.hxx"
|
||||||
#include "CharUtil.hxx"
|
#include "CharUtil.hxx"
|
||||||
#include "StringView.hxx"
|
#include "StringSplit.hxx"
|
||||||
|
|
||||||
#include <string.h>
|
#include <cstring>
|
||||||
|
|
||||||
static constexpr bool
|
static constexpr bool
|
||||||
IsValidSchemeStart(char ch)
|
IsValidSchemeStart(char ch)
|
||||||
@@ -121,10 +121,10 @@ uri_get_path(std::string_view uri) noexcept
|
|||||||
}
|
}
|
||||||
|
|
||||||
[[gnu::pure]]
|
[[gnu::pure]]
|
||||||
static StringView
|
static std::string_view
|
||||||
UriWithoutQueryString(StringView uri) noexcept
|
UriWithoutQueryString(std::string_view uri) noexcept
|
||||||
{
|
{
|
||||||
return uri.Split('?').first;
|
return Split(uri, '?').first;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* suffixes should be ascii only characters */
|
/* suffixes should be ascii only characters */
|
||||||
@@ -133,13 +133,14 @@ uri_get_suffix(std::string_view _uri) noexcept
|
|||||||
{
|
{
|
||||||
const auto uri = UriWithoutQueryString(_uri);
|
const auto uri = UriWithoutQueryString(_uri);
|
||||||
|
|
||||||
const char *dot = uri.FindLast('.');
|
const auto dot = uri.rfind('.');
|
||||||
if (dot == nullptr || dot == uri.data ||
|
if (dot == uri.npos || dot == 0 ||
|
||||||
dot[-1] == '/' || dot[-1] == '\\')
|
uri[dot - 1] == '/' || uri[dot - 1] == '\\')
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
auto suffix = uri.substr(dot + 1);
|
auto suffix = uri.substr(dot + 1);
|
||||||
if (suffix.Find('/') != nullptr || suffix.Find('\\') != nullptr)
|
if (suffix.find('/') != suffix.npos ||
|
||||||
|
suffix.find('\\') != suffix.npos)
|
||||||
/* this was not the last path segment */
|
/* this was not the last path segment */
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
|
@@ -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
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@@ -27,8 +27,7 @@
|
|||||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef URI_EXTRACT_HXX
|
#pragma once
|
||||||
#define URI_EXTRACT_HXX
|
|
||||||
|
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
|
||||||
@@ -67,10 +66,8 @@ 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
|
||||||
* without the '#'. If there is no '#', this function returns
|
* without the '#'. If there is no '#', this function returns
|
||||||
* nullptr; if there is a '#' but no fragment text, it returns an
|
* nullptr; if there is a '#' but no fragment text, it returns an
|
||||||
* empty StringView.
|
* empty std::string_view.
|
||||||
*/
|
*/
|
||||||
[[gnu::pure]] [[gnu::nonnull]]
|
[[gnu::pure]] [[gnu::nonnull]]
|
||||||
const char *
|
const char *
|
||||||
uri_get_fragment(const char *uri) noexcept;
|
uri_get_fragment(const char *uri) noexcept;
|
||||||
|
|
||||||
#endif
|
|
||||||
|
Reference in New Issue
Block a user