LCOV - code coverage report
Current view: top level - extensions/universalchardet/src/xpcom - nsUdetXPCOMWrapper.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 0 54 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 18 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 2; 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/. */
       5             : 
       6             : #include "nscore.h"
       7             : 
       8             : #include "nsUniversalDetector.h"
       9             : #include "nsUdetXPCOMWrapper.h"
      10             : #include "nsCharSetProber.h" // for DumpStatus
      11             : 
      12             : #include "nsUniversalCharDetDll.h"
      13             : //---- for XPCOM
      14             : #include "nsIFactory.h"
      15             : #include "nsISupports.h"
      16             : #include "nsCOMPtr.h"
      17             : 
      18             : //---------------------------------------------------------------------
      19           0 : nsXPCOMDetector:: nsXPCOMDetector()
      20           0 :  : nsUniversalDetector()
      21             : {
      22           0 : }
      23             : //---------------------------------------------------------------------
      24           0 : nsXPCOMDetector::~nsXPCOMDetector()
      25             : {
      26           0 : }
      27             : //---------------------------------------------------------------------
      28             : 
      29           0 : NS_IMPL_ISUPPORTS(nsXPCOMDetector, nsICharsetDetector)
      30             : 
      31             : //---------------------------------------------------------------------
      32           0 : NS_IMETHODIMP nsXPCOMDetector::Init(
      33             :               nsICharsetDetectionObserver* aObserver)
      34             : {
      35           0 :   NS_ASSERTION(mObserver == nullptr , "Init twice");
      36           0 :   if(nullptr == aObserver)
      37           0 :     return NS_ERROR_ILLEGAL_VALUE;
      38             : 
      39           0 :   mObserver = aObserver;
      40           0 :   return NS_OK;
      41             : }
      42             : //----------------------------------------------------------
      43           0 : NS_IMETHODIMP nsXPCOMDetector::DoIt(const char* aBuf,
      44             :               uint32_t aLen, bool* oDontFeedMe)
      45             : {
      46           0 :   NS_ASSERTION(mObserver != nullptr , "have not init yet");
      47             : 
      48           0 :   if((nullptr == aBuf) || (nullptr == oDontFeedMe))
      49           0 :     return NS_ERROR_ILLEGAL_VALUE;
      50             : 
      51           0 :   this->Reset();
      52           0 :   nsresult rv = this->HandleData(aBuf, aLen);
      53           0 :   if (NS_FAILED(rv))
      54           0 :     return rv;
      55             : 
      56           0 :   if (mDone)
      57             :   {
      58           0 :     if (mDetectedCharset)
      59           0 :       Report(mDetectedCharset);
      60             : 
      61           0 :     *oDontFeedMe = true;
      62             :   }
      63           0 :   *oDontFeedMe = false;
      64           0 :   return NS_OK;
      65             : }
      66             : //----------------------------------------------------------
      67           0 : NS_IMETHODIMP nsXPCOMDetector::Done()
      68             : {
      69           0 :   NS_ASSERTION(mObserver != nullptr , "have not init yet");
      70             : #ifdef DEBUG_chardet
      71             :   for (int32_t i = 0; i < NUM_OF_CHARSET_PROBERS; i++)
      72             :   {
      73             :     // If no data was received the array might stay filled with nulls
      74             :     // the way it was initialized in the constructor.
      75             :     if (mCharSetProbers[i])
      76             :       mCharSetProbers[i]->DumpStatus();
      77             :   }
      78             : #endif
      79             : 
      80           0 :   this->DataEnd();
      81           0 :   return NS_OK;
      82             : }
      83             : //----------------------------------------------------------
      84           0 : void nsXPCOMDetector::Report(const char* aCharset)
      85             : {
      86           0 :   NS_ASSERTION(mObserver != nullptr , "have not init yet");
      87             : #ifdef DEBUG_chardet
      88             :   printf("Universal Charset Detector report charset %s . \r\n", aCharset);
      89             : #endif
      90           0 :   mObserver->Notify(aCharset, eBestAnswer);
      91           0 : }
      92             : 
      93             : 
      94             : //---------------------------------------------------------------------
      95           0 : nsXPCOMStringDetector:: nsXPCOMStringDetector()
      96           0 :   : nsUniversalDetector()
      97             : {
      98           0 : }
      99             : //---------------------------------------------------------------------
     100           0 : nsXPCOMStringDetector::~nsXPCOMStringDetector()
     101             : {
     102           0 : }
     103             : //---------------------------------------------------------------------
     104           0 : NS_IMPL_ISUPPORTS(nsXPCOMStringDetector, nsIStringCharsetDetector)
     105             : //---------------------------------------------------------------------
     106           0 : void nsXPCOMStringDetector::Report(const char *aCharset)
     107             : {
     108           0 :   mResult = aCharset;
     109             : #ifdef DEBUG_chardet
     110             :   printf("New Charset Prober report charset %s . \r\n", aCharset);
     111             : #endif
     112           0 : }
     113             : //---------------------------------------------------------------------
     114           0 : NS_IMETHODIMP nsXPCOMStringDetector::DoIt(const char* aBuf,
     115             :                      uint32_t aLen, const char** oCharset,
     116             :                      nsDetectionConfident &oConf)
     117             : {
     118           0 :   mResult = nullptr;
     119           0 :   this->Reset();
     120           0 :   nsresult rv = this->HandleData(aBuf, aLen);
     121           0 :   if (NS_FAILED(rv))
     122           0 :     return rv;
     123           0 :   this->DataEnd();
     124           0 :   if (mResult)
     125             :   {
     126           0 :     *oCharset=mResult;
     127           0 :     oConf = eBestAnswer;
     128             :   }
     129           0 :   return NS_OK;
     130             : }

Generated by: LCOV version 1.13