diff options
author | jshin@chromium.org <jshin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-03 23:25:55 +0000 |
---|---|---|
committer | jshin@chromium.org <jshin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-03 23:25:55 +0000 |
commit | c09fb1c79c0a3e76dbb6091e4b718fd9bb197395 (patch) | |
tree | aab648921cd1817792614596ba4e6f94c9c3d7e0 /base/i18n/icu_string_conversions.cc | |
parent | 0912579b25f74d5b66c8adc0d3d8a7f805141e89 (diff) | |
download | chromium_src-c09fb1c79c0a3e76dbb6091e4b718fd9bb197395.zip chromium_src-c09fb1c79c0a3e76dbb6091e4b718fd9bb197395.tar.gz chromium_src-c09fb1c79c0a3e76dbb6091e4b718fd9bb197395.tar.bz2 |
Add support for the extended header parameter syntax in Content-Disposition header (RFC 5987).
It's not generic, but is only used for 'filename' param.
The CL is originally by James Simonsen I reviewed at http://codereview.chromium.org/4254001/show
I added a check for ASCIIness for RFC 5987 extended header and a few tests to NetUti*.GetFileNameFromCD
(net_unittests) and I*.ConvertCo*Norma* (base_unittests). I also replaced '\uxxxx' notation with
the corresponding UTF-8 byte sequence because Visual Studio does not understand it yet.
BUG=57830
TEST="net_unittests --gtest_filter=NetU*.GetFil*", "base_unittests --gtest_filter=I*.Conver*Norm*" and tests
at http://greenbytes.de/tech/tc2231/
Original CL / Review: By James Simonsen; at http://codereview.chromium.org/4254001/show
Review URL: http://codereview.chromium.org/4435001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@64987 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/i18n/icu_string_conversions.cc')
-rw-r--r-- | base/i18n/icu_string_conversions.cc | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/base/i18n/icu_string_conversions.cc b/base/i18n/icu_string_conversions.cc index 9014a7b..c353feb 100644 --- a/base/i18n/icu_string_conversions.cc +++ b/base/i18n/icu_string_conversions.cc @@ -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 @@ bool CodepageToWide(const std::string& encoded, #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 |