|
Packit |
67f6e7 |
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
Packit |
67f6e7 |
/* ***** BEGIN LICENSE BLOCK *****
|
|
Packit |
67f6e7 |
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
Packit |
67f6e7 |
*
|
|
Packit |
67f6e7 |
* The contents of this file are subject to the Mozilla Public License Version
|
|
Packit |
67f6e7 |
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
Packit |
67f6e7 |
* the License. You may obtain a copy of the License at
|
|
Packit |
67f6e7 |
* http://www.mozilla.org/MPL/
|
|
Packit |
67f6e7 |
*
|
|
Packit |
67f6e7 |
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
Packit |
67f6e7 |
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
Packit |
67f6e7 |
* for the specific language governing rights and limitations under the
|
|
Packit |
67f6e7 |
* License.
|
|
Packit |
67f6e7 |
*
|
|
Packit |
67f6e7 |
* The Original Code is mozilla.org code.
|
|
Packit |
67f6e7 |
*
|
|
Packit |
67f6e7 |
* The Initial Developer of the Original Code is
|
|
Packit |
67f6e7 |
* Netscape Communications Corporation.
|
|
Packit |
67f6e7 |
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
Packit |
67f6e7 |
* the Initial Developer. All Rights Reserved.
|
|
Packit |
67f6e7 |
*
|
|
Packit |
67f6e7 |
* Contributor(s):
|
|
Packit |
67f6e7 |
*
|
|
Packit |
67f6e7 |
* Alternatively, the contents of this file may be used under the terms of
|
|
Packit |
67f6e7 |
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
Packit |
67f6e7 |
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
Packit |
67f6e7 |
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
Packit |
67f6e7 |
* of those above. If you wish to allow use of your version of this file only
|
|
Packit |
67f6e7 |
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
Packit |
67f6e7 |
* use your version of this file under the terms of the MPL, indicate your
|
|
Packit |
67f6e7 |
* decision by deleting the provisions above and replace them with the notice
|
|
Packit |
67f6e7 |
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
Packit |
67f6e7 |
* the provisions above, a recipient may use your version of this file under
|
|
Packit |
67f6e7 |
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
Packit |
67f6e7 |
*
|
|
Packit |
67f6e7 |
* ***** END LICENSE BLOCK ***** */
|
|
Packit |
67f6e7 |
#ifndef nsCodingStateMachine_h__
|
|
Packit |
67f6e7 |
#define nsCodingStateMachine_h__
|
|
Packit |
67f6e7 |
|
|
Packit |
67f6e7 |
#include "nsPkgInt.h"
|
|
Packit |
67f6e7 |
|
|
Packit |
67f6e7 |
typedef enum {
|
|
Packit |
67f6e7 |
eStart = 0,
|
|
Packit |
67f6e7 |
eError = 1,
|
|
Packit |
67f6e7 |
eItsMe = 2
|
|
Packit |
67f6e7 |
} nsSMState;
|
|
Packit |
67f6e7 |
|
|
Packit |
67f6e7 |
#define GETCLASS(c) GETFROMPCK(((unsigned char)(c)), mModel->classTable)
|
|
Packit |
67f6e7 |
|
|
Packit |
67f6e7 |
//state machine model
|
|
Packit |
67f6e7 |
typedef struct
|
|
Packit |
67f6e7 |
{
|
|
Packit |
67f6e7 |
nsPkgInt classTable;
|
|
Packit |
67f6e7 |
PRUint32 classFactor;
|
|
Packit |
67f6e7 |
nsPkgInt stateTable;
|
|
Packit |
67f6e7 |
const PRUint32* charLenTable;
|
|
Packit |
67f6e7 |
const char* name;
|
|
Packit |
67f6e7 |
} SMModel;
|
|
Packit |
67f6e7 |
|
|
Packit |
67f6e7 |
class nsCodingStateMachine {
|
|
Packit |
67f6e7 |
public:
|
|
Packit |
67f6e7 |
nsCodingStateMachine(SMModel* sm){
|
|
Packit |
67f6e7 |
mCurrentState = eStart;
|
|
Packit |
67f6e7 |
mModel = sm;
|
|
Packit |
67f6e7 |
};
|
|
Packit |
67f6e7 |
nsSMState NextState(char c){
|
|
Packit |
67f6e7 |
//for each byte we get its class , if it is first byte, we also get byte length
|
|
Packit |
67f6e7 |
PRUint32 byteCls = GETCLASS(c);
|
|
Packit |
67f6e7 |
if (mCurrentState == eStart)
|
|
Packit |
67f6e7 |
{
|
|
Packit |
67f6e7 |
mCurrentBytePos = 0;
|
|
Packit |
67f6e7 |
mCurrentCharLen = mModel->charLenTable[byteCls];
|
|
Packit |
67f6e7 |
}
|
|
Packit |
67f6e7 |
//from byte's class and stateTable, we get its next state
|
|
Packit |
67f6e7 |
mCurrentState=(nsSMState)GETFROMPCK(mCurrentState*(mModel->classFactor)+byteCls,
|
|
Packit |
67f6e7 |
mModel->stateTable);
|
|
Packit |
67f6e7 |
mCurrentBytePos++;
|
|
Packit |
67f6e7 |
return mCurrentState;
|
|
Packit |
67f6e7 |
};
|
|
Packit |
67f6e7 |
PRUint32 GetCurrentCharLen(void) {return mCurrentCharLen;};
|
|
Packit |
67f6e7 |
void Reset(void) {mCurrentState = eStart;};
|
|
Packit |
67f6e7 |
const char * GetCodingStateMachine() {return mModel->name;};
|
|
Packit |
67f6e7 |
|
|
Packit |
67f6e7 |
protected:
|
|
Packit |
67f6e7 |
nsSMState mCurrentState;
|
|
Packit |
67f6e7 |
PRUint32 mCurrentCharLen;
|
|
Packit |
67f6e7 |
PRUint32 mCurrentBytePos;
|
|
Packit |
67f6e7 |
|
|
Packit |
67f6e7 |
SMModel *mModel;
|
|
Packit |
67f6e7 |
};
|
|
Packit |
67f6e7 |
|
|
Packit |
67f6e7 |
extern SMModel UTF8SMModel;
|
|
Packit |
67f6e7 |
extern SMModel Big5SMModel;
|
|
Packit |
67f6e7 |
extern SMModel EUCJPSMModel;
|
|
Packit |
67f6e7 |
extern SMModel EUCKRSMModel;
|
|
Packit |
67f6e7 |
extern SMModel EUCTWSMModel;
|
|
Packit |
67f6e7 |
extern SMModel GB18030SMModel;
|
|
Packit |
67f6e7 |
extern SMModel SJISSMModel;
|
|
Packit |
67f6e7 |
extern SMModel UCS2BESMModel;
|
|
Packit |
67f6e7 |
|
|
Packit |
67f6e7 |
|
|
Packit |
67f6e7 |
extern SMModel HZSMModel;
|
|
Packit |
67f6e7 |
extern SMModel ISO2022CNSMModel;
|
|
Packit |
67f6e7 |
extern SMModel ISO2022JPSMModel;
|
|
Packit |
67f6e7 |
extern SMModel ISO2022KRSMModel;
|
|
Packit |
67f6e7 |
|
|
Packit |
67f6e7 |
#endif /* nsCodingStateMachine_h__ */
|
|
Packit |
67f6e7 |
|