OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/i18n/encoding_detection.h" | |
6 | |
7 #include "third_party/ced/src/compact_enc_det/compact_enc_det.h" | |
8 | |
9 namespace base { | |
10 | |
11 bool DetectEncoding(const std::string& text, std::string* encoding) { | |
12 int consumedBytes; | |
Lei Zhang
2016/08/08 22:09:55
nit: foo_bar, not fooBar.
Jinsuk Kim
2016/08/09 01:16:19
Done.
| |
13 bool isReliable; | |
14 Encoding enc = CompactEncDet::DetectEncoding( | |
15 text.c_str(), text.length(), nullptr, nullptr, nullptr, | |
16 UNKNOWN_ENCODING, | |
17 UNKNOWN_LANGUAGE, | |
18 CompactEncDet::QUERY_CORPUS, // plain text | |
Lei Zhang
2016/08/08 22:09:55
two spaces in front of comments.
Jinsuk Kim
2016/08/09 01:16:19
Done.
| |
19 false, // Include 7-bit encodings | |
20 &consumedBytes, | |
21 &isReliable); | |
22 | |
23 if (enc == UNKNOWN_ENCODING) | |
24 return false; | |
25 | |
26 // 7-bit encodings (except ISO-2022-JP) are not supported in web standard. | |
27 // Mark them as ascii to keep the raw bytes intact. | |
28 switch (enc) { | |
29 case HZ_GB_2312: | |
30 case ISO_2022_KR: | |
31 case ISO_2022_CN: | |
32 case UTF7: | |
33 enc = ASCII_7BIT; | |
34 break; | |
35 default: | |
36 break; | |
37 } | |
38 *encoding = MimeEncodingName(enc); | |
39 return true; | |
40 } | |
41 } // namespace base | |
OLD | NEW |