Loading...
Searching...
No Matches
implementation.cpp
Go to the documentation of this file.
#include "ada/implementation-inl.h"
#include <string_view>
#include "ada/common_defs.h"
#include "ada/parser.h"
#include "ada/url.h"
#include "ada/url_aggregator.h"
namespace ada {
template <class result_type>
ada_warn_unused tl::expected<result_type, errors> parse(
std::string_view input, const result_type* base_url) {
result_type u =
ada::parser::parse_url_impl<result_type, true>(input, base_url);
if (!u.is_valid) {
return tl::unexpected(errors::type_error);
}
return u;
}
template ada::result<url> parse<url>(std::string_view input,
const url* base_url = nullptr);
template ada::result<url_aggregator> parse<url_aggregator>(
std::string_view input, const url_aggregator* base_url = nullptr);
std::string href_from_file(std::string_view input) {
// This is going to be much faster than constructing a URL.
std::string tmp_buffer;
std::string_view internal_input;
if (unicode::has_tabs_or_newline(input)) {
tmp_buffer = input;
helpers::remove_ascii_tab_or_newline(tmp_buffer);
internal_input = tmp_buffer;
} else {
internal_input = input;
}
std::string path;
if (internal_input.empty()) {
path = "/";
} else if ((internal_input[0] == '/') || (internal_input[0] == '\\')) {
helpers::parse_prepared_path(internal_input.substr(1),
ada::scheme::type::FILE, path);
} else {
helpers::parse_prepared_path(internal_input, ada::scheme::type::FILE, path);
}
return "file://" + path;
}
bool can_parse(std::string_view input, const std::string_view* base_input) {
ada::url_aggregator base_aggregator;
ada::url_aggregator* base_pointer = nullptr;
if (base_input != nullptr) {
base_aggregator = ada::parser::parse_url_impl<ada::url_aggregator, false>(
*base_input, nullptr);
if (!base_aggregator.is_valid) {
return false;
}
base_pointer = &base_aggregator;
}
ada::url_aggregator result =
ada::parser::parse_url_impl<ada::url_aggregator, false>(input,
base_pointer);
return result.is_valid;
}
ada_warn_unused std::string_view to_string(ada::encoding_type type) {
switch (type) {
case ada::encoding_type::UTF8:
return "UTF-8";
case ada::encoding_type::UTF_16LE:
return "UTF-16LE";
case ada::encoding_type::UTF_16BE:
return "UTF-16BE";
default:
unreachable();
}
}
} // namespace ada
common_defs.h
Cross-platform compiler macros and common definitions.
ada_warn_unused
#define ada_warn_unused
Definition common_defs.h:89
implementation-inl.h
ada::parser::parse_url_impl
result_type parse_url_impl(std::string_view user_input, const result_type *base_url=nullptr)
Definition parser.cpp:14
ada::scheme::FILE
@ FILE
Definition scheme.h:48
ada
Definition ada_idna.h:13
ada::can_parse
bool can_parse(std::string_view input, const std::string_view *base_input=nullptr)
Definition implementation.cpp:51
ada::parse< url >
template ada::result< url > parse< url >(std::string_view input, const url *base_url)
ada::href_from_file
std::string href_from_file(std::string_view path)
Definition implementation.cpp:28
ada::errors::type_error
@ type_error
Definition errors.h:18
ada::parse< url_aggregator >
template ada::result< url_aggregator > parse< url_aggregator >(std::string_view input, const url_aggregator *base_url)
ada::encoding_type
encoding_type
Character encoding types for URL processing.
Definition encoding_type.h:25
ada::encoding_type::UTF_16LE
@ UTF_16LE
Definition encoding_type.h:27
ada::encoding_type::UTF8
@ UTF8
Definition encoding_type.h:26
ada::encoding_type::UTF_16BE
@ UTF_16BE
Definition encoding_type.h:28
ada::to_string
ada_warn_unused std::string_view to_string(encoding_type type)
Definition implementation.cpp:70
ada::unreachable
void unreachable()
Definition common_defs.h:161
ada::result
tl::expected< result_type, ada::errors > result
Definition implementation.h:44
ada::parse
ada_warn_unused ada::result< result_type > parse(std::string_view input, const result_type *base_url=nullptr)
Definition implementation.cpp:13
parser.h
Low-level URL parsing functions.
ada::url_aggregator
Memory-efficient URL representation using a single buffer.
Definition url_aggregator.h:46
ada::url_base::is_valid
bool is_valid
Definition url_base.h:56
url.h
Declaration for the ada::url class.
url_aggregator.h
Declaration for the ada::url_aggregator class.