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

KDECore

  • kdecore
  • localization
  • probers
nsCodingStateMachine.h
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#ifndef nsCodingStateMachine_h__
27#define nsCodingStateMachine_h__
28
29#include "kencodingprober.h"
30
31#include "kdemacros.h"
32
33#include "nsPkgInt.h"
34namespace kencodingprober {
35typedef enum {
36 eStart = 0,
37 eError = 1,
38 eItsMe = 2
39} nsSMState;
40
41#define GETCLASS(c) GETFROMPCK(((unsigned char)(c)), mModel->classTable)
42
43//state machine model
44typedef struct
45{
46 nsPkgInt classTable;
47 unsigned int classFactor;
48 nsPkgInt stateTable;
49 const unsigned int* charLenTable;
50 const char* name;
51} SMModel;
52
53class KDE_NO_EXPORT nsCodingStateMachine {
54public:
55 nsCodingStateMachine(SMModel* sm){
56 mCurrentState = eStart;
57 mModel = sm;
58 };
59 nsSMState NextState(char c){
60 //for each byte we get its class KDE_NO_EXPORT , if it is first byte, we also get byte length
61 unsigned int byteCls = GETCLASS(c);
62 if (mCurrentState == eStart)
63 {
64 mCurrentBytePos = 0;
65 mCurrentCharLen = mModel->charLenTable[byteCls];
66 }
67 //from byte's class KDE_NO_EXPORT and stateTable, we get its next state
68 mCurrentState=(nsSMState)GETFROMPCK(mCurrentState*(mModel->classFactor)+byteCls,
69 mModel->stateTable);
70 mCurrentBytePos++;
71 return mCurrentState;
72 };
73 unsigned int GetCurrentCharLen(void) {return mCurrentCharLen;};
74 void Reset(void) {mCurrentState = eStart;};
75 const char * GetCodingStateMachine() {return mModel->name;};
76#ifdef DEBUG_PROBE
77 const char * DumpCurrentState(){
78 switch (mCurrentState) {
79 case eStart:
80 return "eStart";
81 case eError:
82 return "eError";
83 case eItsMe:
84 return "eItsMe";
85 default:
86 return "OK";
87 }
88 }
89#endif
90
91protected:
92 nsSMState mCurrentState;
93 unsigned int mCurrentCharLen;
94 unsigned int mCurrentBytePos;
95
96 SMModel *mModel;
97};
98
99extern KDE_NO_EXPORT SMModel UTF8SMModel;
100extern KDE_NO_EXPORT SMModel Big5SMModel;
101extern KDE_NO_EXPORT SMModel EUCJPSMModel;
102extern KDE_NO_EXPORT SMModel EUCKRSMModel;
103extern KDE_NO_EXPORT SMModel GB18030SMModel;
104extern KDE_NO_EXPORT SMModel SJISSMModel;
105extern KDE_NO_EXPORT SMModel UCS2LESMModel;
106extern KDE_NO_EXPORT SMModel UCS2BESMModel;
107
108
109extern KDE_NO_EXPORT SMModel HZSMModel;
110extern KDE_NO_EXPORT SMModel ISO2022CNSMModel;
111extern KDE_NO_EXPORT SMModel ISO2022JPSMModel;
112extern KDE_NO_EXPORT SMModel ISO2022KRSMModel;
113}
114#endif /* nsCodingStateMachine_h__ */
115
kencodingprober::nsCodingStateMachine
Definition: nsCodingStateMachine.h:53
kencodingprober::nsCodingStateMachine::mModel
SMModel * mModel
Definition: nsCodingStateMachine.h:96
kencodingprober::nsCodingStateMachine::NextState
nsSMState NextState(char c)
Definition: nsCodingStateMachine.h:59
kencodingprober::nsCodingStateMachine::mCurrentCharLen
unsigned int mCurrentCharLen
Definition: nsCodingStateMachine.h:93
kencodingprober::nsCodingStateMachine::mCurrentState
nsSMState mCurrentState
Definition: nsCodingStateMachine.h:92
kencodingprober::nsCodingStateMachine::Reset
void Reset(void)
Definition: nsCodingStateMachine.h:74
kencodingprober::nsCodingStateMachine::GetCurrentCharLen
unsigned int GetCurrentCharLen(void)
Definition: nsCodingStateMachine.h:73
kencodingprober::nsCodingStateMachine::GetCodingStateMachine
const char * GetCodingStateMachine()
Definition: nsCodingStateMachine.h:75
kencodingprober::nsCodingStateMachine::mCurrentBytePos
unsigned int mCurrentBytePos
Definition: nsCodingStateMachine.h:94
kencodingprober::nsCodingStateMachine::nsCodingStateMachine
nsCodingStateMachine(SMModel *sm)
Definition: nsCodingStateMachine.h:55
kencodingprober.h
kencodingprober
Definition: CharDistribution.cpp:37
kencodingprober::UCS2LESMModel
KDE_NO_EXPORT SMModel UCS2LESMModel
Definition: nsMBCSSM.cpp:475
kencodingprober::EUCJPSMModel
KDE_NO_EXPORT SMModel EUCJPSMModel
Definition: nsMBCSSM.cpp:137
kencodingprober::ISO2022JPSMModel
KDE_NO_EXPORT SMModel ISO2022JPSMModel
Definition: nsEscSM.cpp:192
kencodingprober::SJISSMModel
KDE_NO_EXPORT SMModel SJISSMModel
Definition: nsMBCSSM.cpp:362
kencodingprober::GB18030SMModel
KDE_NO_EXPORT SMModel GB18030SMModel
Definition: nsMBCSSM.cpp:305
kencodingprober::UTF8SMModel
KDE_NO_EXPORT SMModel UTF8SMModel
Definition: nsMBCSSM.cpp:553
kencodingprober::ISO2022KRSMModel
KDE_NO_EXPORT SMModel ISO2022KRSMModel
Definition: nsEscSM.cpp:246
kencodingprober::EUCKRSMModel
KDE_NO_EXPORT SMModel EUCKRSMModel
Definition: nsMBCSSM.cpp:189
kencodingprober::UCS2BESMModel
KDE_NO_EXPORT SMModel UCS2BESMModel
Definition: nsMBCSSM.cpp:419
kencodingprober::HZSMModel
KDE_NO_EXPORT SMModel HZSMModel
Definition: nsEscSM.cpp:76
kencodingprober::nsSMState
nsSMState
Definition: nsCodingStateMachine.h:35
kencodingprober::eItsMe
@ eItsMe
Definition: nsCodingStateMachine.h:38
kencodingprober::eError
@ eError
Definition: nsCodingStateMachine.h:37
kencodingprober::eStart
@ eStart
Definition: nsCodingStateMachine.h:36
kencodingprober::Big5SMModel
KDE_NO_EXPORT SMModel Big5SMModel
Definition: nsMBCSSM.cpp:82
kencodingprober::ISO2022CNSMModel
KDE_NO_EXPORT SMModel ISO2022CNSMModel
Definition: nsEscSM.cpp:134
GETCLASS
#define GETCLASS(c)
Definition: nsCodingStateMachine.h:41
nsPkgInt.h
GETFROMPCK
#define GETFROMPCK(i, c)
Definition: nsPkgInt.h:73
kencodingprober::SMModel
Definition: nsCodingStateMachine.h:45
kencodingprober::SMModel::stateTable
nsPkgInt stateTable
Definition: nsCodingStateMachine.h:48
kencodingprober::SMModel::charLenTable
const unsigned int * charLenTable
Definition: nsCodingStateMachine.h:49
kencodingprober::SMModel::name
const char * name
Definition: nsCodingStateMachine.h:50
kencodingprober::SMModel::classTable
nsPkgInt classTable
Definition: nsCodingStateMachine.h:46
kencodingprober::SMModel::classFactor
unsigned int classFactor
Definition: nsCodingStateMachine.h:47
kencodingprober::nsPkgInt
Definition: nsPkgInt.h:54
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 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-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 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
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
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