Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/native/common/unicode/idna.h
38827 views
/*1*******************************************************************************2* Copyright (C) 2010-2012, International Business Machines3* Corporation and others. All Rights Reserved.4*******************************************************************************5* file name: idna.h6* encoding: US-ASCII7* tab size: 8 (not used)8* indentation:49*10* created on: 2010mar0511* created by: Markus W. Scherer12*/1314#ifndef __IDNA_H__15#define __IDNA_H__1617/**18* \file19* \brief C++ API: Internationalizing Domain Names in Applications (IDNA)20*/2122#include "unicode/utypes.h"2324#if !UCONFIG_NO_IDNA2526#include "unicode/bytestream.h"27#include "unicode/stringpiece.h"28#include "unicode/uidna.h"29#include "unicode/unistr.h"3031U_NAMESPACE_BEGIN3233class IDNAInfo;3435/**36* Abstract base class for IDNA processing.37* See http://www.unicode.org/reports/tr46/38* and http://www.ietf.org/rfc/rfc3490.txt39*40* The IDNA class is not intended for public subclassing.41*42* This C++ API currently only implements UTS #46.43* The uidna.h C API implements both UTS #46 (functions using UIDNA service object)44* and IDNA2003 (functions that do not use a service object).45* @stable ICU 4.646*/47class U_COMMON_API IDNA : public UObject {48public:49/**50* Destructor.51* @stable ICU 4.652*/53~IDNA();5455/**56* Returns an IDNA instance which implements UTS #46.57* Returns an unmodifiable instance, owned by the caller.58* Cache it for multiple operations, and delete it when done.59* The instance is thread-safe, that is, it can be used concurrently.60*61* UTS #46 defines Unicode IDNA Compatibility Processing,62* updated to the latest version of Unicode and compatible with both63* IDNA2003 and IDNA2008.64*65* The worker functions use transitional processing, including deviation mappings,66* unless UIDNA_NONTRANSITIONAL_TO_ASCII or UIDNA_NONTRANSITIONAL_TO_UNICODE67* is used in which case the deviation characters are passed through without change.68*69* Disallowed characters are mapped to U+FFFD.70*71* For available options see the uidna.h header.72* Operations with the UTS #46 instance do not support the73* UIDNA_ALLOW_UNASSIGNED option.74*75* By default, the UTS #46 implementation allows all ASCII characters (as valid or mapped).76* When the UIDNA_USE_STD3_RULES option is used, ASCII characters other than77* letters, digits, hyphen (LDH) and dot/full stop are disallowed and mapped to U+FFFD.78*79* @param options Bit set to modify the processing and error checking.80* See option bit set values in uidna.h.81* @param errorCode Standard ICU error code. Its input value must82* pass the U_SUCCESS() test, or else the function returns83* immediately. Check for U_FAILURE() on output or use with84* function chaining. (See User Guide for details.)85* @return the UTS #46 IDNA instance, if successful86* @stable ICU 4.687*/88static IDNA *89createUTS46Instance(uint32_t options, UErrorCode &errorCode);9091/**92* Converts a single domain name label into its ASCII form for DNS lookup.93* If any processing step fails, then info.hasErrors() will be TRUE and94* the result might not be an ASCII string.95* The label might be modified according to the types of errors.96* Labels with severe errors will be left in (or turned into) their Unicode form.97*98* The UErrorCode indicates an error only in exceptional cases,99* such as a U_MEMORY_ALLOCATION_ERROR.100*101* @param label Input domain name label102* @param dest Destination string object103* @param info Output container of IDNA processing details.104* @param errorCode Standard ICU error code. Its input value must105* pass the U_SUCCESS() test, or else the function returns106* immediately. Check for U_FAILURE() on output or use with107* function chaining. (See User Guide for details.)108* @return dest109* @stable ICU 4.6110*/111virtual UnicodeString &112labelToASCII(const UnicodeString &label, UnicodeString &dest,113IDNAInfo &info, UErrorCode &errorCode) const = 0;114115/**116* Converts a single domain name label into its Unicode form for human-readable display.117* If any processing step fails, then info.hasErrors() will be TRUE.118* The label might be modified according to the types of errors.119*120* The UErrorCode indicates an error only in exceptional cases,121* such as a U_MEMORY_ALLOCATION_ERROR.122*123* @param label Input domain name label124* @param dest Destination string object125* @param info Output container of IDNA processing details.126* @param errorCode Standard ICU error code. Its input value must127* pass the U_SUCCESS() test, or else the function returns128* immediately. Check for U_FAILURE() on output or use with129* function chaining. (See User Guide for details.)130* @return dest131* @stable ICU 4.6132*/133virtual UnicodeString &134labelToUnicode(const UnicodeString &label, UnicodeString &dest,135IDNAInfo &info, UErrorCode &errorCode) const = 0;136137/**138* Converts a whole domain name into its ASCII form for DNS lookup.139* If any processing step fails, then info.hasErrors() will be TRUE and140* the result might not be an ASCII string.141* The domain name might be modified according to the types of errors.142* Labels with severe errors will be left in (or turned into) their Unicode form.143*144* The UErrorCode indicates an error only in exceptional cases,145* such as a U_MEMORY_ALLOCATION_ERROR.146*147* @param name Input domain name148* @param dest Destination string object149* @param info Output container of IDNA processing details.150* @param errorCode Standard ICU error code. Its input value must151* pass the U_SUCCESS() test, or else the function returns152* immediately. Check for U_FAILURE() on output or use with153* function chaining. (See User Guide for details.)154* @return dest155* @stable ICU 4.6156*/157virtual UnicodeString &158nameToASCII(const UnicodeString &name, UnicodeString &dest,159IDNAInfo &info, UErrorCode &errorCode) const = 0;160161/**162* Converts a whole domain name into its Unicode form for human-readable display.163* If any processing step fails, then info.hasErrors() will be TRUE.164* The domain name might be modified according to the types of errors.165*166* The UErrorCode indicates an error only in exceptional cases,167* such as a U_MEMORY_ALLOCATION_ERROR.168*169* @param name Input domain name170* @param dest Destination string object171* @param info Output container of IDNA processing details.172* @param errorCode Standard ICU error code. Its input value must173* pass the U_SUCCESS() test, or else the function returns174* immediately. Check for U_FAILURE() on output or use with175* function chaining. (See User Guide for details.)176* @return dest177* @stable ICU 4.6178*/179virtual UnicodeString &180nameToUnicode(const UnicodeString &name, UnicodeString &dest,181IDNAInfo &info, UErrorCode &errorCode) const = 0;182183// UTF-8 versions of the processing methods ---------------------------- ***184185/**186* Converts a single domain name label into its ASCII form for DNS lookup.187* UTF-8 version of labelToASCII(), same behavior.188*189* @param label Input domain name label190* @param dest Destination byte sink; Flush()ed if successful191* @param info Output container of IDNA processing details.192* @param errorCode Standard ICU error code. Its input value must193* pass the U_SUCCESS() test, or else the function returns194* immediately. Check for U_FAILURE() on output or use with195* function chaining. (See User Guide for details.)196* @return dest197* @stable ICU 4.6198*/199virtual void200labelToASCII_UTF8(const StringPiece &label, ByteSink &dest,201IDNAInfo &info, UErrorCode &errorCode) const;202203/**204* Converts a single domain name label into its Unicode form for human-readable display.205* UTF-8 version of labelToUnicode(), same behavior.206*207* @param label Input domain name label208* @param dest Destination byte sink; Flush()ed if successful209* @param info Output container of IDNA processing details.210* @param errorCode Standard ICU error code. Its input value must211* pass the U_SUCCESS() test, or else the function returns212* immediately. Check for U_FAILURE() on output or use with213* function chaining. (See User Guide for details.)214* @return dest215* @stable ICU 4.6216*/217virtual void218labelToUnicodeUTF8(const StringPiece &label, ByteSink &dest,219IDNAInfo &info, UErrorCode &errorCode) const;220221/**222* Converts a whole domain name into its ASCII form for DNS lookup.223* UTF-8 version of nameToASCII(), same behavior.224*225* @param name Input domain name226* @param dest Destination byte sink; Flush()ed if successful227* @param info Output container of IDNA processing details.228* @param errorCode Standard ICU error code. Its input value must229* pass the U_SUCCESS() test, or else the function returns230* immediately. Check for U_FAILURE() on output or use with231* function chaining. (See User Guide for details.)232* @return dest233* @stable ICU 4.6234*/235virtual void236nameToASCII_UTF8(const StringPiece &name, ByteSink &dest,237IDNAInfo &info, UErrorCode &errorCode) const;238239/**240* Converts a whole domain name into its Unicode form for human-readable display.241* UTF-8 version of nameToUnicode(), same behavior.242*243* @param name Input domain name244* @param dest Destination byte sink; Flush()ed if successful245* @param info Output container of IDNA processing details.246* @param errorCode Standard ICU error code. Its input value must247* pass the U_SUCCESS() test, or else the function returns248* immediately. Check for U_FAILURE() on output or use with249* function chaining. (See User Guide for details.)250* @return dest251* @stable ICU 4.6252*/253virtual void254nameToUnicodeUTF8(const StringPiece &name, ByteSink &dest,255IDNAInfo &info, UErrorCode &errorCode) const;256};257258class UTS46;259260/**261* Output container for IDNA processing errors.262* The IDNAInfo class is not suitable for subclassing.263* @stable ICU 4.6264*/265class U_COMMON_API IDNAInfo : public UMemory {266public:267/**268* Constructor for stack allocation.269* @stable ICU 4.6270*/271IDNAInfo() : errors(0), labelErrors(0), isTransDiff(FALSE), isBiDi(FALSE), isOkBiDi(TRUE) {}272/**273* Were there IDNA processing errors?274* @return TRUE if there were processing errors275* @stable ICU 4.6276*/277UBool hasErrors() const { return errors!=0; }278/**279* Returns a bit set indicating IDNA processing errors.280* See UIDNA_ERROR_... constants in uidna.h.281* @return bit set of processing errors282* @stable ICU 4.6283*/284uint32_t getErrors() const { return errors; }285/**286* Returns TRUE if transitional and nontransitional processing produce different results.287* This is the case when the input label or domain name contains288* one or more deviation characters outside a Punycode label (see UTS #46).289* <ul>290* <li>With nontransitional processing, such characters are291* copied to the destination string.292* <li>With transitional processing, such characters are293* mapped (sharp s/sigma) or removed (joiner/nonjoiner).294* </ul>295* @return TRUE if transitional and nontransitional processing produce different results296* @stable ICU 4.6297*/298UBool isTransitionalDifferent() const { return isTransDiff; }299300private:301friend class UTS46;302303IDNAInfo(const IDNAInfo &other); // no copying304IDNAInfo &operator=(const IDNAInfo &other); // no copying305306void reset() {307errors=labelErrors=0;308isTransDiff=FALSE;309isBiDi=FALSE;310isOkBiDi=TRUE;311}312313uint32_t errors, labelErrors;314UBool isTransDiff;315UBool isBiDi;316UBool isOkBiDi;317};318319U_NAMESPACE_END320321#endif // UCONFIG_NO_IDNA322#endif // __IDNA_H__323324325