]>
git.saurik.com Git - apple/icu.git/blob - icuSources/i18n/csrmbcs.h
2 **********************************************************************
3 * Copyright (C) 2005-2012, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
11 #include "unicode/utypes.h"
13 #if !UCONFIG_NO_CONVERSION
19 // "Character" iterated character class.
20 // Recognizers for specific mbcs encodings make their "characters" available
21 // by providing a nextChar() function that fills in an instance of IteratedChar
22 // with the next char from the input.
23 // The returned characters are not converted to Unicode, but remain as the raw
24 // bytes (concatenated into an int) from the codepage data.
26 // For Asian charsets, use the raw input rather than the input that has been
27 // stripped of markup. Detection only considers multi-byte chars, effectively
28 // stripping markup anyway, and double byte chars do occur in markup too.
30 class IteratedChar
: public UMemory
33 uint32_t charValue
; // 1-4 bytes from the raw input data
42 int32_t nextByte(InputText
* det
);
45 #if U_PLATFORM_IS_DARWIN_BASED
46 #define MAX_KEY_STRING_WITH_NULL 16
49 class CharsetRecog_mbcs
: public CharsetRecognizer
{
53 * Test the match of this charset with the input text data
54 * which is obtained via the CharsetDetector object.
56 * @param det The CharsetDetector, which contains the input text
57 * to be checked for being in this charset.
58 * @return Two values packed into one int (Damn java, anyhow)
60 * bits 0-7: the match confidence, ranging from 0-100
62 * bits 8-15: The match reason, an enum-like value.
64 #if U_PLATFORM_IS_DARWIN_BASED
65 int32_t match_mbcs(InputText
* det
, const uint16_t commonChars
[], int32_t commonCharsLen
, const uint8_t (*keyStrings
)[MAX_KEY_STRING_WITH_NULL
] ) const;
67 int32_t match_mbcs(InputText
* det
, const uint16_t commonChars
[], int32_t commonCharsLen
) const;
72 virtual ~CharsetRecog_mbcs();
75 * Get the IANA name of this charset.
76 * @return the charset name.
79 const char *getName() const = 0;
80 const char *getLanguage() const = 0;
81 UBool
match(InputText
* input
, CharsetMatch
*results
) const = 0;
84 * Get the next character (however many bytes it is) from the input data
85 * Subclasses for specific charset encodings must implement this function
86 * to get characters according to the rules of their encoding scheme.
88 * This function is not a method of class IteratedChar only because
89 * that would require a lot of extra derived classes, which is awkward.
90 * @param it The IteratedChar "struct" into which the returned char is placed.
91 * @param det The charset detector, which is needed to get at the input byte data
92 * being iterated over.
93 * @return True if a character was returned, false at end of input.
95 virtual UBool
nextChar(IteratedChar
*it
, InputText
*textIn
) const = 0;
101 * Shift-JIS charset recognizer.
104 class CharsetRecog_sjis
: public CharsetRecog_mbcs
{
106 virtual ~CharsetRecog_sjis();
108 UBool
nextChar(IteratedChar
*it
, InputText
*det
) const;
110 UBool
match(InputText
* input
, CharsetMatch
*results
) const;
112 const char *getName() const;
113 const char *getLanguage() const;
119 * EUC charset recognizers. One abstract class that provides the common function
120 * for getting the next character according to the EUC encoding scheme,
121 * and nested derived classes for EUC_KR, EUC_JP, EUC_CN.
124 class CharsetRecog_euc
: public CharsetRecog_mbcs
127 virtual ~CharsetRecog_euc();
129 const char *getName() const = 0;
130 const char *getLanguage() const = 0;
132 UBool
match(InputText
* input
, CharsetMatch
*results
) const = 0;
135 * Get the next character value for EUC based encodings.
136 * Character "value" is simply the raw bytes that make up the character
137 * packed into an int.
139 UBool
nextChar(IteratedChar
*it
, InputText
*det
) const;
143 * The charset recognize for EUC-JP. A singleton instance of this class
144 * is created and kept by the public CharsetDetector class
146 class CharsetRecog_euc_jp
: public CharsetRecog_euc
149 virtual ~CharsetRecog_euc_jp();
151 const char *getName() const;
152 const char *getLanguage() const;
154 UBool
match(InputText
* input
, CharsetMatch
*results
) const;
158 * The charset recognize for EUC-KR. A singleton instance of this class
159 * is created and kept by the public CharsetDetector class
161 class CharsetRecog_euc_kr
: public CharsetRecog_euc
164 virtual ~CharsetRecog_euc_kr();
166 const char *getName() const;
167 const char *getLanguage() const;
169 UBool
match(InputText
* input
, CharsetMatch
*results
) const;
174 * Big5 charset recognizer.
177 class CharsetRecog_big5
: public CharsetRecog_mbcs
180 virtual ~CharsetRecog_big5();
182 UBool
nextChar(IteratedChar
* it
, InputText
* det
) const;
184 const char *getName() const;
185 const char *getLanguage() const;
187 UBool
match(InputText
* input
, CharsetMatch
*results
) const;
193 * GB-18030 recognizer. Uses simplified Chinese statistics.
196 class CharsetRecog_gb_18030
: public CharsetRecog_mbcs
199 virtual ~CharsetRecog_gb_18030();
201 UBool
nextChar(IteratedChar
* it
, InputText
* det
) const;
203 const char *getName() const;
204 const char *getLanguage() const;
206 UBool
match(InputText
* input
, CharsetMatch
*results
) const;
212 #endif /* __CSRMBCS_H */