1 // Copyright 2016 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/i18n/encoding_detection.h"
7 #include "build/build_config.h"
8 #include "third_party/ced/src/compact_enc_det/compact_enc_det.h"
10 // third_party/ced/src/util/encodings/encodings.h, which is included
11 // by the include above, undefs UNICODE because that is a macro used
12 // internally in ced. If we later in the same translation unit do
13 // anything related to Windows or Windows headers those will then use
14 // the ASCII versions which we do not want. To avoid that happening in
15 // jumbo builds, we redefine UNICODE again here.
18 #endif // BUILDFLAG(IS_WIN)
22 bool DetectEncoding(const std::string& text, std::string* encoding) {
25 Encoding enc = CompactEncDet::DetectEncoding(
26 text.c_str(), text.length(), nullptr, nullptr, nullptr,
29 CompactEncDet::QUERY_CORPUS, // plain text
30 false, // Include 7-bit encodings
34 if (enc == UNKNOWN_ENCODING)
37 *encoding = MimeEncodingName(enc);