]> git.saurik.com Git - apple/icu.git/blame - icuSources/i18n/hextouni.h
ICU-3.13.tar.gz
[apple/icu.git] / icuSources / i18n / hextouni.h
CommitLineData
b75a7d8f
A
1/*
2**********************************************************************
3* Copyright (C) 1999-2003, International Business Machines
4* Corporation and others. All Rights Reserved.
5**********************************************************************
6* Date Name Description
7* 11/17/99 aliu Creation.
8**********************************************************************
9*/
10#ifndef HEXTOUNI_H
11#define HEXTOUNI_H
12
13#include "unicode/utypes.h"
14
15#if !UCONFIG_NO_TRANSLITERATION
16
17#include "unicode/translit.h"
18
19U_NAMESPACE_BEGIN
20
21/**
22 * A transliterator that converts from hexadecimal Unicode escape
23 * sequences to the characters they represent. For example, "U+0040"
24 * and '\u0040'. A default HexToUnicodeTransliterator recognizes the
25 * prefixes "U+", "u+", "\U", and "\u". Hex values may be
26 * upper- or lowercase. By calling the applyPattern() method, one
27 * or more custom prefix/suffix pairs may be specified. See
28 * applyPattern() for details.
29 *
30 * @author Alan Liu
31 * @internal Use transliterator factory methods instead since this class will be removed in that release.
32 */
33class U_I18N_API HexToUnicodeTransliterator : public Transliterator {
34
35 /**
36 * ID for this transliterator.
37 */
38 static const char _ID[];
39
40 /**
41 * The pattern used by the default constructor
42 */
43 static const UChar DEFAULT_PATTERN[];
44
45 // Character constants defined here to avoid ASCII dependency
46 enum {
47 SEMICOLON = 0x003B, // ';'
48 ZERO = 0x0030, // '0'
49 POUND = 0x0023, // '#'
50 BACKSLASH = 0x005C // '\\'
51 };
52
53 /**
54 * The pattern for this transliterator
55 */
56 UnicodeString pattern;
57
58 /**
59 * The processed pattern specification. See applyPattern() for
60 * details.
61 */
62 UnicodeString affixes;
63
64 /**
65 * The number of different affix sets in affixes.
66 */
67 int32_t affixCount;
68
69 /**
70 * The address of this static class variable serves as this class's ID
71 * for ICU "poor man's RTTI".
72 */
73 static const char fgClassID;
74
75public:
76
77 /**
78 * Constructs a transliterator that recognizes the standard
79 * prefixes "\u", "\U", "u+", and "U+", each with no
80 * suffix.
81 * @internal Use transliterator factory methods instead since this class will be removed in that release.
82 */
83 HexToUnicodeTransliterator(UnicodeFilter* adoptedFilter = 0);
84
85 /**
86 * Constructs a custom transliterator with the given pattern.
87 * @see #applyPattern
88 * @internal Use transliterator factory methods instead since this class will be removed in that release.
89 */
90 HexToUnicodeTransliterator(const UnicodeString& pattern,
91 UErrorCode& status);
92
93 /**
94 * Constructs a custom transliterator with the given pattern
95 * and filter.
96 * @see #applyPattern
97 * @internal Use transliterator factory methods instead since this class will be removed in that release.
98 */
99 HexToUnicodeTransliterator(const UnicodeString& pattern,
100 UnicodeFilter* adoptedFilter,
101 UErrorCode& status);
102
103 /**
104 * Destructor.
105 * @internal Use transliterator factory methods instead since this class will be removed in that release.
106 */
107 virtual ~HexToUnicodeTransliterator();
108
109 /**
110 * Copy constructor.
111 * @internal Use transliterator factory methods instead since this class will be removed in that release.
112 */
113 HexToUnicodeTransliterator(const HexToUnicodeTransliterator&);
114
115 /**
116 * Assignment operator.
117 * @internal Use transliterator factory methods instead since this class will be removed in that release.
118 */
119 HexToUnicodeTransliterator& operator=(const HexToUnicodeTransliterator&);
120
121 /**
122 * Transliterator API.
123 * @internal Use transliterator factory methods instead since this class will be removed in that release.
124 */
125 Transliterator* clone(void) const;
126
127 /**
128 * Set the patterns recognized by this transliterator. One or
129 * more patterns may be specified, separated by semicolons (';').
130 * Each pattern contains zero or more prefix characters, one or
131 * more digit characters, and zero or more suffix characters. The
132 * digit characters indicates optional digits ('#') followed by
133 * required digits ('0'). The total number of digits cannot
134 * exceed 4, and must be at least 1 required digit. Use a
135 * backslash ('\\') to escape any of the special characters. An
136 * empty pattern is allowed; it specifies a transliterator that
137 * does nothing.
138 *
139 * <p>Example: "U+0000;<###0>" specifies two patterns. The first
140 * has a prefix of "U+", exactly four digits, and no suffix. The
141 * second has a prefix of "<", between one and four digits, and a
142 * suffix of ">".
143 *
144 * <p><pre>
145 * pattern := spec | ( pattern ';' spec )
146 * spec := prefix-char* digit-spec suffix-char*
147 * digit-spec := '#'* '0'+
148 * prefix-char := [^special-char] | '\\' special-char
149 * suffix-char := [^special-char] | '\\' special-char
150 * special-char := ';' | '0' | '#' | '\\'
151 * </pre>
152 * @internal Use transliterator factory methods instead since this class will be removed in that release.
153 */
154 void applyPattern(const UnicodeString& thePattern, UErrorCode& status);
155
156 /**
157 * Return this transliterator's pattern.
158 * @internal Use transliterator factory methods instead since this class will be removed in that release.
159 */
160 const UnicodeString& toPattern(void) const;
161
162 /**
163 * Implements {@link Transliterator#handleTransliterate}.
164 * @internal Use transliterator factory methods instead since this class will be removed in that release.
165 */
166 virtual void handleTransliterate(Replaceable& text, UTransPosition& offset,
167 UBool isIncremental) const;
168
169 /**
170 * ICU "poor man's RTTI", returns a UClassID for the actual class.
171 *
172 * @draft ICU 2.2
173 */
174 virtual inline UClassID getDynamicClassID() const;
175
176 /**
177 * ICU "poor man's RTTI", returns a UClassID for this class.
178 *
179 * @draft ICU 2.2
180 */
181 static inline UClassID getStaticClassID();
182};
183
184inline HexToUnicodeTransliterator::~HexToUnicodeTransliterator() {}
185
186inline UClassID
187HexToUnicodeTransliterator::getStaticClassID()
188{ return (UClassID)&fgClassID; }
189
190inline UClassID
191HexToUnicodeTransliterator::getDynamicClassID() const
192{ return HexToUnicodeTransliterator::getStaticClassID(); }
193
194U_NAMESPACE_END
195
196#endif /* #if !UCONFIG_NO_TRANSLITERATION */
197
198#endif