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

Unified Diff: base/i18n/icu_encoding_detection.cc

Issue 6718043: FTP: Multiple fixes for localized directory listings: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: trying to make things more clear Created 9 years, 9 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
« no previous file with comments | « no previous file | net/data/ftp/dir-listing-ls-25 » ('j') | net/ftp/ftp_directory_listing_parser_ls.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/i18n/icu_encoding_detection.cc
diff --git a/base/i18n/icu_encoding_detection.cc b/base/i18n/icu_encoding_detection.cc
index d579af280a7af7959ca6d48a3f125c87b98cb13c..4bce18f5bdfd09f5968208f2d96dabab1a4080c0 100644
--- a/base/i18n/icu_encoding_detection.cc
+++ b/base/i18n/icu_encoding_detection.cc
@@ -1,9 +1,11 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/i18n/icu_encoding_detection.h"
+#include <set>
+
#include "base/string_util.h"
#include "unicode/ucsdet.h"
@@ -45,6 +47,13 @@ bool DetectAllEncodings(const std::string& text,
return false;
}
+ // ICU has some heuristics for encoding detection, such that the more likely
+ // encodings should be returned first. However, it doesn't always return
+ // all encodings that properly decode |text|, so we'll append more encodings
+ // later. To make that efficient, keep track of encodings sniffed in this
+ // first phase.
jungshik at Google 2011/04/01 18:28:41 hmm... if ucsdet_detectAll does not return all the
Paweł Hajdan Jr. 2011/04/01 18:45:42 See the raw listing attached to the bug. That was
+ std::set<std::string> sniffed_encodings;
+
encodings->clear();
for (int i = 0; i < matches_count; i++) {
UErrorCode get_name_status = U_ZERO_ERROR;
@@ -55,7 +64,23 @@ bool DetectAllEncodings(const std::string& text,
continue;
encodings->push_back(encoding_name);
+ sniffed_encodings.insert(encoding_name);
+ }
+
+ // Append all encodings not included earlier, in arbitrary order.
jungshik at Google 2011/04/01 18:28:41 This behavior should be documented in the header f
Paweł Hajdan Jr. 2011/04/01 18:45:42 Well, even before this change that was true, i.e.
+ UEnumeration* detectable_encodings = ucsdet_getAllDetectableCharsets(detector,
+ &status);
+ int detectable_count = uenum_count(detectable_encodings, &status);
+ for (int i = 0; i < detectable_count; i++) {
+ int name_length;
+ const char* name_raw = uenum_next(detectable_encodings,
+ &name_length,
+ &status);
+ std::string name(name_raw, name_length);
+ if (sniffed_encodings.find(name) == sniffed_encodings.end())
+ encodings->push_back(name);
}
+ uenum_close(detectable_encodings);
ucsdet_close(detector);
return !encodings->empty();
« no previous file with comments | « no previous file | net/data/ftp/dir-listing-ls-25 » ('j') | net/ftp/ftp_directory_listing_parser_ls.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698