Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Unified Diff: ui/base/resource/resource_bundle_posix.cc

Issue 7744017: Updated *.pak file format to support both UTF8 and UTF16 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleaned up comments/ Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/base/resource/resource_bundle_posix.cc
diff --git a/ui/base/resource/resource_bundle_posix.cc b/ui/base/resource/resource_bundle_posix.cc
index d23a5b1da0986e82e09bd0cd52c68204084066a7..066053ec387a1a60206440c0e4c858645cd27112 100644
--- a/ui/base/resource/resource_bundle_posix.cc
+++ b/ui/base/resource/resource_bundle_posix.cc
@@ -11,6 +11,7 @@
#include "base/string16.h"
#include "base/string_piece.h"
#include "base/synchronization/lock.h"
+#include "base/utf_string_conversions.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/data_pack.h"
#include "ui/base/ui_base_switches.h"
@@ -88,10 +89,19 @@ string16 ResourceBundle::GetLocalizedString(int message_id) {
}
}
- // Data pack encodes strings as UTF16.
- DCHECK_EQ(data.length() % 2, 0U);
- string16 msg(reinterpret_cast<const char16*>(data.data()),
- data.length() / 2);
+ // Strings should not be loaded from data back that contain binary data.
+ DCHECK(locale_resources_data_->GetTextEncodingType() == DataPack::UTF16 ||
+ locale_resources_data_->GetTextEncodingType() == DataPack::UTF8)
+ << "requested localized string from binary pack file";
+
+ // Data pack encodes strings as either UTF8 or UTF16.
+ string16 msg;
+ if (locale_resources_data_->GetTextEncodingType() == DataPack::UTF16) {
+ msg = string16(reinterpret_cast<const char16*>(data.data()),
+ data.length() / 2);
+ } else if (locale_resources_data_->GetTextEncodingType() == DataPack::UTF8) {
+ msg = UTF8ToUTF16(data);
tony 2011/08/29 21:24:39 This is fine for now. We'll want to probably fix
marcvs 2011/08/30 07:58:55 Yes, since GTK uses UTF8 I was saving this for lat
+ }
return msg;
}
« ui/base/resource/data_pack_unittest.cc ('K') | « ui/base/resource/data_pack_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698