parser/html/nsHtml5MetaScannerCppSupplement.h

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:416be6d0f47a
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/. */
4
5 #include "nsEncoderDecoderUtils.h"
6 #include "nsISupportsImpl.h"
7
8 #include "mozilla/dom/EncodingUtils.h"
9
10 using mozilla::dom::EncodingUtils;
11
12 void
13 nsHtml5MetaScanner::sniff(nsHtml5ByteReadable* bytes, nsACString& charset)
14 {
15 readable = bytes;
16 stateLoop(stateSave);
17 readable = nullptr;
18 charset.Assign(mCharset);
19 }
20
21 bool
22 nsHtml5MetaScanner::tryCharset(nsString* charset)
23 {
24 // This code needs to stay in sync with
25 // nsHtml5StreamParser::internalEncodingDeclaration. Unfortunately, the
26 // trickery with member fields here leads to some copy-paste reuse. :-(
27 nsAutoCString label;
28 CopyUTF16toUTF8(*charset, label);
29 nsAutoCString encoding;
30 if (!EncodingUtils::FindEncodingForLabel(label, encoding)) {
31 return false;
32 }
33 if (encoding.EqualsLiteral("UTF-16BE") ||
34 encoding.EqualsLiteral("UTF-16LE")) {
35 mCharset.Assign("UTF-8");
36 return true;
37 }
38 if (encoding.EqualsLiteral("x-user-defined")) {
39 // WebKit/Blink hack for Indian and Armenian legacy sites
40 mCharset.Assign("windows-1252");
41 return true;
42 }
43 mCharset.Assign(encoding);
44 return true;
45 }

mercurial