|
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 #ifndef nsISO2022KRToUnicode_h__ |
|
6 #define nsISO2022KRToUnicode_h__ |
|
7 #include "nsUCSupport.h" |
|
8 #include "mozilla/Telemetry.h" |
|
9 |
|
10 class nsISO2022KRToUnicode : public nsBasicDecoderSupport |
|
11 { |
|
12 public: |
|
13 nsISO2022KRToUnicode() |
|
14 { |
|
15 mState = mState_Init; |
|
16 mLastLegalState = mState_ASCII; |
|
17 mData = 0; |
|
18 mEUCKRDecoder = nullptr; |
|
19 mRunLength = 0; |
|
20 mozilla::Telemetry::Accumulate( |
|
21 mozilla::Telemetry::DECODER_INSTANTIATED_ISO2022KR, true); |
|
22 } |
|
23 |
|
24 virtual ~nsISO2022KRToUnicode() |
|
25 { |
|
26 NS_IF_RELEASE(mEUCKRDecoder); |
|
27 } |
|
28 |
|
29 NS_IMETHOD Convert(const char * aSrc, int32_t * aSrcLength, |
|
30 char16_t * aDest, int32_t * aDestLength) ; |
|
31 |
|
32 NS_IMETHOD GetMaxLength(const char * aSrc, int32_t aSrcLength, |
|
33 int32_t * aDestLength) |
|
34 { |
|
35 *aDestLength = aSrcLength; |
|
36 return NS_OK; |
|
37 } |
|
38 |
|
39 NS_IMETHOD Reset() |
|
40 { |
|
41 mState = mState_Init; |
|
42 mLastLegalState = mState_ASCII; |
|
43 mRunLength = 0; |
|
44 return NS_OK; |
|
45 } |
|
46 |
|
47 private: |
|
48 enum { |
|
49 mState_Init, |
|
50 mState_ASCII, |
|
51 mState_ESC, |
|
52 mState_ESC_24, |
|
53 mState_ESC_24_29, |
|
54 mState_KSX1001_1992, |
|
55 mState_KSX1001_1992_2ndbyte, |
|
56 mState_ERROR |
|
57 } mState, mLastLegalState; |
|
58 |
|
59 uint8_t mData; |
|
60 |
|
61 // Length of non-ASCII run |
|
62 uint32_t mRunLength; |
|
63 |
|
64 nsIUnicodeDecoder *mEUCKRDecoder; |
|
65 }; |
|
66 #endif // nsISO2022KRToUnicode_h__ |