1*0e209d39SAndroid Build Coastguard Worker // © 2016 and later: Unicode, Inc. and others. 2*0e209d39SAndroid Build Coastguard Worker // License & terms of use: http://www.unicode.org/copyright.html 3*0e209d39SAndroid Build Coastguard Worker /* 4*0e209d39SAndroid Build Coastguard Worker ******************************************************************************* 5*0e209d39SAndroid Build Coastguard Worker * 6*0e209d39SAndroid Build Coastguard Worker * Copyright (C) 2002-2003, International Business Machines 7*0e209d39SAndroid Build Coastguard Worker * Corporation and others. All Rights Reserved. 8*0e209d39SAndroid Build Coastguard Worker * 9*0e209d39SAndroid Build Coastguard Worker ******************************************************************************* 10*0e209d39SAndroid Build Coastguard Worker * file name: punycode.h 11*0e209d39SAndroid Build Coastguard Worker * encoding: UTF-8 12*0e209d39SAndroid Build Coastguard Worker * tab size: 8 (not used) 13*0e209d39SAndroid Build Coastguard Worker * indentation:4 14*0e209d39SAndroid Build Coastguard Worker * 15*0e209d39SAndroid Build Coastguard Worker * created on: 2002jan31 16*0e209d39SAndroid Build Coastguard Worker * created by: Markus W. Scherer 17*0e209d39SAndroid Build Coastguard Worker */ 18*0e209d39SAndroid Build Coastguard Worker 19*0e209d39SAndroid Build Coastguard Worker /* This ICU code derived from: */ 20*0e209d39SAndroid Build Coastguard Worker /* 21*0e209d39SAndroid Build Coastguard Worker punycode.c 0.4.0 (2001-Nov-17-Sat) 22*0e209d39SAndroid Build Coastguard Worker http://www.cs.berkeley.edu/~amc/idn/ 23*0e209d39SAndroid Build Coastguard Worker Adam M. Costello 24*0e209d39SAndroid Build Coastguard Worker http://www.nicemice.net/amc/ 25*0e209d39SAndroid Build Coastguard Worker */ 26*0e209d39SAndroid Build Coastguard Worker 27*0e209d39SAndroid Build Coastguard Worker #ifndef __PUNYCODE_H__ 28*0e209d39SAndroid Build Coastguard Worker #define __PUNYCODE_H__ 29*0e209d39SAndroid Build Coastguard Worker 30*0e209d39SAndroid Build Coastguard Worker #include "unicode/utypes.h" 31*0e209d39SAndroid Build Coastguard Worker 32*0e209d39SAndroid Build Coastguard Worker #if !UCONFIG_NO_IDNA 33*0e209d39SAndroid Build Coastguard Worker 34*0e209d39SAndroid Build Coastguard Worker /** 35*0e209d39SAndroid Build Coastguard Worker * u_strToPunycode() converts Unicode to Punycode. 36*0e209d39SAndroid Build Coastguard Worker * 37*0e209d39SAndroid Build Coastguard Worker * The input string must not contain single, unpaired surrogates. 38*0e209d39SAndroid Build Coastguard Worker * The output will be represented as an array of ASCII code points. 39*0e209d39SAndroid Build Coastguard Worker * 40*0e209d39SAndroid Build Coastguard Worker * The output string is NUL-terminated according to normal ICU 41*0e209d39SAndroid Build Coastguard Worker * string output rules. 42*0e209d39SAndroid Build Coastguard Worker * 43*0e209d39SAndroid Build Coastguard Worker * @param src Input Unicode string. 44*0e209d39SAndroid Build Coastguard Worker * This function handles a limited amount of code points 45*0e209d39SAndroid Build Coastguard Worker * (the limit is >=64). 46*0e209d39SAndroid Build Coastguard Worker * U_INDEX_OUTOFBOUNDS_ERROR is set if the limit is exceeded. 47*0e209d39SAndroid Build Coastguard Worker * @param srcLength Number of UChars in src, or -1 if NUL-terminated. 48*0e209d39SAndroid Build Coastguard Worker * @param dest Output Punycode array. 49*0e209d39SAndroid Build Coastguard Worker * @param destCapacity Size of dest. 50*0e209d39SAndroid Build Coastguard Worker * @param caseFlags Vector of boolean values, one per input UChar, 51*0e209d39SAndroid Build Coastguard Worker * indicating that the corresponding character is to be 52*0e209d39SAndroid Build Coastguard Worker * marked for the decoder optionally 53*0e209d39SAndroid Build Coastguard Worker * uppercasing (true) or lowercasing (false) 54*0e209d39SAndroid Build Coastguard Worker * the character. 55*0e209d39SAndroid Build Coastguard Worker * ASCII characters are output directly in the case as marked. 56*0e209d39SAndroid Build Coastguard Worker * Flags corresponding to trail surrogates are ignored. 57*0e209d39SAndroid Build Coastguard Worker * If caseFlags==NULL then input characters are not 58*0e209d39SAndroid Build Coastguard Worker * case-mapped. 59*0e209d39SAndroid Build Coastguard Worker * @param pErrorCode ICU in/out error code parameter. 60*0e209d39SAndroid Build Coastguard Worker * U_INVALID_CHAR_FOUND if src contains 61*0e209d39SAndroid Build Coastguard Worker * unmatched single surrogates. 62*0e209d39SAndroid Build Coastguard Worker * U_INDEX_OUTOFBOUNDS_ERROR if src contains 63*0e209d39SAndroid Build Coastguard Worker * too many code points. 64*0e209d39SAndroid Build Coastguard Worker * @return Number of ASCII characters in puny. 65*0e209d39SAndroid Build Coastguard Worker * 66*0e209d39SAndroid Build Coastguard Worker * @see u_strFromPunycode 67*0e209d39SAndroid Build Coastguard Worker */ 68*0e209d39SAndroid Build Coastguard Worker U_CAPI int32_t 69*0e209d39SAndroid Build Coastguard Worker u_strToPunycode(const UChar *src, int32_t srcLength, 70*0e209d39SAndroid Build Coastguard Worker UChar *dest, int32_t destCapacity, 71*0e209d39SAndroid Build Coastguard Worker const UBool *caseFlags, 72*0e209d39SAndroid Build Coastguard Worker UErrorCode *pErrorCode); 73*0e209d39SAndroid Build Coastguard Worker 74*0e209d39SAndroid Build Coastguard Worker /** 75*0e209d39SAndroid Build Coastguard Worker * u_strFromPunycode() converts Punycode to Unicode. 76*0e209d39SAndroid Build Coastguard Worker * The Unicode string will be at most as long (in UChars) 77*0e209d39SAndroid Build Coastguard Worker * than the Punycode string (in chars). 78*0e209d39SAndroid Build Coastguard Worker * 79*0e209d39SAndroid Build Coastguard Worker * @param src Input Punycode string. 80*0e209d39SAndroid Build Coastguard Worker * @param srcLength Length of puny, or -1 if NUL-terminated 81*0e209d39SAndroid Build Coastguard Worker * @param dest Output Unicode string buffer. 82*0e209d39SAndroid Build Coastguard Worker * @param destCapacity Size of dest in number of UChars, 83*0e209d39SAndroid Build Coastguard Worker * and of caseFlags in numbers of UBools. 84*0e209d39SAndroid Build Coastguard Worker * @param caseFlags Output array for case flags as 85*0e209d39SAndroid Build Coastguard Worker * defined by the Punycode string. 86*0e209d39SAndroid Build Coastguard Worker * The caller should uppercase (true) or lowercase (FASLE) 87*0e209d39SAndroid Build Coastguard Worker * the corresponding character in dest. 88*0e209d39SAndroid Build Coastguard Worker * For supplementary characters, only the lead surrogate 89*0e209d39SAndroid Build Coastguard Worker * is marked, and false is stored for the trail surrogate. 90*0e209d39SAndroid Build Coastguard Worker * This is redundant and not necessary for ASCII characters 91*0e209d39SAndroid Build Coastguard Worker * because they are already in the case indicated. 92*0e209d39SAndroid Build Coastguard Worker * Can be NULL if the case flags are not needed. 93*0e209d39SAndroid Build Coastguard Worker * @param pErrorCode ICU in/out error code parameter. 94*0e209d39SAndroid Build Coastguard Worker * U_INVALID_CHAR_FOUND if a non-ASCII character 95*0e209d39SAndroid Build Coastguard Worker * precedes the last delimiter ('-'), 96*0e209d39SAndroid Build Coastguard Worker * or if an invalid character (not a-zA-Z0-9) is found 97*0e209d39SAndroid Build Coastguard Worker * after the last delimiter. 98*0e209d39SAndroid Build Coastguard Worker * U_ILLEGAL_CHAR_FOUND if the delta sequence is ill-formed. 99*0e209d39SAndroid Build Coastguard Worker * @return Number of UChars written to dest. 100*0e209d39SAndroid Build Coastguard Worker * 101*0e209d39SAndroid Build Coastguard Worker * @see u_strToPunycode 102*0e209d39SAndroid Build Coastguard Worker */ 103*0e209d39SAndroid Build Coastguard Worker U_CAPI int32_t 104*0e209d39SAndroid Build Coastguard Worker u_strFromPunycode(const UChar *src, int32_t srcLength, 105*0e209d39SAndroid Build Coastguard Worker UChar *dest, int32_t destCapacity, 106*0e209d39SAndroid Build Coastguard Worker UBool *caseFlags, 107*0e209d39SAndroid Build Coastguard Worker UErrorCode *pErrorCode); 108*0e209d39SAndroid Build Coastguard Worker 109*0e209d39SAndroid Build Coastguard Worker #endif /* #if !UCONFIG_NO_IDNA */ 110*0e209d39SAndroid Build Coastguard Worker 111*0e209d39SAndroid Build Coastguard Worker #endif 112*0e209d39SAndroid Build Coastguard Worker 113*0e209d39SAndroid Build Coastguard Worker /* 114*0e209d39SAndroid Build Coastguard Worker * Hey, Emacs, please set the following: 115*0e209d39SAndroid Build Coastguard Worker * 116*0e209d39SAndroid Build Coastguard Worker * Local Variables: 117*0e209d39SAndroid Build Coastguard Worker * indent-tabs-mode: nil 118*0e209d39SAndroid Build Coastguard Worker * End: 119*0e209d39SAndroid Build Coastguard Worker * 120*0e209d39SAndroid Build Coastguard Worker */ 121