Path: blob/jdk8u272-b10-aarch32-20201026/jdk/src/share/native/common/unicode/idna.h
48729 views
// © 2016 and later: Unicode, Inc. and others.1// License & terms of use: http://www.unicode.org/copyright.html2/*3*******************************************************************************4* Copyright (C) 2010-2012, International Business Machines5* Corporation and others. All Rights Reserved.6*******************************************************************************7* file name: idna.h8* encoding: UTF-89* tab size: 8 (not used)10* indentation:411*12* created on: 2010mar0513* created by: Markus W. Scherer14*/1516#ifndef __IDNA_H__17#define __IDNA_H__1819/**20* \file21* \brief C++ API: Internationalizing Domain Names in Applications (IDNA)22*/2324#include "unicode/utypes.h"2526#if !UCONFIG_NO_IDNA2728#include "unicode/bytestream.h"29#include "unicode/stringpiece.h"30#include "unicode/uidna.h"31#include "unicode/unistr.h"3233U_NAMESPACE_BEGIN3435class IDNAInfo;3637/**38* Abstract base class for IDNA processing.39* See http://www.unicode.org/reports/tr46/40* and http://www.ietf.org/rfc/rfc3490.txt41*42* The IDNA class is not intended for public subclassing.43*44* This C++ API currently only implements UTS #46.45* The uidna.h C API implements both UTS #46 (functions using UIDNA service object)46* and IDNA2003 (functions that do not use a service object).47* @stable ICU 4.648*/49class U_COMMON_API IDNA : public UObject {50public:51/**52* Destructor.53* @stable ICU 4.654*/55~IDNA();5657/**58* Returns an IDNA instance which implements UTS #46.59* Returns an unmodifiable instance, owned by the caller.60* Cache it for multiple operations, and delete it when done.61* The instance is thread-safe, that is, it can be used concurrently.62*63* UTS #46 defines Unicode IDNA Compatibility Processing,64* updated to the latest version of Unicode and compatible with both65* IDNA2003 and IDNA2008.66*67* The worker functions use transitional processing, including deviation mappings,68* unless UIDNA_NONTRANSITIONAL_TO_ASCII or UIDNA_NONTRANSITIONAL_TO_UNICODE69* is used in which case the deviation characters are passed through without change.70*71* Disallowed characters are mapped to U+FFFD.72*73* For available options see the uidna.h header.74* Operations with the UTS #46 instance do not support the75* UIDNA_ALLOW_UNASSIGNED option.76*77* By default, the UTS #46 implementation allows all ASCII characters (as valid or mapped).78* When the UIDNA_USE_STD3_RULES option is used, ASCII characters other than79* letters, digits, hyphen (LDH) and dot/full stop are disallowed and mapped to U+FFFD.80*81* @param options Bit set to modify the processing and error checking.82* See option bit set values in uidna.h.83* @param errorCode Standard ICU error code. Its input value must84* pass the U_SUCCESS() test, or else the function returns85* immediately. Check for U_FAILURE() on output or use with86* function chaining. (See User Guide for details.)87* @return the UTS #46 IDNA instance, if successful88* @stable ICU 4.689*/90static IDNA *91createUTS46Instance(uint32_t options, UErrorCode &errorCode);9293/**94* Converts a single domain name label into its ASCII form for DNS lookup.95* If any processing step fails, then info.hasErrors() will be TRUE and96* the result might not be an ASCII string.97* The label might be modified according to the types of errors.98* Labels with severe errors will be left in (or turned into) their Unicode form.99*100* The UErrorCode indicates an error only in exceptional cases,101* such as a U_MEMORY_ALLOCATION_ERROR.102*103* @param label Input domain name label104* @param dest Destination string object105* @param info Output container of IDNA processing details.106* @param errorCode Standard ICU error code. Its input value must107* pass the U_SUCCESS() test, or else the function returns108* immediately. Check for U_FAILURE() on output or use with109* function chaining. (See User Guide for details.)110* @return dest111* @stable ICU 4.6112*/113virtual UnicodeString &114labelToASCII(const UnicodeString &label, UnicodeString &dest,115IDNAInfo &info, UErrorCode &errorCode) const = 0;116117/**118* Converts a single domain name label into its Unicode form for human-readable display.119* If any processing step fails, then info.hasErrors() will be TRUE.120* The label might be modified according to the types of errors.121*122* The UErrorCode indicates an error only in exceptional cases,123* such as a U_MEMORY_ALLOCATION_ERROR.124*125* @param label Input domain name label126* @param dest Destination string object127* @param info Output container of IDNA processing details.128* @param errorCode Standard ICU error code. Its input value must129* pass the U_SUCCESS() test, or else the function returns130* immediately. Check for U_FAILURE() on output or use with131* function chaining. (See User Guide for details.)132* @return dest133* @stable ICU 4.6134*/135virtual UnicodeString &136labelToUnicode(const UnicodeString &label, UnicodeString &dest,137IDNAInfo &info, UErrorCode &errorCode) const = 0;138139/**140* Converts a whole domain name into its ASCII form for DNS lookup.141* If any processing step fails, then info.hasErrors() will be TRUE and142* the result might not be an ASCII string.143* The domain name might be modified according to the types of errors.144* Labels with severe errors will be left in (or turned into) their Unicode form.145*146* The UErrorCode indicates an error only in exceptional cases,147* such as a U_MEMORY_ALLOCATION_ERROR.148*149* @param name Input domain name150* @param dest Destination string object151* @param info Output container of IDNA processing details.152* @param errorCode Standard ICU error code. Its input value must153* pass the U_SUCCESS() test, or else the function returns154* immediately. Check for U_FAILURE() on output or use with155* function chaining. (See User Guide for details.)156* @return dest157* @stable ICU 4.6158*/159virtual UnicodeString &160nameToASCII(const UnicodeString &name, UnicodeString &dest,161IDNAInfo &info, UErrorCode &errorCode) const = 0;162163/**164* Converts a whole domain name into its Unicode form for human-readable display.165* If any processing step fails, then info.hasErrors() will be TRUE.166* The domain name might be modified according to the types of errors.167*168* The UErrorCode indicates an error only in exceptional cases,169* such as a U_MEMORY_ALLOCATION_ERROR.170*171* @param name Input domain name172* @param dest Destination string object173* @param info Output container of IDNA processing details.174* @param errorCode Standard ICU error code. Its input value must175* pass the U_SUCCESS() test, or else the function returns176* immediately. Check for U_FAILURE() on output or use with177* function chaining. (See User Guide for details.)178* @return dest179* @stable ICU 4.6180*/181virtual UnicodeString &182nameToUnicode(const UnicodeString &name, UnicodeString &dest,183IDNAInfo &info, UErrorCode &errorCode) const = 0;184185// UTF-8 versions of the processing methods ---------------------------- ***186187/**188* Converts a single domain name label into its ASCII form for DNS lookup.189* UTF-8 version of labelToASCII(), same behavior.190*191* @param label Input domain name label192* @param dest Destination byte sink; Flush()ed if successful193* @param info Output container of IDNA processing details.194* @param errorCode Standard ICU error code. Its input value must195* pass the U_SUCCESS() test, or else the function returns196* immediately. Check for U_FAILURE() on output or use with197* function chaining. (See User Guide for details.)198* @return dest199* @stable ICU 4.6200*/201virtual void202labelToASCII_UTF8(StringPiece label, ByteSink &dest,203IDNAInfo &info, UErrorCode &errorCode) const;204205/**206* Converts a single domain name label into its Unicode form for human-readable display.207* UTF-8 version of labelToUnicode(), same behavior.208*209* @param label Input domain name label210* @param dest Destination byte sink; Flush()ed if successful211* @param info Output container of IDNA processing details.212* @param errorCode Standard ICU error code. Its input value must213* pass the U_SUCCESS() test, or else the function returns214* immediately. Check for U_FAILURE() on output or use with215* function chaining. (See User Guide for details.)216* @return dest217* @stable ICU 4.6218*/219virtual void220labelToUnicodeUTF8(StringPiece label, ByteSink &dest,221IDNAInfo &info, UErrorCode &errorCode) const;222223/**224* Converts a whole domain name into its ASCII form for DNS lookup.225* UTF-8 version of nameToASCII(), same behavior.226*227* @param name Input domain name228* @param dest Destination byte sink; Flush()ed if successful229* @param info Output container of IDNA processing details.230* @param errorCode Standard ICU error code. Its input value must231* pass the U_SUCCESS() test, or else the function returns232* immediately. Check for U_FAILURE() on output or use with233* function chaining. (See User Guide for details.)234* @return dest235* @stable ICU 4.6236*/237virtual void238nameToASCII_UTF8(StringPiece name, ByteSink &dest,239IDNAInfo &info, UErrorCode &errorCode) const;240241/**242* Converts a whole domain name into its Unicode form for human-readable display.243* UTF-8 version of nameToUnicode(), same behavior.244*245* @param name Input domain name246* @param dest Destination byte sink; Flush()ed if successful247* @param info Output container of IDNA processing details.248* @param errorCode Standard ICU error code. Its input value must249* pass the U_SUCCESS() test, or else the function returns250* immediately. Check for U_FAILURE() on output or use with251* function chaining. (See User Guide for details.)252* @return dest253* @stable ICU 4.6254*/255virtual void256nameToUnicodeUTF8(StringPiece name, ByteSink &dest,257IDNAInfo &info, UErrorCode &errorCode) const;258};259260class UTS46;261262/**263* Output container for IDNA processing errors.264* The IDNAInfo class is not suitable for subclassing.265* @stable ICU 4.6266*/267class U_COMMON_API IDNAInfo : public UMemory {268public:269/**270* Constructor for stack allocation.271* @stable ICU 4.6272*/273IDNAInfo() : errors(0), labelErrors(0), isTransDiff(FALSE), isBiDi(FALSE), isOkBiDi(TRUE) {}274/**275* Were there IDNA processing errors?276* @return TRUE if there were processing errors277* @stable ICU 4.6278*/279UBool hasErrors() const { return errors!=0; }280/**281* Returns a bit set indicating IDNA processing errors.282* See UIDNA_ERROR_... constants in uidna.h.283* @return bit set of processing errors284* @stable ICU 4.6285*/286uint32_t getErrors() const { return errors; }287/**288* Returns TRUE if transitional and nontransitional processing produce different results.289* This is the case when the input label or domain name contains290* one or more deviation characters outside a Punycode label (see UTS #46).291* <ul>292* <li>With nontransitional processing, such characters are293* copied to the destination string.294* <li>With transitional processing, such characters are295* mapped (sharp s/sigma) or removed (joiner/nonjoiner).296* </ul>297* @return TRUE if transitional and nontransitional processing produce different results298* @stable ICU 4.6299*/300UBool isTransitionalDifferent() const { return isTransDiff; }301302private:303friend class UTS46;304305IDNAInfo(const IDNAInfo &other); // no copying306IDNAInfo &operator=(const IDNAInfo &other); // no copying307308void reset() {309errors=labelErrors=0;310isTransDiff=FALSE;311isBiDi=FALSE;312isOkBiDi=TRUE;313}314315uint32_t errors, labelErrors;316UBool isTransDiff;317UBool isBiDi;318UBool isOkBiDi;319};320321U_NAMESPACE_END322323#endif // UCONFIG_NO_IDNA324#endif // __IDNA_H__325326327