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

KDECore

  • 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
35namespace kencodingprober {
36//hiragana frequency category table
37extern const char jp2CharContext[83][83];
38
39class KDE_NO_EXPORT JapaneseContextAnalysis
40{
41public:
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
71protected:
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
93class KDE_NO_EXPORT SJISContextAnalysis : public JapaneseContextAnalysis
94{
95 //SJISContextAnalysis(){};
96protected:
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
110class KDE_NO_EXPORT EUCJPContextAnalysis : public JapaneseContextAnalysis
111{
112protected:
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
MAX_REL_THRESHOLD
#define MAX_REL_THRESHOLD
Definition: JpCntx.h:34
ENOUGH_REL_THRESHOLD
#define ENOUGH_REL_THRESHOLD
Definition: JpCntx.h:33
NUM_OF_CATEGORY
#define NUM_OF_CATEGORY
Definition: JpCntx.h:31
kencodingprober::EUCJPContextAnalysis
Definition: JpCntx.h:111
kencodingprober::EUCJPContextAnalysis::GetOrder
int GetOrder(const char *str)
Definition: JpCntx.h:114
kencodingprober::JapaneseContextAnalysis
Definition: JpCntx.h:40
kencodingprober::JapaneseContextAnalysis::mNeedToSkipCharNum
unsigned int mNeedToSkipCharNum
Definition: JpCntx.h:86
kencodingprober::JapaneseContextAnalysis::mDone
bool mDone
Definition: JpCntx.h:89
kencodingprober::JapaneseContextAnalysis::mLastCharOrder
int mLastCharOrder
Definition: JpCntx.h:82
kencodingprober::JapaneseContextAnalysis::GetOrder
virtual int GetOrder(const char *str, unsigned int *charLen)=0
kencodingprober::JapaneseContextAnalysis::~JapaneseContextAnalysis
virtual ~JapaneseContextAnalysis()
Definition: JpCntx.h:43
kencodingprober::JapaneseContextAnalysis::HandleOneChar
void HandleOneChar(const char *aStr, unsigned int aCharLen)
Definition: JpCntx.h:47
kencodingprober::JapaneseContextAnalysis::SetOpion
void SetOpion()
Definition: JpCntx.h:68
kencodingprober::JapaneseContextAnalysis::GetOrder
virtual int GetOrder(const char *str)=0
kencodingprober::JapaneseContextAnalysis::JapaneseContextAnalysis
JapaneseContextAnalysis()
Definition: JpCntx.h:42
kencodingprober::JapaneseContextAnalysis::GotEnoughData
bool GotEnoughData()
Definition: JpCntx.h:69
kencodingprober::JapaneseContextAnalysis::mTotalRel
unsigned int mTotalRel
Definition: JpCntx.h:79
kencodingprober::SJISContextAnalysis
Definition: JpCntx.h:94
kencodingprober::SJISContextAnalysis::GetOrder
int GetOrder(const char *str)
Definition: JpCntx.h:99
kencodingprober
Definition: CharDistribution.cpp:37
kencodingprober::jp2CharContext
const char jp2CharContext[83][83]
Definition: JpCntx.cpp:30
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 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-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 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
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
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