File indexing completed on 2024-05-19 07:41:56
0001 /* -*- C++ -*- 0002 SPDX-FileCopyrightText: 1998 Netscape Communications Corporation <developer@mozilla.org> 0003 0004 SPDX-License-Identifier: MIT 0005 */ 0006 0007 #include "nsBig5Prober.h" 0008 0009 namespace kencodingprober 0010 { 0011 void nsBig5Prober::Reset(void) 0012 { 0013 mCodingSM->Reset(); 0014 mState = eDetecting; 0015 mDistributionAnalyser.Reset(); 0016 } 0017 0018 nsProbingState nsBig5Prober::HandleData(const char *aBuf, unsigned int aLen) 0019 { 0020 if (aLen == 0) { 0021 return mState; 0022 } 0023 0024 for (unsigned int i = 0; i < aLen; i++) { 0025 const nsSMState codingState = mCodingSM->NextState(aBuf[i]); 0026 if (codingState == eError) { 0027 mState = eNotMe; 0028 break; 0029 } 0030 if (codingState == eItsMe) { 0031 mState = eFoundIt; 0032 break; 0033 } 0034 if (codingState == eStart) { 0035 unsigned int charLen = mCodingSM->GetCurrentCharLen(); 0036 0037 if (i == 0) { 0038 mLastChar[1] = aBuf[0]; 0039 mDistributionAnalyser.HandleOneChar(mLastChar, charLen); 0040 } else { 0041 mDistributionAnalyser.HandleOneChar(aBuf + i - 1, charLen); 0042 } 0043 } 0044 } 0045 0046 mLastChar[0] = aBuf[aLen - 1]; 0047 0048 if (mState == eDetecting) { 0049 if (mDistributionAnalyser.GotEnoughData() && GetConfidence() > SHORTCUT_THRESHOLD) { 0050 mState = eFoundIt; 0051 } 0052 } 0053 0054 return mState; 0055 } 0056 0057 float nsBig5Prober::GetConfidence(void) 0058 { 0059 float distribCf = mDistributionAnalyser.GetConfidence(); 0060 0061 return (float)distribCf; 0062 } 0063 }