X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Furl%2Furl_canon_internal.cc;h=1554814c1184e5ff04bedac5cc07417782f99551;hb=004985e17e624662a4c85c76a7654039dc83f028;hp=15f93f77c71574dee0719d4f18b1e1b0c26b14e6;hpb=2f108dbacb161091e42a3479f4e171339b7e7623;p=platform%2Fframework%2Fweb%2Fcrosswalk.git diff --git a/src/url/url_canon_internal.cc b/src/url/url_canon_internal.cc index 15f93f7..1554814 100644 --- a/src/url/url_canon_internal.cc +++ b/src/url/url_canon_internal.cc @@ -2,15 +2,17 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "url/url_canon_internal.h" + #include #include #include #include -#include "url/url_canon_internal.h" +#include "base/strings/utf_string_conversion_utils.h" -namespace url_canon { +namespace url { namespace { @@ -58,12 +60,12 @@ void DoAppendInvalidNarrowString(const CHAR* spec, int begin, int end, } } -// Overrides one component, see the url_canon::Replacements structure for +// Overrides one component, see the Replacements structure for // what the various combionations of source pointer and component mean. void DoOverrideComponent(const char* override_source, - const url_parse::Component& override_component, + const Component& override_component, const char** dest, - url_parse::Component* dest_component) { + Component* dest_component) { if (override_source) { *dest = override_source; *dest_component = override_component; @@ -82,16 +84,15 @@ void DoOverrideComponent(const char* override_source, // may get resized while we're overriding a subsequent component. Instead, the // caller should use the beginning of the |utf8_buffer| as the string pointer // for all components once all overrides have been prepared. -bool PrepareUTF16OverrideComponent( - const base::char16* override_source, - const url_parse::Component& override_component, - CanonOutput* utf8_buffer, - url_parse::Component* dest_component) { +bool PrepareUTF16OverrideComponent(const base::char16* override_source, + const Component& override_component, + CanonOutput* utf8_buffer, + Component* dest_component) { bool success = true; if (override_source) { if (!override_component.is_valid()) { // Non-"valid" component (means delete), so we need to preserve that. - *dest_component = url_parse::Component(); + *dest_component = Component(); } else { // Convert to UTF-8. dest_component->begin = utf8_buffer->length(); @@ -246,6 +247,32 @@ void AppendStringOfType(const base::char16* source, int length, source, length, type, output); } +bool ReadUTFChar(const char* str, int* begin, int length, + unsigned* code_point_out) { + // This depends on ints and int32s being the same thing. If they're not, it + // will fail to compile. + // TODO(mmenke): This should probably be fixed. + if (!base::ReadUnicodeCharacter(str, length, begin, code_point_out) || + !base::IsValidCharacter(*code_point_out)) { + *code_point_out = kUnicodeReplacementCharacter; + return false; + } + return true; +} + +bool ReadUTFChar(const base::char16* str, int* begin, int length, + unsigned* code_point_out) { + // This depends on ints and int32s being the same thing. If they're not, it + // will fail to compile. + // TODO(mmenke): This should probably be fixed. + if (!base::ReadUnicodeCharacter(str, length, begin, code_point_out) || + !base::IsValidCharacter(*code_point_out)) { + *code_point_out = kUnicodeReplacementCharacter; + return false; + } + return true; +} + void AppendInvalidNarrowString(const char* spec, int begin, int end, CanonOutput* output) { DoAppendInvalidNarrowString(spec, begin, end, output); @@ -282,10 +309,10 @@ bool ConvertUTF8ToUTF16(const char* input, int input_len, void SetupOverrideComponents(const char* base, const Replacements& repl, URLComponentSource* source, - url_parse::Parsed* parsed) { + Parsed* parsed) { // Get the source and parsed structures of the things we are replacing. const URLComponentSource& repl_source = repl.sources(); - const url_parse::Parsed& repl_parsed = repl.components(); + const Parsed& repl_parsed = repl.components(); DoOverrideComponent(repl_source.scheme, repl_parsed.scheme, &source->scheme, &parsed->scheme); @@ -314,12 +341,12 @@ bool SetupUTF16OverrideComponents(const char* base, const Replacements& repl, CanonOutput* utf8_buffer, URLComponentSource* source, - url_parse::Parsed* parsed) { + Parsed* parsed) { bool success = true; // Get the source and parsed structures of the things we are replacing. const URLComponentSource& repl_source = repl.sources(); - const url_parse::Parsed& repl_parsed = repl.components(); + const Parsed& repl_parsed = repl.components(); success &= PrepareUTF16OverrideComponent( repl_source.scheme, repl_parsed.scheme, @@ -402,4 +429,4 @@ int _itow_s(int value, base::char16* buffer, size_t size_in_chars, int radix) { #endif // !WIN32 -} // namespace url_canon +} // namespace url