charconvfw/charconvplugins/src/shared/gb2312_shared.cpp
branchRCL_3
changeset 28 26914f8d1faf
parent 0 1fb32624e06b
equal deleted inserted replaced
25:1799ab513ec3 28:26914f8d1faf
    40 	TInt totalWeight=0;		//sum of the weights of 20 most frequent chars
    40 	TInt totalWeight=0;		//sum of the weights of 20 most frequent chars
    41 	TInt sumOfGoodChar=0;		//the number of chars whose first byte and second are both in the range
    41 	TInt sumOfGoodChar=0;		//the number of chars whose first byte and second are both in the range
    42 	TInt sumOfWeight=0;		//sum of the weights of the chars which are included in the sample
    42 	TInt sumOfWeight=0;		//sum of the weights of the chars which are included in the sample
    43 	TInt sumOutChar=0;		//the number of chars which are not common
    43 	TInt sumOutChar=0;		//the number of chars which are not common
    44 	TInt sumOfBadSecondByte=0;//the number of chars whose first byte is in the range but not the second
    44 	TInt sumOfBadSecondByte=0;//the number of chars whose first byte is in the range but not the second
       
    45 	TInt sumOfBadSingleByte=0;	//the number of bad single byte, which is not in valid range
    45 	struct referenceChar
    46 	struct referenceChar
    46 		{
    47 		{
    47 		TUint charGBK;
    48 		TUint charGBK;
    48 		TInt weight;
    49 		TInt weight;
    49 		};
    50 		};
   103 			else
   104 			else
   104 				{
   105 				{
   105 				sumOfBadSecondByte++;				
   106 				sumOfBadSecondByte++;				
   106 				}
   107 				}
   107 			}
   108 			}
       
   109 		// if seldom used characters
       
   110 		else if (aSample[i] < 0x20 || aSample[i] > 0x7F ) 
       
   111 			{
       
   112 			if (aSample[i]!=0x09 && aSample[i]!=0x0A && aSample[i]!=0x0D)
       
   113 				sumOfBadSingleByte++;
       
   114 			}
   108 		} // for 
   115 		} // for 
   109 
   116 
   110 	TInt limit;
   117 	TInt limit;
   111 	limit = (10*sampleLength)/100;
   118 	limit = (10*sampleLength)/100;
   112 	if (sumOfGoodChar > limit)
   119 	if (sumOfGoodChar > limit)
   113 		{
   120 		{
   114 		aConfidenceLevel=sumOfGoodChar*100/(sumOfBadSecondByte+sumOfGoodChar);
   121 		aConfidenceLevel=sumOfGoodChar*100/(sumOfBadSecondByte+sumOfGoodChar+sumOfBadSingleByte);
   115 		aConfidenceLevel=aConfidenceLevel-Max(0,((totalWeight-sumOfWeight)*sumOfGoodChar/1000));//against frequent chars 
   122 		aConfidenceLevel=aConfidenceLevel-Max(0,((totalWeight-sumOfWeight)*sumOfGoodChar/1000));//against frequent chars 
   116 		aConfidenceLevel=aConfidenceLevel-(sumOutChar*100/sumOfGoodChar);//against gap
   123 		aConfidenceLevel=aConfidenceLevel-(sumOutChar*100/sumOfGoodChar);//against gap
   117 		aConfidenceLevel=(aConfidenceLevel < 0)?0:aConfidenceLevel;
   124 		aConfidenceLevel=(aConfidenceLevel < 0)?0:aConfidenceLevel;
   118 		}
   125 		}
   119 	else
   126 	else