summaryrefslogtreecommitdiffstats
path: root/extensions/universalchardet/src/base/nsCodingStateMachine.h
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /extensions/universalchardet/src/base/nsCodingStateMachine.h
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'extensions/universalchardet/src/base/nsCodingStateMachine.h')
-rw-r--r--extensions/universalchardet/src/base/nsCodingStateMachine.h85
1 files changed, 85 insertions, 0 deletions
diff --git a/extensions/universalchardet/src/base/nsCodingStateMachine.h b/extensions/universalchardet/src/base/nsCodingStateMachine.h
new file mode 100644
index 000000000..53779959c
--- /dev/null
+++ b/extensions/universalchardet/src/base/nsCodingStateMachine.h
@@ -0,0 +1,85 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+#ifndef nsCodingStateMachine_h__
+#define nsCodingStateMachine_h__
+
+#include "mozilla/ArrayUtils.h"
+
+#include "nsPkgInt.h"
+
+typedef enum {
+ eStart = 0,
+ eError = 1,
+ eItsMe = 2
+} nsSMState;
+
+#define GETCLASS(c) GETFROMPCK(((unsigned char)(c)), mModel->classTable)
+
+//state machine model
+typedef struct
+{
+ nsPkgInt classTable;
+ uint32_t classFactor;
+ nsPkgInt stateTable;
+ const uint32_t* charLenTable;
+#ifdef DEBUG
+ const size_t charLenTableLength;
+#endif
+ const char* name;
+} SMModel;
+
+class nsCodingStateMachine {
+public:
+ explicit nsCodingStateMachine(const SMModel* sm) : mModel(sm) { mCurrentState = eStart; }
+ nsSMState NextState(char c){
+ //for each byte we get its class , if it is first byte, we also get byte length
+ uint32_t byteCls = GETCLASS(c);
+ if (mCurrentState == eStart)
+ {
+ mCurrentBytePos = 0;
+ MOZ_ASSERT(byteCls < mModel->charLenTableLength);
+ mCurrentCharLen = mModel->charLenTable[byteCls];
+ }
+ //from byte's class and stateTable, we get its next state
+ mCurrentState=(nsSMState)GETFROMPCK(mCurrentState*(mModel->classFactor)+byteCls,
+ mModel->stateTable);
+ mCurrentBytePos++;
+ return mCurrentState;
+ }
+ uint32_t GetCurrentCharLen(void) {return mCurrentCharLen;}
+ void Reset(void) {mCurrentState = eStart;}
+ const char * GetCodingStateMachine() {return mModel->name;}
+
+protected:
+ nsSMState mCurrentState;
+ uint32_t mCurrentCharLen;
+ uint32_t mCurrentBytePos;
+
+ const SMModel *mModel;
+};
+
+extern const SMModel UTF8SMModel;
+extern const SMModel Big5SMModel;
+extern const SMModel EUCJPSMModel;
+extern const SMModel EUCKRSMModel;
+extern const SMModel EUCTWSMModel;
+extern const SMModel GB18030SMModel;
+extern const SMModel SJISSMModel;
+
+
+extern const SMModel HZSMModel;
+extern const SMModel ISO2022CNSMModel;
+extern const SMModel ISO2022JPSMModel;
+extern const SMModel ISO2022KRSMModel;
+
+#undef CHAR_LEN_TABLE
+#ifdef DEBUG
+#define CHAR_LEN_TABLE(x) x, mozilla::ArrayLength(x)
+#else
+#define CHAR_LEN_TABLE(x) x
+#endif
+
+#endif /* nsCodingStateMachine_h__ */
+