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

Unified Diff: base/i18n/icu_string_conversions.cc

Issue 4435001: Add support for the extended header parameter syntax in Content-Disposition h... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 years, 1 month 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
« no previous file with comments | « base/i18n/icu_string_conversions.h ('k') | base/i18n/icu_string_conversions_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/i18n/icu_string_conversions.cc
===================================================================
--- base/i18n/icu_string_conversions.cc (revision 64006)
+++ base/i18n/icu_string_conversions.cc (working copy)
@@ -9,9 +9,11 @@
#include "base/basictypes.h"
#include "base/logging.h"
#include "base/string_util.h"
+#include "base/utf_string_conversions.h"
#include "unicode/ucnv.h"
#include "unicode/ucnv_cb.h"
#include "unicode/ucnv_err.h"
+#include "unicode/unorm.h"
#include "unicode/ustring.h"
namespace base {
@@ -264,4 +266,28 @@
#endif // defined(WCHAR_T_IS_UTF32)
}
+bool ConvertToUtf8AndNormalize(const std::string& text,
+ const std::string& charset,
+ std::string* result) {
+ result->clear();
+ string16 utf16;
+ if (!CodepageToUTF16(
+ text, charset.c_str(), OnStringConversionError::FAIL, &utf16))
+ return false;
+
+ UErrorCode status = U_ZERO_ERROR;
+ size_t max_length = utf16.length() + 1;
+ string16 normalized_utf16;
+ int actual_length = unorm_normalize(
+ utf16.c_str(), utf16.length(), UNORM_NFC, 0,
+ WriteInto(&normalized_utf16, max_length),
+ static_cast<int>(max_length), &status);
+ if (!U_SUCCESS(status))
+ return false;
+ normalized_utf16.resize(actual_length);
+
+ return UTF16ToUTF8(normalized_utf16.data(),
+ normalized_utf16.length(), result);
+}
+
} // namespace base
« no previous file with comments | « base/i18n/icu_string_conversions.h ('k') | base/i18n/icu_string_conversions_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698