This source file includes following definitions.
- FileDoDriveSpec
- DoFileCanonicalizePath
- DoCanonicalizeFileURL
- CanonicalizeFileURL
- CanonicalizeFileURL
- FileCanonicalizePath
- FileCanonicalizePath
- ReplaceFileURL
- ReplaceFileURL
#include "url/url_canon.h"
#include "url/url_canon_internal.h"
#include "url/url_file.h"
#include "url/url_parse_internal.h"
namespace url_canon {
namespace {
#ifdef WIN32
template<typename CHAR>
int FileDoDriveSpec(const CHAR* spec, int begin, int end,
CanonOutput* output) {
int num_slashes = url_parse::CountConsecutiveSlashes(spec, begin, end);
int after_slashes = begin + num_slashes;
if (!url_parse::DoesBeginWindowsDriveSpec(spec, after_slashes, end))
return begin;
output->push_back('/');
if (spec[after_slashes] >= 'a' && spec[after_slashes] <= 'z')
output->push_back(spec[after_slashes] - 'a' + 'A');
else
output->push_back(static_cast<char>(spec[after_slashes]));
output->push_back(':');
return after_slashes + 2;
}
#endif
template<typename CHAR, typename UCHAR>
bool DoFileCanonicalizePath(const CHAR* spec,
const url_parse::Component& path,
CanonOutput* output,
url_parse::Component* out_path) {
out_path->begin = output->length();
int after_drive;
#ifdef WIN32
after_drive = FileDoDriveSpec(spec, path.begin, path.end(), output);
#else
after_drive = path.begin;
#endif
bool success = true;
if (after_drive < path.end()) {
url_parse::Component sub_path =
url_parse::MakeRange(after_drive, path.end());
url_parse::Component fake_output_path;
success = CanonicalizePath(spec, sub_path, output, &fake_output_path);
} else {
output->push_back('/');
}
out_path->len = output->length() - out_path->begin;
return success;
}
template<typename CHAR, typename UCHAR>
bool DoCanonicalizeFileURL(const URLComponentSource<CHAR>& source,
const url_parse::Parsed& parsed,
CharsetConverter* query_converter,
CanonOutput* output,
url_parse::Parsed* new_parsed) {
new_parsed->username = url_parse::Component();
new_parsed->password = url_parse::Component();
new_parsed->port = url_parse::Component();
new_parsed->scheme.begin = output->length();
output->Append("file://", 7);
new_parsed->scheme.len = 4;
bool success = CanonicalizeHost(source.host, parsed.host,
output, &new_parsed->host);
success &= DoFileCanonicalizePath<CHAR, UCHAR>(source.path, parsed.path,
output, &new_parsed->path);
CanonicalizeQuery(source.query, parsed.query, query_converter,
output, &new_parsed->query);
CanonicalizeRef(source.ref, parsed.ref, output, &new_parsed->ref);
return success;
}
}
bool CanonicalizeFileURL(const char* spec,
int spec_len,
const url_parse::Parsed& parsed,
CharsetConverter* query_converter,
CanonOutput* output,
url_parse::Parsed* new_parsed) {
return DoCanonicalizeFileURL<char, unsigned char>(
URLComponentSource<char>(spec), parsed, query_converter,
output, new_parsed);
}
bool CanonicalizeFileURL(const base::char16* spec,
int spec_len,
const url_parse::Parsed& parsed,
CharsetConverter* query_converter,
CanonOutput* output,
url_parse::Parsed* new_parsed) {
return DoCanonicalizeFileURL<base::char16, base::char16>(
URLComponentSource<base::char16>(spec), parsed, query_converter,
output, new_parsed);
}
bool FileCanonicalizePath(const char* spec,
const url_parse::Component& path,
CanonOutput* output,
url_parse::Component* out_path) {
return DoFileCanonicalizePath<char, unsigned char>(spec, path,
output, out_path);
}
bool FileCanonicalizePath(const base::char16* spec,
const url_parse::Component& path,
CanonOutput* output,
url_parse::Component* out_path) {
return DoFileCanonicalizePath<base::char16, base::char16>(spec, path,
output, out_path);
}
bool ReplaceFileURL(const char* base,
const url_parse::Parsed& base_parsed,
const Replacements<char>& replacements,
CharsetConverter* query_converter,
CanonOutput* output,
url_parse::Parsed* new_parsed) {
URLComponentSource<char> source(base);
url_parse::Parsed parsed(base_parsed);
SetupOverrideComponents(base, replacements, &source, &parsed);
return DoCanonicalizeFileURL<char, unsigned char>(
source, parsed, query_converter, output, new_parsed);
}
bool ReplaceFileURL(const char* base,
const url_parse::Parsed& base_parsed,
const Replacements<base::char16>& replacements,
CharsetConverter* query_converter,
CanonOutput* output,
url_parse::Parsed* new_parsed) {
RawCanonOutput<1024> utf8;
URLComponentSource<char> source(base);
url_parse::Parsed parsed(base_parsed);
SetupUTF16OverrideComponents(base, replacements, &utf8, &source, &parsed);
return DoCanonicalizeFileURL<char, unsigned char>(
source, parsed, query_converter, output, new_parsed);
}
}