Bug 1700051: part 36) Reduce accessibility of `SoftText::mBegin` to `private`. r...
[gecko.git] / parser / html / nsHtml5MetaScannerCppSupplement.h
blob16878fa53eaec791d051ef6ff2e6eb44fd18bdcb
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "nsISupportsImpl.h"
7 #include "mozilla/Encoding.h"
9 const mozilla::Encoding* nsHtml5MetaScanner::sniff(nsHtml5ByteReadable* bytes) {
10 readable = bytes;
11 stateLoop(stateSave);
12 readable = nullptr;
13 return mEncoding;
16 bool nsHtml5MetaScanner::tryCharset(nsHtml5String charset) {
17 // This code needs to stay in sync with
18 // nsHtml5StreamParser::internalEncodingDeclaration. Unfortunately, the
19 // trickery with member fields here leads to some copy-paste reuse. :-(
20 nsAutoCString label;
21 nsString charset16; // Not Auto, because using it to hold nsStringBuffer*
22 charset.ToString(charset16);
23 CopyUTF16toUTF8(charset16, label);
24 const mozilla::Encoding* encoding = Encoding::ForLabel(label);
25 if (!encoding) {
26 return false;
28 if (encoding == UTF_16BE_ENCODING || encoding == UTF_16LE_ENCODING) {
29 mEncoding = UTF_8_ENCODING;
30 return true;
32 if (encoding == X_USER_DEFINED_ENCODING) {
33 // WebKit/Blink hack for Indian and Armenian legacy sites
34 mEncoding = WINDOWS_1252_ENCODING;
35 return true;
37 mEncoding = encoding;
38 return true;