]> git.saurik.com Git - apple/icu.git/blob - icuSources/test/intltest/nptrans.h
ICU-6.2.13.tar.gz
[apple/icu.git] / icuSources / test / intltest / nptrans.h
1 /*
2 *******************************************************************************
3 *
4 * Copyright (C) 2003, International Business Machines
5 * Corporation and others. All Rights Reserved.
6 *
7 *******************************************************************************
8 * file name: nptrans.h
9 * encoding: US-ASCII
10 * tab size: 8 (not used)
11 * indentation:4
12 *
13 * created on: 2003feb1
14 * created by: Ram Viswanadha
15 */
16
17 #ifndef NPTRANS_H
18 #define NPTRANS_H
19
20 #include "unicode/utypes.h"
21
22 #if !UCONFIG_NO_IDNA
23 #if !UCONFIG_NO_TRANSLITERATION
24
25 #include "unicode/uniset.h"
26 #include "unicode/ures.h"
27 #include "unicode/translit.h"
28
29
30
31 #define ASCII_SPACE 0x0020
32
33 class NamePrepTransform {
34
35 private :
36 Transliterator *mapping;
37 UnicodeSet unassigned;
38 UnicodeSet prohibited;
39 UnicodeSet labelSeparatorSet;
40 UResourceBundle *bundle;
41 NamePrepTransform(UParseError& parseError, UErrorCode& status);
42
43
44 public :
45
46 static NamePrepTransform* createInstance(UParseError& parseError, UErrorCode& status);
47
48 virtual ~NamePrepTransform();
49
50
51 inline UBool isProhibited(UChar32 ch);
52
53 /**
54 * ICU "poor man's RTTI", returns a UClassID for the actual class.
55 *
56 * @draft ICU 2.6
57 */
58 inline UClassID getDynamicClassID() const { return getStaticClassID(); }
59
60 /**
61 * ICU "poor man's RTTI", returns a UClassID for this class.
62 *
63 * @draft ICU 2.6
64 */
65 static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; }
66
67 /**
68 * Map every character in input stream with mapping character
69 * in the mapping table and populate the output stream.
70 * For any individual character the mapping table may specify
71 * that that a character be mapped to nothing, mapped to one
72 * other character or to a string of other characters.
73 *
74 * @param src Pointer to UChar buffer containing a single label
75 * @param srcLength Number of characters in the source label
76 * @param dest Pointer to the destination buffer to receive the output
77 * @param destCapacity The capacity of destination array
78 * @param allowUnassigned Unassigned values can be converted to ASCII for query operations
79 * If TRUE unassigned values are treated as normal Unicode code point.
80 * If FALSE the operation fails with U_UNASSIGNED_CODE_POINT_FOUND error code.
81 * @param status ICU error code in/out parameter.
82 * Must fulfill U_SUCCESS before the function call.
83 * @return The number of UChars in the destination buffer
84 *
85 */
86 int32_t map(const UChar* src, int32_t srcLength,
87 UChar* dest, int32_t destCapacity,
88 UBool allowUnassigned,
89 UParseError* parseError,
90 UErrorCode& status );
91
92 /**
93 * Prepare the input stream with for use. This operation maps, normalizes(NFKC),
94 * checks for prohited and BiDi characters in the order defined by RFC 3454
95 *
96 * @param src Pointer to UChar buffer containing a single label
97 * @param srcLength Number of characters in the source label
98 * @param dest Pointer to the destination buffer to receive the output
99 * @param destCapacity The capacity of destination array
100 * @param allowUnassigned Unassigned values can be converted to ASCII for query operations
101 * If TRUE unassigned values are treated as normal Unicode code point.
102 * If FALSE the operation fails with U_UNASSIGNED_CODE_POINT error code.
103 * @param status ICU error code in/out parameter.
104 * Must fulfill U_SUCCESS before the function call.
105 * @return The number of UChars in the destination buffer
106 */
107 int32_t process(const UChar* src, int32_t srcLength,
108 UChar* dest, int32_t destCapacity,
109 UBool allowUnassigned,
110 UParseError* parseError,
111 UErrorCode& status );
112
113 /**
114 * Ascertain if the given code point is a label separator as specified by IDNA
115 *
116 * @return TRUE is the code point is a label separator
117 *
118 *
119 */
120 UBool isLabelSeparator(UChar32 ch, UErrorCode& status);
121
122
123 inline UBool isLDHChar(UChar32 ch);
124 private:
125 /**
126 * The address of this static class variable serves as this class's ID
127 * for ICU "poor man's RTTI".
128 */
129 static const char fgClassID;
130 };
131
132 inline UBool NamePrepTransform::isLDHChar(UChar32 ch){
133 // high runner case
134 if(ch>0x007A){
135 return FALSE;
136 }
137 //[\\u002D \\u0030-\\u0039 \\u0041-\\u005A \\u0061-\\u007A]
138 if( (ch==0x002D) ||
139 (0x0030 <= ch && ch <= 0x0039) ||
140 (0x0041 <= ch && ch <= 0x005A) ||
141 (0x0061 <= ch && ch <= 0x007A)
142 ){
143 return TRUE;
144 }
145 return FALSE;
146 }
147
148 #endif /* #if !UCONFIG_NO_TRANSLITERATION */
149 #else
150 class NamePrepTransform {
151 };
152 #endif /* #if !UCONFIG_NO_IDNA */
153
154 #endif
155
156 /*
157 * Hey, Emacs, please set the following:
158 *
159 * Local Variables:
160 * indent-tabs-mode: nil
161 * End:
162 *
163 */