Blame src/nsSBCharSetProber.h

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 Universal charset detector 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) 2001
Packit 67f6e7
 * the Initial Developer. All Rights Reserved.
Packit 67f6e7
 *
Packit 67f6e7
 * Contributor(s):
Packit 67f6e7
 *          Shy Shalom <shooshX@gmail.com>
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 nsSingleByteCharSetProber_h__
Packit 67f6e7
#define nsSingleByteCharSetProber_h__
Packit 67f6e7
Packit 67f6e7
#include "nsCharSetProber.h"
Packit 67f6e7
Packit 67f6e7
#define SAMPLE_SIZE 64
Packit 67f6e7
#define SB_ENOUGH_REL_THRESHOLD  1024
Packit 67f6e7
#define POSITIVE_SHORTCUT_THRESHOLD  (float)0.95
Packit 67f6e7
#define NEGATIVE_SHORTCUT_THRESHOLD  (float)0.05
Packit 67f6e7
#define SYMBOL_CAT_ORDER  250
Packit 67f6e7
#define NUMBER_OF_SEQ_CAT 4
Packit 67f6e7
#define POSITIVE_CAT   (NUMBER_OF_SEQ_CAT-1)
Packit 67f6e7
#define NEGATIVE_CAT   0
Packit 67f6e7
Packit 67f6e7
typedef struct
Packit 67f6e7
{
Packit 67f6e7
  unsigned char *charToOrderMap;    // [256] table use to find a char's order
Packit 67f6e7
  char *precedenceMatrix;           // [SAMPLE_SIZE][SAMPLE_SIZE]; table to find a 2-char sequence's frequency
Packit 67f6e7
  float  mTypicalPositiveRatio;     // = freqSeqs / totalSeqs 
Packit 67f6e7
  PRBool keepEnglishLetter;         // says if this script contains English characters (not implemented)
Packit 67f6e7
  const char* charsetName;
Packit 67f6e7
} SequenceModel;
Packit 67f6e7
Packit 67f6e7
Packit 67f6e7
class nsSingleByteCharSetProber : public nsCharSetProber{
Packit 67f6e7
public:
Packit 67f6e7
  nsSingleByteCharSetProber(SequenceModel *model) 
Packit 67f6e7
    :mModel(model), mReversed(PR_FALSE), mNameProber(0) { Reset(); }
Packit 67f6e7
  nsSingleByteCharSetProber(SequenceModel *model, PRBool reversed, nsCharSetProber* nameProber)
Packit 67f6e7
    :mModel(model), mReversed(reversed), mNameProber(nameProber) { Reset(); }
Packit 67f6e7
Packit 67f6e7
  virtual const char* GetCharSetName();
Packit 67f6e7
  virtual nsProbingState HandleData(const char* aBuf, PRUint32 aLen);
Packit 67f6e7
  virtual nsProbingState GetState(void) {return mState;};
Packit 67f6e7
  virtual void      Reset(void);
Packit 67f6e7
  virtual float     GetConfidence(void);
Packit 67f6e7
  virtual void      SetOpion() {};
Packit 67f6e7
  
Packit 67f6e7
  // This feature is not implemented yet. any current language model
Packit 67f6e7
  // contain this parameter as PR_FALSE. No one is looking at this
Packit 67f6e7
  // parameter or calling this method.
Packit 67f6e7
  // Moreover, the nsSBCSGroupProber which calls the HandleData of this
Packit 67f6e7
  // prober has a hard-coded call to FilterWithoutEnglishLetters which gets rid
Packit 67f6e7
  // of the English letters.
Packit 67f6e7
  PRBool KeepEnglishLetters() {return mModel->keepEnglishLetter;}; // (not implemented)
Packit 67f6e7
Packit 67f6e7
#ifdef DEBUG_chardet
Packit 67f6e7
  virtual void  DumpStatus();
Packit 67f6e7
#endif
Packit 67f6e7
Packit 67f6e7
protected:
Packit 67f6e7
  nsProbingState mState;
Packit 67f6e7
  const SequenceModel *mModel;
Packit 67f6e7
  const PRBool mReversed; // PR_TRUE if we need to reverse every pair in the model lookup
Packit 67f6e7
Packit 67f6e7
  //char order of last character
Packit 67f6e7
  unsigned char mLastOrder;
Packit 67f6e7
Packit 67f6e7
  PRUint32 mTotalSeqs;
Packit 67f6e7
  PRUint32 mSeqCounters[NUMBER_OF_SEQ_CAT];
Packit 67f6e7
Packit 67f6e7
  PRUint32 mTotalChar;
Packit 67f6e7
  //characters that fall in our sampling range
Packit 67f6e7
  PRUint32 mFreqChar;
Packit 67f6e7
  
Packit 67f6e7
  // Optional auxiliary prober for name decision. created and destroyed by the GroupProber
Packit 67f6e7
  nsCharSetProber* mNameProber; 
Packit 67f6e7
Packit 67f6e7
};
Packit 67f6e7
Packit 67f6e7
Packit 67f6e7
extern SequenceModel Koi8rModel;
Packit 67f6e7
extern SequenceModel Win1251Model;
Packit 67f6e7
extern SequenceModel Latin5Model;
Packit 67f6e7
extern SequenceModel MacCyrillicModel;
Packit 67f6e7
extern SequenceModel Ibm866Model;
Packit 67f6e7
extern SequenceModel Ibm855Model;
Packit 67f6e7
extern SequenceModel Latin7Model;
Packit 67f6e7
extern SequenceModel Win1253Model;
Packit 67f6e7
extern SequenceModel Latin5BulgarianModel;
Packit 67f6e7
extern SequenceModel Win1251BulgarianModel;
Packit 67f6e7
extern SequenceModel Latin2HungarianModel;
Packit 67f6e7
extern SequenceModel Win1250HungarianModel;
Packit 67f6e7
extern SequenceModel Win1255Model;
Packit 67f6e7
Packit 67f6e7
#endif /* nsSingleByteCharSetProber_h__ */
Packit 67f6e7