Audacity 3.2.0
Functions
UriParser.cpp File Reference
#include "UriParser.h"
Include dependency graph for UriParser.cpp:

Go to the source code of this file.

Functions

UriFields ParseUri (std::string_view uri) noexcept
 
QueryFields ParseUriQuery (std::string_view query, std::string_view delimiter) noexcept
 Parses URI query and returns QueryFields structure with parsed fields. More...
 

Function Documentation

◆ ParseUri()

UriFields ParseUri ( std::string_view  uri)
noexcept

Parses URI and returns UriFields structure with parsed fields. {Scheme}://[{UserInfo}@]{Host}[:{Port}][/{Path}][?{Query}][#{Fragment}]

Definition at line 9 of file UriParser.cpp.

10{
11 UriFields result;
12 auto schemeEnd = uri.find("://");
13 if (schemeEnd != std::string_view::npos)
14 {
15 result.Scheme = uri.substr(0, schemeEnd);
16 uri.remove_prefix(schemeEnd + 3);
17 }
18
19 auto fragmentStart = uri.find('#');
20 if (fragmentStart != std::string_view::npos)
21 {
22 result.Fragment = uri.substr(fragmentStart + 1);
23 uri.remove_suffix(uri.size() - fragmentStart);
24 }
25
26 auto queryStart = uri.find('?');
27 if (queryStart != std::string_view::npos)
28 {
29 result.Query = uri.substr(queryStart + 1);
30 uri.remove_suffix(uri.size() - queryStart);
31 }
32
33 auto pathStart = uri.find('/');
34 if (pathStart != std::string_view::npos)
35 {
36 result.Path = uri.substr(pathStart + 1);
37 uri.remove_suffix(uri.size() - pathStart);
38 }
39
40 auto userInfoEnd = uri.find('@');
41 if (userInfoEnd != std::string_view::npos)
42 {
43 result.UserInfo = uri.substr(0, userInfoEnd);
44 uri.remove_prefix(userInfoEnd + 1);
45 }
46
47 auto portStart = uri.find(':');
48 if (portStart != std::string_view::npos)
49 {
50 result.Port = uri.substr(portStart + 1);
51 uri.remove_suffix(uri.size() - portStart);
52 }
53
54 result.Host = uri;
55
56 return result;
57}
constexpr size_t npos(-1)
std::string_view UserInfo
Definition: UriParser.h:14
std::string_view Port
Definition: UriParser.h:16
std::string_view Fragment
Definition: UriParser.h:19
std::string_view Host
Definition: UriParser.h:15
std::string_view Query
Definition: UriParser.h:18
std::string_view Scheme
Definition: UriParser.h:13
std::string_view Path
Definition: UriParser.h:17

References UriFields::Fragment, UriFields::Host, Tuple::detail::npos(), UriFields::Path, UriFields::Port, UriFields::Query, UriFields::Scheme, and UriFields::UserInfo.

Referenced by audacity::cloud::audiocom::sync::HandleMixdownLink(), audacity::cloud::audiocom::sync::HandleProjectLink(), audacity::cloud::audiocom::sync::anonymous_namespace{ResumedSnaphotUploadOperation.cpp}::IsUrlExpired(), and TEST_CASE().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ParseUriQuery()

QueryFields ParseUriQuery ( std::string_view  query,
std::string_view  delimiter 
)
noexcept

Parses URI query and returns QueryFields structure with parsed fields.

Definition at line 59 of file UriParser.cpp.

60{
61 QueryFields result;
62
63 while (!query.empty())
64 {
65 const auto queryItemEnd = query.find(delimiter);
66 const auto queryItem = query.substr(0, queryItemEnd);
67
68 query.remove_prefix(
69 queryItemEnd != std::string_view::npos ? queryItemEnd + 1 :
70 query.size());
71
72 const auto queryItemValueStart = queryItem.find('=');
73
74 const auto queryItemValue = queryItem.substr(
75 queryItemValueStart != std::string_view::npos ?
76 queryItemValueStart + 1 :
77 queryItem.size());
78
79 const auto queryItemKey = queryItem.substr(
80 0, queryItemValueStart != std::string_view::npos ?
81 queryItemValueStart :
82 queryItem.size());
83
84 result.emplace(queryItemKey, queryItemValue);
85 }
86
87 return result;
88}
std::unordered_map< std::string_view, std::string_view > QueryFields
Definition: UriParser.h:27

References Tuple::detail::npos().

Referenced by audacity::cloud::audiocom::sync::HandleMixdownLink(), audacity::cloud::audiocom::sync::HandleProjectLink(), audacity::cloud::audiocom::sync::anonymous_namespace{ResumedSnaphotUploadOperation.cpp}::IsUrlExpired(), and TEST_CASE().

Here is the call graph for this function:
Here is the caller graph for this function: