Ada 2.9.2
Fast spec-compliant URL parser
Loading...
Searching...
No Matches
implementation.cpp
Go to the documentation of this file.
1#include <string_view>
2
3#include "ada.h"
4#include "ada/common_defs.h"
5#include "ada/parser.h"
6#include "ada/url.h"
8
9namespace ada {
10
11template <class result_type>
13 std::string_view input, const result_type* base_url) {
15 ada::parser::parse_url_impl<result_type, true>(input, base_url);
16 if (!u.is_valid) {
18 }
19 return u;
20}
21
22template ada::result<url> parse<url>(std::string_view input,
23 const url* base_url = nullptr);
25 std::string_view input, const url_aggregator* base_url = nullptr);
26
27std::string href_from_file(std::string_view input) {
28 // This is going to be much faster than constructing a URL.
29 std::string tmp_buffer;
30 std::string_view internal_input;
31 if (unicode::has_tabs_or_newline(input)) {
33 helpers::remove_ascii_tab_or_newline(tmp_buffer);
35 } else {
37 }
38 std::string path;
39 if (internal_input.empty()) {
40 path = "/";
41 } else if ((internal_input[0] == '/') || (internal_input[0] == '\\')) {
42 helpers::parse_prepared_path(internal_input.substr(1),
43 ada::scheme::type::FILE, path);
44 } else {
45 helpers::parse_prepared_path(internal_input, ada::scheme::type::FILE, path);
46 }
47 return "file://" + path;
48}
49
50bool can_parse(std::string_view input, const std::string_view* base_input) {
53
54 if (base_input != nullptr) {
55 base_aggregator = ada::parser::parse_url_impl<ada::url_aggregator, false>(
56 *base_input, nullptr);
57 if (!base_aggregator.is_valid) {
58 return false;
59 }
61 }
62
64 ada::parser::parse_url_impl<ada::url_aggregator, false>(input,
66 return result.is_valid;
67}
68
70 switch (type) {
72 return "UTF-8";
74 return "UTF-16LE";
76 return "UTF-16BE";
77 default:
79 }
80}
81
82} // namespace ada
Common definitions for cross-platform compiler support.
#define ada_warn_unused
Definition common_defs.h:88
Definition ada_idna.h:13
bool can_parse(std::string_view input, const std::string_view *base_input=nullptr)
Definition ada.cpp:10389
template ada::result< url > parse< url >(std::string_view input, const url *base_url)
std::string href_from_file(std::string_view path)
Definition ada.cpp:10366
ada_warn_unused std::string to_string(encoding_type type)
Definition ada.cpp:10408
template ada::result< url_aggregator > parse< url_aggregator >(std::string_view input, const url_aggregator *base_url)
encoding_type
void unreachable()
tl::expected< result_type, ada::errors > result
ada_warn_unused ada::result< result_type > parse(std::string_view input, const result_type *base_url=nullptr)
Definition ada.cpp:10351
Definitions for the parser.
Lightweight URL struct.
Declaration for the URL.
Declaration for the basic URL definitions.