parser/html/nsHtml5MetaScannerCppSupplement.h

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

     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 "nsEncoderDecoderUtils.h"
     6 #include "nsISupportsImpl.h"
     8 #include "mozilla/dom/EncodingUtils.h"
    10 using mozilla::dom::EncodingUtils;
    12 void
    13 nsHtml5MetaScanner::sniff(nsHtml5ByteReadable* bytes, nsACString& charset)
    14 {
    15   readable = bytes;
    16   stateLoop(stateSave);
    17   readable = nullptr;
    18   charset.Assign(mCharset);
    19 }
    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