This source file includes following definitions.
- DoCanonicalizeMailtoURL
- CanonicalizeMailtoURL
- CanonicalizeMailtoURL
- ReplaceMailtoURL
- ReplaceMailtoURL
#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 {
template<typename CHAR, typename UCHAR>
bool DoCanonicalizeMailtoURL(const URLComponentSource<CHAR>& source,
const url_parse::Parsed& parsed,
CanonOutput* output,
url_parse::Parsed* new_parsed) {
new_parsed->username = url_parse::Component();
new_parsed->password = url_parse::Component();
new_parsed->host = url_parse::Component();
new_parsed->port = url_parse::Component();
new_parsed->ref = url_parse::Component();
new_parsed->scheme.begin = output->length();
output->Append("mailto:", 7);
new_parsed->scheme.len = 6;
bool success = true;
if (parsed.path.is_valid()) {
new_parsed->path.begin = output->length();
int end = parsed.path.end();
for (int i = parsed.path.begin; i < end; ++i) {
UCHAR uch = static_cast<UCHAR>(source.path[i]);
if (uch < 0x20 || uch >= 0x80)
success &= AppendUTF8EscapedChar(source.path, &i, end, output);
else
output->push_back(static_cast<char>(uch));
}
new_parsed->path.len = output->length() - new_parsed->path.begin;
} else {
new_parsed->path.reset();
}
CanonicalizeQuery(source.query, parsed.query, NULL,
output, &new_parsed->query);
return success;
}
}
bool CanonicalizeMailtoURL(const char* spec,
int spec_len,
const url_parse::Parsed& parsed,
CanonOutput* output,
url_parse::Parsed* new_parsed) {
return DoCanonicalizeMailtoURL<char, unsigned char>(
URLComponentSource<char>(spec), parsed, output, new_parsed);
}
bool CanonicalizeMailtoURL(const base::char16* spec,
int spec_len,
const url_parse::Parsed& parsed,
CanonOutput* output,
url_parse::Parsed* new_parsed) {
return DoCanonicalizeMailtoURL<base::char16, base::char16>(
URLComponentSource<base::char16>(spec), parsed, output, new_parsed);
}
bool ReplaceMailtoURL(const char* base,
const url_parse::Parsed& base_parsed,
const Replacements<char>& replacements,
CanonOutput* output,
url_parse::Parsed* new_parsed) {
URLComponentSource<char> source(base);
url_parse::Parsed parsed(base_parsed);
SetupOverrideComponents(base, replacements, &source, &parsed);
return DoCanonicalizeMailtoURL<char, unsigned char>(
source, parsed, output, new_parsed);
}
bool ReplaceMailtoURL(const char* base,
const url_parse::Parsed& base_parsed,
const Replacements<base::char16>& replacements,
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 DoCanonicalizeMailtoURL<char, unsigned char>(
source, parsed, output, new_parsed);
}
}