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

KDECore

  • sources
  • kde-4.12
  • kdelibs
  • kdecore
  • localization
  • probers
nsEscCharsetProber.cpp
Go to the documentation of this file.
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* -*- C++ -*-
3 * Copyright (C) 1998 <developer@mozilla.org>
4 *
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25 
26 #include "nsEscCharsetProber.h"
27 
28 namespace kencodingprober {
29 nsEscCharSetProber::nsEscCharSetProber(void)
30 {
31  mCodingSM[0] = new nsCodingStateMachine(&HZSMModel);
32  mCodingSM[1] = new nsCodingStateMachine(&ISO2022CNSMModel);
33  mCodingSM[2] = new nsCodingStateMachine(&ISO2022JPSMModel);
34  mCodingSM[3] = new nsCodingStateMachine(&ISO2022KRSMModel);
35  mActiveSM = NUM_OF_ESC_CHARSETS;
36  mState = eDetecting;
37  mDetectedCharset = 0;
38 }
39 
40 nsEscCharSetProber::~nsEscCharSetProber(void)
41 {
42  for (unsigned int i = 0; i < NUM_OF_ESC_CHARSETS; i++)
43  delete mCodingSM[i];
44 }
45 
46 void nsEscCharSetProber::Reset(void)
47 {
48  mState = eDetecting;
49  for (unsigned int i = 0; i < NUM_OF_ESC_CHARSETS; i++)
50  mCodingSM[i]->Reset();
51  mActiveSM = NUM_OF_ESC_CHARSETS;
52  mDetectedCharset = 0;
53 }
54 
55 nsProbingState nsEscCharSetProber::HandleData(const char* aBuf, unsigned int aLen)
56 {
57  nsSMState codingState;
58  int j;
59  unsigned int i;
60 
61  for ( i = 0; i < aLen && mState == eDetecting; i++)
62  {
63  for (j = mActiveSM-1; j>= 0; j--)
64  {
65  //byte is feed to all active state machine
66  codingState = mCodingSM[j]->NextState(aBuf[i]);
67  if (codingState == eError)
68  {
69  //got negative answer for this state machine, make it inactive
70  mActiveSM--;
71  if (mActiveSM == 0)
72  {
73  mState = eNotMe;
74  return mState;
75  }
76  else if (j != (int)mActiveSM)
77  {
78  nsCodingStateMachine* t;
79  t = mCodingSM[mActiveSM];
80  mCodingSM[mActiveSM] = mCodingSM[j];
81  mCodingSM[j] = t;
82  }
83  }
84  else if (codingState == eItsMe)
85  {
86  mState = eFoundIt;
87  mDetectedCharset = mCodingSM[j]->GetCodingStateMachine();
88  return mState;
89  }
90  }
91  }
92 
93  return mState;
94 }
95 }
96 
97 
nsEscCharsetProber.h
kencodingprober::nsEscCharSetProber::Reset
void Reset(void)
Definition: nsEscCharsetProber.cpp:46
kencodingprober::nsEscCharSetProber::mCodingSM
nsCodingStateMachine * mCodingSM[NUM_OF_ESC_CHARSETS]
Definition: nsEscCharsetProber.h:48
kencodingprober::ISO2022KRSMModel
KDE_NO_EXPORT SMModel ISO2022KRSMModel
Definition: nsEscSM.cpp:246
kencodingprober::nsEscCharSetProber::mActiveSM
unsigned int mActiveSM
Definition: nsEscCharsetProber.h:49
kencodingprober::nsCodingStateMachine::NextState
nsSMState NextState(char c)
Definition: nsCodingStateMachine.h:59
kencodingprober::HZSMModel
KDE_NO_EXPORT SMModel HZSMModel
Definition: nsEscSM.cpp:76
kencodingprober::eError
Definition: nsCodingStateMachine.h:37
kencodingprober::eFoundIt
Definition: nsCharSetProber.h:36
kencodingprober::ISO2022JPSMModel
KDE_NO_EXPORT SMModel ISO2022JPSMModel
Definition: nsEscSM.cpp:192
kencodingprober::ISO2022CNSMModel
KDE_NO_EXPORT SMModel ISO2022CNSMModel
Definition: nsEscSM.cpp:134
kencodingprober::nsProbingState
nsProbingState
Definition: nsCharSetProber.h:34
NUM_OF_ESC_CHARSETS
#define NUM_OF_ESC_CHARSETS
Definition: nsEscCharsetProber.h:32
kencodingprober::nsCodingStateMachine::GetCodingStateMachine
const char * GetCodingStateMachine()
Definition: nsCodingStateMachine.h:75
kencodingprober::eNotMe
Definition: nsCharSetProber.h:37
kencodingprober::nsEscCharSetProber::~nsEscCharSetProber
virtual ~nsEscCharSetProber(void)
Definition: nsEscCharsetProber.cpp:40
kencodingprober::nsEscCharSetProber::nsEscCharSetProber
nsEscCharSetProber(void)
Definition: nsEscCharsetProber.cpp:29
kencodingprober::nsCodingStateMachine
Definition: nsCodingStateMachine.h:53
kencodingprober::eDetecting
Definition: nsCharSetProber.h:35
kencodingprober::eItsMe
Definition: nsCodingStateMachine.h:38
kencodingprober::nsEscCharSetProber::mDetectedCharset
const char * mDetectedCharset
Definition: nsEscCharsetProber.h:51
kencodingprober::nsEscCharSetProber::HandleData
nsProbingState HandleData(const char *aBuf, unsigned int aLen)
Definition: nsEscCharsetProber.cpp:55
kencodingprober::nsSMState
nsSMState
Definition: nsCodingStateMachine.h:35
kencodingprober::nsEscCharSetProber::mState
nsProbingState mState
Definition: nsEscCharsetProber.h:50
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:47:09 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDECore

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

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal