Chromium Code Reviews| Index: net/ftp/ftp_directory_listing_parser.cc |
| diff --git a/net/ftp/ftp_directory_listing_parser.cc b/net/ftp/ftp_directory_listing_parser.cc |
| index a1aabf3f971f39fe6d898b7681e97ae600cc99e1..73e831f66a11454ea3a4c3ffe9607c5ccd46474a 100644 |
| --- a/net/ftp/ftp_directory_listing_parser.cc |
| +++ b/net/ftp/ftp_directory_listing_parser.cc |
| @@ -6,7 +6,7 @@ |
| #include "base/bind.h" |
| #include "base/callback.h" |
| -#include "base/i18n/icu_encoding_detection.h" |
| +#include "base/i18n/encoding_detection.h" |
| #include "base/i18n/icu_string_conversions.h" |
| #include "base/stl_util.h" |
| #include "base/strings/string_util.h" |
| @@ -84,29 +84,23 @@ int DecodeAndParse(const std::string& text, |
| const base::Time& current_time, |
| std::vector<FtpDirectoryListingEntry>* entries, |
| FtpServerType* server_type) { |
| - const char* const kNewlineSeparators[] = { "\n", "\r\n" }; |
| - |
| - std::vector<std::string> encodings; |
| - if (!base::DetectAllEncodings(text, &encodings)) |
| + std::string encoding; |
| + if (!base::DetectEncoding(text, &encoding)) |
| return ERR_ENCODING_DETECTION_FAILED; |
| - |
| - // Use first encoding that can be used to decode the text. |
| - for (size_t i = 0; i < encodings.size(); i++) { |
| - base::string16 converted_text; |
| - if (base::CodepageToUTF16(text, |
| - encodings[i].c_str(), |
| - base::OnStringConversionError::FAIL, |
| - &converted_text)) { |
| - for (size_t j = 0; j < arraysize(kNewlineSeparators); j++) { |
| - int rv = ParseListing(converted_text, |
| - base::ASCIIToUTF16(kNewlineSeparators[j]), |
| - encodings[i], |
| - current_time, |
| - entries, |
| - server_type); |
| - if (rv == OK) |
| - return rv; |
| - } |
| + const char* encoding_name = encoding.c_str(); |
| + |
| + base::string16 converted_text; |
| + if (base::CodepageToUTF16(text, encoding_name, |
|
cbentzel
2016/08/10 01:52:00
I assume that encoding names are the same in CED a
Jinsuk Kim
2016/08/10 02:15:13
They are not precisely the same. CED returns IANA
|
| + base::OnStringConversionError::FAIL, |
| + &converted_text)) { |
| + const char* const kNewlineSeparators[] = {"\n", "\r\n"}; |
| + |
| + for (size_t j = 0; j < arraysize(kNewlineSeparators); j++) { |
| + int rv = ParseListing(converted_text, |
| + base::ASCIIToUTF16(kNewlineSeparators[j]), |
| + encoding_name, current_time, entries, server_type); |
| + if (rv == OK) |
| + return rv; |
| } |
| } |