• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KDECore

nsEscCharsetProber.cpp

Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /*  -*- C++ -*-
00003 *  Copyright (C) 1998 <developer@mozilla.org>
00004 *
00005 *
00006 *  Permission is hereby granted, free of charge, to any person obtaining
00007 *  a copy of this software and associated documentation files (the
00008 *  "Software"), to deal in the Software without restriction, including
00009 *  without limitation the rights to use, copy, modify, merge, publish,
00010 *  distribute, sublicense, and/or sell copies of the Software, and to
00011 *  permit persons to whom the Software is furnished to do so, subject to
00012 *  the following conditions:
00013 *
00014 *  The above copyright notice and this permission notice shall be included 
00015 *  in all copies or substantial portions of the Software.
00016 *
00017 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00018 *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00019 *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00020 *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00021 *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00022 *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00023 *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00024 */
00025 
00026 #include "nsEscCharsetProber.h"
00027 
00028 namespace kencodingprober {
00029 nsEscCharSetProber::nsEscCharSetProber(void)
00030 {
00031   mCodingSM[0] = new nsCodingStateMachine(&HZSMModel);
00032   mCodingSM[1] = new nsCodingStateMachine(&ISO2022CNSMModel);
00033   mCodingSM[2] = new nsCodingStateMachine(&ISO2022JPSMModel);
00034   mCodingSM[3] = new nsCodingStateMachine(&ISO2022KRSMModel);
00035   mActiveSM = NUM_OF_ESC_CHARSETS;
00036   mState = eDetecting;
00037   mDetectedCharset = 0;
00038 }
00039 
00040 nsEscCharSetProber::~nsEscCharSetProber(void)
00041 {
00042   for (unsigned int i = 0; i < NUM_OF_ESC_CHARSETS; i++)
00043     delete mCodingSM[i];
00044 }
00045 
00046 void nsEscCharSetProber::Reset(void)
00047 {
00048   mState = eDetecting;
00049   for (unsigned int i = 0; i < NUM_OF_ESC_CHARSETS; i++)
00050     mCodingSM[i]->Reset();
00051   mActiveSM = NUM_OF_ESC_CHARSETS;
00052   mDetectedCharset = 0;
00053 }
00054 
00055 nsProbingState nsEscCharSetProber::HandleData(const char* aBuf, unsigned int aLen)
00056 {
00057   nsSMState codingState;
00058   int j;
00059   unsigned int i;
00060 
00061   for ( i = 0; i < aLen && mState == eDetecting; i++)
00062   {
00063     for (j = mActiveSM-1; j>= 0; j--)
00064     {
00065       //byte is feed to all active state machine 
00066       codingState = mCodingSM[j]->NextState(aBuf[i]);
00067       if (codingState == eError)
00068       {
00069         //got negative answer for this state machine, make it inactive
00070         mActiveSM--;
00071         if (mActiveSM == 0)
00072         {
00073           mState = eNotMe;
00074           return mState;
00075         }
00076         else if (j != (int)mActiveSM)
00077         {
00078           nsCodingStateMachine* t;
00079           t = mCodingSM[mActiveSM];
00080           mCodingSM[mActiveSM] = mCodingSM[j];
00081           mCodingSM[j] = t;
00082         }
00083       }
00084       else if (codingState == eItsMe)
00085       {
00086         mState = eFoundIt;
00087         mDetectedCharset = mCodingSM[j]->GetCodingStateMachine();
00088         return mState;
00089       }
00090     }
00091   }
00092 
00093   return mState;
00094 }
00095 }
00096 
00097 

KDECore

Skip menu "KDECore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal