diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-30 19:28:44 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-30 19:28:44 +0000 |
commit | 528c56de01bbbd38788ed6cf8d2eea4c56cbe19e (patch) | |
tree | ac4f7a001affd772c4ab89701d3d46109b5f9e19 /app | |
parent | 5c86ada8d84f6e67d17b027d347052ef451241c4 (diff) | |
download | chromium_src-528c56de01bbbd38788ed6cf8d2eea4c56cbe19e.zip chromium_src-528c56de01bbbd38788ed6cf8d2eea4c56cbe19e.tar.gz chromium_src-528c56de01bbbd38788ed6cf8d2eea4c56cbe19e.tar.bz2 |
Move the number conversions from string_util to a new file.
Use the base namespace in the new file. Update callers.
I removed all wstring variants and also the string->number ones that ignore the return value. That encourages people to write code and forget about error handling.
TEST=included unit tests
BUG=none
Review URL: http://codereview.chromium.org/3056029
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@54355 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app')
-rw-r--r-- | app/clipboard/clipboard_win.cc | 48 | ||||
-rw-r--r-- | app/gfx/font_util.cc | 8 | ||||
-rw-r--r-- | app/l10n_util.cc | 7 | ||||
-rw-r--r-- | app/l10n_util_win.cc | 11 |
4 files changed, 43 insertions, 31 deletions
diff --git a/app/clipboard/clipboard_win.cc b/app/clipboard/clipboard_win.cc index 8ae60d3..393907d 100644 --- a/app/clipboard/clipboard_win.cc +++ b/app/clipboard/clipboard_win.cc @@ -16,7 +16,8 @@ #include "base/logging.h" #include "base/message_loop.h" #include "base/shared_memory.h" -#include "base/string_util.h" +#include "base/string_util.h" // Remove when ASCIIToWide is in utf_string_... +#include "base/string_number_conversions.h" #include "base/utf_string_conversions.h" #include "gfx/size.h" @@ -188,7 +189,7 @@ void Clipboard::WriteHTML(const char* markup_data, std::string html_fragment = ClipboardUtil::HtmlToCFHtml(markup, url); HGLOBAL glob = CreateGlobalData(html_fragment); - WriteToClipboard(StringToInt(GetHtmlFormatType()), glob); + WriteToClipboard(ClipboardUtil::GetHtmlFormat()->cfFormat, glob); } void Clipboard::WriteBookmark(const char* title_data, @@ -202,12 +203,13 @@ void Clipboard::WriteBookmark(const char* title_data, string16 wide_bookmark = UTF8ToWide(bookmark); HGLOBAL glob = CreateGlobalData(wide_bookmark); - WriteToClipboard(StringToInt(GetUrlWFormatType()), glob); + WriteToClipboard(ClipboardUtil::GetUrlWFormat()->cfFormat, glob); } void Clipboard::WriteWebSmartPaste() { DCHECK(clipboard_owner_); - ::SetClipboardData(StringToInt(GetWebKitSmartPasteFormatType()), NULL); + ::SetClipboardData(ClipboardUtil::GetWebKitSmartPasteFormat()->cfFormat, + NULL); } void Clipboard::WriteBitmap(const char* pixel_data, const char* size_data) { @@ -314,7 +316,10 @@ void Clipboard::WriteToClipboard(unsigned int format, HANDLE handle) { bool Clipboard::IsFormatAvailable(const Clipboard::FormatType& format, Clipboard::Buffer buffer) const { DCHECK_EQ(buffer, BUFFER_STANDARD); - return ::IsClipboardFormatAvailable(StringToInt(format)) != FALSE; + int f; + if (!base::StringToInt(format, &f)) + return false; + return ::IsClipboardFormatAvailable(f) != FALSE; } bool Clipboard::IsFormatAvailableByString( @@ -384,7 +389,7 @@ void Clipboard::ReadHTML(Clipboard::Buffer buffer, string16* markup, if (!clipboard.Acquire(GetClipboardWindow())) return; - HANDLE data = ::GetClipboardData(StringToInt(GetHtmlFormatType())); + HANDLE data = ::GetClipboardData(ClipboardUtil::GetHtmlFormat()->cfFormat); if (!data) return; @@ -410,7 +415,7 @@ void Clipboard::ReadBookmark(string16* title, std::string* url) const { if (!clipboard.Acquire(GetClipboardWindow())) return; - HANDLE data = ::GetClipboardData(StringToInt(GetUrlWFormatType())); + HANDLE data = ::GetClipboardData(ClipboardUtil::GetUrlWFormat()->cfFormat); if (!data) return; @@ -507,74 +512,75 @@ void Clipboard::ParseBookmarkClipboardFormat(const string16& bookmark, // static Clipboard::FormatType Clipboard::GetUrlFormatType() { - return IntToString(ClipboardUtil::GetUrlFormat()->cfFormat); + return base::IntToString(ClipboardUtil::GetUrlFormat()->cfFormat); } // static Clipboard::FormatType Clipboard::GetUrlWFormatType() { - return IntToString(ClipboardUtil::GetUrlWFormat()->cfFormat); + return base::IntToString(ClipboardUtil::GetUrlWFormat()->cfFormat); } // static Clipboard::FormatType Clipboard::GetMozUrlFormatType() { - return IntToString(ClipboardUtil::GetMozUrlFormat()->cfFormat); + return base::IntToString(ClipboardUtil::GetMozUrlFormat()->cfFormat); } // static Clipboard::FormatType Clipboard::GetPlainTextFormatType() { - return IntToString(ClipboardUtil::GetPlainTextFormat()->cfFormat); + return base::IntToString(ClipboardUtil::GetPlainTextFormat()->cfFormat); } // static Clipboard::FormatType Clipboard::GetPlainTextWFormatType() { - return IntToString(ClipboardUtil::GetPlainTextWFormat()->cfFormat); + return base::IntToString(ClipboardUtil::GetPlainTextWFormat()->cfFormat); } // static Clipboard::FormatType Clipboard::GetFilenameFormatType() { - return IntToString(ClipboardUtil::GetFilenameFormat()->cfFormat); + return base::IntToString(ClipboardUtil::GetFilenameFormat()->cfFormat); } // static Clipboard::FormatType Clipboard::GetFilenameWFormatType() { - return IntToString(ClipboardUtil::GetFilenameWFormat()->cfFormat); + return base::IntToString(ClipboardUtil::GetFilenameWFormat()->cfFormat); } // MS HTML Format // static Clipboard::FormatType Clipboard::GetHtmlFormatType() { - return IntToString(ClipboardUtil::GetHtmlFormat()->cfFormat); + return base::IntToString(ClipboardUtil::GetHtmlFormat()->cfFormat); } // static Clipboard::FormatType Clipboard::GetBitmapFormatType() { - return IntToString(CF_BITMAP); + return base::IntToString(CF_BITMAP); } // Firefox text/html // static Clipboard::FormatType Clipboard::GetTextHtmlFormatType() { - return IntToString(ClipboardUtil::GetTextHtmlFormat()->cfFormat); + return base::IntToString(ClipboardUtil::GetTextHtmlFormat()->cfFormat); } // static Clipboard::FormatType Clipboard::GetCFHDropFormatType() { - return IntToString(ClipboardUtil::GetCFHDropFormat()->cfFormat); + return base::IntToString(ClipboardUtil::GetCFHDropFormat()->cfFormat); } // static Clipboard::FormatType Clipboard::GetFileDescriptorFormatType() { - return IntToString(ClipboardUtil::GetFileDescriptorFormat()->cfFormat); + return base::IntToString(ClipboardUtil::GetFileDescriptorFormat()->cfFormat); } // static Clipboard::FormatType Clipboard::GetFileContentFormatZeroType() { - return IntToString(ClipboardUtil::GetFileContentFormatZero()->cfFormat); + return base::IntToString(ClipboardUtil::GetFileContentFormatZero()->cfFormat); } // static Clipboard::FormatType Clipboard::GetWebKitSmartPasteFormatType() { - return IntToString(ClipboardUtil::GetWebKitSmartPasteFormat()->cfFormat); + return base::IntToString( + ClipboardUtil::GetWebKitSmartPasteFormat()->cfFormat); } // static diff --git a/app/gfx/font_util.cc b/app/gfx/font_util.cc index b079dd9..61e1b52dd 100644 --- a/app/gfx/font_util.cc +++ b/app/gfx/font_util.cc @@ -6,7 +6,7 @@ #include "app/l10n_util.h" #include "base/logging.h" -#include "base/string_util.h" +#include "base/string_number_conversions.h" #include "base/utf_string_conversions.h" #include "gfx/font.h" @@ -15,7 +15,8 @@ namespace gfx { int GetLocalizedContentsWidthForFont(int col_resource_id, const gfx::Font& font) { double chars = 0; - StringToDouble(WideToUTF8(l10n_util::GetString(col_resource_id)), &chars); + base::StringToDouble(WideToUTF8(l10n_util::GetString(col_resource_id)), + &chars); int width = font.GetExpectedTextWidth(static_cast<int>(chars)); DCHECK_GT(width, 0); return width; @@ -24,7 +25,8 @@ int GetLocalizedContentsWidthForFont(int col_resource_id, int GetLocalizedContentsHeightForFont(int row_resource_id, const gfx::Font& font) { double lines = 0; - StringToDouble(WideToUTF8(l10n_util::GetString(row_resource_id)), &lines); + base::StringToDouble(WideToUTF8(l10n_util::GetString(row_resource_id)), + &lines); int height = static_cast<int>(font.height() * lines); DCHECK_GT(height, 0); return height; diff --git a/app/l10n_util.cc b/app/l10n_util.cc index 95fd0ee..b3e550f 100644 --- a/app/l10n_util.cc +++ b/app/l10n_util.cc @@ -16,8 +16,7 @@ #include "base/path_service.h" #include "base/scoped_ptr.h" #include "base/string16.h" -#include "base/string_piece.h" -#include "base/string_util.h" +#include "base/string_number_conversions.h" #include "base/sys_string_conversions.h" #include "build/build_config.h" #include "gfx/canvas.h" @@ -648,11 +647,11 @@ string16 GetStringFUTF16(int message_id, } std::wstring GetStringF(int message_id, int a) { - return GetStringF(message_id, IntToWString(a)); + return GetStringF(message_id, UTF8ToWide(base::IntToString(a))); } std::wstring GetStringF(int message_id, int64 a) { - return GetStringF(message_id, Int64ToWString(a)); + return GetStringF(message_id, UTF8ToWide(base::Int64ToString(a))); } std::wstring TruncateString(const std::wstring& string, size_t length) { diff --git a/app/l10n_util_win.cc b/app/l10n_util_win.cc index 350c29a..4d22dd3 100644 --- a/app/l10n_util_win.cc +++ b/app/l10n_util_win.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -9,7 +9,8 @@ #include "app/l10n_util_win.h" #include "base/i18n/rtl.h" -#include "base/string_util.h" +#include "base/string_number_conversions.h" +//#include "base/string_util.h" #include "base/win_util.h" #include "grit/app_locale_settings.h" @@ -107,7 +108,11 @@ bool NeedOverrideDefaultUIFont(std::wstring* override_font_family, } std::wstring ui_font_family = GetString(ui_font_family_id); - int scaler100 = StringToInt(l10n_util::GetString(ui_font_size_scaler_id)); + int scaler100; + if (!base::StringToInt(l10n_util::GetString(ui_font_size_scaler_id), + &scaler100)) + return false; + // We use the OS default in two cases: // 1) The resource bundle has 'default' and '100' for font family and // font scaler. |