diff options
author | Zeno Albisser <zeno.albisser@theqtcompany.com> | 2014-12-05 15:04:29 +0100 |
---|---|---|
committer | Andras Becsi <andras.becsi@theqtcompany.com> | 2014-12-09 10:49:28 +0100 |
commit | af6588f8d723931a298c995fa97259bb7f7deb55 (patch) | |
tree | 060ca707847ba1735f01af2372e0d5e494dc0366 /chromium/base/i18n | |
parent | 2fff84d821cc7b1c785f6404e0f8091333283e74 (diff) | |
download | qtwebengine-chromium-af6588f8d723931a298c995fa97259bb7f7deb55.tar.gz |
BASELINE: Update chromium to 40.0.2214.28 and ninja to 1.5.3.
Change-Id: I759465284fd64d59ad120219cbe257f7402c4181
Reviewed-by: Andras Becsi <andras.becsi@theqtcompany.com>
Diffstat (limited to 'chromium/base/i18n')
-rw-r--r-- | chromium/base/i18n/break_iterator.cc | 25 | ||||
-rw-r--r-- | chromium/base/i18n/break_iterator.h | 13 | ||||
-rw-r--r-- | chromium/base/i18n/break_iterator_unittest.cc | 41 | ||||
-rw-r--r-- | chromium/base/i18n/build_utf8_validator_tables.cc | 2 | ||||
-rw-r--r-- | chromium/base/i18n/file_util_icu.cc | 36 | ||||
-rw-r--r-- | chromium/base/i18n/file_util_icu.h | 16 | ||||
-rw-r--r-- | chromium/base/i18n/file_util_icu_unittest.cc | 27 | ||||
-rw-r--r-- | chromium/base/i18n/icu_string_conversions_unittest.cc | 27 | ||||
-rw-r--r-- | chromium/base/i18n/number_formatting_unittest.cc | 4 | ||||
-rw-r--r-- | chromium/base/i18n/rtl.cc | 2 | ||||
-rw-r--r-- | chromium/base/i18n/rtl_unittest.cc | 8 | ||||
-rw-r--r-- | chromium/base/i18n/timezone.cc | 32 |
12 files changed, 144 insertions, 89 deletions
diff --git a/chromium/base/i18n/break_iterator.cc b/chromium/base/i18n/break_iterator.cc index fe26a03a0b8..e3aaa2b5b0b 100644 --- a/chromium/base/i18n/break_iterator.cc +++ b/chromium/base/i18n/break_iterator.cc @@ -12,9 +12,9 @@ namespace base { namespace i18n { -const size_t npos = -1; +const size_t npos = static_cast<size_t>(-1); -BreakIterator::BreakIterator(const string16& str, BreakType break_type) +BreakIterator::BreakIterator(const StringPiece16& str, BreakType break_type) : iter_(NULL), string_(str), break_type_(break_type), @@ -22,7 +22,7 @@ BreakIterator::BreakIterator(const string16& str, BreakType break_type) pos_(0) { } -BreakIterator::BreakIterator(const string16& str, const string16& rules) +BreakIterator::BreakIterator(const StringPiece16& str, const string16& rules) : iter_(NULL), string_(str), rules_(rules), @@ -132,19 +132,20 @@ bool BreakIterator::SetText(const base::char16* text, const size_t length) { NOTREACHED() << "ubrk_setText failed"; return false; } + string_ = StringPiece16(text, length); return true; } bool BreakIterator::IsWord() const { int32_t status = ubrk_getRuleStatus(static_cast<UBreakIterator*>(iter_)); if (break_type_ != BREAK_WORD && break_type_ != RULE_BASED) - return false; + return false; return status != UBRK_WORD_NONE; } bool BreakIterator::IsEndOfWord(size_t position) const { if (break_type_ != BREAK_WORD && break_type_ != RULE_BASED) - return false; + return false; UBreakIterator* iter = static_cast<UBreakIterator*>(iter_); UBool boundary = ubrk_isBoundary(iter, static_cast<int32_t>(position)); @@ -154,7 +155,7 @@ bool BreakIterator::IsEndOfWord(size_t position) const { bool BreakIterator::IsStartOfWord(size_t position) const { if (break_type_ != BREAK_WORD && break_type_ != RULE_BASED) - return false; + return false; UBreakIterator* iter = static_cast<UBreakIterator*>(iter_); UBool boundary = ubrk_isBoundary(iter, static_cast<int32_t>(position)); @@ -163,7 +164,19 @@ bool BreakIterator::IsStartOfWord(size_t position) const { return (!!boundary && next_status != UBRK_WORD_NONE); } +bool BreakIterator::IsGraphemeBoundary(size_t position) const { + if (break_type_ != BREAK_CHARACTER) + return false; + + UBreakIterator* iter = static_cast<UBreakIterator*>(iter_); + return !!ubrk_isBoundary(iter, static_cast<int32_t>(position)); +} + string16 BreakIterator::GetString() const { + return GetStringPiece().as_string(); +} + +StringPiece16 BreakIterator::GetStringPiece() const { DCHECK(prev_ != npos && pos_ != npos); return string_.substr(prev_, pos_ - prev_); } diff --git a/chromium/base/i18n/break_iterator.h b/chromium/base/i18n/break_iterator.h index b34c6770d10..19fdbe01cbd 100644 --- a/chromium/base/i18n/break_iterator.h +++ b/chromium/base/i18n/break_iterator.h @@ -8,6 +8,7 @@ #include "base/basictypes.h" #include "base/i18n/base_i18n_export.h" #include "base/strings/string16.h" +#include "base/strings/string_piece.h" // The BreakIterator class iterates through the words, word breaks, and // line breaks in a UTF-16 string. @@ -71,12 +72,12 @@ class BASE_I18N_EXPORT BreakIterator { }; // Requires |str| to live as long as the BreakIterator does. - BreakIterator(const string16& str, BreakType break_type); + BreakIterator(const StringPiece16& str, BreakType break_type); // Make a rule-based iterator. BreakType == RULE_BASED is implied. // TODO(andrewhayden): This signature could easily be misinterpreted as // "(const string16& str, const string16& locale)". We should do something // better. - BreakIterator(const string16& str, const string16& rules); + BreakIterator(const StringPiece16& str, const string16& rules); ~BreakIterator(); // Init() must be called before any of the iterators are valid. @@ -106,11 +107,17 @@ class BASE_I18N_EXPORT BreakIterator { bool IsEndOfWord(size_t position) const; bool IsStartOfWord(size_t position) const; + // Under BREAK_CHARACTER mode, returns whether |position| is a Unicode + // grapheme boundary. + bool IsGraphemeBoundary(size_t position) const; + // Returns the string between prev() and pos(). // Advance() must have been called successfully at least once for pos() to // have advanced to somewhere useful. string16 GetString() const; + StringPiece16 GetStringPiece() const; + // Returns the value of pos() returned before Advance() was last called. size_t prev() const { return prev_; } @@ -126,7 +133,7 @@ class BASE_I18N_EXPORT BreakIterator { void* iter_; // The string we're iterating over. Can be changed with SetText(...) - const string16& string_; + StringPiece16 string_; // Rules for our iterator. Mutually exclusive with break_type_. const string16 rules_; diff --git a/chromium/base/i18n/break_iterator_unittest.cc b/chromium/base/i18n/break_iterator_unittest.cc index 6dcae18460b..220a996b961 100644 --- a/chromium/base/i18n/break_iterator_unittest.cc +++ b/chromium/base/i18n/break_iterator_unittest.cc @@ -89,7 +89,7 @@ TEST(BreakIteratorTest, BreakWide16) { TEST(BreakIteratorTest, BreakWide32) { // U+1D49C MATHEMATICAL SCRIPT CAPITAL A - const char* very_wide_char = "\xF0\x9D\x92\x9C"; + const char very_wide_char[] = "\xF0\x9D\x92\x9C"; const string16 str( UTF8ToUTF16(base::StringPrintf("%s a", very_wide_char))); const string16 very_wide_word(str.substr(0, 2)); @@ -194,7 +194,7 @@ TEST(BreakIteratorTest, BreakSpacekWide16) { TEST(BreakIteratorTest, BreakSpaceWide32) { // U+1D49C MATHEMATICAL SCRIPT CAPITAL A - const char* very_wide_char = "\xF0\x9D\x92\x9C"; + const char very_wide_char[] = "\xF0\x9D\x92\x9C"; const string16 str( UTF8ToUTF16(base::StringPrintf("%s a", very_wide_char))); const string16 very_wide_word(str.substr(0, 3)); @@ -292,7 +292,7 @@ TEST(BreakIteratorTest, BreakLineWide16) { TEST(BreakIteratorTest, BreakLineWide32) { // U+1D49C MATHEMATICAL SCRIPT CAPITAL A - const char* very_wide_char = "\xF0\x9D\x92\x9C"; + const char very_wide_char[] = "\xF0\x9D\x92\x9C"; const string16 str( UTF8ToUTF16(base::StringPrintf("%s\na", very_wide_char))); const string16 very_wide_line(str.substr(0, 3)); @@ -334,5 +334,40 @@ TEST(BreakIteratorTest, BreakCharacter) { } } +// Test for https://code.google.com/p/chromium/issues/detail?id=411213 +// We should be able to get valid substrings with GetString() function +// after setting new content by calling SetText(). +TEST(BreakIteratorTest, GetStringAfterSetText) { + const string16 initial_string(ASCIIToUTF16("str")); + BreakIterator iter(initial_string, BreakIterator::BREAK_WORD); + ASSERT_TRUE(iter.Init()); + + const string16 long_string(ASCIIToUTF16("another,string")); + EXPECT_TRUE(iter.SetText(long_string.c_str(), long_string.size())); + EXPECT_TRUE(iter.Advance()); + EXPECT_TRUE(iter.Advance()); // Advance to ',' in |long_string| + + // Check that the current position is out of bounds of the |initial_string|. + EXPECT_LT(initial_string.size(), iter.pos()); + + // Check that we can get a valid substring of |long_string|. + EXPECT_EQ(ASCIIToUTF16(","), iter.GetString()); +} + +TEST(BreakIteratorTest, GetStringPiece) { + const string16 initial_string(ASCIIToUTF16("some string")); + BreakIterator iter(initial_string, BreakIterator::BREAK_WORD); + ASSERT_TRUE(iter.Init()); + + EXPECT_TRUE(iter.Advance()); + EXPECT_EQ(iter.GetString(), iter.GetStringPiece().as_string()); + EXPECT_EQ(StringPiece16(ASCIIToUTF16("some")), iter.GetStringPiece()); + + EXPECT_TRUE(iter.Advance()); + EXPECT_TRUE(iter.Advance()); + EXPECT_EQ(iter.GetString(), iter.GetStringPiece().as_string()); + EXPECT_EQ(StringPiece16(ASCIIToUTF16("string")), iter.GetStringPiece()); +} + } // namespace i18n } // namespace base diff --git a/chromium/base/i18n/build_utf8_validator_tables.cc b/chromium/base/i18n/build_utf8_validator_tables.cc index d37a75172a7..45fc6cbf92b 100644 --- a/chromium/base/i18n/build_utf8_validator_tables.cc +++ b/chromium/base/i18n/build_utf8_validator_tables.cc @@ -37,8 +37,8 @@ #include "base/basictypes.h" #include "base/command_line.h" -#include "base/file_util.h" #include "base/files/file_path.h" +#include "base/files/file_util.h" #include "base/logging.h" #include "base/numerics/safe_conversions.h" #include "base/strings/stringprintf.h" diff --git a/chromium/base/i18n/file_util_icu.cc b/chromium/base/i18n/file_util_icu.cc index e250c29a5f7..b5c0b9d8f5f 100644 --- a/chromium/base/i18n/file_util_icu.cc +++ b/chromium/base/i18n/file_util_icu.cc @@ -19,7 +19,8 @@ #include "third_party/icu/source/common/unicode/uniset.h" #include "third_party/icu/source/i18n/unicode/coll.h" -using base::string16; +namespace base { +namespace i18n { namespace { @@ -84,20 +85,18 @@ IllegalCharacters::IllegalCharacters() { } // namespace -namespace file_util { - bool IsFilenameLegal(const string16& file_name) { return IllegalCharacters::GetInstance()->containsNone(file_name); } -void ReplaceIllegalCharactersInPath(base::FilePath::StringType* file_name, +void ReplaceIllegalCharactersInPath(FilePath::StringType* file_name, char replace_char) { DCHECK(file_name); DCHECK(!(IllegalCharacters::GetInstance()->contains(replace_char))); // Remove leading and trailing whitespace. - base::TrimWhitespace(*file_name, base::TRIM_ALL, file_name); + TrimWhitespace(*file_name, TRIM_ALL, file_name); IllegalCharacters* illegal = IllegalCharacters::GetInstance(); int cursor = 0; // The ICU macros expect an int. @@ -133,8 +132,7 @@ void ReplaceIllegalCharactersInPath(base::FilePath::StringType* file_name, } } -bool LocaleAwareCompareFilenames(const base::FilePath& a, - const base::FilePath& b) { +bool LocaleAwareCompareFilenames(const FilePath& a, const FilePath& b) { UErrorCode error_code = U_ZERO_ERROR; // Use the default collator. The default locale should have been properly // set by the time this constructor is called. @@ -144,31 +142,31 @@ bool LocaleAwareCompareFilenames(const base::FilePath& a, collator->setStrength(icu::Collator::TERTIARY); #if defined(OS_WIN) - return base::i18n::CompareString16WithCollator(collator.get(), - base::WideToUTF16(a.value()), base::WideToUTF16(b.value())) == UCOL_LESS; + return CompareString16WithCollator(collator.get(), + WideToUTF16(a.value()), WideToUTF16(b.value())) == UCOL_LESS; #elif defined(OS_POSIX) // On linux, the file system encoding is not defined. We assume // SysNativeMBToWide takes care of it. - return base::i18n::CompareString16WithCollator( + return CompareString16WithCollator( collator.get(), - base::WideToUTF16(base::SysNativeMBToWide(a.value().c_str())), - base::WideToUTF16(base::SysNativeMBToWide(b.value().c_str())) - ) == UCOL_LESS; + WideToUTF16(SysNativeMBToWide(a.value().c_str())), + WideToUTF16(SysNativeMBToWide(b.value().c_str()))) == UCOL_LESS; #else #error Not implemented on your system #endif } -void NormalizeFileNameEncoding(base::FilePath* file_name) { +void NormalizeFileNameEncoding(FilePath* file_name) { #if defined(OS_CHROMEOS) std::string normalized_str; - if (base::ConvertToUtf8AndNormalize(file_name->BaseName().value(), - base::kCodepageUTF8, - &normalized_str)) { - *file_name = file_name->DirName().Append(base::FilePath(normalized_str)); + if (ConvertToUtf8AndNormalize(file_name->BaseName().value(), + kCodepageUTF8, + &normalized_str)) { + *file_name = file_name->DirName().Append(FilePath(normalized_str)); } #endif } -} // namespace +} // namespace i18n +} // namespace base diff --git a/chromium/base/i18n/file_util_icu.h b/chromium/base/i18n/file_util_icu.h index 15526c3a645..7dd94cd9b06 100644 --- a/chromium/base/i18n/file_util_icu.h +++ b/chromium/base/i18n/file_util_icu.h @@ -11,11 +11,12 @@ #include "base/i18n/base_i18n_export.h" #include "base/strings/string16.h" -namespace file_util { +namespace base { +namespace i18n { // Returns true if file_name does not have any illegal character. The input // param has the same restriction as that for ReplaceIllegalCharacters. -BASE_I18N_EXPORT bool IsFilenameLegal(const base::string16& file_name); +BASE_I18N_EXPORT bool IsFilenameLegal(const string16& file_name); // Replaces characters in 'file_name' that are illegal for file names with // 'replace_char'. 'file_name' must not be a full or relative path, but just the @@ -25,19 +26,20 @@ BASE_I18N_EXPORT bool IsFilenameLegal(const base::string16& file_name); // file_name == "bad:file*name?.txt", changed to: "bad-file-name-.txt" when // 'replace_char' is '-'. BASE_I18N_EXPORT void ReplaceIllegalCharactersInPath( - base::FilePath::StringType* file_name, + FilePath::StringType* file_name, char replace_char); // Compares two filenames using the current locale information. This can be // used to sort directory listings. It behaves like "operator<" for use in // std::sort. -BASE_I18N_EXPORT bool LocaleAwareCompareFilenames(const base::FilePath& a, - const base::FilePath& b); +BASE_I18N_EXPORT bool LocaleAwareCompareFilenames(const FilePath& a, + const FilePath& b); // Calculates the canonical file-system representation of |file_name| base name. // Modifies |file_name| in place. No-op if not on ChromeOS. -BASE_I18N_EXPORT void NormalizeFileNameEncoding(base::FilePath* file_name); +BASE_I18N_EXPORT void NormalizeFileNameEncoding(FilePath* file_name); -} // namespace file_util +} // namespace i18n +} // namespace base #endif // BASE_I18N_FILE_UTIL_ICU_H_ diff --git a/chromium/base/i18n/file_util_icu_unittest.cc b/chromium/base/i18n/file_util_icu_unittest.cc index dd8122632e8..369345b6add 100644 --- a/chromium/base/i18n/file_util_icu_unittest.cc +++ b/chromium/base/i18n/file_util_icu_unittest.cc @@ -4,11 +4,14 @@ #include "base/i18n/file_util_icu.h" -#include "base/file_util.h" +#include "base/files/file_util.h" #include "base/strings/utf_string_conversions.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/platform_test.h" +namespace base { +namespace i18n { + // file_util winds up using autoreleased objects on the Mac, so this needs // to be a PlatformTest class FileUtilICUTest : public PlatformTest { @@ -29,7 +32,7 @@ static const struct goodbad_pair { TEST_F(FileUtilICUTest, ReplaceIllegalCharacersInPathLinuxTest) { for (size_t i = 0; i < arraysize(kIllegalCharacterCases); ++i) { std::string bad_name(kIllegalCharacterCases[i].bad_name); - file_util::ReplaceIllegalCharactersInPath(&bad_name, '-'); + ReplaceIllegalCharactersInPath(&bad_name, '-'); EXPECT_EQ(kIllegalCharacterCases[i].good_name, bad_name); } } @@ -70,12 +73,12 @@ TEST_F(FileUtilICUTest, ReplaceIllegalCharactersInPathTest) { for (size_t i = 0; i < arraysize(kIllegalCharacterCases); ++i) { #if defined(OS_WIN) std::wstring bad_name(kIllegalCharacterCases[i].bad_name); - file_util::ReplaceIllegalCharactersInPath(&bad_name, '-'); + ReplaceIllegalCharactersInPath(&bad_name, '-'); EXPECT_EQ(kIllegalCharacterCases[i].good_name, bad_name); #elif defined(OS_MACOSX) - std::string bad_name(base::WideToUTF8(kIllegalCharacterCases[i].bad_name)); - file_util::ReplaceIllegalCharactersInPath(&bad_name, '-'); - EXPECT_EQ(base::WideToUTF8(kIllegalCharacterCases[i].good_name), bad_name); + std::string bad_name(WideToUTF8(kIllegalCharacterCases[i].bad_name)); + ReplaceIllegalCharactersInPath(&bad_name, '-'); + EXPECT_EQ(WideToUTF8(kIllegalCharacterCases[i].good_name), bad_name); #endif } } @@ -96,12 +99,14 @@ static const struct normalize_name_encoding_test_cases { TEST_F(FileUtilICUTest, NormalizeFileNameEncoding) { for (size_t i = 0; i < arraysize(kNormalizeFileNameEncodingTestCases); i++) { - base::FilePath path(kNormalizeFileNameEncodingTestCases[i].original_path); - file_util::NormalizeFileNameEncoding(&path); - EXPECT_EQ( - base::FilePath(kNormalizeFileNameEncodingTestCases[i].normalized_path), - path); + FilePath path(kNormalizeFileNameEncodingTestCases[i].original_path); + NormalizeFileNameEncoding(&path); + EXPECT_EQ(FilePath(kNormalizeFileNameEncodingTestCases[i].normalized_path), + path); } } #endif + +} // namespace i18n +} // namespace base diff --git a/chromium/base/i18n/icu_string_conversions_unittest.cc b/chromium/base/i18n/icu_string_conversions_unittest.cc index 62e055ea6f9..d4d32518575 100644 --- a/chromium/base/i18n/icu_string_conversions_unittest.cc +++ b/chromium/base/i18n/icu_string_conversions_unittest.cc @@ -186,13 +186,6 @@ static const struct { true, L"\x05E9\x05C1\x05B8\x05DC\x05D5\x05B9\x05DD", NULL}, - // Hindi Devanagari (ISCII) - {"iscii-dev", - "\xEF\x42" "\xC6\xCC\xD7\xE8\xB3\xDA\xCF", - OnStringConversionError::FAIL, - true, - L"\x0928\x092E\x0938\x094D\x0915\x093E\x0930", - NULL}, // Korean (EUC) {"euc-kr", "\xBE\xC8\xB3\xE7\xC7\xCF\xBC\xBC\xBF\xE4", @@ -202,10 +195,10 @@ static const struct { NULL}, // Japanese (EUC) {"euc-jp", - "\xA4\xB3\xA4\xF3\xA4\xCB\xA4\xC1\xA4\xCF\xB0\xEC\x8F\xB0\xA1\x8E\xA6", + "\xA4\xB3\xA4\xF3\xA4\xCB\xA4\xC1\xA4\xCF\xB0\xEC\x8E\xA6", OnStringConversionError::FAIL, true, - L"\x3053\x3093\x306B\x3061\x306F\x4E00\x4E02\xFF66", + L"\x3053\x3093\x306B\x3061\x306F\x4E00\xFF66", NULL}, // Japanese (ISO-2022) {"iso-2022-jp", @@ -238,17 +231,10 @@ static const struct { L"\x0E2A\x0E27\x0E31\x0E2A\x0E14\x0E35" L"\x0E04\x0E23\x0e31\x0E1A", NULL}, - // Empty text - {"iscii-dev", - "", - OnStringConversionError::FAIL, - true, - L"", - NULL}, }; TEST(ICUStringConversionsTest, ConvertBetweenCodepageAndWide) { - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kConvertCodepageCases); ++i) { + for (size_t i = 0; i < arraysize(kConvertCodepageCases); ++i) { SCOPED_TRACE(base::StringPrintf( "Test[%" PRIuS "]: <encoded: %s> <codepage: %s>", i, kConvertCodepageCases[i].encoded, @@ -315,7 +301,7 @@ TEST(ICUStringConversionsTest, ConvertBetweenCodepageAndWide) { } TEST(ICUStringConversionsTest, ConvertBetweenCodepageAndUTF16) { - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kConvertCodepageCases); ++i) { + for (size_t i = 0; i < arraysize(kConvertCodepageCases); ++i) { SCOPED_TRACE(base::StringPrintf( "Test[%" PRIuS "]: <encoded: %s> <codepage: %s>", i, kConvertCodepageCases[i].encoded, @@ -357,7 +343,8 @@ static const struct { {"foo-\xe4.html", "iso-8859-1", true, "foo-\xc3\xa4.html"}, {"foo-\xe4.html", "iso-8859-7", true, "foo-\xce\xb4.html"}, {"foo-\xe4.html", "foo-bar", false, ""}, - {"foo-\xff.html", "ascii", false, ""}, + // HTML Encoding spec treats US-ASCII as synonymous with windows-1252 + {"foo-\xff.html", "ascii", true, "foo-\xc3\xbf.html"}, {"foo.html", "ascii", true, "foo.html"}, {"foo-a\xcc\x88.html", "utf-8", true, "foo-\xc3\xa4.html"}, {"\x95\x32\x82\x36\xD2\xBB", "gb18030", true, "\xF0\xA0\x80\x80\xE4\xB8\x80"}, @@ -369,7 +356,7 @@ static const struct { }; TEST(ICUStringConversionsTest, ConvertToUtf8AndNormalize) { std::string result; - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kConvertAndNormalizeCases); ++i) { + for (size_t i = 0; i < arraysize(kConvertAndNormalizeCases); ++i) { SCOPED_TRACE(base::StringPrintf( "Test[%" PRIuS "]: <encoded: %s> <codepage: %s>", i, kConvertAndNormalizeCases[i].encoded, diff --git a/chromium/base/i18n/number_formatting_unittest.cc b/chromium/base/i18n/number_formatting_unittest.cc index da6397df8aa..3b0718d454f 100644 --- a/chromium/base/i18n/number_formatting_unittest.cc +++ b/chromium/base/i18n/number_formatting_unittest.cc @@ -27,7 +27,7 @@ TEST(NumberFormattingTest, FormatNumber) { {-42, "-42", "-42"}, }; - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { + for (size_t i = 0; i < arraysize(cases); ++i) { i18n::SetICUDefaultLocale("en"); testing::ResetFormatters(); EXPECT_EQ(cases[i].expected_english, @@ -72,7 +72,7 @@ TEST(NumberFormattingTest, FormatDouble) { {-42.7, 3, "-42.700", "-42,700"}, }; - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { + for (size_t i = 0; i < arraysize(cases); ++i) { i18n::SetICUDefaultLocale("en"); testing::ResetFormatters(); EXPECT_EQ(cases[i].expected_english, diff --git a/chromium/base/i18n/rtl.cc b/chromium/base/i18n/rtl.cc index d878c40da02..392cb13bdb7 100644 --- a/chromium/base/i18n/rtl.cc +++ b/chromium/base/i18n/rtl.cc @@ -33,7 +33,7 @@ std::string GetLocaleString(const icu::Locale& locale) { if (variant != NULL && *variant != '\0') { std::string variant_str(variant); - StringToLowerASCII(&variant_str); + base::StringToLowerASCII(&variant_str); result += '@' + variant_str; } diff --git a/chromium/base/i18n/rtl_unittest.cc b/chromium/base/i18n/rtl_unittest.cc index 2d923acf0ba..87ac87d242a 100644 --- a/chromium/base/i18n/rtl_unittest.cc +++ b/chromium/base/i18n/rtl_unittest.cc @@ -96,7 +96,7 @@ TEST_F(RTLTest, GetFirstStrongCharacterDirection) { LEFT_TO_RIGHT }, }; - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) + for (size_t i = 0; i < arraysize(cases); ++i) EXPECT_EQ(cases[i].direction, GetFirstStrongCharacterDirection(WideToUTF16(cases[i].text))); } @@ -158,7 +158,7 @@ TEST_F(RTLTest, GetLastStrongCharacterDirection) { LEFT_TO_RIGHT }, }; - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) + for (size_t i = 0; i < arraysize(cases); ++i) EXPECT_EQ(cases[i].direction, GetLastStrongCharacterDirection(WideToUTF16(cases[i].text))); } @@ -236,7 +236,7 @@ TEST_F(RTLTest, GetStringDirection) { LEFT_TO_RIGHT }, }; - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) + for (size_t i = 0; i < arraysize(cases); ++i) EXPECT_EQ(cases[i].direction, GetStringDirection(WideToUTF16(cases[i].text))); } @@ -355,7 +355,7 @@ TEST_F(RTLTest, GetDisplayStringInLTRDirectionality) { for (size_t i = 0; i < 2; ++i) { // Toggle the application default text direction (to try each direction). SetRTL(!IsRTL()); - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { + for (size_t i = 0; i < arraysize(cases); ++i) { string16 input = WideToUTF16(cases[i].path); string16 output = GetDisplayStringInLTRDirectionality(input); // Test the expected wrapping behavior for the current UI directionality. diff --git a/chromium/base/i18n/timezone.cc b/chromium/base/i18n/timezone.cc index 8c652799dbb..f668543ecdc 100644 --- a/chromium/base/i18n/timezone.cc +++ b/chromium/base/i18n/timezone.cc @@ -4,6 +4,8 @@ #include "base/i18n/timezone.h" +#include <string.h> + #include <map> #include "base/memory/singleton.h" @@ -22,7 +24,8 @@ class TimezoneMap { } std::string CountryCodeForTimezone(const std::string& olson_code) { - std::map<std::string, std::string>::iterator iter = map_.find(olson_code); + std::map<const char*, const char*, CompareCStrings>::iterator iter = + map_.find(olson_code.c_str()); if (iter != map_.end()) return iter->second; @@ -35,9 +38,10 @@ class TimezoneMap { // <http://www.ietf.org/timezones/data/zone.tab> and is a part of public // domain. struct OlsonCodeData { - std::string country_code; - std::string olson_code; - } olson_code_data[] = { + const char* country_code; + const char* olson_code; + }; + static const OlsonCodeData olson_code_data[] = { { "AD", "Europe/Andorra" }, { "AE", "Asia/Dubai" }, { "AF", "Asia/Kabul" }, @@ -459,17 +463,17 @@ class TimezoneMap { { "GB", "Etc/UCT" }, }; - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(olson_code_data); ++i) { + for (size_t i = 0; i < arraysize(olson_code_data); ++i) map_[olson_code_data[i].olson_code] = olson_code_data[i].country_code; - } // These are mapping from old codenames to new codenames. They are also // part of public domain, and available at // <http://www.ietf.org/timezones/data/backward>. struct LinkData { - std::string old_code; - std::string new_code; - } link_data[] = { + const char* old_code; + const char* new_code; + }; + static const LinkData link_data[] = { { "Africa/Asmera", "Africa/Asmara" }, { "Africa/Timbuktu", "Africa/Bamako" }, { "America/Argentina/ComodRivadavia", "America/Argentina/Catamarca" }, @@ -582,14 +586,18 @@ class TimezoneMap { { "Zulu", "Etc/UTC" }, }; - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(link_data); ++i) { + for (size_t i = 0; i < arraysize(link_data); ++i) map_[link_data[i].old_code] = map_[link_data[i].new_code]; - } } friend struct DefaultSingletonTraits<TimezoneMap>; - std::map<std::string, std::string> map_; + struct CompareCStrings { + bool operator()(const char* str1, const char* str2) const { + return strcmp(str1, str2) < 0; + } + }; + std::map<const char*, const char*, CompareCStrings> map_; DISALLOW_COPY_AND_ASSIGN(TimezoneMap); }; |