punycode

Name

punycode -- 

Synopsis



enum        Punycode_status;
typedef     punycode_uint;
int         punycode_encode                 (size_t input_length,
                                             const punycode_uint input[],
                                             unsigned char case_flags[],
                                             size_t *output_length,
                                             char output[]);
int         punycode_decode                 (size_t input_length,
                                             const char input[],
                                             size_t *output_length,
                                             punycode_uint output[],
                                             unsigned char case_flags[]);

Description

Details

enum Punycode_status

  typedef enum
  {
    PUNYCODE_SUCCESS = 0,
    PUNYCODE_BAD_INPUT,		/* Input is invalid.                       */
    PUNYCODE_BIG_OUTPUT,	/* Output would exceed the space provided. */
    PUNYCODE_OVERFLOW,		/* Input needs wider integers to process.  */
  } Punycode_status;

Enumerated return codes of punycode_encode() and punycode_decode(). The value 0 is guaranteed to always correspond to success.

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.


punycode_uint

  typedef uint32_t punycode_uint;

Unicode code point data type, this is always a 32 bit unsigned integer.


punycode_encode ()

int         punycode_encode                 (size_t input_length,
                                             const punycode_uint input[],
                                             unsigned char case_flags[],
                                             size_t *output_length,
                                             char output[]);

Converts Unicode to Punycode.

input_length :

The input_length is the number of code points in the input.

input :

The input is represented as an array of Unicode code points (not code units; surrogate pairs are not allowed).

case_flags :

The case_flags array holds input_length boolean values, where nonzero suggests that the corresponding Unicode character be forced to uppercase after being decoded (if possible), and zero suggests that it be forced to lowercase (if possible). ASCII code points are encoded literally, except that ASCII letters are forced to uppercase or lowercase according to the corresponding uppercase flags. If case_flags is a NULL pointer then ASCII letters are left as they are, and other code points are treated as if their uppercase flags were zero.

output_length :

The output_length is an in/out argument: the caller passes in the maximum number of code points that it can receive, and on successful return it will contain the number of code points actually output.

output :

The output will be represented as an array of ASCII code points. The output string is *not* zero-terminated; it will contain zeros if and only if the input contains zeros. (Of course the caller can leave room for a terminator and add one if needed.)

Returns :

The return value can be any of the Punycode_status values defined above except PUNYCODE_BAD_INPUT; if not PUNYCODE_SUCCESS, then output_size and output might contain garbage.


punycode_decode ()

int         punycode_decode                 (size_t input_length,
                                             const char input[],
                                             size_t *output_length,
                                             punycode_uint output[],
                                             unsigned char case_flags[]);

Converts Punycode to Unicode.

input_length :

The input_length is the number of code points in the input.

input :

The input is represented as an array of ASCII code points.

output_length :

The output_length is an in/out argument: the caller passes in the maximum number of code points that it can receive, and on successful return it will contain the actual number of code points output.

output :

The output will be represented as an array of Unicode code points.

case_flags :

The case_flags array needs room for at least output_length values, or it can be a NULL pointer if the case information is not needed. A nonzero flag suggests that the corresponding Unicode character be forced to uppercase by the caller (if possible), while zero suggests that it be forced to lowercase (if possible). ASCII code points are output already in the proper case, but their flags will be set appropriately so that applying the flags would be harmless.

Returns :

The return value can be any of the Punycode_status values defined above; if not PUNYCODE_SUCCESS, then output_length, output, and case_flags might contain garbage. On success, the decoder will never need to write an output_length greater than input_length, because of how the encoding is defined.