On Tue, Feb 7, 2017 at 9:56 PM, Tim Rühsen <tim.rueh...@gmx.de> wrote: >> Great work. The current decode branch seems very good. Do you plan to >> add the idna_to_ascii functions as well? > > Just pushed the first untested code (branch 'decode'). > Needs > - test code > - docs (also the libidn unicode functions are still missing documentation)
What about this documentation and semantic change. That is, the flags parameter is ignored for these functions (to make sure that libidn1 flags don't result to unintentional side-effects).
diff --git a/lookup.c b/lookup.c index 94fd558..db6773e 100644 --- a/lookup.c +++ b/lookup.c @@ -469,6 +469,34 @@ idn2_lookup_ul (const char * src, char ** lookupname, int flags) return rc; } +/** + * idn2_to_ascii_4i: + * @input: zero terminated input Unicode (UCS-4) string. + * @output: pointer to newly allocated zero-terminated output string. + * @flags: are ignored + * + * The ToASCII operation takes a sequence of Unicode code points that make + * up one domain label and transforms it into a sequence of code points in + * the ASCII range (0..7F). If ToASCII succeeds, the original sequence and + * the resulting sequence are equivalent labels. + * + * It is important to note that the ToASCII operation can fail. + * ToASCII fails if any step of it fails. If any step of the + * ToASCII operation fails on any label in a domain name, that domain + * name MUST NOT be used as an internationalized domain name. + * The method for dealing with this failure is application-specific. + * + * The inputs to ToASCII are a sequence of code points. + * + * ToASCII never alters a sequence of code points that are all in the ASCII + * range to begin with (although it could fail). Applying the ToASCII operation multiple + * effect as applying it just once. + * + * The flags to underlying IDN2 functions are assumed to be + * %IDN2_NONTRANSITIONAL and %IDN2_NFC_INPUT. + * + * Return value: Returns %IDN2_OK on success, or error code. + **/ int idn2_to_ascii_4i (const uint32_t * in, size_t inlen, char * out, int flags) { @@ -500,7 +528,7 @@ idn2_to_ascii_4i (const uint32_t * in, size_t inlen, char * out, int flags) return IDN2_ENCODING_ERROR; } - rc = idn2_lookup_u8 (input_u8, &output_u8, flags); + rc = idn2_lookup_u8 (input_u8, &output_u8, IDN2_NFC_INPUT|IDN2_NONTRANSITIONAL); free (input_u8); if (rc == IDN2_OK) @@ -517,6 +545,21 @@ idn2_to_ascii_4i (const uint32_t * in, size_t inlen, char * out, int flags) return rc; } +/** + * idn2_to_ascii_4z: + * @input: zero terminated input Unicode (UCS-4) string. + * @output: pointer to newly allocated zero-terminated output string. + * @flags: are ignored + * + * Convert UCS-4 domain name to ASCII string using the IDNA2008 + * rules. The domain name may contain several labels, separated by dots. + * The output buffer must be deallocated by the caller. + * + * The flags to underlying IDN2 functions are assumed to be + * %IDN2_NONTRANSITIONAL and %IDN2_NFC_INPUT. + * + * Return value: Returns %IDN2_OK on success, or error code. + **/ int idn2_to_ascii_4z (const uint32_t * input, char ** output, int flags) { @@ -539,20 +582,50 @@ idn2_to_ascii_4z (const uint32_t * input, char ** output, int flags) return IDN2_ENCODING_ERROR; } - rc = idn2_lookup_u8 (input_u8, (uint8_t **) output, flags); + rc = idn2_lookup_u8 (input_u8, (uint8_t **) output, IDN2_NFC_INPUT|IDN2_NONTRANSITIONAL); free (input_u8); return rc; } +/** + * idn2_to_ascii_8z: + * @input: zero terminated input UTF-8 string. + * @output: pointer to newly allocated output string. + * @flags: are ignored + * + * Convert UTF-8 domain name to ASCII string using the IDNA2008 + * rules. The domain name may contain several labels, separated by dots. + * The output buffer must be deallocated by the caller. + * + * This is equivalent to idn2_lookup_u8() with %IDN2_NONTRANSITIONAL + * and %IDN2_NFC_INPUT flags. + * + * Return value: Returns %IDN2_OK on success, or error code. + **/ int idn2_to_ascii_8z (const char * input, char ** output, int flags) { - return idn2_lookup_u8 ((const uint8_t *) input, (uint8_t **) output, flags); + return idn2_lookup_u8 ((const uint8_t *) input, (uint8_t **) output, IDN2_NFC_INPUT|IDN2_NONTRANSITIONAL); } +/** + * idn2_to_ascii_lz: + * @input: zero terminated input UTF-8 string. + * @output: pointer to newly allocated output string. + * @flags: are ignored + * + * Convert a domain name in locale's encoding to ASCII string using the IDNA2008 + * rules. The domain name may contain several labels, separated by dots. + * The output buffer must be deallocated by the caller. + * + * This is equivalent to idn2_lookup_ul() with %IDN2_NONTRANSITIONAL + * and %IDN2_NFC_INPUT flags. + * + * Return value: Returns %IDN2_OK on success, or error code. + **/ int idn2_to_ascii_lz (const char * input, char ** output, int flags) { - return idn2_lookup_ul (input, output, flags); + return idn2_lookup_ul (input, output, IDN2_NFC_INPUT|IDN2_NONTRANSITIONAL); }
_______________________________________________ Help-libidn mailing list Help-libidn@gnu.org https://lists.gnu.org/mailman/listinfo/help-libidn