Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/parser/html/nsHtml5MetaScannerCppSupplement.h
Line
Count
Source (jump to first uncovered line)
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 "nsISupportsImpl.h"
6
7
#include "mozilla/Encoding.h"
8
9
const mozilla::Encoding*
10
nsHtml5MetaScanner::sniff(nsHtml5ByteReadable* bytes)
11
0
{
12
0
  readable = bytes;
13
0
  stateLoop(stateSave);
14
0
  readable = nullptr;
15
0
  return mEncoding;
16
0
}
17
18
bool
19
nsHtml5MetaScanner::tryCharset(nsHtml5String charset)
20
0
{
21
0
  // This code needs to stay in sync with
22
0
  // nsHtml5StreamParser::internalEncodingDeclaration. Unfortunately, the
23
0
  // trickery with member fields here leads to some copy-paste reuse. :-(
24
0
  nsAutoCString label;
25
0
  nsString charset16; // Not Auto, because using it to hold nsStringBuffer*
26
0
  charset.ToString(charset16);
27
0
  CopyUTF16toUTF8(charset16, label);
28
0
  const mozilla::Encoding* encoding = Encoding::ForLabel(label);
29
0
  if (!encoding) {
30
0
    return false;
31
0
  }
32
0
  if (encoding == UTF_16BE_ENCODING || encoding == UTF_16LE_ENCODING) {
33
0
    mEncoding = UTF_8_ENCODING;
34
0
    return true;
35
0
  }
36
0
  if (encoding == X_USER_DEFINED_ENCODING) {
37
0
    // WebKit/Blink hack for Indian and Armenian legacy sites
38
0
    mEncoding = WINDOWS_1252_ENCODING;
39
0
    return true;
40
0
  }
41
0
  mEncoding = encoding;
42
0
  return true;
43
0
}