| 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 defined(OS_WIN) |
| 17 | #define UNICODE 1 |
| 18 | #endif // OS_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 |
| 41 |