]>
git.saurik.com Git - apple/icu.git/blob - icuSources/common/unicode/idna.h
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 *******************************************************************************
5 * Copyright (C) 2010-2012, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 *******************************************************************************
10 * tab size: 8 (not used)
13 * created on: 2010mar05
14 * created by: Markus W. Scherer
22 * \brief C++ API: Internationalizing Domain Names in Applications (IDNA)
25 #include "unicode/utypes.h"
27 #if U_SHOW_CPLUSPLUS_API
31 #include "unicode/bytestream.h"
32 #include "unicode/stringpiece.h"
33 #include "unicode/uidna.h"
34 #include "unicode/unistr.h"
41 * Abstract base class for IDNA processing.
42 * See http://www.unicode.org/reports/tr46/
43 * and http://www.ietf.org/rfc/rfc3490.txt
45 * The IDNA class is not intended for public subclassing.
47 * This C++ API currently only implements UTS #46.
48 * The uidna.h C API implements both UTS #46 (functions using UIDNA service object)
49 * and IDNA2003 (functions that do not use a service object).
52 class U_COMMON_API IDNA
: public UObject
{
61 * Returns an IDNA instance which implements UTS #46.
62 * Returns an unmodifiable instance, owned by the caller.
63 * Cache it for multiple operations, and delete it when done.
64 * The instance is thread-safe, that is, it can be used concurrently.
66 * UTS #46 defines Unicode IDNA Compatibility Processing,
67 * updated to the latest version of Unicode and compatible with both
68 * IDNA2003 and IDNA2008.
70 * The worker functions use transitional processing, including deviation mappings,
71 * unless UIDNA_NONTRANSITIONAL_TO_ASCII or UIDNA_NONTRANSITIONAL_TO_UNICODE
72 * is used in which case the deviation characters are passed through without change.
74 * Disallowed characters are mapped to U+FFFD.
76 * For available options see the uidna.h header.
77 * Operations with the UTS #46 instance do not support the
78 * UIDNA_ALLOW_UNASSIGNED option.
80 * By default, the UTS #46 implementation allows all ASCII characters (as valid or mapped).
81 * When the UIDNA_USE_STD3_RULES option is used, ASCII characters other than
82 * letters, digits, hyphen (LDH) and dot/full stop are disallowed and mapped to U+FFFD.
84 * @param options Bit set to modify the processing and error checking.
85 * See option bit set values in uidna.h.
86 * @param errorCode Standard ICU error code. Its input value must
87 * pass the U_SUCCESS() test, or else the function returns
88 * immediately. Check for U_FAILURE() on output or use with
89 * function chaining. (See User Guide for details.)
90 * @return the UTS #46 IDNA instance, if successful
94 createUTS46Instance(uint32_t options
, UErrorCode
&errorCode
);
97 * Converts a single domain name label into its ASCII form for DNS lookup.
98 * If any processing step fails, then info.hasErrors() will be TRUE and
99 * the result might not be an ASCII string.
100 * The label might be modified according to the types of errors.
101 * Labels with severe errors will be left in (or turned into) their Unicode form.
103 * The UErrorCode indicates an error only in exceptional cases,
104 * such as a U_MEMORY_ALLOCATION_ERROR.
106 * @param label Input domain name label
107 * @param dest Destination string object
108 * @param info Output container of IDNA processing details.
109 * @param errorCode Standard ICU error code. Its input value must
110 * pass the U_SUCCESS() test, or else the function returns
111 * immediately. Check for U_FAILURE() on output or use with
112 * function chaining. (See User Guide for details.)
116 virtual UnicodeString
&
117 labelToASCII(const UnicodeString
&label
, UnicodeString
&dest
,
118 IDNAInfo
&info
, UErrorCode
&errorCode
) const = 0;
121 * Converts a single domain name label into its Unicode form for human-readable display.
122 * If any processing step fails, then info.hasErrors() will be TRUE.
123 * The label might be modified according to the types of errors.
125 * The UErrorCode indicates an error only in exceptional cases,
126 * such as a U_MEMORY_ALLOCATION_ERROR.
128 * @param label Input domain name label
129 * @param dest Destination string object
130 * @param info Output container of IDNA processing details.
131 * @param errorCode Standard ICU error code. Its input value must
132 * pass the U_SUCCESS() test, or else the function returns
133 * immediately. Check for U_FAILURE() on output or use with
134 * function chaining. (See User Guide for details.)
138 virtual UnicodeString
&
139 labelToUnicode(const UnicodeString
&label
, UnicodeString
&dest
,
140 IDNAInfo
&info
, UErrorCode
&errorCode
) const = 0;
143 * Converts a whole domain name into its ASCII form for DNS lookup.
144 * If any processing step fails, then info.hasErrors() will be TRUE and
145 * the result might not be an ASCII string.
146 * The domain name might be modified according to the types of errors.
147 * Labels with severe errors will be left in (or turned into) their Unicode form.
149 * The UErrorCode indicates an error only in exceptional cases,
150 * such as a U_MEMORY_ALLOCATION_ERROR.
152 * @param name Input domain name
153 * @param dest Destination string object
154 * @param info Output container of IDNA processing details.
155 * @param errorCode Standard ICU error code. Its input value must
156 * pass the U_SUCCESS() test, or else the function returns
157 * immediately. Check for U_FAILURE() on output or use with
158 * function chaining. (See User Guide for details.)
162 virtual UnicodeString
&
163 nameToASCII(const UnicodeString
&name
, UnicodeString
&dest
,
164 IDNAInfo
&info
, UErrorCode
&errorCode
) const = 0;
167 * Converts a whole domain name into its Unicode form for human-readable display.
168 * If any processing step fails, then info.hasErrors() will be TRUE.
169 * The domain name might be modified according to the types of errors.
171 * The UErrorCode indicates an error only in exceptional cases,
172 * such as a U_MEMORY_ALLOCATION_ERROR.
174 * @param name Input domain name
175 * @param dest Destination string object
176 * @param info Output container of IDNA processing details.
177 * @param errorCode Standard ICU error code. Its input value must
178 * pass the U_SUCCESS() test, or else the function returns
179 * immediately. Check for U_FAILURE() on output or use with
180 * function chaining. (See User Guide for details.)
184 virtual UnicodeString
&
185 nameToUnicode(const UnicodeString
&name
, UnicodeString
&dest
,
186 IDNAInfo
&info
, UErrorCode
&errorCode
) const = 0;
188 // UTF-8 versions of the processing methods ---------------------------- ***
191 * Converts a single domain name label into its ASCII form for DNS lookup.
192 * UTF-8 version of labelToASCII(), same behavior.
194 * @param label Input domain name label
195 * @param dest Destination byte sink; Flush()ed if successful
196 * @param info Output container of IDNA processing details.
197 * @param errorCode Standard ICU error code. Its input value must
198 * pass the U_SUCCESS() test, or else the function returns
199 * immediately. Check for U_FAILURE() on output or use with
200 * function chaining. (See User Guide for details.)
205 labelToASCII_UTF8(StringPiece label
, ByteSink
&dest
,
206 IDNAInfo
&info
, UErrorCode
&errorCode
) const;
209 * Converts a single domain name label into its Unicode form for human-readable display.
210 * UTF-8 version of labelToUnicode(), same behavior.
212 * @param label Input domain name label
213 * @param dest Destination byte sink; Flush()ed if successful
214 * @param info Output container of IDNA processing details.
215 * @param errorCode Standard ICU error code. Its input value must
216 * pass the U_SUCCESS() test, or else the function returns
217 * immediately. Check for U_FAILURE() on output or use with
218 * function chaining. (See User Guide for details.)
223 labelToUnicodeUTF8(StringPiece label
, ByteSink
&dest
,
224 IDNAInfo
&info
, UErrorCode
&errorCode
) const;
227 * Converts a whole domain name into its ASCII form for DNS lookup.
228 * UTF-8 version of nameToASCII(), same behavior.
230 * @param name Input domain name
231 * @param dest Destination byte sink; Flush()ed if successful
232 * @param info Output container of IDNA processing details.
233 * @param errorCode Standard ICU error code. Its input value must
234 * pass the U_SUCCESS() test, or else the function returns
235 * immediately. Check for U_FAILURE() on output or use with
236 * function chaining. (See User Guide for details.)
241 nameToASCII_UTF8(StringPiece name
, ByteSink
&dest
,
242 IDNAInfo
&info
, UErrorCode
&errorCode
) const;
245 * Converts a whole domain name into its Unicode form for human-readable display.
246 * UTF-8 version of nameToUnicode(), same behavior.
248 * @param name Input domain name
249 * @param dest Destination byte sink; Flush()ed if successful
250 * @param info Output container of IDNA processing details.
251 * @param errorCode Standard ICU error code. Its input value must
252 * pass the U_SUCCESS() test, or else the function returns
253 * immediately. Check for U_FAILURE() on output or use with
254 * function chaining. (See User Guide for details.)
259 nameToUnicodeUTF8(StringPiece name
, ByteSink
&dest
,
260 IDNAInfo
&info
, UErrorCode
&errorCode
) const;
266 * Output container for IDNA processing errors.
267 * The IDNAInfo class is not suitable for subclassing.
270 class U_COMMON_API IDNAInfo
: public UMemory
{
273 * Constructor for stack allocation.
276 IDNAInfo() : errors(0), labelErrors(0), isTransDiff(FALSE
), isBiDi(FALSE
), isOkBiDi(TRUE
) {}
278 * Were there IDNA processing errors?
279 * @return TRUE if there were processing errors
282 UBool
hasErrors() const { return errors
!=0; }
284 * Returns a bit set indicating IDNA processing errors.
285 * See UIDNA_ERROR_... constants in uidna.h.
286 * @return bit set of processing errors
289 uint32_t getErrors() const { return errors
; }
291 * Returns TRUE if transitional and nontransitional processing produce different results.
292 * This is the case when the input label or domain name contains
293 * one or more deviation characters outside a Punycode label (see UTS #46).
295 * <li>With nontransitional processing, such characters are
296 * copied to the destination string.
297 * <li>With transitional processing, such characters are
298 * mapped (sharp s/sigma) or removed (joiner/nonjoiner).
300 * @return TRUE if transitional and nontransitional processing produce different results
303 UBool
isTransitionalDifferent() const { return isTransDiff
; }
308 IDNAInfo(const IDNAInfo
&other
); // no copying
309 IDNAInfo
&operator=(const IDNAInfo
&other
); // no copying
312 errors
=labelErrors
=0;
318 uint32_t errors
, labelErrors
;
326 #endif // UCONFIG_NO_IDNA
328 #endif /* U_SHOW_CPLUSPLUS_API */