<?xml version="1.0"?> <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd"> <refentry id="libidn-punycode"> <refmeta> <refentrytitle role="top_of_page">punycode</refentrytitle> <manvolnum>3</manvolnum> <refmiscinfo>LIBIDN Library</refmiscinfo> </refmeta> <refnamediv> <refname>punycode</refname> <refpurpose></refpurpose> <!--[<xref linkend="desc" endterm="desc.title"/>]--> </refnamediv> <refsynopsisdiv role="synopsis"> <title role="synopsis.title">Synopsis</title> <synopsis> enum <link linkend="Punycode-status">Punycode_status</link>; const <link linkend="char">char</link>* <link linkend="punycode-strerror">punycode_strerror</link> (<link linkend="Punycode-status">Punycode_status</link> rc); typedef <link linkend="punycode-uint">punycode_uint</link>; <link linkend="int">int</link> <link linkend="punycode-encode">punycode_encode</link> (<link linkend="size-t">size_t</link> input_length, const <link linkend="punycode-uint">punycode_uint</link> input[], unsigned <link linkend="char">char</link> case_flags[], <link linkend="size-t">size_t</link> *output_length, <link linkend="char">char</link> output[]); <link linkend="int">int</link> <link linkend="punycode-decode">punycode_decode</link> (<link linkend="size-t">size_t</link> input_length, const <link linkend="char">char</link> input[], <link linkend="size-t">size_t</link> *output_length, <link linkend="punycode-uint">punycode_uint</link> output[], unsigned <link linkend="char">char</link> case_flags[]); </synopsis> </refsynopsisdiv> <refsect1 role="desc"> <title role="desc.title">Description</title> <para> </para> </refsect1> <refsect1 role="details"> <title role="details.title">Details</title> <refsect2> <title><anchor id="Punycode-status" role="enum"/>enum Punycode_status</title> <indexterm><primary>Punycode_status</primary></indexterm><programlisting> typedef enum { PUNYCODE_SUCCESS = punycode_success, PUNYCODE_BAD_INPUT = punycode_bad_input, PUNYCODE_BIG_OUTPUT = punycode_big_output, PUNYCODE_OVERFLOW = punycode_overflow } Punycode_status; </programlisting> <para> Enumerated return codes of <link linkend="punycode-encode"><function>punycode_encode()</function></link> and <link linkend="punycode-decode"><function>punycode_decode()</function></link>. The value 0 is guaranteed to always correspond to success.</para> <para> </para><variablelist role="enum"> <varlistentry> <term><anchor id="PUNYCODE-SUCCESS:CAPS" role="constant"/><literal>PUNYCODE_SUCCESS</literal></term> <listitem><simpara> Successful operation. This value is guaranteed to always be zero, the remaining ones are only guaranteed to hold non-zero values, for logical comparison purposes. </simpara></listitem> </varlistentry> <varlistentry> <term><anchor id="PUNYCODE-BAD-INPUT:CAPS" role="constant"/><literal>PUNYCODE_BAD_INPUT</literal></term> <listitem><simpara> Input is invalid. </simpara></listitem> </varlistentry> <varlistentry> <term><anchor id="PUNYCODE-BIG-OUTPUT:CAPS" role="constant"/><literal>PUNYCODE_BIG_OUTPUT</literal></term> <listitem><simpara> Output would exceed the space provided. </simpara></listitem> </varlistentry> <varlistentry> <term><anchor id="PUNYCODE-OVERFLOW:CAPS" role="constant"/><literal>PUNYCODE_OVERFLOW</literal></term> <listitem><simpara> Input needs wider integers to process. </simpara></listitem> </varlistentry> </variablelist></refsect2> <refsect2> <title><anchor id="punycode-strerror" role="function"/>punycode_strerror ()</title> <indexterm><primary>punycode_strerror</primary></indexterm><programlisting>const <link linkend="char">char</link>* punycode_strerror (<link linkend="Punycode-status">Punycode_status</link> rc);</programlisting> <para> Convert a return code integer to a text string. This string can be used to output a diagnostic message to the user. </para> <para> PUNYCODE_SUCCESS: Successful operation. This value is guaranteed to always be zero, the remaining ones are only guaranteed to hold non-zero values, for logical comparison purposes. PUNYCODE_BAD_INPUT: Input is invalid. PUNYCODE_BIG_OUTPUT: Output would exceed the space provided. PUNYCODE_OVERFLOW: Input needs wider integers to process.</para> <para> </para><variablelist role="params"> <varlistentry><term><parameter>rc</parameter> :</term> <listitem><simpara> an <link linkend="Punycode-status"><type>Punycode_status</type></link> return code. </simpara></listitem></varlistentry> <varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> Returns a pointer to a statically allocated string containing a description of the error with the return code <parameter>rc</parameter>. </simpara></listitem></varlistentry> </variablelist></refsect2> <refsect2> <title><anchor id="punycode-uint" role="typedef"/>punycode_uint</title> <indexterm><primary>punycode_uint</primary></indexterm><programlisting> typedef uint32_t punycode_uint; </programlisting> <para> Unicode code point data type, this is always a 32 bit unsigned integer.</para> <para> </para></refsect2> <refsect2> <title><anchor id="punycode-encode" role="function"/>punycode_encode ()</title> <indexterm><primary>punycode_encode</primary></indexterm><programlisting><link linkend="int">int</link> punycode_encode (<link linkend="size-t">size_t</link> input_length, const <link linkend="punycode-uint">punycode_uint</link> input[], unsigned <link linkend="char">char</link> case_flags[], <link linkend="size-t">size_t</link> *output_length, <link linkend="char">char</link> output[]);</programlisting> <para> Converts a sequence of code points (presumed to be Unicode code points) to Punycode.</para> <para> </para><variablelist role="params"> <varlistentry><term><parameter>input_length</parameter> :</term> <listitem><simpara> The number of code points in the <parameter>input</parameter> array and the number of flags in the <parameter>case_flags</parameter> array. </simpara></listitem></varlistentry> <varlistentry><term><parameter>input</parameter> :</term> <listitem><simpara> An array of code points. They are presumed to be Unicode code points, but that is not strictly REQUIRED. The array contains code points, not code units. UTF-16 uses code units D800 through DFFF to refer to code points 10000..10FFFF. The code points D800..DFFF do not occur in any valid Unicode string. The code points that can occur in Unicode strings (0..D7FF and E000..10FFFF) are also called Unicode scalar values. </simpara></listitem></varlistentry> <varlistentry><term><parameter>case_flags</parameter> :</term> <listitem><simpara> A <link linkend="NULL:CAPS"><literal>NULL</literal></link> pointer or an array of boolean values parallel to the <parameter>input</parameter> array. Nonzero (true, flagged) suggests that the corresponding Unicode character be forced to uppercase after being decoded (if possible), and zero (false, unflagged) suggests that it be forced to lowercase (if possible). ASCII code points (0..7F) are encoded literally, except that ASCII letters are forced to uppercase or lowercase according to the corresponding case flags. If <parameter>case_flags</parameter> is a <link linkend="NULL:CAPS"><literal>NULL</literal></link> pointer then ASCII letters are left as they are, and other code points are treated as unflagged. </simpara></listitem></varlistentry> <varlistentry><term><parameter>output_length</parameter> :</term> <listitem><simpara> The caller passes in the maximum number of ASCII code points that it can receive. On successful return it will contain the number of ASCII code points actually output. </simpara></listitem></varlistentry> <varlistentry><term><parameter>output</parameter> :</term> <listitem><simpara> An array of ASCII code points. It is *not* null-terminated; it will contain zeros if and only if the <parameter>input</parameter> contains zeros. (Of course the caller can leave room for a terminator and add one if needed.) </simpara></listitem></varlistentry> <varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> The return value can be any of the <link linkend="Punycode-status"><type>Punycode_status</type></link> values defined above except <link linkend="PUNYCODE-BAD-INPUT:CAPS"><literal>PUNYCODE_BAD_INPUT</literal></link>. If not <link linkend="PUNYCODE-SUCCESS:CAPS"><literal>PUNYCODE_SUCCESS</literal></link>, then <parameter>output_size</parameter> and <parameter>output</parameter> might contain garbage. </simpara></listitem></varlistentry> </variablelist></refsect2> <refsect2> <title><anchor id="punycode-decode" role="function"/>punycode_decode ()</title> <indexterm><primary>punycode_decode</primary></indexterm><programlisting><link linkend="int">int</link> punycode_decode (<link linkend="size-t">size_t</link> input_length, const <link linkend="char">char</link> input[], <link linkend="size-t">size_t</link> *output_length, <link linkend="punycode-uint">punycode_uint</link> output[], unsigned <link linkend="char">char</link> case_flags[]);</programlisting> <para> Converts Punycode to a sequence of code points (presumed to be Unicode code points).</para> <para> </para><variablelist role="params"> <varlistentry><term><parameter>input_length</parameter> :</term> <listitem><simpara> The number of ASCII code points in the <parameter>input</parameter> array. </simpara></listitem></varlistentry> <varlistentry><term><parameter>input</parameter> :</term> <listitem><simpara> An array of ASCII code points (0..7F). </simpara></listitem></varlistentry> <varlistentry><term><parameter>output_length</parameter> :</term> <listitem><simpara> The caller passes in the maximum number of code points that it can receive into the <parameter>output</parameter> array (which is also the maximum number of flags that it can receive into the <parameter>case_flags</parameter> array, if <parameter>case_flags</parameter> is not a <link linkend="NULL:CAPS"><literal>NULL</literal></link> pointer). On successful return it will contain the number of code points actually output (which is also the number of flags actually output, if case_flags is not a null pointer). The decoder will never need to output more code points than the number of ASCII code points in the input, because of the way the encoding is defined. The number of code points output cannot exceed the maximum possible value of a punycode_uint, even if the supplied <parameter>output_length</parameter> is greater than that. </simpara></listitem></varlistentry> <varlistentry><term><parameter>output</parameter> :</term> <listitem><simpara> An array of code points like the input argument of <link linkend="punycode-encode"><function>punycode_encode()</function></link> (see above). </simpara></listitem></varlistentry> <varlistentry><term><parameter>case_flags</parameter> :</term> <listitem><simpara> A <link linkend="NULL:CAPS"><literal>NULL</literal></link> pointer (if the flags are not needed by the caller) or an array of boolean values parallel to the <parameter>output</parameter> array. Nonzero (true, flagged) suggests that the corresponding Unicode character be forced to uppercase by the caller (if possible), and zero (false, unflagged) suggests that it be forced to lowercase (if possible). ASCII code points (0..7F) are output already in the proper case, but their flags will be set appropriately so that applying the flags would be harmless. </simpara></listitem></varlistentry> <varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> The return value can be any of the <link linkend="Punycode-status"><type>Punycode_status</type></link> values defined above. If not <link linkend="PUNYCODE-SUCCESS:CAPS"><literal>PUNYCODE_SUCCESS</literal></link>, then <parameter>output_length</parameter>, <parameter>output</parameter>, and <parameter>case_flags</parameter> might contain garbage. </simpara></listitem></varlistentry> </variablelist></refsect2> </refsect1> </refentry>