• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KDECore

  • sources
  • kde-4.12
  • kdelibs
  • kdecore
  • localization
  • probers
nsSJISProber.cpp
Go to the documentation of this file.
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* -*- C++ -*-
3 * Copyright (C) 1998 <developer@mozilla.org>
4 *
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25 
26 // for S-JIS encoding, obeserve characteristic:
27 // 1, kana character (or hankaku?) often have hight frequency of appereance
28 // 2, kana character often exist in group
29 // 3, certain combination of kana is never used in japanese language
30 
31 
32 
33 #include "nsSJISProber.h"
34 
35 namespace kencodingprober {
36 void nsSJISProber::Reset(void)
37 {
38  mCodingSM->Reset();
39  mState = eDetecting;
40  mContextAnalyser.Reset();
41  mDistributionAnalyser.Reset();
42 }
43 
44 nsProbingState nsSJISProber::HandleData(const char* aBuf, unsigned int aLen)
45 {
46  nsSMState codingState;
47 
48  for (unsigned int i = 0; i < aLen; i++)
49  {
50  codingState = mCodingSM->NextState(aBuf[i]);
51  if (codingState == eError)
52  {
53  mState = eNotMe;
54  break;
55  }
56  if (codingState == eItsMe)
57  {
58  mState = eFoundIt;
59  break;
60  }
61  if (codingState == eStart)
62  {
63  unsigned int charLen = mCodingSM->GetCurrentCharLen();
64  if (i == 0)
65  {
66  mLastChar[1] = aBuf[0];
67  mContextAnalyser.HandleOneChar(mLastChar+2-charLen, charLen);
68  mDistributionAnalyser.HandleOneChar(mLastChar, charLen);
69  }
70  else
71  {
72  mContextAnalyser.HandleOneChar(aBuf+i+1-charLen, charLen);
73  mDistributionAnalyser.HandleOneChar(aBuf+i-1, charLen);
74  }
75  }
76  }
77 
78  mLastChar[0] = aBuf[aLen-1];
79 
80  if (mState == eDetecting)
81  if (mContextAnalyser.GotEnoughData() && GetConfidence() > SHORTCUT_THRESHOLD)
82  mState = eFoundIt;
83 
84  return mState;
85 }
86 
87 float nsSJISProber::GetConfidence(void)
88 {
89  float contxtCf = mContextAnalyser.GetConfidence();
90  float distribCf = mDistributionAnalyser.GetConfidence();
91 
92  return (contxtCf > distribCf ? contxtCf : distribCf);
93 }
94 }
95 
96 
kencodingprober::nsSJISProber::mLastChar
char mLastChar[2]
Definition: nsSJISProber.h:71
kencodingprober::JapaneseContextAnalysis::HandleOneChar
void HandleOneChar(const char *aStr, unsigned int aCharLen)
Definition: JpCntx.h:47
nsSJISProber.h
kencodingprober::nsSJISProber::mContextAnalyser
SJISContextAnalysis mContextAnalyser
Definition: nsSJISProber.h:68
kencodingprober::nsCodingStateMachine::NextState
nsSMState NextState(char c)
Definition: nsCodingStateMachine.h:59
kencodingprober::JapaneseContextAnalysis::Reset
void Reset(void)
Definition: JpCntx.cpp:161
kencodingprober::nsSJISProber::Reset
void Reset(void)
Definition: nsSJISProber.cpp:36
kencodingprober::nsSJISProber::mDistributionAnalyser
SJISDistributionAnalysis mDistributionAnalyser
Definition: nsSJISProber.h:69
kencodingprober::JapaneseContextAnalysis::GetConfidence
float GetConfidence()
Definition: JpCntx.cpp:172
kencodingprober::nsSJISProber::mState
nsProbingState mState
Definition: nsSJISProber.h:66
kencodingprober::eError
Definition: nsCodingStateMachine.h:37
kencodingprober::eFoundIt
Definition: nsCharSetProber.h:36
SHORTCUT_THRESHOLD
#define SHORTCUT_THRESHOLD
Definition: nsCharSetProber.h:40
kencodingprober::nsSJISProber::HandleData
nsProbingState HandleData(const char *aBuf, unsigned int aLen)
Definition: nsSJISProber.cpp:44
kencodingprober::nsCodingStateMachine::Reset
void Reset(void)
Definition: nsCodingStateMachine.h:74
kencodingprober::nsCodingStateMachine::GetCurrentCharLen
unsigned int GetCurrentCharLen(void)
Definition: nsCodingStateMachine.h:73
kencodingprober::nsSJISProber::GetConfidence
float GetConfidence(void)
Definition: nsSJISProber.cpp:87
kencodingprober::nsProbingState
nsProbingState
Definition: nsCharSetProber.h:34
kencodingprober::eNotMe
Definition: nsCharSetProber.h:37
kencodingprober::nsSJISProber::mCodingSM
nsCodingStateMachine * mCodingSM
Definition: nsSJISProber.h:62
kencodingprober::eDetecting
Definition: nsCharSetProber.h:35
kencodingprober::eItsMe
Definition: nsCodingStateMachine.h:38
kencodingprober::eStart
Definition: nsCodingStateMachine.h:36
kencodingprober::CharDistributionAnalysis::Reset
void Reset(void)
Definition: CharDistribution.h:67
kencodingprober::nsSMState
nsSMState
Definition: nsCodingStateMachine.h:35
kencodingprober::JapaneseContextAnalysis::GotEnoughData
bool GotEnoughData()
Definition: JpCntx.h:69
kencodingprober::CharDistributionAnalysis::HandleOneChar
void HandleOneChar(const char *aStr, unsigned int aCharLen)
Definition: CharDistribution.h:44
kencodingprober::CharDistributionAnalysis::GetConfidence
float GetConfidence()
Definition: CharDistribution.cpp:40
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:47:09 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDECore

Skip menu "KDECore"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal