Ada 2.7.8
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>
12ada_warn_unused tl::expected<result_type, ada::errors> parse(
13 std::string_view input, const result_type* base_url) {
14 result_type u = ada::parser::parse_url<result_type>(input, base_url);
15 if (!u.is_valid) {
16 return tl::unexpected(errors::generic_error);
17 }
18 return u;
19}
20
21template ada::result<url> parse<url>(std::string_view input,
22 const url* base_url = nullptr);
24 std::string_view input, const url_aggregator* base_url = nullptr);
25
26std::string href_from_file(std::string_view input) {
27 // This is going to be much faster than constructing a URL.
28 std::string tmp_buffer;
29 std::string_view internal_input;
30 if (unicode::has_tabs_or_newline(input)) {
32 helpers::remove_ascii_tab_or_newline(tmp_buffer);
34 } else {
36 }
37 std::string path;
38 if (internal_input.empty()) {
39 path = "/";
40 } else if ((internal_input[0] == '/') || (internal_input[0] == '\\')) {
41 helpers::parse_prepared_path(internal_input.substr(1),
43 } else {
44 helpers::parse_prepared_path(internal_input, ada::scheme::type::FILE, path);
45 }
46 return "file://" + path;
47}
48
49bool can_parse(std::string_view input, const std::string_view* base_input) {
52 if (base_input != nullptr) {
54 if (!base) {
55 return false;
56 }
57 base_pointer = &base.value();
58 }
60}
61
63 switch (type) {
65 return "UTF-8";
67 return "UTF-16LE";
69 return "UTF-16BE";
70 default:
72 }
73}
74
75} // namespace ada
Includes all definitions for 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)
template ada::result< url > parse< url >(std::string_view input, const url *base_url)
std::string href_from_file(std::string_view path)
ada_warn_unused std::string to_string(encoding_type type)
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)
Definitions for the parser.
Lightweight URL struct.
Declaration for the URL.
Declaration for the basic URL definitions.