• 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
JpCntx.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 2; 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 #ifndef __JPCNTX_H__
27 #define __JPCNTX_H__
28 
29 #include "kdemacros.h"
30 
31 #define NUM_OF_CATEGORY 6
32 
33 #define ENOUGH_REL_THRESHOLD 100
34 #define MAX_REL_THRESHOLD 1000
35 namespace kencodingprober {
36 //hiragana frequency category table
37 extern const char jp2CharContext[83][83];
38 
39 class KDE_NO_EXPORT JapaneseContextAnalysis
40 {
41 public:
42  JapaneseContextAnalysis() {Reset();};
43  virtual ~JapaneseContextAnalysis() {};
44 
45  void HandleData(const char* aBuf, unsigned int aLen);
46 
47  void HandleOneChar(const char* aStr, unsigned int aCharLen)
48  {
49  int order;
50 
51  //if we received enough data, stop here
52  if (mTotalRel > MAX_REL_THRESHOLD) mDone = true;
53  if (mDone) return;
54 
55  //Only 2-bytes characters are of our interest
56  order = (aCharLen == 2) ? GetOrder(aStr) : -1;
57  if (order != -1 && mLastCharOrder != -1)
58  {
59  mTotalRel++;
60  //count this sequence to its category counter
61  mRelSample[(int)jp2CharContext[mLastCharOrder][order]]++;
62  }
63  mLastCharOrder = order;
64  };
65 
66  float GetConfidence();
67  void Reset(void);
68  void SetOpion(){};
69  bool GotEnoughData() {return mTotalRel > ENOUGH_REL_THRESHOLD;};
70 
71 protected:
72  virtual int GetOrder(const char* str, unsigned int *charLen) = 0;
73  virtual int GetOrder(const char* str) = 0;
74 
75  //category counters, each interger counts sequence in its category
76  unsigned int mRelSample[NUM_OF_CATEGORY];
77 
78  //total sequence received
79  unsigned int mTotalRel;
80 
81  //The order of previous char
82  int mLastCharOrder;
83 
84  //if last byte in current buffer is not the last byte of a character, we
85  //need to know how many byte to skip in next buffer.
86  unsigned int mNeedToSkipCharNum;
87 
88  //If this flag is set to true, detection is done and conclusion has been made
89  bool mDone;
90 };
91 
92 
93 class KDE_NO_EXPORT SJISContextAnalysis : public JapaneseContextAnalysis
94 {
95  //SJISContextAnalysis(){};
96 protected:
97  int GetOrder(const char* str, unsigned int *charLen);
98 
99  int GetOrder(const char* str)
100  {
101  //We only interested in Hiragana, so first byte is '\202'
102  if (*str == '\202' &&
103  (unsigned char)*(str+1) >= (unsigned char)0x9f &&
104  (unsigned char)*(str+1) <= (unsigned char)0xf1)
105  return (unsigned char)*(str+1) - (unsigned char)0x9f;
106  return -1;
107  };
108 };
109 
110 class KDE_NO_EXPORT EUCJPContextAnalysis : public JapaneseContextAnalysis
111 {
112 protected:
113  int GetOrder(const char* str, unsigned int *charLen);
114  int GetOrder(const char* str)
115  //We only interested in Hiragana, so first byte is '\244'
116  {
117  if (*str == '\244' &&
118  (unsigned char)*(str+1) >= (unsigned char)0xa1 &&
119  (unsigned char)*(str+1) <= (unsigned char)0xf3)
120  return (unsigned char)*(str+1) - (unsigned char)0xa1;
121  return -1;
122  };
123 };
124 }
125 #endif /* __JPCNTX_H__ */
126 
kencodingprober::JapaneseContextAnalysis::~JapaneseContextAnalysis
virtual ~JapaneseContextAnalysis()
Definition: JpCntx.h:43
kencodingprober::JapaneseContextAnalysis::HandleOneChar
void HandleOneChar(const char *aStr, unsigned int aCharLen)
Definition: JpCntx.h:47
KDE_NO_EXPORT
#define KDE_NO_EXPORT
The KDE_NO_EXPORT macro marks the symbol of the given variable to be hidden.
Definition: kdemacros.h.cmake:73
kencodingprober::JapaneseContextAnalysis::mNeedToSkipCharNum
unsigned int mNeedToSkipCharNum
Definition: JpCntx.h:86
kencodingprober::JapaneseContextAnalysis::SetOpion
void SetOpion()
Definition: JpCntx.h:68
kencodingprober::jp2CharContext
const char jp2CharContext[83][83]
Definition: JpCntx.cpp:30
ENOUGH_REL_THRESHOLD
#define ENOUGH_REL_THRESHOLD
Definition: JpCntx.h:33
kencodingprober::JapaneseContextAnalysis
Definition: JpCntx.h:39
kencodingprober::EUCJPContextAnalysis
Definition: JpCntx.h:110
kencodingprober::JapaneseContextAnalysis::JapaneseContextAnalysis
JapaneseContextAnalysis()
Definition: JpCntx.h:42
kencodingprober::JapaneseContextAnalysis::mTotalRel
unsigned int mTotalRel
Definition: JpCntx.h:79
kencodingprober::JapaneseContextAnalysis::mLastCharOrder
int mLastCharOrder
Definition: JpCntx.h:82
NUM_OF_CATEGORY
#define NUM_OF_CATEGORY
Definition: JpCntx.h:31
kencodingprober::SJISContextAnalysis
Definition: JpCntx.h:93
kencodingprober::EUCJPContextAnalysis::GetOrder
int GetOrder(const char *str)
Definition: JpCntx.h:114
kencodingprober::SJISContextAnalysis::GetOrder
int GetOrder(const char *str)
Definition: JpCntx.h:99
kencodingprober::JapaneseContextAnalysis::mDone
bool mDone
Definition: JpCntx.h:89
MAX_REL_THRESHOLD
#define MAX_REL_THRESHOLD
Definition: JpCntx.h:34
kencodingprober::JapaneseContextAnalysis::GotEnoughData
bool GotEnoughData()
Definition: JpCntx.h:69
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:47:07 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