diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-07 00:33:23 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-07 00:33:23 +0000 |
commit | c7b982176e711f0882a08b683c9d1496072d271a (patch) | |
tree | e4e4c7c9d3f66507054db8d99d3a5386796bee67 | |
parent | 3baef3bd25801d51d8b66ca21f5e8704d1380b31 (diff) | |
download | chromium_src-c7b982176e711f0882a08b683c9d1496072d271a.zip chromium_src-c7b982176e711f0882a08b683c9d1496072d271a.tar.gz chromium_src-c7b982176e711f0882a08b683c9d1496072d271a.tar.bz2 |
Eliminate icu_stubs. Things still seem to link fine without these. I suspect splitting utf_string_conversions out of string_utils on the Chrome side helped here.
If I don't eliminate these, I need to patch them for bug 4010, but I'm not going to do that if they aren't needed.
BUG=4010
TEST=none
Review URL: http://codereview.chromium.org/371039
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31343 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome_frame/chrome_frame.gyp | 16 | ||||
-rw-r--r-- | chrome_frame/icu_stubs.cc | 169 | ||||
-rw-r--r-- | chrome_frame/test/icu_stubs_unittests.cc | 73 |
3 files changed, 0 insertions, 258 deletions
diff --git a/chrome_frame/chrome_frame.gyp b/chrome_frame/chrome_frame.gyp index 3b9af9a..37436b7 100644 --- a/chrome_frame/chrome_frame.gyp +++ b/chrome_frame/chrome_frame.gyp @@ -182,17 +182,6 @@ ], }, { - # build the ICU stubs - 'target_name': 'icu_stubs', - 'type': 'static_library', - 'dependencies': [ - '../base/base.gyp:base', - ], - 'sources': [ - 'icu_stubs.cc' - ], - }, - { # TODO(slightlyoff): de-win32-ify # # build the base_noicu.lib. @@ -200,7 +189,6 @@ 'type': 'none', 'dependencies': [ '../base/base.gyp:base', - 'icu_stubs', ], 'actions': [ { @@ -208,7 +196,6 @@ 'msvs_cygwin_shell': 0, 'inputs': [ '<(PRODUCT_DIR)/lib/base.lib', - '<(PRODUCT_DIR)/lib/icu_stubs.lib', ], 'outputs': [ '<(PRODUCT_DIR)/lib/base_noicu.lib', @@ -238,7 +225,6 @@ '../testing/gmock.gyp:gmock', '../testing/gtest.gyp:gtest', 'base_noicu', - 'icu_stubs', 'chrome_frame_npapi', 'chrome_frame_strings', 'xulrunner_sdk', @@ -312,7 +298,6 @@ 'test/http_negotiate_unittest.cc', 'test/http_server.cc', 'test/http_server.h', - 'test/icu_stubs_unittests.cc', 'test/run_all_unittests.cc', 'test/test_server.cc', 'test/test_server.h', @@ -650,7 +635,6 @@ 'function_stub.h', 'http_negotiate.h', 'http_negotiate.cc', - 'icu_stubs.cc', 'iids.cc', 'in_place_menu.h', 'ole_document_impl.h', diff --git a/chrome_frame/icu_stubs.cc b/chrome_frame/icu_stubs.cc deleted file mode 100644 index 2f3abcf..0000000 --- a/chrome_frame/icu_stubs.cc +++ /dev/null @@ -1,169 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/logging.h" -#include "base/string_util.h" -#include "googleurl/src/url_canon.h" - -#include <windows.h> - -//////////////////////////////////////////////////////////////////////////////// -// Avoid dependency on string_util_icu.cc (which pulls in icu). - -std::string WideToAnsiDirect(const wchar_t* wide, size_t wide_len) { - std::string ret; - char* write = WriteInto(&ret, wide_len + 1); - for (size_t i = 0; i < wide_len; ++i) { - // We can only convert characters below 0x80 directly from wide to ansi. - DCHECK(wide[i] <= 127) << "can't convert"; - write[i] = static_cast<char>(wide[i]); - } - - write[wide_len] = '\0'; - - return ret; -} - -bool WideToUTF8(const wchar_t* wide, size_t wide_len, std::string* utf8) { - DCHECK(utf8); - - // Add a cutoff. If it's all ASCII, convert it directly - size_t i; - for (i = 0; i < wide_len; ++i) { - if (wide[i] > 127) - break; - } - - // If we made it to the end without breaking, then it's all ANSI, so do a - // quick convert - if (i == wide_len) { - *utf8 = WideToAnsiDirect(wide, wide_len); - return true; - } - - // Figure out how long the string is - int size = WideCharToMultiByte(CP_UTF8, 0, wide, wide_len + 1, NULL, 0, NULL, - NULL); - - if (size > 0) { - WideCharToMultiByte(CP_UTF8, 0, wide, wide_len + 1, WriteInto(utf8, size), - size, NULL, NULL); - } - - return (size > 0); -} - -std::string WideToUTF8(const std::wstring& wide) { - std::string ret; - if (!wide.empty()) { - // Ignore the success flag of this call, it will do the best it can for - // invalid input, which is what we want here. - WideToUTF8(wide.data(), wide.length(), &ret); - } - return ret; -} - -bool UTF8ToWide(const char* src, size_t src_len, std::wstring* output) { - DCHECK(output); - - if (src_len == 0) { - output->clear(); - return true; - } - - int wide_chars = MultiByteToWideChar(CP_UTF8, 0, src, src_len, NULL, 0); - if (!wide_chars) { - NOTREACHED(); - return false; - } - - wide_chars++; // make room for L'\0' - // Note that WriteInto will fill the string with '\0', so in the case - // where the input string is not \0 terminated, we will still be ensured - // that the output string will be. - if (!MultiByteToWideChar(CP_UTF8, 0, src, src_len, - WriteInto(output, wide_chars), wide_chars)) { - NOTREACHED(); - output->clear(); - return false; - } - - return true; -} - -std::wstring UTF8ToWide(const base::StringPiece& utf8) { - std::wstring ret; - if (!utf8.empty()) - UTF8ToWide(utf8.data(), utf8.length(), &ret); - return ret; -} - -#ifdef WCHAR_T_IS_UTF16 -string16 UTF8ToUTF16(const std::string& utf8) { - std::wstring ret; - if (!utf8.empty()) - UTF8ToWide(utf8.data(), utf8.length(), &ret); - return ret; -} -#else -#error Need WCHAR_T_IS_UTF16 -#endif - -//////////////////////////////////////////////////////////////////////////////// -// Replace ICU dependent functions in googleurl. -/*#define __UTF_H__ -#include "third_party/icu38/public/common/unicode/utf16.h" -#define U_IS_SURROGATE(c) (((c)&0xfffff800)==0xd800) -extern const char16 kUnicodeReplacementCharacter;*/ - -namespace url_canon { - -bool IDNToASCII(const char16* src, int src_len, CanonOutputW* output) { - // We should only hit this when the user attempts to navigate - // CF to an invalid URL. - DLOG(WARNING) << __FUNCTION__ << " not implemented"; - return false; -} - -bool ReadUTFChar(const char* str, int* begin, int length, - unsigned* code_point_out) { - // We should only hit this when the user attempts to navigate - // CF to an invalid URL. - DLOG(WARNING) << __FUNCTION__ << " not implemented"; - - // TODO(tommi): consider if we can use something like - // http://bjoern.hoehrmann.de/utf-8/decoder/dfa/ - return false; -} - -bool ReadUTFChar(const 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;*/ - CHECK(false); - return false; -} - -} // namespace url_canon diff --git a/chrome_frame/test/icu_stubs_unittests.cc b/chrome_frame/test/icu_stubs_unittests.cc deleted file mode 100644 index 4da4a40..0000000 --- a/chrome_frame/test/icu_stubs_unittests.cc +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome_frame/test/chrome_frame_unittests.h" - -// Need to include these first since they're included -#include "base/logging.h" -#include "base/string_util.h" -#include "googleurl/src/url_canon.h" - -// Include the implementation of our stubs into a special namespace so that -// we can separate them from Chrome's implementation. -namespace icu_stubs { - // This struct is only to avoid build problems for the two googleurl stubs - // that currently are noops. - struct CanonOutputW { }; - - #include "chrome_frame/icu_stubs.cc" -} // namespace icu_stubs - -// anonymous namespace for test data. -namespace { - - // Test strings borrowed from base/string_util_unittest.cc - static const wchar_t* const kConvertRoundtripCases[] = { - L"", - L"Google Vid¯ôfY »" - L"\x7f51\x9875\x0020\x56fe\x7247\x0020\x8d44\x8baf\x66f4\x591a\x0020\x00bb", - // " ±³ºÌü¹¿Â ÃÄÌÂ" - L"\x03a0\x03b1\x03b3\x03ba\x03cc\x03c3\x03bc\x03b9" - L"\x03bf\x03c2\x0020\x0399\x03c3\x03c4\x03cc\x03c2", - // ">8A: AB@0=8F =0 @CAA:><" - L"\x041f\x043e\x0438\x0441\x043a\x0020\x0441\x0442" - L"\x0440\x0430\x043d\x0438\x0446\x0020\x043d\x0430" - L"\x0020\x0440\x0443\x0441\x0441\x043a\x043e\x043c", - // "È´ÌÁD¾¤Â" - L"\xc804\xccb4\xc11c\xbe44\xc2a4", - - // Test characters that take more than 16 bits. This will depend on whether - // wchar_t is 16 or 32 bits. - #if defined(WCHAR_T_IS_UTF16) - L"\xd800\xdf00", - // ????? (Mathematical Alphanumeric Symbols (U+011d40 - U+011d44 : A,B,C,D,E) - L"\xd807\xdd40\xd807\xdd41\xd807\xdd42\xd807\xdd43\xd807\xdd44", - #elif defined(WCHAR_T_IS_UTF32) - L"\x10300", - // ????? (Mathematical Alphanumeric Symbols (U+011d40 - U+011d44 : A,B,C,D,E) - L"\x11d40\x11d41\x11d42\x11d43\x11d44", - #endif - }; - -} // namespace - -TEST(IcuStubsTests, UTF8AndWideStubTest) { - // Test code borrowed from ConvertUTF8AndWide in base/string_util_unittest.cc. - - // The difference is that we want to make sure that our stubs work the same - // way as chrome's implementation of WideToUTF8 and UTF8ToWide. - for (size_t i = 0; i < arraysize(kConvertRoundtripCases); ++i) { - std::ostringstream utf8_base, utf8_stub; - utf8_base << WideToUTF8(kConvertRoundtripCases[i]); - utf8_stub << icu_stubs::WideToUTF8(kConvertRoundtripCases[i]); - - EXPECT_EQ(utf8_base.str(), utf8_stub.str()); - - std::wostringstream wide_base, wide_stub; - wide_base << UTF8ToWide(utf8_base.str()); - wide_stub << icu_stubs::UTF8ToWide(utf8_base.str()); - - EXPECT_EQ(wide_base.str(), wide_stub.str()); - } -} |