diff options
22 files changed, 132 insertions, 97 deletions
diff --git a/base/json_reader.cc b/base/json_reader.cc index f3dfc75..b5013ef 100644 --- a/base/json_reader.cc +++ b/base/json_reader.cc @@ -357,11 +357,12 @@ Value* JSONReader::DecodeNumber(const Token& token) { const std::wstring num_string(token.begin, token.length); int num_int; - if (StringToInt(num_string, &num_int)) + if (StringToInt(WideToUTF16Hack(num_string), &num_int)) return Value::CreateIntegerValue(num_int); double num_double; - if (StringToDouble(num_string, &num_double) && base::IsFinite(num_double)) + if (StringToDouble(WideToUTF16Hack(num_string), &num_double) && + base::IsFinite(num_double)) return Value::CreateRealValue(num_double); return NULL; diff --git a/base/string_util.cc b/base/string_util.cc index d84fadb..64c0cdc 100644 --- a/base/string_util.cc +++ b/base/string_util.cc @@ -127,14 +127,25 @@ class StringToLongTraits { } }; -class WStringToLongTraits { +class String16ToLongTraits { public: - typedef std::wstring string_type; + typedef string16 string_type; typedef long value_type; static const int kBase = 10; static inline value_type convert_func(const string_type::value_type* str, string_type::value_type** endptr) { +#if defined(WCHAR_T_IS_UTF16) return wcstol(str, endptr, kBase); +#elif defined(WCHAR_T_IS_UTF32) + std::string ascii_string = UTF16ToASCII(string16(str)); + char* ascii_end = NULL; + value_type ret = strtol(ascii_string.c_str(), &ascii_end, kBase); + if (ascii_string.c_str() + ascii_string.length() == ascii_end) { + *endptr = + const_cast<string_type::value_type*>(str) + ascii_string.length(); + } + return ret; +#endif } static inline bool valid_func(const string_type& str) { return !str.empty() && !iswspace(str[0]); @@ -159,9 +170,9 @@ class StringToInt64Traits { } }; -class WStringToInt64Traits { +class String16ToInt64Traits { public: - typedef std::wstring string_type; + typedef string16 string_type; typedef int64 value_type; static const int kBase = 10; static inline value_type convert_func(const string_type::value_type* str, @@ -169,7 +180,14 @@ class WStringToInt64Traits { #ifdef OS_WIN return _wcstoi64(str, endptr, kBase); #else // assume OS_POSIX - return wcstoll(str, endptr, kBase); + std::string ascii_string = UTF16ToASCII(string16(str)); + char* ascii_end = NULL; + value_type ret = strtoll(ascii_string.c_str(), &ascii_end, kBase); + if (ascii_string.c_str() + ascii_string.length() == ascii_end) { + *endptr = + const_cast<string_type::value_type*>(str) + ascii_string.length(); + } + return ret; #endif } static inline bool valid_func(const string_type& str) { @@ -194,14 +212,25 @@ class HexStringToLongTraits { } }; -class HexWStringToLongTraits { +class HexString16ToLongTraits { public: - typedef std::wstring string_type; + typedef string16 string_type; typedef long value_type; static const int kBase = 16; static inline value_type convert_func(const string_type::value_type* str, string_type::value_type** endptr) { +#if defined(WCHAR_T_IS_UTF16) return wcstoul(str, endptr, kBase); +#elif defined(WCHAR_T_IS_UTF32) + std::string ascii_string = UTF16ToASCII(string16(str)); + char* ascii_end = NULL; + value_type ret = strtoul(ascii_string.c_str(), &ascii_end, kBase); + if (ascii_string.c_str() + ascii_string.length() == ascii_end) { + *endptr = + const_cast<string_type::value_type*>(str) + ascii_string.length(); + } + return ret; +#endif } static inline bool valid_func(const string_type& str) { return !str.empty() && !iswspace(str[0]); @@ -221,22 +250,23 @@ class StringToDoubleTraits { } }; -class WStringToDoubleTraits { +class String16ToDoubleTraits { public: - typedef std::wstring string_type; + typedef string16 string_type; typedef double value_type; static inline value_type convert_func(const string_type::value_type* str, string_type::value_type** endptr) { - // Because dmg_fp::strtod does not like wchar_t, we convert it to ASCII. - // In theory, this should be safe, but it's possible that wide chars + // Because dmg_fp::strtod does not like char16, we convert it to ASCII. + // In theory, this should be safe, but it's possible that 16-bit chars // might get ignored by accident causing something to be parsed when it // shouldn't. - std::string ascii_string = WideToASCII(std::wstring(str)); + std::string ascii_string = UTF16ToASCII(string16(str)); char* ascii_end = NULL; value_type ret = dmg_fp::strtod(ascii_string.c_str(), &ascii_end); if (ascii_string.c_str() + ascii_string.length() == ascii_end) { // Put endptr at end of input string, so it's not recognized as an error. - *endptr = const_cast<string_type::value_type*>(str) + wcslen(str); + *endptr = + const_cast<string_type::value_type*>(str) + ascii_string.length(); } return ret; @@ -1426,18 +1456,18 @@ bool StringToInt(const std::string& input, int* output) { reinterpret_cast<long*>(output)); } -bool StringToInt(const std::wstring& input, int* output) { +bool StringToInt(const string16& input, int* output) { COMPILE_ASSERT(sizeof(int) == sizeof(long), cannot_wcstol_to_int); - return StringToNumber<WStringToLongTraits>(input, - reinterpret_cast<long*>(output)); + return StringToNumber<String16ToLongTraits>(input, + reinterpret_cast<long*>(output)); } bool StringToInt64(const std::string& input, int64* output) { return StringToNumber<StringToInt64Traits>(input, output); } -bool StringToInt64(const std::wstring& input, int64* output) { - return StringToNumber<WStringToInt64Traits>(input, output); +bool StringToInt64(const string16& input, int64* output) { + return StringToNumber<String16ToInt64Traits>(input, output); } bool HexStringToInt(const std::string& input, int* output) { @@ -1446,9 +1476,9 @@ bool HexStringToInt(const std::string& input, int* output) { reinterpret_cast<long*>(output)); } -bool HexStringToInt(const std::wstring& input, int* output) { +bool HexStringToInt(const string16& input, int* output) { COMPILE_ASSERT(sizeof(int) == sizeof(long), cannot_wcstol_to_int); - return StringToNumber<HexWStringToLongTraits>( + return StringToNumber<HexString16ToLongTraits>( input, reinterpret_cast<long*>(output)); } @@ -1490,7 +1520,7 @@ bool HexStringToBytes(const std::string& input, std::vector<uint8>* output) { return HexStringToBytesT(input, output); } -bool HexStringToBytes(const std::wstring& input, std::vector<uint8>* output) { +bool HexStringToBytes(const string16& input, std::vector<uint8>* output) { return HexStringToBytesT(input, output); } @@ -1500,7 +1530,7 @@ int StringToInt(const std::string& value) { return result; } -int StringToInt(const std::wstring& value) { +int StringToInt(const string16& value) { int result; StringToInt(value, &result); return result; @@ -1512,7 +1542,7 @@ int64 StringToInt64(const std::string& value) { return result; } -int64 StringToInt64(const std::wstring& value) { +int64 StringToInt64(const string16& value) { int64 result; StringToInt64(value, &result); return result; @@ -1524,7 +1554,7 @@ int HexStringToInt(const std::string& value) { return result; } -int HexStringToInt(const std::wstring& value) { +int HexStringToInt(const string16& value) { int result; HexStringToInt(value, &result); return result; @@ -1534,8 +1564,8 @@ bool StringToDouble(const std::string& input, double* output) { return StringToNumber<StringToDoubleTraits>(input, output); } -bool StringToDouble(const std::wstring& input, double* output) { - return StringToNumber<WStringToDoubleTraits>(input, output); +bool StringToDouble(const string16& input, double* output) { + return StringToNumber<String16ToDoubleTraits>(input, output); } double StringToDouble(const std::string& value) { @@ -1544,7 +1574,7 @@ double StringToDouble(const std::string& value) { return result; } -double StringToDouble(const std::wstring& value) { +double StringToDouble(const string16& value) { double result; StringToDouble(value, &result); return result; diff --git a/base/string_util.h b/base/string_util.h index b65253a..4e04cd8 100644 --- a/base/string_util.h +++ b/base/string_util.h @@ -408,18 +408,18 @@ std::wstring DoubleToWString(double value); // |*output| will be set to 0. // - Empty string. |*output| will be set to 0. bool StringToInt(const std::string& input, int* output); -bool StringToInt(const std::wstring& input, int* output); +bool StringToInt(const string16& input, int* output); bool StringToInt64(const std::string& input, int64* output); -bool StringToInt64(const std::wstring& input, int64* output); +bool StringToInt64(const string16& input, int64* output); bool HexStringToInt(const std::string& input, int* output); -bool HexStringToInt(const std::wstring& input, int* output); +bool HexStringToInt(const string16& input, int* output); // Similar to the previous functions, except that output is a vector of bytes. // |*output| will contain as many bytes as were successfully parsed prior to the // error. There is no overflow, but input.size() must be evenly divisible by 2. // Leading 0x or +/- are not allowed. bool HexStringToBytes(const std::string& input, std::vector<uint8>* output); -bool HexStringToBytes(const std::wstring& input, std::vector<uint8>* output); +bool HexStringToBytes(const string16& input, std::vector<uint8>* output); // For floating-point conversions, only conversions of input strings in decimal // form are defined to work. Behavior with strings representing floating-point @@ -428,19 +428,19 @@ bool HexStringToBytes(const std::wstring& input, std::vector<uint8>* output); // variants. This expects the input string to NOT be specific to the locale. // If your input is locale specific, use ICU to read the number. bool StringToDouble(const std::string& input, double* output); -bool StringToDouble(const std::wstring& input, double* output); +bool StringToDouble(const string16& input, double* output); // Convenience forms of the above, when the caller is uninterested in the // boolean return value. These return only the |*output| value from the // above conversions: a best-effort conversion when possible, otherwise, 0. int StringToInt(const std::string& value); -int StringToInt(const std::wstring& value); +int StringToInt(const string16& value); int64 StringToInt64(const std::string& value); -int64 StringToInt64(const std::wstring& value); +int64 StringToInt64(const string16& value); int HexStringToInt(const std::string& value); -int HexStringToInt(const std::wstring& value); +int HexStringToInt(const string16& value); double StringToDouble(const std::string& value); -double StringToDouble(const std::wstring& value); +double StringToDouble(const string16& value); // Return a C++ string given printf-like input. std::string StringPrintf(const char* format, ...); diff --git a/base/string_util_unittest.cc b/base/string_util_unittest.cc index 9d099ab..6fc6f7f 100644 --- a/base/string_util_unittest.cc +++ b/base/string_util_unittest.cc @@ -828,8 +828,9 @@ TEST(StringUtilTest, StringToInt) { EXPECT_EQ(cases[i].output, output); std::wstring wide_input = ASCIIToWide(cases[i].input); - EXPECT_EQ(cases[i].output, StringToInt(wide_input)); - EXPECT_EQ(cases[i].success, StringToInt(wide_input, &output)); + EXPECT_EQ(cases[i].output, StringToInt(WideToUTF16Hack(wide_input))); + EXPECT_EQ(cases[i].success, StringToInt(WideToUTF16Hack(wide_input), + &output)); EXPECT_EQ(cases[i].output, output); } @@ -843,7 +844,7 @@ TEST(StringUtilTest, StringToInt) { EXPECT_EQ(6, output); std::wstring wide_input = ASCIIToWide(input_string); - EXPECT_FALSE(StringToInt(wide_input, &output)); + EXPECT_FALSE(StringToInt(WideToUTF16Hack(wide_input), &output)); EXPECT_EQ(6, output); } @@ -892,8 +893,9 @@ TEST(StringUtilTest, StringToInt64) { EXPECT_EQ(cases[i].output, output); std::wstring wide_input = ASCIIToWide(cases[i].input); - EXPECT_EQ(cases[i].output, StringToInt64(wide_input)); - EXPECT_EQ(cases[i].success, StringToInt64(wide_input, &output)); + EXPECT_EQ(cases[i].output, StringToInt64(WideToUTF16Hack(wide_input))); + EXPECT_EQ(cases[i].success, StringToInt64(WideToUTF16Hack(wide_input), + &output)); EXPECT_EQ(cases[i].output, output); } @@ -907,7 +909,7 @@ TEST(StringUtilTest, StringToInt64) { EXPECT_EQ(6, output); std::wstring wide_input = ASCIIToWide(input_string); - EXPECT_FALSE(StringToInt64(wide_input, &output)); + EXPECT_FALSE(StringToInt64(WideToUTF16Hack(wide_input), &output)); EXPECT_EQ(6, output); } @@ -953,8 +955,9 @@ TEST(StringUtilTest, HexStringToInt) { EXPECT_EQ(cases[i].output, output); std::wstring wide_input = ASCIIToWide(cases[i].input); - EXPECT_EQ(cases[i].output, HexStringToInt(wide_input)); - EXPECT_EQ(cases[i].success, HexStringToInt(wide_input, &output)); + EXPECT_EQ(cases[i].output, HexStringToInt(WideToUTF16Hack(wide_input))); + EXPECT_EQ(cases[i].success, HexStringToInt(WideToUTF16Hack(wide_input), + &output)); EXPECT_EQ(cases[i].output, output); } // One additional test to verify that conversion of numbers in strings with @@ -967,7 +970,7 @@ TEST(StringUtilTest, HexStringToInt) { EXPECT_EQ(0xc0ffee, output); std::wstring wide_input = ASCIIToWide(input_string); - EXPECT_FALSE(HexStringToInt(wide_input, &output)); + EXPECT_FALSE(HexStringToInt(WideToUTF16Hack(wide_input), &output)); EXPECT_EQ(0xc0ffee, output); } @@ -1013,7 +1016,8 @@ TEST(StringUtilTest, HexStringToBytes) { compare.clear(); std::wstring wide_input = ASCIIToWide(cases[i].input); - EXPECT_EQ(cases[i].success, HexStringToBytes(wide_input, &output)) << + EXPECT_EQ(cases[i].success, + HexStringToBytes(WideToUTF16Hack(wide_input), &output)) << i << ": " << cases[i].input; for (size_t j = 0; j < cases[i].output_len; ++j) compare.push_back(static_cast<uint8>(cases[i].output[j])); @@ -1065,8 +1069,10 @@ TEST(StringUtilTest, StringToDouble) { EXPECT_DOUBLE_EQ(cases[i].output, output); std::wstring wide_input = ASCIIToWide(cases[i].input); - EXPECT_DOUBLE_EQ(cases[i].output, StringToDouble(wide_input)); - EXPECT_EQ(cases[i].success, StringToDouble(wide_input, &output)); + EXPECT_DOUBLE_EQ(cases[i].output, + StringToDouble(WideToUTF16Hack(wide_input))); + EXPECT_EQ(cases[i].success, StringToDouble(WideToUTF16Hack(wide_input), + &output)); EXPECT_DOUBLE_EQ(cases[i].output, output); } @@ -1080,7 +1086,7 @@ TEST(StringUtilTest, StringToDouble) { EXPECT_DOUBLE_EQ(3.14, output); std::wstring wide_input = ASCIIToWide(input_string); - EXPECT_FALSE(StringToDouble(wide_input, &output)); + EXPECT_FALSE(StringToDouble(WideToUTF16Hack(wide_input), &output)); EXPECT_DOUBLE_EQ(3.14, output); } diff --git a/chrome/browser/bookmarks/bookmark_codec.cc b/chrome/browser/bookmarks/bookmark_codec.cc index fc4b592..dd39fc8 100644 --- a/chrome/browser/bookmarks/bookmark_codec.cc +++ b/chrome/browser/bookmarks/bookmark_codec.cc @@ -175,8 +175,8 @@ bool BookmarkCodec::DecodeNode(BookmarkModel* model, if (!node) node = new BookmarkNode(model, GURL()); node->type_ = history::StarredEntry::USER_GROUP; - node->date_group_modified_ = - Time::FromInternalValue(StringToInt64(last_modified_date)); + node->date_group_modified_ = Time::FromInternalValue( + StringToInt64(WideToUTF16Hack(last_modified_date))); if (parent) parent->Add(parent->GetChildCount(), node); @@ -186,7 +186,7 @@ bool BookmarkCodec::DecodeNode(BookmarkModel* model, } node->SetTitle(title); - node->date_added_ = - Time::FromInternalValue(StringToInt64(date_added_string)); + node->date_added_ = Time::FromInternalValue( + StringToInt64(WideToUTF16Hack(date_added_string))); return true; } diff --git a/chrome/browser/bookmarks/bookmark_html_writer.cc b/chrome/browser/bookmarks/bookmark_html_writer.cc index bb39ebe..6b6c556 100644 --- a/chrome/browser/bookmarks/bookmark_html_writer.cc +++ b/chrome/browser/bookmarks/bookmark_html_writer.cc @@ -193,8 +193,8 @@ class Writer : public Task { // Converts a time string written to the JSON codec into a time_t string // (used by bookmarks.html) and writes it. bool WriteTime(const std::wstring& time_string) { - base::Time time = - base::Time::FromInternalValue(StringToInt64(time_string)); + base::Time time = base::Time::FromInternalValue( + StringToInt64(WideToUTF16Hack(time_string))); return Write(Int64ToString(time.ToTimeT())); } diff --git a/chrome/browser/browser_init.cc b/chrome/browser/browser_init.cc index b393d18..8b5eb37 100644 --- a/chrome/browser/browser_init.cc +++ b/chrome/browser/browser_init.cc @@ -217,7 +217,7 @@ bool BrowserInit::LaunchWithProfile::Launch(Profile* profile, if (!RenderProcessHost::run_renderer_in_process()) { std::wstring port_str = command_line_.GetSwitchValue(switches::kRemoteShellPort); - int64 port = StringToInt64(port_str); + int64 port = StringToInt64(WideToUTF16Hack(port_str)); if (port > 0 && port < 65535) { g_browser_process->InitDebuggerWrapper(static_cast<int>(port)); } else { @@ -425,7 +425,7 @@ bool BrowserInit::ProcessCommandLine( command_line.GetSwitchValue(switches::kOmniBoxPopupCount); if (!popup_count_string.empty()) { int count = 0; - if (StringToInt(popup_count_string, &count)) { + if (StringToInt(WideToUTF16Hack(popup_count_string), &count)) { const int popup_count = std::max(0, count); AutocompleteResult::set_max_matches(popup_count); AutocompleteProvider::set_max_matches(popup_count / 2); @@ -439,7 +439,7 @@ bool BrowserInit::ProcessCommandLine( command_line.GetSwitchValue(switches::kTabCountToLoadOnSessionRestore); if (!tab_count_string.empty()) { int count = 0; - if (StringToInt(tab_count_string, &count)) { + if (StringToInt(WideToUTF16Hack(tab_count_string), &count)) { const int tab_count = std::max(0, count); SessionRestore::num_tabs_to_load_ = static_cast<size_t>(tab_count); } diff --git a/chrome/browser/dom_ui/dom_ui.cc b/chrome/browser/dom_ui/dom_ui.cc index 22e3382..b0efcad 100644 --- a/chrome/browser/dom_ui/dom_ui.cc +++ b/chrome/browser/dom_ui/dom_ui.cc @@ -148,7 +148,7 @@ bool DOMMessageHandler::ExtractIntegerValue(const Value* value, int* out_int) { static_cast<const StringValue*>(list_member); std::wstring wstring_value; string_value->GetAsString(&wstring_value); - *out_int = StringToInt(wstring_value); + *out_int = StringToInt(WideToUTF16Hack(wstring_value)); return true; } } @@ -173,4 +173,3 @@ std::wstring DOMMessageHandler::ExtractStringValue(const Value* value) { } return std::wstring(); } - diff --git a/chrome/browser/dom_ui/history_ui.cc b/chrome/browser/dom_ui/history_ui.cc index fcabc19..0f735d4 100644 --- a/chrome/browser/dom_ui/history_ui.cc +++ b/chrome/browser/dom_ui/history_ui.cc @@ -278,7 +278,7 @@ void BrowsingHistoryHandler::ExtractSearchHistoryArguments(const Value* value, static_cast<const StringValue*>(list_member); std::wstring wstring_value; string_value->GetAsString(&wstring_value); - *month = StringToInt(wstring_value); + *month = StringToInt(WideToUTF16Hack(wstring_value)); } } } diff --git a/chrome/browser/dom_ui/new_tab_ui.cc b/chrome/browser/dom_ui/new_tab_ui.cc index 3b83c99..189f703 100644 --- a/chrome/browser/dom_ui/new_tab_ui.cc +++ b/chrome/browser/dom_ui/new_tab_ui.cc @@ -596,7 +596,7 @@ void RecentlyClosedTabsHandler::HandleReopenTab(const Value* content) { static_cast<const StringValue*>(list_member); std::wstring wstring_value; if (string_value->GetAsString(&wstring_value)) { - int session_to_restore = StringToInt(wstring_value); + int session_to_restore = StringToInt(WideToUTF16Hack(wstring_value)); tab_restore_service_->RestoreEntryById(browser, session_to_restore, true); // The current tab has been nuked at this point; don't touch any member diff --git a/chrome/browser/history/text_database.cc b/chrome/browser/history/text_database.cc index 00d05ce..37b15ba 100644 --- a/chrome/browser/history/text_database.cc +++ b/chrome/browser/history/text_database.cc @@ -127,8 +127,8 @@ TextDatabase::DBIdent TextDatabase::FileNameToID(const std::wstring& file_path){ return 0; } - int year = StringToInt(suffix.substr(0, 4)); - int month = StringToInt(suffix.substr(5, 2)); + int year = StringToInt(WideToUTF16Hack(suffix.substr(0, 4))); + int month = StringToInt(WideToUTF16Hack(suffix.substr(5, 2))); return year * 100 + month; } @@ -392,4 +392,3 @@ void TextDatabase::GetTextMatches(const std::string& query, } } // namespace history - diff --git a/chrome/browser/metrics/metrics_service.cc b/chrome/browser/metrics/metrics_service.cc index c50a4c5..5b41058 100644 --- a/chrome/browser/metrics/metrics_service.cc +++ b/chrome/browser/metrics/metrics_service.cc @@ -616,12 +616,12 @@ void MetricsService::InitializeMetricsState() { // This is marked false when we get a WM_ENDSESSION. pref->SetBoolean(prefs::kStabilitySessionEndCompleted, true); - int64 last_start_time = - StringToInt64(pref->GetString(prefs::kStabilityLaunchTimeSec)); - int64 last_end_time = - StringToInt64(pref->GetString(prefs::kStabilityLastTimestampSec)); - int64 uptime = - StringToInt64(pref->GetString(prefs::kStabilityUptimeSec)); + int64 last_start_time = StringToInt64( + WideToUTF16Hack(pref->GetString(prefs::kStabilityLaunchTimeSec))); + int64 last_end_time = StringToInt64( + WideToUTF16Hack(pref->GetString(prefs::kStabilityLastTimestampSec))); + int64 uptime = StringToInt64( + WideToUTF16Hack(pref->GetString(prefs::kStabilityUptimeSec))); if (last_start_time && last_end_time) { // TODO(JAR): Exclude sleep time. ... which must be gathered in UI loop. diff --git a/chrome/browser/page_state.cc b/chrome/browser/page_state.cc index 1d52ffb..827416c 100644 --- a/chrome/browser/page_state.cc +++ b/chrome/browser/page_state.cc @@ -82,7 +82,7 @@ void PageState::SetInt64Property(const std::wstring& key, int64 value) { bool PageState::GetInt64Property(const std::wstring& key, int64* value) const { std::wstring v; if (GetProperty(key, &v)) { - return StringToInt64(v, value); + return StringToInt64(WideToUTF16Hack(v), value); } return false; } @@ -94,7 +94,7 @@ void PageState::SetIntProperty(const std::wstring& key, int value) { bool PageState::GetIntProperty(const std::wstring& key, int* value) const { std::wstring v; if (GetProperty(key, &v)) { - return StringToInt(v, value); + return StringToInt(WideToUTF16Hack(v), value); } return false; } @@ -105,4 +105,3 @@ PageState* PageState::Copy() const { copy->state_.reset(static_cast<DictionaryValue*>(state_->DeepCopy())); return copy; } - diff --git a/chrome/browser/search_engines/template_url_model.cc b/chrome/browser/search_engines/template_url_model.cc index 316ad80..cac5bea 100644 --- a/chrome/browser/search_engines/template_url_model.cc +++ b/chrome/browser/search_engines/template_url_model.cc @@ -828,7 +828,7 @@ bool TemplateURLModel::LoadDefaultSearchProviderFromPrefs( (*default_provider)->SetURL(search_url, 0, 0); (*default_provider)->SetSuggestionsURL(suggest_url, 0, 0); if (!id_string.empty()) - (*default_provider)->set_id(StringToInt64(id_string)); + (*default_provider)->set_id(StringToInt64(WideToUTF16Hack(id_string))); return true; } diff --git a/chrome/browser/search_engines/template_url_parser.cc b/chrome/browser/search_engines/template_url_parser.cc index 0bec982..8c44933 100644 --- a/chrome/browser/search_engines/template_url_parser.cc +++ b/chrome/browser/search_engines/template_url_parser.cc @@ -311,9 +311,11 @@ void ParseURL(const xmlChar** atts, ParsingContext* context) { } else if (name == kURLTemplateAttribute) { template_url = XMLCharToWide(value); } else if (name == kURLIndexOffsetAttribute) { - index_offset = std::max(1, StringToInt(XMLCharToWide(value))); + index_offset = + std::max(1, StringToInt(WideToUTF16Hack(XMLCharToWide(value)))); } else if (name == kURLPageOffsetAttribute) { - page_offset = std::max(1, StringToInt(XMLCharToWide(value))); + page_offset = + std::max(1, StringToInt(WideToUTF16Hack(XMLCharToWide(value)))); } else if (name == kParamMethodAttribute) { is_post = LowerCaseEqualsASCII(XMLCharToString(value), "post"); } @@ -346,9 +348,9 @@ void ParseImage(const xmlChar** atts, ParsingContext* context) { if (name == kImageTypeAttribute) { type = XMLCharToWide(value); } else if (name == kImageWidthAttribute) { - width = StringToInt(XMLCharToWide(value)); + width = StringToInt(WideToUTF16Hack(XMLCharToWide(value))); } else if (name == kImageHeightAttribute) { - height = StringToInt(XMLCharToWide(value)); + height = StringToInt(WideToUTF16Hack(XMLCharToWide(value))); } attributes += 2; } @@ -585,5 +587,3 @@ bool TemplateURLParser::Parse(const unsigned char* data, size_t length, } return false; } - - diff --git a/chrome/common/logging_chrome.cc b/chrome/common/logging_chrome.cc index 6b34cbe..66a49cf 100644 --- a/chrome/common/logging_chrome.cc +++ b/chrome/common/logging_chrome.cc @@ -125,7 +125,7 @@ void InitChromeLogging(const CommandLine& command_line, // default to LOG_WARNING. std::wstring log_level = command_line.GetSwitchValue(switches::kLoggingLevel); int level = 0; - if (StringToInt(log_level, &level)) { + if (StringToInt(WideToUTF16Hack(log_level), &level)) { if ((level >= 0) && (level < LOG_NUM_SEVERITIES)) logging::SetMinLogLevel(level); } else { @@ -200,4 +200,3 @@ size_t GetFatalAssertions(AssertionList* assertions) { } } // namespace logging - diff --git a/chrome/common/pref_service.cc b/chrome/common/pref_service.cc index ebc9452..b728a87 100644 --- a/chrome/common/pref_service.cc +++ b/chrome/common/pref_service.cc @@ -72,12 +72,14 @@ Value* CreateLocaleDefaultValue(Value::ValueType type, int message_id) { } case Value::TYPE_INTEGER: { - return Value::CreateIntegerValue(StringToInt(resource_string)); + return Value::CreateIntegerValue( + StringToInt(WideToUTF16Hack(resource_string))); break; } case Value::TYPE_REAL: { - return Value::CreateRealValue(StringToDouble(resource_string)); + return Value::CreateRealValue( + StringToDouble(WideToUTF16Hack(resource_string))); break; } @@ -683,4 +685,3 @@ bool PrefService::Preference::IsDefaultValue() const { DCHECK(default_value_.get()); return default_value_->Equals(GetValue()); } - diff --git a/chrome/test/ui/ui_test.cc b/chrome/test/ui/ui_test.cc index d7bb7ca..2124ba7 100644 --- a/chrome/test/ui/ui_test.cc +++ b/chrome/test/ui/ui_test.cc @@ -186,27 +186,27 @@ void UITest::InitializeTimeouts() { const CommandLine& command_line = *CommandLine::ForCurrentProcess(); if (command_line.HasSwitch(kUiTestTimeout)) { std::wstring timeout_str = command_line.GetSwitchValue(kUiTestTimeout); - int timeout = StringToInt(timeout_str); + int timeout = StringToInt(WideToUTF16Hack(timeout_str)); command_execution_timeout_ms_ = std::max(kMaxTestExecutionTime, timeout); } if (command_line.HasSwitch(kUiTestActionTimeout)) { std::wstring act_str = command_line.GetSwitchValue(kUiTestActionTimeout); - int act_timeout = StringToInt(act_str); + int act_timeout = StringToInt(WideToUTF16Hack(act_str)); action_timeout_ms_ = std::max(kWaitForActionMsec, act_timeout); } if (command_line.HasSwitch(kUiTestActionMaxTimeout)) { std::wstring action_max_str = command_line.GetSwitchValue(kUiTestActionMaxTimeout); - int max_timeout = StringToInt(action_max_str); + int max_timeout = StringToInt(WideToUTF16Hack(action_max_str)); action_max_timeout_ms_ = std::max(kWaitForActionMaxMsec, max_timeout); } if (CommandLine::ForCurrentProcess()->HasSwitch(kUiTestSleepTimeout)) { std::wstring sleep_timeout_str = CommandLine::ForCurrentProcess()->GetSwitchValue(kUiTestSleepTimeout); - int sleep_timeout = StringToInt(sleep_timeout_str); + int sleep_timeout = StringToInt(WideToUTF16Hack(sleep_timeout_str)); sleep_timeout_ms_ = std::max(kWaitForActionMsec, sleep_timeout); } } diff --git a/chrome/test/ui/ui_test_suite.h b/chrome/test/ui/ui_test_suite.h index dfe5eeb..d450a71 100644 --- a/chrome/test/ui/ui_test_suite.h +++ b/chrome/test/ui/ui_test_suite.h @@ -42,7 +42,7 @@ class UITestSuite : public ChromeTestSuite { std::wstring test_timeout = parsed_command_line.GetSwitchValue(UITestSuite::kTestTimeout); if (!test_timeout.empty()) { - UITest::set_test_timeout_ms(StringToInt(test_timeout)); + UITest::set_test_timeout_ms(StringToInt(WideToUTF16Hack(test_timeout))); } std::wstring js_flags = parsed_command_line.GetSwitchValue(switches::kJavaScriptFlags); @@ -69,4 +69,3 @@ class UITestSuite : public ChromeTestSuite { }; #endif // CHROME_TEST_UI_UI_TEST_SUITE_H_ - diff --git a/webkit/glue/dom_operations.cc b/webkit/glue/dom_operations.cc index 2f178d9..00e0802 100644 --- a/webkit/glue/dom_operations.cc +++ b/webkit/glue/dom_operations.cc @@ -685,7 +685,7 @@ static int ParseSingleIconSize(const std::wstring& text) { return 0; } int output; - if (!StringToInt(text, &output)) + if (!StringToInt(WideToUTF16Hack(text), &output)) return 0; return output; } diff --git a/webkit/tools/test_shell/node_leak_test.cc b/webkit/tools/test_shell/node_leak_test.cc index f24172a..8b1c815 100644 --- a/webkit/tools/test_shell/node_leak_test.cc +++ b/webkit/tools/test_shell/node_leak_test.cc @@ -49,7 +49,8 @@ class NodeLeakTest : public TestShellTest { if (parsed_command_line.HasSwitch(test_shell::kTestShellTimeOut)) { const std::wstring timeout_str = parsed_command_line.GetSwitchValue( test_shell::kTestShellTimeOut); - int timeout_ms = static_cast<int>(StringToInt64(timeout_str.c_str())); + int timeout_ms = + static_cast<int>(StringToInt64(WideToUTF16Hack(timeout_str.c_str()))); if (timeout_ms > 0) TestShell::SetFileTestTimeout(timeout_ms); } diff --git a/webkit/tools/test_shell/test_shell_main.cc b/webkit/tools/test_shell/test_shell_main.cc index d042226..01afc6d 100644 --- a/webkit/tools/test_shell/test_shell_main.cc +++ b/webkit/tools/test_shell/test_shell_main.cc @@ -151,7 +151,8 @@ int main(int argc, char* argv[]) { if (parsed_command_line.HasSwitch(test_shell::kTestShellTimeOut)) { const std::wstring timeout_str = parsed_command_line.GetSwitchValue( test_shell::kTestShellTimeOut); - int timeout_ms = static_cast<int>(StringToInt64(timeout_str.c_str())); + int timeout_ms = + static_cast<int>(StringToInt64(WideToUTF16Hack(timeout_str.c_str()))); if (timeout_ms > 0) TestShell::SetFileTestTimeout(timeout_ms); } |