]>
git.saurik.com Git - apple/icu.git/blob - icuSources/i18n/csrmbcs.h
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 **********************************************************************
5 * Copyright (C) 2005-2012, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 **********************************************************************
13 #include "unicode/utypes.h"
15 #if !UCONFIG_NO_CONVERSION
21 // "Character" iterated character class.
22 // Recognizers for specific mbcs encodings make their "characters" available
23 // by providing a nextChar() function that fills in an instance of IteratedChar
24 // with the next char from the input.
25 // The returned characters are not converted to Unicode, but remain as the raw
26 // bytes (concatenated into an int) from the codepage data.
28 // For Asian charsets, use the raw input rather than the input that has been
29 // stripped of markup. Detection only considers multi-byte chars, effectively
30 // stripping markup anyway, and double byte chars do occur in markup too.
32 class IteratedChar
: public UMemory
35 uint32_t charValue
; // 1-4 bytes from the raw input data
44 int32_t nextByte(InputText
* det
);
47 #if U_PLATFORM_IS_DARWIN_BASED
48 #define MAX_KEY_STRING_WITH_NULL 16
51 class CharsetRecog_mbcs
: public CharsetRecognizer
{
55 * Test the match of this charset with the input text data
56 * which is obtained via the CharsetDetector object.
58 * @param det The CharsetDetector, which contains the input text
59 * to be checked for being in this charset.
60 * @return Two values packed into one int (Damn java, anyhow)
62 * bits 0-7: the match confidence, ranging from 0-100
64 * bits 8-15: The match reason, an enum-like value.
66 #if U_PLATFORM_IS_DARWIN_BASED
67 int32_t match_mbcs(InputText
* det
, const uint16_t commonChars
[], int32_t commonCharsLen
, const uint8_t (*keyStrings
)[MAX_KEY_STRING_WITH_NULL
] ) const;
69 int32_t match_mbcs(InputText
* det
, const uint16_t commonChars
[], int32_t commonCharsLen
) const;
74 virtual ~CharsetRecog_mbcs();
77 * Get the IANA name of this charset.
78 * @return the charset name.
81 const char *getName() const = 0;
82 const char *getLanguage() const = 0;
83 UBool
match(InputText
* input
, CharsetMatch
*results
) const = 0;
86 * Get the next character (however many bytes it is) from the input data
87 * Subclasses for specific charset encodings must implement this function
88 * to get characters according to the rules of their encoding scheme.
90 * This function is not a method of class IteratedChar only because
91 * that would require a lot of extra derived classes, which is awkward.
92 * @param it The IteratedChar "struct" into which the returned char is placed.
93 * @param det The charset detector, which is needed to get at the input byte data
94 * being iterated over.
95 * @return True if a character was returned, false at end of input.
97 virtual UBool
nextChar(IteratedChar
*it
, InputText
*textIn
) const = 0;
103 * Shift-JIS charset recognizer.
106 class CharsetRecog_sjis
: public CharsetRecog_mbcs
{
108 virtual ~CharsetRecog_sjis();
110 UBool
nextChar(IteratedChar
*it
, InputText
*det
) const;
112 UBool
match(InputText
* input
, CharsetMatch
*results
) const;
114 const char *getName() const;
115 const char *getLanguage() const;
121 * EUC charset recognizers. One abstract class that provides the common function
122 * for getting the next character according to the EUC encoding scheme,
123 * and nested derived classes for EUC_KR, EUC_JP, EUC_CN.
126 class CharsetRecog_euc
: public CharsetRecog_mbcs
129 virtual ~CharsetRecog_euc();
131 const char *getName() const = 0;
132 const char *getLanguage() const = 0;
134 UBool
match(InputText
* input
, CharsetMatch
*results
) const = 0;
137 * Get the next character value for EUC based encodings.
138 * Character "value" is simply the raw bytes that make up the character
139 * packed into an int.
141 UBool
nextChar(IteratedChar
*it
, InputText
*det
) const;
145 * The charset recognize for EUC-JP. A singleton instance of this class
146 * is created and kept by the public CharsetDetector class
148 class CharsetRecog_euc_jp
: public CharsetRecog_euc
151 virtual ~CharsetRecog_euc_jp();
153 const char *getName() const;
154 const char *getLanguage() const;
156 UBool
match(InputText
* input
, CharsetMatch
*results
) const;
160 * The charset recognize for EUC-KR. A singleton instance of this class
161 * is created and kept by the public CharsetDetector class
163 class CharsetRecog_euc_kr
: public CharsetRecog_euc
166 virtual ~CharsetRecog_euc_kr();
168 const char *getName() const;
169 const char *getLanguage() const;
171 UBool
match(InputText
* input
, CharsetMatch
*results
) const;
176 * Big5 charset recognizer.
179 class CharsetRecog_big5
: public CharsetRecog_mbcs
182 virtual ~CharsetRecog_big5();
184 UBool
nextChar(IteratedChar
* it
, InputText
* det
) const;
186 const char *getName() const;
187 const char *getLanguage() const;
189 UBool
match(InputText
* input
, CharsetMatch
*results
) const;
195 * GB-18030 recognizer. Uses simplified Chinese statistics.
198 class CharsetRecog_gb_18030
: public CharsetRecog_mbcs
201 virtual ~CharsetRecog_gb_18030();
203 UBool
nextChar(IteratedChar
* it
, InputText
* det
) const;
205 const char *getName() const;
206 const char *getLanguage() const;
208 UBool
match(InputText
* input
, CharsetMatch
*results
) const;
214 #endif /* __CSRMBCS_H */