|
||||
Warning, file /include/unicode/idna.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 // © 2016 and later: Unicode, Inc. and others. 0002 // License & terms of use: http://www.unicode.org/copyright.html 0003 /* 0004 ******************************************************************************* 0005 * Copyright (C) 2010-2012, International Business Machines 0006 * Corporation and others. All Rights Reserved. 0007 ******************************************************************************* 0008 * file name: idna.h 0009 * encoding: UTF-8 0010 * tab size: 8 (not used) 0011 * indentation:4 0012 * 0013 * created on: 2010mar05 0014 * created by: Markus W. Scherer 0015 */ 0016 0017 #ifndef __IDNA_H__ 0018 #define __IDNA_H__ 0019 0020 /** 0021 * \file 0022 * \brief C++ API: Internationalizing Domain Names in Applications (IDNA) 0023 */ 0024 0025 #include "unicode/utypes.h" 0026 0027 #if U_SHOW_CPLUSPLUS_API 0028 0029 #if !UCONFIG_NO_IDNA 0030 0031 #include "unicode/bytestream.h" 0032 #include "unicode/stringpiece.h" 0033 #include "unicode/uidna.h" 0034 #include "unicode/unistr.h" 0035 0036 U_NAMESPACE_BEGIN 0037 0038 class IDNAInfo; 0039 0040 /** 0041 * Abstract base class for IDNA processing. 0042 * See http://www.unicode.org/reports/tr46/ 0043 * and http://www.ietf.org/rfc/rfc3490.txt 0044 * 0045 * The IDNA class is not intended for public subclassing. 0046 * 0047 * This C++ API currently only implements UTS #46. 0048 * The uidna.h C API implements both UTS #46 (functions using UIDNA service object) 0049 * and IDNA2003 (functions that do not use a service object). 0050 * @stable ICU 4.6 0051 */ 0052 class U_COMMON_API IDNA : public UObject { 0053 public: 0054 /** 0055 * Destructor. 0056 * @stable ICU 4.6 0057 */ 0058 ~IDNA(); 0059 0060 /** 0061 * Returns an IDNA instance which implements UTS #46. 0062 * Returns an unmodifiable instance, owned by the caller. 0063 * Cache it for multiple operations, and delete it when done. 0064 * The instance is thread-safe, that is, it can be used concurrently. 0065 * 0066 * UTS #46 defines Unicode IDNA Compatibility Processing, 0067 * updated to the latest version of Unicode and compatible with both 0068 * IDNA2003 and IDNA2008. 0069 * 0070 * The worker functions use transitional processing, including deviation mappings, 0071 * unless UIDNA_NONTRANSITIONAL_TO_ASCII or UIDNA_NONTRANSITIONAL_TO_UNICODE 0072 * is used in which case the deviation characters are passed through without change. 0073 * 0074 * Disallowed characters are mapped to U+FFFD. 0075 * 0076 * For available options see the uidna.h header. 0077 * Operations with the UTS #46 instance do not support the 0078 * UIDNA_ALLOW_UNASSIGNED option. 0079 * 0080 * By default, the UTS #46 implementation allows all ASCII characters (as valid or mapped). 0081 * When the UIDNA_USE_STD3_RULES option is used, ASCII characters other than 0082 * letters, digits, hyphen (LDH) and dot/full stop are disallowed and mapped to U+FFFD. 0083 * 0084 * @param options Bit set to modify the processing and error checking. 0085 * See option bit set values in uidna.h. 0086 * @param errorCode Standard ICU error code. Its input value must 0087 * pass the U_SUCCESS() test, or else the function returns 0088 * immediately. Check for U_FAILURE() on output or use with 0089 * function chaining. (See User Guide for details.) 0090 * @return the UTS #46 IDNA instance, if successful 0091 * @stable ICU 4.6 0092 */ 0093 static IDNA * 0094 createUTS46Instance(uint32_t options, UErrorCode &errorCode); 0095 0096 /** 0097 * Converts a single domain name label into its ASCII form for DNS lookup. 0098 * If any processing step fails, then info.hasErrors() will be true and 0099 * the result might not be an ASCII string. 0100 * The label might be modified according to the types of errors. 0101 * Labels with severe errors will be left in (or turned into) their Unicode form. 0102 * 0103 * The UErrorCode indicates an error only in exceptional cases, 0104 * such as a U_MEMORY_ALLOCATION_ERROR. 0105 * 0106 * @param label Input domain name label 0107 * @param dest Destination string object 0108 * @param info Output container of IDNA processing details. 0109 * @param errorCode Standard ICU error code. Its input value must 0110 * pass the U_SUCCESS() test, or else the function returns 0111 * immediately. Check for U_FAILURE() on output or use with 0112 * function chaining. (See User Guide for details.) 0113 * @return dest 0114 * @stable ICU 4.6 0115 */ 0116 virtual UnicodeString & 0117 labelToASCII(const UnicodeString &label, UnicodeString &dest, 0118 IDNAInfo &info, UErrorCode &errorCode) const = 0; 0119 0120 /** 0121 * Converts a single domain name label into its Unicode form for human-readable display. 0122 * If any processing step fails, then info.hasErrors() will be true. 0123 * The label might be modified according to the types of errors. 0124 * 0125 * The UErrorCode indicates an error only in exceptional cases, 0126 * such as a U_MEMORY_ALLOCATION_ERROR. 0127 * 0128 * @param label Input domain name label 0129 * @param dest Destination string object 0130 * @param info Output container of IDNA processing details. 0131 * @param errorCode Standard ICU error code. Its input value must 0132 * pass the U_SUCCESS() test, or else the function returns 0133 * immediately. Check for U_FAILURE() on output or use with 0134 * function chaining. (See User Guide for details.) 0135 * @return dest 0136 * @stable ICU 4.6 0137 */ 0138 virtual UnicodeString & 0139 labelToUnicode(const UnicodeString &label, UnicodeString &dest, 0140 IDNAInfo &info, UErrorCode &errorCode) const = 0; 0141 0142 /** 0143 * Converts a whole domain name into its ASCII form for DNS lookup. 0144 * If any processing step fails, then info.hasErrors() will be true and 0145 * the result might not be an ASCII string. 0146 * The domain name might be modified according to the types of errors. 0147 * Labels with severe errors will be left in (or turned into) their Unicode form. 0148 * 0149 * The UErrorCode indicates an error only in exceptional cases, 0150 * such as a U_MEMORY_ALLOCATION_ERROR. 0151 * 0152 * @param name Input domain name 0153 * @param dest Destination string object 0154 * @param info Output container of IDNA processing details. 0155 * @param errorCode Standard ICU error code. Its input value must 0156 * pass the U_SUCCESS() test, or else the function returns 0157 * immediately. Check for U_FAILURE() on output or use with 0158 * function chaining. (See User Guide for details.) 0159 * @return dest 0160 * @stable ICU 4.6 0161 */ 0162 virtual UnicodeString & 0163 nameToASCII(const UnicodeString &name, UnicodeString &dest, 0164 IDNAInfo &info, UErrorCode &errorCode) const = 0; 0165 0166 /** 0167 * Converts a whole domain name into its Unicode form for human-readable display. 0168 * If any processing step fails, then info.hasErrors() will be true. 0169 * The domain name might be modified according to the types of errors. 0170 * 0171 * The UErrorCode indicates an error only in exceptional cases, 0172 * such as a U_MEMORY_ALLOCATION_ERROR. 0173 * 0174 * @param name Input domain name 0175 * @param dest Destination string object 0176 * @param info Output container of IDNA processing details. 0177 * @param errorCode Standard ICU error code. Its input value must 0178 * pass the U_SUCCESS() test, or else the function returns 0179 * immediately. Check for U_FAILURE() on output or use with 0180 * function chaining. (See User Guide for details.) 0181 * @return dest 0182 * @stable ICU 4.6 0183 */ 0184 virtual UnicodeString & 0185 nameToUnicode(const UnicodeString &name, UnicodeString &dest, 0186 IDNAInfo &info, UErrorCode &errorCode) const = 0; 0187 0188 // UTF-8 versions of the processing methods ---------------------------- *** 0189 0190 /** 0191 * Converts a single domain name label into its ASCII form for DNS lookup. 0192 * UTF-8 version of labelToASCII(), same behavior. 0193 * 0194 * @param label Input domain name label 0195 * @param dest Destination byte sink; Flush()ed if successful 0196 * @param info Output container of IDNA processing details. 0197 * @param errorCode Standard ICU error code. Its input value must 0198 * pass the U_SUCCESS() test, or else the function returns 0199 * immediately. Check for U_FAILURE() on output or use with 0200 * function chaining. (See User Guide for details.) 0201 * @return dest 0202 * @stable ICU 4.6 0203 */ 0204 virtual void 0205 labelToASCII_UTF8(StringPiece label, ByteSink &dest, 0206 IDNAInfo &info, UErrorCode &errorCode) const; 0207 0208 /** 0209 * Converts a single domain name label into its Unicode form for human-readable display. 0210 * UTF-8 version of labelToUnicode(), same behavior. 0211 * 0212 * @param label Input domain name label 0213 * @param dest Destination byte sink; Flush()ed if successful 0214 * @param info Output container of IDNA processing details. 0215 * @param errorCode Standard ICU error code. Its input value must 0216 * pass the U_SUCCESS() test, or else the function returns 0217 * immediately. Check for U_FAILURE() on output or use with 0218 * function chaining. (See User Guide for details.) 0219 * @return dest 0220 * @stable ICU 4.6 0221 */ 0222 virtual void 0223 labelToUnicodeUTF8(StringPiece label, ByteSink &dest, 0224 IDNAInfo &info, UErrorCode &errorCode) const; 0225 0226 /** 0227 * Converts a whole domain name into its ASCII form for DNS lookup. 0228 * UTF-8 version of nameToASCII(), same behavior. 0229 * 0230 * @param name Input domain name 0231 * @param dest Destination byte sink; Flush()ed if successful 0232 * @param info Output container of IDNA processing details. 0233 * @param errorCode Standard ICU error code. Its input value must 0234 * pass the U_SUCCESS() test, or else the function returns 0235 * immediately. Check for U_FAILURE() on output or use with 0236 * function chaining. (See User Guide for details.) 0237 * @return dest 0238 * @stable ICU 4.6 0239 */ 0240 virtual void 0241 nameToASCII_UTF8(StringPiece name, ByteSink &dest, 0242 IDNAInfo &info, UErrorCode &errorCode) const; 0243 0244 /** 0245 * Converts a whole domain name into its Unicode form for human-readable display. 0246 * UTF-8 version of nameToUnicode(), same behavior. 0247 * 0248 * @param name Input domain name 0249 * @param dest Destination byte sink; Flush()ed if successful 0250 * @param info Output container of IDNA processing details. 0251 * @param errorCode Standard ICU error code. Its input value must 0252 * pass the U_SUCCESS() test, or else the function returns 0253 * immediately. Check for U_FAILURE() on output or use with 0254 * function chaining. (See User Guide for details.) 0255 * @return dest 0256 * @stable ICU 4.6 0257 */ 0258 virtual void 0259 nameToUnicodeUTF8(StringPiece name, ByteSink &dest, 0260 IDNAInfo &info, UErrorCode &errorCode) const; 0261 }; 0262 0263 class UTS46; 0264 0265 /** 0266 * Output container for IDNA processing errors. 0267 * The IDNAInfo class is not suitable for subclassing. 0268 * @stable ICU 4.6 0269 */ 0270 class U_COMMON_API IDNAInfo : public UMemory { 0271 public: 0272 /** 0273 * Constructor for stack allocation. 0274 * @stable ICU 4.6 0275 */ 0276 IDNAInfo() : errors(0), labelErrors(0), isTransDiff(false), isBiDi(false), isOkBiDi(true) {} 0277 /** 0278 * Were there IDNA processing errors? 0279 * @return true if there were processing errors 0280 * @stable ICU 4.6 0281 */ 0282 UBool hasErrors() const { return errors!=0; } 0283 /** 0284 * Returns a bit set indicating IDNA processing errors. 0285 * See UIDNA_ERROR_... constants in uidna.h. 0286 * @return bit set of processing errors 0287 * @stable ICU 4.6 0288 */ 0289 uint32_t getErrors() const { return errors; } 0290 /** 0291 * Returns true if transitional and nontransitional processing produce different results. 0292 * This is the case when the input label or domain name contains 0293 * one or more deviation characters outside a Punycode label (see UTS #46). 0294 * <ul> 0295 * <li>With nontransitional processing, such characters are 0296 * copied to the destination string. 0297 * <li>With transitional processing, such characters are 0298 * mapped (sharp s/sigma) or removed (joiner/nonjoiner). 0299 * </ul> 0300 * @return true if transitional and nontransitional processing produce different results 0301 * @stable ICU 4.6 0302 */ 0303 UBool isTransitionalDifferent() const { return isTransDiff; } 0304 0305 private: 0306 friend class UTS46; 0307 0308 IDNAInfo(const IDNAInfo &other) = delete; // no copying 0309 IDNAInfo &operator=(const IDNAInfo &other) = delete; // no copying 0310 0311 void reset() { 0312 errors=labelErrors=0; 0313 isTransDiff=false; 0314 isBiDi=false; 0315 isOkBiDi=true; 0316 } 0317 0318 uint32_t errors, labelErrors; 0319 UBool isTransDiff; 0320 UBool isBiDi; 0321 UBool isOkBiDi; 0322 }; 0323 0324 U_NAMESPACE_END 0325 0326 #endif // UCONFIG_NO_IDNA 0327 0328 #endif /* U_SHOW_CPLUSPLUS_API */ 0329 0330 #endif // __IDNA_H__
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |