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

Side by Side Diff: base/i18n/icu_encoding_detection.cc

Issue 7064039: Make DetectEncoding() failed when ucsdet_detect() returls NULL. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/i18n/icu_encoding_detection.h" 5 #include "base/i18n/icu_encoding_detection.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "unicode/ucsdet.h" 10 #include "unicode/ucsdet.h"
11 11
12 namespace base { 12 namespace base {
13 13
14 bool DetectEncoding(const std::string& text, std::string* encoding) { 14 bool DetectEncoding(const std::string& text, std::string* encoding) {
15 if (IsStringASCII(text)) { 15 if (IsStringASCII(text)) {
16 *encoding = std::string(); 16 *encoding = std::string();
17 return true; 17 return true;
18 } 18 }
19 19
20 UErrorCode status = U_ZERO_ERROR; 20 UErrorCode status = U_ZERO_ERROR;
21 UCharsetDetector* detector = ucsdet_open(&status); 21 UCharsetDetector* detector = ucsdet_open(&status);
22 ucsdet_setText(detector, text.data(), static_cast<int32_t>(text.length()), 22 ucsdet_setText(detector, text.data(), static_cast<int32_t>(text.length()),
23 &status); 23 &status);
24 const UCharsetMatch* match = ucsdet_detect(detector, &status); 24 const UCharsetMatch* match = ucsdet_detect(detector, &status);
25 // In case that ucsdet_detect() returns NULL with no error
26 // http://crosbug.com/15691
zel 2011/05/24 22:46:48 Please remove this comment, no need for that.
27 if (match == NULL)
28 return false;
25 const char* detected_encoding = ucsdet_getName(match, &status); 29 const char* detected_encoding = ucsdet_getName(match, &status);
26 ucsdet_close(detector); 30 ucsdet_close(detector);
27 31
28 if (U_FAILURE(status)) 32 if (U_FAILURE(status))
29 return false; 33 return false;
30 34
31 *encoding = detected_encoding; 35 *encoding = detected_encoding;
32 return true; 36 return true;
33 } 37 }
34 38
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 if (sniffed_encodings.find(name) == sniffed_encodings.end()) 97 if (sniffed_encodings.find(name) == sniffed_encodings.end())
94 encodings->push_back(name); 98 encodings->push_back(name);
95 } 99 }
96 uenum_close(detectable_encodings); 100 uenum_close(detectable_encodings);
97 101
98 ucsdet_close(detector); 102 ucsdet_close(detector);
99 return !encodings->empty(); 103 return !encodings->empty();
100 } 104 }
101 105
102 } // namespace base 106 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698