diff options
-rw-r--r-- | chrome/common/common_glue.cc | 6 | ||||
-rw-r--r-- | tools/grit/grit/node/message.py | 6 | ||||
-rw-r--r-- | webkit/glue/glue_util.cc | 5 | ||||
-rw-r--r-- | webkit/glue/glue_util.h | 1 | ||||
-rw-r--r-- | webkit/glue/localized_strings.cc | 9 | ||||
-rw-r--r-- | webkit/glue/webkit_glue.h | 2 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell_gtk.cc | 6 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell_mac.mm | 5 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell_win.cc | 4 |
9 files changed, 29 insertions, 15 deletions
diff --git a/chrome/common/common_glue.cc b/chrome/common/common_glue.cc index 7d957d9..eb993bd 100644 --- a/chrome/common/common_glue.cc +++ b/chrome/common/common_glue.cc @@ -4,6 +4,8 @@ #include "base/command_line.h" #include "base/path_service.h" +#include "base/string16.h" +#include "base/string_util.h" #include "build/build_config.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_switches.h" @@ -39,8 +41,8 @@ std::wstring GetWebKitLocale() { return lang; } -std::wstring GetLocalizedString(int message_id) { - return l10n_util::GetString(message_id); +string16 GetLocalizedString(int message_id) { + return WideToUTF16(l10n_util::GetString(message_id)); } } // namespace webkit_glue diff --git a/tools/grit/grit/node/message.py b/tools/grit/grit/node/message.py index 66afa64..5ae1162 100644 --- a/tools/grit/grit/node/message.py +++ b/tools/grit/grit/node/message.py @@ -183,8 +183,10 @@ class MessageNode(base.ContentNode): id = id_map[self.GetTextualIds()[0]] message = self.ws_at_start + self.Translate(lang) + self.ws_at_end - # |message| is a python unicode string, so convert to a utf8 byte stream. - return id, message.encode('utf8') + # |message| is a python unicode string, so convert to a utf16 byte stream + # because that's the format of datapacks. We skip the first 2 bytes + # because it is the BOM. + return id, message.encode('utf16')[2:] # static method def Construct(parent, message, name, desc='', meaning='', translateable=True): diff --git a/webkit/glue/glue_util.cc b/webkit/glue/glue_util.cc index 997af01..3759b2b 100644 --- a/webkit/glue/glue_util.cc +++ b/webkit/glue/glue_util.cc @@ -48,6 +48,11 @@ string16 StringToString16(const WebCore::String& str) { return string16(chars ? chars : (UChar *)L"", str.length()); } +WebCore::String String16ToString(const string16& str) { + return WebCore::String(reinterpret_cast<const UChar*>(str.data()), + str.length()); +} + std::string StringToStdString(const WebCore::String& str) { if (str.length() == 0) return std::string(); diff --git a/webkit/glue/glue_util.h b/webkit/glue/glue_util.h index ace448b..b9ebf41 100644 --- a/webkit/glue/glue_util.h +++ b/webkit/glue/glue_util.h @@ -36,6 +36,7 @@ WebCore::String StdWStringToString(const std::wstring& str); // WebCore::String -> string16. This is a direct copy of UTF-16 characters. string16 StringToString16(const WebCore::String& str); +WebCore::String String16ToString(const string16& str); // WebCore::String <-> std::string. We assume the WebCore::String is UTF-16 and // the std::string is UTF-8, and convert as necessary. diff --git a/webkit/glue/localized_strings.cc b/webkit/glue/localized_strings.cc index 957b42ed..148252a 100644 --- a/webkit/glue/localized_strings.cc +++ b/webkit/glue/localized_strings.cc @@ -30,20 +30,21 @@ #undef LOG -#include "webkit/glue/glue_util.h" -#include "webkit/glue/webkit_glue.h" #include "base/logging.h" #include "base/file_util.h" +#include "base/string16.h" #include "base/string_util.h" #include "build/build_config.h" #include "webkit/glue/glue_util.h" +#include "webkit/glue/webkit_glue.h" + #include "webkit_strings.h" using namespace WebCore; inline String GetLocalizedString(int message_id) { - const std::wstring& str(webkit_glue::GetLocalizedString(message_id)); - return webkit_glue::StdWStringToString(str); + const string16& str = webkit_glue::GetLocalizedString(message_id); + return webkit_glue::String16ToString(str); } String WebCore::searchableIndexIntroduction() { diff --git a/webkit/glue/webkit_glue.h b/webkit/glue/webkit_glue.h index 820d569..1826876 100644 --- a/webkit/glue/webkit_glue.h +++ b/webkit/glue/webkit_glue.h @@ -177,7 +177,7 @@ void NotifyCacheStats(); // Gets a localized string given a message id. Returns an empty string if the // message id is not found. -std::wstring GetLocalizedString(int message_id); +string16 GetLocalizedString(int message_id); // Returns the raw data for a resource. This resource must have been // specified as BINDATA in the relevant .rc file. diff --git a/webkit/tools/test_shell/test_shell_gtk.cc b/webkit/tools/test_shell/test_shell_gtk.cc index 7cdca4b..1fa1d20 100644 --- a/webkit/tools/test_shell/test_shell_gtk.cc +++ b/webkit/tools/test_shell/test_shell_gtk.cc @@ -16,6 +16,7 @@ #include "base/file_util.h" #include "base/message_loop.h" #include "base/path_service.h" +#include "base/string16.h" #include "base/string_piece.h" #include "base/string_util.h" #include "net/base/mime_util.h" @@ -632,13 +633,14 @@ StringPiece TestShell::NetResourceProvider(int key) { namespace webkit_glue { -std::wstring GetLocalizedString(int message_id) { +string16 GetLocalizedString(int message_id) { StringPiece res; if (!g_resource_data_pack->Get(message_id, &res)) { LOG(FATAL) << "failed to load webkit string with id " << message_id; } - return UTF8ToWide(res.as_string()); + return string16(reinterpret_cast<const char16*>(res.data()), + res.length() / 2); } std::string GetDataResource(int resource_id) { diff --git a/webkit/tools/test_shell/test_shell_mac.mm b/webkit/tools/test_shell/test_shell_mac.mm index cbf1794..0f9db5c 100644 --- a/webkit/tools/test_shell/test_shell_mac.mm +++ b/webkit/tools/test_shell/test_shell_mac.mm @@ -21,6 +21,7 @@ #include "base/message_loop.h" #include "base/path_service.h" #include "base/stats_table.h" +#include "base/string16.h" #include "base/string_piece.h" #include "base/string_util.h" #include "net/base/mime_util.h" @@ -634,11 +635,11 @@ StringPiece TestShell::NetResourceProvider(int key) { namespace webkit_glue { -std::wstring GetLocalizedString(int message_id) { +string16 GetLocalizedString(int message_id) { NSString* idString = [NSString stringWithFormat:@"%d", message_id]; NSString* localString = NSLocalizedString(idString, @""); - return UTF8ToWide([localString UTF8String]); + return UTF8ToUTF16([localString UTF8String]); } std::string GetDataResource(int resource_id) { diff --git a/webkit/tools/test_shell/test_shell_win.cc b/webkit/tools/test_shell/test_shell_win.cc index 0ca8490..57dc592 100644 --- a/webkit/tools/test_shell/test_shell_win.cc +++ b/webkit/tools/test_shell/test_shell_win.cc @@ -683,7 +683,7 @@ StringPiece TestShell::NetResourceProvider(int key) { namespace webkit_glue { -std::wstring GetLocalizedString(int message_id) { +string16 GetLocalizedString(int message_id) { const ATLSTRINGRESOURCEIMAGE* image = AtlGetStringResourceImage(_AtlBaseModule.GetModuleInstance(), message_id); @@ -691,7 +691,7 @@ std::wstring GetLocalizedString(int message_id) { NOTREACHED(); return L"No string for this identifier!"; } - return std::wstring(image->achString, image->nLength); + return string16(image->achString, image->nLength); } // TODO(tc): Convert this to using resources from test_shell.rc. |