summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormmenke@chromium.org <mmenke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-02 15:58:31 +0000
committermmenke@chromium.org <mmenke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-02 15:58:31 +0000
commit15f2283fa979bebfef4312a2d10bb951e64fc864 (patch)
treee4cb4ee765541b0e384ce3baedcb5fd718b2005c
parentbc80973ac4906e1a04851b086f0a96863d0fec78 (diff)
downloadchromium_src-15f2283fa979bebfef4312a2d10bb951e64fc864.zip
chromium_src-15f2283fa979bebfef4312a2d10bb951e64fc864.tar.gz
chromium_src-15f2283fa979bebfef4312a2d10bb951e64fc864.tar.bz2
Remove url::ReadUTFChar's dependency on icu. Use base instead.
BUG=362608 Review URL: https://codereview.chromium.org/250233002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@267800 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--url/url_canon_icu.cc43
-rw-r--r--url/url_canon_internal.cc30
-rw-r--r--url/url_canon_internal.h6
3 files changed, 30 insertions, 49 deletions
diff --git a/url/url_canon_icu.cc b/url/url_canon_icu.cc
index d53d7cc..741bed2 100644
--- a/url/url_canon_icu.cc
+++ b/url/url_canon_icu.cc
@@ -184,47 +184,4 @@ bool IDNToASCII(const base::char16* src, int src_len, CanonOutputW* output) {
}
}
-bool ReadUTFChar(const char* str, int* begin, int length,
- unsigned* code_point_out) {
- int code_point; // Avoids warning when U8_NEXT writes -1 to it.
- U8_NEXT(str, *begin, length, code_point);
- *code_point_out = static_cast<unsigned>(code_point);
-
- // The ICU macro above moves to the next char, we want to point to the last
- // char consumed.
- (*begin)--;
-
- // Validate the decoded value.
- if (U_IS_UNICODE_CHAR(code_point))
- return true;
- *code_point_out = kUnicodeReplacementCharacter;
- return false;
-}
-
-bool ReadUTFChar(const base::char16* str, int* begin, int length,
- unsigned* code_point) {
- if (U16_IS_SURROGATE(str[*begin])) {
- if (!U16_IS_SURROGATE_LEAD(str[*begin]) || *begin + 1 >= length ||
- !U16_IS_TRAIL(str[*begin + 1])) {
- // Invalid surrogate pair.
- *code_point = kUnicodeReplacementCharacter;
- return false;
- } else {
- // Valid surrogate pair.
- *code_point = U16_GET_SUPPLEMENTARY(str[*begin], str[*begin + 1]);
- (*begin)++;
- }
- } else {
- // Not a surrogate, just one 16-bit word.
- *code_point = str[*begin];
- }
-
- if (U_IS_UNICODE_CHAR(*code_point))
- return true;
-
- // Invalid code point.
- *code_point = kUnicodeReplacementCharacter;
- return false;
-}
-
} // namespace url
diff --git a/url/url_canon_internal.cc b/url/url_canon_internal.cc
index bbd1484..1554814c 100644
--- a/url/url_canon_internal.cc
+++ b/url/url_canon_internal.cc
@@ -2,13 +2,15 @@
// 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 <errno.h>
#include <stdlib.h>
#include <cstdio>
#include <string>
-#include "url/url_canon_internal.h"
+#include "base/strings/utf_string_conversion_utils.h"
namespace url {
@@ -245,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<char, unsigned char>(spec, begin, end, output);
diff --git a/url/url_canon_internal.h b/url/url_canon_internal.h
index e8efd82..71bfc40 100644
--- a/url/url_canon_internal.h
+++ b/url/url_canon_internal.h
@@ -148,8 +148,6 @@ extern const base::char16 kUnicodeReplacementCharacter;
// |*begin| will be updated to point to the last character consumed so it
// can be incremented in a loop and will be ready for the next character.
// (for a single-byte ASCII character, it will not be changed).
-//
-// Implementation is in url_canon_icu.cc.
URL_EXPORT bool ReadUTFChar(const char* str, int* begin, int length,
unsigned* code_point_out);
@@ -225,10 +223,8 @@ inline void AppendUTF8EscapedValue(unsigned char_value, CanonOutput* output) {
// |*begin| will be updated to point to the last character consumed so it
// can be incremented in a loop and will be ready for the next character.
// (for a single-16-bit-word character, it will not be changed).
-//
-// Implementation is in url_canon_icu.cc.
URL_EXPORT bool ReadUTFChar(const base::char16* str, int* begin, int length,
- unsigned* code_point);
+ unsigned* code_point_out);
// Equivalent to U16_APPEND_UNSAFE in ICU but uses our output method.
inline void AppendUTF16Value(unsigned code_point,