intl/icu/source/i18n/csrmbcs.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /*
michael@0 2 **********************************************************************
michael@0 3 * Copyright (C) 2005-2012, International Business Machines
michael@0 4 * Corporation and others. All Rights Reserved.
michael@0 5 **********************************************************************
michael@0 6 */
michael@0 7
michael@0 8 #ifndef __CSRMBCS_H
michael@0 9 #define __CSRMBCS_H
michael@0 10
michael@0 11 #include "unicode/utypes.h"
michael@0 12
michael@0 13 #if !UCONFIG_NO_CONVERSION
michael@0 14
michael@0 15 #include "csrecog.h"
michael@0 16
michael@0 17 U_NAMESPACE_BEGIN
michael@0 18
michael@0 19 // "Character" iterated character class.
michael@0 20 // Recognizers for specific mbcs encodings make their "characters" available
michael@0 21 // by providing a nextChar() function that fills in an instance of IteratedChar
michael@0 22 // with the next char from the input.
michael@0 23 // The returned characters are not converted to Unicode, but remain as the raw
michael@0 24 // bytes (concatenated into an int) from the codepage data.
michael@0 25 //
michael@0 26 // For Asian charsets, use the raw input rather than the input that has been
michael@0 27 // stripped of markup. Detection only considers multi-byte chars, effectively
michael@0 28 // stripping markup anyway, and double byte chars do occur in markup too.
michael@0 29 //
michael@0 30 class IteratedChar : public UMemory
michael@0 31 {
michael@0 32 public:
michael@0 33 uint32_t charValue; // 1-4 bytes from the raw input data
michael@0 34 int32_t index;
michael@0 35 int32_t nextIndex;
michael@0 36 UBool error;
michael@0 37 UBool done;
michael@0 38
michael@0 39 public:
michael@0 40 IteratedChar();
michael@0 41 //void reset();
michael@0 42 int32_t nextByte(InputText* det);
michael@0 43 };
michael@0 44
michael@0 45
michael@0 46 class CharsetRecog_mbcs : public CharsetRecognizer {
michael@0 47
michael@0 48 protected:
michael@0 49 /**
michael@0 50 * Test the match of this charset with the input text data
michael@0 51 * which is obtained via the CharsetDetector object.
michael@0 52 *
michael@0 53 * @param det The CharsetDetector, which contains the input text
michael@0 54 * to be checked for being in this charset.
michael@0 55 * @return Two values packed into one int (Damn java, anyhow)
michael@0 56 * <br/>
michael@0 57 * bits 0-7: the match confidence, ranging from 0-100
michael@0 58 * <br/>
michael@0 59 * bits 8-15: The match reason, an enum-like value.
michael@0 60 */
michael@0 61 int32_t match_mbcs(InputText* det, const uint16_t commonChars[], int32_t commonCharsLen) const;
michael@0 62
michael@0 63 public:
michael@0 64
michael@0 65 virtual ~CharsetRecog_mbcs();
michael@0 66
michael@0 67 /**
michael@0 68 * Get the IANA name of this charset.
michael@0 69 * @return the charset name.
michael@0 70 */
michael@0 71
michael@0 72 const char *getName() const = 0;
michael@0 73 const char *getLanguage() const = 0;
michael@0 74 UBool match(InputText* input, CharsetMatch *results) const = 0;
michael@0 75
michael@0 76 /**
michael@0 77 * Get the next character (however many bytes it is) from the input data
michael@0 78 * Subclasses for specific charset encodings must implement this function
michael@0 79 * to get characters according to the rules of their encoding scheme.
michael@0 80 *
michael@0 81 * This function is not a method of class IteratedChar only because
michael@0 82 * that would require a lot of extra derived classes, which is awkward.
michael@0 83 * @param it The IteratedChar "struct" into which the returned char is placed.
michael@0 84 * @param det The charset detector, which is needed to get at the input byte data
michael@0 85 * being iterated over.
michael@0 86 * @return True if a character was returned, false at end of input.
michael@0 87 */
michael@0 88 virtual UBool nextChar(IteratedChar *it, InputText *textIn) const = 0;
michael@0 89
michael@0 90 };
michael@0 91
michael@0 92
michael@0 93 /**
michael@0 94 * Shift-JIS charset recognizer.
michael@0 95 *
michael@0 96 */
michael@0 97 class CharsetRecog_sjis : public CharsetRecog_mbcs {
michael@0 98 public:
michael@0 99 virtual ~CharsetRecog_sjis();
michael@0 100
michael@0 101 UBool nextChar(IteratedChar *it, InputText *det) const;
michael@0 102
michael@0 103 UBool match(InputText* input, CharsetMatch *results) const;
michael@0 104
michael@0 105 const char *getName() const;
michael@0 106 const char *getLanguage() const;
michael@0 107
michael@0 108 };
michael@0 109
michael@0 110
michael@0 111 /**
michael@0 112 * EUC charset recognizers. One abstract class that provides the common function
michael@0 113 * for getting the next character according to the EUC encoding scheme,
michael@0 114 * and nested derived classes for EUC_KR, EUC_JP, EUC_CN.
michael@0 115 *
michael@0 116 */
michael@0 117 class CharsetRecog_euc : public CharsetRecog_mbcs
michael@0 118 {
michael@0 119 public:
michael@0 120 virtual ~CharsetRecog_euc();
michael@0 121
michael@0 122 const char *getName() const = 0;
michael@0 123 const char *getLanguage() const = 0;
michael@0 124
michael@0 125 UBool match(InputText* input, CharsetMatch *results) const = 0;
michael@0 126 /*
michael@0 127 * (non-Javadoc)
michael@0 128 * Get the next character value for EUC based encodings.
michael@0 129 * Character "value" is simply the raw bytes that make up the character
michael@0 130 * packed into an int.
michael@0 131 */
michael@0 132 UBool nextChar(IteratedChar *it, InputText *det) const;
michael@0 133 };
michael@0 134
michael@0 135 /**
michael@0 136 * The charset recognize for EUC-JP. A singleton instance of this class
michael@0 137 * is created and kept by the public CharsetDetector class
michael@0 138 */
michael@0 139 class CharsetRecog_euc_jp : public CharsetRecog_euc
michael@0 140 {
michael@0 141 public:
michael@0 142 virtual ~CharsetRecog_euc_jp();
michael@0 143
michael@0 144 const char *getName() const;
michael@0 145 const char *getLanguage() const;
michael@0 146
michael@0 147 UBool match(InputText* input, CharsetMatch *results) const;
michael@0 148 };
michael@0 149
michael@0 150 /**
michael@0 151 * The charset recognize for EUC-KR. A singleton instance of this class
michael@0 152 * is created and kept by the public CharsetDetector class
michael@0 153 */
michael@0 154 class CharsetRecog_euc_kr : public CharsetRecog_euc
michael@0 155 {
michael@0 156 public:
michael@0 157 virtual ~CharsetRecog_euc_kr();
michael@0 158
michael@0 159 const char *getName() const;
michael@0 160 const char *getLanguage() const;
michael@0 161
michael@0 162 UBool match(InputText* input, CharsetMatch *results) const;
michael@0 163 };
michael@0 164
michael@0 165 /**
michael@0 166 *
michael@0 167 * Big5 charset recognizer.
michael@0 168 *
michael@0 169 */
michael@0 170 class CharsetRecog_big5 : public CharsetRecog_mbcs
michael@0 171 {
michael@0 172 public:
michael@0 173 virtual ~CharsetRecog_big5();
michael@0 174
michael@0 175 UBool nextChar(IteratedChar* it, InputText* det) const;
michael@0 176
michael@0 177 const char *getName() const;
michael@0 178 const char *getLanguage() const;
michael@0 179
michael@0 180 UBool match(InputText* input, CharsetMatch *results) const;
michael@0 181 };
michael@0 182
michael@0 183
michael@0 184 /**
michael@0 185 *
michael@0 186 * GB-18030 recognizer. Uses simplified Chinese statistics.
michael@0 187 *
michael@0 188 */
michael@0 189 class CharsetRecog_gb_18030 : public CharsetRecog_mbcs
michael@0 190 {
michael@0 191 public:
michael@0 192 virtual ~CharsetRecog_gb_18030();
michael@0 193
michael@0 194 UBool nextChar(IteratedChar* it, InputText* det) const;
michael@0 195
michael@0 196 const char *getName() const;
michael@0 197 const char *getLanguage() const;
michael@0 198
michael@0 199 UBool match(InputText* input, CharsetMatch *results) const;
michael@0 200 };
michael@0 201
michael@0 202 U_NAMESPACE_END
michael@0 203
michael@0 204 #endif
michael@0 205 #endif /* __CSRMBCS_H */

mercurial