extensions/universalchardet/src/base/nsEscCharsetProber.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 #include "nsEscCharsetProber.h"
     8 #include "nsUniversalDetector.h"
    10 nsEscCharSetProber::nsEscCharSetProber(uint32_t aLanguageFilter)
    11 {
    12   for (uint32_t i = 0; i < NUM_OF_ESC_CHARSETS; i++)
    13     mCodingSM[i] = nullptr;
    14   if (aLanguageFilter & NS_FILTER_CHINESE_SIMPLIFIED) 
    15   {
    16     mCodingSM[0] = new nsCodingStateMachine(&HZSMModel);
    17     mCodingSM[1] = new nsCodingStateMachine(&ISO2022CNSMModel);
    18   }
    19   if (aLanguageFilter & NS_FILTER_JAPANESE)
    20     mCodingSM[2] = new nsCodingStateMachine(&ISO2022JPSMModel);
    21   if (aLanguageFilter & NS_FILTER_KOREAN)
    22     mCodingSM[3] = new nsCodingStateMachine(&ISO2022KRSMModel);
    23   mActiveSM = NUM_OF_ESC_CHARSETS;
    24   mState = eDetecting;
    25   mDetectedCharset = nullptr;
    26 }
    28 nsEscCharSetProber::~nsEscCharSetProber(void)
    29 {
    30   for (uint32_t i = 0; i < NUM_OF_ESC_CHARSETS; i++)
    31     delete mCodingSM[i];
    32 }
    34 void nsEscCharSetProber::Reset(void)
    35 {
    36   mState = eDetecting;
    37   for (uint32_t i = 0; i < NUM_OF_ESC_CHARSETS; i++)
    38     if (mCodingSM[i])
    39       mCodingSM[i]->Reset();
    40   mActiveSM = NUM_OF_ESC_CHARSETS;
    41   mDetectedCharset = nullptr;
    42 }
    44 nsProbingState nsEscCharSetProber::HandleData(const char* aBuf, uint32_t aLen)
    45 {
    46   nsSMState codingState;
    47   int32_t j;
    48   uint32_t i;
    50   for ( i = 0; i < aLen && mState == eDetecting; i++)
    51   {
    52     for (j = mActiveSM-1; j>= 0; j--)
    53     {
    54       if (mCodingSM[j])
    55       {
    56         codingState = mCodingSM[j]->NextState(aBuf[i]);
    57         if (codingState == eItsMe)
    58         {
    59           mState = eFoundIt;
    60           mDetectedCharset = mCodingSM[j]->GetCodingStateMachine();
    61           return mState;
    62         }
    63       }
    64     }
    65   }
    67   return mState;
    68 }

mercurial