#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include <algorithm>
#include <ostream>
#include <string_view>
#include "base/check_op.h"
#include "base/strings/string_util.h"
#include "url/url_canon.h"
#include "url/url_canon_internal.h"
#include "url/url_constants.h"
#include "url/url_features.h"
#include "url/url_file.h"
#include "url/url_parse_internal.h"
#include "url/url_util.h"
#include "url/url_util_internal.h"
namespace url {
namespace {
template<typename CHAR>
bool AreSchemesEqual(const char* base,
const Component& base_scheme,
const CHAR* cmp,
const Component& cmp_scheme) { … }
#ifdef WIN32
template<typename CHAR>
bool DoesBeginSlashWindowsDriveSpec(const CHAR* spec, int start_offset,
int spec_len) {
if (start_offset >= spec_len)
return false;
return IsSlashOrBackslash(spec[start_offset]) &&
DoesBeginWindowsDriveSpec(spec, start_offset + 1, spec_len);
}
#endif
template <typename CHAR>
bool IsValidScheme(const CHAR* url, const Component& scheme) { … }
template<typename CHAR>
bool DoIsRelativeURL(const char* base,
const Parsed& base_parsed,
const CHAR* url,
int url_len,
bool is_base_hierarchical,
bool* is_relative,
Component* relative_component) { … }
void CopyToLastSlash(const char* spec,
int begin,
int end,
CanonOutput* output) { … }
void CopyOneComponent(const char* source,
const Component& source_component,
CanonOutput* output,
Component* output_component) { … }
#ifdef WIN32
template<typename CHAR>
int CopyBaseDriveSpecIfNecessary(const char* base_url,
int base_path_begin,
int base_path_end,
const CHAR* relative_url,
int path_start,
int relative_url_len,
CanonOutput* output) {
if (base_path_begin >= base_path_end)
return base_path_begin;
if (DoesBeginWindowsDriveSpec(relative_url, path_start, relative_url_len)) {
return base_path_begin;
}
if (DoesBeginSlashWindowsDriveSpec(base_url,
base_path_begin,
base_path_end)) {
output->push_back('/');
output->push_back(base_url[base_path_begin + 1]);
output->push_back(base_url[base_path_begin + 2]);
return base_path_begin + 3;
}
return base_path_begin;
}
#endif
template <typename CHAR>
bool DoResolveRelativePath(const char* base_url,
const Parsed& base_parsed,
bool base_is_file,
const CHAR* relative_url,
const Component& relative_component,
CharsetConverter* query_converter,
CanonMode canon_mode,
CanonOutput* output,
Parsed* out_parsed) { … }
template<typename CHAR>
bool DoResolveRelativeHost(const char* base_url,
const Parsed& base_parsed,
const CHAR* relative_url,
const Component& relative_component,
CharsetConverter* query_converter,
CanonOutput* output,
Parsed* out_parsed) { … }
template <typename CharT>
bool DoResolveAbsoluteFile(const CharT* relative_url,
const Component& relative_component,
CharsetConverter* query_converter,
CanonOutput* output,
Parsed* out_parsed) { … }
template<typename CHAR>
bool DoResolveRelativeURL(const char* base_url,
const Parsed& base_parsed,
bool base_is_file,
const CHAR* relative_url,
const Component& relative_component,
CharsetConverter* query_converter,
CanonOutput* output,
Parsed* out_parsed) { … }
}
bool IsRelativeURL(const char* base,
const Parsed& base_parsed,
const char* fragment,
int fragment_len,
bool is_base_hierarchical,
bool* is_relative,
Component* relative_component) { … }
bool IsRelativeURL(const char* base,
const Parsed& base_parsed,
const char16_t* fragment,
int fragment_len,
bool is_base_hierarchical,
bool* is_relative,
Component* relative_component) { … }
bool ResolveRelativeURL(const char* base_url,
const Parsed& base_parsed,
bool base_is_file,
const char* relative_url,
const Component& relative_component,
CharsetConverter* query_converter,
CanonOutput* output,
Parsed* out_parsed) { … }
bool ResolveRelativeURL(const char* base_url,
const Parsed& base_parsed,
bool base_is_file,
const char16_t* relative_url,
const Component& relative_component,
CharsetConverter* query_converter,
CanonOutput* output,
Parsed* out_parsed) { … }
}