Fix emulator build error
[platform/framework/web/chromium-efl.git] / base / i18n / encoding_detection.cc
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.
4
5 #include "base/i18n/encoding_detection.h"
6
7 #include "build/build_config.h"
8 #include "third_party/ced/src/compact_enc_det/compact_enc_det.h"
9
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.
16 #if BUILDFLAG(IS_WIN)
17 #define UNICODE 1
18 #endif  // BUILDFLAG(IS_WIN)
19
20 namespace base {
21
22 bool DetectEncoding(const std::string& text, std::string* encoding) {
23   int consumed_bytes;
24   bool is_reliable;
25   Encoding enc = CompactEncDet::DetectEncoding(
26       text.c_str(), text.length(), nullptr, nullptr, nullptr,
27       UNKNOWN_ENCODING,
28       UNKNOWN_LANGUAGE,
29       CompactEncDet::QUERY_CORPUS,  // plain text
30       false,  // Include 7-bit encodings
31       &consumed_bytes,
32       &is_reliable);
33
34   if (enc == UNKNOWN_ENCODING)
35     return false;
36
37   *encoding = MimeEncodingName(enc);
38   return true;
39 }
40 }  // namespace base